python-kucoin icon indicating copy to clipboard operation
python-kucoin copied to clipboard

[V2] Incorrect keys to place orders

Open avaucher opened this issue 6 years ago • 14 comments

Placing orders does not work for me.
There appear to be some inconsistencies between the code and the API docs (https://docs.kucoin.com/#place-a-new-order)

  • The endpoint should be '/api/v1/orders' but in the code it is currently '/api/v1/order'
  • The body should contain "clientOid" and "size" instead of "orderOid" and "amount", respectively

However, even when doing these changes locally, I get a 401 error with b'{"code":"400005","msg":"Invalid KC-API-SIGN"}'. There appears to be some other problem elsewhere, but I couldn't find what.

avaucher avatar Feb 23 '19 22:02 avaucher

Are you sure you used the right keys and passphrase? You didnt swap your sandbox and normal keys?

nielskool avatar Feb 24 '19 02:02 nielskool

I probably chose a bad issue title: "keys" refers to the Python dict keys for the request body, not for the API key.

A strange thing is that other authenticated endpoints worked fine, f.i. /api/v1/accounts.

avaucher avatar Feb 24 '19 09:02 avaucher

Hmm this breaks other stuff for me. I'll be back

File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 1329, in get_fills
    return self._get('fills', True, data=data)
  File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 193, in _get
    return self._request('get', path, signed, **kwargs)
  File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 160, in _request
    if signed and kwargs['data']:
KeyError: 'data'

nielskool avatar Feb 24 '19 19:02 nielskool

I see. I updated it, this error should not happen again.

avaucher avatar Feb 24 '19 19:02 avaucher

Hmm the one or two before your last fix did work for my cancel orders but get accounts didn't. Now get accounts works but cancel_all_orders not anymore.

File "<stdin>", line 1, in <module>
  File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 1095, in cancel_all_orders
    return self._delete('orders', True, data=data)
  File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 202, in _delete
    return self._request('delete', path, signed, **kwargs)
  File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 164, in _request
    return self._handle_response(response)
  File "/media/rasppi/rasppi/Python/bot/kucoin/client.py", line 174, in _handle_response
    raise KucoinAPIException(response)
kucoin.exceptions.KucoinAPIException: KucoinAPIException 400005: Invalid KC-API-SIGN

nielskool avatar Feb 24 '19 19:02 nielskool

Are you sure? Both work for me now.

avaucher avatar Feb 24 '19 20:02 avaucher

Anyway... Tried another fix, maybe this will do it. Otherwise I'll give up :sweat_smile:

avaucher avatar Feb 24 '19 20:02 avaucher

The last fix now works yea! i changed the cancel all so it accepts the optional symbol and without the optional it worked but not with the symbol but your last fix fixed that

nielskool avatar Feb 24 '19 20:02 nielskool

Thanks @nielskool and @avaucher v2.1.0 should fix this now.

sammchardy avatar Feb 25 '19 11:02 sammchardy

Works for me, thanks!

avaucher avatar Feb 25 '19 18:02 avaucher

Hello, I updated to the latest version but I still can't get create_limit_order() to work. i copied it 100% from the docs and used to get Errorcode: 404000 Url Not Found -- The request resource could not be found

now I keep getting Errorcode: KucoinAPIException 400004: Invalid KC-API-PASSPHRASE

this is my code:

from kucoin.client import Client api_key = "" api_secret = "" api_passphrase = ""

client = Client(api_key, api_secret, api_passphrase)

order = client.create_limit_order('KCS-BTC', Client.SIDE_BUY, '0.000001', '1')

full error log:

C:\Users\Megaport\Desktop\kucoin>python testkucoin.py Traceback (most recent call last): File "testkucoin.py", line 19, in order = client.create_limit_order('KCS-BTC', Client.SIDE_BUY, '0.000001', '1') File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 1047, in create_limit_order return self._post('orders', True, data=data) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 190, in _post return self._request('post', path, signed, **kwargs) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 158, in _request return self._handle_response(response) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 168, in _handle_response raise KucoinAPIException(response) kucoin.exceptions.KucoinAPIException: KucoinAPIException 400004: Invalid KC-API-PASSPHRASE

help would be much appreciated, I really need to get this running! other calls to orderbook and currencies etc work just fine

Fluuuk avatar Feb 26 '19 02:02 Fluuuk

@Fluuuk this function is a private function so you need to be authenticated. You will need to create an api_key, secret and passphrase to initialise the Client before calling create_limit_order

sammchardy avatar Feb 26 '19 03:02 sammchardy

@Fluuuk this function is a private function so you need to be authenticated. You will need to create an api_key, secret and passphrase to initialise the Client before calling create_limit_order

Thx for the quick reply. Isn't this the part where I initialize my Client and feed it the api_data?

api_key = "" api_secret = "" api_passphrase = ""

client = Client(api_key, api_secret, api_passphrase)

sorry I don't know how to proceed

Fluuuk avatar Feb 26 '19 10:02 Fluuuk

I added .init to my code, am I doing this right? getting a whole bunch of new errors now

code:

api_key = "" api_secret = "" api_passphrase = ""

client = Client(api_key, api_secret, api_passphrase) client.init(client, api_key, api_secret, api_passphrase)

order = client.create_limit_order('KCS-BTC', Client.SIDE_BUY, '0.000001', '1')

error: File "testkucoin.py", line 20, in order = client.create_limit_order('KCS-BTC', Client.SIDE_BUY, '0.000001', '1') File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 1047, in create_limit_order return self._post('orders', True, data=data) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 190, in _post return self._request('post', path, signed, **kwargs) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kucoin\client.py", line 157, in _request response = getattr(self.session, method)(uri, **kwargs) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 500, in post return self.request('POST', url, data=data, json=json, **kwargs) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 457, in request resp = self.send(prep, **send_kwargs) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 569, in send r = adapter.send(request, **kwargs) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 362, in send timeout=timeout File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 516, in urlopen body=body, headers=headers) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 308, in _make_request conn.request(method, url, **httplib_request_kw) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1229, in request self._send_request(method, url, body, headers, encode_chunked) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1270, in _send_request self.putheader(hdr, value) File "C:\Users\Megaport\AppData\Local\Programs\Python\Python37-32\lib\http\client.py", line 1206, in putheader if _is_illegal_header_value(values[i]): TypeError: expected string or bytes-like object

Fluuuk avatar Feb 26 '19 10:02 Fluuuk