From a30feff2d2d79a2f3a8ef61ff8dc64d6823bd519 Mon Sep 17 00:00:00 2001 From: Tristian Date: Mon, 27 Mar 2017 19:02:31 -0400 Subject: [PATCH] Add 'sellonbid' for Livecoin (#99) * Add 'sellonbid' for Livecoin * Remove extraneous bracket * Upgrade Livecoin priority * Remove duplicate variable name --- web/yaamp/core/backend/markets.php | 2 +- web/yaamp/core/trading/livecoin_trading.php | 72 +++++++-------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 871e57d..9bba248 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -1045,7 +1045,7 @@ function updateLiveCoinMarkets() $market->price = AverageIncrement($market->price, $ticker->best_bid); $market->price2 = AverageIncrement($market->price2, $ticker->best_ask); $market->txfee = 0.2; - $market->priority = -1; // not ready for trading + $market->priority = 0; $market->pricetime = time(); if (floatval($ticker->volume) > 0.01) diff --git a/web/yaamp/core/trading/livecoin_trading.php b/web/yaamp/core/trading/livecoin_trading.php index 920bf39..f3cfa14 100644 --- a/web/yaamp/core/trading/livecoin_trading.php +++ b/web/yaamp/core/trading/livecoin_trading.php @@ -101,6 +101,10 @@ function doLiveCoinTrading($quick = false) $flushall = false; } + $min_btc_trade = exchange_get($exchange, 'trade_min_btc', 0.0001); + $sell_ask_pct = exchange_get($exchange, 'trade_sell_ask_pct', 1.05); + $cancel_ask_pct = exchange_get($exchange, 'trade_cancel_ask_pct', 1.20); + // upgrade orders $coins = getdbolist('db_coins', "enable=1 AND IFNULL(dontsell,0)=0 AND id IN (SELECT DISTINCT coinid FROM markets WHERE name='livecoin')"); foreach ($coins as $coin) { @@ -177,13 +181,13 @@ function doLiveCoinTrading($quick = false) } foreach ($balances as $balance) { - if ($balance->type != 'total') { + if ($balance->type != 'available') { continue; } $amount = $balance->value; $symbol = $balance->currency; - if (!$amount || $symbol == 'BTC') { + if (!$balance || $symbol == 'BTC') { continue; } @@ -207,59 +211,27 @@ function doLiveCoinTrading($quick = false) continue; } + sleep(1); + $pair = "$symbol/BTC"; - $maxprice = 0; - $maxamount = 0; - - sleep(1); - $orders = $livecoin->getOrderBook($pair); - - if (!empty($orders) && !empty($orders->bids)) { - foreach ($orders->bids as $order) { - if ($order[0] > $maxprice) { - $maxprice = $order[0]; - $maxamount = $order[1]; - } - } - } - - if ($amount >= $maxamount && $maxamount*$maxprice > $min_btc_trade) { - $sellprice = bitcoinvaluetoa($maxprice); - debuglog("LiveCoin: Selling market $pair, $maxamount, $sellprice"); - sleep(1); - - // This needs to be simplified. - // Make sure API methods return a value? - $res = $livecoin->sellLimit($pair, $sellprice, $maxamount); - if (!$res) { - debuglog('LiveCoin: Sell failed'); - } else { - $success = 'false'; - if (isset($res->success)) { - $success = $res->success; - } - if ($success == 'false') { - debuglog('LiveCoin: Sell failed'); - } else { - $amount -= $maxamount; - } - } - sleep(1); - } - - sleep(1); $ticker = $livecoin->getTickerInfo($pair); - if (!$ticker) { - continue; - } - $sellprice = bitcoinvaluetoa($ticker->best_ask); + if(!isset($tickers[$pair])) continue; - sleep(1); - $res = $livecoin->sellLimit($pair, $sellprice, $amount); + if($coin->sellonbid) + $sellprice = bitcoinvaluetoa($ticker->best_bid); + else + $sellprice = bitcoinvaluetoa($ticker->best_ask * $sell_ask_pct); - if (!($res->success == 'true' && $res->added == 'true')) { - continue; + if ($amount*$sellprice > $min_btc_trade) { + debuglog("LiveCoin: Selling market $pair, $sellprice, $sellprice"); + sleep(1); + + $res = $livecoin->sellLimit($pair, $sellprice, $amount); + if (!$res->success == 'true' && $res->added == 'true') { + debuglog('LiveCoin: Sell failed'); + continue; + } } $db_order = new db_orders;