From c3a70f830714385eb5939d827e3bdef8da5af419 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 12 Jul 2015 15:33:16 +0200 Subject: [PATCH] add banx.io markets api --- web/yaamp/core/backend/markets.php | 52 +++++++++++++++++++++++----- web/yaamp/core/backend/rawcoins.php | 25 ++++++++++--- web/yaamp/core/exchange/banxio.php | 35 +++++++++++++++++++ web/yaamp/core/exchange/exchange.php | 1 + 4 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 web/yaamp/core/exchange/banxio.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 9356386..4d0fcb4 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -4,8 +4,6 @@ function BackendPricesUpdate() { // debuglog(__FUNCTION__); - updateAlcurexMarkets(); - updateCryptopiaMarkets(); updateBittrexMarkets(); updateCryptsyMarkets(); updateCCexMarkets(); @@ -13,6 +11,10 @@ function BackendPricesUpdate() updatePoloniexMarkets(); updateYobitMarkets(); updateJubiMarkets(); + updateAlcurexMarkets(); + updateCryptopiaMarkets(); + updateBanxioMarkets(); + $list2 = getdbolist('db_coins', "installed and symbol2 is not null"); foreach($list2 as $coin2) @@ -110,11 +112,11 @@ function getBestMarket($coin) ORDER BY price DESC"); } - // note: you can add a record in market to hide this debug warning - if (!$market && $coin->enable) + if (!$market && empty($coin->market)) { debuglog("best market for {$coin->symbol} is unknown"); - //else - // debuglog("best market for {$coin->symbol} is {$market->name}"); + $coin->market = 'unknown'; + $coin->save(); + } return $market; } @@ -582,7 +584,7 @@ function updateAlcurexMarkets() $coin->price2 = $market->price2; $coin->save(); } -// debuglog("alcurex update $coin->symbol: $market->price $market->price2"); +// debuglog("alcurex: $pair $market->price ".bitcoinvaluetoa($market->price2)); } } } @@ -613,10 +615,44 @@ function updateCryptopiaMarkets() $coin->price2 = $market->price2; $coin->save(); } -// debuglog("cryptopia update $coin->symbol: $market->price $market->price2"); +// debuglog("cryptopia: $pair $market->price ".bitcoinvaluetoa($market->price2)); break; } } } } +function updateBanxioMarkets() +{ + $data = banx_public_api_query('getmarketsummaries'); + if(!$data || !is_array($data->result)) return; + + $list = getdbolist('db_markets', "name='banx'"); + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin || !$coin->installed) continue; + + $pair = strtoupper($coin->symbol).'-BTC'; + foreach ($data->result as $ticker) { + if ($ticker->marketname === $pair) { + $market->price = AverageIncrement($market->price, $ticker->bid); + $market->price2 = AverageIncrement($market->price2, $ticker->last); +// debuglog("banx: $pair {$ticker->bid} {$ticker->last} => {$market->price} {$market->price2}"); + if (intval($ticker->dayvolume) > 1) + $market->save(); + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->save(); + } + if ($coin->name == 'unknown' && !empty($market->currencylong)) { + $coin->name = $market->currencylong; + $coin->save(); + debuglog("banx: update $symbol name {$coin->name}"); + } + break; + } + } + } +} diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index b334115..9b2d156 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -56,7 +56,7 @@ function updateRawcoins() $res = yobit_api_query('info'); if($res) { - dborun("update markets set deleted=true where name='yobit'"); + dborun("UPDATE markets SET deleted=true WHERE name='yobit'"); foreach($res->pairs as $i=>$item) { $e = explode('_', $i); @@ -68,7 +68,7 @@ function updateRawcoins() $list = cryptopia_api_query('GetMarkets'); if(isset($list->Data)) { - dborun("update markets set deleted=true where name='cryptopia'"); + dborun("UPDATE markets SET deleted=true WHERE name='cryptopia'"); foreach($list->Data as $item) { $e = explode('/', $item->Label); if (strtoupper($e[1]) !== 'BTC') @@ -78,11 +78,10 @@ function updateRawcoins() } } - $list = alcurex_api_query('market','?info=on'); if(isset($list->MARKETS)) { - dborun("update markets set deleted=true where name='alcurex'"); + dborun("UPDATE markets SET deleted=true WHERE name='alcurex'"); foreach($list->MARKETS as $item) { $e = explode('_', $item->Pair); $symbol = strtoupper($e[0]); @@ -90,6 +89,24 @@ function updateRawcoins() } } + $list = banx_simple_api_query('marketsv2'); + if(isset($list) && is_array($list)) + { + dborun("UPDATE markets SET deleted=true WHERE name='banx'"); + foreach($list as $item) { + $e = explode('/', $item->market); + $base = strtoupper($e[1]); + if ($base != 'BTC') + continue; + $symbol = strtoupper($e[0]); + if ($symbol == 'ATP') + continue; + $name = explode('/',$item->marketname); + updateRawCoin('banx', $symbol, $name[0]); + //debuglog("banx: $symbol {$name[0]}"); + } + } + ////////////////////////////////////////////////////////// dborun("delete from markets where deleted"); diff --git a/web/yaamp/core/exchange/banxio.php b/web/yaamp/core/exchange/banxio.php new file mode 100644 index 0000000..83a0966 --- /dev/null +++ b/web/yaamp/core/exchange/banxio.php @@ -0,0 +1,35 @@ +