function testGenerate() { $templates = array('currencies_list' => array(), 'currencies_inline' => array(), 'fiat_currencies_list' => array(), 'fiat_currencies_inline' => array(), 'crypto_currencies_list' => array(), 'crypto_currencies_inline' => array(), 'commodity_currencies_list' => array(), 'commodity_currencies_inline' => array(), 'exchange_wallets_list' => array(), 'mining_pools_list' => array(), 'securities_list' => array(), 'exchange_list' => array()); foreach (get_all_currencies() as $cur) { $templates['currencies_list'][] = " * " . get_currency_name($cur); $templates['currencies_inline'][] = get_currency_abbr($cur); } foreach (get_all_fiat_currencies() as $cur) { $templates['fiat_currencies_list'][] = " * " . get_currency_name($cur); $templates['fiat_currencies_inline'][] = get_currency_abbr($cur); } foreach (get_all_cryptocurrencies() as $cur) { $templates['crypto_currencies_list'][] = " * " . get_currency_name($cur); $templates['crypto_currencies_inline'][] = get_currency_abbr($cur); } foreach (get_all_commodity_currencies() as $cur) { $templates['commodity_currencies_list'][] = " * " . get_currency_name($cur); $templates['commodity_currencies_inline'][] = get_currency_abbr($cur); } $grouped = account_data_grouped(); foreach ($grouped['Exchanges'] as $key => $data) { if (!$data['disabled']) { $templates['exchange_wallets_list'][] = " * " . get_exchange_name($key); } } foreach ($grouped['Mining pools'] as $key => $data) { if (!$data['disabled']) { $templates['mining_pools_list'][] = " * " . get_exchange_name($key); } } foreach ($grouped['Securities'] as $key => $data) { if (!$data['disabled']) { $templates['securities_list'][] = " * " . get_exchange_name($key); } } foreach (get_exchange_pairs() as $key => $pairs) { $templates['exchange_list'][] = " * " . get_exchange_name($key); } $templates['currencies_list'] = implode("\n", array_unique($templates['currencies_list'])); $templates['fiat_currencies_list'] = implode("\n", array_unique($templates['fiat_currencies_list'])); $templates['crypto_currencies_list'] = implode("\n", array_unique($templates['crypto_currencies_list'])); $templates['commodity_currencies_list'] = implode("\n", array_unique($templates['commodity_currencies_list'])); $templates['exchange_wallets_list'] = implode("\n", array_unique($templates['exchange_wallets_list'])); $templates['mining_pools_list'] = implode("\n", array_unique($templates['mining_pools_list'])); $templates['securities_list'] = implode("\n", array_unique($templates['securities_list'])); $templates['exchange_list'] = implode("\n", array_unique($templates['exchange_list'])); $templates['currencies_inline'] = implode(", ", array_unique($templates['currencies_inline'])); $templates['fiat_currencies_inline'] = implode(", ", array_unique($templates['fiat_currencies_inline'])); $templates['crypto_currencies_inline'] = implode(", ", array_unique($templates['crypto_currencies_inline'])); $templates['commodity_currencies_inline'] = implode(", ", array_unique($templates['commodity_currencies_inline'])); // load the template $input = file_get_contents(__DIR__ . "/../README.template.md"); foreach ($templates as $key => $value) { $input = str_replace('{$' . $key . '}', $value, $input); } // write it out file_put_contents(__DIR__ . "/../README.md", $input); }
/** * @return an array of columns e.g. (type, title, args) */ function getTickerColumns() { $args = array(':pair' => get_currency_abbr($this->currency1) . "/" . get_currency_abbr($this->currency2)); $columns = array(); if ($this->onlyhasLastTrade()) { // hack fix because TheMoneyConverter and Coinbase only have last_trade $columns[] = array('type' => 'number', 'title' => ct(":pair"), 'args' => $args); } else { $columns[] = array('type' => 'number', 'title' => ct(":pair Bid"), 'args' => $args); $columns[] = array('type' => 'number', 'title' => ct(":pair Ask"), 'args' => $args); } return $columns; }
function getJSON($arguments) { // important for url_for() links define('FORCE_NO_RELATIVE', true); $result = array(); $result['currencies'] = array(); foreach (get_all_currencies() as $cur) { $result['currencies'][] = array('code' => $cur, 'abbr' => get_currency_abbr($cur), 'name' => get_currency_name($cur), 'fiat' => is_fiat_currency($cur)); } require __DIR__ . "/../../inc/api.php"; $result['rates'] = api_get_all_rates(); return $result; }
public function getData($days) { $columns = array(); $key_column = array('type' => 'string', 'title' => ct("Key")); $columns[] = array('type' => 'string', 'title' => ct("Title"), 'heading' => true); $columns[] = array('type' => 'string align-right', 'title' => ct("Total")); $columns[] = array('type' => 'string align-right', 'title' => ct("Last week")); $columns[] = array('type' => 'string align-right', 'title' => ct("Last day")); $columns[] = array('type' => 'string align-right', 'title' => ct("Last hour")); $last_updated = time(); $summary = array('user_properties' => array('title' => ct('Users'), 'extra' => array('is_disabled=1' => ct('Disabled'))), 'addresses' => array('title' => ct('Addresses')), 'jobs' => array('title' => ct('Jobs'), 'extra' => array('is_executed=0' => ct('Pending'))), 'outstanding_premiums' => array('title' => ct('Premiums'), 'extra' => array('is_paid=1' => ct('Paid'))), 'uncaught_exceptions' => array('title' => ct('Uncaught exceptions')), 'ticker' => array('title' => ct('Ticker instances'))); $result = array(); foreach ($summary as $key => $data) { $row = array(); $row[0] = $data['title']; if (isset($data['extra'])) { foreach ($data['extra'] as $extra_key => $extra_title) { $row[0] .= " ({$extra_title})"; } } $parts = array('1', 'created_at >= date_sub(now(), interval 7 day)', 'created_at >= date_sub(now(), interval 1 day)', 'created_at >= date_sub(now(), interval 1 hour)'); foreach ($parts as $query) { $q = db()->prepare("SELECT COUNT(*) AS c FROM {$key} WHERE {$query}"); $q->execute(); $c = $q->fetch(); $row[] = number_format($c['c']); if (isset($data['extra'])) { foreach ($data['extra'] as $extra_key => $extra_title) { $q = db()->prepare("SELECT COUNT(*) AS c FROM {$key} WHERE {$query} AND {$extra_key}"); $q->execute(); $c = $q->fetch(); $row[count($row) - 1] .= " (" . number_format($c['c']) . ")"; } } } $result[$key] = $row; } $row = array(ct("Unused premium addresses")); $q = db()->prepare("SELECT currency, COUNT(*) AS c FROM premium_addresses WHERE is_used=0 GROUP BY currency"); $q->execute(); while ($c = $q->fetch()) { $row[] = number_format($c['c']) . " (" . get_currency_abbr($c['currency']) . ")"; } $result['unused_premium_addresses'] = $row; return array('key' => $key_column, 'columns' => $columns, 'data' => $result, 'last_updated' => $last_updated); }
/** * We need to transpose the returned data, both data and columns. */ public function getData($days) { $original = parent::getData($days); $columns = array(); $columns[] = array('type' => 'string', 'title' => ct("Total :currency"), 'args' => array(':currency' => get_currency_abbr($this->currency)), 'heading' => true); $data = array(); $total = 0; foreach ($original['data'] as $key => $row) { foreach ($row as $i => $value) { $data[] = array($original['columns'][$i]['title'], currency_format($this->currency, $value, 4)); $total += $value; } } // 'Total BTC' column $columns[] = array('type' => 'string', 'title' => currency_format($this->currency, $total, 4)); // save for later $this->total = $total; return array('key' => $original['key'], 'columns' => $columns, 'data' => $data, 'last_updated' => $original['last_updated']); }
public function getData($days) { $key_column = array('type' => 'string', 'title' => ct("Currency")); $columns = array(); // get all balances $balances = get_all_summary_instances($this->getUser()); $last_updated = find_latest_created_at($balances, "total"); // and convert them using the most recent rates $rates = get_all_recent_rates(); // create data // TODO refactor this into generic any-currency balances $data = array(); if (isset($balances['totalbtc']) && $balances['totalbtc']['balance'] != 0) { $columns[] = array('type' => 'number', 'title' => get_currency_abbr('btc')); $data[] = graph_number_format(demo_scale($balances['totalbtc']['balance'])); } foreach (get_all_currencies() as $cur) { // if the key is a currency, use the same currency colour across all graphs (#293) $color = array_search($cur, get_all_currencies()); if ($cur == 'btc') { continue; } if (!is_fiat_currency($cur) && isset($balances['total' . $cur]) && $balances['total' . $cur]['balance'] != 0 && isset($rates['btc' . $cur])) { $columns[] = array('type' => 'number', 'title' => get_currency_abbr($cur), 'color' => $color); $data[] = graph_number_format(demo_scale($balances['total' . $cur]['balance'] * $rates['btc' . $cur]['bid'])); } if (is_fiat_currency($cur) && isset($balances['total' . $cur]) && $balances['total' . $cur]['balance'] != 0 && isset($rates[$cur . 'btc']) && $rates[$cur . 'btc']['ask']) { $columns[] = array('type' => 'number', 'title' => get_currency_abbr($cur), 'color' => $color); $data[] = graph_number_format(demo_scale($balances['total' . $cur]['balance'] / $rates[$cur . 'btc']['ask'])); } } // display a helpful message if there's no data if (!$data) { throw new NoDataGraphException_AddAccountsAddresses(); } // sort data by balance arsort($data); $data = array(get_currency_abbr('btc') => $data); return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated); }
public function getData($days) { $key_column = array('type' => 'string', 'title' => ct("Currency")); $columns = array(); $columns[] = array('type' => 'string', 'title' => ct("Currency"), 'heading' => true); $columns[] = array('type' => 'string', 'title' => ct("Total")); // a table of each currency // get all balances $balances = get_all_summary_instances($this->getUser()); $summaries = get_all_summary_currencies($this->getUser()); $currencies = get_all_currencies(); $last_updated = find_latest_created_at($balances, "total"); // create data $data = array(); foreach ($currencies as $c) { if (isset($summaries[$c])) { $balance = isset($balances['total' . $c]) ? $balances['total' . $c]['balance'] : 0; $data[] = array("<span title=\"" . htmlspecialchars(get_currency_name($c)) . "\">" . get_currency_abbr($c) . "</span>", currency_format($c, demo_scale($balance), 4)); } } return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated, 'add_more_currencies' => true, 'no_header' => true); }
public function getData($days) { $columns = array(); $key_column = array('type' => 'string', 'title' => ct("Key")); $columns[] = array('type' => 'string', 'title' => ct("Exchange"), 'heading' => true); $columns[] = array('type' => 'string', 'title' => ct("Price")); $columns[] = array('type' => 'string', 'title' => ct("Volume")); $q = db()->prepare("SELECT * FROM ticker_recent WHERE currency1=? AND currency2=? ORDER BY volume DESC"); $q->execute(array($this->currency1, $this->currency2)); $tickers = $q->fetchAll(); $q = db()->prepare("SELECT * FROM average_market_count WHERE currency1=? AND currency2=?"); $q->execute(array($this->currency1, $this->currency2)); $market_count = $q->fetch(); $average = false; foreach ($tickers as $ticker) { if ($ticker['exchange'] == 'average') { $average = $ticker; } } if (!$average) { throw new RenderGraphException(t("Could not find any average data")); } $volume_currency = $average['currency2']; // generate the table of data $data = array(); foreach ($tickers as $ticker) { if ($ticker['exchange'] == "average") { continue; } if ($ticker['volume'] == 0) { continue; } $id = $ticker['exchange'] . "_" . $ticker['currency1'] . $ticker['currency2'] . "_daily"; $data[$ticker['exchange']] = array("<a href=\"" . htmlspecialchars(url_for('historical', array('id' => $id, 'days' => 180))) . "\">" . get_exchange_name($ticker['exchange']) . "</a>", $this->average_currency_format_html($ticker['last_trade'], $ticker['last_trade']), currency_format($volume_currency, $ticker['volume'], 0) . " (" . ($average['volume'] == 0 ? "-" : number_format($ticker['volume'] * 100 / $average['volume']) . "%") . ")"); } $last_updated = $average['created_at']; return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated, 'h1' => get_currency_abbr($average['currency1']) . "/" . get_currency_abbr($average['currency2']) . ": " . currency_format($average['currency1'], $average['last_trade']), 'h2' => "(" . number_format($average['volume']) . " " . get_currency_abbr($volume_currency) . " total volume)"); }
/** * @return an array of columns e.g. (type, title, args) */ function getTickerColumns() { $columns = array(); $columns[] = array('type' => 'number', 'title' => get_currency_abbr($this->currency)); return $columns; }
echo "<th>" . htmlspecialchars(date('M y', strtotime($m['start']))) . "</th>"; } ?> <th>Total</th> </tr> </thead> <tbody> <?php $queries = array("New users" => array('query' => "SELECT COUNT(*) AS c FROM user_properties WHERE created_at >= :start AND created_at <= :end", 'callback' => 'number_format'), "Total users" => array('query' => "SELECT COUNT(*) AS c FROM user_properties WHERE created_at <= :end AND :start = :start", 'callback' => 'number_format'), "Disabled users" => array('query' => "SELECT disabled_users AS c FROM site_statistics WHERE created_at >= :start AND created_at <= :end LIMIT 1", 'callback' => 'number_format'), "Total disabled users" => array('query' => "SELECT COUNT(*) AS c FROM user_properties WHERE disabled_at <= :end AND :start = :start AND is_disabled=1", 'callback' => 'number_format'), "Premium users" => array('query' => "SELECT premium_users AS c FROM site_statistics WHERE created_at >= :start AND created_at <= :end LIMIT 1", 'callback' => 'number_format'), "Current Premium users" => array('query' => "SELECT COUNT(*) AS c FROM user_properties WHERE created_at <= :end AND :start = :start AND is_premium=1", 'callback' => 'number_format'), "Completed premiums" => array('query' => "SELECT COUNT(*) AS c FROM outstanding_premiums WHERE is_paid=1 AND (created_at >= :start AND created_at <= :end)", 'callback' => 'number_format')); foreach (get_site_config('premium_currencies') as $cur) { $queries["Income (" . get_currency_abbr($cur) . ")"] = array('query' => "SELECT IFNULL(SUM(paid_balance), 0) AS c FROM outstanding_premiums\n JOIN premium_addresses ON outstanding_premiums.premium_address_id=premium_addresses.id\n WHERE is_paid=1 AND (outstanding_premiums.created_at >= :start AND outstanding_premiums.created_at <= :end) AND currency='" . $cur . "'", 'callback' => 'number_format_autoprecision'); } if (get_site_config('taxable_countries')) { $list = "('" . implode("', '", get_site_config('taxable_countries')) . "')"; foreach (get_site_config('premium_currencies') as $cur) { $queries["Taxable income (" . get_currency_abbr($cur) . ")"] = array('query' => "SELECT IFNULL(SUM(paid_balance), 0) AS c FROM outstanding_premiums\n JOIN premium_addresses ON outstanding_premiums.premium_address_id=premium_addresses.id\n LEFT JOIN user_properties ON outstanding_premiums.user_id = user_properties.id\n WHERE is_paid=1 AND (outstanding_premiums.created_at >= :start AND outstanding_premiums.created_at <= :end) AND currency='" . $cur . "' AND user_properties.country IN {$list}", 'callback' => 'number_format_autoprecision'); } } foreach ($queries as $query_title => $query) { echo "<tr>\n"; echo "<th>" . htmlspecialchars($query_title) . "</th>\n"; foreach ($months as $m) { $q = db()->prepare($query['query']); $q->execute(array('start' => $m['start'], 'end' => $m['end'])); $result = $q->fetch(); echo "<td class=\"number\">" . $query['callback']($result['c']) . "</td>"; } // total $q = db()->prepare($query['query']); $q->execute(array('start' => '2001-01-01', 'end' => '2049-01-01')); $result = $q->fetch();
/** * Get all of the defined graph types. Used for display and validation. */ function graph_types() { $total_fiat_currencies = array(); foreach (get_total_conversion_summary_types() as $c) { $total_fiat_currencies[] = $c['title']; } $total_fiat_currencies = implode_english($total_fiat_currencies); $data = array('category_general' => array('title' => t('General'), 'category' => true), 'subcategory_general' => array('title' => t('General graphs'), 'subcategory' => true), 'btc_equivalent' => array('title' => t('Equivalent BTC balances (pie)'), 'heading' => t('Equivalent BTC'), 'description' => t('A pie chart representing the overall proportional value of all currencies if they were all converted into BTC.') . '<p>' . t('Exchanges used:') . ' ' . get_default_exchange_text(array_diff(get_all_currencies(), array('btc'))) . '.', 'default_width' => get_site_config('default_user_graph_height'), 'uses_summaries' => true), 'btc_equivalent_graph' => array('title' => t('Equivalent BTC balances (graph)'), 'heading' => t('Equivalent BTC'), 'description' => t('A line graph displaying the historical value of all currencies if they were all converted into BTC.') . '<p>' . t('Exchanges used:') . ' ' . get_default_exchange_text(array_diff(get_all_currencies(), array('btc'))) . '.', 'days' => true, 'uses_summaries' => true), 'btc_equivalent_stacked' => array('title' => t('Equivalent BTC balances (stacked)'), 'heading' => t('Equivalent BTC'), 'description' => t('A stacked area graph displaying the historical value of all currencies if they were all converted into BTC.') . '<p>' . t('Exchanges used:') . ' ' . get_default_exchange_text(array_diff(get_all_currencies(), array('btc'))) . '.', 'days' => true, 'uses_summaries' => true), 'btc_equivalent_proportional' => array('title' => t('Equivalent BTC balances (proportional)'), 'heading' => t('Equivalent BTC'), 'description' => t('A stacked area graph displaying the proportional historical value of all currencies if they were all converted into BTC.') . '<p>' . t('Exchanges used:') . ' ' . get_default_exchange_text(array_diff(get_all_currencies(), array('btc'))) . '.', 'days' => true, 'uses_summaries' => true), 'ticker_matrix' => array('title' => t('All currencies exchange rates (matrix)'), 'heading' => t('All exchanges'), 'description' => t('A matrix displaying the current bid/ask of all of the currencies and exchanges :interested_in.', array(':interested_in' => link_to(url_for('wizard_currencies'), t('you are interested in'))))), 'balances_table' => array('title' => t('Total balances (table)'), 'heading' => t('Total balances'), 'description' => t('A table displaying the current sum of all your currencies (before any conversions).'), 'default_width' => get_site_config('default_user_graph_height'), 'uses_summaries' => true), 'total_converted_table' => array('title' => t('Total converted fiat balances (table)'), 'heading' => t('Converted fiat'), 'description' => t('A table displaying the equivalent value of all cryptocurrencies and fiat currencies if they were immediately converted into fiat currencies. Cryptocurrencies are converted via BTC.') . '<p>' . t('Supports :currencies.', array(':currencies' => $total_fiat_currencies)) . '<p>' . t('Exchanges used:') . ' ' . get_default_exchange_text(array_diff(get_all_currencies(), array('btc'))) . '.', 'default_width' => get_site_config('default_user_graph_height'), 'uses_summaries' => true), 'crypto_converted_table' => array('title' => t('Total converted crypto balances (table)'), 'heading' => t('Converted crypto'), 'description' => t('A table displaying the equivalent value of all cryptocurrencies - but not fiat currencies - if they were immediately converted into other cryptocurrencies.') . '<p>' . t('Exchanges used:') . ' ' . get_default_exchange_text(array_diff(get_all_cryptocurrencies(), array('btc'))) . '.', 'default_width' => get_site_config('default_user_graph_height'), 'uses_summaries' => true), 'balances_offset_table' => array('title' => t('Total balances with offsets (table)'), 'heading' => t('Total balances'), 'description' => t('A table displaying the current sum of all currencies (before any conversions), along with the current total offset values of each currency.'), 'uses_summaries' => true)); $summaries = array(); $conversions = array(); if (user_logged_in()) { $summaries = get_all_summary_currencies(); $conversions = get_all_conversion_currencies(); } $data['category_summaries'] = array('title' => t('Your summaries'), 'category' => true); $data['subcategory_summaries_total'] = array('title' => t('Historical currency value'), 'subcategory' => true); // we can generate a list of summary daily graphs from all the currencies that we support foreach (get_summary_types() as $key => $summary) { $cur = $summary['currency']; $data["total_" . $cur . "_daily"] = array('title' => t("Total :currency historical (graph)", array(':currency' => get_currency_name($cur))), 'heading' => t("Total :currency", array(':currency' => get_currency_abbr($cur))), 'description' => t("A line graph displaying the historical sum of your :currency (before any conversions).", array(':currency' => get_currency_name($cur))), 'hide' => !isset($summaries[$cur]), 'days' => true, 'delta' => true, 'technical' => true, 'uses_summaries' => true); } $data['subcategory_summaries_crypto2'] = array('title' => t('Historical converted value'), 'subcategory' => true); foreach (get_crypto_conversion_summary_types() as $key => $summary) { $cur = $summary['currency']; $data["crypto2" . $key . "_daily"] = array('title' => t("Converted :title historical (graph)", array(':title' => $summary['title'])), 'heading' => t("Converted :title", array(':title' => $summary['short_title'])), 'description' => t("A line graph displaying the historical equivalent value of all cryptocurrencies - and not other fiat currencies - if they were immediately converted to :title.", array(':title' => $summary['title'])), 'hide' => !isset($conversions['summary_' . $key]), 'days' => true, 'delta' => true, 'technical' => true, 'uses_summaries' => true); } /* * Issue #112 reported that 'all2CUR' was not correctly converting fiat currencies other than CUR. * Rather than renaming 'all2CUR' as 'all cryptocurrencies and CUR', which doesn't seem to be particularly useful * - and it will mean we'll have to track two new summaries for every currency - * as of 0.19 this will now correctly be calculated as 'all cryptocurrencies and fiat currencies'. This means that there * will be a jump in the value of data when deployed. */ foreach (get_total_conversion_summary_types() as $key => $summary) { $cur = $summary['currency']; $data["all2" . $key . "_daily"] = array('title' => t("Converted :title historical (graph)", array(':title' => $summary['title'])), 'heading' => t("Converted :title", array(':title' => $summary['short_title'])), 'description' => t("A line graph displaying the historical equivalent value of all cryptocurrencies and fiat currencies if they were immediately converted to :title (where possible).", array(':title' => $summary['title'])), 'hide' => !isset($conversions['summary_' . $key]), 'days' => true, 'delta' => true, 'technical' => true, 'uses_summaries' => true); } $data['subcategory_summaries_composition'] = array('title' => t('Total balance composition'), 'subcategory' => true); // we can generate a list of composition graphs from all of the currencies that we support foreach (get_all_currencies() as $currency) { $data["composition_" . $currency . "_pie"] = array('title' => t("Total :currency balance composition (pie)", array(':currency' => get_currency_name($currency))), 'heading' => t("Total :currency", array(':currency' => get_currency_abbr($currency))), 'description' => t("A pie chart representing all of the sources of your total :currency balance (before any conversions).", array(':currency' => get_currency_name($currency))), 'hide' => !isset($summaries[$currency]), 'default_width' => get_site_config('default_user_graph_height'), 'uses_summaries' => true); } $data['subcategory_summaries_graph'] = array('title' => t('All balances (graph)'), 'subcategory' => true); foreach (get_all_currencies() as $currency) { $data["composition_" . $currency . "_daily"] = array('title' => t("All :currency balances (graph)", array(':currency' => get_currency_name($currency))), 'heading' => t("All :currency balances", array(':currency' => get_currency_abbr($currency))), 'description' => t("A line graph representing all of the sources of your total :currency balance (before any conversions).", array(':currency' => get_currency_name($currency))), 'days' => true, 'hide' => !isset($summaries[$currency]), 'uses_summaries' => true); } $data['subcategory_summaries_table'] = array('title' => t('All balances (table)'), 'subcategory' => true); foreach (get_all_currencies() as $currency) { $data["composition_" . $currency . "_table"] = array('title' => t("Your :currency balances (table)", array(':currency' => get_currency_name($currency))), 'heading' => t("Your :currency balances", array(':currency' => get_currency_abbr($currency))), 'description' => t("A table displaying all of your :currency balances and the total balance (before any conversions).", array(':currency' => get_currency_name($currency))), 'hide' => !isset($summaries[$currency]), 'uses_summaries' => true); } $data['subcategory_summaries_stacked'] = array('title' => t('All balances (stacked)'), 'subcategory' => true); foreach (get_all_currencies() as $currency) { $data["composition_" . $currency . "_stacked"] = array('title' => t("All :currency balances (stacked)", array(':currency' => get_currency_name($currency))), 'heading' => t("All :currency balances", array(':currency' => get_currency_abbr($currency))), 'description' => t("A stacked area graph displaying the historical value of your total :currency balance (before any conversions).", array(':currency' => get_currency_name($currency))), 'days' => true, 'hide' => !isset($summaries[$currency]), 'uses_summaries' => true); } $data['subcategory_summaries_proportional'] = array('title' => t('All balances (proportional)'), 'subcategory' => true); foreach (get_all_currencies() as $currency) { $data["composition_" . $currency . "_proportional"] = array('title' => t("All :currency balances (proportional)", array(':currency' => get_currency_name($currency))), 'heading' => t("All :currency balances", array(':currency' => get_currency_abbr($currency))), 'description' => t("A stacked area graph displaying the proportional historical value of your total :currency balance (before any conversions).", array(':currency' => get_currency_name($currency))), 'days' => true, 'hide' => !isset($summaries[$currency]), 'uses_summaries' => true); } $data['category_hashrate'] = array('title' => t('Your mining'), 'category' => true); $data['category_hashrate_hashrate'] = array('title' => t('Historical hashrates'), 'subcategory' => true); // and for each cryptocurrency that can be hashed foreach (get_all_hashrate_currencies() as $cur) { $data["hashrate_" . $cur . "_daily"] = array('title' => t(":currency historical MHash/s (graph)", array(':currency' => get_currency_name($cur))), 'heading' => t(":currency MHash/s", array(':currency' => get_currency_abbr($cur))), 'description' => t("A line graph displaying the historical hashrate sum of all workers mining :currency across all mining pools (in MHash/s).", array(':currency' => get_currency_name($cur))), 'hide' => !isset($summaries[$cur]), 'days' => true, 'delta' => true, 'technical' => true, 'uses_summaries' => true); } // merge in graph_types_public() here foreach (graph_types_public($summaries) as $key => $public_data) { // but add 'hide' parameter to hide irrelevant currencies if (isset($public_data['pairs'])) { $pairs = $public_data['pairs']; $public_data['hide'] = !(isset($summaries[$pairs[0]]) && isset($summaries[$pairs[1]])); } $data[$key] = $public_data; } $data['subcategory_layout'] = array('title' => t('Layout tools'), 'subcategory' => true); $data['linebreak'] = array('title' => t('Line break'), 'description' => t('Forces a line break at a particular location. Select \'Enable layout editing\' to move it.'), 'heading' => t('Line break')); $data['heading'] = array('title' => t('Heading'), 'description' => t("Displays a line of text as a heading at a particular location. Also functions as a line break. Select 'Enable layout editing' to move it.'"), 'string0' => t("Example heading"), 'heading' => t('Heading')); // add sample images $images = array('btc_equivalent' => 'btc_equivalent.png', 'composition_btc_pie' => 'composition_btc_pie.png', 'composition_ltc_pie' => 'composition_ltc_pie.png', 'composition_nmc_pie' => 'composition_nmc_pie.png', 'btce_btcnmc_daily' => 'btce_btcnmc_daily.png', 'btce_btcftc_daily' => 'btce_btcftc_daily.png', 'btce_btcltc_daily' => 'btce_btcltc_daily.png', 'bitstamp_usdbtc_daily' => 'bitstamp_usdbtc_daily.png', 'bitnz_nzdbtc_daily' => 'bitnz_nzdbtc_daily.png', 'btcchina_cnybtc_daily' => 'btcchina_cnybtc_daily.png', 'cexio_btcghs_daily' => 'cexio_btcghs_daily.png', 'vircurex_btcltc_daily' => 'vircurex_btcltc_daily.png', 'vircurex_btcdog_daily' => 'vircurex_btcdog_daily.png', 'themoneyconverter_usdeur_daily' => 'themoneyconverter_usdeur_daily.png', 'themoneyconverter_usdaud_daily' => 'themoneyconverter_usdaud_daily.png', 'themoneyconverter_usdcad_daily' => 'themoneyconverter_usdcad_daily.png', 'themoneyconverter_usdnzd_daily' => 'themoneyconverter_usdnzd_daily.png', 'crypto2btc_daily' => 'crypto2btc_daily.png', 'crypto2ltc_daily' => 'crypto2ltc_daily.png', 'crypto2nmc_daily' => 'crypto2nmc_daily.png', 'crypto2dog_daily' => 'crypto2dog_daily.png', 'all2nzd_bitnz_daily' => 'all2nzd_bitnz_daily.png', 'all2cad_virtex_daily' => 'all2cad_virtex_daily.png', 'all2usd_bitstamp_daily' => 'all2usd_bitstamp_daily.png', 'all2usd_btce_daily' => 'all2usd_btce_daily.png', 'btc_equivalent_graph' => 'btc_equivalent_graph.png', 'btc_equivalent_proportional' => 'btc_equivalent_proportional.png', 'btc_equivalent_stacked' => 'btc_equivalent_stacked.png', 'total_btc_daily' => 'total_btc_daily.png', 'total_ltc_daily' => 'total_ltc_daily.png', 'total_nmc_daily' => 'total_nmc_daily.png', 'total_ghs_daily' => 'total_ghs_daily.png', 'hashrate_ltc_daily' => 'hashrate_ltc_daily.png', 'balances_table' => 'balances_table.png', 'balances_offset_table' => 'balances_offset_table.png', 'crypto_converted_table' => 'crypto_converted_table.png', 'total_converted_table' => 'total_converted_table.png', 'composition_btc_daily' => 'composition_btc_daily.png', 'composition_ltc_daily' => 'composition_ltc_daily.png', 'composition_nmc_daily' => 'composition_ltc_daily.png', 'composition_ftc_daily' => 'composition_ltc_daily.png', 'composition_ppc_daily' => 'composition_ltc_daily.png', 'composition_nvc_daily' => 'composition_ltc_daily.png', 'composition_dog_daily' => 'composition_dog_daily.png', 'composition_btc_table' => 'composition_btc_table.png', 'composition_ltc_table' => 'composition_ltc_table.png', 'composition_nmc_table' => 'composition_nmc_table.png', 'composition_ftc_table' => 'composition_ltc_table.png', 'composition_ppc_table' => 'composition_ltc_table.png', 'composition_nvc_table' => 'composition_ltc_table.png', 'composition_dog_table' => 'composition_dog_table.png', 'composition_btc_proportional' => 'composition_btc_proportional.png', 'composition_ltc_proportional' => 'composition_ltc_proportional.png', 'composition_nmc_proportional' => 'composition_nmc_proportional.png', 'composition_ftc_proportional' => 'composition_ltc_proportional.png', 'composition_ppc_proportional' => 'composition_ltc_proportional.png', 'composition_nvc_proportional' => 'composition_ltc_proportional.png', 'composition_btc_stacked' => 'composition_btc_stacked.png', 'composition_ltc_stacked' => 'composition_ltc_stacked.png', 'composition_nmc_stacked' => 'composition_ltc_stacked.png', 'composition_ftc_stacked' => 'composition_ltc_stacked.png', 'composition_ppc_stacked' => 'composition_ltc_stacked.png', 'composition_nvc_stacked' => 'composition_ltc_stacked.png', 'composition_ghs_stacked' => 'composition_ghs_stacked.png', 'average_usdbtc_daily' => 'average_usdbtc_daily.png', 'average_usdbtc_markets' => 'average_usdbtc_markets.png', 'average_cadbtc_daily' => 'average_cadbtc_daily.png', 'average_cadbtc_markets' => 'average_cadbtc_markets.png', 'average_audbtc_daily' => 'average_audbtc_daily.png', 'average_audbtc_markets' => 'average_audbtc_markets.png', 'average_nzdbtc_daily' => 'average_nzdbtc_daily.png', 'average_nzdbtc_markets' => 'average_nzdbtc_markets.png', 'average_btcdog_daily' => 'average_btcdog_daily.png', 'average_btcdog_markets' => 'average_btcdog_markets.png', 'average_btcltc_daily' => 'average_btcltc_daily.png', 'average_btcltc_markets' => 'average_btcltc_markets.png', 'ticker_matrix' => 'ticker_matrix.png', 'calculator' => 'calculator.png'); $data = add_example_images($data, $images); return $data; }
public function getData($days) { $key_column = array('type' => 'string', 'title' => ct("Currency")); $columns = array(); // get data // TODO could probably cache this $q = db()->prepare("SELECT SUM(balance) AS balance, exchange, MAX(created_at) AS created_at FROM balances WHERE user_id=? AND is_recent=1 AND currency=? GROUP BY exchange"); $q->execute(array($this->getUser(), $this->currency)); $balances = $q->fetchAll(); // need to also get address balances $summary_balances = get_all_summary_instances($this->getUser()); // get additional balances $data = array(); if (isset($summary_balances['blockchain' . $this->currency]) && $summary_balances['blockchain' . $this->currency]['balance'] != 0) { $balances[] = array("balance" => $summary_balances['blockchain' . $this->currency]['balance'], "exchange" => "blockchain", "created_at" => $summary_balances['blockchain' . $this->currency]['created_at']); } if (isset($summary_balances['offsets' . $this->currency]) && $summary_balances['offsets' . $this->currency]['balance'] != 0) { $balances[] = array("balance" => $summary_balances['offsets' . $this->currency]['balance'], "exchange" => "offsets", "created_at" => $summary_balances['offsets' . $this->currency]['created_at']); } // sort by balance usort($balances, array($this, 'sort_by_balance_desc')); $last_updated = find_latest_created_at($balances); // apply demo_scale and calculate total summary $data = array(); $total = 0; foreach ($balances as $b) { if ($b['balance'] != 0) { $columns[] = array('type' => 'number', 'title' => get_exchange_name($b['exchange'])); $data[] = demo_scale($b['balance']); $total += demo_scale($b['balance']); } } // return a more helpful message if there is no data if (!$data) { throw new NoDataGraphException_AddAccountsAddresses(); } // sort data by balance $data = array(get_currency_abbr($this->currency) => $data); return array('key' => $key_column, 'columns' => $columns, 'data' => $data, 'last_updated' => $last_updated); }
/** * Just returns an array of ('ltc' => 'LTC', 'btc' => 'BTC', ...) */ function dropdown_currency_list() { $result = array(); foreach (get_all_currencies() as $c) { $result[$c] = get_currency_abbr($c); } return $result; }
require __DIR__ . "/../layout/templates.php"; $messages = array(); $errors = array(); page_header("Admin: Show Explorers", "page_admin_show_explorers"); ?> <h1>Currency Explorers</h1> <p class="backlink"><a href="<?php echo htmlspecialchars(url_for('admin')); ?> ">< Back to Site Status</a></p> <ul> <?php $grouped = account_data_grouped(); $external = get_external_apis(); foreach ($grouped['Addresses'] as $key => $data) { echo "<li><span style=\"display: inline-block; min-width: 250px;\">"; echo get_currency_abbr($data['currency']); echo " using " . $external['Address balances'][$key]; echo " using " . $external['Address balances'][$key]['link']; echo ":</span> "; echo crypto_address($data['currency'], 'example'); echo "</li>"; } ?> </ul> <?php page_footer();
if ($user['email']) { $args = array("name" => $user['name'] ? $user['name'] : $user['email'], "url" => absolute_url(url_for('wizard_notifications')), "profile" => absolute_url(url_for('profile')), "last_value" => number_format_human($notification['last_value']), "current_value" => number_format_human($current_value), "value_label" => $value_label, "value_delta" => number_format_human($value_delta), "percent" => $percent === null ? "infinite%" : number_format_human($percent * 100, -1), "change_text" => $change_text, "period" => $notification['period']); switch ($notification['notification_type']) { case "ticker": $email_template = 'notification_ticker'; $args += array("exchange" => get_exchange_name($account['exchange']), "currency1" => get_currency_abbr($account['currency1']), "currency2" => get_currency_abbr($account['currency2'])); break; case "summary_instance": $email_template = 'notification_summary_instance'; if (substr($account['summary_type'], 0, strlen('totalmh_')) == 'totalmh_') { $currency = substr($account['summary_type'], strlen('totalmh_')); $args += array("label" => "total " . get_currency_abbr($currency) . " hashrate"); } else { if (substr($account['summary_type'], 0, strlen('total')) == 'total') { $currency = substr($account['summary_type'], strlen('total')); $args += array("label" => "total " . get_currency_abbr($currency)); } else { if (substr($account['summary_type'], 0, strlen('all2')) == 'all2') { $summary_type = substr($account['summary_type'], strlen('all2')); $summary_types = get_total_conversion_summary_types(); $args += array("label" => "converted " . $summary_types[$summary_type]['short_title']); } else { throw new JobException("Unknown summary_instance summary_type '" . htmlspecialchars($account['summary_type']) . "'"); } } } $args['label_uc'] = capitalize($args['label']); break; default: throw new JobException("Unknown notification type for email '" . $notification['notification_type'] . "'"); }
} ?> </select> </li> <li><?php echo t("My preferred fiat currency:"); ?> <select name="preferred_fiat"> <?php foreach (get_all_currencies() as $c) { if (in_array($c, get_all_cryptocurrencies())) { continue; } if (isset($summaries[$c])) { echo "<option value=\"" . htmlspecialchars($c) . "\"\n class=\"currency_name_" . htmlspecialchars($c) . "\"" . ($user['preferred_fiat'] == $c ? " selected" : "") . ">" . get_currency_abbr($c) . "</option>\n"; } } ?> </select> </li> </ul> <?php function print_graph_types($managed, $is_auto = false) { global $graphs, $user; ?> <a class="collapse-link collapsed report-help">?</a> <div class="collapse-target report-help-details">
/** * e.g. {@link #get_exchange_name()} */ function getHeadingTitle($key, $args) { return get_currency_abbr($key); }
} // e.g. NMC to BTC if (isset($totals[$c])) { if ($ticker = get_latest_ticker(get_default_currency_exchange($c), "btc", $c)) { $temp = $totals[$c] * ($ticker['ask'] ? $ticker['ask'] : $ticker['last_trade']); crypto_log("+ from " . get_currency_abbr($c) . " (BTC): " . $temp); // and then BTC to CUR if ($ticker = get_latest_ticker(get_default_currency_exchange($currency), "btc", $currency)) { $temp2 = $temp / ($ticker['bid'] ? $ticker['bid'] : $ticker['last_trade']); crypto_log("+ from " . get_currency_abbr($c) . " (" . get_currency_abbr($currency) . "): " . $temp2); $total += $temp2; } } } } crypto_log("Total converted " . get_currency_abbr($currency) . " balance for user " . $job['user_id'] . ": " . $total); add_summary_instance($job, 'crypto2' . $currency, $total); } } crypto_log("</ul>"); } // update last_sum_job $q = db()->prepare("UPDATE user_properties SET last_sum_job=NOW() WHERE id=?"); $q->execute(array($job['user_id'])); // and now that we have added summary instances, check for first_report // (this is so that first_report jobs don't block up the job queue) /** * Send an e-mail to new users once their first non-zero summary reports have been compiled. */ // reload user in case multiple summary jobs for the same user are all blocked at once $user = get_user($job['user_id']);
<table class="fancy standard"> <thead> <tr> <th>Code</th> <th>Title</th> <th>Votes</th> <th>Users</th> <th></th> </tr> </thead> <tbody> <?php $abbrs = array(); foreach (get_all_currencies() as $cur) { $abbrs[] = get_currency_abbr($cur); } $q = db()->prepare("SELECT * FROM vote_coins WHERE total_votes > 0 ORDER BY code ASC"); $q->execute(); while ($vote = $q->fetch()) { if (in_array(strtolower($vote['code']), get_all_currencies()) || in_array($vote['code'], $abbrs)) { ?> <tr> <td><?php echo htmlspecialchars($vote['code']); ?> </td> <td><?php echo htmlspecialchars($vote['title']); ?> </td>
</select> </span> <span class="row"> <span class="equals">=</span> </span> <span class="row"> <input type="text" id="value2" value="<?php echo htmlspecialchars($value2); ?> "> <select id="currency2"> <?php foreach (get_all_currencies() as $cur) { echo "<option value=\"" . htmlspecialchars($cur) . "\" class=\"currency_name_" . htmlspecialchars($cur) . "\"" . ($cur == $currency2 ? " selected" : "") . ">" . get_currency_abbr($cur) . "</option>\n"; } ?> </select> </span> <div class="using"><?php echo t("Using :exchange", array(':exchange' => '<span id="exchange_text">' . t("no exchange") . '</span>')); ?> </div> </div> <script type="text/javascript"> function get_all_rates() { return <?php require_once __DIR__ . "/../inc/api.php";
public function getTitleArgs() { return array(':exchange' => get_exchange_name($this->exchange), ':pair' => get_currency_abbr($this->currency1) . "/" . get_currency_abbr($this->currency2)); }
public function getTitleArgs() { return array(':currency' => get_currency_abbr($this->currency)); }
$periods = get_permitted_notification_periods(); if (!isset($periods[$notification['period']]['interval'])) { throw new JobException("Unknown job period '" . $notification['period'] . "'"); } $period = $periods[$notification['period']]['interval']; $q = db()->prepare("SELECT * FROM summary_instances WHERE user_id=:user_id AND summary_type=:summary_type AND created_at <= DATE_SUB(NOW(), {$period}) ORDER BY id DESC LIMIT 1"); $q->execute(array("user_id" => $notification['user_id'], "summary_type" => $account['summary_type'])); $last = $q->fetch(); if (!$last) { throw new JobException("Could not find any last values for " . $account['summary_type'] . " for user " . $notification['user_id']); } $notification['last_value'] = $last['balance']; } // other parameters if (substr($account['summary_type'], 0, strlen('totalmh_')) == 'totalmh_') { $currency = substr($account['summary_type'], strlen('totalmh_')); $value_label = "MH/s"; } else { if (substr($account['summary_type'], 0, strlen('total')) == 'total') { $currency = substr($account['summary_type'], strlen('total')); $value_label = get_currency_abbr($currency); } else { if (substr($account['summary_type'], 0, strlen('all2')) == 'all2') { $summary_type = substr($account['summary_type'], strlen('all2')); $summary_types = get_total_conversion_summary_types(); $value_label = get_currency_abbr($summary_types[$summary_type]['currency']); } else { throw new JobException("Unknown summary_instance summary_type '" . htmlspecialchars($account['summary_type']) . "'"); } } }
public function getData($days) { $key_column = array('type' => 'string', 'title' => ct("Currency")); $columns = array(); $last_updated = false; $columns[] = array('type' => 'string', 'title' => "", 'heading' => true); // a matrix table of each currency vs. each currency, and their current // last_trade and volume on each exchange the user is interested in $currencies = get_all_currencies(); $summaries = get_all_summary_currencies($this->getUser()); $conversion = get_all_conversion_currencies($this->getUser()); $graph["last_updated"] = 0; $interested = array(); foreach ($currencies as $c) { if (isset($summaries[$c])) { $interested[] = $c; $columns[] = array('type' => 'string', 'title' => get_currency_abbr($c)); } } foreach ($interested as $c1) { $row = array(get_currency_abbr($c1)); foreach ($interested as $c2) { // go through each exchange pair $cell = ""; foreach (get_exchange_pairs() as $exchange => $pairs) { foreach ($pairs as $pair) { if ($c1 == $pair[0] && $c2 == $pair[1]) { $q = db()->prepare("SELECT * FROM ticker_recent WHERE exchange=? AND currency1=? AND currency2=? LIMIT 1"); $q->execute(array($exchange, $c1, $c2)); if ($ticker = $q->fetch()) { // TODO currency_format should be a graph option $exchange_short = strlen($exchange) > 8 ? substr($exchange, 0, 7) . "..." : $exchange; $cell .= "<li><span class=\"rate\">" . number_format_html($ticker['last_trade'], 4) . "</span> " . ($ticker['volume'] == 0 ? "" : "<span class=\"volume\">(" . number_format_html($ticker['volume'], 4) . ")</span>"); $cell .= " <span class=\"exchange\" title=\"" . htmlspecialchars(get_exchange_name($exchange)) . "\">[" . htmlspecialchars($exchange_short) . "]</span>"; $cell .= "</li>\n"; $last_updated = max($last_updated, strtotime($ticker['created_at'])); } else { $cell .= "<li class=\"warning\">" . t("Could not find rate for :exchange: :pair", array(':exchange' => $exchange, ':pair' => $c1 . "/" . $c2)) . "</li>\n"; } } } } if ($cell) { $cell = "<ul class=\"rate_matrix\">" . $cell . "</ul>"; } $row[] = $cell; } $data[] = $row; } // now delete any empty rows or columns // columns $deleteRows = array(); $deleteColumns = array(); for ($i = 0; $i < count($data) - 1; $i++) { $empty = true; for ($j = 1; $j < count($data[$i]); $j++) { if ($data[$i][$j]) { $empty = false; break; } } if ($empty) { $deleteRows[] = $i; } } for ($i = 1; $i < count($data); $i++) { $empty = true; for ($j = 0; $j < count($data[$i]) - 1; $j++) { if ($data[$j][$i]) { $empty = false; break; } } if ($empty) { $deleteColumns[] = $i; } } $new_data = array(); foreach ($data as $i => $row) { if (in_array($i, $deleteRows)) { continue; } $x = array(); foreach ($data[$i] as $j => $cell) { if (in_array($j, $deleteColumns)) { continue; } $x[] = $cell; } $new_data[] = $x; } foreach ($deleteColumns as $i) { unset($columns[$i]); } $columns = array_values($columns); return array('key' => $key_column, 'columns' => $columns, 'data' => $new_data, 'last_updated' => $last_updated, 'add_more_currencies' => true); }
/** * @return a HTML string that can be used in an e-mail, listing all prices */ function get_html_premium_prices() { $prices = array(); foreach (get_site_config('premium_currencies') as $currency) { $prices[] = " " . get_currency_abbr($currency) . ": " . number_format_autoprecision(get_premium_price($currency, 'monthly')) . " " . get_currency_abbr($currency) . "/month, or " . number_format_autoprecision(get_premium_price($currency, 'yearly')) . " " . get_currency_abbr($currency) . "/year" . (get_site_config('premium_' . $currency . '_discount') ? " (" . (int) (get_site_config('premium_' . $currency . '_discount') * 100) . "% off)" : ""); } return implode("<br>\n", $prices); }
throw new PurchaseException(t("Could not generate :currency address for purchase; please try again later.", array(':currency' => get_currency_abbr($currency)))); } // register it to the system as a normal blockchain address, but we need to get received rather than balance $q = db()->prepare("INSERT INTO addresses SET user_id=:user_id, address=:address, currency=:currency, is_received=1"); $q->execute(array("user_id" => get_site_config('system_user_id'), "address" => $address['address'], "currency" => $currency)); $new_address_id = db()->lastInsertId(); // create a new outstanding premium $q = db()->prepare("INSERT INTO outstanding_premiums SET user_id=:user_id, premium_address_id=:pid, address_id=:aid, balance=:balance, months=:months, years=:years"); $q->execute(array("user_id" => user_id(), "pid" => $address['id'], "aid" => $new_address_id, "balance" => $cost, "months" => $months, "years" => $years)); $purchase_id = db()->lastInsertId(); // address is now in use $q = db()->prepare("UPDATE premium_addresses SET is_used=1,used_at=NOW() WHERE id=?"); $q->execute(array($address['id'])); // try sending email, if an email address has been registered if ($user['email']) { send_user_email($user, "purchase", array("name" => $user['name'] ? $user['name'] : $user['email'], "amount" => number_format_autoprecision($cost), "currency" => get_currency_abbr($currency), "currency_name" => get_currency_name($currency), "address" => $address['address'], "explorer" => get_explorer_address($currency, $address['address']), "url" => absolute_url(url_for("user#user_outstanding")))); } // success! inform the user redirect(url_for('user#user_outstanding', array('new_purchase' => $purchase_id))); } catch (PurchaseException $e) { log_uncaught_exception($e); $errors[] = $e->getMessage(); } } page_header(t("Purchase Premium"), "page_purchase", array('js' => 'purchase')); ?> <h1><?php echo ht("Purchase Premium with :currency", array(':currency' => get_currency_name($currency))); ?> </h1>
function rate_format($currency1, $currency2, $n, $precision = 8) { $currency1 = get_currency_abbr($currency1); $currency2 = get_currency_abbr($currency2); if (!is_numeric($n)) { return "<span class=\"error\">" . $n . " {$currency}</span>"; } return "<span class=\"rate_format currency_format\" title=\"" . number_format_autoprecision($n, 8) . " {$currency1}/{$currency2}\">" . number_format_precision($n, $precision) . " <span class=\"code\">{$currency1}/{$currency2}</span></span>"; }
?> class="tab"> <h3><?php echo get_currency_name($c); ?> market averages</h3> <ul> <?php foreach ($pairs as $pair) { if ($pair['currency1'] != $c) { continue; } $selected = $currency1 == $pair['currency1'] && $currency2 == $pair['currency2']; echo "<li" . ($selected ? " class=\"selected\"" : "") . ">"; echo "<a href=\"" . htmlspecialchars(url_for('average#average_' . $pair['currency1'], array('currency1' => $pair['currency1'], 'currency2' => $pair['currency2']))) . "\">"; echo get_currency_abbr($pair['currency1']) . "/" . get_currency_abbr($pair['currency2']); echo "</a>"; echo " (" . number_format($pair['market_count']) . ")"; echo "</li>\n"; } ?> </ul> </li> <?php $first_tab = false; } ?> </ul> </div> </div>
<?php $page_id = -1; $your_currencies = true; require __DIR__ . "/_profile_pages.php"; ?> <?php require __DIR__ . "/_sort_buttons.php"; ?> <div class="tabs" id="tabs_your_currencies"> <ul class="tab_list"> <?php /* each <li> must not have any whitespace between them otherwise whitespace will appear when rendered */ foreach ($balances as $currency => $data) { echo '<li id="tab_currencies_' . htmlspecialchars($currency) . '"><span class="currency_name_' . htmlspecialchars($currency) . '">' . htmlspecialchars(get_currency_abbr($currency)) . '</span></li>'; } ?> </ul> <ul class="tab_groups"> <?php $first_tab = true; foreach ($balances as $currency => $data) { ?> <li id="tab_currencies_<?php echo htmlspecialchars($currency); ?> _tab"<?php echo $first_tab ? "" : " style=\"display:none;\""; ?>
*/ $exchange = "litecoininvest"; $currency = 'ltc'; // get the relevant address $q = db()->prepare("SELECT * FROM accounts_litecoininvest WHERE user_id=? AND id=?"); $q->execute(array($job['user_id'], $job['arg_id'])); $account = $q->fetch(); if (!$account) { throw new JobException("Cannot find a {$exchange} account " . $job['arg_id'] . " for user " . $job['user_id']); } // first, get balances $data = crypto_json_decode(crypto_get_contents(crypto_wrap_url('https://www.litecoininvest.com/api/act?key=' . urlencode($account['api_key']))), false, true); if (!isset($data['balance'][get_currency_abbr($currency)])) { throw new ExternalAPIException("No " . get_currency_abbr($currency) . " balance found"); } $wallet = $data['balance'][get_currency_abbr($currency)]; // -- and now get securities -- // set is_recent=0 for all old security instances for this user $q = db()->prepare("UPDATE securities SET is_recent=0 WHERE user_id=? AND exchange=? AND account_id=?"); $q->execute(array($job['user_id'], $exchange, $account['id'])); $balance = 0; $data = crypto_json_decode(crypto_get_contents(crypto_wrap_url('https://www.litecoininvest.com/api/private/portfolio?key=' . urlencode($account['api_key']))), false, true); foreach ($data as $row) { $security = $row['ticker']; $bid = $row['bid']; // also available: avg_buy_price // make sure that a security definition exists $q = db()->prepare("SELECT * FROM securities_litecoininvest WHERE name=?"); $q->execute(array($security)); $security_def = $q->fetch(); if (!$security_def) {