# Limits and lockouts Every cap in the API in one place: request sizes, stream counts, timeouts, lockouts and the broker's own limits. Termless does not rate-limit ordinary API calls: it is your server, and the broker's own limits apply behind it. The caps below exist to keep one misbehaving client from harming the rest. ## Requests | What | Limit | |---|---| | Symbols per quote or stream request | 200 (`?symbols=`) | | `GET /trades` without `after` | the newest `limit` events, default 100, at most 1,024 (0.6.3) | | Candles per request | 50,000 by `count` (`count` plus `offset`); a `from`/`to` range over 100,000 bars is `400`, one over 50,000 keeps the latest 50,000 | | Big candle requests (over 10,000 bars) | one at a time per account; the account's others wait their turn (within the 30 s route bound) | | Batch candle reads (`POST /candles/batch`) | 1 to 20 ranges, at most 200,000 bars in all (each range's whole span counts); a bad range refuses the batch (0.7.0) | | Specs per request (`GET /specs`) | 200 names (0.7.0) | | Statistics (`GET /stats`) | a range of at most 366 days; `days` 1 to 366 (default 30) (0.7.0) | | How long a `/quotes` read keeps its symbols | `hold` 0 to 3,600 s (default 600); `0` subscribes nothing (0.7.0) | | Ticks per request (`GET /ticks`) | `count` 1 to 20,000 (default 1,000), from what the server kept (below) | | Deals or history orders per request | a `from`/`to` range of at most 10 years; default the last 8 days up to tomorrow, or 10 years back with `position` or `ticket` | | Order books (`GET /book`) | 32 per account (one more is `400`; `DELETE /book` releases one); a book older than `max_age_ms` (100 to 60,000, default 1,000; outside that is `400`) is asked for again, waiting up to 3 s; a symbol that brought no fresh book is not asked again for 30 s, one the broker never sent a book for (`time: 0`) for 5 minutes | | Symbol search | `limit` up to 10,000 (default 50) | | Server directory search | `limit` up to 200 (default 20) | | Deals page, history orders page | `limit` up to 5,000 (the default), `before` cursor | | Trade events kept for resuming | the last 1,024 per account (`GET /trades?after=`, `?after=` or `Last-Event-ID` on a stream); older is a `resync` | | Audit trail page | `limit` up to 1,000 (default 100), `before` cursor | | Connection history page | `limit` up to 1,000 (default 100), `before` cursor | | Equity curve | `hours` 1 to 168 (default 24) | | Undecoded frames | `limit` up to 200 (default 50); `body_hex` cut to 128 bytes unless `bodies=1` (then up to 64 KB a frame) | | Log lines | `lines` up to 5,000 (default 200) | | Request body | 1 MB | | `Idempotency-Key` | 1 to 200 printable ASCII characters; reserved before the broker is asked; results kept 24 hours; a concurrent repeat waits up to 30 s | | `X-Request-Id` | 1 to 64 characters of `A-Z a-z 0-9 - _ . :` (anything else is replaced) | | `comment` on an order | up to 255 characters (more is `400`); the broker keeps 31, Termless keeps the whole text for a market or pending order | | Key name | up to 80 characters | | Account id | `a-z`, `0-9`, `-`, up to 48 characters | | Query parameters | one a route does not take is `400`, naming the ones it takes; `key=` is accepted anywhere | | Admin password | 15 to 200 characters with a lowercase letter, a capital, a digit and a symbol (anything but a letter or a digit is a symbol, a space too). Checked when a password is set; one set before the rule keeps working until it is changed. | ## Streams | What | Limit | |---|---| | Open streams per server | 1,024 (SSE and WebSocket together) | | Open streams per key or dashboard session | 256 | | Symbols per stream | 200 | | Symbols streamed per account beyond its watchlist (every stream's, quotes read's and ticks read's symbols; a stream's leave when its last stream closes, a read's when its lease ends, 0.7.0; before, a read's stayed until a restart) | 1,000 (0.6.3; a stream or read past it is refused with 400; the watchlist is never counted, never refused, and a symbol taken off it stops streaming unless a stream holds it) | | Buffered ticks per stream | 1,024; beyond that a slow client gets the latest tick per symbol and a `gap` event (0.7.0) | | Bar series per stream | 100 (`bars=`, 0.7.0); buffered bar events 1,024, beyond that a slow stream gets a `bars_gap` per series | | Bar series per account, across its streams | 200 symbols and 1,000 series (0.7.1); past either a stream's series are refused with `429` and a message naming the cap | | `batch_ms` | 0 to 100 | | Heartbeat | every 15 s (SSE comment, WebSocket ping) | A stream over either count answers `429 too_many_requests` with `Retry-After` and a message naming the cap. ## Time | What | Value | |---|---| | One broker request | 20 s before it is given up (`504 timeout`) | | Waiting for a turn (requests of one command go to the broker one at a time per account, candles from many callers included) | up to 20 s, then `503 busy`: the request was not sent, so sending it again is safe | | A request the broker did not answer in time | keeps its kind's turn up to 40 s more for its late reply; if none comes, the link is closed and the account reconnects | | One API route (except streams) | `504 timeout` after 30 s in total (`TERMLESS_REQUEST_TIMEOUT` seconds; `0` = no bound) | | A trade's result push after the broker queued it | 25 s, then `504` from the trade route itself (the audit row and the idempotency result are still written; the position may have opened) | | Waiting for a reconnecting account before `503` | up to 2 s | | Waiting for a first price on a newly subscribed symbol | up to 3 s | | A quote lease (`/quotes`, `/ticks`) | 600 s after the caller's last read by default; ended leases are let go every 30 s (0.7.0) | | A bar's close (bar streams) | read from the broker 2 s after its period ends; read again a minute later (0.7.0), and so is a period that closed with no bar while its symbol was trading (0.7.1) | | A cached symbol spec | read again once it is a day old (`TERMLESS_SPEC_MAX_AGE_S`, 0.7.0), off the trade path: a trade, a position read or a margin check uses the spec it has and never waits on that read | | A symbol subscribed for the server's own use (a `/calc` price, a conversion, a position's price) | kept 10 minutes after its last use (`TERMLESS_OWN_SUB_HOLD_MS`), at most 200 per account, then let go (0.7.0) | | A trade still waiting for its turn when its deadline passes | never sent: `503 busy`, so sending it again is safe (0.7.0) | | A tick subscription the broker refused or never confirmed | sent again at the next sweep, every 30 s (0.7.0) | | A candle in the cache | only once it closed at least 15 minutes ago; younger bars always come from the broker (0.7.0) | | Reconnect backoff | 1 s, doubling to 30 s, with about 20 % jitter | | Retry after the broker rejected the login | after 10, 20, 30 and 60 s when the login worked within the last hour (a broker restarting refuses logins with code 2 for seconds to minutes), then every minute for code 2 until an hour after the loss (0.6.3), then every 5 minutes; any other code, or no recent working login, every 5 minutes | | Dead-link detection | a ping every 5 s must be answered within 6 s; the second miss in a row closes the link (12 to 17 s after the broker went quiet), the fifth while a big reply is still arriving (about 30 s) | | Dashboard session | 30 days | ## Retention | What | Kept | |---|---| | Audit trail | 90 days or 200,000 rows, whichever is hit first | | Connection history | 90 days or 50,000 rows | | Equity samples | 7 days (one a minute while connected) | | Idempotency results | 24 hours | | Magic numbers and long comments kept for orders sent through Termless | 400 days, the newest 100,000 orders | | Trade events kept for resuming | the last 1,024 per account, in memory and in the database, so the numbering carries on across a restart or an upgrade | | Ticks kept for `GET /ticks` | since 0.7.0 only for symbols read through `/ticks` (from the first read on): the newest 1,000 per symbol (`TERMLESS_TICK_HISTORY`, at most 100,000; `0` keeps none) and 100,000 over all of an account's symbols, shared evenly (500 symbols keep 200 each); in memory, about 7 MB an account at most; a reconnect starts them again | | Settled candles (the candle cache) | 32 MB over every account (`TERMLESS_CANDLE_CACHE_MB`, `0` keeps none), least recently used out first; a new broker connection starts an account afresh (0.7.0) | | Log files | 14 days, one file a day | | Undecoded frames | 200 in memory, read back from the end of `captures/undecoded.jsonl` at start; at most 5 bodies an hour per (account, command, kind) appended to that file | Pruning runs at start and then hourly, off the request path. ## Lockouts Counted per caller, each lasting 15 minutes. A caller is its IPv4 address, or for IPv6 its /64 (the block one home or server is normally given), so stepping through the addresses of one block does not reset the count: | Trigger | Locked out of | |---|---| | 5 wrong admin passwords or setup tokens in 15 minutes | sign-in (`POST /session`, `POST /setup`, `PUT /admin/password`) | | 30 unknown API keys in 15 minutes | key authentication on every route | Password checks have two more limits, so that sign-in cannot be used to wear the server down or to slip extra guesses past the lockout: | Limit | What happens past it | |---|---| | One password check at a time per IP (sign-in and password change) | Another attempt from the same IP while one is being checked answers `429` with `Retry-After: 1`. It is not a guess: nothing is checked or counted. | | Two password checks at a time on the whole server (each takes 19 MiB, by design of the hash) | Further checks wait their turn, up to 10 seconds, then answer `429` with `Retry-After: 5`. At most 64 wait at once; one more is refused at once the same way. | A locked-out request answers `429` with `Retry-After`. The lockout is in memory and clears when the server restarts; the lockout tables remember at most 50,000 addresses, past which everything but live lockouts is forgotten. Each lockout is also a row in the audit trail (`kind: "lockout"`, with the IP). > **Note: Behind a reverse proxy** > > Without `--trust-proxy` (or `TERMLESS_TRUST_PROXY=1`) every request appears to come from the proxy's address, so one person's wrong passwords lock everyone out. With it, the server reads the client address from one header only, `--proxy-header` / `TERMLESS_PROXY_HEADER` (default `X-Forwarded-For`, last hop; `X-Real-IP` is never a fallback), and the scheme from `X-Forwarded-Proto`. The proxy must overwrite that header on every request, and clients must not be able to reach the port directly; otherwise a client chooses its own address. [Authentication](/docs/authentication#behind-a-reverse-proxy) has the details. ## Broker gateways Gateways must be on the public internet. A host that resolves to loopback, link-local (cloud metadata), private (`10/8`, `172.16/12`, `192.168/16`, `fc00::/7`), carrier-grade NAT (`100.64/10`), multicast or documentation space is refused with `400` by `POST /servers/check` and when adding or changing an account, unless termlessd runs with `TERMLESS_ALLOW_PRIVATE_GATEWAYS=1` (implied by `TERMLESS_ALLOW_INSECURE_GATEWAYS=1`, which a plain `ws://` test broker needs). A failed check answers one generic `502` whatever went wrong; the reason is in the server log and the audit trail. ## The broker's limits These are not Termless's and vary per broker and symbol: - `volume_min`, `volume_max`, `volume_step`, `volume_limit` (the largest total open in one direction) in the symbol spec. - `stops_level` and `freeze_level` in points. - Pending order count (`10033`) and position count (`10040`) per account. - `10024 Too frequent requests` when a bot hammers the trade server; back off for a few seconds. - Candle history reaches about 100,000 bars back per timeframe through the web protocol (M1 about three months); older bars are not served. - Brokers serve no tick history through the web protocol. `GET /ticks` has only what Termless kept since subscribing a symbol (above), so record ticks from a stream if you need every one. - Brokers must have web access turned on for their MT5 servers; `POST /api/v1/servers/check` tells you whether a host has it. ## Events on a stream Trade, account and positions events are not coalesced like ticks: a slow client misses none until it falls more than 1,024 events behind, and then it gets a `resync` event. `account` and `positions` are computed every 500 ms at most and sent only when something changed.