0 && strrpos($res,'500 Error')) { $res = substr($res, 0, $p+2); debuglog("cryptopia: $method stripped to fix json"); } $result = json_decode($res); if(!is_object($result) && !is_array($result)) { $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (strpos($res,'Maintenance')) debuglog("cryptopia: $method failed (Maintenance)"); else debuglog("cryptopia: $method failed ($status) ".strip_data($res)); } curl_close($ch); return $result; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // manual update of one market function cryptopia_update_market($market) { $exchange = 'cryptopia'; if (is_string($market)) { $symbol = $market; $coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol)); if(!$coin) return false; $pair = $symbol.'_BTC'; $market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'"); if(!$market) return false; } else if (is_object($market)) { $coin = getdbo('db_coins', $market->coinid); if(!$coin) return false; $symbol = $coin->getOfficialSymbol(); $pair = $symbol.'_BTC'; if (!empty($market->base_coin)) $pair = $symbol.'_'.$market->base_coin; } $t1 = microtime(true); $m = cryptopia_api_query('GetMarket', $pair); if(!is_object($m) || !$m->Success || !is_object($m->Data)) return false; $ticker = $m->Data; $price2 = ($ticker->BidPrice+$ticker->AskPrice)/2; $market->price2 = AverageIncrement($market->price2, $price2); $market->price = AverageIncrement($market->price, $ticker->BidPrice*0.98); $market->marketid = $ticker->TradePairId; $market->pricetime = time(); $market->save(); $apims = round((microtime(true) - $t1)*1000,3); user()->setFlash('message', "$exchange $symbol price updated in $apims ms"); return true; }