mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
api: use new kucoin public api url and disable it
private api to finish, tired to decrypt asian brains...
This commit is contained in:
parent
a36f11d6ba
commit
64ee803369
6 changed files with 49 additions and 35 deletions
|
@ -197,7 +197,7 @@ class ExchangeCommand extends CConsoleCommand
|
||||||
echo("kraken btc: ".json_encode($balance)."\n");
|
echo("kraken btc: ".json_encode($balance)."\n");
|
||||||
}
|
}
|
||||||
if (!empty(EXCH_KUCOIN_KEY)) {
|
if (!empty(EXCH_KUCOIN_KEY)) {
|
||||||
$balance = kucoin_api_user('account/BTC/balance');
|
$balance = kucoin_api_user('accounts',array('currency=BTC'));
|
||||||
if (!is_object($balance) || !isset($balance->data)) echo "kucoin error ".json_encode($balance)."\n";
|
if (!is_object($balance) || !isset($balance->data)) echo "kucoin error ".json_encode($balance)."\n";
|
||||||
else echo("kucoin: ".json_encode($balance->data)."\n");
|
else echo("kucoin: ".json_encode($balance->data)."\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1527,13 +1527,11 @@ function updateKuCoinMarkets()
|
||||||
$list = getdbolist('db_markets', "name LIKE '$exchange%'");
|
$list = getdbolist('db_markets', "name LIKE '$exchange%'");
|
||||||
if (empty($list)) return;
|
if (empty($list)) return;
|
||||||
|
|
||||||
$markets = kucoin_api_query('open/symbols','market=BTC');
|
$symbols = kucoin_api_query('symbols','market=BTC');
|
||||||
if(!kucoin_result_valid($markets) || empty($markets->data)) return;
|
if(!kucoin_result_valid($symbols) || empty($symbols->data)) return;
|
||||||
|
|
||||||
$coininfo = NULL; //kucoin_api_query('market/open/coins');
|
$markets = kucoin_api_query('markets/allTickers');
|
||||||
if(!kucoin_result_valid($coininfo) || empty($coininfo->data)) {
|
if(!kucoin_result_valid($markets) || empty($markets->data)) return;
|
||||||
$coininfo = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($list as $market)
|
foreach($list as $market)
|
||||||
{
|
{
|
||||||
|
@ -1550,18 +1548,25 @@ function updateKuCoinMarkets()
|
||||||
|
|
||||||
$pair = strtoupper($symbol).'-BTC';
|
$pair = strtoupper($symbol).'-BTC';
|
||||||
|
|
||||||
|
$enableTrading = false;
|
||||||
|
foreach ($symbols->data as $sym) {
|
||||||
|
if (objSafeVal($sym,'symbol') != $pair) continue;
|
||||||
|
$enableTrading = objSafeVal($sym,'enableTrading',false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($market->disabled == $enableTrading) {
|
||||||
|
$market->disabled = (int) (!$enableTrading);
|
||||||
|
$market->save();
|
||||||
|
if ($market->disabled) continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($markets->data as $ticker) {
|
foreach ($markets->data as $ticker) {
|
||||||
if ($ticker->symbol != $pair) continue;
|
if ($ticker->symbol != $pair) continue;
|
||||||
if (objSafeVal($ticker,'buy',-1) == -1) continue;
|
if (objSafeVal($ticker,'buy',-1) == -1) continue;
|
||||||
|
|
||||||
$market->price = AverageIncrement($market->price, $ticker->buy);
|
$market->price = AverageIncrement($market->price, $ticker->buy);
|
||||||
$market->price2 = AverageIncrement($market->price2, objSafeVal($ticker,'sell',$ticker->buy));
|
$market->price2 = AverageIncrement($market->price2, objSafeVal($ticker,'sell',$ticker->buy));
|
||||||
if (!empty($coininfo)) foreach ($coininfo->data as $info) {
|
|
||||||
if ($info->coin == $symbol) {
|
|
||||||
//todo: $market->withdrawfee = $info->withdrawMinFee;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$market->txfee = $ticker->feeRate * 100; // is 0.1% for trades (0.001)
|
$market->txfee = $ticker->feeRate * 100; // is 0.1% for trades (0.001)
|
||||||
$market->priority = -1;
|
$market->priority = -1;
|
||||||
$market->pricetime = time();
|
$market->pricetime = time();
|
||||||
|
|
|
@ -17,6 +17,7 @@ function updateRawcoins()
|
||||||
exchange_set_default('escodex', 'disabled', true);
|
exchange_set_default('escodex', 'disabled', true);
|
||||||
exchange_set_default('gateio', 'disabled', true);
|
exchange_set_default('gateio', 'disabled', true);
|
||||||
exchange_set_default('jubi', 'disabled', true);
|
exchange_set_default('jubi', 'disabled', true);
|
||||||
|
exchange_set_default('kucoin', 'disabled', true);
|
||||||
exchange_set_default('nova', 'disabled', true);
|
exchange_set_default('nova', 'disabled', true);
|
||||||
exchange_set_default('stocksexchange', 'disabled', true);
|
exchange_set_default('stocksexchange', 'disabled', true);
|
||||||
exchange_set_default('tradesatoshi', 'disabled', true);
|
exchange_set_default('tradesatoshi', 'disabled', true);
|
||||||
|
|
|
@ -8,14 +8,14 @@ function kucoin_result_valid($obj, $method='')
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://api.kucoin.com/v1/open/symbols/?market=BTC
|
// https://openapi-v2.kucoin.com/api/v1/symbols?market=BTC
|
||||||
|
// https://openapi-v2.kucoin.com/api/v1/currencies for labels
|
||||||
|
|
||||||
function kucoin_api_query($method, $params='', $returnType='object')
|
function kucoin_api_query($method, $params='', $returnType='object')
|
||||||
{
|
{
|
||||||
$exchange = 'kucoin';
|
$exchange = 'kucoin';
|
||||||
$url = "https://api.kucoin.com/v1/$method/";
|
$url = "https://openapi-v2.kucoin.com/api/v1/$method";
|
||||||
if (!empty($params))
|
if (!empty($params)) $url .= "?$params";
|
||||||
$url .= "?$params";
|
|
||||||
|
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
@ -46,7 +46,7 @@ function kucoin_api_query($method, $params='', $returnType='object')
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://api.kucoin.com/v1/account/<coin>/wallet/address
|
// https://openapi-v2.kucoin.com/api/v1/deposit-addresses?currency=<coin>
|
||||||
|
|
||||||
function kucoin_api_user($method, $params=NULL, $isPostMethod=false)
|
function kucoin_api_user($method, $params=NULL, $isPostMethod=false)
|
||||||
{
|
{
|
||||||
|
@ -55,26 +55,33 @@ function kucoin_api_user($method, $params=NULL, $isPostMethod=false)
|
||||||
if (!defined('EXCH_KUCOIN_SECRET')) define('EXCH_KUCOIN_SECRET', '');
|
if (!defined('EXCH_KUCOIN_SECRET')) define('EXCH_KUCOIN_SECRET', '');
|
||||||
|
|
||||||
if (empty(EXCH_KUCOIN_KEY) || empty(EXCH_KUCOIN_SECRET)) return false;
|
if (empty(EXCH_KUCOIN_KEY) || empty(EXCH_KUCOIN_SECRET)) return false;
|
||||||
|
if (empty(EXCH_KUCOIN_PASSPHRASE)) return false;
|
||||||
|
|
||||||
$api_host = 'https://api.kucoin.com';
|
$api_host = 'https://openapi-v2.kucoin.com';
|
||||||
$mt = explode(' ', microtime());
|
$mt = explode(' ', microtime());
|
||||||
$nonce = $mt[1].substr($mt[0], 2, 3);
|
$nonce = $mt[1].substr($mt[0], 2, 3);
|
||||||
$url = $endpoint = "/v1/$method";
|
$url = $endpoint = "/api/v1/$method";
|
||||||
$tosign = "$endpoint/$nonce/";
|
|
||||||
|
|
||||||
if (empty($params)) $params = array();
|
if (empty($params)) $params = array();
|
||||||
$query = http_build_query($params);
|
$query = http_build_query($params);
|
||||||
if (strlen($query) && !$isPostMethod) {
|
$body = "";
|
||||||
$url .= '&'.$query; $query = '';
|
if ($isPostMethod)
|
||||||
|
$body = json_encode($params);
|
||||||
|
else if (strlen($query)) {
|
||||||
|
$body = '?'.$query;
|
||||||
|
$url .= $body;
|
||||||
}
|
}
|
||||||
if ($isPostMethod) $post_data = $params;
|
|
||||||
$hmac = strtolower(hash_hmac('sha256', base64_encode($tosign.$query), EXCH_KUCOIN_SECRET));
|
$req = $isPostMethod ? "POST" : "GET";
|
||||||
|
$tosign = "{$nonce}{$req}{$endpoint}{$body}";
|
||||||
|
$hmac = strtolower(hash_hmac('sha256', base64_encode($tosign), EXCH_KUCOIN_SECRET));
|
||||||
|
|
||||||
$headers = array(
|
$headers = array(
|
||||||
'Content-Type: application/json;charset=UTF-8',
|
'Content-Type: application/json;charset=UTF-8',
|
||||||
'KC-API-KEY: '.EXCH_KUCOIN_KEY,
|
'KC-API-KEY: '.EXCH_KUCOIN_KEY,
|
||||||
'KC-API-NONCE: '.$nonce,
|
'KC-API-PASSPHRASE: '.EXCH_KUCOIN_PASSPHRASE,
|
||||||
'KC-API-SIGNATURE: '.$hmac,
|
'KC-API-TIMESTAMP: '.$nonce,
|
||||||
|
'KC-API-SIGN: '.$hmac,
|
||||||
);
|
);
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
@ -83,7 +90,7 @@ function kucoin_api_user($method, $params=NULL, $isPostMethod=false)
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
if ($isPostMethod) {
|
if ($isPostMethod) {
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||||||
}
|
}
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
|
|
|
@ -14,7 +14,7 @@ function doKuCoinTrading($quick=false)
|
||||||
|
|
||||||
if (exchange_get($exchange, 'disabled')) return;
|
if (exchange_get($exchange, 'disabled')) return;
|
||||||
|
|
||||||
$data = kucoin_api_user('account/balance');
|
$data = kucoin_api_user('accounts');
|
||||||
if (!kucoin_result_valid($data)) return;
|
if (!kucoin_result_valid($data)) return;
|
||||||
|
|
||||||
$savebalance = getdbosql('db_balances', "name='$exchange'");
|
$savebalance = getdbosql('db_balances', "name='$exchange'");
|
||||||
|
@ -22,19 +22,19 @@ function doKuCoinTrading($quick=false)
|
||||||
if (is_array($data->data))
|
if (is_array($data->data))
|
||||||
foreach($data->data as $balance)
|
foreach($data->data as $balance)
|
||||||
{
|
{
|
||||||
if ($balance->coinType == 'BTC') {
|
if ($balance->currency == 'BTC' && $balance->type == 'main') {
|
||||||
if (is_object($savebalance)) {
|
if (is_object($savebalance)) {
|
||||||
$savebalance->balance = $balance->balance;
|
$savebalance->balance = $balance->balance;
|
||||||
$savebalance->onsell = $balance->freezeBalance;
|
$savebalance->onsell = $balance->holds;
|
||||||
$savebalance->save();
|
$savebalance->save();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($updatebalances) {
|
if ($updatebalances && $balance->type == 'main') {
|
||||||
// store available balance in market table
|
// 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->coinType)
|
array(':symbol'=>$balance->currency)
|
||||||
);
|
);
|
||||||
if (empty($coins)) continue;
|
if (empty($coins)) continue;
|
||||||
foreach ($coins as $coin) {
|
foreach ($coins as $coin) {
|
||||||
|
@ -44,14 +44,14 @@ function doKuCoinTrading($quick=false)
|
||||||
);
|
);
|
||||||
if (!$market) continue;
|
if (!$market) continue;
|
||||||
$market->balance = $balance->balance;
|
$market->balance = $balance->balance;
|
||||||
$market->ontrade = $balance->freezeBalance;
|
$market->ontrade = $balance->holds;
|
||||||
$market->balancetime = time();
|
$market->balancetime = time();
|
||||||
$market->save();
|
$market->save();
|
||||||
|
|
||||||
$checked_today = cache()->get($exchange.'-deposit_address-check-'.$coin->symbol);
|
$checked_today = cache()->get($exchange.'-deposit_address-check-'.$coin->symbol);
|
||||||
if ($coin->installed && !$checked_today) {
|
if ($coin->installed && !$checked_today) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
$obj = kucoin_api_user("account/{$coin->symbol}/wallet/address");
|
$obj = kucoin_api_user('deposit-addresses','currency='.$coin->symbol);
|
||||||
if (!kucoin_result_valid($obj)) continue;
|
if (!kucoin_result_valid($obj)) continue;
|
||||||
$result = $obj->data;
|
$result = $obj->data;
|
||||||
$deposit_address = objSafeVal($result,'address');
|
$deposit_address = objSafeVal($result,'address');
|
||||||
|
|
|
@ -43,6 +43,7 @@ if (!defined('EXCH_POLONIEX_KEY')) define('EXCH_POLONIEX_KEY', '');
|
||||||
if (!defined('EXCH_YOBIT_KEY')) define('EXCH_YOBIT_KEY', '');
|
if (!defined('EXCH_YOBIT_KEY')) define('EXCH_YOBIT_KEY', '');
|
||||||
if (!defined('EXCH_KRAKEN_KEY')) define('EXCH_KRAKEN_KEY', '');
|
if (!defined('EXCH_KRAKEN_KEY')) define('EXCH_KRAKEN_KEY', '');
|
||||||
if (!defined('EXCH_KUCOIN_KEY')) define('EXCH_KUCOIN_KEY', '');
|
if (!defined('EXCH_KUCOIN_KEY')) define('EXCH_KUCOIN_KEY', '');
|
||||||
|
if (!defined('EXCH_KUCOIN_PASSPHRASE')) define('EXCH_KUCOIN_PASSPHRASE', '');
|
||||||
if (!defined('EXCH_LIVECOIN_KEY')) define('EXCH_LIVECOIN_KEY', '');
|
if (!defined('EXCH_LIVECOIN_KEY')) define('EXCH_LIVECOIN_KEY', '');
|
||||||
if (!defined('EXCH_NOVA_KEY')) define('EXCH_NOVA_KEY', '');
|
if (!defined('EXCH_NOVA_KEY')) define('EXCH_NOVA_KEY', '');
|
||||||
if (!defined('EXCH_STOCKSEXCHANGE_KEY')) define('EXCH_STOCKSEXCHANGE_KEY', '');
|
if (!defined('EXCH_STOCKSEXCHANGE_KEY')) define('EXCH_STOCKSEXCHANGE_KEY', '');
|
||||||
|
|
Loading…
Add table
Reference in a new issue