# Market data Symbols, their full specs, quotes, candles, the recent ticks the server kept and order books. Times are in the trade server's clock; subtract the account's server_offset for UTC. ### Search symbols `GET /api/v1/accounts/{id}/symbols` Scope: read. Symbols the broker offers on this account: the exact name first, then names starting with `q`, then the rest (names or descriptions containing it). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `q` | string | no | Text to match in the name or description. Empty lists every symbol. | | `limit` | integer | no | Most rows to return, at most 10000. (default 50; 1 to 10000) | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Symbols. A JSON array of SymbolBrief. | Field | Type | Description | |---|---|---| | `name` | string | Symbol name, for example XAUUSD. (required) | | `description` | string | Broker's description. (required) | | `path` | string | Folder in the broker's symbol tree. (required) | | `digits` | integer | Price decimals. (required) | Example: ```json [ { "name": "XAUUSD", "description": "Gold vs US Dollar", "path": "Metals\\XAUUSD", "digits": 2 } ] ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/symbols?q=xau&limit=50" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/symbols", headers=auth, params={"q": "xau", "limit": 50}) r.raise_for_status() print(r.json()) ``` ### Get a symbol's spec `GET /api/v1/accounts/{id}/symbols/{symbol}` Scope: read. Everything needed to size and place an order: digits, contract size, tick size and value, lot limits, stop levels, swaps and their unit and triple day, margin settings with every order type's rate (`margin_rates`), the expiry modes and order types the symbol takes, and sessions, with the broker's group overrides applied, plus `tradeable`: whether a trade can be opened now, as on /quotes. `tick_value` is the broker's, else worked out as the terminal does (null when it cannot be). `sessions.quote` and `sessions.trade` are 7 lists (Sunday first) of `[open_min, close_min]` minutes from midnight, server time. The specs of the watchlist, order books, positions and pending orders are read in one request after each connect, so the first read of one does not wait a broker round trip for its spec. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | | `symbol` | string | yes | Symbol name (exact, else matched case-insensitively). | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Symbol spec. A SymbolSpec object. | Field | Type | Description | |---|---|---| | `name` | string | Symbol name. (required) | | `description` | string | Broker's description. (required) | | `path` | string | Folder in the broker's symbol tree. (required) | | `digits` | integer | Price decimals. (required) | | `point` | number | Smallest price step, 10^-digits. (required) | | `contract_size` | number | Units per 1.00 lot. (required) | | `tick_size` | number | Smallest price change. The point when the broker does not send one. (required) | | `tick_value` | number or null | Value of one tick_size move for 1.00 lot, in the account currency. The broker's own figure, else worked out as the terminal does: tick_size x contract_size, converted from currency_profit to the account currency, for forex, CFD, leveraged CFD and exchange stock symbols. null when the broker sends none and it cannot be worked out (futures and index CFDs, or no conversion symbol). Pepperstone sends neither tick value nor tick size. (required) | | `currency_base` | string | Base currency. (required) | | `currency_profit` | string | Profit currency. (required) | | `currency_margin` | string | Margin currency. (required) | | `volume_min` | number | Smallest order, in lots. (required) | | `volume_max` | number | Largest order, in lots. (required) | | `volume_step` | number | Lot step. (required) | | `volume_limit` | number | Largest total of open positions and pending orders in one direction, in lots. 0 = no limit. (required) | | `trade_mode` | string | Whether trading is allowed. unknown only for a value MetaTrader does not define. (required; one of full, long_only, short_only, close_only, disabled, unknown) | | `execution` | string | Execution mode. unknown only for a value MetaTrader does not define. (required; one of market, instant, request, exchange, unknown) | | `filling` | array of string | Filling modes the symbol allows. (required; one of fok, ioc, return) | | `stops_level` | integer | Minimum distance of SL and TP from the price, in points. (required) | | `freeze_level` | integer | Distance in points inside which orders cannot be changed. (required) | | `swap_long` | number | Swap for long positions, in the unit swap_mode names. (required) | | `swap_short` | number | Swap for short positions, in the unit swap_mode names. (required) | | `swap_mode` | string | The unit of swap_long and swap_short. unknown only for a value MetaTrader does not define. (required; one of disabled, points, symbol_currency, margin_currency, deposit_currency, interest_current, interest_open, reopen_current, reopen_bid, profit_currency, unknown) | | `swap_3day` | string or null | The day the swap is charged three times: sunday, monday, tuesday, wednesday, thursday, friday or saturday. null for none (crypto CFDs send none). (required) | | `margin_initial` | number | Initial margin setting of the symbol, as the broker sends it. (required) | | `margin_maintenance` | number | Maintenance margin setting, as the broker sends it. (required) | | `margin_hedged` | number | Margin for a hedged pair of positions (one lot each way), as the broker sends it. (required) | | `margin_rate_buy` | number | Initial margin rate for a buy (the same as margin_rates.buy). (required) | | `margin_rate_sell` | number | Initial margin rate for a sell (the same as margin_rates.sell). (required) | | `margin_rates` | object | Every order type's initial margin rate, as the broker sends it. A pending type's rate is what the broker holds while such an order waits: the brokers seen send 0 there (nothing is held), and once the order fills the position needs its side's market rate. A market rate of 0 counts as 1. (required; object: buy, sell, buy_limit, sell_limit, buy_stop, sell_stop, buy_stop_limit, sell_stop_limit) | | `expiration` | array of string | The expiry modes a pending order on this symbol may use. (required; one of gtc, day, specified, specified_day) | | `order_types` | array of string | The order types the symbol takes. (required; one of market, limit, stop, stop_limit, sl, tp, close_by) | | `sessions` | object | (required; object: quote, trade) | | `tradeable` | boolean or null | Whether a trade can be opened now, as on /quotes: the trade_mode is full, long_only or short_only, and one of today's trade sessions is open by the server's clock. null when the broker sent no trade sessions. (required) | | `book_depth` | integer | The levels a side of the symbol's order book may hold (0 when the broker sends none); a book past it is renewed (0.7.0). | Example: ```json { "name": "XAUUSD", "description": "Gold vs US Dollar", "path": "Metals\\XAUUSD", "digits": 2, "point": 0.01, "contract_size": 100, "tick_size": 0.01, "tick_value": 1.0, "currency_base": "XAU", "currency_profit": "USD", "currency_margin": "XAU", "volume_min": 0.01, "volume_max": 100, "volume_step": 0.01, "volume_limit": 0, "trade_mode": "full", "execution": "market", "filling": [ "fok", "ioc" ], "stops_level": 0, "freeze_level": 0, "swap_long": -6.2, "swap_short": 1.4, "swap_mode": "points", "swap_3day": "wednesday", "margin_initial": 0.0, "margin_maintenance": 0.0, "margin_hedged": 50.0, "margin_rate_buy": 1.0, "margin_rate_sell": 1.0, "margin_rates": { "buy": 1.0, "sell": 1.0, "buy_limit": 0.0, "sell_limit": 0.0, "buy_stop": 0.0, "sell_stop": 0.0, "buy_stop_limit": 0.0, "sell_stop_limit": 0.0 }, "expiration": [ "gtc", "day", "specified", "specified_day" ], "order_types": [ "market", "limit", "stop", "stop_limit", "sl", "tp", "close_by" ], "sessions": { "quote": [ [], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [] ], "trade": [ [], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [ [ 0, 1440 ] ], [] ] }, "tradeable": true } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/symbols/XAUUSD" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/symbols/XAUUSD", headers=auth) r.raise_for_status() print(r.json()) ``` ### Get many symbol specs `GET /api/v1/accounts/{id}/specs` Scope: read. Many specs in one broker request (0.7.0), each with when it was read; a cached spec is read again once it is a day old (TERMLESS_SPEC_MAX_AGE_S). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `names` | string | yes | Comma-separated symbols, at most 200. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Specs, in the order asked. A JSON array of SpecItem. **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/specs?names=XAUUSD,EURUSD" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/specs", headers=auth, params={"names": "XAUUSD,EURUSD"}) r.raise_for_status() print(r.json()) ``` ### Get quotes `GET /api/v1/accounts/{id}/quotes` Scope: read. The latest bid and ask, and `tradeable`: whether a trade can be opened now (trade mode and today's trade sessions, by the server's clock; null when the broker sent no sessions). The first request for a symbol subscribes it and waits up to 3 s for a first price; later ones answer at once. A symbol with no price yet (a closed market) has null prices. For a steady feed use the stream instead of polling. Since 0.7.0 a read leases its symbols for `hold` seconds after the caller's last read, then lets them go (0.6.3 kept them until a restart); a lease is the caller's own and never stops a symbol a stream holds or the watchlist pins. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `symbols` | string | no | Comma-separated symbols, at most 200. Defaults to the account's watchlist (400 when that is empty too). | | `hold` | integer | no | Seconds the symbols stay subscribed after this read (0.7.0; 0 to 3600, default 600). 0 answers from prices already streaming and subscribes nothing. (default 600; 0 to 3600) | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Quotes, in the order asked. A JSON array of Quote. | Field | Type | Description | |---|---|---| | `symbol` | string | Symbol name. (required) | | `bid` | number or null | Bid price. null when the symbol has no price yet. (required) | | `ask` | number or null | Ask price. null when the symbol has no price yet. (required) | | `last` | number or null | Last deal price. 0 for most forex and CFD symbols; null when the symbol has no price yet. (required) | | `time` | integer or null | Unix seconds, trade server clock. (required) | | `time_msc` | integer or null | Unix milliseconds, trade server clock. (required) | | `tradeable` | boolean or null | Whether a trade can be opened now: the symbol's trade_mode is full, long_only or short_only, and one of today's trade sessions is open by the server's clock. null when the broker sent no trade sessions. (required) | Example: ```json [ { "symbol": "XAUUSD", "bid": 2391.42, "ask": 2391.6, "last": 0, "time": 1790981179, "time_msc": 1790981179473, "tradeable": true } ] ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/quotes?symbols=XAUUSD,EURUSD&hold=600" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/quotes", headers=auth, params={"symbols": "XAUUSD,EURUSD", "hold": 600}) r.raise_for_status() print(r.json()) ``` ### Let quotes go `DELETE /api/v1/accounts/{id}/quotes` Scope: read. The caller's leases on these symbols end now (0.7.0). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `symbols` | string | yes | Comma-separated symbols. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: What was let go. | Field | Type | Description | |---|---|---| | `released` | array of string | The symbols. (required) | Example: ```json { "released": [ "EURUSD" ] } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s -X DELETE "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/quotes?symbols=EURUSD" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.delete(f"{base}/accounts/pepperstone-12345678/quotes", headers=auth, params={"symbols": "EURUSD"}) r.raise_for_status() print(r.json()) ``` ### Get candles `GET /api/v1/accounts/{id}/candles` Scope: read. Bars for one symbol and timeframe, oldest first, at most 50000. Ask by `count` (the latest N bars, or the N ending at `to`; with `offset`, the N ending that many bars before the newest, as copy_rates_from_pos's `start_pos`) or by range (`from` and `to`, unix seconds in trade server time; `to` defaults to now). A range over 100,000 bars is 400 ("that range holds more than 100000 bars; narrow it (a range over 50000 bars keeps the newest 50000) or use count"); one over 50,000 keeps the newest 50,000. Each bar says whether it is `complete` (closed by the server's clock): read that rather than dropping the last bar, which at a weekend or a daily break is closed too. `spread` is always 0 (the web protocol's bars carry none). The broker serves candle requests one at a time, so requests from many callers on one account queue rather than fail. Requests of more than 10,000 bars take turns per account, one at a time; the account's others wait their turn. History reaches about 100,000 bars back per timeframe through the web protocol (M1 about three months); older bars are not served. A range read's settled bars (closed at least 15 minutes ago) come from a cache shared by every account (0.7.0, TERMLESS_CANDLE_CACHE_MB, default 32); younger bars always from the broker. With the account's clock rule (0.7.0), UTC fields come beside it (see the account's clock). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `symbol` | string | yes | Symbol name. | | `timeframe` | string | no | Bar size. MN works for MN1. (default "M5"; one of M1, M2, M3, M4, M5, M6, M10, M12, M15, M20, M30, H1, H2, H3, H4, H6, H8, H12, D1, W1, MN1) | | `count` | integer | no | Latest N bars, 1 to 50000. Ignored when from is given. (default 500; 1 to 50000) | | `offset` | integer | no | With count: end the bars this many bars before the newest (or before to), like copy_rates_from_pos's start_pos. count plus offset at most 50000. Ignored when from is given. (default 0; 0 to 49999) | | `from` | integer | no | Range start, unix seconds, trade server time. | | `to` | integer | no | Range end (or the end of the count), unix seconds, trade server time. Defaults to now. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Candles. A Candles object. | Field | Type | Description | |---|---|---| | `symbol` | string | Symbol name, as the broker spells it. (required) | | `timeframe` | string | Timeframe. (required; one of M1, M2, M3, M4, M5, M6, M10, M12, M15, M20, M30, H1, H2, H3, H4, H6, H8, H12, D1, W1, MN1) | | `candles` | array of Candle | Bars, oldest first. Each says whether it is complete. (required; see Candle) | Example: ```json { "symbol": "XAUUSD", "timeframe": "M5", "candles": [ { "time": 1790980500, "open": 2394.31, "high": 2395.1, "low": 2390.58, "close": 2392.41, "tick_volume": 2330, "real_volume": 0, "spread": 0, "complete": true }, { "time": 1790980800, "open": 2392.41, "high": 2394.19, "low": 2392.29, "close": 2393.97, "tick_volume": 834, "real_volume": 0, "spread": 0, "complete": false } ] } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/candles?symbol=XAUUSD&timeframe=M5&count=500" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/candles", headers=auth, params={"symbol": "XAUUSD", "timeframe": "M5", "count": 500}) r.raise_for_status() print(r.json()) ``` ### Get candles for many ranges `POST /api/v1/accounts/{id}/candles/batch` Scope: read. Up to 20 ranges read one after another through the candle cache (0.7.0), each answered with its candles or its own error. A bad timeframe or range in any item, or more than 200,000 bars in all, refuses the whole batch (400). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Request body** (CandleBatchRequest) | Field | Type | Description | |---|---|---| | `items` | array of object | 1 to 20 ranges, at most 200,000 bars in all (each item's whole range counts). (required; object: symbol, timeframe, from, to) | Example: ```json { "items": [ { "symbol": "XAUUSD", "timeframe": "M5", "from": 1790894400, "to": 1790980800 }, { "symbol": "EURUSD", "timeframe": "H1", "from": 1790376000, "to": 1790980800 } ] } ``` **Response 200**: One result per range. A CandleBatch object. | Field | Type | Description | |---|---|---| | `items` | array of CandleBatchItem | One per range asked, in order. (required) | **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s -X POST "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/candles/batch" \ -H "Authorization: Bearer $TERMLESS_KEY" \ -H "Content-Type: application/json" \ -d '{"items": [{"symbol": "XAUUSD", "timeframe": "M5", "from": 1790894400, "to": 1790980800}, {"symbol": "EURUSD", "timeframe": "H1", "from": 1790376000, "to": 1790980800}]}' ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.post(f"{base}/accounts/pepperstone-12345678/candles/batch", headers=auth, json={ "items": [ { "symbol": "XAUUSD", "timeframe": "M5", "from": 1790894400, "to": 1790980800 }, { "symbol": "EURUSD", "timeframe": "H1", "from": 1790376000, "to": 1790980800 } ] }) r.raise_for_status() print(r.json()) ``` ### Get an order book `GET /api/v1/accounts/{id}/book` Scope: read. market_book_add and market_book_get in one call: the symbol's order book (depth of market), sells from the highest price down, then buys. The first request for a symbol asks the broker for its book and waits up to 3 s for the snapshot that brings; termlessd keeps the book for every caller until DELETE /book releases it, and asks again by itself after a reconnect. At most 32 books per account (400 past that). Brokers may send changes rarely or never (Pepperstone sent none for BTCUSD in 90 s while its price ticked), so a book older than `max_age_ms` is renewed first: that symbol alone is taken out of the subscribed set and put back, which brings a fresh snapshot, waited for up to 3 s (the other books stay). When none comes, the kept book is answered and its `time` says how old it is, and the symbol is not asked again for 30 s; one the broker never sent a book for is answered with `time: 0` and no levels, and asked again only after 5 minutes. A broker that refuses a change of the set gets the kept book answered, not an error. A symbol whose market is closed has an empty book. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `symbol` | string | yes | Symbol name. | | `max_age_ms` | integer | no | The oldest book answered without asking the broker again, in milliseconds, 100 to 60000; outside that is 400. (default 1000; 100 to 60000) | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: The book. A Book object. | Field | Type | Description | |---|---|---| | `symbol` | string | Symbol name, as the broker spells it. (required) | | `time` | integer | The trade server's time of this book, unix seconds, server time. 0 when the broker has sent no book for the symbol (it likely has no depth there; it is asked again after 5 minutes); an old time means the broker sent no fresh book within 3 s when asked again (asked again after 30 s). (required) | | `time_msc` | integer | The same to the millisecond (a change the broker pushed carries its milliseconds; a full snapshot 0 of them). 0 when time is 0. (required) | | `levels` | array of BookLevel | Sells from the highest price down, then buys from the highest price down. Empty when the market is closed, or when the broker sent no book (time 0). (required; see BookLevel) | Example: ```json { "symbol": "XAUUSD", "time": 1790981179, "time_msc": 1790981179629, "levels": [ { "type": 1, "side": "sell", "price": 2391.8, "volume": 250, "volume_dbl": 250.0, "lots": 2.5 }, { "type": 1, "side": "sell", "price": 2391.6, "volume": 100, "volume_dbl": 100.0, "lots": 1.0 }, { "type": 2, "side": "buy", "price": 2391.42, "volume": 120, "volume_dbl": 120.0, "lots": 1.2 }, { "type": 2, "side": "buy", "price": 2391.2, "volume": 300, "volume_dbl": 300.0, "lots": 3.0 } ] } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `409 conflict`: The thing already exists or the state does not allow it. On a trade route with an Idempotency-Key: the key was already used with a different body or query string, or the first request with it did not finish (cut off, or the server restarted; check positions and orders, then use a new key), or it is still running after 30 s. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/book?symbol=XAUUSD" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/book", headers=auth, params={"symbol": "XAUUSD"}) r.raise_for_status() print(r.json()) ``` ### Release an order book `DELETE /api/v1/accounts/{id}/book` Scope: read. market_book_release: the broker stops sending the symbol's book and it no longer counts toward the 32. `released` is false when the book was not added. Releasing the last book succeeds even on a broker that refuses an empty set (its pushes for that symbol are then dropped here). **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `symbol` | string | yes | Symbol name. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Released. | Field | Type | Description | |---|---|---| | `symbol` | string | Symbol name, as the broker spells it. (required) | | `released` | boolean | True when the book was added and is now released. (required) | Example: ```json { "symbol": "XAUUSD", "released": true } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s -X DELETE "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/book?symbol=XAUUSD" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.delete(f"{base}/accounts/pepperstone-12345678/book", headers=auth, params={"symbol": "XAUUSD"}) r.raise_for_status() print(r.json()) ``` ### Get recent ticks `GET /api/v1/accounts/{id}/ticks` Scope: read. copy_ticks_from and copy_ticks_range over the ticks this server kept for the symbol, oldest first. The web protocol has no tick-history request, so these are the ticks the broker pushed since the account's current broker connection subscribed the symbol: the newest 1,000 per streaming symbol (`TERMLESS_TICK_HISTORY`, at most 100,000; 0 keeps none), and at most 100,000 over all of the account's streaming symbols, shared evenly (500 symbols keep 200 each). A reconnect starts the history again; `kept_from_msc` says how far back it reaches. Without `from`, the newest `count` (up to `to` when given); with `from`, the first `count` from there on (up to `to` when given). The first request for a symbol not streaming yet subscribes it, like /quotes, but does not wait for a price, so it may answer no ticks. To keep every tick, record them from a stream. Since 0.7.0 a symbol's ticks are kept from its first read on, so the first answer is often empty; the read leases the symbol like /quotes. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `symbol` | string | yes | Symbol name. | | `count` | integer | no | Most ticks to return: the newest when from is not given, else the first ones from from on. (default 1000; 1 to 20000) | | `from` | integer | no | Start, unix seconds, trade server time (copy_ticks_from's date_from). | | `to` | integer | no | End, unix seconds, trade server time; ticks within that second are included. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Ticks. A TickHistory object. | Field | Type | Description | |---|---|---| | `symbol` | string | Symbol name, as the broker spells it. (required) | | `kept_from_msc` | integer or null | time_msc of the oldest tick kept for the symbol, whatever the request asked: how far back GET /ticks can reach right now. null while none is kept (a symbol subscribed just now, or TERMLESS_TICK_HISTORY=0). (required) | | `ticks` | array of HistoryTick | Ticks, oldest first. (required; see HistoryTick) | Example: ```json { "symbol": "XAUUSD", "kept_from_msc": 1790980874102, "ticks": [ { "time": 1790981179, "time_msc": 1790981179473, "bid": 2391.42, "ask": 2391.6, "last": 0, "volume": 0, "volume_raw": 0, "volume_real": 0.0, "flags": 6 }, { "time": 1790981179, "time_msc": 1790981179688, "bid": 2391.45, "ask": 2391.6, "last": 0, "volume": 0, "volume_raw": 0, "volume_real": 0.0, "flags": 2 } ] } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `502 broker_error`: The broker's server failed or answered with something unexpected. - `503 disconnected, busy, stopping`: disconnected: the account is not connected (it reconnects on its own; the route waits up to 2 s first) or is turned off; retry with backoff (on a trade route it was never sent: a trade's Idempotency-Key is let go). busy: requests of one command go to the broker one at a time per account, and this one waited its whole turn (20 s) behind earlier ones and was never sent, so sending it again is safe (a trade's Idempotency-Key is let go, so the retry with the same key is sent). - `504 timeout, unconfirmed`: timeout: the broker did not answer a request that was sent (one broker call is given 20 s), or the whole request ran past 30 s (TERMLESS_REQUEST_TIMEOUT). unconfirmed (trades, since 0.6.0): the broker took the trade but its final result did not come, so it may have been carried out; the body adds request_id, retcode (null or the last in-between state, 10001 to 10003) and retcode_text. Retry with the same Idempotency-Key: the stored answer is replayed (the real result once it came late), so the broker never sees it twice; then check positions and orders. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/ticks?symbol=XAUUSD&count=100" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/accounts/pepperstone-12345678/ticks", headers=auth, params={"symbol": "XAUUSD", "count": 100}) r.raise_for_status() print(r.json()) ```