$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);
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); }