Пример #1
0
 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);
 }
/**
 * 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);
        }
    } else {
Пример #3
0
/**
 * 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;
}
Пример #4
0
 $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;
             }
         }
Пример #5
0
 function testAllCurrenciesComplete()
 {
     $this->assertSame(array(), array_diff(get_all_currencies(), get_all_fiat_currencies(), get_all_cryptocurrencies(), get_all_commodity_currencies()));
 }
Пример #6
0
/**
 * 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;
}