r/CryptoTradingBot • u/AoideusWasBanned • 13d ago
What does your bot do when the exchange API goes down mid-trade?
This is the part of running a bot I think about the most and test the least. Backtests never have a moment where the exchange stops answering, but live it happens, usually at the worst time.
So I'm curious how y'all handle it:
- If your bot crashes or loses connection with an open position, what happens next?
- Do you keep stop losses on the exchange side, or does the bot manage them?
- How do you make sure it doesn't send the same order twice after a reconnect?
- Do you get an alert, or do you find out when you check the balance?
Not after a perfect setup, just wanna know what you actually run and what bit you before. Thanks in advance.
2
u/FromBitcoinWithLove 13d ago
What you are asking is called "Fault Tolerance, Interruption Handling, and Recovery".
WebSocket recovery:
During an ACTIVE lifecycle, if your bot detects connection failures, it must use its existing recovery and reconciliation paths. It should first try to reconnect to the exchange using Market-data WebSocket.
Authoritative REST recovery
When applicable, your bot uses exchange REST queries to recover or verify information that cannot safely be established from the available web socket stream evidence.
Recovery after a process restart
A restarted bot does not simply assume that its previous trading mission completed. It must examine the locally recorded lifecycle and obtains exchange evidence needed to establish the current operational condition.
If an unresolved trading lifecycle or exposure exists, your bot must follow its supported recovery and reconciliation route.
2
u/TrenchersAi 12d ago
the stuff that bit us early was always the reconnect, not the crash itself.
what we run now:
- stops live on the exchange side whenever the venue supports it. if the bot dies, the position still has a floor.
- every order gets a client order id generated before sending. on reconnect the bot checks that id first, so a retry can't double fill.
- on restart the bot never trusts its own memory. it pulls open orders and positions from the exchange and rebuilds state from that.
- heartbeat with an alert if it misses two in a row, so you find out from a ping, not from your balance.
- if state looks wrong after reconnect, it goes flat or freezes new entries instead of guessing.
backtests never simulate the api going quiet, so we kill the connection on purpose in paper mode to test it.
1
u/[deleted] 13d ago
[removed] — view removed comment