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);
 }
示例#2
0
 function testAllExchangeCurrencies()
 {
     foreach (get_exchange_pairs() as $exchange => $pairs) {
         foreach ($pairs as $p) {
             $this->assertTrue(in_array($p[0], get_all_currencies()), "Exchange {$exchange} had invalid currency {$p['0']} in pair {$p['0']}/{$p['1']}");
             $this->assertTrue(in_array($p[1], get_all_currencies()), "Exchange {$exchange} had invalid currency {$p['1']} in pair {$p['0']}/{$p['1']}");
         }
     }
 }
示例#3
0
 function getJSON($arguments)
 {
     $result = array();
     foreach (get_all_currencies() as $cur) {
         $instance = \DiscoveredComponents\Currencies::getInstance($cur);
         $result[] = array("code" => $instance->getCode(), "abbr" => $instance->getAbbr(), "name" => $instance->getName(), "cryptocurrency" => $instance->isCryptocurrency(), "fiat" => $instance->isFiat(), "commodity" => $instance->isCommodity());
     }
     return $result;
 }
示例#4
0
 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;
 }
示例#5
0
 function getJSON($arguments)
 {
     // important for url_for() links
     define('FORCE_NO_RELATIVE', true);
     if (!in_array($arguments['currency1'], get_all_currencies())) {
         throw new \Exception("Invalid currency '" . $arguments['currency1'] . "'");
     }
     if (!in_array($arguments['currency2'], get_all_currencies())) {
         throw new \Exception("Invalid currency '" . $arguments['currency2'] . "'");
     }
     $q = db()->prepare("SELECT * FROM ticker_recent WHERE currency1=? AND currency2=? ORDER BY volume DESC");
     $q->execute(array($arguments['currency1'], $arguments['currency2']));
     $result = array();
     while ($ticker = $q->fetch()) {
         $result[] = array('exchange' => $ticker['exchange'], 'last_trade' => $ticker['last_trade'], 'bid' => $ticker['bid'], 'ask' => $ticker['ask'], "volume" => $ticker['volume'], 'time' => $ticker['created_at'], 'url' => absolute_url(url_for('historical', array('id' => $ticker['exchange'] . "_" . $ticker['currency1'] . $ticker['currency2'] . "_daily"))));
     }
     if (!$result) {
         throw new \Exception("No rates found");
     }
     return $result;
 }
示例#6
0
 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);
 }
示例#7
0
 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);
 }
 function getCompositionSources($days, $extra_days)
 {
     $sources = array();
     $summary_currencies = get_all_summary_currencies($this->getUser());
     foreach (get_all_currencies() as $cur) {
         if (isset($summary_currencies[$cur])) {
             if ($cur == 'btc') {
                 // we can't LIMIT by days here, because we may have many accounts for one exchange
                 // first get summarised data
                 $sources[] = array('query' => "SELECT *, '{$cur}' AS exchange FROM graph_data_summary WHERE user_id=:user_id AND summary_type='totalbtc'\n            AND data_date > DATE_SUB(NOW(), INTERVAL " . ($days + $extra_days) . " DAY) ORDER BY data_date DESC", 'key' => 'data_date', 'balance_key' => 'balance_closing');
                 // and then get more recent data
                 $sources[] = array('query' => "SELECT *, '{$cur}' AS exchange FROM summary_instances WHERE is_daily_data=1 AND summary_type='totalbtc'\n            AND user_id=:user_id AND created_at >= DATE_SUB(NOW(), INTERVAL " . ($days + $extra_days) . " DAY) ORDER BY created_at DESC", 'key' => 'created_at', 'balance_key' => 'balance');
             } else {
                 // we can't LIMIT by days here, because we may have many accounts for one exchange
                 // first get summarised data
                 $sources[] = array('query' => "SELECT *, '{$cur}' AS exchange FROM graph_data_summary WHERE user_id=:user_id AND summary_type='equivalent_btc_{$cur}'\n            AND data_date > DATE_SUB(NOW(), INTERVAL " . ($days + $extra_days) . " DAY) ORDER BY data_date DESC", 'key' => 'data_date', 'balance_key' => 'balance_closing');
                 // and then get more recent data
                 $sources[] = array('query' => "SELECT *, '{$cur}' AS exchange FROM summary_instances WHERE is_daily_data=1 AND summary_type='equivalent_btc_{$cur}'\n            AND user_id=:user_id AND created_at >= DATE_SUB(NOW(), INTERVAL " . ($days + $extra_days) . " DAY) ORDER BY created_at DESC", 'key' => 'created_at', 'balance_key' => 'balance');
             }
         }
     }
     return $sources;
 }
示例#9
0
/**
 * Helper function that converts a {@code graph_type} to a GraphRenderer
 * object, which we can then use to get raw graph data and format it as necessary.
 */
function construct_graph_renderer($graph_type, $arg0, $arg0_resolved)
{
    $bits = explode("_", $graph_type);
    $all_exchanges = get_all_exchanges();
    if (count($bits) == 3) {
        $cur1 = false;
        $cur2 = false;
        if (strlen($bits[1]) == 6) {
            $cur1 = substr($bits[1], 0, 3);
            $cur2 = substr($bits[1], 3);
            $cur1 = in_array($cur1, get_all_currencies()) ? $cur1 : false;
            $cur2 = in_array($cur2, get_all_currencies()) ? $cur2 : false;
        }
        if (strlen($bits[2]) == 6 && !$cur1 && !$cur2) {
            $cur1 = substr($bits[2], 0, 3);
            $cur2 = substr($bits[2], 3);
            $cur1 = in_array($cur1, get_all_currencies()) ? $cur1 : false;
            $cur2 = in_array($cur2, get_all_currencies()) ? $cur2 : false;
        }
        if ($bits[2] == "daily" && $cur1 && $cur2 && isset($all_exchanges[$bits[0]])) {
            return new GraphRenderer_Ticker($bits[0], $cur1, $cur2);
        }
        if ($bits[2] == "markets" && $cur1 && $cur2 && $bits[0] == "average") {
            return new GraphRenderer_AverageMarketData($cur1, $cur2);
        }
        if ($bits[0] == "composition" && in_array($bits[1], get_all_currencies())) {
            switch ($bits[2]) {
                case "pie":
                    return new GraphRenderer_CompositionPie($bits[1]);
                case "table":
                    return new GraphRenderer_CompositionTable($bits[1]);
                case "daily":
                    return new GraphRenderer_CompositionGraph($bits[1]);
                case "stacked":
                    return new GraphRenderer_CompositionStacked($bits[1]);
                case "proportional":
                    return new GraphRenderer_CompositionProportional($bits[1]);
            }
        }
        if ($bits[0] == "total" && in_array($bits[1], get_all_currencies()) && $bits[2] == "daily") {
            return new GraphRenderer_SummaryGraph('total' . $bits[1], $bits[1]);
        }
        if ($bits[0] == "hashrate" && in_array($bits[1], get_all_currencies()) && $bits[2] == "daily") {
            return new GraphRenderer_SummaryGraphHashrate('totalmh_' . $bits[1], $bits[1]);
        }
        if ($bits[0] == "securities" && in_array($bits[2], get_all_currencies())) {
            $renderer = new GraphRenderer_BalancesGraphSecurities('securities_' . $bits[1], $arg0, $bits[2], $arg0_resolved);
            return $renderer;
        }
        if ($bits[0] == "pair" && isset($all_exchanges[$bits[1]]) && $cur1 && $cur2) {
            return new GraphRenderer_ExchangePair($bits[1], $cur1, $cur2);
        }
    }
    // issue #273: fix bitmarket_pl exchange
    if (count($bits) == 4) {
        $cur1 = false;
        $cur2 = false;
        if (strlen($bits[2]) == 6) {
            $cur1 = substr($bits[2], 0, 3);
            $cur2 = substr($bits[2], 3);
            $cur1 = in_array($cur1, get_all_currencies()) ? $cur1 : false;
            $cur2 = in_array($cur2, get_all_currencies()) ? $cur2 : false;
        }
        if ($bits[3] == "daily" && $cur1 && $cur2 && isset($all_exchanges[$bits[0] . "_" . $bits[1]])) {
            return new GraphRenderer_Ticker($bits[0] . "_" . $bits[1], $cur1, $cur2);
        }
    }
    if (count($bits) >= 2) {
        if (substr($bits[0], 0, strlen("all2")) == "all2" || substr($bits[0], 0, strlen("crypto2")) == "crypto2") {
            $cur = substr($bits[0], -3);
            if (in_array($cur, get_all_currencies())) {
                if (count($bits) == 3 && $bits[2] == "daily" && isset($all_exchanges[$bits[1]])) {
                    // e.g. all2nzd_bitnz_daily
                    return new GraphRenderer_SummaryGraphConvertedExchange($bits[0] . "_" . $bits[1], $cur);
                }
                if (count($bits) == 4 && $bits[3] == "daily" && isset($all_exchanges[$bits[1] . "_" . $bits[2]])) {
                    // e.g. all2pln_bitmarket_pl_daily (#273)
                    return new GraphRenderer_SummaryGraphConvertedExchange($bits[0] . "_" . $bits[1] . "_" . $bits[2], $cur);
                }
                if (count($bits) == 2 && $bits[1] == "daily") {
                    // e.g. crypto2ltc_daily
                    return new GraphRenderer_SummaryGraphConvertedCrypto($bits[0], $cur);
                }
            }
        }
    }
    if (count($bits) >= 2 && $bits[0] == "metrics") {
        $possible = GraphRenderer_AdminMetrics::getMetrics();
        $bits_two = explode("_", $graph_type, 2);
        if (isset($possible[$bits_two[1]])) {
            return new GraphRenderer_AdminMetrics($bits_two[1]);
        }
    }
    switch ($graph_type) {
        case "btc_equivalent":
            return new GraphRenderer_EquivalentPieBTC();
        case "balances_table":
            return new GraphRenderer_BalancesTable();
        case "total_converted_table":
            return new GraphRenderer_TotalConvertedTable();
        case "crypto_converted_table":
            return new GraphRenderer_CryptoConvertedTable();
        case "balances_offset_table":
            return new GraphRenderer_BalancesOffsetsTable();
        case "ticker_matrix":
            return new GraphRenderer_TickerMatrix();
        case "btc_equivalent_graph":
            return new GraphRenderer_BtcEquivalentGraph();
        case "btc_equivalent_stacked":
            return new GraphRenderer_BtcEquivalentStacked();
        case "btc_equivalent_proportional":
            return new GraphRenderer_BtcEquivalentProportional();
        case "external_historical":
            return new GraphRenderer_ExternalHistorical($arg0_resolved);
        case "admin_statistics":
            return new GraphRenderer_AdminStatistics();
        case "statistics_queue":
            return new GraphRenderer_StatisticsQueue();
        case "statistics_system_load":
            return new GraphRenderer_StatisticsSystemLoad("");
        case "statistics_db_system_load":
            return new GraphRenderer_StatisticsSystemLoad("db_");
        default:
            throw new NoGraphRendererException("Unknown graph to render '{$graph_type}'");
    }
}
示例#10
0
function get_all_recent_rates()
{
    global $global_all_recent_rates;
    if ($global_all_recent_rates === null) {
        $global_all_recent_rates = array();
        $query = "";
        foreach (get_all_currencies() as $cur) {
            if ($cur == 'btc') {
                continue;
            }
            // we don't provide a 'btcbtc' rate
            $exchange = get_default_currency_exchange($cur);
            $query .= "(currency1 = 'btc' AND currency2 = '{$cur}' AND exchange='{$exchange}') OR";
            $query .= "(currency1 = '{$cur}' AND currency2 = 'btc' AND exchange='{$exchange}') OR";
        }
        $q = db()->prepare("SELECT * FROM ticker_recent WHERE 1 AND ({$query} 0)");
        $q->execute();
        while ($ticker = $q->fetch()) {
            $global_all_recent_rates[$ticker['currency1'] . $ticker['currency2']] = $ticker;
        }
    }
    return $global_all_recent_rates;
}
                    <h3><?php 
echo lang_key('bank_currency_settings');
?>
</h3>
                    <div class="form-group">
                        <label class="col-sm-3 col-lg-2 control-label"><?php 
echo lang_key('bank_currency');
?>
</label>

                        <div class="col-sm-9 col-md-3 controls">
                               
                            <select name="bank_currency" class="form-control">
                                <?php 
$options = get_all_currencies();
?>

                                <?php 
$bank_currency = isset($settings->bank_currency) ? $settings->bank_currency : '';
?>

                                <?php 
$v = set_value('bank_currency') != '' ? set_value('bank_currency') : $bank_currency;
?>

                                <?php 
$sel = $v == 'use_paypal' ? 'selected="selected"' : '';
?>

                                <option value="use_paypal" <?php 
示例#12
0
    insert_new_address_balance($job, $address, $balance);
} else {
    if ($instance instanceof \Openclerk\Currencies\BlockBalanceableCurrency) {
        // get the most recent block count, to calculate confirmations
        $block = null;
        $q = db()->prepare("SELECT * FROM blockcount_" . $currency . " WHERE is_recent=1");
        $q->execute();
        if ($result = $q->fetch()) {
            $block = $result['blockcount'] - \Openclerk\Config::get($currency . "_confirmations", 6);
        }
        $balance = $instance->getBalanceAtBlock($address['address'], $block, $logger);
        insert_new_address_balance($job, $address, $balance);
    } else {
        // we can't do confirmations or block balances
        $balance = $instance->getBalance($address['address'], $logger);
        insert_new_address_balance($job, $address, $balance);
    }
}
if ($instance instanceof \Openclerk\Currencies\MultiBalanceableCurrency) {
    $balances = $instance->getMultiBalances($address['address'], $logger);
    foreach ($balances as $code => $balance) {
        if (in_array($code, get_all_currencies())) {
            if ($code != $currency) {
                // skip balances we've already inserted for this currency
                insert_new_balance($job, $address, 'ripple', $code, $balance);
            }
        } else {
            $logger->info("Unknown multi currency '{$code}'");
        }
    }
}
示例#13
0
/**
 * 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;
}
示例#14
0
function is_valid_currency($c)
{
    return in_array($c, get_all_currencies());
}
示例#15
0
/**
 * Renders a collection of $sources with a given set of arguments $args, a user ID $user_id
 * and a heading callback function $get_heading_title.
 *
 * @param $has_subheadings true (default), false (no subheading), 'last_total' (total the most recent data)
 * @param $stacked if true, renders the graph as a stacked graph rather than line graph. defaults to false.
 * @param $make_proportional if true, converts all values to proportional data w.r.t. each date point, up to 100%. defaults to false.
 */
function render_sources_graph($graph, $sources, $args, $user_id, $get_heading_title, $has_subheadings = true, $stacked = false, $make_proportional = false)
{
    $data = array();
    $last_updated = false;
    $days = get_graph_days($graph);
    $extra_days = extra_days_necessary($graph);
    $exchanges_found = array();
    $maximum_balances = array();
    // only used to check for non-zero accounts
    $data_temp = array();
    $hide_missing_data = !require_get("debug_show_missing_data", false);
    $latest = array();
    foreach ($sources as $source) {
        $q = db()->prepare($source['query']);
        $q_args = $args;
        $q_args['user_id'] = $user_id;
        $q->execute($q_args);
        while ($ticker = $q->fetch()) {
            $key = date('Y-m-d', strtotime($ticker[$source['key']]));
            if (!isset($data_temp[$key])) {
                $data_temp[$key] = array();
            }
            if (!isset($data_temp[$key][$ticker['exchange']])) {
                $data_temp[$key][$ticker['exchange']] = 0;
            }
            $data_temp[$key][$ticker['exchange']] += $ticker[$source['balance_key']];
            $last_updated = max($last_updated, strtotime($ticker['created_at']));
            $exchanges_found[$ticker['exchange']] = $ticker['exchange'];
            if (!isset($maximum_balances[$ticker['exchange']])) {
                $maximum_balances[$ticker['exchange']] = 0;
            }
            $maximum_balances[$ticker['exchange']] = max($ticker[$source['balance_key']], $maximum_balances[$ticker['exchange']]);
            if (!isset($latest[$ticker['exchange']])) {
                $latest[$ticker['exchange']] = 0;
            }
            $latest[$ticker['exchange']] = max($latest[$ticker['exchange']], strtotime($ticker[$source['key']]));
        }
    }
    // get rid of any exchange summaries that had zero data
    foreach ($maximum_balances as $key => $balance) {
        if ($balance == 0) {
            foreach ($data_temp as $dt_key => $values) {
                unset($data_temp[$dt_key][$key]);
            }
            unset($exchanges_found[$key]);
        }
    }
    // sort by date so we can get previous dates if necessary for missing data
    ksort($data_temp);
    $data = array();
    // add headings after we know how many exchanges we've found
    $first_heading = array('title' => t("Date"));
    if ($make_proportional) {
        $first_heading['min'] = 0;
        $first_heading['max'] = 100;
    }
    $headings = array($first_heading);
    $i = 0;
    // sort them so they're always in the same order
    ksort($exchanges_found);
    foreach ($exchanges_found as $key => $ignored) {
        $headings[$key] = array('title' => $get_heading_title($key, $args), 'line_width' => 2, 'color' => default_chart_color(in_array(strtolower($key), get_all_currencies()) ? array_search(strtolower($key), get_all_currencies()) : $i++));
    }
    $data[0] = $headings;
    // add '0' for exchanges that we've found at one point, but don't have a data point
    // but reset to '0' for exchanges that are no longer present (i.e. from graph_data_balances archives)
    // this fixes a bug where old securities data is still displayed as present in long historical graphs
    $previous_row = array();
    foreach ($data_temp as $date => $values) {
        $row = array('new Date(' . date('Y, n-1, j', strtotime($date)) . ')');
        foreach ($exchanges_found as $key => $ignored) {
            if (!$hide_missing_data || strtotime($date) <= $latest[$key]) {
                if (!isset($values[$key])) {
                    $row[$key] = graph_number_format(isset($previous_row[$key]) ? $previous_row[$key] : 0);
                } else {
                    $row[$key] = graph_number_format(demo_scale($values[$key]));
                }
            } else {
                $row[$key] = graph_number_format(0);
            }
        }
        if (count($row) > 1) {
            // don't add empty rows
            $data[$date] = $row;
            $previous_row = $row;
        }
    }
    // make proportional?
    if ($make_proportional) {
        $data_temp = array();
        foreach ($data as $row => $columns) {
            $row_temp = array();
            if ($row == 0) {
                foreach ($columns as $key => $value) {
                    if ($key !== 0) {
                        $value['title'] .= " %";
                    }
                    $row_temp[$key] = $value;
                }
            } else {
                $total = 0;
                foreach ($columns as $key => $value) {
                    $total += $key === 0 ? 0 : $value;
                }
                foreach ($columns as $key => $value) {
                    $row_temp[$key] = $key === 0 ? $value : graph_number_format($total == 0 ? 0 : $value / $total * 100);
                }
            }
            $data_temp[$row] = $row_temp;
        }
        $data = $data_temp;
    }
    // sort each row by the biggest value in the most recent data
    // so e.g. BTC comes first, LTC comes second, regardless of order of summary_instances, balances etc
    $keys = array_keys($data);
    $last_row = $data[$keys[count($keys) - 1]];
    arsort($last_row);
    $data_temp = array();
    foreach ($data as $row => $columns) {
        $temp = array();
        $temp[0] = $columns[0];
        // keep row 0 the same
        foreach ($last_row as $key => $ignored) {
            if ($key !== 0) {
                $temp[$key] = $columns[$key];
            }
        }
        $data_temp[$row] = $temp;
    }
    $data = $data_temp;
    if (count($data) > 1) {
        // calculate deltas if necessary
        $data = calculate_graph_deltas($graph, $data);
        // calculate technicals
        // (only if there is at least one point of data, otherwise calculate_technicals() will throw an error)
        $data = calculate_technicals($graph, $data);
        // discard early data
        $data = discard_early_data($data, $days);
        // sort by key, but we only want values
        // we also need to sort by time *before* calculating subheadings
        uksort($data, 'cmp_time');
        if ($has_subheadings) {
            if ($has_subheadings == 'last_total') {
                $graph['subheading'] = format_subheading_values_subtotal($graph, $data);
            } else {
                $graph['subheading'] = format_subheading_values($graph, $data);
            }
        }
        $graph['last_updated'] = $last_updated;
        render_linegraph_date($graph, array_values($data), $stacked);
    } else {
        if ($user_id == get_site_config('system_user_id')) {
            render_text($graph, t("No data to display."));
            // or Invalid balance type.
        } else {
            render_text($graph, t("Either you have not enabled this balance, or your summaries for this balance have not yet been updated by :site_name.") . "<br><a class=\"add_accounts\" href=\"" . htmlspecialchars(url_for('wizard_currencies')) . "\">" . ht("Configure currencies") . "</a>");
        }
    }
}
echo "<th>Exchange</th>";
foreach ($all_currencies as $cur => $ignored) {
    $class = in_array($cur, get_all_currencies()) ? "supported" : "";
    if (require_get("only_supported", false) && !in_array($cur, get_all_currencies())) {
        continue;
    }
    echo "<th class=\"{$class}\">" . htmlspecialchars($cur) . "</th>";
}
echo "</tr>\n";
$exchange_pairs = get_exchange_pairs();
$get_supported_wallets = get_supported_wallets();
foreach ($exchanges as $exchange) {
    echo "<tr>";
    echo "<th>" . htmlspecialchars($exchange->getName()) . "</th>";
    foreach ($all_currencies as $cur => $ignored) {
        if (require_get("only_supported", false) && !in_array($cur, get_all_currencies())) {
            continue;
        }
        $class = isset($matrix[$exchange->getCode()][$cur]) ? "reported" : "";
        // do we have at least one exchange pair for this defined?
        $pair_supported = false;
        foreach ($exchange_pairs[$exchange->getCode()] as $pair) {
            if ($pair[0] == $cur || $pair[1] == $cur) {
                $pair_supported = true;
            }
        }
        if (isset($get_supported_wallets[$exchange->getCode()]) && in_array($cur, $get_supported_wallets[$exchange->getCode()])) {
            $class .= " wallet";
        }
        $class .= $pair_supported ? " supported" : "";
        echo "<td class=\"{$class}\">{$class}</td>";
示例#17
0
 * This page is the second page in a series of wizards to configure a user account.
 * A user may revisit this page at any time to reconfigure their account.
 * This page allows the user to select which kind of accounts to add.
 */
require_login();
require __DIR__ . "/../layout/templates.php";
page_header(t("Add Accounts and Addresses"), "page_wizard_accounts", array('js' => 'wizard', 'class' => 'page_accounts'));
$user = get_user(user_id());
require_user($user);
$messages = array();
// get all of our accounts
$accounts = user_limits_summary(user_id());
// get our offset values
require __DIR__ . "/../graphs/util.php";
$summaries = get_all_summary_currencies();
$currencies = get_all_currencies();
require_template("wizard_accounts");
?>

<div class="wizard">

<ul class="account-type">

  <li><a href="<?php 
echo htmlspecialchars(url_for('wizard_accounts_addresses'));
?>
"><?php 
echo t("Address");
?>
    <?php 
if ($accounts['wizard_addresses']) {
示例#18
0
    <?php 
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)
{
示例#19
0
    <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>
        <td><?php 
        echo htmlspecialchars($vote['total_votes']);
        ?>
</td>
        <td><?php 
示例#20
0
<?php

/**
 * Discovered exchange ticker job.
 */
if (!$exchange) {
    throw new JobException("No exchange defined");
}
$instance = \DiscoveredComponents\Exchanges::getInstance($exchange);
$rates = $instance->fetchAllRates($logger);
$logger->info("Found " . count($rates) . " rates from exchange");
foreach ($rates as $code => $rate) {
    $currency1 = $rate['currency1'];
    $currency2 = $rate['currency2'];
    if (!in_array($currency1, get_all_currencies())) {
        $logger->info("Ignoring currency '{$currency1}': not a supported currency");
        continue;
    }
    if (!in_array($currency2, get_all_currencies())) {
        $logger->info("Ignoring currency '{$currency2}': not a supported currency");
        continue;
    }
    insert_new_ticker($job, array("name" => $exchange), $currency1, $currency2, $rate);
}
示例#21
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;
}
 function get_currency_icon($currency = null)
 {
     $currencies = get_all_currencies();
     $currencySymbol = '';
     if ($currency == null) {
         return 'N/A';
     }
     $symbol = $currencies[$currency][1];
     if ($symbol == '') {
         return $currency;
     }
     $symbols = explode(', ', $symbol);
     if (is_array($symbols)) {
         $symbol = "";
         foreach ($symbols as $temp) {
             $symbol .= '&#x' . $temp . ';';
         }
     } else {
         $symbol = '&#x' . $symbol . ';';
     }
     return $symbol;
 }
示例#23
0
 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);
 }
 public function getData($days)
 {
     $columns = array();
     $key_column = array('type' => 'date', 'title' => ct("Date"));
     // $columns = $this->getTickerColumns();
     // TODO extra_days_necessary
     $extra_days = 10;
     $sources = $this->getCompositionSources($days, $extra_days);
     $args = $this->getCompositionArgs();
     $data = array();
     $last_updated = false;
     $exchanges_found = array();
     $maximum_balances = array();
     // only used to check for non-zero accounts
     $data_temp = array();
     $hide_missing_data = !require_get("debug_show_missing_data", false);
     $latest = array();
     foreach ($sources as $source) {
         $q = db()->prepare($source['query']);
         $q->execute($args);
         while ($ticker = $q->fetch()) {
             $key = date('Y-m-d', strtotime($ticker[$source['key']]));
             if (!isset($data_temp[$key])) {
                 $data_temp[$key] = array();
             }
             if (!isset($data_temp[$key][$ticker['exchange']])) {
                 $data_temp[$key][$ticker['exchange']] = 0;
             }
             $data_temp[$key][$ticker['exchange']] += $ticker[$source['balance_key']];
             $last_updated = max($last_updated, strtotime($ticker['created_at']));
             $exchanges_found[$ticker['exchange']] = $ticker['exchange'];
             if (!isset($maximum_balances[$ticker['exchange']])) {
                 $maximum_balances[$ticker['exchange']] = 0;
             }
             $maximum_balances[$ticker['exchange']] = max($ticker[$source['balance_key']], $maximum_balances[$ticker['exchange']]);
             if (!isset($latest[$ticker['exchange']])) {
                 $latest[$ticker['exchange']] = 0;
             }
             $latest[$ticker['exchange']] = max($latest[$ticker['exchange']], strtotime($ticker[$source['key']]));
         }
     }
     // get rid of any exchange summaries that had zero data
     foreach ($maximum_balances as $key => $balance) {
         if ($balance == 0) {
             foreach ($data_temp as $dt_key => $values) {
                 unset($data_temp[$dt_key][$key]);
             }
             unset($exchanges_found[$key]);
         }
     }
     // sort by date so we can get previous dates if necessary for missing data
     ksort($data_temp);
     $data = array();
     // add headings after we know how many exchanges we've found
     $first_heading = array('title' => t("Date"));
     $headings = array($first_heading);
     $i = 0;
     // sort them so they're always in the same order
     ksort($exchanges_found);
     foreach ($exchanges_found as $key => $ignored) {
         $headings[$key] = array('title' => $this->getHeadingTitle($key, $args));
     }
     // $data[0] = $headings;
     // add '0' for exchanges that we've found at one point, but don't have a data point
     // but reset to '0' for exchanges that are no longer present (i.e. from graph_data_balances archives)
     // this fixes a bug where old securities data is still displayed as present in long historical graphs
     $previous_row = array();
     foreach ($data_temp as $date => $values) {
         $row = array();
         foreach ($exchanges_found as $key => $ignored) {
             if (!$hide_missing_data || strtotime($date) <= $latest[$key]) {
                 if (!isset($values[$key])) {
                     $row[$key] = graph_number_format(isset($previous_row[$key]) ? $previous_row[$key] : 0);
                 } else {
                     $row[$key] = graph_number_format(demo_scale($values[$key]));
                 }
             } else {
                 $row[$key] = graph_number_format(0);
             }
         }
         if (count($row) > 0) {
             // don't add empty rows
             $data[$date] = $row;
             $previous_row = $row;
         }
     }
     // sort each row by the biggest value in the most recent data
     // so e.g. BTC comes first, LTC comes second, regardless of order of summary_instances, balances etc
     $keys = array_keys($data);
     // we can only sort if we actually have data
     if (count($keys) == 0) {
         // bail early
         throw new NoDataGraphException_AddCurrencies();
     }
     $last_row = $data[$keys[count($keys) - 1]];
     arsort($last_row);
     $data_temp = array();
     foreach ($data as $row => $columns) {
         $temp = array();
         foreach ($last_row as $key => $ignored) {
             $temp[$key] = $columns[$key];
         }
         $data_temp[$row] = $temp;
     }
     $data = $data_temp;
     // convert columns and data into numeric indices
     $result_columns = array();
     $result_column_map = array();
     foreach ($columns as $key => $column) {
         $result_columns[] = array('type' => 'number', 'title' => $this->getHeadingTitle($key, $args));
         // if the key is a currency, use the same currency colour across all graphs
         if (in_array(strtolower($key), get_all_currencies())) {
             $result_columns[count($result_columns) - 1]['color'] = array_search(strtolower($key), get_all_currencies());
         }
         $result_column_map[$key] = count($result_columns) - 1;
     }
     $result_data = array();
     foreach ($data as $date => $row) {
         $new_row = array();
         foreach ($row as $key => $value) {
             $new_row[$result_column_map[$key]] = $value;
         }
         $result_data[$date] = $new_row;
     }
     // find the last row, and calculate its total for later
     $last_row = array();
     $last_row_total = 0;
     foreach ($result_data as $date => $row) {
         $last_row = $row;
     }
     foreach ($row as $value) {
         $last_row_total += $value;
     }
     // sort the last row, and then use this new order to resort all
     // of the columns and data
     arsort($last_row);
     $sorted_columns = array();
     $sorted_data = array();
     foreach ($last_row as $i => $ignored) {
         $sorted_columns[] = $result_columns[$i];
     }
     foreach ($result_data as $date => $rows) {
         $sorted_row = array();
         foreach ($last_row as $i => $ignored) {
             $sorted_row[] = $rows[$i];
         }
         $sorted_rows[$date] = $sorted_row;
     }
     return array('key' => $key_column, 'columns' => $sorted_columns, 'data' => $sorted_rows, 'last_updated' => $last_updated, 'last_row_total' => $last_row_total);
 }
示例#25
0
/**
 * /api/v1/rates.json
 */
function api_get_all_rates($with_extra = true)
{
    $rates = array();
    foreach (get_all_currencies() as $cur1) {
        foreach (get_all_currencies() as $cur2) {
            if ($cur1 == $cur2) {
                continue;
            }
            $rate = -1;
            $exchange = array();
            $pair = array();
            if ($cur1 == "btc") {
                if (!is_fiat_currency($cur2)) {
                    // btc/ltc and btc/ghs
                    $exchange = get_default_currency_exchange($cur2);
                    $ticker = get_latest_ticker($exchange, $cur1, $cur2);
                    $rate = $ticker['last_trade'] == 0 ? 0 : 1 / $ticker['last_trade'];
                    $pair = $cur1 . $cur2;
                } else {
                    // btc/usd
                    $exchange = get_default_currency_exchange($cur2);
                    $ticker = get_latest_ticker($exchange, $cur2, $cur1);
                    $rate = $ticker['last_trade'];
                    $pair = $cur2 . $cur1;
                }
            } else {
                if ($cur2 == "btc") {
                    if (!is_fiat_currency($cur1)) {
                        // btc/ltc and btc/ghs
                        $exchange = get_default_currency_exchange($cur1);
                        $ticker = get_latest_ticker($exchange, $cur2, $cur1);
                        $rate = $ticker['last_trade'];
                        $pair = $cur2 . $cur1;
                    } else {
                        // btc/usd
                        $exchange = get_default_currency_exchange($cur1);
                        $ticker = get_latest_ticker($exchange, $cur1, $cur2);
                        $rate = $ticker['last_trade'] == 0 ? 0 : 1 / $ticker['last_trade'];
                        $pair = $cur1 . $cur2;
                    }
                } else {
                    // first have to convert to btc and then to the target currency
                    if (!is_fiat_currency($cur1)) {
                        // ltc/? and ghs/?
                        $exchange = array(get_default_currency_exchange($cur1));
                        $ticker = get_latest_ticker($exchange[0], 'btc', $cur1);
                        $rate = $ticker['last_trade'];
                        $pair = array('btc' . $cur1);
                    } else {
                        // usd/?
                        $exchange = array(get_default_currency_exchange($cur1));
                        $ticker = get_latest_ticker($exchange[0], $cur1, 'btc');
                        $rate = $ticker['last_trade'] == 0 ? 0 : 1 / $ticker['last_trade'];
                        $pair = array($cur1 . 'btc');
                    }
                    // and then to the second currency
                    if (!is_fiat_currency($cur2)) {
                        // ?/ltc and ?/ghs
                        $exchange[] = get_default_currency_exchange($cur2);
                        $ticker = get_latest_ticker($exchange[1], 'btc', $cur2);
                        $rate = $ticker['last_trade'] == 0 ? 0 : $rate / $ticker['last_trade'];
                        $pair[] = 'btc' . $cur2;
                    } else {
                        // ?/usd
                        $exchange[] = get_default_currency_exchange($cur2);
                        $ticker = get_latest_ticker($exchange[1], $cur2, 'btc');
                        $rate = $rate * $ticker['last_trade'];
                        $pair[] = $cur2 . 'btc';
                    }
                }
            }
            $rates[$cur1 . '_' . $cur2] = array('rate' => $rate, 'exchanges' => is_array($exchange) ? get_exchange_name($exchange[0]) . " and " . get_exchange_name($exchange[1]) : get_exchange_name($exchange));
            if (is_array($exchange)) {
                $rates[$cur1 . '_' . $cur2]['exchange1'] = get_exchange_name($exchange[0]);
                $rates[$cur1 . '_' . $cur2]['exchange2'] = get_exchange_name($exchange[1]);
                if ($with_extra) {
                    $rates[$cur1 . '_' . $cur2]['pair1'] = $pair[0];
                    $rates[$cur1 . '_' . $cur2]['pair2'] = $pair[1];
                    $rates[$cur1 . '_' . $cur2]['url1'] = absolute_url(url_for('historical', array('id' => $exchange[0] . '_' . $pair[0] . '_daily')));
                    // TODO add analytics
                    $rates[$cur1 . '_' . $cur2]['url2'] = absolute_url(url_for('historical', array('id' => $exchange[0] . '_' . $pair[1] . '_daily')));
                }
            } else {
                $rates[$cur1 . '_' . $cur2]['exchange1'] = get_exchange_name($exchange);
                if ($with_extra) {
                    $rates[$cur1 . '_' . $cur2]['pair1'] = $pair;
                    $rates[$cur1 . '_' . $cur2]['url1'] = absolute_url(url_for('historical', array('id' => $exchange . '_' . $pair . '_daily')));
                    // TODO add analytics
                }
            }
        }
    }
    return $rates;
}