Skip to content

Commit

Permalink
api: kucoin v2 private api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Feb 19, 2019
1 parent 20655e5 commit a5de1e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions web/yaamp/commands/ExchangeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public function testApiKeys()
$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");
}
Expand Down
7 changes: 3 additions & 4 deletions web/yaamp/core/backend/rawcoins.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
12 changes: 6 additions & 6 deletions web/yaamp/core/exchange/kucoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a5de1e3

Please sign in to comment.