ctubio / tribeca

Self-hosted crypto trading bot (automated high frequency market making) in node.js, angular, typescript and c++
https://127.0.0.1:3000
Other
95 stars 26 forks source link

(IMPROVEMENT) Error handler #23

Closed Camille92 closed 7 years ago

Camille92 commented 7 years ago

Given the errors #15 and #21 and others I was thinking of a better way to deal with errors.

Goals: Improved general stability of Tribeca Offering better solution to coming errors _ Easier implementation of new exchanges

The problem: When there is an error, Tribeca can react in three different ways: 1: it leads to a crash and forever restarts tribeca The error is not solved and the stability is affected/ 2: It is dealt in the exchange gateway The error is solved but it needs to be coded for each exchange 3: Or it's a minor error not leading to a crash There error is not solved, and not optimum solution is given.

Proposed improvement: The idea is that a gateway error should not lead to a total crash of tribeca. It should be dealt by a "error handler" layer. This layer would be above the gateway layer, maybe part of the "adapter layer". When an error occurs it is sent to this error handler that gives a series of solutions and, when it is possible the solution should be common to different exchanges.

Ie: Tribeca is trading on Okcoin. It encounter an error 10010 (insufficient fund). It translates it in a "common error name" ie. Insfund and send it to the erorr handler. Error handler processes it and send back to okcoin gateway a solution "cancel all open orders and retry". If the error is not solved, you can imagine that the second time error handler would send a "stop trading for X seg and retry" to OkCoin.

The idea is to keep the errors between "error handler" and the gateway without provoking a general crash.

If you have an unknown error, instead of crashing like now, error handler could give a series of general solution like "stop trading for X seg and retry" (with X growing over time). Or "Stop API connection and reconnect".

Lastly I think it is convenient when you add a new exchange, you just need to link the error sent by them to the common name managed by "error handler" and it is solved.

Camille92 commented 7 years ago

After doing long readings on the matter, I think a try catch or domains should do the job very well and would be easier :)

Camille92 commented 7 years ago

Maybe not that useful after all !