Why hot-swap of strategies breaks in live trading
Hot-swap of strategies looks like a simple operation: stop one logic, bring up another without shutting down the trading loop.
That is exactly the moment when the bot diverges from what actually sits on the exchange — and the cost of an error is measured not in hours of downtime but in an open position that no one manages.
First typical failure — position desynchronization. The old logic has already sent an order, the new one doesn't know about it: there is no position in memory, but there is one on the exchange.
Then each side calculates volume from its own picture, and a normal overlap turns into a doubled position.
This is closed not by engineer's care but by reconciliation: before replacing logic in live trading, a snapshot of positions and open orders is taken from exchange state, not from process memory.
Second — duplicate orders. If the old and new strategies run in parallel for some time, and a trading bot restart falls at the moment of partial execution, both see the same signal and place an order twice.
Without a unique key by which the exchange cuts off repeats, and without an explicit sign of "who owns the position now", duplicates are not filtered out, and they have to be removed manually.
Third — state loss. Indicators, accumulated statistics, the level of the last protective stop trigger live in memory: when logic is substituted they reset, and the new strategy starts as if there is no position. Hence false entries and removed stops.
A trading cycle pause at this moment looks harmless, but it is exactly what masks the problem — the loop works, while decisions are made on empty history.
We break down how this is closed: state contract, transfer of position ownership, and reconciliation points with the exchange.
What changes after implementing managed logic replacement
Previously, changing trading logic meant a downtime window: take the bot off the market, wait for trades to close, roll out a new build, and manually reconcile positions.
Managed logic replacement moves this process inside the running system: the new module comes up in an isolated slot, accepts a snapshot of position state, and only after reconciliation takes over the order flow.
The key here is position integrity. Switching does not break the link between open trades and the logic that manages them: orders, stops, and accumulated context are transferred together, and duplicates and orphaned orders do not appear.
The switch itself fits into seconds, so night and weekend sessions stop being a forbidden zone for releases.
Version control of trading logic is built on immutable artifacts: each version has its own fingerprint, change description, and attached set of parameters.
Configuration rollback is performed in one operation to the previous slice, together with risk settings and limits, rather than by editing files on the server.
This removes a separate class of failures during version changes — desynchronization between strategy code and its parameters, which usually surfaces on live trades.
The effect is visible in measurable values: the share of manual operations during release drops almost to zero, and returning to the previous version takes as long as a normal switch.
We display metrics of module replacement without stopping (strategy hot-swap) and state discrepancies on Grafana monitoring panels — an incident is analyzed by graph, not by real-time logs.
Replacement modes: strategy hot-swap versus full restart
The replacement mode is determined not by deployment convenience but by where state lives. As long as open positions, orders in flight, and quote stream subscriptions remain in process memory, switching logic is an operation over state, not over configuration files.
Hence three options: live module replacement, parallel launch of versions, and full bot restart — each has its own applicability conditions.
| Option | When it fits | Limitations |
|---|---|---|
| Live module replacement | stateless logic computed from market data | cannot change the configuration schema or portfolio structure on the fly |
| Parallel launch of versions | need to compare two logics on one order flow | versions share limits per instrument, an explicit flow separator is required |
| Full bot restart | core, connection transport, or accounting model changes | positions and orders are restored from the journal, there is a downtime window |
The key point is switching the order flow. The new logic must not pick up orders placed by the old one, otherwise duplicates and removal of other people's orders are possible.
Switching is done along a boundary: wait for confirmations on all active orders, cancel unexecuted ones, transfer a position snapshot, and only then enable the new module.
We test mode limitations in a rehearsal: the same scenario is run on historical data, and it is clear in advance how long the downtime window lasts and which orders fell at the moment of switching.
Implementation stages: from loop audit to handover
Implementing logic replacement on a running loop is not rewriting a module but a managed change in the behavior of a system that already holds positions.
Therefore we go from survey to acceptance and at each step record exactly what is switched and how to return to the previous version.
- Trading loop audit. We capture the interaction diagram of the bot, exchange interfaces, state storage, and journals. Separately, we note which data the strategy reads at input and which orders it forms at output.
- Switching scheme. We design the boundary between old and new logic: handler substitution, strategy version in configuration, or a separate executor process. Here we also describe what happens to open positions at the moment of change.
- Replacement mechanism implementation. We build hot replacement without stopping trading: version check, parameter validation before activation, predictable behavior with incomplete data.
- Historical data validation. We run the new logic on archived quotes and compare trades, drawdown, and risk metrics with the previous version. Discrepancies are analyzed before enabling in the production loop.
- Logic replacement implementation. We enable gradually — first on a limited set of instruments or share of capital, with automatic return to the previous version under specified conditions.
- Acceptance and handover. We hand over configurations, switching scheme, rollback regulations, and incident analysis procedure; we train the on-call team and record who and how launches strategy change.
Delivery package: configurations, schemes, regulations
After handover, the customer's team retains not only a running loop but also a complete set of documentation by which they can independently change active strategies, roll back releases, and analyze incidents without our involvement.
We assemble artifacts so that the on-call engineer finds the needed document in a minute rather than reconstructing logic from code.
- Switching configurations: a separate profile for each strategy with activation parameters — by schedule, on threshold, or manually, plus limits on position size and number of simultaneous entries.
- Rollback regulations: step-by-step procedure for returning to the previous version with timeouts, checkpoints, and a list of states that must be reconciled after return.
- Flow schemes: the path of market data from receipt to order placement and journal entry, with marked queues, buffers, and places where an event can be lost.
- Access matrix: who prepares the configuration, who confirms the release, who has the right to emergency switching, and how roles are transferred when an employee changes or leaves.
- Version journal: which strategy and with which parameters was active at each point in time — the basis for analyzing trades and disputed situations.
- Post-switch acceptance checklist: a set of control reconciliations showing that the new version started correctly and processes the flow.
- Test stand instructions: how to reproduce strategy behavior on historical data without affecting the production loop.
Case: module replacement in live trading without stopping
A trading bot on OKX managed several instruments at once, and changing logic meant stopping it: exporting positions, manual reconciliation with the exchange, restarting.
A release took 40-90 minutes of live market — volatility windows passed, and changing a version required six to eight manual operations.
We separated strategy and execution and built logic hot-swap: the strategy became a swappable module with a fixed interface, and state — positions, placed orders, candle cursors — moved to separate storage that lives longer than any version.
The new version comes up alongside, receives a snapshot, and is validated on a shadow market data stream before taking control.
Switching is an atomic substitution of the pointer to the active module within one processing cycle. Orders from the previous version remain under supervisor control until closure, so the position is not left unattended at the moment of change.
Rollback is arranged the same way: the previous module lies in the version registry and is enabled with one command.
Metrics before and after
- trading break: 40-90 minutes of pause → zero, the switch fits into one processing cycle;
- manual interventions: six to eight operations per release → one confirmation in the panel;
- failures during version change: three out of ten changes produced position desynchronization → none;
- rollback: return to the previous module without rebuild and repeated reconciliation.
Each change writes the module version, state snapshot, and supervisor decision to the journal — incident analysis takes minutes instead of hours. Logic experiments and nightly releases stopped being an event for trading.
What if you already have your own configuration dispatcher?
You do not need to rewrite the trading core. Your dispatcher remains the single entry point for bots; only the data source changes: the custom storage is replaced by a managed configuration layer via an adapter.
The core still calls the same read method and the same change subscription — the interface contract is preserved.
The adapter covers three things: versioning of the strategy schema, atomic publication of a new revision, and rollback to the previous one in one operation. Publication includes integrity validation, so the bot does not pick up half a configuration. Subscription works the same as in your solution — hot parameter replacement remains instantaneous.
We migrate without stopping trading: enable mirror writing to the old and new storage, read from the old one for now, and compare discrepancies. When there are none, we switch one strategy at a time — then an error affects one instrument instead of the entire portfolio.
For storage we take Consul or a similar managed service if a suitable one already exists in the loop.
The main risk of transition is not code but desynchronization during dual writing and behavior when storage is unavailable.
We close this with a cache of the last valid configuration and a wait limit: if the external layer does not respond, the bot works on a verified revision rather than stopping. Rights, audit, and network rules remain yours — we do not expand access, only transfer management.
Technical questions: validation, rollback, open positions
Hot strategy replacement is not a bot restart but a change of control logic on a live account. Before starting, we fix three invariants: the fate of open positions during replacement, reversibility of switching, and boundaries of partial rule replacement. We answer in the form in which an engineer asks these questions.
What happens to open positions during replacement?
Forced closure on live liquidity causes slippage, so positions are not closed. The new strategy receives a snapshot of portfolio state — size, average price, placed protective orders — and manages them itself.
If the risk model changes, the old logic brings the position to a flat state, and the new one takes only new entries.
Can a strategy version be rolled back?
Yes. Each logic build receives an immutable identifier and enters the version registry together with parameters. Rollback is switching the pointer to the previous build plus reconciling account state with actual orders and balances: seconds, without stopping the trading loop. The rollback itself is rehearsed on a test loop before release.
Where are the boundaries of partial rule replacement?
Entry, exit, and risk manager modules change independently as long as the interface contract and state model remain unchanged — they communicate through a fixed set of events.
A new order type or a change in state structure requires full replacement with snapshot migration, otherwise the position will remain without support.
Before going live, the new logic enters shadow mode: it calculates signals in parallel with the current one, and discrepancies are analyzed line by line. Validation of the new logic relies on actual trades, and switching becomes a managed event with a known cost of error.Let's discuss the task: we'll return with a scheme and work estimate
To return with a switching scheme and implementation plan, we need a slice of the current loop — specifics on the places where the strategy interfaces with order execution.
It is enough to send, in free form, configurations, a state storage scheme, and a restart log at the moment of strategy hot-swap.
- Where strategies live: a separate process, a module inside the bot, or an external service — and how they receive parameters.
- What happens to open positions and placed orders at the moment of logic change: closed, transferred, or left as is.
- How state is stored — in memory, in a local file, or in a database — and whether it survives a restart.
- How long manual switching takes and what steps the on-call engineer performs.
- Where the bottlenecks are: locks, races when reading configuration, lack of an integral transition between strategies.
- How rollback is arranged: whether there is a previous parameter set and how quickly it can be returned.
- Which metrics are taken from the strategy and by which signs you understand that switching went normally.
- Access and environment constraints: test loop, broker connections, deployment rights.
Based on this, we assemble a switching scheme: points where the new strategy is picked up without stopping trading, the order of displacing the old one, and rollback conditions.
Along with it — an estimate of the scope of work by stages and implementation timelines with a breakdown: what we enable first, what we move to the second priority. Describe the task — we'll return with this package.







