diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index ea5531c..86dc468 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -27,6 +27,7 @@ function BackendPricesUpdate() updateNovaMarkets(); updateCoinExchangeMarkets(); updateCoinsMarketsMarkets(); + updateStocksExchangeMarkets(); updateTradeSatoshiMarkets(); updateShapeShiftMarkets(); @@ -1339,6 +1340,53 @@ function updateCoinsMarketsMarkets() } } +function updateStocksExchangeMarkets() +{ + $exchange = 'stocksexchange'; + if (exchange_get($exchange, 'disabled')) return; + + $list = stocksexchange_api_query('ticker'); + if(empty($list) || !is_array($list)) return; + foreach($list as $m) + { + $e = explode('_', $m->market_name); + $symbol = strtoupper($e[0]); $base = $e[1]; + if($base != 'BTC') continue; + + $coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol)); + if(!$coin) continue; + + $market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange' AND IFNULL(base_coin,'') IN ('','BTC')"); + if(!$market) continue; + + $symbol = $coin->getOfficialSymbol(); + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + $market->disabled = ($m->bid == 0); + + $price2 = ((double)$m->ask + (double)$m->bid)/2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, (double)$m->bid); + $market->priority = -1; // not ready for trading + $market->txfee = $m->sell_fee_percent; + + //debuglog("$exchange: $symbol price set to ".bitcoinvaluetoa($market->price)); + $market->pricetime = time(); // $m->updated_time; + $market->save(); + + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->save(); + } + } +} + function updateTradeSatoshiMarkets() { $exchange = 'tradesatoshi'; diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 00c987f..8e7bdf9 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -15,6 +15,7 @@ function updateRawcoins() exchange_set_default('coinsmarkets', 'disabled', true); exchange_set_default('jubi', 'disabled', true); exchange_set_default('nova', 'disabled', true); + exchange_set_default('stocksexchange', 'disabled', true); exchange_set_default('tradesatoshi', 'disabled', true); settings_prefetch_all(); @@ -225,6 +226,23 @@ function updateRawcoins() } } + if (!exchange_get('stocksexchange', 'disabled')) { + $list = stocksexchange_api_query('markets'); + if(is_array($list)) + { + dborun("UPDATE markets SET deleted=true WHERE name='stocksexchange'"); + foreach($list as $item) { + if ($item->partner != 'BTC') + continue; + if ($item->active == false) + continue; + $symbol = strtoupper($item->currency); + $name = trim($item->currency_long); + updateRawCoin('stocksexchange', $symbol, $name); + } + } + } + if (!exchange_get('empoex', 'disabled')) { $list = empoex_api_query('marketinfo'); if(is_array($list)) diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index 1df219b..431999d 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -33,6 +33,7 @@ require_once("nova.php"); require_once("coinexchange.php"); require_once("coinsmarkets.php"); require_once("cryptowatch.php"); +require_once("stocksexchange.php"); require_once("tradesatoshi.php"); /* Format an exchange coin Url */ @@ -101,6 +102,8 @@ function getMarketUrl($coin, $marketName) $url = "https://www.livecoin.net/trade/?currencyPair={$symbol}%2F{$base}"; else if($market == 'nova') $url = "https://novaexchange.com/market/{$base}_{$symbol}/"; + else if($market == 'stocksexchange') + $url = "https://stocks.exchange/trade/$symbol/$base"; else if($market == 'tradesatoshi') $url = "https://tradesatoshi.com/Exchange?market={$symbol}_{$base}"; else if($market == 'yobit') diff --git a/web/yaamp/core/exchange/stocksexchange.php b/web/yaamp/core/exchange/stocksexchange.php new file mode 100644 index 0000000..13682e5 --- /dev/null +++ b/web/yaamp/core/exchange/stocksexchange.php @@ -0,0 +1,64 @@ +$symbol)); + if(!$coin) return false; + $pair = strtoupper($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 = strtoupper($symbol).'_BTC'; + if (!empty($market->base_coin)) $pair = strtoupper($symbol).'_'.$market->base_coin; + } + + $t1 = microtime(true); + $tickers = stocksexchange_api_query('ticker'); + if(empty($tickers) || !is_array($tickers)) return false; + foreach ($tickers as $t) { + if ($t->market_name == $pair) $ticker = $t; + } + if (!isset($ticker)) return false; + + $price2 = ($ticker->bid+$ticker->ask)/2; + $market->price = AverageIncrement($market->price, $ticker->bid); + $market->price2 = AverageIncrement($market->price2, $price2); + $market->pricetime = time(); + $market->save(); + + $apims = round((microtime(true) - $t1)*1000,3); + user()->setFlash('message', "$exchange $symbol price updated in $apims ms"); + + return true; +}