sammchardy / python-kucoin

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

Method for "List dealt orders(merged)" #3

Closed danricho closed 5 years ago

danricho commented 6 years ago

Hi, I'm wondering if you have a way of getting all previous fulfilled orders via the API with your library? I'd like an option without symbol being specified.

From the API:

Trading / List dealt orders(merged) GET https://api.kucoin.com/v1/order/dealt

Cheers, Dan

sammchardy commented 6 years ago

Hi @danricho I've just released v0.1.1 with updates to the Trading endpoints including a new get_dealt_orders function to handle that endpoint.

I need to update my method of watching for API changes as there are some other changes I need to address as well.

Thanks for opening a request.

danricho commented 6 years ago

Sounds great! I will update and try it out soon. Cheers for the great library.

danricho commented 6 years ago

I've trialed it and it has been working well, but it stopped last night with the following Exception:

raise KucoinAPIException(response) kucoin.exceptions.KucoinAPIException: KucoinAPIException : b''

danricho commented 6 years ago

I've looked at this further and notice that it only occurs on the get_dealt_orders call and I believe its a 401 error.

Is this an authorisation error?

sammchardy commented 6 years ago

Hi @danricho I think it may be a 504 gateway timeout error with a message like

b'<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor="white">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n</body>\r\n</html>\r\n'

I will add some handling in for that error.

See also discussion on this issue #6 about inconsistent response times which I think is the major factor. Kucoin struggling.

danricho commented 6 years ago

I'm definitely getting that error... But others also... I've started logging exceptions. Here are the three types I've seen:

2018-01-09 07:50:55.670475 : KUCOIN : KucoinAPIException UNAUTH: Invalid nonce 2018-01-09 08:38:04.159860 : KUCOIN : KucoinAPIException : b'<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor="white">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n</body>\r\n</html>\r\n' 2018-01-09 09:03:48.077724 : KUCOIN : KucoinAPIException : b''

Exception text is just a str(e). It's all very intermittent.... Thanks again.

danricho commented 6 years ago

Hi Sam,

From your response in #6

Responses that take longer than 10 seconds return a 504 gateway timeout message that I need to handle properly. Response that take between 6 and 10 seconds return the UNAUTH: Invalid nonce error.

If the response returns in the less than 6 seconds then it works properly.

So at the moment the only fix may be retrying the request.

I agree with you that lot of these errors are caused by on the KuCoin side as it depends on the time of day as to the frequency of the error.


I've got another observation now. The dealt orders available on my account just ticked over 100. When I attempt to fetch the 101st, I get a None type returned. It fails on the query which contains the 101st no matter my page or limit value.

My current workaround is to query for dealt orders twice; once for buys and once for sells... which is obviously a temporary solution.

The other obvious workaround is to limit the query per coin held as 100 orders is (maybe) more sufficient for a single coin; but this isn't ideal if you are building overall profit to date.

I'm guessing this may be a KuCoin issue also, but I just want to log it here, in case you can think of anything.

Cheers, Dan

sammchardy commented 6 years ago

Hi @danricho can you give an example of how you're trying to fetch the 101st order.

May need to clarify with the Kucoin devs on how to use the pagination properly.

danricho commented 6 years ago

I am currently using these two lines to avoid the 100 order limit:

order_list = kucoinAPI.get_dealt_orders(order_type="BUY", limit=100)["datas"] order_list += kucoinAPI.get_dealt_orders(order_type="SELL", limit=100)["datas"]

I previously was using a first call to get the total number of orders, then a second to get them all via the limit parameter.

Since finding the limit, I was playing with the current pagination available (as described previously).

I am open to other ideas, but I'm limited to not specifying the coin as my aim is to derive the held coins (also a full trading history and deriving the averaged cost/coin value).

sammchardy commented 5 years ago

Closing because of new API version