Rate limiting on the Deriv WebSocket API is a flow-control problem, not a bug. A bot that opens too many subscriptions, sends ticks faster than it consumes them, or fires `proposal` and `buy` calls without tracking in-flight state will eventually receive `RateLimit` errors or a dropped connection. The practical fix is three layers: exponential backoff with jitter for retries, a bounded request queue that serialises outbound calls, and priority scheduling so that time-critical calls (buy, sell, cancel) are never stuck behind low-value ones (tick subscriptions, balance polls). This article describes each layer with concrete numbers and a minimal pseudo-code reference.
Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.
Why Deriv Rate Limits Are Structural, Not Incidental
The Deriv API is a request/response protocol over a persistent WebSocket. Every `send` is a JSON message with a `reqid`, and every response echoes that `reqid`. Subscriptions (`ticks`, `proposalopencontract`, `balance`) are long-lived streams that keep pushing data until you call `forget`. This means a bot’s outbound message rate is a function of three things: how many subscriptions are open, how often the strategy logic calls `proposal`, and how aggressively retries are attempted. None of these are throttled by the platform unless you throttle them yourself.
The consequence is that a naive loop — send `proposal`, send `buy`, send `proposal`, send `buy` — will work fine on a quiet demo account and fail on a busy real account or during a volatile synthetic index session. The failure mode is not a crash; it is a stream of `RateLimit` errors interleaved with valid responses, which the bot must distinguish from genuine rejections. If the bot treats `RateLimit` as a strategy signal (e.g. “proposal failed, retry immediately”), it amplifies the problem.
The Deriv API documentation at developers.deriv.com specifies the error codes and the subscription lifecycle. Read it before tuning anything.
Exponential Backoff With Jitter
Backoff is the first line of defence. When a request fails with a rate-limit error or a transient socket error, the bot waits before retrying. The wait should grow exponentially with each consecutive failure, and it should include random jitter so that multiple bot instances do not synchronise their retries into a thundering herd.
A standard formula is `delay = min(cap, base 2^attempt) (0.5 + random())`. With `base = 500 ms` and `cap = 30,000 ms`, the sequence of maximum delays is 500, 1000, 2000, 4000, 8000, 16000, 30000, 30000 ms. The `(0.5 + random())` factor spreads each delay uniformly between 50% and 150% of the nominal value.
Two rules matter more than the formula. First, backoff must be per-request-class, not global — a rate-limited `proposal` should not delay a pending `sell`. Second, backoff must have a hard ceiling and a maximum attempt count. A request that has failed five times with rate-limit errors is not going to succeed on the sixth; it should be dropped and logged, not retried indefinitely.
Note: `RateLimit` and `InvalidRequest` are different. Only retry the former. A malformed `buy` will never succeed no matter how long you wait.
Bounded Request Queuing
The queue is the second layer. All outbound messages pass through a single serialiser that maintains at most N in-flight requests (N is typically 1 to 4; Deriv’s own libraries and the official Deriv API libraries handle this internally in some languages, but if you are writing raw WebSocket code you own it). The queue has a fixed maximum length. When the queue is full, new low-priority requests are dropped rather than buffered — buffering unboundedly just moves the failure from the socket to memory.
The queue also enforces a minimum inter-request interval. If the platform tolerates roughly R requests per second and you have observed errors at that rate, target 0.7 * R and leave headroom. The exact R is not published as a fixed number and depends on account and endpoint, so treat it as an empirical parameter: start conservatively, measure, and adjust only with recorded evidence.
A correct queue has these properties:
- Every request carries a `req_id` and a timestamp at enqueue.
- In-flight requests are tracked in a map keyed by `req_id`.
- A request that exceeds its timeout is removed from in-flight and either retried (with backoff) or failed.
- The queue exposes a `pending` count that the strategy can read; if `pending` exceeds a threshold, the strategy skips optional work (e.g. refreshing a chart subscription).
Priority Scheduling
Priority scheduling is the third layer and the one most often omitted. Not all requests are equal. A `buy` call that arrives 200 ms before the contract’s entry tick is worthless if it waits behind three `proposal` refreshes. Assign each request class a priority:
- P0: `sell`, `cancel`, `buy` — anything that closes or opens exposure.
- P1: `proposal` for an imminent entry.
- P2: `proposalopencontract` subscription management.
- P3: `ticks` and `balance` subscriptions, chart data, historical candles.
The serialiser always drains the highest non-empty priority queue first. Within a priority class, requests are FIFO. This guarantees that a P0 request waits at most for the currently in-flight request plus any other P0s ahead of it — never for a P3. In practice this is the difference between a bot that exits a Multiplier position on time and one that does not.
For fixed-stake contracts (Rise/Fall, Digits, Accumulators), there is no stop-loss or take-profit by price — risk is controlled by stake, duration, and session limits. Priority scheduling still matters because a delayed `buy` can miss the intended entry tick, which changes the contract’s start time and therefore its settlement. For Multipliers, where stop-loss and take-profit by price do exist, a delayed `sell` is a direct risk-control failure.
Worked example
Suppose a bot runs on a synthetic index with a 1-second tick. It maintains one `ticks` subscription, one `balance` subscription, and one `proposalopencontract` subscription — three persistent streams. Each new tick triggers a strategy evaluation that may call `proposal` once, and on a signal calls `buy` once. Assume the platform’s observed error threshold is around 10 outbound messages per second on the account in use, so the bot targets 7 per second (0.7 * 10).
Persistent streams contribute nothing to outbound rate after subscription. Strategy calls contribute at most 2 per second (one `proposal` plus at most one `buy` per tick). Subscription refreshes — say the bot re-subscribes to `proposalopencontract` after each contract closes — add roughly 1 per contract. If the bot trades once every 10 ticks, that is 0.1 contracts per second, so refreshes add 0.1 per second. Total steady-state outbound rate is about 2.1 per second, well under 7. The queue never fills.
Now consider a burst: a volatile session where the strategy signals on 5 consecutive ticks. Outbound rate for that second is 5 `proposal` + 5 `buy` = 10 messages, plus 0.5 refresh = 10.5 per second, above the 7 target and near the 10 threshold. Without priority scheduling, the 5 `buy` calls queue behind 5 `proposal` calls and may execute after the entry tick has passed. With P0 for `buy` and P1 for `proposal`, the serialiser interleaves them as `proposal` → `buy` → `proposal` → `buy`, and the P0s are never blocked by more than one P1. The queue’s `pending` count rises to 10, which the strategy reads and uses to suppress further optional `proposal` calls until it drops below 5.
The arithmetic: 10.5 messages per second exceeds the 7 target by 3.5, so the queue absorbs the excess for roughly (10.5 − 7) / 7 ≈ 0.5 seconds before draining. That is within tolerance. If the burst persisted for 3 seconds, the queue would hold about 10.5 messages, and the drop rule for P3 would kick in.
Limitations
This approach does not solve strategy quality, and it does not make a bad bot safe. Backoff, queuing, and priority scheduling reduce the probability of disconnects and missed entries; they do not eliminate them, and they add latency of their own. A serialised queue with a minimum interval introduces a floor on round-trip time that a direct send does not have. On very fast markets this floor can be the difference between filling at the intended tick and filling at the next one.
The approach also does not address authentication expiry, connection resets from the network side, or platform-side maintenance windows. Those require separate handling: a reconnect routine that re-subscribes and reconciles open contracts, and a session-limit check that halts the bot if the connection has been unstable. The exact rate-limit thresholds are not published as fixed numbers and may vary by account and endpoint; treat any figure in this article as an illustrative starting point, not a specification.
Finally, none of this substitutes for the ORSTAC premises. Demo first, with a recorded sample. Define the maximum loss before the expected gain. Risk at most 1% (ceiling 2%) of balance per contract; on fixed-stake contracts the stake is the maximum loss. Hard automatic limits on daily loss, drawdown, and consecutive losses, with the bot stopping itself. No martingale — and if any progression is used, a hard cap on steps and stake plus a ruin test before live. A backtest is a filter, not proof. Win rate is meaningless without payout; judge by expectancy, break-even rate, and drawdown. Rules are written before trading and changed only through a process. No data, no claim.
Frequently Asked Questions
Does Deriv publish a fixed request-per-second limit for the WebSocket API? No — the documentation describes rate-limit errors and subscription behaviour but does not commit to a single published number, so the practical approach is to measure on your own account and target roughly 70% of the observed threshold.
Should I retry a `buy` call that returned a rate-limit error? Only after confirming the original request did not execute, because a retried `buy` that actually succeeded the first time opens a second position — check `proposalopencontract` or your own request log before retrying.
Is priority scheduling necessary if my bot only trades once per minute? No — at one trade per minute the queue rarely exceeds one in-flight request, so a simple serialiser with backoff is sufficient, and priority scheduling only becomes material when bursts exceed the target rate.
Key Takeaways
- Rate limits are a flow-control problem: control outbound rate with a bounded queue, not with hope.
- Exponential backoff with jitter and a hard attempt cap handles transient errors; never retry `InvalidRequest`.
- Priority scheduling keeps `buy`, `sell`, and `cancel` ahead of subscriptions and refreshes.
- Measure your own threshold empirically and target about 70% of it; published numbers are not specifications.
- None of this replaces demo testing, hard session limits, or the 1–2% per-contract risk ceiling.
The reference implementation of these patterns, together with the bot templates that use them, is in the ORSTAC repository. The bots run on Deriv, where a free demo account is available to test them before any real stake is involved; discussion of specific implementations happens in the ORSTAC Telegram group.
Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.
