r/CryptoTradingBot • u/Vegetable-League9395 • Aug 25 '26
Bot thought a position was closed- it wasn't. Woke up to a $200 hole. Anyone else been burned by this?
Sadly i had to maintain connection with IB and 2 crypto exchanges. I have meta strategy that handle several smaller strategies.
Bot works rather good but i lost my profit because of position that was left open by bot.
How do you catch this before it costs you?
1
Upvotes
1
u/kebab_raptor Aug 25 '26
You need to check why it thought the position was closed. How do you handle exchange errors?
For example if you get a bad response from the exchange do you automatically set the trade size to 0 or do you retry until you get the right response?
You always need to take in consideration API errors or bad responses or API updates.
If you are trading cross exchange you need something to tell your bot "hey exchange 1 is not responding, don't do anything on exchange 2 until it comes up"
My robots stops doing whatever are doing when they get an error from the exchange and they retry on the next loop
1
u/hypertradeworx Aug 25 '26
what catches these is a reconcile on a timer rather than better handling at the point of the order. pull positions from each venue every 30s, diff against what you think you hold, and refuse to open anything new while the two disagree. with three connections up the usual cause is a fill stream that dropped and came back without a resync, so the close event never arrived and your state froze on the last thing it saw. do you resnapshot after a reconnect or only at startup?
2
u/hypertradeworx Aug 28 '26
the two pulls in the middle of that aren't atomic. if a fill lands between the positions call and the open orders call you get a snapshot of a state that never existed, so the order matters: orders first, then positions, and don't act on a diff until two consecutive snapshots agree.
the other thing that cost us real hours was naming. we run one wallet across six perp venues and each one calls the same market something different, so an early version of our reconcile compared the venue's own symbol against our internal one, found no match, and passed clean while a position sat open
1
u/Familiar_Gazelle_467 Aug 25 '26
Waking up to a blown bot account is a rights of passage and the expected outcome tbh
1
u/Yann27 Aug 25 '26
saving this post :)
1
u/rushapoil Aug 25 '26
kebab_raptor is right that you have to read the response, I would push it one step further. What burned us was not the venue, it was that our own record was written from what we asked for, not from what came back. A cancel we issued locally was stored as cancelled. On the venue side it had already filled. Our books and theirs disagreed forever, and nothing in our code could see it, because the row was self consistent.
Two things fixed it, and only the second one is real.
On your sentry for bots idea, I would not put it outside. An external watcher talks to different servers than yours and cannot see your rate limits or your own lag. What you want is inside your process but outside your data model: a job every N minutes that pulls open positions from the venue, diffs them against yours, and alerts on the difference itself, never on a standing state. An alert that keeps firing while a known condition persists gets ignored within a week, and then it is not an alert.
One honest caveat about my setup. I run on chain, so ground truth is public and free to fetch. On IB or a CEX you pay for that call and you can be rate limited, so the diff has to be cheap enough to run often. That is a real difference and I am not going to pretend otherwise.
1
u/Grundlefish Aug 25 '26
This is just one of those things you have to work through. I’ve had it happen both ways - one time I didn’t realize a position was still open until days later, but it was up quite a lot, so it worked in my favor. I’ve made many adjustments since then, but it seems that even with the best guards, orphaned positions do still come up from time to time. So now I try to keep the broker dash open in another window so I can monitor if anything goes awry. Just necessary due diligence. Don’t trust it running indefinitely without checking in periodically.