ccxt: Can't make POST requests for Kucoin

Can’t seem to make POST requests on Kucoin, it says that “Signature verification failed”. All GET requests have worked fine so far.

  • OS: Mac OS
  • Programming Language: Python (ipynb format)
  • CCXT version: 1.10
  • Exchange: Kucoin
  • Method: create_order
ku_client.create_order('LTC/BTC', 'limit', 'buy', .01, 0.01655)



Result:
AuthenticationError: kucoin {"msg":"Signature verification failed","timestamp":1514554308458,"code":"UNAUTH","success":false}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, they’re having load issues. Sometimes that page works, (it does for me at the moment). Some more info when that page works:

import ccxt
import test_config as config
from pprint import pprint
import time

e = ccxt.kucoin()
e.apiKey = config.exchange_keys['kucoin']['key']
e.secret = config.exchange_keys['kucoin']['secret']
e.timeout = 60000
e.proxies = {'http': 'http://localhost:8080',
             'https': 'http://localhost:8080'}
balances = e.fetch_balance()
print(balances['ETH'])
time.sleep(1)
e.createLimitSellOrder('ETH/BTC', 0.00059940, 0.04978104)


C:\Users\gaardiolor\Anaconda3\python.exe C:/Users/gaardiolor/PycharmProjects/Test2/_test/test_kucoin.py
{'free': 0.0005994, 'used': 0.0, 'total': 0.0005994}
Traceback (most recent call last):
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 345, in fetch_requests
    response.raise_for_status()
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\requests\models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error:  for url: https://api.kucoin.com/v1/order

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/gaardiolor/PycharmProjects/Test2/_test/test_kucoin.py", line 15, in <module>
    e.createLimitSellOrder('ETH/BTC', 0.00059940, 0.04978104)
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 1050, in create_limit_sell_order
    return self.create_order(symbol, 'limit', 'sell', *args)
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\kucoin.py", line 298, in create_order
    response = self.privatePostOrder(self.extend(order, params))
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\kucoin.py", line 471, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 290, in fetch2
    return self.fetch_requests(request['url'], request['method'], request['headers'], request['body'])
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 357, in fetch_requests
    self.handle_errors(response.status_code, response.reason, url, method, None, self.last_http_response)
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\kucoin.py", line 465, in handle_errors
    raise AuthenticationError(self.id + ' ' + self.json(response))
ccxt.base.errors.AuthenticationError: kucoin {"code":"UNAUTH","msg":"Signature verification failed","success":false,"timestamp":1514555842503}

So fetching (also using private api) works, placing orders doesn’t work.

ok great! I think both problems are solved.

@gaardiolor, ok, both problem 1 and problem 2 should be fixed in Python as of version 1.10.513 (again, wait 5-10 minutes, then update). Tested the python case. It works now (throws an adequate exception + does not need the .truncate anymore – will truncate up to precision for you). Let us know if it still doesn’t work on your side. Thx!

they’re working for me now thanks @kroitor !

my debugging proxy gets the following response:

{"success":false,"code":"ERROR","msg":"The precision of amount(ETH) is incorrect. The precision of ETH is 6","timestamp":1514560457260,"data":null}

@kroitor unfortunately still an error;

Traceback (most recent call last):
  File "C:/Users/gaardiolor/PycharmProjects/Test2/_test/test_kucoin.py", line 16, in <module>
    e.createLimitSellOrder('ETH/BTC', 0.00059940, 0.04978104)
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 1050, in create_limit_sell_order
    return self.create_order(symbol, 'limit', 'sell', *args)
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\kucoin.py", line 301, in create_order
    'id': self.safe_string(response['data'], 'orderOid'),
  File "C:\Users\gaardiolor\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 474, in safe_string
    return str(dictionary[key]) if key is not None and (key in dictionary) and dictionary[key] else default_value
TypeError: argument of type 'NoneType' is not iterable
POST https://api.kucoin.com/v1/order 
Request: {'KC-API-KEY': '<snip>', 'KC-API-NONCE': '1514556151971', 'KC-API-SIGNATURE': '<snip>', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', 'Accept-Encoding': 'gzip, deflate'} 
amount=0.0005994&price=0.04978104&symbol=ETH-BTC&type=SELL

That’s when placing the order. Let me know if you need more info

Hmm did you try playing around with the sign method? Let me know if you find some solution!