# Conventions The rules every route follows: two clocks, lots, prices, symbols, timeframes, ids, request ids, cursors, why a trade happened and the one error shape. ## Base URL and format Every route lives under `/api/v1` on your server. Requests and responses are JSON (`Content-Type: application/json`); a successful delete answers `204` with no body; the log and crash reports are `text/plain`; the SSE stream is `text/event-stream`. Lists are plain JSON arrays, not wrapped in an object. ## Two clocks MetaTrader reports every market time in the **trade server's clock**, not UTC, and Termless passes them through unchanged so your numbers match the terminal and the broker's statements. That covers `time` and `time_msc` on ticks, candles, positions, orders and deals, `expiration` on pending orders, and the `from` and `to` you send to the candles and deals routes. Each account's summary carries `server_offset`, the trade server's clock in seconds east of UTC. Most brokers run UTC+2 in winter and UTC+3 in summer, so the value changes twice a year; read it, do not hard-code it. Termless reads it from the account record at least once an hour, so a switch shows up without a reconnect, and checks it against live ticks (a tick's server time minus the moment it arrived, to the nearest quarter hour). If the two disagree, the ticks win and the server log says so once. `server_offset` is the offset **now**. A bar, deal or order from before the broker's last clock change carries the offset of its own time: a summer bar on a UTC+3 broker is UTC+3 even when you read it in winter, at UTC+2. To turn old times into UTC, use the broker's summer-time dates. Most UTC+2/UTC+3 brokers switch on the US dates (the second Sunday of March and the first Sunday of November), so their clock is New York time plus seven hours. ```python from datetime import datetime, timezone summary = requests.get(f"{base}/accounts/{acc}/summary", headers=auth).json() offset = summary["server_offset"] # for example 10800 = UTC+3 utc = datetime.fromtimestamp(candle["time"] - offset, timezone.utc) # right since the broker's last clock change server_from = int(datetime(2026, 10, 1, tzinfo=timezone.utc).timestamp()) + offset # a UTC date as a query time ``` Times about Termless itself are plain UTC unix seconds: `status.since`, `status.retry_at`, `created_at`, `last_used_at`, `verified_at`, `started_at`, and `time` on diagnostics entries. | Field | Clock | Unit | |---|---|---| | `time` on a tick, candle, position, order, deal; `time_setup`, `time_done` on orders | trade server | unix seconds | | `time_msc`, `time_setup_msc`, `time_done_msc` | trade server | unix milliseconds | | `expiration` on a pending order | trade server | unix seconds, `0` = good till cancelled | | `from`, `to` query parameters | trade server | unix seconds | | `created_at`, `since`, `retry_at`, `last_used_at`, `verified_at`, `started_at` | UTC | unix seconds | | `last_tick_at_ms`, `last_frame_at_ms` in diagnostics | UTC | unix milliseconds | | `at` on audit rows, connection events and equity samples; `time_ms` on `account`, `positions` and `orders` events | UTC | unix milliseconds | ## Volumes are lots `volume` is always lots, as in MT5: `0.01` is a micro lot, `1.0` a standard lot. The symbol's spec gives `volume_min`, `volume_max` and `volume_step`, and `contract_size` says how many units one lot is (100,000 for most forex pairs, 100 for gold). A volume off the step is refused by the broker with `10014 Invalid volume`. ## Prices Prices are plain JSON numbers with the symbol's `digits` decimals (`2` for gold, `5` for EURUSD, `3` for yen pairs). `0` means none: a stop loss or take profit of `0` is no stop, and in a request `0` removes one. `last` is `0` for most forex and CFD symbols, which have no last-deal price. A quote whose symbol has not ticked yet (a closed market) has `null` prices. ## Sides and types `side` is `"buy"` or `"sell"` everywhere. Pending order `type` is `limit`, `stop` or `stop_limit` when you place one, and the full MetaTrader name (`buy_limit`, `sell_stop`, ...) when you read one back. Deal `type` and `entry` use MetaTrader's names in lowercase (`buy`, `sell`, `balance`; `in`, `out`, `inout`, `out_by`). Any enum value the server does not know comes back as `"unknown"` rather than failing the whole response. ## Symbols Symbol names are matched exactly first, then case-insensitively: `xauusd` finds `XAUUSD`. Responses always spell the name the broker's way. Brokers add suffixes (`EURUSD.a`, `XAUUSD.r`); search with `GET /api/v1/accounts/{id}/symbols?q=xau` when you are not sure. ## Timeframes `M1 M2 M3 M4 M5 M6 M10 M12 M15 M20 M30 H1 H2 H3 H4 H6 H8 H12 D1 W1 MN1`. The ones MetaTrader does not store natively (`M2`, `H3` and so on) are built from finer bars, the way the terminal does it. A candle's `time` is the bar's open time. ## Account ids An account id is yours: `a-z`, `0-9` and `-`, up to 48 characters, chosen when you add the account (default: the server's first word and the login, `pepperstone-12345678`). Tickets (`ticket`, `order`, `deal`, `position_id`, `identifier`) are MetaTrader's integers. ## Errors Every error has the same shape and an HTTP status that matches the code: ```json {"error": {"code": "not_found", "message": "no account with id pepperstone-live"}} ``` The one exception that adds to the shape rather than replacing it: a trade the broker refused answers `422` with the full trade result plus `error`. [Errors and retries](/docs/errors) lists every code. ## Query parameters Lists of symbols and event types are comma-separated (`?symbols=XAUUSD,EURUSD`, at most 200; `?events=ticks,trades`). Numbers are plain (`?count=100`, `?volume=0.1`). The one boolean, `bodies=1` on `/diagnostics/undecoded`, takes `1` or `true`. A query parameter the route does not take is `400`, never silently ignored, so a typo cannot turn a filtered request into an unfiltered one. The message names the parameter and the ones the route takes: ```json {"error": {"code": "bad_request", "message": "tickt: unknown query parameter `tickt`, expected one of `from`, `to`, `limit`, `before`, `position`, `ticket`, `symbol`"}} ``` A route that takes none says `this route takes no query parameters (got ...)`. `key=` is accepted on any route (only the two stream routes read it as a key). Routes that take a JSON body read nothing from the query string. ## Request ids Every response carries an `X-Request-Id` header. Send your own (1 to 64 characters of `A-Z a-z 0-9 - _ . :`) and it is kept; otherwise the server makes one of 16 hex characters. The same id is on every log line the request wrote and on every audit row it caused. It is the one thing to quote when you report a problem. ## Idempotency The trade routes that change something take an `Idempotency-Key` header (1 to 200 printable ASCII characters). The same key with the same body replays the first answer, with `Idempotent-Replayed: true`, instead of asking the broker again; the same key with a different body or query string is `409`. [Trading safely](/docs/trading#after-a-timeout-the-one-rule) has the rules; the short version is: always send one, retry with the same one. ## Lists and cursors Most lists come back whole: positions, orders, accounts, keys and symbols (bounded by `limit`, at most 10,000) are small. Candles are bounded by `count` (at most 50,000) or a `from`/`to` range. Four lists page with a cursor, newest first except deals and history orders: | Route | Page size | Cursor | Next page | |---|---|---|---| | `GET /accounts/{id}/deals` | `limit` (default and max 5,000), inside the `from`/`to` window (at most 10 years) | `before` = a `time_msc` | `before` = the first (oldest) deal's `time_msc` of the page you have; the page is oldest first | | `GET /accounts/{id}/orders/history` | `limit` (default and max 5,000), inside the `from`/`to` window on when each order was placed | `before` = a `time_setup_msc` | `before` = the first (oldest) order's `time_setup_msc` of the page you have; the page is oldest first | | `GET /audit` | `limit` (default 100, max 1,000) | `before` = an `id` | `before` = the `id` of the last row you have | | `GET /accounts/{id}/events` | `limit` (default 100, max 1,000) | `before` = an `id` | `before` = the `id` of the last row you have | `GET /accounts/{id}/equity` is bounded by `hours` (1 to 168) instead and comes back whole, oldest first. Trade events have a cursor of their own: an event id, `":"`. `GET /accounts/{id}/trades?after=` returns what came after it (oldest first) and the newest id to ask with next time; a stream takes the same id as `?after=` or `Last-Event-ID`. [Streaming](/docs/streaming#picking-up-where-you-left-off) has the details. ## Why a trade happened Positions, orders and deals carry `reason`, a word for what made them: `web` for anything sent through Termless, `client` for a desktop terminal, `mobile`, `expert` (an EA), `sl` and `tp` for a close at the stop loss or take profit, `stop_out`, and a few rarer ones (`rollover`, `vmargin`, `split`, `corporate_action`, `dealer`, `gateway`, `signal`, `settlement`, `transfer`, `sync`, `external_client`, `external_service`, `migration`, `unknown`). A closing deal with `reason: "sl"` is a stop hit, whatever its comment says.