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); }
<?php /** * Process selected currencies and redirect to the next wizard page if successful. */ require_login(); $user = get_user(user_id()); require_user($user); $errors = array(); $messages = array(); // get all of our limits $accounts = user_limits_summary(user_id()); $currencies = require_post("currencies", array()); $exchanges = require_post("exchanges", array()); $cryptos = get_all_cryptocurrencies(); $fiats = get_all_fiat_currencies(); $commodities = get_all_commodity_currencies(); // go through all fiat currencies and, if no exchange is selected, select a default one foreach ($fiats as $c) { if (in_array($c, $currencies)) { $found = false; foreach ($exchanges as $e) { $prefix = "summary_" . $c . "_"; if (substr($e, 0, strlen($prefix)) == $prefix) { // found one $found = true; } } if (!$found) { $exchanges[] = "summary_" . $c . "_" . get_default_currency_exchange($c); }
</p> <div class="tip"> Cryptocurrencies that do <em>not</em> have a suitable explorer API yet at the time of writing: <ul> <li><span class="currency_name_smc">Smartcoin</span></li> </ul> </div> <p> Currently <?php echo htmlspecialchars(get_site_config('site_name')); ?> supports the <?php $result = array(); foreach (get_all_cryptocurrencies() as $c) { $result[] = "<span class=\"currency_name_" . htmlspecialchars($c) . "\">" . htmlspecialchars(get_currency_name($c)) . "</span>" . (in_array($c, get_new_supported_currencies()) ? " <span class=\"new\">" . ht("new") . "</span>" : ""); } echo implode_english($result); ?> cryptocurrencies. </p> <p> In the future, <?php echo htmlspecialchars(get_site_config('site_name')); ?> will host cryptocurrency explorer instances locally, removing these requirements and making it possible to add almost any cryptocurrency; please donate or purchase a <a href="<?php echo htmlspecialchars(url_for('premium'));
/** * 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; }
/** * Calculate all of the different types of managed graphs that * may be provided to a given user, in each category of managed * graphs (see get_managed_graph_categories()). */ function calculate_all_managed_graphs($user) { $result = array(); $summaries = get_all_summary_currencies(); $all_summaries = get_all_summaries(); $currencies = get_all_currencies(); $accounts = account_data_grouped(); $wallets = get_supported_wallets(); $order_currency = array(); foreach (get_all_currencies() as $c) { $order_currency[$c] = count($order_currency); } $order_exchange = array(); foreach (get_all_exchanges() as $key => $label) { $order_exchange[$key] = count($order_exchange) * 10; } $default_order = array('btc_equivalent' => -1000, 'composition_pie' => 0, 'balances_table' => 1000, 'exchange_daily' => 2000, 'total_daily' => 3000, 'all_daily' => 4000, 'composition_daily' => 5000, 'hashrate_daily' => 6000); $result['summary'] = array(); $result['all_summary'] = array(); $result['summary']['balances_table'] = array('order' => $default_order['balances_table'], 'width' => get_site_config('default_user_graph_height'), 'free' => true, 'priority' => 1); if (count($summaries) >= 2 && isset($summaries['btc'])) { $result['summary']['btc_equivalent'] = array('order' => $default_order['btc_equivalent'], 'width' => get_site_config('default_user_graph_height'), 'free' => true, 'priority' => 2); } foreach (get_all_cryptocurrencies() as $cur) { if (isset($summaries[$cur])) { $result['summary']["composition_" . $cur . "_pie"] = array('order' => $default_order['composition_pie'] + $order_currency[$cur], 'width' => get_site_config('default_user_graph_height'), 'free' => $cur == $user['preferred_crypto'], 'priority' => $cur == $user['preferred_crypto'] ? 100 : 300 + $order_currency[$cur]); $result['summary']["composition_" . $cur . "_daily"] = array('order' => $default_order['composition_daily'] + $order_currency[$cur], 'free' => $cur == $user['preferred_crypto'], 'priority' => $cur == $user['preferred_crypto'] ? 105 : 200 + $order_currency[$cur]); $result['summary']['total_' . $cur . '_daily'] = array('order' => $default_order['total_daily'] + $order_currency[$cur], 'source' => $cur, 'free' => $cur == $user['preferred_crypto'], 'priority' => 100 + $order_currency[$cur]); } } foreach (get_all_commodity_currencies() as $cur) { if (isset($summaries[$cur])) { $result['summary']['total_' . $cur . '_daily'] = array('order' => $default_order['total_daily'] + $order_currency[$cur], 'source' => $cur, 'free' => $cur == $user['preferred_crypto'], 'priority' => 100 + $order_currency[$cur]); } } $result['currency'] = array(); $result['all_currency'] = array(); foreach (get_exchange_pairs() as $exchange => $pairs) { foreach ($pairs as $pair) { // we are interested in both of these currencies if (isset($summaries[$pair[0]]) && isset($summaries[$pair[1]])) { // and one of these currencies are a preferred currency if ($pair[0] == $user['preferred_crypto'] || $pair[0] == $user['preferred_fiat'] || $pair[1] == $user['preferred_crypto'] || $pair[1] == $user['preferred_fiat']) { // and we have a summary instance for this pair somewhere $possible_summaries = array('summary_' . $pair[0] . '_' . $exchange, 'summary_' . $pair[1] . '_' . $exchange); if (in_array($pair[0], get_all_cryptocurrencies())) { $possible_summaries[] = "summary_" . $pair[0]; } if (in_array($pair[1], get_all_cryptocurrencies())) { $possible_summaries[] = "summary_" . $pair[1]; } foreach ($possible_summaries as $p) { if (isset($all_summaries[$p])) { $is_default = is_fiat_currency($pair[0]) && get_default_currency_exchange($pair[0]) == $exchange || is_fiat_currency($pair[1]) && get_default_currency_exchange($pair[1]) == $exchange; $result['all_currency'][$exchange . "_" . $pair[0] . $pair[1] . "_daily"] = array('order' => $default_order['exchange_daily'] + $order_exchange[$exchange] + $order_currency[$pair[0]], 'source' => $p, 'priority' => 150 + $order_currency[$pair[0]]); if ($is_default) { $result['currency'][$exchange . "_" . $pair[0] . $pair[1] . "_daily"] = array('order' => $default_order['exchange_daily'] + $order_exchange[$exchange] + $order_currency[$pair[0]], 'source' => $p, 'free' => true, 'priority' => 150 + $order_currency[$pair[0]]); } // don't display all2btc etc if (!in_array(substr($p, strlen("summary_")), get_all_cryptocurrencies())) { $result['all_summary']['all2' . substr($p, strlen("summary_")) . '_daily'] = array('order' => $default_order['all_daily'] + $order_exchange[$exchange] + $order_currency[$pair[0]], 'source' => $p, 'priority' => 50 + $order_currency[$pair[0]]); if ($is_default) { $result['summary']['all2' . substr($p, strlen("summary_")) . '_daily'] = array('order' => $default_order['all_daily'] + $order_exchange[$exchange] + $order_currency[$pair[0]], 'source' => $p, 'free' => $pair[0] == $user['preferred_crypto'] || $pair[0] == $user['preferred_fiat'], 'priority' => 5 + $order_currency[$pair[0]]); } } break; } } } } } } $result['securities'] = array(); // no graphs to put in here yet... // TODO in the future: securities composition graphs? e.g. composition_litecoinglobal_daily $result['mining'] = array(); foreach (get_all_hashrate_currencies() as $cur) { if (isset($summaries[$cur])) { // we need to have at least one pool that supports reporting hashrate $has_hashing_account = false; foreach ($accounts['Mining pools'] as $key => $account) { if (!isset($wallets[$key])) { continue; } $instances = get_all_user_account_instances($key); if ($instances) { if (in_array('hash', $wallets[$key])) { $has_hashing_account = $key; } } } if (!$has_hashing_account) { continue; } $result['mining']["hashrate_" . $cur . "_daily"] = array('order' => $default_order['hashrate_daily'] + $order_currency[$cur], 'source' => $has_hashing_account, 'free' => $cur == $user['preferred_crypto'], 'priority' => 150 + $order_currency[$cur]); } } // all 'summary' are also 'all_summary' etc foreach ($result['summary'] as $key => $value) { $result['all_summary'][$key] = $value; } foreach ($result['currency'] as $key => $value) { $result['all_currency'][$key] = $value; } // go through each category and sort by order foreach ($result as $key => $value) { uasort($result[$key], '_sort_by_order_key'); } return $result; }
foreach (get_all_cryptocurrencies() as $c) { if (isset($summaries[$c])) { echo "<option value=\"" . htmlspecialchars($c) . "\"\n class=\"currency_name_" . htmlspecialchars($c) . "\"" . ($user['preferred_crypto'] == $c ? " selected" : "") . ">" . get_currency_abbr($c) . "</option>\n"; } } ?> </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;
$total = 0; // CUR is kept as-is if (isset($totals[$currency])) { crypto_log("Initial {$currency} balance: " . $totals[$currency]); $total += $totals[$currency]; } // BTC is converted at default ticker rate bid if (isset($totals['btc'])) { if ($ticker = get_latest_ticker(get_default_currency_exchange($currency), "btc", $currency)) { $temp = $totals['btc'] / ($ticker['bid'] ? $ticker['bid'] : $ticker['last_trade']); crypto_log("+ from BTC: " . $temp); $total += $temp; } } // other cryptocurrencies are converted first to BTC, and then to the given currency foreach (array_merge(get_all_cryptocurrencies(), get_all_commodity_currencies()) as $c) { if ($c == $currency || $c == 'btc') { continue; } // 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; } }
function testAllCurrenciesComplete() { $this->assertSame(array(), array_diff(get_all_currencies(), get_all_fiat_currencies(), get_all_cryptocurrencies(), get_all_commodity_currencies())); }
/** * Crypto conversions: all cryptocurrencies to a single currency. */ function get_crypto_conversion_summary_types() { $currencies = get_all_cryptocurrencies() + get_all_commodity_currencies(); $result = array(); foreach ($currencies as $c) { $result[$c] = array('currency' => $c, 'title' => get_currency_name($c), 'short_title' => get_currency_abbr($c)); } return $result; }
require_user($user); $errors = array(); $messages = array(); require __DIR__ . "/../graphs/managed.php"; // get all of our limits $accounts = user_limits_summary(user_id()); $preferred_crypto = require_post("preferred_crypto", false); $preferred_fiat = require_post("preferred_fiat", false); $preference = require_post("preference"); $managed = require_post("managed", array()); $categories = get_managed_graph_categories(); // checks if ($preference == "managed" && !$managed) { $errors[] = t("You need to select at least one category of graph portfolio preferences."); } if (!in_array($preferred_crypto, get_all_cryptocurrencies())) { $errors[] = t("Invalid preferred cryptocurrency."); } if (!is_fiat_currency($preferred_fiat)) { $errors[] = t("Invalid preferred fiat currency."); } if (!in_array($preference, array('auto', 'managed', 'none'))) { $errors[] = t("Invalid graph management preference."); } if ($preference != "none" && !$preferred_fiat) { $errors[] = t("You need to select at least :one_currency in order to use managed graphs.", array(':one_currency' => link_to(url_for('wizard_currencies'), t("one fiat currency")))); } if ($preference != "none" && !$preferred_crypto) { $errors[] = t("You need to select at least :one_currency in order to use managed graphs.", array(':one_currency' => link_to(url_for('wizard_currencies'), t("one cryptocurrency")))); } foreach ($managed as $m) {