can exchanges override error handling?
See original GitHub issueLet’s say I’ve got the following exception from Kuna:
[Exchange Not Available Error] kuna POST https://kuna.io/api/v2/orders 400 Bad Request {"error":{"code":2002,"message":"Failed to create order. Reason: cannot lock funds (amount: 0.000138)"}} (possible reasons: invalid API keys, bad or old nonce, exchange is down or offline, on maintenance, DDoS protection, rate-limiting)
The issue is that my existing sell order was executed before I had a chance to refresh a balance. As a result, I thought I had an inventory and tried to submit one more sell order but had insufficient funds for it (as I sold all my inventory before).
If I had a chance to know that I had insufficient funds then I would have updated a balance programmatically. Unfortunately, instead of InsufficientFunds
I caught ExchangeNotAvailable
exception.
I see that you have a single error handler for all exchanges but it’s too generic to handle all individual cases.
One approach would be to let exchange instances to override error handling. So that if I see an error to be incorrectly classified by generic handler I could handle it in exchange class.
Is there is a way for me to do it with the current ccxt
implementation?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top GitHub Comments
I’m not fluent in JavaScript (I came here a month ago from typed languages world) so please, don’t treat me rough if you find my suggestions stupid.
The following is based on assumption that error handling is done by
handleRestErrors()
method of the base class.I think of empty
handleErrors(response)
method in the base class which exchange implementations could override. ThishandleErrors()
is called byhandleRestErrors()
at the very beginning.If an exchange-specific override of
handleErrors(response)
detects an error in response then it throws an appropriate exception which is then propagated to a client by thehandleRestErrors()
of the base class.If the override does not detect an error then it returns nothing effectively resorting to the
handleRestErrors()
default error handling.This issue was closed here: https://github.com/ccxt-dev/ccxt/pull/375 in v1.9.236. Exchanges can now override default error handling in all languages. Thx for your feedback and for your amazing help! It is really important to us!