Esempio n. 1
0
 /**
  * If we have disabled an account, it should not appear in {@link get_supported_wallets()}.
  */
 function testDisabledAccountsArentWallets()
 {
     $account_data_grouped = account_data_grouped();
     $wallets = get_supported_wallets();
     $this->assertGreaterThan(0, count($account_data_grouped['Mining pools']));
     foreach ($account_data_grouped['Mining pools'] as $key => $data) {
         if ($data['disabled']) {
             $this->assertFalse(isset($wallets[$key]), "Did not expect disabled mining pool wallet '{$key}' in supported wallets");
         }
     }
     $this->assertGreaterThan(0, count($account_data_grouped['Exchanges']));
     foreach ($account_data_grouped['Exchanges'] as $key => $data) {
         if ($data['disabled']) {
             $this->assertFalse(isset($wallets[$key]), "Did not expect disabled exchange wallet '{$key}' in supported wallets");
         }
     }
     $this->assertGreaterThan(0, count($account_data_grouped['Securities']));
     foreach ($account_data_grouped['Securities'] as $key => $data) {
         if ($data['disabled']) {
             $this->assertFalse(isset($wallets[$key]), "Did not expect disabled mining pool wallet '{$key}' in supported wallets");
         }
     }
 }
Esempio n. 2
0
    $res = curl_exec($ch);
    if ($res === false) {
        throw new ExternalAPIException('Could not get reply: ' . curl_error($ch));
    }
    $dec = crypto_json_decode($res, "in request");
    if (isset($dec['errno']) && $dec['errno']) {
        throw new ExternalAPIException("Error in reply: " . htmlspecialchars($dec['msg']));
    }
    if (!isset($dec['data'])) {
        throw new ExternalAPIException("No data in reply");
    }
    return $dec['data'];
}
$balance = xchange796_query($account['api_app_id'], $account['api_key'], $account['api_secret'], 'https://796.com/v1/user/get_balance');
crypto_log(print_r($balance, true));
$get_supported_wallets = get_supported_wallets();
$currencies = $get_supported_wallets['796'];
// btc, usd
foreach ($currencies as $currency) {
    if (!isset($balance['main_wallet'][$currency])) {
        crypto_log("No main_wallet {$exchange} balance for {$currency}");
        continue;
    }
    if (!isset($balance['futures_wallet'][$currency])) {
        crypto_log("No futures_wallet {$exchange} balance for {$currency}");
        // continue;
        $balance['futures_wallet'][$currency] = 0;
    }
    // also $currency_reserved and $currency_available; we use $currency_balance
    $b = $balance['main_wallet'][$currency] + $balance['futures_wallet'][$currency];
    crypto_log($exchange . " balance for " . $currency . ": " . $b);
Esempio n. 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;
}