From a5de1e3d1a6632658315b3a47e677cb13b7c0f7f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 19 Feb 2019 14:24:22 +0100 Subject: [PATCH] api: kucoin v2 private api changes --- web/yaamp/commands/ExchangeCommand.php | 4 ++-- web/yaamp/core/backend/rawcoins.php | 7 +++---- web/yaamp/core/exchange/kucoin.php | 12 ++++++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/web/yaamp/commands/ExchangeCommand.php b/web/yaamp/commands/ExchangeCommand.php index 1c33577..e659917 100644 --- a/web/yaamp/commands/ExchangeCommand.php +++ b/web/yaamp/commands/ExchangeCommand.php @@ -191,8 +191,8 @@ class ExchangeCommand extends CConsoleCommand $balance = kraken_api_user('Balance'); echo("kraken btc: ".json_encode($balance)."\n"); } - if (!empty(EXCH_KUCOIN_KEY)) { - $balance = kucoin_api_user('accounts'/*,array('currency=BTC')*/); + if (!empty(EXCH_KUCOIN_KEY) && !empty(EXCH_KUCOIN_PASSPHRASE)) { + $balance = kucoin_api_user('accounts',array('currency'=>'BTC')); if (!is_object($balance) || !isset($balance->data)) echo "kucoin error ".json_encode($balance)."\n"; else echo("kucoin: ".json_encode($balance->data)."\n"); } diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 520ad91..c9948b5 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -339,14 +339,13 @@ function updateRawcoins() } if (!exchange_get('kucoin', 'disabled')) { - $list = kucoin_api_query('market/open/coins'); + $list = kucoin_api_query('currencies'); if(is_object($list) && isset($list->data) && !empty($list->data)) { dborun("UPDATE markets SET deleted=true WHERE name='kucoin'"); foreach($list->data as $item) { - $symbol = $item->coin; - $name = $item->name; - if (strpos($item->withdrawRemark,'Ethereum')) continue; + $symbol = $item->name; + $name = $item->fullName; updateRawCoin('kucoin', $symbol, $name); } } diff --git a/web/yaamp/core/exchange/kucoin.php b/web/yaamp/core/exchange/kucoin.php index 8077f42..474846c 100644 --- a/web/yaamp/core/exchange/kucoin.php +++ b/web/yaamp/core/exchange/kucoin.php @@ -74,14 +74,14 @@ function kucoin_api_user($method, $params=NULL, $isPostMethod=false) $req = $isPostMethod ? "POST" : "GET"; $tosign = "{$nonce}{$req}{$endpoint}{$body}"; - $hmac = strtolower(hash_hmac('sha256', base64_encode($tosign), EXCH_KUCOIN_SECRET)); + $hmac = hash_hmac('sha256', $tosign, EXCH_KUCOIN_SECRET, true); $headers = array( 'Content-Type: application/json;charset=UTF-8', 'KC-API-KEY: '.EXCH_KUCOIN_KEY, 'KC-API-PASSPHRASE: '.EXCH_KUCOIN_PASSPHRASE, 'KC-API-TIMESTAMP: '.$nonce, - 'KC-API-SIGN: '.$hmac, + 'KC-API-SIGN: '.base64_encode($hmac), ); $ch = curl_init(); @@ -145,14 +145,14 @@ function kucoin_update_market($market) } $t1 = microtime(true); - $query = kucoin_api_query("$pair/open/tick"); + $query = kucoin_api_query('market/orderbook/level1','symbol='.$pair); if(!kucoin_result_valid($query)) return false; $ticker = $query->data; - $price2 = ((double) $ticker->buy + (double)$ticker->sell)/2; + $price2 = ((double) $ticker->bestBid + (double)$ticker->bestAsk)/2; $market->price2 = AverageIncrement($market->price2, $price2); - $market->price = AverageIncrement($market->price, $ticker->buy); - $market->pricetime = time(); + $market->price = AverageIncrement($market->price, $ticker->bestBid); + $market->pricetime = min(time(), 0 + $ticker->sequence); $market->save(); $apims = round((microtime(true) - $t1)*1000,3);