From 1c2a51394b8519c84d5ffab296a07da53ae273e8 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 10 Sep 2018 06:58:33 +0200 Subject: [PATCH] exchange: handle crex24 public api --- web/yaamp/core/backend/markets.php | 61 +++++++++++++++++++++++++++- web/yaamp/core/backend/rawcoins.php | 18 +++++++- web/yaamp/core/exchange/crex24.php | 26 ++++++++++++ web/yaamp/core/exchange/exchange.php | 3 ++ 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 web/yaamp/core/exchange/crex24.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index b9a332f87..fa4c60b78 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -20,6 +20,7 @@ function BackendPricesUpdate() updateKrakenMarkets(); updateKuCoinMarkets(); updateCCexMarkets(); + updateCrex24Markets(); updateCryptopiaMarkets(); updateHitBTCMarkets(); updateYobitMarkets(); @@ -975,7 +976,65 @@ function updateAlcurexMarkets() $coin->price2 = $market->price2; $coin->save(); } -// debuglog("alcurex: $pair $market->price ".bitcoinvaluetoa($market->price2)); + //debuglog("$exchange: $pair price updated to {$market->price}"); + break; + } + } + } +} + +function updateCrex24Markets() +{ + $exchange = 'crex24'; + if (exchange_get($exchange, 'disabled')) return; + + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + + $data = crex24_api_query('tickers'); + if(!is_array($data)) return; + + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + + $symbol = $coin->getOfficialSymbol(); + $pair = strtoupper($symbol).'-BTC'; + + $sqlFilter = ''; + if (!empty($market->base_coin)) { + $pair = strtoupper($symbol.'-'.$market->base_coin); + $sqlFilter = "AND base_coin='{$market->base_coin}'"; + } + + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + foreach ($data as $ticker) { + if ($ticker->instrument === $pair) { + if ($market->disabled < 9) { + $nbm = (int) dboscalar("SELECT COUNT(id) FROM markets WHERE coinid={$coin->id} $sqlFilter"); + $market->disabled = ($ticker->bid < $ticker->ask/2) && ($nbm > 1); + } + + $price2 = ($ticker->bid+$ticker->ask)/2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, $ticker->bid); + $market->pricetime = time(); // $ticker->timestamp "2018-08-31T12:48:56Z" + $market->save(); + + if (empty($coin->price) && $ticker->ask) { + $coin->price = $market->price; + $coin->price2 = $price2; + $coin->save(); + } + //debuglog("$exchange: $pair price updated to {$market->price}"); + break; } } } diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 70de461f0..2515a4063 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -38,7 +38,7 @@ function updateRawcoins() if (!exchange_get('bitz', 'disabled')) { $list = bitz_api_query('tickerall'); - + if (!empty($list)) { dborun("UPDATE markets SET deleted=true WHERE name='bitz'"); foreach($list as $c => $ticker) { $e = explode('_', $c); @@ -47,6 +47,7 @@ function updateRawcoins() $symbol = strtoupper($e[0]); updateRawCoin('bitz', $symbol); } + } } if (!exchange_get('bleutrade', 'disabled')) { @@ -64,6 +65,19 @@ function updateRawcoins() } } + if (!exchange_get('crex24', 'disabled')) { + $list = crex24_api_query('currencies'); + if(is_array($list) && !empty($list)) { + dborun("UPDATE markets SET deleted=true WHERE name='crex24'"); + foreach ($list as $currency) { + $symbol = objSafeVal($currency, 'symbol'); + $name = objSafeVal($currency, 'name'); + if ($currency->isFiat || $currency->isDelisted) continue; + updateRawCoin('crex24', $symbol, $name); + } + } + } + if (!exchange_get('poloniex', 'disabled')) { $poloniex = new poloniex; $tickers = $poloniex->get_currencies(); @@ -436,7 +450,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') } // some other to ignore... - if (in_array($marketname, array('yobit','kucoin','tradesatoshi'))) + if (in_array($marketname, array('crex24','yobit','kucoin','tradesatoshi'))) return; if (market_get($marketname, $symbol, "disabled")) { diff --git a/web/yaamp/core/exchange/crex24.php b/web/yaamp/core/exchange/crex24.php new file mode 100644 index 000000000..2808ef49d --- /dev/null +++ b/web/yaamp/core/exchange/crex24.php @@ -0,0 +1,26 @@ +