Kucoin errorhandling
See original GitHub issueIs this enough info to convert these errors from ExchangeError to NetworkError ? Sorry I don’t have verbose logging this time, hopefully the stacktraces give enough info.
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=20, file=sys.stdout)
- The 502 ‘Gateway Timeout’ seems obvious… It should be NetworkError by default imo. If exchanges use this error correctly, you can always recover from it by waiting a little (or a lot) and retry. Surely there are some exchanges that use 502 incorrectly, but shouldn’t we make exceptions for those then, instead of the other way around ?
- The 404 is less obvious, normally you can’t recover from this by retrying. But with Kucoin you can somehow, they unjustly generate 404’s when they’re busy.
The 502, fetch_order_book
Traceback (most recent call last):
File "/usr/local/scripts/test2/test2.py", line 841, in fetch_with_retries
result = json.loads(json.dumps(await fetch()), use_decimal=True)
File "/usr/lib/python3.6/site-packages/ccxt/async/kucoin.py", line 285, in fetch_order_book
}, params))
File "/usr/lib/python3.6/site-packages/ccxt/async/kucoin.py", line 534, in request
response = await self.fetch2(path, api, method, params, headers, body)
File "/usr/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 88, in fetch2
return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/usr/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 110, in fetch
self.handle_errors(response.status, text, url, method, None, text)
File "/usr/lib/python3.6/site-packages/ccxt/async/kucoin.py", line 531, in handle_errors
raise ExchangeError(self.id + ' ' + str(code) + ' ' + reason)
ccxt.base.errors.ExchangeError: kucoin 502 <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
The 404, create_limit_buy_order
Traceback (most recent call last):
File "/usr/local/scripts/test2/test2.py", line 703, in do_order
order_output = await action_with_retries(e, lambda: e.create_limit_buy_order(pair, float(amount), float(price)), retries=retries)
File "/usr/local/scripts/test2/test2.py", line 880, in action_with_retries
result = await action()
File "/usr/lib/python3.6/site-packages/ccxt/async/kucoin.py", line 357, in create_order
response = await self.privatePostOrder(self.extend(order, params))
File "/usr/lib/python3.6/site-packages/ccxt/async/kucoin.py", line 534, in request
response = await self.fetch2(path, api, method, params, headers, body)
File "/usr/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 88, in fetch2
return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "/usr/lib/python3.6/site-packages/ccxt/async/base/exchange.py", line 110, in fetch
self.handle_errors(response.status, text, url, method, None, text)
File "/usr/lib/python3.6/site-packages/ccxt/async/kucoin.py", line 531, in handle_errors
raise ExchangeError(self.id + ' ' + str(code) + ' ' + reason)
ccxt.base.errors.ExchangeError: kucoin 404
{}
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Exceptions — python-kucoin 0.2.0 documentation
On an API call error a kucoin.exceptions.KucoinAPIException will be raised. The exception provides access to the. status_code - response status code ...
Read more >kucoin_rs - Rust - Docs.rs
Error Handling. kucoin_rs uses the failure crate to propagate errors. Kucoin REST errors are passed as part of the response structs, however by...
Read more >KuCoin account support - Quicken Community
Quicken for Windows seems to support KuCoin accounts, however, this doesn't seem to work. ... Needs fixing and better error handling.
Read more >Exchanges — ccxt 2.4.71 documentation
Error Handling ¶. The error handling with CCXT is done with the exception mechanism that is natively available with all languages. To handle...
Read more >What is a Gate io/KuCoin New Coin Listings Crypto Bot?
A new coin listing describes the point in time at which a new cryptocurrency can be traded for the first time on an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Fcl69 Sure! Basically I check for the following exceptions:
(ccxt.RequestTimeout, ccxt.ExchangeError, ccxt.NetworkError, ccxt.InvalidNonce, ccxt.AuthenticationError)
.If I get them and I did a read operation, I simply sleep for a second and retry. After 10 tries I abort.
If I get them and I did a write operation (order, cancel_order), It could be that it processed anyway. So I check for that with
fetch_balance()
. If it went through within a minute I don’t retry.If it appears that it did not went through, it could be lagging and go through later (it made me cry the first time… but I’m in the acceptance phase now): If it’s a trade that I can retry without me getting very sad if I end up doing the same trade twice: I simply retry. Mostly those are trades that would completely empty the source symbol balance, or
cancel_order
. I can retry those as much as I want, the balance can’t go below 0 anyway and cancelling the same order id twice doesn’t matter much too. If it appears that it did not went through and it’s a trade that would made me sad if it happens twice I’m not retrying it. Periodically I check if it went through or not until I’m pretty sure it didn’t (10 minutes or so).I’ve tried quite some exchanges now, and almost all of them are horrible to script against. Error-catching and retrying is the easy part, the tricky part is the fact that the errors themselves are not reliable and that, despite the error, the operation in the background could be successful. After some time. Maybe. It’s horrible really.
I would say you’re moving in the right direction, in general, you’re not guaranteed any result right away from create_order (can be a http error, a net quirk, exchange outage, your local connection problem, a lightning just hit the house, anything…), so, upon an error you have to check the result of execution to make sure. A network error from create_order means literally: the order may be accepted or it may be not.