How I Fixed the Binance -2022 Bug in a Live Trading Bot
The December 2025 algo order migration broke my live trading system. Here's what happened, why it happened, and how I fixed it under pressure.
In December 2025 Binance migrated algo orders — TRAILING_STOP_MARKET and similar — which broke the close-position flow in my live trading bot. This is the full post-mortem.
What -2022 means
Error code -2022 is "reduceOnly Order is rejected". The bot was trying to close a position with a MARKET order while an algo stop-loss order was still active. Binance's new rules no longer allow this.
The fix
Before sending the MARKET close order, explicitly cancel the active SL order and wait for confirmation. The order of operations matters — cancel, confirm cancellation, then close. Adding a retry with exponential backoff on the cancellation confirmation was the final piece.
Lessons
Exchange APIs change without enough warning. Any production trading system needs an atomic state machine for positions, not just optimistic order sends. The OPEN→CLOSING→CLOSED state with MongoDB claims is what saved the live capital during the incident.