sammchardy / python-kucoin

Kucoin REST and Websocket API python implementation
https://python-kucoin.readthedocs.io/en/latest/
MIT License
349 stars 147 forks source link

[V2] Incorrect keys to place orders #47

Open avaucher opened 5 years ago

avaucher commented 5 years ago

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)

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.

nielskool commented 5 years ago

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

avaucher commented 5 years ago

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.

nielskool commented 5 years ago

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'
avaucher commented 5 years ago

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

nielskool commented 5 years ago

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
avaucher commented 5 years ago

Are you sure? Both work for me now.

avaucher commented 5 years ago

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

nielskool commented 5 years ago

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

sammchardy commented 5 years ago

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

avaucher commented 5 years ago

Works for me, thanks!

Fluuuk commented 5 years ago

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

sammchardy commented 5 years ago

@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

Fluuuk commented 5 years ago

@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 commented 5 years ago

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