Ejemplo n.º 1
0
function query_exchanges($query_time, $tolerance, $btc_usd, $nbt_cny, $nbt_eur)
{
    $total_ask = 0;
    $total_bid = 0;
    $total_both = 0;
    include "config.php";
    $poloniex_btc_nbt = get_poloniex_btc_nbt($tolerance, $btc_usd);
    $bittrex_btc_nbt = get_bittrex_btc_nbt($tolerance, $btc_usd);
    $bter_nbt_btc = get_bter_nbt_btc($tolerance, $btc_usd);
    $bter_nbt_cny = get_bter_nbt_cny($tolerance, $nbt_cny);
    $hitbtc_nbt_btc = get_hitbtc_nbt_btc($tolerance, $btc_usd);
    $southx_btc_nbt = get_southx_btc_nbt($tolerance, $btc_usd);
    $southx_nbt_usd = get_southx_nbt_usd($tolerance);
    #$cryptsy_nbt_btc=get_cryptsy_nbt_btc($tolerance, $btc_usd); - defunc
    #$cryptsy_nbt_usd=get_cryptsy_nbt_usd(1.6); - defunc
    $ccedk_nbt_usd = get_ccedk_nbt_usd($tolerance);
    $ccedk_nbt_btc = get_ccedk_nbt_btc($tolerance, $btc_usd);
    $ccedk_nbt_eur = get_ccedk_nbt_eur($tolerance, $nbt_eur);
    $nulagoon_btc_nbt = get_nulagoon_btc_nbt($tolerance, $btc_usd);
    //write exchanges into walls_data.dat
    $data = array('timestamp' => $query_time, 'btc_usd' => "{$btc_usd}", 'exchanges' => array(array('pair' => 'poloniex_btc_nbt', 'amount' => $poloniex_btc_nbt), array('pair' => 'bittrex_btc_nbt', 'amount' => $bittrex_btc_nbt), array('pair' => 'bter_nbt_btc', 'amount' => $bter_nbt_btc), array('pair' => 'bter_nbt_cny', 'amount' => $bter_nbt_cny), array('pair' => 'hitbtc_nbt_btc', 'amount' => $hitbtc_nbt_btc), array('pair' => 'southx_btc_nbt', 'amount' => $southx_btc_nbt), array('pair' => 'southx_nbt_usd', 'amount' => $southx_nbt_usd), array('pair' => 'ccedk_nbt_usd', 'amount' => $ccedk_nbt_usd), array('pair' => 'ccedk_nbt_btc', 'amount' => $ccedk_nbt_btc), array('pair' => 'ccedk_nbt_eur', 'amount' => $ccedk_nbt_eur), array('pair' => 'nulagoon_btc_nbt', 'amount' => $nulagoon_btc_nbt)));
    foreach ($data["exchanges"] as $line) {
        $total_ask = $total_ask + $line["amount"]["ask_total"];
        $total_bid = $total_bid + $line["amount"]["bid_total"];
    }
    $total_both = $total_ask + $total_bid;
    $total_ask_percent = round($total_ask / $total_both * 100, 2);
    $total_bid_percent = round($total_bid / $total_both * 100, 2);
    $total_both_percent = $total_ask_percent + $total_bid_percent;
    $totals = array('totals' => array('total_ask' => $total_ask, 'total_bid' => $total_bid, 'total_both' => $total_both, 'total_ask_percent' => $total_ask_percent, 'total_bid_percent' => $total_bid_percent, 'total_both_percent' => $total_both_percent));
    $data = array_replace_recursive($data, $totals);
    #get avgs
    $var = get_avg(15);
    #15 minutes
    $var = json_encode($var);
    file_put_contents($data_15, $var, LOCK_EX);
    $var = get_avg(240);
    #4 hours
    $var = json_encode($var);
    file_put_contents($data_4h, $var, LOCK_EX);
    #calculate ma 15
    $avg15 = calculate_ma($data_15);
    $avg15_array = array('15min_avg' => $avg15);
    $data = array_replace_recursive($data, $avg15_array);
    #calculate ma 4h
    $avg4h = calculate_ma($data_4h);
    $avg4h_array = array('4h_avg' => $avg4h);
    $data = array_replace_recursive($data, $avg4h_array);
    #create and write final json
    $new_json = json_encode($data);
    $current = $new_json . "\n";
    file_put_contents($data_file, $current, FILE_APPEND | LOCK_EX);
    return $new_json;
}
Ejemplo n.º 2
0
function query_exchanges()
{
    $file = 'data/alix_data.dat';
    $btc_usd = get_btc_usd();
    $poloniex_btc_nbt_24 = get_poloniex_btc_nbt();
    $bittrex_btc_nbt_24 = get_bittrex_btc_nbt();
    $southx_btc_nbt_24 = get_southx_btc_nbt($btc_usd);
    $southx_nbt_usd_24 = get_southx_nbt_usd();
    #$cryptsy_nbt_btc_24=get_cryptsy_nbt_btc(); - defunc
    #$cryptsy_nbt_usd_24=get_cryptsy_nbt_usd(); - defunc
    $bter_nbt_cny_24 = get_bter_nbt_cny();
    $bter_nbt_btc_24 = get_bter_nbt_btc();
    $ccedk_nbt_usd_24 = get_ccedk_nbt_usd();
    $ccedk_nbt_btc_24 = get_ccedk_nbt_btc();
    $ccedk_nbt_ppc_24 = get_ccedk_nbt_ppc();
    $ccedk_nbt_eur_24 = get_ccedk_nbt_eur();
    $hitbtc_nbt_btc_24 = get_hitbtc_nbt_btc();
    $nulagoon_btc_nbt_24 = get_nulagoon_btc_nbt();
    //write exchanges into alix_data.dat
    $data = array('timestamp' => time(), 'btc_usd' => "{$btc_usd}", 'exchanges' => array(array('pair' => 'poloniex_btc_nbt', 'amount' => "{$poloniex_btc_nbt_24}"), array('pair' => 'bittrex_btc_nbt', 'amount' => "{$bittrex_btc_nbt_24}"), array('pair' => 'southx_btc_nbt', 'amount' => "{$southx_btc_nbt_24}"), array('pair' => 'southx_nbt_usd', 'amount' => "{$southx_nbt_usd_24}"), array('pair' => 'bter_nbt_cny', 'amount' => "{$bter_nbt_cny_24}"), array('pair' => 'bter_nbt_btc', 'amount' => "{$bter_nbt_btc_24}"), array('pair' => 'ccedk_nbt_usd', 'amount' => "{$ccedk_nbt_usd_24}"), array('pair' => 'ccedk_nbt_btc', 'amount' => "{$ccedk_nbt_btc_24}"), array('pair' => 'ccedk_nbt_ppc', 'amount' => "{$ccedk_nbt_ppc_24}"), array('pair' => 'ccedk_nbt_eur', 'amount' => "{$ccedk_nbt_eur_24}"), array('pair' => 'hitbtc_nbt_btc', 'amount' => "{$hitbtc_nbt_btc_24}"), array('pair' => 'nulagoon_btc_nbt', 'amount' => "{$nulagoon_btc_nbt_24}")));
    $new_json = json_encode($data);
    $current = file_get_contents($file);
    $current .= $new_json . "\n";
    file_put_contents($file, $current, PHP_EOL | LOCK_EX);
}