diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 871e57da2..f5ae34dd6 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -23,6 +23,7 @@ function BackendPricesUpdate() updateJubiMarkets(); updateLiveCoinMarkets(); updateNovaMarkets(); + updateCoinExchangeMarkets(); updateShapeShiftMarkets(); updateOtherMarkets(); @@ -1087,6 +1088,46 @@ function updateLiveCoinMarkets() } } +function updateCoinExchangeMarkets() +{ + $exchange = 'coinexchange'; + if (exchange_get($exchange, 'disabled')) return; + + $list = coinexchange_api_query('getmarkets'); + if(!is_object($list)) return; + $markets = coinexchange_api_query('getmarketsummaries'); + if(!is_object($markets)) return; + foreach($list->result as $currency) + { + $symbol = objSafeVal($currency,'MarketAssetCode',''); + $exchid = objSafeVal($currency,'MarketAssetID',0); + if(empty($symbol) || !$exchid || $symbol == 'BTC') continue; + + $coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol)); + if(!$coin) continue; + + $market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'"); + if(!$market) continue; + + if($market->disabled < 9) $market->disabled = !$currency->Active; + + $market->save(); + + if($market->disabled || $market->deleted) continue; + + foreach ($markets->result as $m) { + if ($m->MarketID == $exchid) { + $price2 = ($m->BidPrice + $m->AskPrice)/2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, $m->BidPrice); + $market->pricetime = time(); + $market->save(); + //debuglog("$exchange: $symbol price set to ".bitcoinvaluetoa($market->price)); + } + } + } +} + // todo: store min/max txs limits function updateShapeShiftMarkets() { diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index bfb45bb04..7a80d2f7d 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -96,6 +96,21 @@ function updateRawcoins() } } + if (!exchange_get('coinexchange', 'disabled')) { + $list = coinexchange_api_query('getmarkets'); + if(isset($list->result) && !empty($list->result)) + { + dborun("UPDATE markets SET deleted=true WHERE name='coinexchange'"); + foreach($list->result as $item) { + if ($item->BaseCurrencyCode != 'BTC') + continue; + $symbol = $item->MarketAssetCode; + $label = objSafeVal($item, 'MarketAssetName'); + updateRawCoin('coinexchange', $symbol, $label); + } + } + } + if (!exchange_get('cryptopia', 'disabled')) { $list = cryptopia_api_query('GetMarkets'); if(isset($list->Data)) @@ -249,7 +264,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') } } - if ($marketname == 'nova' || $marketname == 'askcoin') { + if ($marketname == 'nova' || $marketname == 'askcoin' || $marketname == 'coinexchange') { // don't polute too much the db return; } diff --git a/web/yaamp/core/exchange/coinexchange.php b/web/yaamp/core/exchange/coinexchange.php new file mode 100644 index 000000000..5e289b563 --- /dev/null +++ b/web/yaamp/core/exchange/coinexchange.php @@ -0,0 +1,38 @@ +