A bot that misbehaves on a live Deriv account is usually misbehaving for one of two reasons: the logic is wrong, or the market conditions that triggered it cannot be recreated. The second problem is the harder one, and it is the one that makes debugging feel like guesswork. Capturing the raw WebSocket tick stream and replaying it through the exact same execution path removes the guesswork. This article describes a practical method for recording Deriv ticks, storing them with enough metadata to be deterministic, and feeding them back into your bot so that any anomaly, live or in backtest, can be reproduced on demand.
Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.
Why Deterministic Replay Matters
A backtest that reads from a CSV of closes is not the same execution path as a live bot that reacts to individual ticks. The live bot sees a sequence of messages, applies timing, evaluates conditions, and may place a contract mid-stream. If you debug only against a CSV, you are testing a different program than the one that runs live.
Deterministic replay means the same input sequence produces the same decision sequence. To get that, you need three things recorded together: the ticks themselves, the timestamps at which they arrived, and the bot state at the moment each tick was consumed. Without the third, you can replay the market but not the bot’s reaction to it.
The goal is not to prove a strategy is profitable. It is to make failures reproducible. A reproducible failure can be fixed; an unreproducible one can only be avoided.
Recording the Stream Correctly
The Deriv API delivers ticks over a WebSocket subscription. The Deriv API documentation describes the `ticks` and `ticks_history` calls, and the official Deriv API libraries handle the connection layer. Your recorder should sit as close to the socket as possible, before any bot logic touches the data.
Record each message with:
- The raw payload as received, unmodified.
- A local monotonic receive timestamp in milliseconds.
- The subscription request that produced it (symbol, granularity if any).
- A session identifier and a schema version.
Do not record only the price. Record the full message, including fields you do not currently use. Deriv may add fields, and a replay that strips them is no longer faithful to the original stream.
A minimal recorder in pseudo-code:
open socket to Deriv API
send { ticks: "R_100", subscribe: 1 }
on message:
t = monotonic_ms()
append { t, raw: message } to ticks.log
forward message to bot
The forward step matters. The recorder must not alter the stream the live bot sees, or the recording will not match live behaviour.
Store the log in append-only form, one JSON object per line. Include a header line with the symbol, the API endpoint, and the recorder version. If you later change how the bot interprets ticks, you can still replay old logs against old bot versions.
Replaying Through the Same Execution Path
The common mistake is to write a separate replay harness that calls the strategy function directly. That harness diverges from the live path over time, and the divergence is exactly what you are trying to eliminate.
Instead, make the data source an injectable dependency. The bot should not know whether ticks come from a socket or a file. Both sources emit the same message objects in the same order, and the bot’s tick handler is identical in both cases.
A replay loop:
load header and ticks.log
for each record in order:
wait until monotonic_ms() >= record.t - start_offset
deliver record.raw to the same handler used live
The optional wait reproduces inter-tick timing. For most logic this is unnecessary, and replaying as fast as possible is preferable. But if your bot uses time-based conditions, such as “no tick for 500 ms, then act,” you must preserve timing or the replay will not match. Decide explicitly which mode you are in and label the output accordingly.
Two further requirements for determinism:
- Seed any random number generator in the bot from a recorded seed. If the bot uses randomness for stake sizing or contract selection, an unseeded replay is not deterministic.
- Freeze the configuration. Record the bot’s parameters alongside the tick log. A replay with different parameters is a different experiment.
For Deriv Bot users, the same principle applies at the block level. DBot does not natively expose a tick-injection interface, so the practical route is to run the equivalent logic outside DBot against recorded ticks, or to use the Deriv API libraries to build a testable harness. The Deriv Bot interface is useful for visual strategy construction, but reproducible debugging generally requires code you control.
Worked example
Suppose you record 10,000 ticks of a synthetic index and replay them through a Rise/Fall bot. The bot places a fixed-stake contract of 1.00 USD on every 100th tick, with a payout ratio of 0.95 on a win. Assume, purely as an illustration, that the replay produces 40 wins and 60 losses across 100 contracts.
- Wins return stake plus payout: 40 × (1.00 × 0.95) = 38.00 USD.
- Losses forfeit stake: 60 × 1.00 = 60.00 USD.
- Net result: 38.00 − 60.00 = −22.00 USD.
The break-even win rate for this payout is 1 / (1 + 0.95) = 0.5128, or about 51.3%. The observed 40% is below it, so the replay shows a losing configuration. That is a statement about this sample only. It is not proof the strategy fails in general, and it is not proof it would have succeeded with different parameters. It is a reproducible fact about a specific input sequence and a specific rule set, which is exactly what you need to debug.
Now suppose the live account showed a 55% win rate over the same period while the replay shows 40%. That discrepancy is the anomaly worth investigating. Possible causes: the live bot saw ticks the recorder missed, the live bot’s state differed at session start, or the recording began mid-session. Each cause is testable once the replay is deterministic.
Operational Rules for Replay Sessions
Treat replay as an experiment with a written protocol, consistent with the ORSTAC premise that rules are written before trading and changes follow a process.
- Record the hypothesis before replaying. “The bot places a contract after a missed tick” is a hypothesis. “The bot is broken” is not.
- Replay the same log against the current bot version and against the version that produced the anomaly. If both behave identically, the bug is in the market data, not the logic.
- Log every decision the bot makes during replay with the tick index that triggered it. This is the audit trail.
- Change one parameter at a time and version the change. Do not tune after a loss; tune after a completed replay analysis.
- Keep the tick log. Storage is cheap; an unreproducible anomaly is not.
If a replay shows a configuration with a positive result, that is a filter, not proof. Test on out-of-sample ticks, report how many configurations you tried, and remember that a backtest with many attempts will produce some winners by chance alone.
Limitations
Deterministic replay does not reproduce execution latency, slippage on entry, or the platform’s internal matching behaviour. Deriv contract pricing and payout ratios can change; a replay using recorded payouts will not reflect a later change in the payout schedule. Replay also cannot reproduce the psychological difference between demo and real money, which affects human-in-the-loop decisions but not a fully automated bot. Finally, replay validates logic against recorded conditions only; it says nothing about conditions you have not recorded, and past tick sequences do not predict future ones.
Frequently Asked Questions
Does replaying ticks guarantee my bot will behave the same live?
No. Replay guarantees the same decision sequence for the same input and configuration; live execution adds latency, platform state, and payout changes that replay does not capture.
Can I use this with Deriv Bot directly?
Not natively. Deriv Bot does not expose a tick-injection interface, so deterministic replay is typically implemented with the Deriv API libraries in code you control.
Is a positive replay result evidence the strategy works?
No. A positive replay is a filter, not proof; it must be followed by out-of-sample testing and a clear record of how many configurations were tried.
Key Takeaways
- Record raw WebSocket messages with receive timestamps and the subscription request, not just prices.
- Inject the data source so live and replay share the same execution path.
- Seed randomness and freeze configuration, or the replay is not deterministic.
- Treat replay as a debugging tool, not a profitability test.
- Keep logs and version changes; an unreproducible anomaly cannot be fixed.
The ORSTAC repository contains open-source bots and harness patterns for this kind of work, and Deriv provides the platform and API used to record and replay these streams, with a free demo account available to test the bots. Discussion of recording formats, replay harnesses, and anomaly reports is welcome in the ORSTAC Telegram group.
Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.
