TermlessDocs

Reference

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

Symbols the broker offers on this account: the exact name first, then names starting with q, then the rest (names or descriptions containing it).

Scope read

Path parameters

  • id string required

    Account id.

Query parameters

  • q string

    Text to match in the name or description. Empty lists every symbol.

  • limit integer default 50 min 1, max 10000

    Most rows to return, at most 10000.

Headers

  • X-Request-Id string

    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 objects.

  • name string required

    Symbol name, for example XAUUSD.

  • description string required

    Broker's description.

  • path string required

    Folder in the broker's symbol tree.

  • digits integer required

    Price decimals.

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
curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/symbols?q=xau&limit=50" \
  -H "Authorization: Bearer $TERMLESS_KEY"
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())
Python, stdlib
import json
import os
import urllib.error
import urllib.request

base = os.environ["TERMLESS_URL"] + "/api/v1"
headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}

req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/symbols?q=xau&limit=50", data=None, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=35) as r:
    print(json.load(r))
JavaScript
const base = `${process.env.TERMLESS_URL}/api/v1`;

const res = await fetch(`${base}/accounts/pepperstone-12345678/symbols?q=xau&limit=50`, {
  headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
});
if (!res.ok) throw new Error((await res.json()).error.message);
console.log(await res.json());
Response 200
[
  {
    "name": "XAUUSD",
    "description": "Gold vs US Dollar",
    "path": "Metals\\XAUUSD",
    "digits": 2
  }
]

Get a symbol's spec

GET/api/v1/accounts/{id}/symbols/{symbol}

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.

Scope read

Path parameters

  • id string required

    Account id.

  • symbol string required

    Symbol name (exact, else matched case-insensitively).

Headers

  • X-Request-Id string

    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.

  • name string required

    Symbol name.

  • description string required

    Broker's description.

  • path string required

    Folder in the broker's symbol tree.

  • digits integer required

    Price decimals.

  • point number required

    Smallest price step, 10^-digits.

  • contract_size number required

    Units per 1.00 lot.

  • tick_size number required

    Smallest price change. The point when the broker does not send one.

  • tick_value number or null required

    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.

  • currency_base string required

    Base currency.

  • currency_profit string required

    Profit currency.

  • currency_margin string required

    Margin currency.

  • volume_min number required

    Smallest order, in lots.

  • volume_max number required

    Largest order, in lots.

  • volume_step number required

    Lot step.

  • volume_limit number required

    Largest total of open positions and pending orders in one direction, in lots. 0 = no limit.

  • trade_mode string required

    Whether trading is allowed. unknown only for a value MetaTrader does not define.

    fulllong_onlyshort_onlyclose_onlydisabledunknown
  • execution string required

    Execution mode. unknown only for a value MetaTrader does not define.

    marketinstantrequestexchangeunknown
  • filling array of string required

    Filling modes the symbol allows.

    fokiocreturn
  • stops_level integer required

    Minimum distance of SL and TP from the price, in points.

  • freeze_level integer required

    Distance in points inside which orders cannot be changed.

  • swap_long number required

    Swap for long positions, in the unit swap_mode names.

  • swap_short number required

    Swap for short positions, in the unit swap_mode names.

  • swap_mode string required

    The unit of swap_long and swap_short. unknown only for a value MetaTrader does not define.

    disabledpointssymbol_currencymargin_currencydeposit_currencyinterest_currentinterest_openreopen_currentreopen_bidprofit_currencyunknown
  • swap_3day string or null required

    The day the swap is charged three times: sunday, monday, tuesday, wednesday, thursday, friday or saturday. null for none (crypto CFDs send none).

  • margin_initial number required

    Initial margin setting of the symbol, as the broker sends it.

  • margin_maintenance number required

    Maintenance margin setting, as the broker sends it.

  • margin_hedged number required

    Margin for a hedged pair of positions (one lot each way), as the broker sends it.

  • margin_rate_buy number required

    Initial margin rate for a buy (the same as margin_rates.buy).

  • margin_rate_sell number required

    Initial margin rate for a sell (the same as margin_rates.sell).

  • margin_rates object required

    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.

    Fields
    • buy number required

      Initial margin rate for a buy.

    • sell number required

      Initial margin rate for a sell.

    • buy_limit number required

      Initial margin rate for a buy limit.

    • sell_limit number required

      Initial margin rate for a sell limit.

    • buy_stop number required

      Initial margin rate for a buy stop.

    • sell_stop number required

      Initial margin rate for a sell stop.

    • buy_stop_limit number required

      Initial margin rate for a buy stop limit.

    • sell_stop_limit number required

      Initial margin rate for a sell stop limit.

  • expiration array of string required

    The expiry modes a pending order on this symbol may use.

    gtcdayspecifiedspecified_day
  • order_types array of string required

    The order types the symbol takes.

    marketlimitstopstop_limitsltpclose_by
  • sessions object required

    Fields
    • quote array of array of array of integer required

      Quote sessions: 7 lists, one per weekday, Sunday first, each a list of [open_min, close_min] in minutes from midnight, trade server time.

    • trade array of array of array of integer required

      Trade sessions, same shape as quote.

  • tradeable boolean or null required

    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.

  • 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).

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
curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/symbols/XAUUSD" \
  -H "Authorization: Bearer $TERMLESS_KEY"
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())
Python, stdlib
import json
import os
import urllib.error
import urllib.request

base = os.environ["TERMLESS_URL"] + "/api/v1"
headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}

req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/symbols/XAUUSD", data=None, headers=headers, method="GET")
with urllib.request.urlopen(req, timeout=35) as r:
    print(json.load(r))
JavaScript
const base = `${process.env.TERMLESS_URL}/api/v1`;

const res = await fetch(`${base}/accounts/pepperstone-12345678/symbols/XAUUSD`, {
  headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
});
if (!res.ok) throw new Error((await res.json()).error.message);
console.log(await res.json());
Response 200
{
  "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
}

Get many symbol specs

GET/api/v1/accounts/{id}/specs

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).

Scope read

Path parameters

  • id string required

    Account id.

Query parameters

  • names string required

    Comma-separated symbols, at most 200.

Headers

  • X-Request-Id string

    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 objects.

    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
    curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/specs?names=XAUUSD,EURUSD" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/specs?names=XAUUSD,EURUSD", data=None, headers=headers, method="GET")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/specs?names=XAUUSD,EURUSD`, {
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());

    Get quotes

    GET/api/v1/accounts/{id}/quotes

    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.

    Scope read

    Path parameters

    • id string required

      Account id.

    Query parameters

    • symbols string

      Comma-separated symbols, at most 200. Defaults to the account's watchlist (400 when that is empty too).

    • hold integer default 600 min 0, max 3600

      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.

    Headers

    • X-Request-Id string

      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 objects.

    • symbol string required

      Symbol name.

    • bid number or null required

      Bid price. null when the symbol has no price yet.

    • ask number or null required

      Ask price. null when the symbol has no price yet.

    • last number or null required

      Last deal price. 0 for most forex and CFD symbols; null when the symbol has no price yet.

    • time integer or null required

      Unix seconds, trade server clock.

    • time_msc integer or null required

      Unix milliseconds, trade server clock.

    • tradeable boolean or null required

      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.

    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
    curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/quotes?symbols=XAUUSD,EURUSD&hold=600" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/quotes?symbols=XAUUSD,EURUSD&hold=600", data=None, headers=headers, method="GET")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/quotes?symbols=XAUUSD,EURUSD&hold=600`, {
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());
    Response 200
    [
      {
        "symbol": "XAUUSD",
        "bid": 2391.42,
        "ask": 2391.6,
        "last": 0,
        "time": 1790981179,
        "time_msc": 1790981179473,
        "tradeable": true
      }
    ]

    Let quotes go

    DELETE/api/v1/accounts/{id}/quotes

    The caller's leases on these symbols end now (0.7.0).

    Scope read

    Path parameters

    • id string required

      Account id.

    Query parameters

    • symbols string required

      Comma-separated symbols.

    Headers

    • X-Request-Id string

      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.

    • released array of string required

      The symbols.

    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
    curl -s -X DELETE "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/quotes?symbols=EURUSD" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/quotes?symbols=EURUSD", data=None, headers=headers, method="DELETE")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/quotes?symbols=EURUSD`, {
      method: "DELETE",
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());
    Response 200
    {
      "released": [
        "EURUSD"
      ]
    }

    Get candles

    GET/api/v1/accounts/{id}/candles

    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).

    Scope read

    Path parameters

    • id string required

      Account id.

    Query parameters

    • symbol string required

      Symbol name.

    • timeframe string default "M5"

      Bar size. MN works for MN1.

      M1M2M3M4M5M6M10M12M15M20M30H1H2H3H4H6H8H12D1W1MN1
    • count integer default 500 min 1, max 50000

      Latest N bars, 1 to 50000. Ignored when from is given.

    • offset integer default 0 min 0, max 49999

      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.

    • from integer

      Range start, unix seconds, trade server time.

    • to integer

      Range end (or the end of the count), unix seconds, trade server time. Defaults to now.

    Headers

    • X-Request-Id string

      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.

    • symbol string required

      Symbol name, as the broker spells it.

    • timeframe string required

      Timeframe.

      M1M2M3M4M5M6M10M12M15M20M30H1H2H3H4H6H8H12D1W1MN1
    • candles array of Candle required

      Bars, oldest first. Each says whether it is complete.

      Candle fields
      • time integer required

        Bar open time, unix seconds, trade server clock.

      • open number required

        Open.

      • high number required

        High.

      • low number required

        Low.

      • close number required

        Close.

      • tick_volume integer required

        Tick count in the bar.

      • real_volume integer required

        Exchange volume. 0 for most CFD symbols.

      • spread integer required

        Always 0: the web protocol's bars carry no spread (MetaTrader builds bars from the bid).

      • complete boolean required

        The bar has closed, by the server's clock (a month bar closes at the next month's start). The newest bar is usually still forming, but at a weekend or a daily break it may be closed too: read this rather than dropping the last bar.

      • time_utc integer

        Bar open time in UTC, unix seconds; only with the account's clock rule (0.7.0).

      • time_utc_ambiguous boolean

        true when the time falls in New York's repeated autumn hour (0.7.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.
    • 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
    curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/candles?symbol=XAUUSD&timeframe=M5&count=500" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/candles?symbol=XAUUSD&timeframe=M5&count=500", data=None, headers=headers, method="GET")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/candles?symbol=XAUUSD&timeframe=M5&count=500`, {
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());
    Response 200
    {
      "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
        }
      ]
    }

    Get candles for many ranges

    POST/api/v1/accounts/{id}/candles/batch

    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).

    Scope read

    Path parameters

    • id string required

      Account id.

    Headers

    • X-Request-Id string

      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

    • items array of object required

      1 to 20 ranges, at most 200,000 bars in all (each item's whole range counts).

      Fields
      • symbol string required

        Symbol name.

      • timeframe string

        Timeframe (default M5).

        M1M2M3M4M5M6M10M12M15M20M30H1H2H3H4H6H8H12D1W1MN1
      • from integer required

        Range start, unix seconds, server time.

      • to integer required

        Range end.

    Response 200 One result per range.

    A CandleBatch object.

    • items array of CandleBatchItem required

      One per range asked, in order.

      See CandleBatchItem.

    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
    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
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    payload = {
        "items": [
            {
                "symbol": "XAUUSD",
                "timeframe": "M5",
                "from": 1790894400,
                "to": 1790980800
            },
            {
                "symbol": "EURUSD",
                "timeframe": "H1",
                "from": 1790376000,
                "to": 1790980800
            }
        ]
    }
    
    headers["Content-Type"] = "application/json"
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/candles/batch", data=json.dumps(payload).encode(), headers=headers, method="POST")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/candles/batch`, {
      method: "POST",
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}`, "Content-Type": "application/json" },
      body: JSON.stringify({
        "items": [
          {
            "symbol": "XAUUSD",
            "timeframe": "M5",
            "from": 1790894400,
            "to": 1790980800
          },
          {
            "symbol": "EURUSD",
            "timeframe": "H1",
            "from": 1790376000,
            "to": 1790980800
          }
        ]
      })
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());

    Get an order book

    GET/api/v1/accounts/{id}/book

    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.

    Scope read

    Path parameters

    • id string required

      Account id.

    Query parameters

    • symbol string required

      Symbol name.

    • max_age_ms integer default 1000 min 100, max 60000

      The oldest book answered without asking the broker again, in milliseconds, 100 to 60000; outside that is 400.

    Headers

    • X-Request-Id string

      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.

    • symbol string required

      Symbol name, as the broker spells it.

    • time integer required

      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).

    • time_msc integer required

      The same to the millisecond (a change the broker pushed carries its milliseconds; a full snapshot 0 of them). 0 when time is 0.

    • levels array of BookLevel required

      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).

      BookLevel fields
      • type integer required

        MetaTrader's BOOK_TYPE_*: 1 sell, 2 buy, 3 sell market, 4 buy market.

        1234
      • side string required

        sell for types 1 and 3, buy for 2 and 4.

        sellbuy
      • price number required

        The level's price.

      • volume integer required

        Volume at this price in the broker's units (units of the base, as the web terminal shows them; 0.7.0, it was called lots), whole (the official volume).

      • volume_dbl number required

        The same, exactly.

      • lots number required

        The units over the symbol's contract size (0.7.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
    curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/book?symbol=XAUUSD" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/book?symbol=XAUUSD", data=None, headers=headers, method="GET")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/book?symbol=XAUUSD`, {
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());
    Response 200
    {
      "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
        }
      ]
    }

    Release an order book

    DELETE/api/v1/accounts/{id}/book

    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).

    Scope read

    Path parameters

    • id string required

      Account id.

    Query parameters

    • symbol string required

      Symbol name.

    Headers

    • X-Request-Id string

      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.

    • symbol string required

      Symbol name, as the broker spells it.

    • released boolean required

      True when the book was added and is now released.

    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
    curl -s -X DELETE "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/book?symbol=XAUUSD" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/book?symbol=XAUUSD", data=None, headers=headers, method="DELETE")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/book?symbol=XAUUSD`, {
      method: "DELETE",
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());
    Response 200
    {
      "symbol": "XAUUSD",
      "released": true
    }

    Get recent ticks

    GET/api/v1/accounts/{id}/ticks

    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.

    Scope read

    Path parameters

    • id string required

      Account id.

    Query parameters

    • symbol string required

      Symbol name.

    • count integer default 1000 min 1, max 20000

      Most ticks to return: the newest when from is not given, else the first ones from from on.

    • from integer

      Start, unix seconds, trade server time (copy_ticks_from's date_from).

    • to integer

      End, unix seconds, trade server time; ticks within that second are included.

    Headers

    • X-Request-Id string

      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.

    • symbol string required

      Symbol name, as the broker spells it.

    • kept_from_msc integer or null required

      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).

    • ticks array of HistoryTick required

      Ticks, oldest first.

      HistoryTick fields
      • time integer required

        Unix seconds, trade server clock.

      • time_msc integer required

        Unix milliseconds, trade server clock.

      • bid number required

        Bid after the tick (the previous one when the tick did not change it).

      • ask number required

        Ask after the tick (the previous one when the tick did not change it).

      • last number required

        Last deal price after the tick. 0 for most forex and CFD symbols.

      • volume integer required

        The tick's volume; 0 unless the tick changed it (flag 16).

      • flags integer required

        MetaTrader's TICK_FLAG_* for what the tick changed, added together: 2 bid, 4 ask, 8 last, 16 volume.

      • volume_raw integer required

        The broker's volume number (lots times 10^8), as volume (0.7.0).

      • volume_real number required

        The volume in lots (0.7.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.
    • 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
    curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/ticks?symbol=XAUUSD&count=100" \
      -H "Authorization: Bearer $TERMLESS_KEY"
    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())
    Python, stdlib
    import json
    import os
    import urllib.error
    import urllib.request
    
    base = os.environ["TERMLESS_URL"] + "/api/v1"
    headers = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]}
    
    req = urllib.request.Request(f"{base}/accounts/pepperstone-12345678/ticks?symbol=XAUUSD&count=100", data=None, headers=headers, method="GET")
    with urllib.request.urlopen(req, timeout=35) as r:
        print(json.load(r))
    JavaScript
    const base = `${process.env.TERMLESS_URL}/api/v1`;
    
    const res = await fetch(`${base}/accounts/pepperstone-12345678/ticks?symbol=XAUUSD&count=100`, {
      headers: { Authorization: `Bearer ${process.env.TERMLESS_KEY}` }
    });
    if (!res.ok) throw new Error((await res.json()).error.message);
    console.log(await res.json());
    Response 200
    {
      "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
        }
      ]
    }