question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can exchanges override error handling?

See original GitHub issue

Let’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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mkutnycommented, Oct 20, 2017

If I asked you about how you would design the error overrides, what would you suggest?

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.

I’m thinking about defining handleErrors() method for each exchange…

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. This handleErrors() is called by handleRestErrors() at the very beginning.

If an exchange-specific override ofhandleErrors(response) detects an error in response then it throws an appropriate exception which is then propagated to a client by the handleRestErrors() of the base class.

If the override does not detect an error then it returns nothing effectively resorting to the handleRestErrors() default error handling.

0reactions
kroitorcommented, Oct 23, 2017

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling in Integration Flows
Error handlers in Camel will only react to exceptions set on the exchange. By default, they won't react if an irrecoverable error has...
Read more >
Error handling in Camel | Manning
By default, Camel handles exceptions by suppressing them; it removes the exceptions from the Exchange and stores them as properties on the Exchange....
Read more >
Error Handler - Apache Camel
The error handlers is inherited, so if you only have set a global error handler then its use everywhere. But you can override...
Read more >
java - Apache-camel - custom error handling - Stack Overflow
Yes you can have a generic error handler. In the configure method I have done like this: public void configure() throws Exception ...
Read more >
How to Handle Errors with Spring and Apache Camel - Medium
The boundaries of where an error handler can be triggered in Camel are the exchange limits : when a route starts, an exchange...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found