mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-09-30 07:10:35 +00:00
parent
093c884c27
commit
5cd77ae054
6 changed files with 537 additions and 182 deletions
|
@ -164,8 +164,9 @@ class ExchangeCommand extends CConsoleCommand
|
|||
echo("kraken btc: ".json_encode($balance)."\n");
|
||||
}
|
||||
if (!empty(EXCH_LIVECOIN_KEY)) {
|
||||
$balance = livecoin_api_user('payment/balance', array('currency'=>'BTC'));
|
||||
if (!is_object($balance)) echo("livecoin error\n");
|
||||
$livecoin = new LiveCoinApi;
|
||||
$balance = $livecoin->getBalances('BTC');
|
||||
if (!$balance) echo("livecoin error\n");
|
||||
else echo("livecoin btc: ".json_encode($balance)."\n");
|
||||
// {"type":"available","currency":"BTC","value":0}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ function BackendPricesUpdate()
|
|||
updateBterMarkets();
|
||||
//updateEmpoexMarkets();
|
||||
updateJubiMarkets();
|
||||
updateLivecoinMarkets();
|
||||
updateLiveCoinMarkets();
|
||||
updateNovaMarkets();
|
||||
|
||||
updateShapeShiftMarkets();
|
||||
|
@ -1015,12 +1015,13 @@ function updateEmpoexMarkets()
|
|||
}
|
||||
}
|
||||
|
||||
function updateLivecoinMarkets()
|
||||
function updateLiveCoinMarkets()
|
||||
{
|
||||
$exchange = 'livecoin';
|
||||
if (exchange_get($exchange, 'disabled')) return;
|
||||
|
||||
$markets = livecoin_api_query('exchange/ticker');
|
||||
$livecoin = new LiveCoinApi;
|
||||
$markets = $livecoin->getTickerInfo();
|
||||
if(!is_array($markets)) return;
|
||||
|
||||
$list = getdbolist('db_markets', "name='$exchange'");
|
||||
|
@ -1064,7 +1065,7 @@ function updateLivecoinMarkets()
|
|||
if(empty($market->deposit_address) && !$last_checked)
|
||||
{
|
||||
sleep(1);
|
||||
$data = livecoin_api_user('payment/get/address', array('currency'=>$coin->symbol));
|
||||
$data = $livecoin->getDepositAddress($coin->symbol);
|
||||
if(!empty($data) && objSafeVal($data, 'wallet', '') != '') {
|
||||
$addr = arraySafeVal($data, 'wallet');
|
||||
if (!empty($addr) && $addr != $market->deposit_address) {
|
||||
|
|
|
@ -173,16 +173,18 @@ function updateRawcoins()
|
|||
}
|
||||
|
||||
if (!exchange_get('livecoin', 'disabled')) {
|
||||
$list = livecoin_api_query('exchange/ticker');
|
||||
$livecoin = new LiveCoinApi;
|
||||
$list = $livecoin->getTickerInfo();
|
||||
if(is_array($list))
|
||||
{
|
||||
dborun("UPDATE markets SET deleted=true WHERE name='livecoin'");
|
||||
foreach($list as $item) {
|
||||
$e = explode('/', $item->symbol);
|
||||
$base = strtoupper($e[1]);
|
||||
if ($base != 'BTC')
|
||||
$symbol = $e[0];
|
||||
$base = $e[1];
|
||||
if ($base != 'BTC') {
|
||||
continue;
|
||||
$symbol = strtoupper($e[0]);
|
||||
}
|
||||
updateRawCoin('livecoin', $symbol);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,131 +1,234 @@
|
|||
<?php
|
||||
|
||||
// https://api.livecoin.net/exchange/ticker
|
||||
|
||||
function livecoin_api_query($method, $params='')
|
||||
class LiveCoinApi
|
||||
{
|
||||
protected $api_url = 'https://api.livecoin.net/';
|
||||
protected $api_key = EXCH_LIVECOIN_KEY;
|
||||
|
||||
$uri = "https://api.livecoin.net/$method";
|
||||
if (!empty($params))
|
||||
$uri .= "/$params";
|
||||
public $timeout = 10;
|
||||
|
||||
$ch = curl_init($uri);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
|
||||
$execResult = curl_exec($ch);
|
||||
$obj = json_decode($execResult);
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// payment/balance
|
||||
|
||||
function livecoin_api_user($method, $params=NULL)
|
||||
{
|
||||
protected function jsonAuth($url, $params=array(), $post=false)
|
||||
{
|
||||
require_once('/etc/yiimp/keys.php');
|
||||
if (!defined('EXCH_LIVECOIN_SECRET')) define('EXCH_LIVECOIN_SECRET', '');
|
||||
if (empty(EXCH_LIVECOIN_KEY) || empty(EXCH_LIVECOIN_SECRET)) return false;
|
||||
$apikey = EXCH_LIVECOIN_KEY;
|
||||
if (!defined('EXCH_LIVECOIN_SECRET')) {
|
||||
define('EXCH_LIVECOIN_SECRET', '');
|
||||
}
|
||||
if (empty(EXCH_LIVECOIN_SECRET)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$exchange = "livecoin";
|
||||
|
||||
if (empty($params)) $params = array();
|
||||
ksort($params);
|
||||
$fields = http_build_query($params, '', '&');
|
||||
$signature = strtoupper(hash_hmac('sha256', $fields, EXCH_LIVECOIN_SECRET));
|
||||
|
||||
$headers = array(
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'Api-key: '.$apikey,
|
||||
'Sign: '.$signature,
|
||||
"Api-Key: $this->api_key",
|
||||
"Sign: $signature"
|
||||
);
|
||||
|
||||
$url = "https://api.livecoin.net/$method?$fields";
|
||||
|
||||
if ($post) {
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, 'POST');
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
|
||||
} else {
|
||||
$ch = curl_init($url."?".$fields);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; YiiMP API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_ENCODING , '');
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; LiveCoin PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout/2);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||
|
||||
$res = curl_exec($ch);
|
||||
if($res === false)
|
||||
{
|
||||
$e = curl_error($ch);
|
||||
debuglog("$exchange: $e");
|
||||
curl_close($ch);
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = json_decode($res);
|
||||
if(!is_object($result) && !is_array($result)) {
|
||||
$response = curl_exec($ch);
|
||||
if ($response) {
|
||||
$a = json_decode($response);
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
debuglog("$exchange: $method failed ($status) $res");
|
||||
if (!$a) {
|
||||
debuglog("LiveCoin: Auth API failed ($status) ".strip_data($response).' '.curl_error($ch));
|
||||
}
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return $result;
|
||||
}
|
||||
return isset($a) ? $a : false;
|
||||
}
|
||||
|
||||
// untested yet
|
||||
protected function jsonGet($url, $params=array())
|
||||
{
|
||||
|
||||
function livecoin_api_post($method, $params=NULL)
|
||||
{
|
||||
require_once('/etc/yiimp/keys.php');
|
||||
if (!defined('EXCH_LIVECOIN_SECRET')) define('EXCH_LIVECOIN_SECRET', '');
|
||||
if (empty(EXCH_LIVECOIN_KEY) || empty(EXCH_LIVECOIN_SECRET)) return false;
|
||||
$apikey = EXCH_LIVECOIN_KEY;
|
||||
$fields = http_build_query($params, '', '&');
|
||||
$ch = curl_init($url."?".$fields);
|
||||
|
||||
$exchange = "livecoin";
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; LiveCoin PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout/2);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
|
||||
|
||||
$url = "https://api.livecoin.net/$method";
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if (empty($params)) $params = array();
|
||||
ksort($params);
|
||||
$postFields = http_build_query($params, '', '&');
|
||||
$signature = strtoupper(hash_hmac('sha256', $postFields, EXCH_LIVECOIN_SECRET));
|
||||
if ($response) {
|
||||
$a = json_decode($response);
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if (!$a) {
|
||||
debuglog("LiveCoin: Auth API failed ($status) ".strip_data($response).' '.curl_error($ch));
|
||||
}
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$headers = array(
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'Api-key: '.$apikey,
|
||||
'Sign: '.$signature,
|
||||
return isset($a) ? $a : false;
|
||||
}
|
||||
|
||||
// Public data
|
||||
public function getTickerInfo($pair=false)
|
||||
{
|
||||
$params = array();
|
||||
if ($pair) {
|
||||
$params['currencyPair'] = $pair;
|
||||
}
|
||||
|
||||
return $this->jsonGet($this->api_url.'/exchange/ticker', $params);
|
||||
}
|
||||
|
||||
public function getLastTrades($pair, $minorhr='false', $type='flase')
|
||||
{
|
||||
$params = array('currencyPair' => $pair,
|
||||
'minutesOrHour' => $minorhr,
|
||||
'type' => $type
|
||||
);
|
||||
|
||||
$ch = curl_init($url);
|
||||
return $this->jsonGet($this->api_url.'/exchange/last_trades', $params);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; YiiMP API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
|
||||
curl_setopt($ch, CURLOPT_ENCODING , '');
|
||||
|
||||
$res = curl_exec($ch);
|
||||
if($res === false)
|
||||
public function getOrderBook($pair, $group='false', $depth=10)
|
||||
{
|
||||
$e = curl_error($ch);
|
||||
debuglog("$exchange: $e");
|
||||
curl_close($ch);
|
||||
return false;
|
||||
$params = array('currencyPair' => $pair, 'groupByPrice' => $group, 'depth' => $depth);
|
||||
return $this->jsonGet($this->api_url.'/exchange/order_book', $params);
|
||||
}
|
||||
|
||||
$result = json_decode($res);
|
||||
if(!is_object($result) && !is_array($result)) {
|
||||
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
debuglog("$exchange: $method failed ($status) $res");
|
||||
public function getAllOrderBook($group='false', $depth=10)
|
||||
{
|
||||
$params = array('groupByPrice' => $group, 'depth' => $depth);
|
||||
return $this->jsonGet($this->api_url.'/exchange/all/order_book', $params);
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
public function getMaxMin($pair=false)
|
||||
{
|
||||
$params = array();
|
||||
if ($pair) {
|
||||
$params['currencyPair'] = $pair;
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $this->jsonGet($this->api_url.'/exchange/maxbid_minask', $params);
|
||||
}
|
||||
|
||||
public function getRestrictions()
|
||||
{
|
||||
return $this->jsonGet($this->api_url.'/exchange/restrictions');
|
||||
}
|
||||
|
||||
public function getCoinInfo()
|
||||
{
|
||||
return $this->jsonGet($this->api_url.'/info/coininfo');
|
||||
}
|
||||
|
||||
|
||||
// Private user data
|
||||
public function getTrades($pair=false, $order='true', $limit=100, $offset=0)
|
||||
{
|
||||
$params = array('orderDesc' => $order,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset
|
||||
);
|
||||
if ($pair) {
|
||||
$params['currencyPair'] = $pair;
|
||||
}
|
||||
|
||||
return $this->jsonAuth($this->api_url.'/exchange/trades', $params);
|
||||
}
|
||||
|
||||
public function getClientOrders($pair=false, $open='ALL', $from=false, $to=false, $start=0, $end=2147483646)
|
||||
{
|
||||
$params = array('open' => $open,
|
||||
'start' => $start,
|
||||
'end' => $end
|
||||
);
|
||||
if ($pair) {
|
||||
$params['currencyPair'] = $pair;
|
||||
}
|
||||
if ($from) {
|
||||
$params['issuedFrom'] = $from;
|
||||
}
|
||||
if ($to) {
|
||||
$params['issuedTo'] = $to;
|
||||
}
|
||||
|
||||
return $this->jsonAuth($this->api_url.'/exchange/client_orders', $params);
|
||||
}
|
||||
|
||||
public function getOrder($id)
|
||||
{
|
||||
$params = array('orderId' => $id);
|
||||
return $this->jsonAuth($this->api_url.'/exchange/order', $params);
|
||||
}
|
||||
|
||||
public function getBalances($currency=false)
|
||||
{
|
||||
$params = array();
|
||||
if ($currency) {
|
||||
$params['currency'] = $currency;
|
||||
}
|
||||
return $this->jsonAuth($this->api_url.'/payment/balances', $params);
|
||||
}
|
||||
|
||||
public function getTransactions($start, $end, $types='BUY,SELL,DEPOSIT,WITHDRAWAL', $limit=100, $offset=0)
|
||||
{
|
||||
$params = array('start' => $start,
|
||||
'end' => $end,
|
||||
'types' => $types,
|
||||
'limit' => $limit,
|
||||
'offset' => $offset
|
||||
);
|
||||
return $this->jsonAuth($this->api_url.'/payment/history/transactions', $params);
|
||||
}
|
||||
|
||||
|
||||
// Orders
|
||||
public function buyLimit($pair, $price, $quantity)
|
||||
{
|
||||
$params = array('currencyPair' => $pair,
|
||||
'price' => $price,
|
||||
'quantity' => $quantity
|
||||
);
|
||||
return $this->jsonAuth($this->api_url.'/exchange/buylimit', $params, true);
|
||||
}
|
||||
|
||||
public function sellLimit($pair, $price, $quantity)
|
||||
{
|
||||
$params = array('currencyPair' => $pair,
|
||||
'price' => $price,
|
||||
'quantity' => $quantity
|
||||
);
|
||||
return $this->jsonAuth($this->api_url.'/exchange/selllimit', $params, true);
|
||||
}
|
||||
|
||||
public function cancelLimitOrder($pair, $id)
|
||||
{
|
||||
$params = array('currencyPair' => $pair,
|
||||
'orderId' => $id
|
||||
);
|
||||
return $this->jsonAuth($this->api_url.'/exchange/cancellimit', $params, true);
|
||||
}
|
||||
|
||||
// Deposit and Withdrawal
|
||||
public function getDepositAddress($symbol) {
|
||||
$params = array('currency' => $symbol);
|
||||
return $this->jsonAuth($this->api_url.'/payment/get/address', $params);
|
||||
}
|
||||
|
||||
public function withdrawCoin($amnt, $currency, $wallet)
|
||||
{
|
||||
$params = array('amount' => $amnt,
|
||||
'currency' => $currency,
|
||||
'wallet' => $wallet
|
||||
);
|
||||
return $this->jsonAuth($this->api_url.'/payment/out/coin', $params, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,60 @@
|
|||
<?php
|
||||
|
||||
function doLivecoinTrading($quick=false)
|
||||
function doLiveCoinCancelOrder($pair = false, $id = false, $live = false)
|
||||
{
|
||||
if (!$pair || !$id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$livecoin) {
|
||||
$livecoin = new LiveCoinApi;
|
||||
}
|
||||
|
||||
$res = $livecoin->cancelLimitOrder($pair, $id);
|
||||
|
||||
if ($res->success == 'true') {
|
||||
$db_order = getdbosql(
|
||||
'db_orders',
|
||||
'market=:market AND uuid=:uuid',
|
||||
array(':market'=>'livecoin', ':uuid'=>$id)
|
||||
);
|
||||
|
||||
if ($db_order) {
|
||||
$db_order->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doLiveCoinTrading($quick = false)
|
||||
{
|
||||
$exchange = 'livecoin';
|
||||
$updatebalances = true;
|
||||
|
||||
if (exchange_get($exchange, 'disabled')) return;
|
||||
if (exchange_get($exchange, 'disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$flushall = rand(0, 8) == 0;
|
||||
if($quick) $flushall = false;
|
||||
|
||||
// https://www.livecoin.net/api/userdata#paymentbalances
|
||||
$balances = livecoin_api_user('payment/balances');
|
||||
|
||||
if(!$balances || !is_array($balances)) return;
|
||||
$livecoin = new LiveCoinApi;
|
||||
|
||||
$savebalance = getdbosql('db_balances', "name='$exchange'");
|
||||
if (is_object($savebalance)) {
|
||||
$savebalance->balance = 0;
|
||||
$savebalance->save();
|
||||
} else {
|
||||
dborun("INSERT INTO balances (name,balance) VALUES ('$exchange',0)");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($balances as $balance)
|
||||
{
|
||||
if($balance->currency == 'BTC' && $balance->type == "available") {
|
||||
if (!is_object($savebalance)) continue;
|
||||
$balances = $livecoin->getBalances();
|
||||
if (!$balances || !is_array($balances)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($balances as $balance) {
|
||||
if ($balance->currency == 'BTC' && $balance->type == "available") {
|
||||
if (!is_object($savebalance)) {
|
||||
continue;
|
||||
}
|
||||
$savebalance->balance = $balance->value;
|
||||
$savebalance->save();
|
||||
continue;
|
||||
|
@ -32,22 +62,237 @@ function doLivecoinTrading($quick=false)
|
|||
|
||||
if ($updatebalances) {
|
||||
// store available balance in market table
|
||||
$coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol",
|
||||
$coins = getdbolist(
|
||||
'db_coins',
|
||||
'symbol=:symbol OR symbol2=:symbol',
|
||||
array(':symbol'=>$balance->currency)
|
||||
);
|
||||
if (empty($coins)) continue;
|
||||
|
||||
if (empty($coins)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($coins as $coin) {
|
||||
$market = getdbosql('db_markets', "coinid=:coinid AND name='$exchange'", array(':coinid'=>$coin->id));
|
||||
if (!$market) continue;
|
||||
if ($balance->type == "available")
|
||||
$market->balance = $balance->value;
|
||||
elseif ($balance->type == "trade")
|
||||
$market->ontrade = $balance->value;
|
||||
|
||||
if (!$market) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$market->balance = arraySafeVal($balance, 'Available', 0.0);
|
||||
$market->ontrade = arraySafeVal($balance, 'Balance') - $market->balance;
|
||||
$market->balancetime = time();
|
||||
$address = arraySafeVal($balance, 'CryptoAddress');
|
||||
if (!empty($address) && $market->deposit_address != $address) {
|
||||
debuglog("$exchange: {$coin->symbol} deposit address updated");
|
||||
$market->deposit_address = $address;
|
||||
}
|
||||
$market->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!YAAMP_ALLOW_EXCHANGE) return;
|
||||
if (!YAAMP_ALLOW_EXCHANGE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$flushall = rand(0, 8) == 0;
|
||||
if ($quick) {
|
||||
$flushall = false;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if ($coin->dontsell || $coin->symbol == 'BTC') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pair = $coin->symbol.'/BTC';
|
||||
sleep(1);
|
||||
$orders = $livecoin->getClientOrders($pair, 'OPEN');
|
||||
|
||||
if (isset($orders->success) || !isset($orders->data)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($orders->data as $order) {
|
||||
$uuid = $order['id'];
|
||||
$pair = $order['currencyPair'];
|
||||
sleep(1);
|
||||
$ticker = $livecoin->getTickerInfo($pair);
|
||||
|
||||
if (!$ticker) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($order['price'] > $cancel_ask_pct*$ticker->best_ask || $flushall) {
|
||||
sleep(1);
|
||||
doLiveCoinCancelOrder($pair, $uuid, $livecoin);
|
||||
} else {
|
||||
$db_order = getdbosql(
|
||||
'db_orders',
|
||||
'market=:market AND uuid=:uuid',
|
||||
array(':market'=>'livecoin', ':uuid'=>$uuid)
|
||||
);
|
||||
|
||||
if ($db_order) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$db_order = new db_orders;
|
||||
$db_order->market = 'livecoin';
|
||||
$db_order->coinid = $coin->id;
|
||||
$db_order->amount = $order['quantity'];
|
||||
$db_order->price = $order['price'];
|
||||
$db_order->ask = $ticker['best_ask'];
|
||||
$db_order->bid = $ticker['best_sell'];
|
||||
$db_order->uuid = $uuid;
|
||||
$db_order->created = time();
|
||||
$db_order->save();
|
||||
}
|
||||
}
|
||||
$list = getdbolist('db_orders', "coinid=$coin->id and market='livecoin'");
|
||||
foreach ($list as $db_order) {
|
||||
$found = false;
|
||||
foreach ($orders->data as $order) {
|
||||
$uuid = $order['id'];
|
||||
if ($uuid == $db_order->uuid) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
debuglog("LiveCoin: Deleting order $coin->name $db_order->amount");
|
||||
$db_order->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
sleep(2);
|
||||
|
||||
/* Update balances and sell */
|
||||
$balances = $livecoin->getBalances();
|
||||
if (!$balances) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($balances as $balance) {
|
||||
if ($balance->type != 'total') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$amount = $balance->value;
|
||||
$symbol = $balance->currency;
|
||||
if (!$amount || $symbol == 'BTC') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
|
||||
if (!$coin || $coin->dontsell) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$market2 = getdbosql('db_markets', "coinid={$coin->id} AND (name='bittrex' OR name='poloniex')");
|
||||
if ($market2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$market = getdbosql('db_markets', "coinid=$coin->id and name='livecoin'");
|
||||
if ($market) {
|
||||
$market->lasttraded = time();
|
||||
$market->save();
|
||||
}
|
||||
|
||||
if ($amount*$coin->price < $min_btc_trade) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
sleep(1);
|
||||
$res = $livecoin->sellLimit($pair, $sellprice, $amount);
|
||||
|
||||
if (!($res->success == 'true' && $res->added == 'true')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$db_order = new db_orders;
|
||||
$db_order->market = 'livecoin';
|
||||
$db_order->coinid = $coin->id;
|
||||
$db_order->amount = $amount;
|
||||
$db_order->price = $sellprice;
|
||||
$db_order->ask = $ticker->best_ask;
|
||||
$db_order->bid = $ticker->best_bid;
|
||||
$db_order->uuid = $res->orderId;
|
||||
$db_order->created = time();
|
||||
$db_order->save();
|
||||
}
|
||||
|
||||
/* Withdrawals */
|
||||
$withdraw_min = exchange_get($exchange, 'withdraw_min_btc', EXCH_AUTO_WITHDRAW);
|
||||
$withdraw_fee = exchange_get($exchange, 'withdraw_fee_btc', 0.0002);
|
||||
if (floatval($withdraw_min) > 0 && $savebalance->balance >= ($withdraw_min + $withdraw_fee)) {
|
||||
$amount = $savebalance->balance - $withdraw_fee;
|
||||
debuglog("$exchange: withdraw $amount BTC to $btcaddr");
|
||||
sleep(1);
|
||||
$res = $livecoin->withdrawCoin($amount, 'BTC', $btcaddr);
|
||||
debuglog("$exchange: withdraw ".json_encode($res));
|
||||
if ($res) {
|
||||
$withdraw = new db_withdraws;
|
||||
$withdraw->market = 'livecoin';
|
||||
$withdraw->address = $btcaddr;
|
||||
$withdraw->amount = $amount;
|
||||
$withdraw->time = time();
|
||||
$withdraw->uuid = $res->id;
|
||||
$withdraw->save();
|
||||
$savebalance->balance = 0;
|
||||
$savebalance->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
require_once('poloniex_trading.php');
|
||||
require_once('bittrex_trading.php');
|
||||
require_once('bleutrade_trading.php');
|
||||
|
@ -32,6 +31,10 @@ function cancelExchangeOrder($order=false)
|
|||
case 'cryptopia':
|
||||
doCryptopiaCancelOrder($order->uuid);
|
||||
break;
|
||||
case 'livecoin':
|
||||
doLiveCoinCancelOrder($order->uuid);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,8 +93,8 @@ function runExchange($exchangeName=false)
|
|||
break;
|
||||
|
||||
case 'livecoin':
|
||||
doLivecoinTrading(true);
|
||||
updateLivecoinMarkets();
|
||||
doLiveCoinTrading(true);
|
||||
updateLiveCoinMarkets();
|
||||
break;
|
||||
|
||||
case 'nova':
|
||||
|
|
Loading…
Add table
Reference in a new issue