# Trails What happened, with the request id that caused it: the audit trail (every write and every security event), each account's connection history, and an equity curve sampled once a minute. Rows are written off the request path and pruned hourly: audit 90 days or 200,000 rows, connection events 90 days or 50,000 rows, equity 7 days. Also who is connected right now and what they receive (in memory, since the server started). ### Read the audit trail `GET /api/v1/audit` Scope: admin. Every write and every security event, newest first: trades (one row per broker call with the request in short JSON, the retcode, the result and the broker latency; none for an idempotent replay), account and key changes, sign-ins, wrong passwords, lockouts, password changes, setup, server checks and server starts. Each row carries the `X-Request-Id` of the request that caused it, so a bot's log, the server log and the trail line up. Every filter given must match; an empty one is ignored. `request_id` finds the rows of one request (exact, indexed). `q` finds a piece of text, case-insensitive, in the request id, actor, account, route, summary or result; it reads from the newest row down and stops at `limit` matches (a search that matches little reads the whole trail, 40 to 60 ms at the 200,000-row cap). Page with `before` = the `id` of the last row seen, with or without a search. **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `account` | string | no | Only rows about this account. | | `kind` | string | no | Only rows of this kind. (one of trade, account, key, signin, auth_failed, lockout, password, setup, server_check, server_trust, start) | | `actor` | string | no | Only rows by this actor (a key id, admin, an IP, termlessd). | | `request_id` | string | no | Only rows caused by the request with this X-Request-Id (exact match). | | `q` | string | no | Only rows whose request_id, actor, account, route, summary or result contains this text, ignoring case (`%` and `_` are plain characters). More than 200 characters is 400. | | `before` | integer | no | Only rows with an id below this: the id of the last row of the previous page. | | `limit` | integer | no | Most rows to return, at most 1000. (default 100; 1 to 1000) | **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**: Rows, newest first. A JSON array of AuditRow. | Field | Type | Description | |---|---|---| | `id` | integer | Row id, increasing. Page with `before`. (required) | | `at` | integer | When it happened, unix milliseconds (UTC). (required) | | `kind` | string | What kind of thing happened. (required; one of trade, account, key, signin, auth_failed, lockout, password, setup, server_check, server_trust, start) | | `actor` | string | Who did it: the key id for a key, admin for the dashboard, the client IP before sign-in, termlessd for the server itself. (required) | | `actor_kind` | string | admin for the dashboard session, key for an API key, anonymous before sign-in, system for the server. (required; one of admin, key, anonymous, system) | | `account` | string or null | The account it concerned, when one did. (required) | | `route` | string | What was done. For a trade: market order, pending order, order change, order cancel, SL/TP change, close, partial close or order_send. For an account: add, update or delete. For a key: create or delete. (required) | | `summary` | string | One line a person can read. (required) | | `request` | string or null | For a trade: the request sent to the broker, in short JSON (cut to 400 characters). (required) | | `status` | integer or null | The HTTP status the caller got. (required) | | `retcode` | integer or null | For a trade the broker answered: its return code. (required) | | `result` | string or null | For a trade: the broker's answer in words with the order and deal tickets, or the error when it did not answer. (required) | | `latency_ms` | integer or null | For a trade: the broker round trip in milliseconds. (required) | | `request_id` | string or null | The X-Request-Id of the request that caused the row; the same id is on its log lines. (required) | | `ip` | string or null | The client IP, recorded for sign-ins, wrong passwords and lockouts. (required) | Example: ```json [ { "id": 4821, "at": 1790981179473, "kind": "trade", "actor": "key_3f9a1c07", "actor_kind": "key", "account": "pepperstone-12345678", "route": "market order", "summary": "market buy 0.10 XAUUSD", "request": "{\"symbol\":\"XAUUSD\",\"volume\":0.1,\"type\":0,\"price\":0.0,\"sl\":2380.0,\"tp\":2420.0,\"order\":0,\"position\":0,\"comment\":\"breakout\"}", "status": 200, "retcode": 10009, "result": "Request completed order 51830031 deal 81200131", "latency_ms": 212, "request_id": "bot-20261003-0042", "ip": null }, { "id": 4790, "at": 1790968301004, "kind": "signin", "actor": "203.0.113.7", "actor_kind": "anonymous", "account": null, "route": "signin", "summary": "dashboard sign-in from 203.0.113.7 (Mozilla/5.0 ...)", "request": null, "status": 200, "retcode": null, "result": null, "latency_ms": null, "request_id": "7c1e2a9f4b3d8e60", "ip": "203.0.113.7" } ] ``` **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. - `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. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/audit?account=pepperstone-12345678&kind=trade&request_id=bot-20261003-0042&q=xauusd&limit=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}/audit", headers=auth, params={"account": "pepperstone-12345678", "kind": "trade", "request_id": "bot-20261003-0042", "q": "xauusd", "limit": 100}) r.raise_for_status() print(r.json()) ``` ### Get connection history `GET /api/v1/accounts/{id}/events` Scope: read. The account's connection events, newest first: started, connected (with the broker's build and how long it had been disconnected), reconnected, lost (why: `connection lost: ...` with the cause, and how long it had been connected), connect_failed, login_rejected, stopped. Kept 90 days or 50,000 rows. Page with `before` = the `id` of the last row seen. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `before` | integer | no | Only rows with an id below this: the id of the last row of the previous page. | | `limit` | integer | no | Most rows to return, at most 1000. (default 100; 1 to 1000) | **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**: Events, newest first. A JSON array of ConnectionEvent. | Field | Type | Description | |---|---|---| | `id` | integer | Row id, increasing. Page with `before`. (required) | | `at` | integer | When it happened, unix milliseconds (UTC). (required) | | `account` | string | Account id. (required) | | `kind` | string | started when the session began; connected (reason: the broker's build) the first time it logged in and reconnected after that; lost (reason: the session's last error) when the link dropped; connect_failed or login_rejected when an attempt failed; stopped when the account was turned off or removed. (required; one of started, connected, reconnected, lost, connect_failed, login_rejected, stopped) | | `reason` | string or null | The build for connected and reconnected, the error for lost, connect_failed and login_rejected. (required) | | `duration_ms` | integer or null | For connected and reconnected: how long the account had been disconnected. For lost and stopped: how long it had been connected. (required) | | `quiet_since` | integer or null | On a lost event cut for missed pings (0.6.0): when the first unanswered ping was sent, unix milliseconds (UTC), so when the broker went quiet; null otherwise. (required) | Example: ```json [ { "id": 310, "at": 1790968298412, "account": "pepperstone-12345678", "kind": "connected", "reason": "build 6090", "duration_ms": 1840, "quiet_since": null }, { "id": 309, "at": 1790968296572, "account": "pepperstone-12345678", "kind": "lost", "reason": "connection lost: 2 pings unanswered in a row (the broker keeps the socket open but has stopped answering)", "duration_ms": 73284110, "quiet_since": 1790968282572 } ] ``` **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. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/events?limit=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/events", headers=auth, params={"limit": 100}) r.raise_for_status() print(r.json()) ``` ### Get the equity curve `GET /api/v1/accounts/{id}/equity` Scope: read. Balance, equity, margin and profit sampled about once a minute while the account is connected (the first sample right after connecting), oldest first, for the last `hours` hours, and `gaps`: the periods in that window when the account was not connected (`to: null` while it still is not), so a chart can break there. Kept 7 days (168 hours). Read from the database: an account that is disconnected or turned off still shows its curve. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Account id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `hours` | integer | no | How far back, 1 to 168. (default 24; 1 to 168) | **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 curve. A EquityCurve object. | Field | Type | Description | |---|---|---| | `account` | string | Account id. (required) | | `hours` | integer | The window asked for, ending now. (required) | | `every_s` | integer | Seconds between samples while connected (60). (required) | | `samples` | array of EquitySample | Oldest first. About one a minute while the account is connected, the first right after it connects; none while it is not (see gaps). (required; see EquitySample) | | `gaps` | array of EquityGap | Oldest first: the periods inside the window when the account was not connected, read from its connection events. Draw a break there instead of a line across the outage. (required; see EquityGap) | Example: ```json { "account": "pepperstone-12345678", "hours": 24, "every_s": 60, "samples": [ { "at": 1790977560000, "balance": 10412.58, "equity": 10641.2, "margin": 878.93, "profit": 228.62 }, { "at": 1790977620000, "balance": 10412.58, "equity": 10650.69, "margin": 878.93, "profit": 238.11 } ], "gaps": [ { "from": 1790968296572, "to": 1790968298412 } ] } ``` **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. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/accounts/pepperstone-12345678/equity?hours=24" \ -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/equity", headers=auth, params={"hours": 24}) r.raise_for_status() print(r.json()) ``` ### See a key's traffic `GET /api/v1/keys/{id}/traffic` Scope: admin. One key's last requests, newest first (a ring of the last 500, in memory since the server started), each with its route template, path and query (`key=` removed), status, time, bytes and address, and its open streams with what they have sent. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `id` | string | yes | Key id. | **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `limit` | integer | no | Most requests to return, at most 500. (default 100; 1 to 500) | **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 key's traffic. A KeyTrafficLog object. | Field | Type | Description | |---|---|---| | `key_id` | string | Key id. (required) | | `name` | string | Key name. (required) | | `time_ms` | integer | Now, unix milliseconds (UTC). (required) | | `since_ms` | integer | When the server started. (required) | | `requests` | array of TrafficRequest | Its last requests, newest first (up to 500 are kept). (required; see TrafficRequest) | | `streams` | array of StreamConnection | Its open streams. (required; see StreamConnection) | Example: ```json { "key_id": "key_3f9a1c07", "name": "EA bridge (gold)", "time_ms": 1790981179473, "since_ms": 1790968290000, "requests": [ { "at": 1790981175002, "method": "GET", "route": "GET /api/v1/accounts/{id}/positions", "path": "/api/v1/accounts/pepperstone-12345678/positions?symbol=XAUUSD", "status": 200, "latency_ms": 0.21, "bytes": 812, "ip": "203.0.113.7", "account": "pepperstone-12345678" } ], "streams": [ { "id": 12, "kind": "sse", "who": { "kind": "key", "key_id": "key_3f9a1c07", "name": "EA bridge (gold)" }, "ip": "203.0.113.7", "user_agent": "python-requests/2.32", "account": "pepperstone-12345678", "symbols": [ "XAUUSD", "EURUSD" ], "events": [ "ticks", "trades", "account" ], "batch_ms": 0, "opened_at": 1790977520000, "sent": { "messages": 52811, "bytes": 6203417, "ticks": 52102, "events": 708 }, "last_sent_at": 1790981179401, "rate_per_s": 14.6, "coalesced": 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. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/keys/key_3f9a1c07/traffic?limit=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}/keys/key_3f9a1c07/traffic", headers=auth, params={"limit": 100}) r.raise_for_status() print(r.json()) ``` ### See who is connected `GET /api/v1/connections` Scope: admin. What leaves the server and to whom, live: every open stream (who opened it, from where, for which account, symbols and events, and what it has sent, with its rate over the last 10 s), every key's requests (1 h and 24 h counts, errors, bytes, busiest routes, last request; zeros when unused) and the dashboard's, counted apart. In memory since the server started (`since_ms`); nothing is persisted and key secrets never appear. **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**: Connections. A Connections object. | Field | Type | Description | |---|---|---| | `time_ms` | integer | Now, unix milliseconds (UTC). (required) | | `since_ms` | integer | When the server started: every counter here begins then; nothing is kept across a restart. (required) | | `streams` | array of StreamConnection | Open streams, newest first. (required; see StreamConnection) | | `keys` | array of KeyTraffic | Every key in the keys table. (required; see KeyTraffic) | | `dashboard` | object | (required; object: sessions_active, streams_open, stream_bytes, requests_1h, requests_24h, errors_1h, bytes_out_1h, last_request_at) | Example: ```json { "time_ms": 1790981179473, "since_ms": 1790968290000, "streams": [ { "id": 12, "kind": "sse", "who": { "kind": "key", "key_id": "key_3f9a1c07", "name": "EA bridge (gold)" }, "ip": "203.0.113.7", "user_agent": "python-requests/2.32", "account": "pepperstone-12345678", "symbols": [ "XAUUSD", "EURUSD" ], "events": [ "ticks", "trades", "account" ], "batch_ms": 0, "opened_at": 1790977520000, "sent": { "messages": 52811, "bytes": 6203417, "ticks": 52102, "events": 708 }, "last_sent_at": 1790981179401, "rate_per_s": 14.6, "coalesced": 0 } ], "keys": [ { "key_id": "key_3f9a1c07", "name": "EA bridge (gold)", "scope": "trade", "accounts": [ "pepperstone-12345678" ], "streams_open": 1, "stream_bytes": 6203417, "requests_1h": 120, "requests_24h": 2211, "errors_1h": 0, "bytes_out_1h": 48210, "last_request_at": 1790981175002, "last_ip": "203.0.113.7", "top_routes_1h": [ { "route": "GET /api/v1/accounts/{id}/positions", "count": 60 }, { "route": "GET /api/v1/accounts/{id}/deals", "count": 60 } ] } ], "dashboard": { "sessions_active": 1, "streams_open": 0, "stream_bytes": 0, "requests_1h": 340, "requests_24h": 1902, "errors_1h": 0, "bytes_out_1h": 912044, "last_request_at": 1790981179470 } } ``` **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. - `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. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/connections" \ -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}/connections", headers=auth) r.raise_for_status() print(r.json()) ```