function doPoloniexTrading() { // debuglog('-------------- doPoloniexTrading()'); $flushall = rand(0, 4) == 0; $poloniex = new poloniex(); $tickers = $poloniex->get_ticker(); if (!$tickers) { return; } // upgrade orders $coins = getdbolist('db_coins', "enable and id in (select distinct coinid from markets where name='poloniex')"); foreach ($coins as $coin) { if ($coin->dontsell) { continue; } $pair = "BTC_{$coin->symbol}"; if (!isset($tickers[$pair])) { continue; } $orders = $poloniex->get_open_orders($pair); if (!$orders || !isset($orders[0])) { dborun("delete from orders where coinid={$coin->id} and market='poloniex'"); continue; } foreach ($orders as $order) { if (!isset($order['orderNumber'])) { debuglog($order); continue; } if ($order['rate'] > $tickers[$pair]['lowestAsk'] + 5.0E-8 || $flushall) { // debuglog("poloniex cancel order for $pair {$order['orderNumber']}"); $poloniex->cancel_order($pair, $order['orderNumber']); $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order['orderNumber'])); if ($db_order) { $db_order->delete(); } sleep(1); } else { $db_order = getdbosql('db_orders', "uuid=:uuid", array(':uuid' => $order['orderNumber'])); if ($db_order) { continue; } debuglog("poloniex adding order {$coin->symbol}"); $db_order = new db_orders(); $db_order->market = 'poloniex'; $db_order->coinid = $coin->id; $db_order->amount = $order['amount']; $db_order->price = $order['rate']; $db_order->ask = $tickers[$pair]['lowestAsk']; $db_order->bid = $tickers[$pair]['highestBid']; $db_order->uuid = $order['orderNumber']; $db_order->created = time(); $db_order->save(); } } $list = getdbolist('db_orders', "coinid={$coin->id} and market='poloniex'"); foreach ($list as $db_order) { $found = false; foreach ($orders as $order) { if (!isset($order['orderNumber'])) { debuglog($order); continue; } if ($order['orderNumber'] == $db_order->uuid) { $found = true; break; } } if (!$found) { debuglog("poloniex deleting order {$coin->name} {$db_order->amount}"); $db_order->delete(); } } } // add orders $savebalance = getdbosql('db_balances', "name='poloniex'"); $balances = $poloniex->get_balances(); foreach ($balances as $symbol => $balance) { if (!$balance) { continue; } if ($symbol == 'BTC') { $savebalance->balance = $balance; $savebalance->save(); continue; } $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol)); if (!$coin || $coin->dontsell) { continue; } $market = getdbosql('db_markets', "coinid={$coin->id} and name='poloniex'"); if ($market) { $market->lasttraded = time(); $market->save(); } $pair = "BTC_{$symbol}"; if (!isset($tickers[$pair])) { continue; } $sellprice = $tickers[$pair]['highestBid']; if ($balance * $sellprice < 0.0001) { continue; } // debuglog("poloniex selling $pair, $sellprice, $balance"); $res = $poloniex->sell($pair, $sellprice, $balance); if (!isset($res['orderNumber'])) { debuglog($res, 5); continue; } if (!isset($tickers[$pair])) { continue; } $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol)); if (!$coin) { continue; } $db_order = new db_orders(); $db_order->market = 'poloniex'; $db_order->coinid = $coin->id; $db_order->amount = $balance; $db_order->price = $sellprice; $db_order->ask = $tickers[$pair]['lowestAsk']; $db_order->bid = $tickers[$pair]['highestBid']; $db_order->uuid = $res['orderNumber']; $db_order->created = time(); $db_order->save(); } if ($savebalance->balance >= 0.2) { $btcaddr = YAAMP_BTCADDRESS; //'14LS7Uda6EZGXLtRrFEZ2kWmarrxobkyu9'; $amount = $savebalance->balance; // - 0.0002; debuglog("poloniex withdraw {$amount} to {$btcaddr}"); sleep(1); $res = $poloniex->withdraw('BTC', $amount, $btcaddr); debuglog($res); if ($res && $res->success) { $withdraw = new db_withdraws(); $withdraw->market = 'poloniex'; $withdraw->address = $btcaddr; $withdraw->amount = $amount; $withdraw->time = time(); // $withdraw->uuid = $res->result->uuid; $withdraw->save(); } } // debuglog('-------------- doPoloniexTrading() done'); }
function updatePoloniexMarkets() { $poloniex = new poloniex(); $tickers = $poloniex->get_ticker(); if (!$tickers) { return; } foreach ($tickers as $symbol => $ticker) { $a = explode('_', $symbol); if (!isset($a[1])) { continue; } if ($a[0] != 'BTC') { continue; } $symbol = $a[1]; $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol)); if (!$coin || !$coin->installed) { continue; } $market = getdbosql('db_markets', "coinid={$coin->id} and name='poloniex'"); if (!$market) { $market = new db_markets(); $market->coinid = $coin->id; $market->name = 'poloniex'; } if (empty($market->deposit_address) && $coin->installed) { $poloniex->generate_address($coin->symbol); } $price2 = ($ticker['highestBid'] + $ticker['lowestAsk']) / 2; $market->price2 = AverageIncrement($market->price2, $price2); $market->price = AverageIncrement($market->price, $ticker['highestBid']); $market->save(); } $list = $poloniex->get_deposit_addresses(); foreach ($list as $symbol => $item) { if ($symbol == 'BTC') { continue; } $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol' => $symbol)); if (!$coin) { continue; } $market = getdbosql('db_markets', "coinid={$coin->id} and name='poloniex'"); if (!$market) { continue; } $market->deposit_address = $item; $market->save(); } }
<div class="panel-tools"> <div class="dropdown"> <a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey"> <i class="fa fa-cog"></i> </a> <ul class="dropdown-menu dropdown-light pull-right" role="menu"> <li><a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>Collapse</span> </a></li> <li><a class="panel-refresh" href="#"> <i class="fa fa-refresh"></i> <span>Refresh</span> </a></li> <li><a class="panel-config" href="#panel-config" data-toggle="modal"> <i class="fa fa-wrench"></i> <span>Configurations</span> </a></li> <li><a class="panel-expand" href="#"> <i class="fa fa-expand"></i> <span>Fullscreen</span> </a></li> </ul> </div> <a class="btn btn-xs btn-link panel-close" href="#"> <i Class="fa fa-times"></i> </a> </div> <div style="height:220px; overflow:auto;" class="panel-body"> <div class="table-responsive"> <?php $tricker = $poloniex->get_ticker($pair = "ALL"); ?> <table class="table table-hover" id="sample-table-1" style="height: 10px;"> <thead> <tr><th><i class="fa fa-star"></i></th> <th><small>Coin</small></th> <th><small>Price</small></th> <th><small>Volume</small></th> <th><small>Change</small></th> <th><small>Name</small></th> </tr> </thead> <tbody> <?php foreach ($tricker as $key => $value) { $match = strstr($key, '_', true);