$content_wall = file_get_contents($url_wall); $wall_json = json_decode($content_wall, true); $url_price = 'https://bitbucket.org/henry_nu/data/downloads/rd.json'; $content_price = file_get_contents($url_price); $price_json = json_decode($content_price, true); $ask_total = 0; $bid_total = 0; if (!check_value($wall_json["bal"]["NBT"]) && !check_value($price_json["ask"])) { writelog("nulagoon_btc_nbt", "querry_error", "unresolved"); } else { $tolerance = $btc_usd * $search_tolerance / 100; $ask_price = $btc_usd + $tolerance; $bid_price = $btc_usd - $tolerance; $ask_value = $wall_json["bal"]["NBT"]; $bid_value = $wall_json["bal"]["BTC"] * $btc_usd; $wall_price_ask = $price_json["ask"]; $wall_price_bid = $price_json["bid"]; if ($wall_price_ask <= $ask_price) { $ask_total = $ask_value; } if ($wall_price_bid >= $bid_price) { $bid_total = $bid_value; } } $total = $ask_total + $bid_total; $orderbook = array('tolerance' => $search_tolerance, 'ask_total' => $ask_total, 'bid_total' => $bid_total, 'total' => $total); return $orderbook; } $btc_usd = get_btc_usd(); $json = get_nulagoon_btc_nbt(1.5, $btc_usd); print_r($json);
<?php include "logger.php"; function check_value($value) { $return = true; if (!is_numeric($value)) { $return = false; } return $return; } function get_nulagoon_btc_nbt() { $url_price = 'https://bitbucket.org/henry_nu/data/downloads/rd.json'; $content_price = file_get_contents($url_price); $price_json = json_decode($content_price, true); if (!check_value($price_json["24vol"][0])) { writelog("nulagoon_btc_nbt", "querry_error", "unresolved"); $nulagoon_btc_nbt_24 = "-1"; } else { $nulagoon_btc_nbt_24 = $price_json["24vol"][0]; } return $nulagoon_btc_nbt_24; } $jop = get_nulagoon_btc_nbt(); print_r($jop);
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; }
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); }