{
  "openapi": "3.1.0",
  "info": {
    "title": "Termless API",
    "version": "1",
    "summary": "Keep MetaTrader 5 accounts connected around the clock and use them over HTTP.",
    "description": "Termless keeps MetaTrader 5 accounts logged in on a Linux box and exposes them through REST and streaming. JSON over HTTP; every route lives under /api/v1.\n\nAuth: send `Authorization: Bearer <api key>`. The two stream routes also accept `?key=` (browsers cannot set headers on EventSource); no other route reads it, though any route accepts it in the query string. Keys look like `tl_` and 48 hex characters; only a SHA-256 hash is stored, and the key is shown once. Each key has one scope: read (market data and account state), trade (read plus orders) or admin (everything, including accounts, keys, servers and diagnostics). A read or trade key can be limited to some account ids; an admin key cannot. The dashboard signs in with the admin password and gets the HttpOnly, SameSite=Strict cookie `termless_session` (30 days), which acts like an admin key; a cookie-authenticated write or WebSocket whose `Origin` is another site is refused (403).\n\nErrors: `{\"error\": {\"code\", \"message\"}}` with a matching HTTP status: 400 bad_request, 401 unauthorized, 403 forbidden, 403 real_account (trading on an account the broker reports as real money, off until an admin sets `trade_real: true`), 404 not_found, 405 method_not_allowed, 409 conflict, 422 rejected (the broker refused a trade; the body is the trade result plus error), 429 too_many_requests (with Retry-After), 500 internal, 502 broker_error, 503 disconnected, 503 busy (the request waited its whole turn behind earlier ones of the same command and was not sent: safe to send again), 503 stopping (termlessd is stopping; the trade was not sent), 504 timeout (the broker did not answer a request that was sent), 504 unconfirmed (a trade the broker took whose final result did not come: it may have been carried out; check positions and orders).\n\nQuery parameters: a parameter a route does not take is 400, and the message names the ones it takes, so a mistyped filter is never silently ignored. `key=` is accepted on any route.\n\nLockouts: 5 wrong passwords or setup tokens from one IP lock it out of sign-in for 15 minutes; 30 unknown API keys from one IP in 15 minutes lock it out of key auth for 15 minutes (a valid key from that IP still works, 0.6.3: the lockout refuses unknown keys only). Behind a reverse proxy, start with `--trust-proxy` (`TERMLESS_TRUST_PROXY=1`): the client IP is then read from one header, `--proxy-header` / `TERMLESS_PROXY_HEADER` (default `X-Forwarded-For`, its last hop; `X-Real-IP` is never a fallback), and https from `X-Forwarded-Proto`. The proxy must set or overwrite that header on every request, and clients must not reach the port directly.\n\nRequest ids: every response carries `X-Request-Id`. Send your own (1 to 64 characters of `A-Z a-z 0-9 - _ . :`) and it is kept; otherwise the server makes one. The same id is on every log line the request wrote and on every audit row it caused.\n\nIdempotency: the trade routes that change something (POST /orders, POST /order_send, PATCH and DELETE on /orders/{ticket} and /positions/{ticket}) take an `Idempotency-Key` header (1 to 200 printable ASCII characters, scoped to the caller, the method and the path). The first request with a key is executed and its whole response stored for 24 hours; a repeat with the same key and body gets it back with `Idempotent-Replayed: true` and never reaches the broker; the same key with a different body or query string is 409; a concurrent repeat waits for the first's result. Error results are stored too (503 busy and stopping aside: never sent, so the key is let go; a 504 unconfirmed is replaced by the trade's result if it comes late), and the key is reserved before the broker is asked, so a first request that never finished answers 409 on its retry: a blind retry can never double a trade.\n\nTimeouts: one broker call is given 20 s; requests of one command go to the broker one at a time per account, and one that waits 20 s for its turn is 503 busy without being sent; every route except the two streams is given up with 504 after 30 s (`TERMLESS_REQUEST_TIMEOUT` seconds changes it, 0 removes it). Broker gateways must be on the public internet: a host that resolves to loopback, link-local, private, carrier-grade NAT, multicast or documentation space is refused with 400 unless the server runs with `TERMLESS_ALLOW_PRIVATE_GATEWAYS=1`.\n\nTimes: market and trade times are unix seconds (`time`) and milliseconds (`time_msc`) in the trade server's clock, exactly as MetaTrader reports them; each account's summary has `server_offset` (seconds east of UTC; subtract it to get UTC; read again hourly and checked against live ticks; it is the offset now, so times from before the broker's last summer-time switch need that switch's dates), and query times (`from`, `to`) use the same clock. Times about Termless itself (`status.since`, `status.retry_at`, `created_at`, `last_used_at`, `verified_at`, `started_at`) are plain UTC unix seconds.\n\nVolumes are lots. Prices are plain numbers; 0 means none (no SL, no TP). side is buy or sell. Symbol names are matched exactly, else case-insensitively (xauusd finds XAUUSD). Account ids use a-z, 0-9 and -, up to 48 characters.\n\nStatic: `/` is the dashboard (single page, hash routes), `/docs` the API docs page, `/api/openapi.json` this file, `/assets/*` their files. All are built into the binary and served with `Content-Security-Policy: default-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; object-src 'none'`.",
    "license": {
      "name": "MIT",
      "identifier": "MIT"
    }
  },
  "servers": [
    {
      "url": "/",
      "description": "This server"
    }
  ],
  "tags": [
    {
      "name": "Health, setup and session",
      "description": "Whether the server is up and how well it has been (GET /status, GET /metrics for Prometheus), first-run setup, and the dashboard's own sign-in. Apps and agents need /health, /me, /status and each account's /ready."
    },
    {
      "name": "Diagnostics",
      "description": "What the server itself is doing: the process, each account's connection, frames the client could not decode, recent warnings, crash reports and the log. Undecodable frames are the first sign of a broker build the client does not understand. Each (account, command, kind) keeps at most 5 bodies an hour; the rest are only counted. Kept ones are also appended to `<data>/captures/undecoded.jsonl`, and the newest of them are read back at start, so a restart does not empty the list (the counters start again). Admin only."
    },
    {
      "name": "Broker servers",
      "description": "The directory of known broker servers and a check for any address. Used when adding an account."
    },
    {
      "name": "Accounts",
      "description": "The MT5 accounts this server keeps connected around the clock. Each has an id you choose, used in every account URL. A route that needs the broker answers 503 while the account reconnects (it waits up to 2 s first) or while it is turned off. On an account the broker reports as real money, trading is off until an admin sets `trade_real: true`."
    },
    {
      "name": "Market data",
      "description": "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."
    },
    {
      "name": "Streaming",
      "description": "Live prices pushed to you. Server-sent events for browsers and simple scripts, a WebSocket when you want to change symbols on the fly. Both end when the account is deleted or logs in with new details; reconnect to follow it. Trade events are numbered per account, and the numbering survives a restart: a client that dropped resumes with `Last-Event-ID` or `?after=<id>` and gets what it missed first (from the last 1,024), or a `resync` when that cannot be done. After a gap (the broker link was down, the server stopped, the account's session started again) the deals made meanwhile come as trade events marked `caught_up`, then a `resync`. `GET /trades?after=` serves the same numbering to clients that poll."
    },
    {
      "name": "Trading",
      "description": "Positions, pending orders, deal and order history, the calls that change them, and margin, profit and order checks that send nothing (GET /calc, POST /order_check). Every change returns a trade result with the broker's return code: 200 when placed or done, 422 when the broker refused it, with `warnings` when something in the request was changed or cannot be kept. `comment` takes up to 255 characters; the broker keeps 31. `magic` cannot be sent to the broker (the web protocol has no field for it). For a market or pending order, Termless keeps both and puts them back on its positions, orders, deals and stream events. Positions, orders and deals carry `reason` (web, sl, tp, stop_out, ...). On an account the broker reports as real money, the routes that trade answer 403 `real_account` until an admin sets `trade_real: true` on it."
    },
    {
      "name": "Trails",
      "description": "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)."
    },
    {
      "name": "API keys",
      "description": "Keys for apps, scripts and agents. Each has one scope; a read or trade key can be limited to some accounts. The full key is shown once, when you create it."
    }
  ],
  "security": [
    {
      "bearerKey": []
    },
    {
      "sessionCookie": []
    }
  ],
  "paths": {
    "/api/v1/health": {
      "get": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "getHealth",
        "summary": "Check health",
        "description": "Answers without a key, so it works for uptime monitors. `degraded` means an enabled account is not connected. `version` and `accounts` are filled in only for a signed-in caller or a valid key (`accounts` then only with the accounts it may see); anyone else gets `version: null` and no accounts.",
        "x-scope": "none",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Server state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "ok",
                  "version": "0.6.2",
                  "uptime_s": 86412,
                  "accounts": [
                    {
                      "id": "pepperstone-12345678",
                      "label": "Pepperstone demo",
                      "enabled": true,
                      "connected": true,
                      "ping_ms": 14.2,
                      "reconnects": 0
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        },
        "security": [
          {}
        ]
      }
    },
    "/api/v1/setup": {
      "get": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "getSetup",
        "summary": "Check whether setup is needed",
        "description": "True on a new install until the admin password is set.",
        "x-scope": "none",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Setup state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SetupState"
                },
                "example": {
                  "needs_setup": false
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        },
        "security": [
          {}
        ]
      },
      "post": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "completeSetup",
        "summary": "Finish first-run setup",
        "description": "Sets the admin password using the one-time setup token the server printed to its log (also in `<data>/setup-token`), and signs you in with a session cookie. The token stops anyone who reaches the port first from claiming the install. Setting `TERMLESS_ADMIN_PASSWORD` in the environment skips this step; `termlessd passwd` resets the password. Wrong tokens count toward the 5-try lockout.",
        "x-scope": "none",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetupRequest"
              },
              "example": {
                "token": "4f1c9e0b7a2d5e8c3b6a9d0e",
                "password": "A long passphrase, 2 commas"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done, and signed in (Set-Cookie).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {}
        ]
      }
    },
    "/api/v1/session": {
      "post": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "signIn",
        "summary": "Sign in to the dashboard",
        "description": "Checks the admin password and sets the HttpOnly, SameSite=Strict cookie `termless_session` (30 days) that acts like an admin key. A cookie-authenticated write or WebSocket whose `Origin` is another site is refused (403). Five wrong tries from one IP lock that IP out for 15 minutes.",
        "x-scope": "none",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SessionRequest"
              },
              "example": {
                "password": "a long passphrase"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in (Set-Cookie).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {}
        ]
      },
      "delete": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "signOut",
        "summary": "Sign out",
        "description": "Clears the session cookie.",
        "x-scope": "none",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Signed out.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/me": {
      "get": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "getMe",
        "summary": "Who am I",
        "description": "Tells you what the key (or session) you sent may do. A good first call for an agent: it shows the scope and the accounts in reach.",
        "x-scope": "any",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The caller.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                },
                "example": {
                  "kind": "key",
                  "name": "EA bridge (gold)",
                  "scopes": [
                    "trade"
                  ],
                  "accounts": [
                    "pepperstone-12345678"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/admin/password": {
      "put": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "changeAdminPassword",
        "summary": "Change the admin password",
        "description": "Dashboard session only; an API key gets 403. Signs out every other dashboard session. A wrong `current` is 400 (not 401, so the dashboard stays signed in) and counts toward the 5-try lockout.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PasswordChange"
              },
              "example": {
                "current": "A long passphrase, 2 commas",
                "new": "An even longer passphrase, 3 commas"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Changed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-cookie-only": true
      }
    },
    "/api/v1/status": {
      "get": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "getStatus",
        "summary": "Get the status report",
        "description": "Whether Termless and each broker link are working, and how well over time: a verdict and one plain sentence at the top; the process (version, uptime, memory, restarts and unclean exits in 30 days); and per account its verdict, uptime over 1 hour, 24 hours, 7 days and 30 days (time before the account was added and time it was turned off are left out; Termless's own downtime counts as down), reconnects, the longest outage, a 30-day strip of UTC days, the outages with a cause (broker maintenance, broker unreachable, broker unresponsive, Termless restart, network, login refused), the tick rate and each watched symbol's last tick, order round-trip latency and counts over 24 hours, and protocol drift (the build, whether it is verified, undecoded frames). A key limited to some accounts sees only those; an admin key, a key without an account list and the dashboard see all. Read from the connection history and the audit trail.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The report.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatusReport"
                },
                "example": {
                  "verdict": "healthy",
                  "summary": "All good: 1 account connected, 99.86% up over the last 24 hours.",
                  "checked_at": 1792300000123,
                  "termless": {
                    "version": "0.6.2",
                    "started_at": 1792200000,
                    "uptime_s": 100000,
                    "rss_kb": 16384,
                    "rss_peak_kb": 20480,
                    "restarts_30d": 3,
                    "unclean_exits_30d": 0,
                    "last_start_at": 1792200000000,
                    "crash_reports_24h": 0,
                    "errors_1h": 0,
                    "trail_rows_dropped": 0
                  },
                  "accounts": [
                    {
                      "id": "pepperstone-12345678",
                      "label": "Pepperstone demo",
                      "server": "Pepperstone-Demo",
                      "broker": "Pepperstone",
                      "enabled": true,
                      "verdict": "healthy",
                      "summary": "Connected for 2 h 46 min, ping 12 ms.",
                      "connected": true,
                      "since": 1792290000,
                      "ping_ms": 12.4,
                      "tracked_since": 1790000000000,
                      "uptime": {
                        "1h": {
                          "percent": 100.0,
                          "up_ms": 3600000,
                          "down_ms": 0,
                          "measured_ms": 3600000,
                          "reconnects": 0,
                          "outages": 0,
                          "longest_outage_ms": 0
                        },
                        "24h": {
                          "percent": 99.86,
                          "up_ms": 86280000,
                          "down_ms": 120000,
                          "measured_ms": 86400000,
                          "reconnects": 1,
                          "outages": 1,
                          "longest_outage_ms": 120000
                        },
                        "7d": {
                          "percent": 99.97,
                          "up_ms": 604620000,
                          "down_ms": 180000,
                          "measured_ms": 604800000,
                          "reconnects": 3,
                          "outages": 2,
                          "longest_outage_ms": 120000
                        },
                        "30d": {
                          "percent": 99.95,
                          "up_ms": 2590710000,
                          "down_ms": 1290000,
                          "measured_ms": 2592000000,
                          "reconnects": 9,
                          "outages": 6,
                          "longest_outage_ms": 600000
                        }
                      },
                      "days": [
                        {
                          "date": "2026-09-19",
                          "from": 1789776000000,
                          "percent": null,
                          "up_ms": 0,
                          "down_ms": 0,
                          "measured_ms": 0,
                          "outages": 0
                        },
                        {
                          "date": "2026-10-18",
                          "from": 1792281600000,
                          "percent": 99.35,
                          "up_ms": 18280000,
                          "down_ms": 120000,
                          "measured_ms": 18400000,
                          "outages": 1
                        }
                      ],
                      "outages": [
                        {
                          "from": 1792291200000,
                          "to": 1792291320000,
                          "duration_ms": 120000,
                          "ongoing": false,
                          "start_estimated": false,
                          "detected_at": null,
                          "cause": "broker_maintenance",
                          "message": "Pepperstone restarted its servers; back after 2 min.",
                          "detail": "login refused (code 2) for 1 min after the link dropped"
                        },
                        {
                          "from": 1792199996000,
                          "to": 1792200001200,
                          "duration_ms": 5200,
                          "ongoing": false,
                          "start_estimated": false,
                          "detected_at": null,
                          "cause": "termless_restart",
                          "message": "Termless restarted; back after 5 s.",
                          "detail": "termlessd stopped (upgrade or restart)"
                        }
                      ],
                      "ticks": {
                        "per_min": 384.0,
                        "seen": 1234567,
                        "last_tick_age_ms": 400,
                        "feed_quiet": false,
                        "symbols": [
                          {
                            "symbol": "EURUSD",
                            "last_tick_age_ms": 400,
                            "market_open": true,
                            "fresh": true
                          },
                          {
                            "symbol": "XAUUSD",
                            "last_tick_age_ms": 812,
                            "market_open": true,
                            "fresh": true
                          }
                        ]
                      },
                      "orders": {
                        "window_h": 24,
                        "count": 12,
                        "done": 11,
                        "rejected": 1,
                        "timeout": 0,
                        "failed": 0,
                        "latency_ms": {
                          "p50": 41,
                          "p95": 120,
                          "max": 133
                        }
                      },
                      "protocol": {
                        "build": 6090,
                        "build_verified": true,
                        "undecoded_1h": 0,
                        "undecoded_24h": 0,
                        "undecoded_by_command": []
                      },
                      "pings_missed": 2,
                      "trades_unconfirmed": 0,
                      "trades_late": 0,
                      "command_waits": 1840,
                      "command_wait_ms": 3120
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/metrics": {
      "get": {
        "tags": [
          "Health, setup and session"
        ],
        "operationId": "getMetrics",
        "summary": "Get Prometheus metrics",
        "description": "The same numbers in the Prometheus text format 0.0.4 (`text/plain; version=0.0.4`), for a scraper: termless_up, termless_build_info{version}, termless_uptime_seconds, termless_process_resident_memory_bytes (Linux), and per account (label `account`): enabled, connected, ready{kind=read|trade}, ping_seconds, reconnects_total, ticks_total, last_tick_age_seconds, uptime_ratio{window=1h|24h|7d|30d}, undecoded_frames_total, server_build, build_verified, orders_total{result=done|rejected|timeout|failed} and order_latency_seconds_sum/_count (since this start). The accounts follow the same rule as GET /status. Send the key as `Authorization: Bearer` (Prometheus: `authorization: {credentials: ...}`).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The metrics, text/plain; version=0.0.4.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "example": "# HELP termless_up Always 1 while termlessd answers.\n# TYPE termless_up gauge\ntermless_up 1\n# HELP termless_build_info The termlessd version.\n# TYPE termless_build_info gauge\ntermless_build_info{version=\"0.6.2\"} 1\n# HELP termless_uptime_seconds Seconds since termlessd started.\n# TYPE termless_uptime_seconds gauge\ntermless_uptime_seconds 100000\n# HELP termless_crash_reports_24h Crash reports (panics termlessd survived, unclean exits) written in the last 24 hours.\n# TYPE termless_crash_reports_24h gauge\ntermless_crash_reports_24h 0\n# HELP termless_errors_logged_1h Error lines in termlessd's log in the last hour.\n# TYPE termless_errors_logged_1h gauge\ntermless_errors_logged_1h 0\n# HELP termless_account_connected 1 while the account's link to the broker is up.\n# TYPE termless_account_connected gauge\ntermless_account_connected{account=\"pepperstone-12345678\"} 1\n# HELP termless_account_ready The ready check without asked symbols, 1 or 0.\n# TYPE termless_account_ready gauge\ntermless_account_ready{account=\"pepperstone-12345678\",kind=\"read\"} 1\ntermless_account_ready{account=\"pepperstone-12345678\",kind=\"trade\"} 1\n# HELP termless_account_uptime_ratio Share of the window the account was connected (as /status).\n# TYPE termless_account_uptime_ratio gauge\ntermless_account_uptime_ratio{account=\"pepperstone-12345678\",window=\"24h\"} 0.9986\n# HELP termless_account_orders_total Trade requests since this start, by result.\n# TYPE termless_account_orders_total counter\ntermless_account_orders_total{account=\"pepperstone-12345678\",result=\"done\"} 11\n"
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/diagnostics": {
      "get": {
        "tags": [
          "Diagnostics"
        ],
        "operationId": "getDiagnostics",
        "summary": "Get diagnostics",
        "description": "One snapshot of the server: version and build target, process stats (null off Linux), data folder, log file, database size, dashboard sessions, open streams, every account's status with tick and decode counters, frames the client could not decode, the last 100 warnings and errors, crash reports, and the report from an unclean exit, if any.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Diagnostics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Diagnostics"
                },
                "example": {
                  "version": "0.1.0",
                  "target": "x86_64-unknown-linux-gnu",
                  "pid": 41822,
                  "started_at": 1790894779,
                  "uptime_s": 75600,
                  "process": {
                    "rss_kb": 23140,
                    "rss_peak_kb": 31200,
                    "threads": 9,
                    "open_files": 21
                  },
                  "data_dir": "/var/lib/termless",
                  "log_file": "/var/lib/termless/logs/termlessd.2026-10-03.log",
                  "db_bytes": 135168,
                  "dashboard_sessions": 1,
                  "streams": {
                    "sse": 1,
                    "ws": 0,
                    "max": 1024,
                    "max_per_key": 256
                  },
                  "accounts": [
                    {
                      "connected": true,
                      "since": 1790968298,
                      "reconnects": 0,
                      "ping_ms": 14.2,
                      "server_build": 6090,
                      "last_error": null,
                      "subscribed": 2,
                      "login_rejected": false,
                      "retry_at": null,
                      "id": "pepperstone-12345678",
                      "enabled": true,
                      "session_running": true,
                      "ticks_seen": 1840211,
                      "last_tick_at_ms": 1790970379473,
                      "last_frame_at_ms": 1790970381002,
                      "streams": 1,
                      "ticks_coalesced": 0,
                      "undecoded": 3
                    }
                  ],
                  "undecoded": {
                    "total": 3,
                    "file": "/var/lib/termless/captures/undecoded.jsonl",
                    "by_command": [
                      {
                        "account": "pepperstone-12345678",
                        "command": 8,
                        "kind": "body",
                        "context": "tick push",
                        "count": 3,
                        "first_at": 1790964410,
                        "last_at": 1790965012,
                        "last_error": "short read at offset 40"
                      }
                    ],
                    "recent": [
                      {
                        "id": 3,
                        "time": 1790965012,
                        "account": "pepperstone-12345678",
                        "kind": "body",
                        "command": 8,
                        "code": 0,
                        "context": "tick push",
                        "error": "short read at offset 40",
                        "server_build": 6090,
                        "len": 52
                      }
                    ]
                  },
                  "problems": [
                    {
                      "time": 1790968290,
                      "level": "warn",
                      "target": "termless::session",
                      "message": "[pepperstone-12345678] connection lost, reconnecting"
                    }
                  ],
                  "crashes": [
                    {
                      "name": "20261002T231405Z-panic.txt",
                      "time": 1790896445,
                      "size": 6120,
                      "summary": "index out of bounds: the len is 3 but the index is 3"
                    }
                  ],
                  "unclean_exit_report": null
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/diagnostics/undecoded": {
      "get": {
        "tags": [
          "Diagnostics"
        ],
        "operationId": "listUndecoded",
        "summary": "List undecoded frames",
        "description": "Frames the client could not decode, newest first, with their bytes as hex. The server keeps the last 200 in memory, and at start reads the newest kept ones back from `captures/undecoded.jsonl` (its last 4 MB), so a restart does not empty this list. Without `bodies=1`, `body_hex` is cut to its first 128 bytes and `body_preview: true` says so (a page of 200 frames is then under 100 KB); with it, up to 64 KB a frame.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "account",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only this account's frames.",
            "example": "pepperstone-12345678"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 50,
              "minimum": 1,
              "maximum": 200
            },
            "description": "Most frames to return, at most 200.",
            "example": 50
          },
          {
            "name": "bodies",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "1 (or true) returns each frame's whole body_hex, up to 64 KB a frame."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Frames.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/UndecodedFrame"
                  },
                  "description": "Frames, newest first."
                },
                "example": [
                  {
                    "id": 3,
                    "time": 1790965012,
                    "account": "pepperstone-12345678",
                    "login": 12345678,
                    "kind": "body",
                    "command": 8,
                    "code": 0,
                    "context": "tick push",
                    "error": "short read at offset 40",
                    "server_build": 6090,
                    "len": 52,
                    "body_hex": "0a000000b80b0000a4703d0ad7af924000000000000000000000000000000000c8b1e2a4b5010000",
                    "truncated": false,
                    "body_preview": true
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/diagnostics/doctor": {
      "get": {
        "tags": [
          "Diagnostics"
        ],
        "operationId": "runDoctor",
        "summary": "Run the doctor",
        "description": "The same checks as `termlessd doctor` on the command line, against the running server: the data folder (exists, writable, owner-only), `master.key`, the database (integrity check and row counts), the listen address, each account's gateway (DNS, TLS, the web terminal's build, and the session's live state), the clock against the first connected broker (warns past 5 s) and free disk. Each warn or fail says what to do.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The report.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DoctorReport"
                },
                "example": {
                  "verdict": "warnings",
                  "version": "0.1.0",
                  "data_dir": "/var/lib/termless",
                  "checks": [
                    {
                      "name": "data folder",
                      "level": "ok",
                      "detail": "/var/lib/termless exists and is writable"
                    },
                    {
                      "name": "master.key",
                      "level": "ok",
                      "detail": "/var/lib/termless/master.key present (owner-only)"
                    },
                    {
                      "name": "database",
                      "level": "ok",
                      "detail": "/var/lib/termless/termless.db (132 KB) integrity ok; rows: accounts 1, keys 2, audit 4821, account_events 310, equity_samples 1440"
                    },
                    {
                      "name": "listen",
                      "level": "ok",
                      "detail": "serving on http://127.0.0.1:8780"
                    },
                    {
                      "name": "gateway",
                      "level": "ok",
                      "detail": "pepperstone-12345678: mt5-demo01.pepperstone.com:443 is Pepperstone Group Limited build 6090 (2 servers); connected, build 6090"
                    },
                    {
                      "name": "clock",
                      "level": "warn",
                      "detail": "7 s off the broker's clock",
                      "fix": "enable NTP (timedatectl set-ntp true); candle times and expirations depend on it"
                    },
                    {
                      "name": "disk",
                      "level": "ok",
                      "detail": "18240 MB free; termless uses 3 MB"
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/audit": {
      "get": {
        "tags": [
          "Trails"
        ],
        "operationId": "listAudit",
        "summary": "Read the audit trail",
        "description": "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.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "account",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only rows about this account.",
            "example": "pepperstone-12345678"
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "trade",
                "account",
                "key",
                "signin",
                "auth_failed",
                "lockout",
                "password",
                "setup",
                "server_check",
                "server_trust",
                "start"
              ]
            },
            "description": "Only rows of this kind.",
            "example": "trade"
          },
          {
            "name": "actor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only rows by this actor (a key id, admin, an IP, termlessd)."
          },
          {
            "name": "request_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 64
            },
            "description": "Only rows caused by the request with this X-Request-Id (exact match).",
            "example": "bot-20261003-0042"
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "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.",
            "example": "xauusd"
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Only rows with an id below this: the id of the last row of the previous page."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Most rows to return, at most 1000.",
            "example": 100
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Rows, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/AuditRow"
                  },
                  "description": "Audit rows."
                },
                "example": [
                  {
                    "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"
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/diagnostics/crashes/{name}": {
      "parameters": [
        {
          "name": "name",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[^/\\\\]+\\.txt$"
          },
          "description": "Crash report file name, from the crashes list in GET /api/v1/diagnostics.",
          "example": "20261002T231405Z-panic.txt"
        }
      ],
      "get": {
        "tags": [
          "Diagnostics"
        ],
        "operationId": "getCrashReport",
        "summary": "Get a crash report",
        "description": "The text of one crash report: a panic, or an exit without a clean shutdown, with the last log lines before it.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The report, as text/plain.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/diagnostics/logs": {
      "get": {
        "tags": [
          "Diagnostics"
        ],
        "operationId": "getLogs",
        "summary": "Get the log",
        "description": "The end of the current log file (`<data>/logs/termlessd.<date>.log`, one per day). 404 before the first one is written.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "lines",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 200,
              "minimum": 1,
              "maximum": 5000
            },
            "description": "How many lines from the end, at most 5000.",
            "example": 200
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The last lines, as text/plain.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/Internal"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/servers": {
      "get": {
        "tags": [
          "Broker servers"
        ],
        "operationId": "searchServers",
        "summary": "Search broker servers",
        "description": "Searches the directory of trade servers whose web terminal host is known: the built-in list plus every one this install has checked. Matches server name, company and host, ignoring case, spaces, hyphens, dots and other punctuation (`black bull`, `blackbull` and `Black-Bull` find the same). Servers this install has checked come first; an empty `q` returns the top of the list. Server names may contain spaces.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Text to match, for example black bull. Empty for the top of the list.",
            "example": "pepperstone"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 200
            },
            "description": "Most rows to return, at most 200.",
            "example": 20
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Matching servers.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Server"
                  },
                  "description": "Servers."
                },
                "example": [
                  {
                    "server": "Pepperstone-Demo",
                    "company": "Pepperstone Group Limited",
                    "host": "mt5-demo01.pepperstone.com",
                    "port": 443,
                    "type": "demo",
                    "build": 6090,
                    "verified_at": 1790966779,
                    "tls_name": null,
                    "pin_sha256": null,
                    "prop_firm": false
                  },
                  {
                    "server": "Pepperstone-MT5-Live01",
                    "company": "Pepperstone Group Limited",
                    "host": "mt5-1.pepperstone.com",
                    "port": 443,
                    "type": "real",
                    "build": null,
                    "verified_at": null,
                    "tls_name": null,
                    "pin_sha256": null,
                    "prop_firm": false
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/servers/check": {
      "post": {
        "tags": [
          "Broker servers"
        ],
        "operationId": "checkServerHost",
        "summary": "Check an address",
        "description": "Reads the public web terminal page on a host and reports which trade servers it answers for, and remembers them in the directory. Use it before adding an account on a server the directory does not know. Gateways must be on the public internet: a host that resolves to loopback, link-local, private, carrier-grade NAT, multicast or documentation space is 400 (unless the server runs with `TERMLESS_ALLOW_PRIVATE_GATEWAYS=1`). The certificate is always verified: a missing intermediate is fetched from the certificate's own CA Issuers URL (public addresses only) and the chain verified again; `tls_name` checks an IP access point against the name on its certificate; a certificate for another name or from a private CA is refused with 502 `untrusted_certificate` and a `certificate` object (CertificateError) whose `spki_sha256` an admin may pin by checking again with `fingerprint` (audited as `server_trust`); a pinned host that shows another key is 502 `certificate_changed`. A terminal behind a Cloudflare challenge (only browsers get in) is 502 `browser_only`. Any other failure answers one generic 502 `broker_error` (the route is not a port scanner); the reason is in the server log and the audit trail (`server_check`).",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ServerCheckRequest"
              },
              "example": {
                "host": "mt5-demo01.pepperstone.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The host serves an MT5 web terminal.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServerCheck"
                },
                "example": {
                  "ok": true,
                  "host": "mt5-demo01.pepperstone.com",
                  "port": 443,
                  "company": "Pepperstone Group Limited",
                  "build": 6090,
                  "servers": [
                    {
                      "server": "Pepperstone-Demo",
                      "type": "demo"
                    }
                  ],
                  "tls_name": null,
                  "pin_sha256": null
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "description": "broker_error (generic), untrusted_certificate or certificate_changed (with the certificate), or browser_only.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "$ref": "#/components/schemas/CertificateError"
                    }
                  ]
                },
                "examples": {
                  "untrusted": {
                    "value": {
                      "error": {
                        "code": "untrusted_certificate",
                        "message": "the certificate of mt5-demo.broker-example.com is not trusted: it is for another name; ..."
                      },
                      "certificate": {
                        "host": "mt5-demo.broker-example.com",
                        "reason": "name_mismatch",
                        "detail": "NotValidForNameContext",
                        "names": [
                          "*.mobile-demo.example.net",
                          "mobile-demo.example.net"
                        ],
                        "subject": "CN=*.mobile-demo.example.net",
                        "issuer": "CN=Example DV CA, O=Example Trust, C=LU",
                        "not_before": 1759190400,
                        "not_after": 1790726399,
                        "spki_sha256": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7",
                        "pinned": null
                      }
                    }
                  },
                  "browser_only": {
                    "value": {
                      "error": {
                        "code": "browser_only",
                        "message": "this broker's web terminal only lets browsers in, so Termless can't reach it"
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/servers/{server}/trust": {
      "parameters": [
        {
          "name": "server",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Trade server name as in the directory (spaces are allowed; encode them).",
          "example": "Alpari-MT5-Demo"
        }
      ],
      "post": {
        "tags": [
          "Broker servers"
        ],
        "operationId": "trustServerKey",
        "summary": "Pin a certificate key",
        "description": "Pins a certificate key for the server's host and port (every directory row on it), for a broker whose certificate cannot be verified (another name, a private CA). The live host is checked with the pin first, so only the key it presents now can be pinned: 502 `certificate_changed` otherwise. Accounts on that gateway log in again with the pin. Audited as `server_trust`.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TrustRequest"
              },
              "example": {
                "fingerprint": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pinned.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrustResult"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "description": "certificate_changed (the host shows another key), or another failure reading the host.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "$ref": "#/components/schemas/CertificateError"
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "delete": {
        "tags": [
          "Broker servers"
        ],
        "operationId": "untrustServerKey",
        "summary": "Remove a pinned key",
        "description": "Removes the pin for the server's host and port; the host is checked the normal way again and its accounts log in again. Audited as `server_trust`.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "204": {
            "description": "Removed.",
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "operationId": "listAccounts",
        "summary": "List accounts",
        "description": "Every account the key may see, with its live connection status.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Accounts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Account"
                  },
                  "description": "Accounts."
                },
                "example": [
                  {
                    "id": "pepperstone-12345678",
                    "label": "Pepperstone demo",
                    "login": 12345678,
                    "server": "Pepperstone-Demo",
                    "host": "mt5-demo01.pepperstone.com",
                    "port": 443,
                    "symbols": [
                      "XAUUSD",
                      "EURUSD"
                    ],
                    "enabled": true,
                    "created_at": 1790881742,
                    "tls_name": null,
                    "trade_real": false,
                    "new_trades_paused": false,
                    "clock": null,
                    "pinned": false,
                    "status": {
                      "connected": true,
                      "since": 1790968298,
                      "reconnects": 0,
                      "ping_ms": 14.2,
                      "server_build": 6090,
                      "last_error": null,
                      "subscribed": 2,
                      "login_rejected": false,
                      "retry_at": null
                    }
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "post": {
        "tags": [
          "Accounts"
        ],
        "operationId": "createAccount",
        "summary": "Add an account",
        "description": "Saves the account and starts connecting it in the background, so `status.connected` is false at first. Poll `GET /api/v1/accounts/{id}` until it connects; a refused login shows in `status.last_error` and `status.login_rejected`. `host` is looked up from `server` (this install's directory, then the built-in list) when omitted; 400 if it cannot be found. 409 if the id, or the same login on the same host, exists. `trade_real: true` allows trading if the broker reports the account as real money (off by default).",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountCreate"
              },
              "example": {
                "label": "Pepperstone demo",
                "login": 12345678,
                "password": "your MT5 password",
                "server": "Pepperstone-Demo",
                "symbols": [
                  "XAUUSD",
                  "EURUSD"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Saved. Connecting in the background.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                },
                "example": {
                  "id": "pepperstone-12345678",
                  "label": "Pepperstone demo",
                  "login": 12345678,
                  "server": "Pepperstone-Demo",
                  "host": "mt5-demo01.pepperstone.com",
                  "port": 443,
                  "symbols": [
                    "XAUUSD",
                    "EURUSD"
                  ],
                  "enabled": true,
                  "created_at": 1790981179,
                  "tls_name": null,
                  "trade_real": false,
                  "new_trades_paused": false,
                  "clock": null,
                  "pinned": false,
                  "status": {
                    "connected": false,
                    "since": null,
                    "reconnects": 0,
                    "ping_ms": null,
                    "server_build": null,
                    "last_error": null,
                    "subscribed": 0,
                    "login_rejected": false,
                    "retry_at": null
                  }
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Accounts"
        ],
        "operationId": "getAccount",
        "summary": "Get an account",
        "description": "One account with its live connection status.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                },
                "example": {
                  "id": "pepperstone-12345678",
                  "label": "Pepperstone demo",
                  "login": 12345678,
                  "server": "Pepperstone-Demo",
                  "host": "mt5-demo01.pepperstone.com",
                  "port": 443,
                  "symbols": [
                    "XAUUSD",
                    "EURUSD"
                  ],
                  "enabled": true,
                  "created_at": 1790881742,
                  "tls_name": null,
                  "trade_real": false,
                  "new_trades_paused": false,
                  "clock": null,
                  "pinned": false,
                  "status": {
                    "connected": true,
                    "since": 1790968298,
                    "reconnects": 0,
                    "ping_ms": 14.2,
                    "server_build": 6090,
                    "last_error": null,
                    "subscribed": 2,
                    "login_rejected": false,
                    "retry_at": null
                  }
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "patch": {
        "tags": [
          "Accounts"
        ],
        "operationId": "updateAccount",
        "summary": "Update an account",
        "description": "Change the label, watchlist or login details, or turn it off with `enabled: false` (logs out and parks it). Changing password, server, host, port or tls_name logs in again; `symbols` replaces the watchlist and starts streaming new ones without logging in again. `trade_real` allows (true) or stops (false) trading when the broker reports the account as real money; it takes effect at once.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccountPatch"
              },
              "example": {
                "symbols": [
                  "XAUUSD",
                  "EURUSD",
                  "GBPUSD"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                },
                "example": {
                  "id": "pepperstone-12345678",
                  "label": "Pepperstone demo",
                  "login": 12345678,
                  "server": "Pepperstone-Demo",
                  "host": "mt5-demo01.pepperstone.com",
                  "port": 443,
                  "symbols": [
                    "XAUUSD",
                    "EURUSD",
                    "GBPUSD"
                  ],
                  "enabled": true,
                  "created_at": 1790881742,
                  "tls_name": null,
                  "trade_real": false,
                  "new_trades_paused": false,
                  "clock": null,
                  "pinned": false,
                  "status": {
                    "connected": true,
                    "since": 1790968298,
                    "reconnects": 0,
                    "ping_ms": 14.2,
                    "server_build": 6090,
                    "last_error": null,
                    "subscribed": 2,
                    "login_rejected": false,
                    "retry_at": null
                  }
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "delete": {
        "tags": [
          "Accounts"
        ],
        "operationId": "deleteAccount",
        "summary": "Remove an account",
        "description": "Logs out and forgets the account. Positions at the broker are not touched.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "204": {
            "description": "Removed.",
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/summary": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Accounts"
        ],
        "operationId": "getAccountSummary",
        "summary": "Get balance and margin",
        "description": "Balance, equity, margin and the counts of positions and orders, the same numbers MT5 shows. Profit, equity and margin are live. `server_offset` turns this account's market and trade times into UTC. Never waits on the broker once the account record has been read: a copy older than 5 s is answered at once and read again in the background (balance and credit follow the trade pushes either way).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Account summary.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Summary"
                },
                "example": {
                  "login": 12345678,
                  "name": "Demo Trader",
                  "server": "Pepperstone-Demo",
                  "company": "Pepperstone Group Limited",
                  "currency": "USD",
                  "leverage": 200,
                  "balance": 10412.58,
                  "credit": 0.0,
                  "profit": 238.11,
                  "equity": 10650.69,
                  "margin": 878.93,
                  "margin_free": 9771.76,
                  "margin_level": 1211.78,
                  "margin_so_call": 100.0,
                  "margin_so_so": 50.0,
                  "trade_allowed": true,
                  "demo": true,
                  "hedging": true,
                  "server_offset": 10800,
                  "positions": 3,
                  "orders": 2
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/overview": {
      "get": {
        "tags": [
          "Accounts"
        ],
        "operationId": "getOverview",
        "summary": "Get every account's summary",
        "description": "The summary of every enabled account the caller may read, read together, in one request (0.7.0): what the dashboard's Overview asks every 4 s. An account with no summary (not connected) carries an error instead.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Summaries.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Overview"
                },
                "example": {
                  "accounts": [
                    {
                      "id": "pepperstone-12345678",
                      "summary": {
                        "login": 12345678,
                        "name": "Demo Trader",
                        "server": "Pepperstone-Demo",
                        "company": "Pepperstone Group Limited",
                        "currency": "USD",
                        "leverage": 200,
                        "balance": 10412.58,
                        "credit": 0.0,
                        "profit": 238.11,
                        "equity": 10650.69,
                        "margin": 878.93,
                        "margin_free": 9771.76,
                        "margin_level": 1211.78,
                        "margin_so_call": 100.0,
                        "margin_so_so": 50.0,
                        "trade_allowed": true,
                        "demo": true,
                        "hedging": true,
                        "server_offset": 10800,
                        "positions": 3,
                        "orders": 2
                      }
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/ready": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Accounts"
        ],
        "operationId": "getAccountReady",
        "summary": "Check the account is ready",
        "description": "A bot's pre-flight check before it sends an order: `ready_to_read` and `ready_to_trade`, the `reasons` (a machine `code`, what it `blocks`: read, trade or none, and a plain `message`), and the facts behind them: the link (connected, since, ping, the last frame's age), the login, the server build and whether Termless has been checked against it, the trade side (the broker allows trading, investor login, demo, the real-money switch, whether the caller's key can trade), each watched or asked symbol's last tick age and whether its market is open (from the symbol's quote sessions; a closed market is never stale), and frames that could not be decoded in the last hour. Answered from memory, with no broker round trip, so it is cheap enough to call before every order. A not-ready account is a 200 with the reasons, not an error.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbols",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The symbols you are about to trade, comma-separated, at most 50 (more is 400). Their market must be open for ready_to_trade (an old or missing price is a note, price_stale or no_price, not a block; each one's age is in prices); an unknown one is the reason unknown_symbol.",
            "example": "XAUUSD,EURUSD"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The check.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ready"
                },
                "example": {
                  "account": "pepperstone-12345678",
                  "checked_at": 1792300000123,
                  "ready_to_read": true,
                  "ready_to_trade": true,
                  "reasons": [],
                  "link": {
                    "connected": true,
                    "since": 1792290000,
                    "connected_for_s": 10000,
                    "ping_ms": 12.4,
                    "reconnects": 2,
                    "last_frame_age_ms": 800,
                    "ping_pending_ms": null,
                    "pings_missed": 0,
                    "last_error": null,
                    "retry_at": null
                  },
                  "login": {
                    "logged_in": true,
                    "rejected": false
                  },
                  "server": {
                    "build": 6090,
                    "build_verified": true,
                    "verified_builds": [
                      6090,
                      6182,
                      6230
                    ]
                  },
                  "trading": {
                    "allowed": true,
                    "account_trade_allowed": true,
                    "investor": false,
                    "demo": true,
                    "real_money": "demo",
                    "key_can_trade": true
                  },
                  "prices": [
                    {
                      "symbol": "XAUUSD",
                      "watched": true,
                      "asked": true,
                      "last_tick_age_ms": 812,
                      "market_open": true,
                      "market_source": "sessions",
                      "fresh": true
                    },
                    {
                      "symbol": "EURUSD",
                      "watched": true,
                      "asked": false,
                      "last_tick_age_ms": 240,
                      "market_open": true,
                      "market_source": "sessions",
                      "fresh": true
                    }
                  ],
                  "undecoded_last_hour": 0
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/events": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trails"
        ],
        "operationId": "listAccountEvents",
        "summary": "Get connection history",
        "description": "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.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "before",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Only rows with an id below this: the id of the last row of the previous page."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Most rows to return, at most 1000.",
            "example": 100
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Events, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ConnectionEvent"
                  },
                  "description": "Connection events."
                },
                "example": [
                  {
                    "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
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/equity": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trails"
        ],
        "operationId": "getEquityCurve",
        "summary": "Get the equity curve",
        "description": "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.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "hours",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 24,
              "minimum": 1,
              "maximum": 168
            },
            "description": "How far back, 1 to 168.",
            "example": 24
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The curve.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EquityCurve"
                },
                "example": {
                  "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
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/stats": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Accounts"
        ],
        "operationId": "getStats",
        "summary": "Get account statistics",
        "description": "The trades closed in a range (0.7.0): trades, wins and losses, win rate, profit factor, average win and loss, the largest drawdown of the closed results and the profit of each day (the forex day from 17:00 New York with a clock rule, else the server's date). An answer is kept while the account's trade log has not moved, at most 5 minutes.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Range start, unix seconds, server time."
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Range end; defaults to now."
          },
          {
            "name": "days",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 366
            },
            "description": "Instead of from: this many days before to (1 to 366; default 30).",
            "example": 30
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Stats"
                },
                "example": {
                  "trades": 5,
                  "wins": 3,
                  "losses": 2,
                  "win_rate": 60.0,
                  "profit_factor": 2.02,
                  "avg_win": 29.0,
                  "avg_loss": -21.5,
                  "gross_profit": 87.0,
                  "gross_loss": -43.0,
                  "net": 44.0,
                  "max_drawdown": 32.0,
                  "by_day": [
                    {
                      "day": "2026-11-30",
                      "profit": 16.0,
                      "trades": 2
                    },
                    {
                      "day": "2026-12-01",
                      "profit": 28.0,
                      "trades": 3
                    }
                  ],
                  "from": 1793780000,
                  "to": 1796372000,
                  "currency": "USD"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/symbols": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "listSymbols",
        "summary": "Search symbols",
        "description": "Symbols the broker offers on this account: the exact name first, then names starting with `q`, then the rest (names or descriptions containing it).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Text to match in the name or description. Empty lists every symbol.",
            "example": "xau"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 50,
              "minimum": 1,
              "maximum": 10000
            },
            "description": "Most rows to return, at most 10000.",
            "example": 50
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Symbols.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SymbolBrief"
                  },
                  "description": "Symbols."
                },
                "example": [
                  {
                    "name": "XAUUSD",
                    "description": "Gold vs US Dollar",
                    "path": "Metals\\XAUUSD",
                    "digits": 2
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/symbols/{symbol}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        },
        {
          "name": "symbol",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Symbol name (exact, else matched case-insensitively).",
          "example": "XAUUSD"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getSymbol",
        "summary": "Get a symbol's spec",
        "description": "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.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Symbol spec.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SymbolSpec"
                },
                "example": {
                  "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
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/specs": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getSpecs",
        "summary": "Get many symbol specs",
        "description": "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).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "names",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated symbols, at most 200.",
            "example": "XAUUSD,EURUSD"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Specs, in the order asked.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SpecItem"
                  },
                  "description": "Specs."
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/quotes": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getQuotes",
        "summary": "Get quotes",
        "description": "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.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbols",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated symbols, at most 200. Defaults to the account's watchlist (400 when that is empty too).",
            "example": "XAUUSD,EURUSD"
          },
          {
            "name": "hold",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 3600,
              "default": 600
            },
            "description": "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.",
            "example": 600
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Quotes, in the order asked.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Quote"
                  },
                  "description": "Quotes."
                },
                "example": [
                  {
                    "symbol": "XAUUSD",
                    "bid": 2391.42,
                    "ask": 2391.6,
                    "last": 0,
                    "time": 1790981179,
                    "time_msc": 1790981179473,
                    "tradeable": true
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "delete": {
        "tags": [
          "Market data"
        ],
        "operationId": "releaseQuotes",
        "summary": "Let quotes go",
        "description": "The caller's leases on these symbols end now (0.7.0).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbols",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated symbols.",
            "example": "EURUSD"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "What was let go.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "released": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "The symbols."
                    }
                  },
                  "required": [
                    "released"
                  ]
                },
                "example": {
                  "released": [
                    "EURUSD"
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/candles": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getCandles",
        "summary": "Get candles",
        "description": "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).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Symbol name.",
            "example": "XAUUSD"
          },
          {
            "name": "timeframe",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "M1",
                "M2",
                "M3",
                "M4",
                "M5",
                "M6",
                "M10",
                "M12",
                "M15",
                "M20",
                "M30",
                "H1",
                "H2",
                "H3",
                "H4",
                "H6",
                "H8",
                "H12",
                "D1",
                "W1",
                "MN1"
              ],
              "default": "M5"
            },
            "description": "Bar size. MN works for MN1.",
            "example": "M5"
          },
          {
            "name": "count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 500,
              "minimum": 1,
              "maximum": 50000
            },
            "description": "Latest N bars, 1 to 50000. Ignored when from is given.",
            "example": 500
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0,
              "maximum": 49999
            },
            "description": "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."
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Range start, unix seconds, trade server time."
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Range end (or the end of the count), unix seconds, trade server time. Defaults to now."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Candles.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Candles"
                },
                "example": {
                  "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
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/candles/batch": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "post": {
        "tags": [
          "Market data"
        ],
        "operationId": "getCandlesBatch",
        "summary": "Get candles for many ranges",
        "description": "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).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CandleBatchRequest"
              },
              "example": {
                "items": [
                  {
                    "symbol": "XAUUSD",
                    "timeframe": "M5",
                    "from": 1790894400,
                    "to": 1790980800
                  },
                  {
                    "symbol": "EURUSD",
                    "timeframe": "H1",
                    "from": 1790376000,
                    "to": 1790980800
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "One result per range.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CandleBatch"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/book": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getBook",
        "summary": "Get an order book",
        "description": "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.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Symbol name.",
            "example": "XAUUSD"
          },
          {
            "name": "max_age_ms",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1000,
              "minimum": 100,
              "maximum": 60000
            },
            "description": "The oldest book answered without asking the broker again, in milliseconds, 100 to 60000; outside that is 400."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The book.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                },
                "example": {
                  "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
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "delete": {
        "tags": [
          "Market data"
        ],
        "operationId": "releaseBook",
        "summary": "Release an order book",
        "description": "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).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Symbol name.",
            "example": "XAUUSD"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Released.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "symbol": {
                      "type": "string",
                      "description": "Symbol name, as the broker spells it."
                    },
                    "released": {
                      "type": "boolean",
                      "description": "True when the book was added and is now released."
                    }
                  },
                  "required": [
                    "symbol",
                    "released"
                  ]
                },
                "example": {
                  "symbol": "XAUUSD",
                  "released": true
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/ticks": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Market data"
        ],
        "operationId": "getTicks",
        "summary": "Get recent ticks",
        "description": "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.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Symbol name.",
            "example": "XAUUSD"
          },
          {
            "name": "count",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1000,
              "minimum": 1,
              "maximum": 20000
            },
            "description": "Most ticks to return: the newest when from is not given, else the first ones from from on.",
            "example": 100
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Start, unix seconds, trade server time (copy_ticks_from's date_from)."
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "End, unix seconds, trade server time; ticks within that second are included."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Ticks.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TickHistory"
                },
                "example": {
                  "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
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/stream": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Streaming"
        ],
        "operationId": "streamTicks",
        "summary": "Stream prices and events (SSE)",
        "description": "Server-sent events. `event: status` (a StreamStatus, `{connected, ping_ms}`) arrives first and again whenever the account connects or drops. Each price change arrives as `event: tick` with a Tick as data. A comment line (`: heartbeat`) arrives every 15 s so you can spot a dead connection. `events=` picks what the stream carries: `ticks` (the default), `trades` (`event: trade`, a TradeEvent per broker trade push), `account` (`event: account`, an AccountSnapshot when a value changed, every 500 ms at most), `positions` (`event: positions`, a PositionsSnapshot with live P/L on the same rhythm) and `orders` (`event: orders`, an OrdersSnapshot right after the first status and whenever a trade push changed the pending orders); leave `ticks` out for events only. An unknown name is 400. Trade events are numbered (`seq`, and `id` = `<epoch>:<seq>`). `trade` and `resync` events and the first `status` carry an `id:` line, so EventSource sends the last one back as `Last-Event-ID` when it reconnects; `?after=<id>` does the same by hand. The first status's data has `id` too when the stream follows trades or orders (the client's cursor when it resumes, else the newest id). A resumed stream gets the events after its cursor first, in order, from the last 1,024 kept per account (kept in the database too, so an id from before a restart resumes); when that cannot be done (an id from another epoch: the account was added again or logs in to another broker account; an id from the future; too much happened) it gets `event: resync` (a Resync) instead: read positions, orders and deals again. After a gap (the broker link came back, the server restarted, the account's session started again) the deals the broker made meanwhile come as `trade` events marked `caught_up`, then a resync; a stream that fell 1,024 events behind gets a resync too. The stream ends after a last status with `reason` (`account changed` when the account is deleted or logs in with new details, `server stopping` on shutdown, `key revoked` or `key changed` when its key is deleted or may no longer read the account, `signed out` for a dashboard session); EventSource reconnects by itself. At most 1,024 streams per server and 256 per key (429 with Retry-After past that). Browsers cannot set headers on `EventSource`, so this route also accepts `?key=`. Since 0.7.0 a stream with ticks gets `gap` events (a Gap) when it missed some: it fell behind, the broker link came back, or the fan-out fell behind. `events=bars&bars=EURUSD:M1,XAUUSD:H1` adds bar series (at most 100): `bar` events (a Bar) forming from the bids and closed from the broker's own bars, corrected if the broker changes one within a minute, and `bars_gap` (a BarsGap) when bars cannot be sent.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbols",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated symbols, at most 200. Defaults to the account's watchlist.",
            "example": "XAUUSD,EURUSD"
          },
          {
            "name": "events",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "default": "ticks"
            },
            "description": "Comma-separated event types: ticks, bars, trades, account, positions, orders. Absent means ticks.",
            "example": "ticks,trades,orders"
          },
          {
            "name": "bars",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "With events=bars: comma-separated series, SYMBOL:TF, at most 100 (0.7.0).",
            "example": "XAUUSD:M1,EURUSD:H1"
          },
          {
            "name": "batch_ms",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0,
              "maximum": 100
            },
            "description": "0 writes every broker frame as it arrives. N gathers the ticks of the next N ms after a tick into one write, for clients that prefer fewer, larger reads over the last millisecond."
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+:[0-9]+$"
            },
            "description": "Resume after this trade event id (<epoch>:<seq>, from a trade or resync event or the first status). The events after it come first, from the last 1,024 kept per account, or a resync when that cannot be done. A malformed id is 400."
          },
          {
            "name": "Last-Event-ID",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "What EventSource sends by itself when it reconnects: the id of the last event it saw. Works like after= (which wins when both are sent).",
            "example": "1790968290117:42"
          },
          {
            "name": "key",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "API key, for clients that cannot send headers."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "An open text/event-stream.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                },
                "example": "event: status\nid: 1790968290117:40\ndata: {\"connected\":true,\"ping_ms\":14.2,\"id\":\"1790968290117:40\"}\n\nevent: tick\ndata: {\"symbol\":\"XAUUSD\",\"bid\":2391.42,\"ask\":2391.6,\"last\":0,\"time_msc\":1790981179473}\n\nevent: trade\nid: 1790968290117:43\ndata: {\"seq\":43,\"id\":\"1790968290117:43\",\"what\":\"updated\",\"kind\":\"position\",\"position\":{\"ticket\":51830012,\"symbol\":\"XAUUSD\",\"side\":\"buy\",\"volume\":0.2,\"price_open\":2385.0,\"price_current\":2391.42,\"sl\":2386.0,\"tp\":2420.0,\"profit\":128.4,\"swap\":-1.12,\"commission\":-1.4,\"comment\":\"breakout\",\"magic\":0,\"reason\":\"web\",\"identifier\":51830012,\"time\":1790975498,\"time_msc\":1790975498123,\"time_update\":1790981102,\"open\":true}}\n\n: heartbeat\n\n"
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "queryKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-stream": "sse"
      }
    },
    "/api/v1/accounts/{id}/ws": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Streaming"
        ],
        "operationId": "tickSocket",
        "summary": "Stream prices and events (WebSocket)",
        "description": "A WebSocket of JSON messages told apart by `type` (WsMessage): first `{\"type\": \"status\", \"connected\", \"ping_ms\"}`, then `{\"type\": \"subscribed\", \"symbols\"}`, then `{\"type\": \"tick\", \"symbol\", \"bid\", \"ask\", \"last\", \"time_msc\"}` for each price change, and status again whenever the account connects or drops. With `events=`, `trade`, `resync`, `account`, `positions` and `orders` messages arrive too (orders right after subscribed), with the same `type` field and the shapes of the SSE events. `?after=<id>` resumes the trade events as on SSE: the missed ones come right after subscribed (or a resync), and the first status carries `id`. Send `{\"subscribe\": [\"GBPUSD\"]}` or `{\"unsubscribe\": [...]}` (WsCommand) at any time; the answer is `subscribed` with the whole list or `{\"type\": \"error\", \"message\"}`. The server pings every 15 s. The socket closes after a last status with `reason` (`account changed`, `server stopping`, `key revoked`, `key changed` or `signed out`), like the SSE stream, and counts against the same caps. Accepts `?key=` because browsers cannot set headers on a WebSocket either. Since 0.7.0 a stream with ticks gets `gap` events (a Gap) when it missed some: it fell behind, the broker link came back, or the fan-out fell behind. `events=bars&bars=EURUSD:M1,XAUUSD:H1` adds bar series (at most 100): `bar` events (a Bar) forming from the bids and closed from the broker's own bars, corrected if the broker changes one within a minute, and `bars_gap` (a BarsGap) when bars cannot be sent. On a socket opened with events=bars, `{\"bars\": [...]}` and `{\"unbars\": [...]}` add and remove series; the answer is `{\"type\": \"bars\", \"series\"}`.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbols",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated symbols to start with, at most 200. Defaults to the account's watchlist.",
            "example": "XAUUSD,EURUSD"
          },
          {
            "name": "events",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "default": "ticks"
            },
            "description": "Comma-separated event types: ticks, bars, trades, account, positions, orders. Absent means ticks.",
            "example": "ticks,trades,orders"
          },
          {
            "name": "bars",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "With events=bars: comma-separated series, SYMBOL:TF, at most 100 (0.7.0).",
            "example": "XAUUSD:M1,EURUSD:H1"
          },
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+:[0-9]+$"
            },
            "description": "Resume after this trade event id (<epoch>:<seq>, from a trade or resync event or the first status). The events after it come first, from the last 1,024 kept per account, or a resync when that cannot be done. A malformed id is 400."
          },
          {
            "name": "key",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "API key, for clients that cannot send headers."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "101": {
            "description": "Switching protocols. The socket is open; messages are WsMessage.",
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "queryKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-stream": "websocket"
      }
    },
    "/api/v1/accounts/{id}/trades": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Streaming"
        ],
        "operationId": "listTradeEvents",
        "summary": "Read trade events since an id",
        "description": "The account's numbered trade events, for a client that polls instead of holding a stream open: the same `trade` and `resync` events, `seq` and `id` as on `/stream?events=trades`. `id` in the answer is the newest event's id: send it as `after` next time. `events` are the ones after `after`, oldest first, each with `event` (`trade` or `resync`) beside its fields. `resync` is null, or why the events since `after` cannot be given (an id from another epoch: the account was added again or logs in to another broker account; an id newer than anything sent; more happened than the server keeps): then read positions, orders and deals again and carry on from `id`. The events are kept in the database, so an id from before a restart still resumes; the deals made while the server was stopped or the broker link was down come as trade events marked `caught_up`, before that gap's resync event. Without `after`, the newest `limit` events kept (default 100, at most 1,024; 0.6.3). 503 while the account is turned off.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+:[0-9]+$"
            },
            "description": "The last event id you handled (<epoch>:<seq>). Leave it out for every kept event. A malformed id is 400.",
            "example": "1790968290117:41"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1024
            },
            "description": "Without after: how many of the newest kept events to return (default 100, at most 1,024; 0.6.3).",
            "example": 100
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The events since after.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradesSince"
                },
                "example": {
                  "id": "1790968290117:43",
                  "events": [
                    {
                      "event": "trade",
                      "seq": 42,
                      "id": "1790968290117:42",
                      "what": "opened",
                      "kind": "deal",
                      "deal": {
                        "ticket": 81200118,
                        "order": 51830012,
                        "position_id": 51830012,
                        "symbol": "XAUUSD",
                        "type": "buy",
                        "entry": "in",
                        "volume": 0.2,
                        "price": 2385.0,
                        "profit": 0.0,
                        "commission": -0.7,
                        "swap": 0.0,
                        "fee": 0.0,
                        "magic": 0,
                        "comment": "breakout",
                        "reason": "web",
                        "time": 1790975498,
                        "time_msc": 1790975498123
                      },
                      "balance": 10412.58,
                      "credit": 0.0,
                      "position": {
                        "ticket": 51830012,
                        "symbol": "XAUUSD",
                        "side": "buy",
                        "volume": 0.2,
                        "price_open": 2385.0,
                        "price_current": 2385.0,
                        "sl": 2380.0,
                        "tp": 2420.0,
                        "profit": 0.0,
                        "swap": 0.0,
                        "commission": -0.7,
                        "comment": "breakout",
                        "magic": 0,
                        "reason": "web",
                        "identifier": 51830012,
                        "time": 1790975498,
                        "time_msc": 1790975498123,
                        "time_update": 1790975498,
                        "open": true
                      }
                    },
                    {
                      "event": "trade",
                      "seq": 43,
                      "id": "1790968290117:43",
                      "what": "updated",
                      "kind": "position",
                      "position": {
                        "ticket": 51830012,
                        "symbol": "XAUUSD",
                        "side": "buy",
                        "volume": 0.2,
                        "price_open": 2385.0,
                        "price_current": 2391.42,
                        "sl": 2386.0,
                        "tp": 2420.0,
                        "profit": 128.4,
                        "swap": -1.12,
                        "commission": -1.4,
                        "comment": "breakout",
                        "magic": 0,
                        "reason": "web",
                        "identifier": 51830012,
                        "time": 1790975498,
                        "time_msc": 1790975498123,
                        "time_update": 1790981102,
                        "open": true
                      }
                    }
                  ],
                  "resync": null
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/positions": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "listPositions",
        "summary": "List open positions",
        "description": "Open positions with live profit.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only this symbol (any case).",
            "example": "XAUUSD"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Positions.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Position"
                  },
                  "description": "Positions."
                },
                "example": [
                  {
                    "ticket": 51830012,
                    "symbol": "XAUUSD",
                    "side": "buy",
                    "volume": 0.2,
                    "price_open": 2385.0,
                    "price_current": 2391.42,
                    "sl": 2380.0,
                    "tp": 2420.0,
                    "profit": 128.4,
                    "swap": -1.12,
                    "commission": -1.4,
                    "comment": "breakout",
                    "magic": 0,
                    "reason": "web",
                    "identifier": 51830012,
                    "time": 1790975498,
                    "time_msc": 1790975498123,
                    "time_update": 1790975498
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/orders": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "listOrders",
        "summary": "List pending orders",
        "description": "Pending orders waiting to trigger (limit, stop, stop limit; a market order is never listed, not even in the instant between its placement and its fill). A stream with `events=orders` pushes this list whenever it changes.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only this symbol (any case).",
            "example": "XAUUSD"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Orders.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Order"
                  },
                  "description": "Orders."
                },
                "example": [
                  {
                    "ticket": 51830020,
                    "symbol": "XAUUSD",
                    "type": "buy_limit",
                    "side": "buy",
                    "volume": 0.1,
                    "volume_initial": 0.1,
                    "price": 2365.0,
                    "stop_limit": 0,
                    "sl": 2350.0,
                    "tp": 2410.0,
                    "expiration": 0,
                    "comment": "dip buy",
                    "magic": 0,
                    "reason": "web",
                    "time_setup": 1790977698,
                    "time_setup_msc": 1790977698412
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "post": {
        "tags": [
          "Trading"
        ],
        "operationId": "placeOrder",
        "summary": "Place an order",
        "description": "A market order when there is no `type` field, a pending order when `type` is `limit`, `stop` or `stop_limit`. Answers 200 with the trade result when the broker placed or filled it, and 422 when the broker refused it (the body is the trade result plus `error`, code `rejected`). Send an `Idempotency-Key` header and a retry with the same key and body replays the stored answer (with `Idempotent-Replayed: true`) instead of reaching the broker again; after a 502, 503 or 504 retry with the same key, then check positions and orders (a 503 `busy` or `stopping` was never sent and is not kept, so its retry is sent; a 504 `unconfirmed` whose result came late replays that result). On an account the broker reports as real money this answers 403 `real_account` until an admin sets `trade_real: true`. ",
        "x-scope": "trade",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-~]{1,200}$"
            },
            "description": "A key of your choosing (1 to 200 printable ASCII characters) that makes this request safe to retry. The first request with a key is executed and its whole response kept for 24 hours; a repeat with the same key and body gets that response back with `Idempotent-Replayed: true` and never reaches the broker. The same key with a different body is 409. Two requests in flight with one key: the second waits for the first's result and replays it. An error result (422, 502, 503, 504) is replayed too, so a blind retry cannot double a trade; check positions and orders, then use a new key. The exceptions are 503 `busy` and 503 `stopping`: that request was never sent, so its key is let go and a retry with the same key is sent. A 504 `unconfirmed` trade whose final result comes later (within 120 s, on the same broker link) has its stored answer replaced by that result. The key is reserved in the database before the broker is asked, so a first request that never got an answer (cut by the 30 s bound, the server killed or restarted) is not forgotten: its retry is 409 (check positions and orders, then use a new key), never a second blind send; if the reservation cannot be written the request is 500 and not sent. Scoped to the caller, the method and the path.",
            "example": "order-2026-10-03-0001"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/MarketOrder"
                  },
                  {
                    "$ref": "#/components/schemas/PendingOrder"
                  }
                ]
              },
              "examples": {
                "market": {
                  "summary": "Market buy with SL and TP",
                  "value": {
                    "symbol": "XAUUSD",
                    "side": "buy",
                    "volume": 0.1,
                    "sl": 2380.0,
                    "tp": 2420.0,
                    "comment": "breakout"
                  }
                },
                "pending": {
                  "summary": "Buy limit",
                  "value": {
                    "symbol": "XAUUSD",
                    "side": "buy",
                    "volume": 0.1,
                    "type": "limit",
                    "price": 2365.0,
                    "sl": 2350.0,
                    "tp": 2410.0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done. ok is true.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradeResult"
                },
                "example": {
                  "ok": true,
                  "retcode": 10009,
                  "retcode_text": "Request completed",
                  "deal": 81200131,
                  "order": 51830031,
                  "volume": 0.1,
                  "price": 2391.6,
                  "bid": 2391.42,
                  "ask": 2391.6,
                  "comment": "Request completed",
                  "request_id": 31
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/Idempotent-Replayed"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenTrade"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Rejected"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-idempotent": true
      }
    },
    "/api/v1/accounts/{id}/orders/history": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "listHistoryOrders",
        "summary": "List past orders",
        "description": "Orders that left the book (filled, cancelled, expired, rejected), market orders included, oldest first by when they were placed, each with its `state`, `time_done` and the `position_id` it opened or closed. The place to see a pending order that expired or was cancelled, which leaves no deal behind. Defaults to the last 8 days up to tomorrow (trade server time, on when each order was placed); at most 10 years per request. A page is the newest `limit` orders in the window before the `before` cursor, still oldest first; for the next (older) page send `before` = the first order's `time_setup_msc`. `position`, `ticket` and `symbol` narrow it the way history_orders_get(position=, ticket=) does; they combine. With `position` or `ticket` and no `from`, the window reaches 10 years back instead of 8 days, as the official call searches all history.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Start, unix seconds, trade server time, on when the orders were placed. Defaults to 8 days before to (10 years with position or ticket).",
            "example": 1790376379
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "End, unix seconds, trade server time. Defaults to tomorrow (now + 1 day)."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 5000,
              "minimum": 1,
              "maximum": 5000
            },
            "description": "Page size: the newest N orders in the window (before the cursor), at most 5000."
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Cursor: only orders with time_setup_msc below this. Send the first order's time_setup_msc of the page you have."
          },
          {
            "name": "before_ticket",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "With before: orders in that same millisecond with a smaller ticket come too. Send the first order's ticket, so a page boundary never cuts orders that share a millisecond (0.6.0)."
          },
          {
            "name": "position",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Only the orders that opened or closed this position (their position_id)."
          },
          {
            "name": "ticket",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Only the order with this ticket."
          },
          {
            "name": "symbol",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only this symbol (exact name, any case)."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Orders, oldest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/HistoryOrder"
                  },
                  "description": "Orders that left the book."
                },
                "example": [
                  {
                    "ticket": 51830007,
                    "symbol": "XAUUSD",
                    "type": "sell_stop",
                    "side": "sell",
                    "volume": 0.1,
                    "volume_initial": 0.1,
                    "price": 2371.5,
                    "stop_limit": 0,
                    "sl": 2380.0,
                    "tp": 2350.0,
                    "expiration": 0,
                    "comment": "breakdown",
                    "magic": 0,
                    "reason": "web",
                    "time_setup": 1790962100,
                    "time_setup_msc": 1790962100544,
                    "state": "cancelled",
                    "time_done": 1790970120,
                    "time_done_msc": 1790970120310,
                    "position_id": 0
                  },
                  {
                    "ticket": 51830012,
                    "symbol": "XAUUSD",
                    "type": "buy",
                    "side": "buy",
                    "volume": 0.0,
                    "volume_initial": 0.2,
                    "price": 2385.0,
                    "stop_limit": 0,
                    "sl": 2380.0,
                    "tp": 2420.0,
                    "expiration": 0,
                    "comment": "breakout",
                    "magic": 0,
                    "reason": "web",
                    "time_setup": 1790975498,
                    "time_setup_msc": 1790975497981,
                    "state": "filled",
                    "time_done": 1790975498,
                    "time_done_msc": 1790975498123,
                    "position_id": 51830012
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/orders/{ticket}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        },
        {
          "name": "ticket",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "description": "Pending order ticket.",
          "example": 51830020
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "getOrder",
        "summary": "Get one pending order",
        "description": "One pending order, like orders_get(ticket=). 404 when no pending order has this ticket (a market order is never one; an order that left the book is in GET /orders/history?ticket=).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The order.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                },
                "example": {
                  "ticket": 51830020,
                  "symbol": "XAUUSD",
                  "type": "buy_limit",
                  "side": "buy",
                  "volume": 0.1,
                  "volume_initial": 0.1,
                  "price": 2365.0,
                  "stop_limit": 0,
                  "sl": 2350.0,
                  "tp": 2410.0,
                  "expiration": 0,
                  "comment": "dip buy",
                  "magic": 0,
                  "reason": "web",
                  "time_setup": 1790977698,
                  "time_setup_msc": 1790977698412
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "patch": {
        "tags": [
          "Trading"
        ],
        "operationId": "modifyOrder",
        "summary": "Modify a pending order",
        "description": "Move the price, stop limit, SL, TP or expiry; omitted fields keep their value. Answers 200 with the trade result when the broker placed or filled it, and 422 when the broker refused it (the body is the trade result plus `error`, code `rejected`). Send an `Idempotency-Key` header and a retry with the same key and body replays the stored answer (with `Idempotent-Replayed: true`) instead of reaching the broker again; after a 502, 503 or 504 retry with the same key, then check positions and orders (a 503 `busy` or `stopping` was never sent and is not kept, so its retry is sent; a 504 `unconfirmed` whose result came late replays that result). On an account the broker reports as real money this answers 403 `real_account` until an admin sets `trade_real: true`. 404 when no pending order has this ticket.",
        "x-scope": "trade",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-~]{1,200}$"
            },
            "description": "A key of your choosing (1 to 200 printable ASCII characters) that makes this request safe to retry. The first request with a key is executed and its whole response kept for 24 hours; a repeat with the same key and body gets that response back with `Idempotent-Replayed: true` and never reaches the broker. The same key with a different body is 409. Two requests in flight with one key: the second waits for the first's result and replays it. An error result (422, 502, 503, 504) is replayed too, so a blind retry cannot double a trade; check positions and orders, then use a new key. The exceptions are 503 `busy` and 503 `stopping`: that request was never sent, so its key is let go and a retry with the same key is sent. A 504 `unconfirmed` trade whose final result comes later (within 120 s, on the same broker link) has its stored answer replaced by that result. The key is reserved in the database before the broker is asked, so a first request that never got an answer (cut by the 30 s bound, the server killed or restarted) is not forgotten: its retry is 409 (check positions and orders, then use a new key), never a second blind send; if the reservation cannot be written the request is 500 and not sent. Scoped to the caller, the method and the path.",
            "example": "order-2026-10-03-0001"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderModify"
              },
              "example": {
                "price": 2360.0,
                "sl": 2345.0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradeResult"
                },
                "example": {
                  "ok": true,
                  "retcode": 10009,
                  "retcode_text": "Request completed",
                  "deal": 0,
                  "order": 51830020,
                  "volume": 0.1,
                  "price": 2360.0,
                  "bid": 2391.42,
                  "ask": 2391.6,
                  "comment": "Request completed",
                  "request_id": 31
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/Idempotent-Replayed"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenTrade"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Rejected"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-idempotent": true
      },
      "delete": {
        "tags": [
          "Trading"
        ],
        "operationId": "cancelOrder",
        "summary": "Cancel a pending order",
        "description": "Removes the order at the broker. Answers 200 with the trade result when the broker placed or filled it, and 422 when the broker refused it (the body is the trade result plus `error`, code `rejected`). Send an `Idempotency-Key` header and a retry with the same key and body replays the stored answer (with `Idempotent-Replayed: true`) instead of reaching the broker again; after a 502, 503 or 504 retry with the same key, then check positions and orders (a 503 `busy` or `stopping` was never sent and is not kept, so its retry is sent; a 504 `unconfirmed` whose result came late replays that result). On an account the broker reports as real money this answers 403 `real_account` until an admin sets `trade_real: true`. 404 when no pending order has this ticket.",
        "x-scope": "trade",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-~]{1,200}$"
            },
            "description": "A key of your choosing (1 to 200 printable ASCII characters) that makes this request safe to retry. The first request with a key is executed and its whole response kept for 24 hours; a repeat with the same key and body gets that response back with `Idempotent-Replayed: true` and never reaches the broker. The same key with a different body is 409. Two requests in flight with one key: the second waits for the first's result and replays it. An error result (422, 502, 503, 504) is replayed too, so a blind retry cannot double a trade; check positions and orders, then use a new key. The exceptions are 503 `busy` and 503 `stopping`: that request was never sent, so its key is let go and a retry with the same key is sent. A 504 `unconfirmed` trade whose final result comes later (within 120 s, on the same broker link) has its stored answer replaced by that result. The key is reserved in the database before the broker is asked, so a first request that never got an answer (cut by the 30 s bound, the server killed or restarted) is not forgotten: its retry is 409 (check positions and orders, then use a new key), never a second blind send; if the reservation cannot be written the request is 500 and not sent. Scoped to the caller, the method and the path.",
            "example": "order-2026-10-03-0001"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradeResult"
                },
                "example": {
                  "ok": true,
                  "retcode": 10009,
                  "retcode_text": "Request completed",
                  "deal": 0,
                  "order": 51830020,
                  "volume": 0.1,
                  "price": 0,
                  "bid": 2391.42,
                  "ask": 2391.6,
                  "comment": "Request completed",
                  "request_id": 31
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/Idempotent-Replayed"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenTrade"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Rejected"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-idempotent": true
      }
    },
    "/api/v1/accounts/{id}/positions/{ticket}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        },
        {
          "name": "ticket",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          },
          "description": "Position ticket.",
          "example": 51830012
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "getPosition",
        "summary": "Get one open position",
        "description": "One open position with live profit, like positions_get(ticket=). 404 when no open position has this ticket (a closed one is in GET /deals?position=).",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The position.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Position"
                },
                "example": {
                  "ticket": 51830012,
                  "symbol": "XAUUSD",
                  "side": "buy",
                  "volume": 0.2,
                  "price_open": 2385.0,
                  "price_current": 2391.42,
                  "sl": 2380.0,
                  "tp": 2420.0,
                  "profit": 128.4,
                  "swap": -1.12,
                  "commission": -1.4,
                  "comment": "breakout",
                  "magic": 0,
                  "reason": "web",
                  "identifier": 51830012,
                  "time": 1790975498,
                  "time_msc": 1790975498123,
                  "time_update": 1790975498
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "patch": {
        "tags": [
          "Trading"
        ],
        "operationId": "modifyPosition",
        "summary": "Set SL and TP",
        "description": "Change or remove a position's stop loss and take profit: an omitted one keeps its value, 0 removes it. Answers 200 with the trade result when the broker placed or filled it, and 422 when the broker refused it (the body is the trade result plus `error`, code `rejected`). Send an `Idempotency-Key` header and a retry with the same key and body replays the stored answer (with `Idempotent-Replayed: true`) instead of reaching the broker again; after a 502, 503 or 504 retry with the same key, then check positions and orders (a 503 `busy` or `stopping` was never sent and is not kept, so its retry is sent; a 504 `unconfirmed` whose result came late replays that result). On an account the broker reports as real money this answers 403 `real_account` until an admin sets `trade_real: true`. 404 when no open position has this ticket.",
        "x-scope": "trade",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-~]{1,200}$"
            },
            "description": "A key of your choosing (1 to 200 printable ASCII characters) that makes this request safe to retry. The first request with a key is executed and its whole response kept for 24 hours; a repeat with the same key and body gets that response back with `Idempotent-Replayed: true` and never reaches the broker. The same key with a different body is 409. Two requests in flight with one key: the second waits for the first's result and replays it. An error result (422, 502, 503, 504) is replayed too, so a blind retry cannot double a trade; check positions and orders, then use a new key. The exceptions are 503 `busy` and 503 `stopping`: that request was never sent, so its key is let go and a retry with the same key is sent. A 504 `unconfirmed` trade whose final result comes later (within 120 s, on the same broker link) has its stored answer replaced by that result. The key is reserved in the database before the broker is asked, so a first request that never got an answer (cut by the 30 s bound, the server killed or restarted) is not forgotten: its retry is 409 (check positions and orders, then use a new key), never a second blind send; if the reservation cannot be written the request is 500 and not sent. Scoped to the caller, the method and the path.",
            "example": "order-2026-10-03-0001"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PositionModify"
              },
              "example": {
                "sl": 2386.0,
                "tp": 2425.0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradeResult"
                },
                "example": {
                  "ok": true,
                  "retcode": 10009,
                  "retcode_text": "Request completed",
                  "deal": 0,
                  "order": 51830012,
                  "volume": 0.1,
                  "price": 0,
                  "bid": 2391.42,
                  "ask": 2391.6,
                  "comment": "Request completed",
                  "request_id": 31
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/Idempotent-Replayed"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenTrade"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Rejected"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-idempotent": true
      },
      "delete": {
        "tags": [
          "Trading"
        ],
        "operationId": "closePosition",
        "summary": "Close a position",
        "description": "Closes the whole position at market, or part of it with `?volume=`. Answers 200 with the trade result when the broker placed or filled it, and 422 when the broker refused it (the body is the trade result plus `error`, code `rejected`). Send an `Idempotency-Key` header and a retry with the same key and body replays the stored answer (with `Idempotent-Replayed: true`) instead of reaching the broker again; after a 502, 503 or 504 retry with the same key, then check positions and orders (a 503 `busy` or `stopping` was never sent and is not kept, so its retry is sent; a 504 `unconfirmed` whose result came late replays that result). On an account the broker reports as real money this answers 403 `real_account` until an admin sets `trade_real: true`. 404 when no open position has this ticket.",
        "x-scope": "trade",
        "parameters": [
          {
            "name": "volume",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Lots to close. Omit to close all of it; more than the position is 400.",
            "example": 0.1
          },
          {
            "name": "deviation",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 0
            },
            "description": "Largest slippage you accept, in points."
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-~]{1,200}$"
            },
            "description": "A key of your choosing (1 to 200 printable ASCII characters) that makes this request safe to retry. The first request with a key is executed and its whole response kept for 24 hours; a repeat with the same key and body gets that response back with `Idempotent-Replayed: true` and never reaches the broker. The same key with a different body is 409. Two requests in flight with one key: the second waits for the first's result and replays it. An error result (422, 502, 503, 504) is replayed too, so a blind retry cannot double a trade; check positions and orders, then use a new key. The exceptions are 503 `busy` and 503 `stopping`: that request was never sent, so its key is let go and a retry with the same key is sent. A 504 `unconfirmed` trade whose final result comes later (within 120 s, on the same broker link) has its stored answer replaced by that result. The key is reserved in the database before the broker is asked, so a first request that never got an answer (cut by the 30 s bound, the server killed or restarted) is not forgotten: its retry is 409 (check positions and orders, then use a new key), never a second blind send; if the reservation cannot be written the request is 500 and not sent. Scoped to the caller, the method and the path.",
            "example": "order-2026-10-03-0001"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradeResult"
                },
                "example": {
                  "ok": true,
                  "retcode": 10009,
                  "retcode_text": "Request completed",
                  "deal": 81200140,
                  "order": 51830044,
                  "volume": 0.2,
                  "price": 2391.42,
                  "bid": 2391.42,
                  "ask": 2391.6,
                  "comment": "Request completed",
                  "request_id": 31
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/Idempotent-Replayed"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenTrade"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Rejected"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-idempotent": true
      }
    },
    "/api/v1/accounts/{id}/deals": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "listDeals",
        "summary": "List deals",
        "description": "Deal history: fills, closes and balance operations, oldest first. Defaults to the last 8 days up to tomorrow (trade server time); at most 10 years per request. A page is the newest `limit` deals in the window before the `before` cursor, still oldest first; for the next (older) page send `before` = the first deal's `time_msc`. `position`, `ticket` and `symbol` narrow it the way history_deals_get(position=, ticket=) does: `ticket` is the order that made the deals (their `order`, DEAL_ORDER). They combine. With `position` or `ticket` and no `from`, the window reaches 10 years back instead of 8 days, as the official call searches all history.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Start, unix seconds, trade server time. Defaults to 8 days before to (10 years with position or ticket).",
            "example": 1790376379
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "End, unix seconds, trade server time. Defaults to tomorrow (now + 1 day)."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 5000,
              "minimum": 1,
              "maximum": 5000
            },
            "description": "Page size: the newest N deals in the window (before the cursor), at most 5000."
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Cursor: only deals with time_msc below this. Send the first deal's time_msc of the page you have."
          },
          {
            "name": "before_ticket",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "With before: deals in that same millisecond with a smaller ticket come too. Send the first deal's ticket, so a page boundary never cuts deals that share a millisecond (0.6.0)."
          },
          {
            "name": "position",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Only the deals of this position (their position_id), like history_deals_get(position=)."
          },
          {
            "name": "ticket",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Only the deals this order made (their order field), like history_deals_get(ticket=)."
          },
          {
            "name": "symbol",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Only this symbol (exact name, any case)."
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Deals.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Deal"
                  },
                  "description": "Deals, oldest first."
                },
                "example": [
                  {
                    "ticket": 81200118,
                    "order": 51830012,
                    "position_id": 51830012,
                    "symbol": "XAUUSD",
                    "type": "buy",
                    "entry": "in",
                    "volume": 0.2,
                    "price": 2385.0,
                    "profit": 0.0,
                    "commission": -0.7,
                    "swap": 0.0,
                    "fee": 0.0,
                    "magic": 0,
                    "comment": "breakout",
                    "reason": "web",
                    "time": 1790975498,
                    "time_msc": 1790975498123
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/calc": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "get": {
        "tags": [
          "Trading"
        ],
        "operationId": "calcMarginProfit",
        "summary": "Work out margin and profit",
        "description": "order_calc_margin and order_calc_profit in one call, in the account currency: the margin `volume` lots need once the trade is open at `price` (default the current ask for a buy, bid for a sell), and with `close` the profit from `price` to `close`. For a pending `type`, `margin` is what the position needs when the order fills (the market rate of its side) and `margin_pending` what the broker holds while it waits (the pending type's own rate: 0 at the brokers seen, so nothing); `margin_pending` is null for a market order. Worked out the way the terminal does it, from the symbol's spec, the account's leverage and the live prices of the symbols that convert currencies. A margin (or `profit`) is null when no symbol converts its currency to the account's. All are rounded to the account currency's digits. No order is sent.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Symbol name.",
            "example": "XAUUSD"
          },
          {
            "name": "side",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "buy",
                "sell"
              ]
            },
            "description": "Direction.",
            "example": "buy"
          },
          {
            "name": "volume",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Lots, more than 0.",
            "example": 0.1
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "market",
                "limit",
                "stop",
                "stop_limit"
              ],
              "default": "market"
            },
            "description": "Order type. For a pending type the answer also says what the order holds while it waits (margin_pending)."
          },
          {
            "name": "price",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Open price. Omit (or 0) for the current ask for a buy, bid for a sell.",
            "example": 2391.6
          },
          {
            "name": "close",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Closing price: also work out the profit from price to close. More than 0.",
            "example": 2400.0
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Margin and profit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Calc"
                },
                "example": {
                  "symbol": "XAUUSD",
                  "side": "buy",
                  "type": "buy",
                  "volume": 0.1,
                  "price": 2391.6,
                  "margin": 119.58,
                  "margin_pending": null,
                  "close": 2400.0,
                  "profit": 84.0,
                  "currency": "USD"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/order_check": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "post": {
        "tags": [
          "Trading"
        ],
        "operationId": "checkOrder",
        "summary": "Check an order without sending it",
        "description": "order_check: takes the same request as order_send and answers what sending it would do, without sending it. A read key is enough; nothing is audited and no Idempotency-Key is needed. For a deal or pending order that opens something (`position` 0) it checks, in order: the volume against the symbol's volume_min, volume_max and volume_step (10014); the symbol's trade mode (10017 disabled, 10044 close only, 10042 a sell on a long_only symbol, 10043 a buy on a short_only one); today's trade sessions by the server's clock (10018; skipped when the broker sent none); a pending order's price against the live quote (10015: a buy limit must sit below the ask, a buy stop above it, a sell limit above the bid, a sell stop below it, each at least `stops_level` points away; a stop limit's limit price below its stop price for a buy and above it for a sell; a pending order without a price); its stop-loss and take-profit (10016: on the losing and winning side of the price they are measured from, at least `stops_level` points away; a deal's from the price that would close it, the bid for a buy and the ask for a sell, a pending order's from its own price, a stop limit's from its limit price); then the margin the order needs at `price` (the current price when 0) against the free margin (10019; a pending order needs only what it holds while it waits, usually nothing). `TRADE_ACTION_SLTP` and `TRADE_ACTION_MODIFY` are checked against the market too (10016, and 10015 for an order's new price) when the position or order is open on the account. The first failing check sets `retcode` and `comment`; 0 and Done when all pass. Other actions, and a deal that closes a position, never get 10019: `request_margin` is 0 and the answer is the account as it is. The freeze level is not checked, and an opening order counts its whole margin even when an opposite position would hedge or net it. Always 200 when the request could be read; 400 when it cannot, or when no symbol converts the margin currency to the account's.",
        "x-scope": "read",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderSendRequest"
              },
              "example": {
                "action": "TRADE_ACTION_DEAL",
                "symbol": "XAUUSD",
                "volume": 0.1,
                "type": "ORDER_TYPE_BUY"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The check.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderCheck"
                },
                "example": {
                  "ok": true,
                  "retcode": 0,
                  "comment": "Done",
                  "balance": 10412.58,
                  "equity": 10650.69,
                  "profit": 238.11,
                  "margin": 998.51,
                  "margin_free": 9652.18,
                  "margin_level": 1066.66,
                  "request_margin": 119.58
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/accounts/{id}/order_send": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Account id.",
          "example": "pepperstone-12345678"
        }
      ],
      "post": {
        "tags": [
          "Trading"
        ],
        "operationId": "orderSend",
        "summary": "Send a raw MetaTrader request",
        "description": "Takes the same request dict as order_send() in the official MetaTrader5 Python package, so existing scripts port over unchanged. Enum fields take the numbers or the official names (`\"TRADE_ACTION_DEAL\"`, `\"ORDER_TYPE_SELL\"`, `\"ORDER_FILLING_IOC\"`). Any other field is 400 naming it, and TRADE_ACTION_SLTP without `position` works only when one position is open on the symbol. Answers 200 with the trade result when the broker placed or filled it, and 422 when the broker refused it (the body is the trade result plus `error`, code `rejected`). Send an `Idempotency-Key` header and a retry with the same key and body replays the stored answer (with `Idempotent-Replayed: true`) instead of reaching the broker again; after a 502, 503 or 504 retry with the same key, then check positions and orders (a 503 `busy` or `stopping` was never sent and is not kept, so its retry is sent; a 504 `unconfirmed` whose result came late replays that result). On an account the broker reports as real money this answers 403 `real_account` until an admin sets `trade_real: true`. Prefer the routes above for new code.",
        "x-scope": "trade",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200,
              "pattern": "^[!-~]{1,200}$"
            },
            "description": "A key of your choosing (1 to 200 printable ASCII characters) that makes this request safe to retry. The first request with a key is executed and its whole response kept for 24 hours; a repeat with the same key and body gets that response back with `Idempotent-Replayed: true` and never reaches the broker. The same key with a different body is 409. Two requests in flight with one key: the second waits for the first's result and replays it. An error result (422, 502, 503, 504) is replayed too, so a blind retry cannot double a trade; check positions and orders, then use a new key. The exceptions are 503 `busy` and 503 `stopping`: that request was never sent, so its key is let go and a retry with the same key is sent. A 504 `unconfirmed` trade whose final result comes later (within 120 s, on the same broker link) has its stored answer replaced by that result. The key is reserved in the database before the broker is asked, so a first request that never got an answer (cut by the 30 s bound, the server killed or restarted) is not forgotten: its retry is 409 (check positions and orders, then use a new key), never a second blind send; if the reservation cannot be written the request is 500 and not sent. Scoped to the caller, the method and the path.",
            "example": "order-2026-10-03-0001"
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderSendRequest"
              },
              "example": {
                "action": "TRADE_ACTION_DEAL",
                "symbol": "XAUUSD",
                "volume": 0.1,
                "type": "ORDER_TYPE_BUY",
                "price": 2391.6,
                "sl": 2380.0,
                "tp": 2420.0,
                "deviation": 20,
                "type_filling": "ORDER_FILLING_IOC",
                "type_time": 0,
                "comment": "from mt5 script",
                "magic": 7
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Done.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TradeResult"
                },
                "example": {
                  "ok": true,
                  "retcode": 10009,
                  "retcode_text": "Request completed",
                  "deal": 81200131,
                  "order": 51830031,
                  "volume": 0.1,
                  "price": 2391.6,
                  "bid": 2391.42,
                  "ask": 2391.6,
                  "comment": "Request completed",
                  "request_id": 31
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              },
              "Idempotent-Replayed": {
                "$ref": "#/components/headers/Idempotent-Replayed"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenTrade"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/Rejected"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "502": {
            "$ref": "#/components/responses/BrokerError"
          },
          "503": {
            "$ref": "#/components/responses/Disconnected"
          },
          "504": {
            "$ref": "#/components/responses/Timeout"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ],
        "x-idempotent": true
      }
    },
    "/api/v1/keys": {
      "get": {
        "tags": [
          "API keys"
        ],
        "operationId": "listKeys",
        "summary": "List keys",
        "description": "Every key, newest first. The full key is never shown again; `prefix` helps you tell them apart.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Keys.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ApiKey"
                  },
                  "description": "Keys."
                },
                "example": [
                  {
                    "id": "key_3f9a1c07",
                    "name": "EA bridge (gold)",
                    "prefix": "tl_4be1a09c7",
                    "scopes": [
                      "trade"
                    ],
                    "accounts": [
                      "pepperstone-12345678"
                    ],
                    "created_at": 1790709498,
                    "last_used_at": 1790974298,
                    "max_volume": 0.5,
                    "max_open_per_min": 10,
                    "max_daily_loss": 500.0,
                    "max_drawdown_pct": null,
                    "limits_since": null
                  }
                ]
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "post": {
        "tags": [
          "API keys"
        ],
        "operationId": "createKey",
        "summary": "Create a key",
        "description": "Pick one scope: `read` (prices and account state), `trade` (read plus orders) or `admin` (everything, including accounts, keys, servers and diagnostics). Limit a read or trade key to some accounts with `accounts`; an admin key cannot be limited (400). Keys look like `tl_` and 48 hex characters; only a SHA-256 hash is stored, so the response is the only time the full `key` appears.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ApiKeyCreate"
              },
              "example": {
                "name": "EA bridge (gold)",
                "scopes": [
                  "trade"
                ],
                "accounts": [
                  "pepperstone-12345678"
                ],
                "max_volume": 0.5,
                "max_open_per_min": 10
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created. Store key now.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyCreated"
                },
                "example": {
                  "id": "key_3f9a1c07",
                  "name": "EA bridge (gold)",
                  "prefix": "tl_4be1a09c7",
                  "scopes": [
                    "trade"
                  ],
                  "accounts": [
                    "pepperstone-12345678"
                  ],
                  "created_at": 1790981179,
                  "last_used_at": null,
                  "max_volume": 0.5,
                  "max_open_per_min": 10,
                  "max_daily_loss": 500.0,
                  "max_drawdown_pct": null,
                  "limits_since": null,
                  "key": "tl_4be1a09c7d2e5f8b1a3c6e9d0f2b4a7c8e1d3f5a7b9c0e2d"
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/keys/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Key id.",
          "example": "key_3f9a1c07"
        }
      ],
      "patch": {
        "tags": [
          "API keys"
        ],
        "operationId": "updateKey",
        "summary": "Edit a key",
        "description": "Change a key's name, scope or accounts in place (0.6.0). The key itself and its id stay the same, so nothing that holds it has to change. Every request sees the change at once; a stored Idempotency-Key answer is not replayed to a key that may no longer trade on its account (403); a stream it opened on an account it may no longer read ends with reason key changed. Audited (kind key, route update).",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ApiKeyUpdate"
              },
              "example": {
                "scopes": [
                  "trade"
                ],
                "accounts": [
                  "pepperstone-12345678"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The key as listed (the secret is never shown again).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKey"
                },
                "example": {
                  "id": "key_3f9a1c07",
                  "name": "EA bridge (gold)",
                  "prefix": "tl_4be1a09c7",
                  "scopes": [
                    "trade"
                  ],
                  "accounts": [
                    "pepperstone-12345678"
                  ],
                  "created_at": 1790709498,
                  "last_used_at": 1790974298,
                  "max_volume": 0.5,
                  "max_open_per_min": 10,
                  "max_daily_loss": 500.0,
                  "max_drawdown_pct": null,
                  "limits_since": null
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      },
      "delete": {
        "tags": [
          "API keys"
        ],
        "operationId": "revokeKey",
        "summary": "Revoke a key",
        "description": "The key stops working at once, its traffic in the connections view is dropped, and the streams it opened end (reason key revoked).",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked.",
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/keys/{id}/traffic": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Key id.",
          "example": "key_3f9a1c07"
        }
      ],
      "get": {
        "tags": [
          "Trails"
        ],
        "operationId": "getKeyTraffic",
        "summary": "See a key's traffic",
        "description": "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.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 500
            },
            "description": "Most requests to return, at most 500.",
            "example": 100
          },
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "The key's traffic.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KeyTrafficLog"
                },
                "example": {
                  "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
                    }
                  ]
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    },
    "/api/v1/connections": {
      "get": {
        "tags": [
          "Trails"
        ],
        "operationId": "listConnections",
        "summary": "See who is connected",
        "description": "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.",
        "x-scope": "admin",
        "parameters": [
          {
            "name": "X-Request-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,64}$"
            },
            "description": "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.",
            "example": "bot-20261003-0042"
          }
        ],
        "responses": {
          "200": {
            "description": "Connections.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Connections"
                },
                "example": {
                  "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
                  }
                }
              }
            },
            "headers": {
              "X-Request-Id": {
                "$ref": "#/components/headers/X-Request-Id"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "security": [
          {
            "bearerKey": []
          },
          {
            "sessionCookie": []
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code. Matches the HTTP status.",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "real_account",
                  "not_found",
                  "method_not_allowed",
                  "conflict",
                  "rejected",
                  "too_many_requests",
                  "internal",
                  "broker_error",
                  "disconnected",
                  "busy",
                  "stopping",
                  "timeout",
                  "unconfirmed",
                  "trading_paused",
                  "key_limit",
                  "untrusted_certificate",
                  "certificate_changed",
                  "browser_only"
                ]
              },
              "message": {
                "type": "string",
                "description": "What went wrong, in a sentence a person can read."
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ],
        "description": "Every error response has this shape.",
        "examples": [
          {
            "error": {
              "code": "not_found",
              "message": "no account with id pepperstone-live"
            }
          }
        ]
      },
      "Ok": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true,
            "description": "Always true."
          }
        },
        "required": [
          "ok"
        ],
        "examples": [
          {
            "ok": true
          }
        ]
      },
      "Health": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "ok when every enabled account is connected, degraded when an enabled account is not, setup before the admin password exists.",
            "enum": [
              "ok",
              "degraded",
              "setup"
            ]
          },
          "version": {
            "type": [
              "string",
              "null"
            ],
            "description": "Server version, for a signed-in caller or a valid key; null for anyone else (the exact version tells an attacker which fixes are missing)."
          },
          "uptime_s": {
            "type": "integer",
            "description": "Seconds since the server started."
          },
          "accounts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Account id."
                },
                "label": {
                  "type": "string",
                  "description": "Display name."
                },
                "enabled": {
                  "type": "boolean",
                  "description": "False for an account that is turned off."
                },
                "connected": {
                  "type": "boolean",
                  "description": "Whether the session to the broker is up."
                },
                "ping_ms": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "Last heartbeat round trip in milliseconds."
                },
                "reconnects": {
                  "type": "integer",
                  "description": "Reconnects since the server started."
                }
              },
              "required": [
                "id",
                "label",
                "enabled",
                "connected",
                "ping_ms",
                "reconnects"
              ]
            },
            "description": "Empty unless the caller is signed in or sends a valid key; then the accounts it may see."
          }
        },
        "required": [
          "status",
          "version",
          "uptime_s",
          "accounts"
        ],
        "examples": [
          {
            "status": "ok",
            "version": "0.6.2",
            "uptime_s": 86412,
            "accounts": [
              {
                "id": "pepperstone-12345678",
                "label": "Pepperstone demo",
                "enabled": true,
                "connected": true,
                "ping_ms": 14.2,
                "reconnects": 0
              }
            ]
          },
          {
            "status": "ok",
            "version": null,
            "uptime_s": 86412,
            "accounts": []
          }
        ]
      },
      "SetupState": {
        "type": "object",
        "properties": {
          "needs_setup": {
            "type": "boolean",
            "description": "True until the admin password has been set."
          }
        },
        "required": [
          "needs_setup"
        ],
        "examples": [
          {
            "needs_setup": true
          }
        ]
      },
      "SetupRequest": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "description": "The one-time setup token from the server log or <data>/setup-token."
          },
          "password": {
            "type": "string",
            "description": "The new admin password: 15 to 200 characters with a lowercase letter, a capital, a digit and a symbol (anything but a letter or a digit counts as a symbol).",
            "minLength": 15,
            "maxLength": 200
          }
        },
        "required": [
          "token",
          "password"
        ],
        "examples": [
          {
            "token": "4f1c9e0b7a2d5e8c3b6a9d0e",
            "password": "A long passphrase, 2 commas"
          }
        ]
      },
      "SessionRequest": {
        "type": "object",
        "properties": {
          "password": {
            "type": "string",
            "description": "The admin password."
          }
        },
        "required": [
          "password"
        ],
        "examples": [
          {
            "password": "a long passphrase"
          }
        ]
      },
      "PasswordChange": {
        "type": "object",
        "properties": {
          "current": {
            "type": "string",
            "description": "The admin password in use now. A wrong one is 400, not 401, so the dashboard stays signed in."
          },
          "new": {
            "type": "string",
            "description": "The new admin password: 15 to 200 characters with a lowercase letter, a capital, a digit and a symbol (anything but a letter or a digit counts as a symbol).",
            "minLength": 15,
            "maxLength": 200
          }
        },
        "required": [
          "current",
          "new"
        ],
        "examples": [
          {
            "current": "A long passphrase, 2 commas",
            "new": "An even longer passphrase, 3 commas"
          }
        ]
      },
      "Me": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "description": "admin for the dashboard session, key for an API key.",
            "enum": [
              "admin",
              "key"
            ]
          },
          "name": {
            "type": "string",
            "description": "admin, or the key's name."
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "description": "Scope.",
              "enum": [
                "read",
                "trade",
                "admin"
              ]
            },
            "description": "What this caller may do."
          },
          "accounts": {
            "type": [
              "array",
              "null"
            ],
            "description": "Account ids this caller may use. null means every account.",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "kind",
          "name",
          "scopes",
          "accounts"
        ],
        "examples": [
          {
            "kind": "key",
            "name": "EA bridge (gold)",
            "scopes": [
              "trade"
            ],
            "accounts": [
              "pepperstone-12345678"
            ]
          }
        ]
      },
      "Diagnostics": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string",
            "description": "Server version."
          },
          "target": {
            "type": "string",
            "description": "The platform the binary was built for, for example x86_64-unknown-linux-gnu."
          },
          "pid": {
            "type": "integer",
            "description": "Process id."
          },
          "started_at": {
            "type": "integer",
            "description": "When the server started, unix seconds (UTC)."
          },
          "uptime_s": {
            "type": "integer",
            "description": "Seconds since the server started."
          },
          "process": {
            "type": "object",
            "properties": {
              "rss_kb": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Resident memory in KB."
              },
              "rss_peak_kb": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The most resident memory since the start, in KB (VmHWM)."
              },
              "threads": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Threads."
              },
              "open_files": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Open file descriptors."
              }
            },
            "required": [
              "rss_kb",
              "rss_peak_kb",
              "threads",
              "open_files"
            ],
            "description": "Read from /proc; every field is null off Linux."
          },
          "data_dir": {
            "type": "string",
            "description": "The data folder."
          },
          "log_file": {
            "type": [
              "string",
              "null"
            ],
            "description": "The current log file, null before the first one is written."
          },
          "db_bytes": {
            "type": "integer",
            "description": "Size of the database (with its write-ahead log) in bytes."
          },
          "dashboard_sessions": {
            "type": "integer",
            "description": "Dashboard sign-ins that have not expired."
          },
          "streams": {
            "type": "object",
            "properties": {
              "sse": {
                "type": "integer",
                "description": "Open SSE streams."
              },
              "ws": {
                "type": "integer",
                "description": "Open WebSockets."
              },
              "max": {
                "type": "integer",
                "description": "Cap on open streams in total."
              },
              "max_per_key": {
                "type": "integer",
                "description": "Cap on open streams per key or dashboard session."
              }
            },
            "required": [
              "sse",
              "ws"
            ],
            "description": "Open price streams and their caps."
          },
          "accounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DiagnosticsAccount"
            },
            "description": "Every account, with its connection status."
          },
          "undecoded": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer",
                "description": "Frames the client could not decode since the server started."
              },
              "file": {
                "type": "string",
                "description": "Where kept frames are appended: <data>/captures/undecoded.jsonl."
              },
              "by_command": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/UndecodedCount"
                },
                "description": "One counter per (account, command, kind), most recent first."
              },
              "recent": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer",
                      "description": "Frame number since the server started."
                    },
                    "time": {
                      "type": "integer",
                      "description": "When it arrived, unix seconds (UTC)."
                    },
                    "account": {
                      "type": "string",
                      "description": "Account id."
                    },
                    "kind": {
                      "type": "string",
                      "description": "frame: the outer frame or its encryption did not check out. body: a known command whose body did not parse. unknown_push: a push with a command id the client does not handle. extra (0.6.0): a reply read in full with bytes after the records the layout knows; kept for diagnosis, never counted as undecoded.",
                      "enum": [
                        "frame",
                        "body",
                        "unknown_push",
                        "extra"
                      ]
                    },
                    "command": {
                      "type": "integer",
                      "description": "Protocol command id."
                    },
                    "code": {
                      "type": "integer",
                      "description": "The frame's result code."
                    },
                    "context": {
                      "type": "string",
                      "description": "Where it happened, for example tick push or account reply."
                    },
                    "error": {
                      "type": "string",
                      "description": "What the decoder said."
                    },
                    "server_build": {
                      "type": "integer",
                      "description": "The broker's MT5 build at the time."
                    },
                    "len": {
                      "type": "integer",
                      "description": "Body length in bytes."
                    }
                  },
                  "required": [
                    "id",
                    "time",
                    "account",
                    "kind",
                    "command",
                    "code",
                    "context",
                    "error",
                    "server_build",
                    "len"
                  ]
                },
                "description": "The last 20 kept frames, newest first, without their bytes (GET /api/v1/diagnostics/undecoded has them). Frames kept before a restart are among them: the newest are read back from the file at start."
              }
            },
            "required": [
              "total",
              "file",
              "by_command",
              "recent"
            ],
            "description": "Frames the client could not decode."
          },
          "problems": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LogLine"
            },
            "description": "The last 100 warnings and errors from the log, newest first."
          },
          "crashes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CrashReport"
            },
            "description": "Crash reports in <data>/crashes, newest first."
          },
          "unclean_exit_report": {
            "type": [
              "string",
              "null"
            ],
            "description": "null, or the file name (such as unclean-exit-2026-10-03T00-12-07Z.txt) of the report written at this start because the previous run did not shut down cleanly (its pid file was still there). Read it with GET /api/v1/diagnostics/crashes/{name}. It stays set for the whole run."
          }
        },
        "required": [
          "version",
          "target",
          "pid",
          "started_at",
          "uptime_s",
          "process",
          "data_dir",
          "log_file",
          "db_bytes",
          "dashboard_sessions",
          "streams",
          "accounts",
          "undecoded",
          "problems",
          "crashes",
          "unclean_exit_report"
        ],
        "description": "What the server itself is doing.",
        "examples": [
          {
            "version": "0.1.0",
            "target": "x86_64-unknown-linux-gnu",
            "pid": 41822,
            "started_at": 1790894779,
            "uptime_s": 75600,
            "process": {
              "rss_kb": 23140,
              "rss_peak_kb": 31200,
              "threads": 9,
              "open_files": 21
            },
            "data_dir": "/var/lib/termless",
            "log_file": "/var/lib/termless/logs/termlessd.2026-10-03.log",
            "db_bytes": 135168,
            "dashboard_sessions": 1,
            "streams": {
              "sse": 1,
              "ws": 0,
              "max": 1024,
              "max_per_key": 256
            },
            "accounts": [
              {
                "connected": true,
                "since": 1790968298,
                "reconnects": 0,
                "ping_ms": 14.2,
                "server_build": 6090,
                "last_error": null,
                "subscribed": 2,
                "login_rejected": false,
                "retry_at": null,
                "id": "pepperstone-12345678",
                "enabled": true,
                "session_running": true,
                "ticks_seen": 1840211,
                "last_tick_at_ms": 1790970379473,
                "last_frame_at_ms": 1790970381002,
                "streams": 1,
                "ticks_coalesced": 0,
                "undecoded": 3
              }
            ],
            "undecoded": {
              "total": 3,
              "file": "/var/lib/termless/captures/undecoded.jsonl",
              "by_command": [
                {
                  "account": "pepperstone-12345678",
                  "command": 8,
                  "kind": "body",
                  "context": "tick push",
                  "count": 3,
                  "first_at": 1790964410,
                  "last_at": 1790965012,
                  "last_error": "short read at offset 40"
                }
              ],
              "recent": [
                {
                  "id": 3,
                  "time": 1790965012,
                  "account": "pepperstone-12345678",
                  "kind": "body",
                  "command": 8,
                  "code": 0,
                  "context": "tick push",
                  "error": "short read at offset 40",
                  "server_build": 6090,
                  "len": 52
                }
              ]
            },
            "problems": [
              {
                "time": 1790968290,
                "level": "warn",
                "target": "termless::session",
                "message": "[pepperstone-12345678] connection lost, reconnecting"
              }
            ],
            "crashes": [
              {
                "name": "20261002T231405Z-panic.txt",
                "time": 1790896445,
                "size": 6120,
                "summary": "index out of bounds: the len is 3 but the index is 3"
              }
            ],
            "unclean_exit_report": null
          }
        ]
      },
      "DiagnosticsAccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Account id."
          },
          "enabled": {
            "type": "boolean",
            "description": "False for an account that is turned off."
          },
          "connected": {
            "type": "boolean",
            "description": "Whether the session to the broker is up right now."
          },
          "since": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds (UTC) when the current connection came up. null while disconnected."
          },
          "reconnects": {
            "type": "integer",
            "description": "Automatic reconnects since the server started."
          },
          "ping_ms": {
            "type": [
              "number",
              "null"
            ],
            "description": "Last heartbeat round trip in milliseconds. null before the first one."
          },
          "server_build": {
            "type": [
              "integer",
              "null"
            ],
            "description": "MT5 build the broker's server reported. null before the first login."
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ],
            "description": "Why the last connection attempt failed or the connection dropped. null while connected."
          },
          "subscribed": {
            "type": "integer",
            "description": "Number of symbols with a live price subscription."
          },
          "login_rejected": {
            "type": "boolean",
            "description": "True after the broker refused the login. A refusal within an hour of losing a working connection (a broker restarting refuses logins with code 2 for seconds to minutes) is tried again after 10, 20, 30 and 60 s, then every minute for code 2 until an hour after the loss (0.6.3), then every 5 minutes; any other refusal only every 5 minutes, so a wrong password cannot get the account locked."
          },
          "retry_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds (UTC) of the next connection attempt while disconnected, else null."
          },
          "session_running": {
            "type": "boolean",
            "description": "Whether the account's connection loop is running."
          },
          "ticks_seen": {
            "type": "integer",
            "description": "Price ticks received since the session started."
          },
          "last_tick_at_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When the last tick arrived, unix milliseconds (UTC). null before the first."
          },
          "last_frame_at_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When the last frame of any kind (pings included) arrived from the broker, unix milliseconds (UTC). A connected account with an old value is about to be declared dead."
          },
          "streams": {
            "type": "integer",
            "description": "Open streams (SSE and WebSocket) on this account."
          },
          "ticks_coalesced": {
            "type": "integer",
            "description": "Ticks dropped for slow stream readers (they got the latest tick per symbol instead)."
          },
          "undecoded": {
            "type": "integer",
            "description": "Frames from this account the client could not decode."
          }
        },
        "required": [
          "id",
          "enabled",
          "connected",
          "since",
          "reconnects",
          "ping_ms",
          "server_build",
          "last_error",
          "subscribed",
          "login_rejected",
          "retry_at",
          "session_running",
          "ticks_seen",
          "last_tick_at_ms",
          "last_frame_at_ms",
          "streams",
          "ticks_coalesced",
          "undecoded"
        ],
        "description": "An account's status plus the counters diagnostics adds."
      },
      "UndecodedFrame": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Frame number since the server started."
          },
          "time": {
            "type": "integer",
            "description": "When it arrived, unix seconds (UTC)."
          },
          "account": {
            "type": "string",
            "description": "Account id."
          },
          "login": {
            "type": "integer",
            "description": "MT5 login of the account."
          },
          "kind": {
            "type": "string",
            "description": "frame: the outer frame or its encryption did not check out. body: a known command whose body did not parse. unknown_push: a push with a command id the client does not handle. extra (0.6.0): a reply read in full with bytes after the records the layout knows; kept for diagnosis, never counted as undecoded.",
            "enum": [
              "frame",
              "body",
              "unknown_push",
              "extra"
            ]
          },
          "command": {
            "type": "integer",
            "description": "Protocol command id."
          },
          "code": {
            "type": "integer",
            "description": "The frame's result code."
          },
          "context": {
            "type": "string",
            "description": "Where it happened, for example tick push or account reply."
          },
          "error": {
            "type": "string",
            "description": "What the decoder said."
          },
          "server_build": {
            "type": "integer",
            "description": "The broker's MT5 build at the time."
          },
          "len": {
            "type": "integer",
            "description": "Body length in bytes."
          },
          "body_hex": {
            "type": "string",
            "description": "The body as hex. Without `bodies=1` it is cut to the first 128 bytes and `body_preview` is true; with it, up to 64 KB a frame."
          },
          "truncated": {
            "type": "boolean",
            "description": "True when the kept body itself holds only the first 64 KB."
          },
          "body_preview": {
            "type": "boolean",
            "description": "Present and true when body_hex was cut to its first 128 bytes; ask with `bodies=1` for the whole body."
          }
        },
        "required": [
          "id",
          "time",
          "account",
          "login",
          "kind",
          "command",
          "code",
          "context",
          "error",
          "server_build",
          "len",
          "body_hex",
          "truncated"
        ],
        "description": "A frame the client could not decode, kept with its bytes.",
        "examples": [
          {
            "id": 3,
            "time": 1790965012,
            "account": "pepperstone-12345678",
            "login": 12345678,
            "kind": "body",
            "command": 8,
            "code": 0,
            "context": "tick push",
            "error": "short read at offset 40",
            "server_build": 6090,
            "len": 52,
            "body_hex": "0a000000b80b0000a4703d0ad7af924000000000000000000000000000000000c8b1e2a4b5010000",
            "truncated": false
          }
        ]
      },
      "DoctorReport": {
        "type": "object",
        "properties": {
          "verdict": {
            "type": "string",
            "description": "ok when every check passed, warnings when something should be looked at, problems when something is broken.",
            "enum": [
              "ok",
              "warnings",
              "problems"
            ]
          },
          "version": {
            "type": "string",
            "description": "Server version."
          },
          "data_dir": {
            "type": "string",
            "description": "The data folder that was checked."
          },
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DoctorCheck"
            },
            "description": "One row per check, in the order they ran."
          }
        },
        "required": [
          "verdict",
          "version",
          "data_dir",
          "checks"
        ],
        "description": "The same checks as `termlessd doctor`: data folder, master.key, database integrity and row counts, listen address, each account's gateway (DNS, TLS, the web terminal's build), the clock against the broker (the newest live tick), free disk.",
        "examples": [
          {
            "verdict": "warnings",
            "version": "0.1.0",
            "data_dir": "/var/lib/termless",
            "checks": [
              {
                "name": "data folder",
                "level": "ok",
                "detail": "/var/lib/termless exists and is writable"
              },
              {
                "name": "master.key",
                "level": "ok",
                "detail": "/var/lib/termless/master.key present (owner-only)"
              },
              {
                "name": "database",
                "level": "ok",
                "detail": "/var/lib/termless/termless.db (132 KB) integrity ok; rows: accounts 1, keys 2, audit 4821, account_events 310, equity_samples 1440"
              },
              {
                "name": "listen",
                "level": "ok",
                "detail": "serving on http://127.0.0.1:8780"
              },
              {
                "name": "gateway",
                "level": "ok",
                "detail": "pepperstone-12345678: mt5-demo01.pepperstone.com:443 is Pepperstone Group Limited build 6090 (2 servers); connected, build 6090"
              },
              {
                "name": "clock",
                "level": "warn",
                "detail": "7 s off the broker's clock",
                "fix": "enable NTP (timedatectl set-ntp true); candle times and expirations depend on it"
              },
              {
                "name": "disk",
                "level": "ok",
                "detail": "18240 MB free; termless uses 3 MB"
              }
            ]
          }
        ]
      },
      "DoctorCheck": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "What was checked: data folder, master.key, setup-token, database, listen, gateway (one per account; gateways when there are none), clock, disk."
          },
          "level": {
            "type": "string",
            "description": "ok, warn or fail.",
            "enum": [
              "ok",
              "warn",
              "fail"
            ]
          },
          "detail": {
            "type": "string",
            "description": "What was found, in a sentence."
          },
          "fix": {
            "type": "string",
            "description": "What to do. Only on a warn or fail."
          }
        },
        "required": [
          "name",
          "level",
          "detail"
        ],
        "examples": [
          {
            "name": "clock",
            "level": "warn",
            "detail": "7 s off the broker's clock",
            "fix": "enable NTP (timedatectl set-ntp true); candle times and expirations depend on it"
          }
        ]
      },
      "AuditRow": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Row id, increasing. Page with `before`."
          },
          "at": {
            "type": "integer",
            "description": "When it happened, unix milliseconds (UTC)."
          },
          "kind": {
            "type": "string",
            "description": "What kind of thing happened.",
            "enum": [
              "trade",
              "account",
              "key",
              "signin",
              "auth_failed",
              "lockout",
              "password",
              "setup",
              "server_check",
              "server_trust",
              "start"
            ]
          },
          "actor": {
            "type": "string",
            "description": "Who did it: the key id for a key, admin for the dashboard, the client IP before sign-in, termlessd for the server itself."
          },
          "actor_kind": {
            "type": "string",
            "description": "admin for the dashboard session, key for an API key, anonymous before sign-in, system for the server.",
            "enum": [
              "admin",
              "key",
              "anonymous",
              "system"
            ]
          },
          "account": {
            "type": [
              "string",
              "null"
            ],
            "description": "The account it concerned, when one did."
          },
          "route": {
            "type": "string",
            "description": "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."
          },
          "summary": {
            "type": "string",
            "description": "One line a person can read."
          },
          "request": {
            "type": [
              "string",
              "null"
            ],
            "description": "For a trade: the request sent to the broker, in short JSON (cut to 400 characters)."
          },
          "status": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The HTTP status the caller got."
          },
          "retcode": {
            "type": [
              "integer",
              "null"
            ],
            "description": "For a trade the broker answered: its return code."
          },
          "result": {
            "type": [
              "string",
              "null"
            ],
            "description": "For a trade: the broker's answer in words with the order and deal tickets, or the error when it did not answer."
          },
          "latency_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "For a trade: the broker round trip in milliseconds."
          },
          "request_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The X-Request-Id of the request that caused the row; the same id is on its log lines."
          },
          "ip": {
            "type": [
              "string",
              "null"
            ],
            "description": "The client IP, recorded for sign-ins, wrong passwords and lockouts."
          }
        },
        "required": [
          "id",
          "at",
          "kind",
          "actor",
          "actor_kind",
          "account",
          "route",
          "summary",
          "request",
          "status",
          "retcode",
          "result",
          "latency_ms",
          "request_id",
          "ip"
        ],
        "description": "One row of the audit trail: every write and every security event, with the request id that caused it. Trades get one row per broker call and none for an idempotent replay.",
        "examples": [
          {
            "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"
          }
        ]
      },
      "ConnectionEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Row id, increasing. Page with `before`."
          },
          "at": {
            "type": "integer",
            "description": "When it happened, unix milliseconds (UTC)."
          },
          "account": {
            "type": "string",
            "description": "Account id."
          },
          "kind": {
            "type": "string",
            "description": "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.",
            "enum": [
              "started",
              "connected",
              "reconnected",
              "lost",
              "connect_failed",
              "login_rejected",
              "stopped"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "description": "The build for connected and reconnected, the error for lost, connect_failed and login_rejected."
          },
          "duration_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "For connected and reconnected: how long the account had been disconnected. For lost and stopped: how long it had been connected."
          },
          "quiet_since": {
            "type": [
              "integer",
              "null"
            ],
            "description": "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": [
          "id",
          "at",
          "account",
          "kind",
          "reason",
          "duration_ms",
          "quiet_since"
        ],
        "description": "One entry of an account's connection history.",
        "examples": [
          {
            "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",
            "duration_ms": 73284110,
            "quiet_since": null
          }
        ]
      },
      "EquityCurve": {
        "type": "object",
        "properties": {
          "account": {
            "type": "string",
            "description": "Account id."
          },
          "hours": {
            "type": "integer",
            "description": "The window asked for, ending now."
          },
          "every_s": {
            "type": "integer",
            "description": "Seconds between samples while connected (60)."
          },
          "samples": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EquitySample"
            },
            "description": "Oldest first. About one a minute while the account is connected, the first right after it connects; none while it is not (see gaps)."
          },
          "gaps": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EquityGap"
            },
            "description": "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": [
          "account",
          "hours",
          "every_s",
          "samples",
          "gaps"
        ],
        "description": "Balance, equity, margin and profit sampled about once a minute, kept 7 days, and the gaps when the account was not connected. Served from the database, so it works while the account is disconnected or turned off.",
        "examples": [
          {
            "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
              }
            ]
          }
        ]
      },
      "EquityGap": {
        "type": "object",
        "properties": {
          "from": {
            "type": "integer",
            "description": "When the account stopped being connected (a lost or stopped event, the window's start if it was already down, or for a run that ended without a stop the last sample before the restart), unix milliseconds (UTC)."
          },
          "to": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When it connected again, unix milliseconds (UTC). null while it still is not."
          }
        },
        "required": [
          "from",
          "to"
        ],
        "description": "A period the account was not connected.",
        "examples": [
          {
            "from": 1790968296572,
            "to": 1790968298412
          },
          {
            "from": 1790981100000,
            "to": null
          }
        ]
      },
      "EquitySample": {
        "type": "object",
        "properties": {
          "at": {
            "type": "integer",
            "description": "Unix milliseconds (UTC)."
          },
          "balance": {
            "type": "number",
            "description": "Balance."
          },
          "equity": {
            "type": "number",
            "description": "Equity, with live profit."
          },
          "margin": {
            "type": "number",
            "description": "Margin in use."
          },
          "profit": {
            "type": "number",
            "description": "Floating profit of open positions."
          }
        },
        "required": [
          "at",
          "balance",
          "equity",
          "margin",
          "profit"
        ],
        "examples": [
          {
            "at": 1790977560000,
            "balance": 10412.58,
            "equity": 10641.2,
            "margin": 878.93,
            "profit": 228.62
          }
        ]
      },
      "UndecodedCount": {
        "type": "object",
        "properties": {
          "account": {
            "type": "string",
            "description": "Account id."
          },
          "command": {
            "type": "integer",
            "description": "Protocol command id."
          },
          "kind": {
            "type": "string",
            "description": "frame: the outer frame or its encryption did not check out. body: a known command whose body did not parse. unknown_push: a push with a command id the client does not handle. extra (0.6.0): a reply read in full with bytes after the records the layout knows; kept for diagnosis, never counted as undecoded.",
            "enum": [
              "frame",
              "body",
              "unknown_push",
              "extra"
            ]
          },
          "context": {
            "type": "string",
            "description": "Where it happened."
          },
          "count": {
            "type": "integer",
            "description": "How many such frames arrived (kept or only counted)."
          },
          "first_at": {
            "type": "integer",
            "description": "First one, unix seconds (UTC)."
          },
          "last_at": {
            "type": "integer",
            "description": "Latest one, unix seconds (UTC)."
          },
          "last_error": {
            "type": "string",
            "description": "What the decoder said about the latest one."
          }
        },
        "required": [
          "account",
          "command",
          "kind",
          "context",
          "count",
          "first_at",
          "last_at",
          "last_error"
        ],
        "examples": [
          {
            "account": "pepperstone-12345678",
            "command": 8,
            "kind": "body",
            "context": "tick push",
            "count": 3,
            "first_at": 1790964410,
            "last_at": 1790965012,
            "last_error": "short read at offset 40"
          }
        ]
      },
      "LogLine": {
        "type": "object",
        "properties": {
          "time": {
            "type": "integer",
            "description": "Unix seconds (UTC)."
          },
          "level": {
            "type": "string",
            "description": "Log level.",
            "enum": [
              "warn",
              "error"
            ]
          },
          "target": {
            "type": "string",
            "description": "The module that logged it."
          },
          "message": {
            "type": "string",
            "description": "The log message."
          }
        },
        "required": [
          "time",
          "level",
          "target",
          "message"
        ],
        "examples": [
          {
            "time": 1790968290,
            "level": "warn",
            "target": "termless::session",
            "message": "[pepperstone-12345678] connection lost, reconnecting"
          }
        ]
      },
      "CrashReport": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "File name in <data>/crashes; fetch the text with GET /api/v1/diagnostics/crashes/{name}."
          },
          "time": {
            "type": "integer",
            "description": "When it was written, unix seconds (UTC)."
          },
          "size": {
            "type": "integer",
            "description": "Size in bytes."
          },
          "summary": {
            "type": "string",
            "description": "The panic message, or the first line of an unclean-exit report."
          }
        },
        "required": [
          "name",
          "time",
          "size",
          "summary"
        ],
        "examples": [
          {
            "name": "20261002T231405Z-panic.txt",
            "time": 1790896445,
            "size": 6120,
            "summary": "index out of bounds: the len is 3 but the index is 3"
          }
        ]
      },
      "Server": {
        "type": "object",
        "properties": {
          "server": {
            "type": "string",
            "description": "Trade server name exactly as the broker spells it, for example Pepperstone-Demo."
          },
          "company": {
            "type": "string",
            "description": "Broker company name."
          },
          "host": {
            "type": "string",
            "description": "Host that serves the broker's MT5 web terminal."
          },
          "port": {
            "type": "integer",
            "description": "Port, usually 443."
          },
          "type": {
            "type": "string",
            "description": "Demo or real money server.",
            "enum": [
              "demo",
              "real"
            ]
          },
          "build": {
            "type": [
              "integer",
              "null"
            ],
            "description": "MT5 web terminal build seen on the host. null until this install has checked it."
          },
          "verified_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds (UTC) when this install last checked the host. null for a built-in entry it has not checked."
          },
          "tls_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "For an IP access point: the name sent (SNI) and checked against the certificate while TCP goes to the IP. null for a named host."
          },
          "pin_sha256": {
            "type": [
              "string",
              "null"
            ],
            "description": "SHA-256 of the certificate key an admin pinned for this host (64 hex), or null."
          },
          "prop_firm": {
            "type": "boolean",
            "description": "A prop firm's server (from the built-in directory)."
          }
        },
        "required": [
          "server",
          "company",
          "host",
          "port",
          "type",
          "build",
          "verified_at",
          "tls_name",
          "pin_sha256",
          "prop_firm"
        ],
        "examples": [
          {
            "server": "Pepperstone-Demo",
            "company": "Pepperstone Group Limited",
            "host": "mt5-demo01.pepperstone.com",
            "port": 443,
            "type": "demo",
            "build": 6090,
            "verified_at": 1790966779,
            "tls_name": null,
            "pin_sha256": null,
            "prop_firm": false
          },
          {
            "server": "Pepperstone-MT5-Live01",
            "company": "Pepperstone Group Limited",
            "host": "mt5-1.pepperstone.com",
            "port": 443,
            "type": "real",
            "build": null,
            "verified_at": null,
            "tls_name": null,
            "pin_sha256": null,
            "prop_firm": false
          },
          {
            "server": "Exness-MT5Trial7",
            "company": "Exness Technologies Ltd",
            "host": "52.221.81.217",
            "port": 443,
            "type": "demo",
            "build": null,
            "verified_at": null,
            "tls_name": "exwebterm.com",
            "pin_sha256": null,
            "prop_firm": false
          }
        ]
      },
      "ServerCheckRequest": {
        "type": "object",
        "properties": {
          "host": {
            "type": "string",
            "description": "Host name to check. A pasted link works: the scheme, path, query, fragment and any user@ are dropped, and host:port works when port is left out."
          },
          "port": {
            "type": "integer",
            "description": "Port. Defaults to 443.",
            "default": 443
          },
          "tls_name": {
            "type": "string",
            "description": "For an IP access point: the name on its certificate (sent as SNI and checked). Defaults to the directory's for that host."
          },
          "fingerprint": {
            "type": "string",
            "description": "Pin this certificate key for the host: the spki_sha256 a refused check reported (64 hex; sha256: and colons allowed). Only for a host you know is the broker's; audited as server_trust."
          }
        },
        "required": [
          "host"
        ],
        "examples": [
          {
            "host": "mt5-demo01.pepperstone.com"
          },
          {
            "host": "52.221.81.217",
            "tls_name": "exwebterm.com"
          },
          {
            "host": "mt5-demo.broker-example.com",
            "fingerprint": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7"
          }
        ]
      },
      "Certificate": {
        "type": "object",
        "properties": {
          "host": {
            "type": "string",
            "description": "The name that was checked (the TLS name, else the host)."
          },
          "reason": {
            "type": "string",
            "description": "Why it was refused.",
            "enum": [
              "unknown_issuer",
              "name_mismatch",
              "expired",
              "not_yet_valid",
              "pin_mismatch",
              "invalid"
            ]
          },
          "detail": {
            "type": "string",
            "description": "The TLS library's words."
          },
          "names": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The names the certificate is for (subjectAltName, else its common name)."
          },
          "subject": {
            "type": "string",
            "description": "Its subject, most specific first."
          },
          "issuer": {
            "type": "string",
            "description": "Who issued it."
          },
          "not_before": {
            "type": "integer",
            "description": "Valid from, unix seconds (UTC)."
          },
          "not_after": {
            "type": "integer",
            "description": "Valid until, unix seconds (UTC)."
          },
          "spki_sha256": {
            "type": "string",
            "description": "SHA-256 of its DER SubjectPublicKeyInfo, 64 lower-case hex: the value to pin."
          },
          "pinned": {
            "type": [
              "string",
              "null"
            ],
            "description": "For pin_mismatch: the key that was expected."
          }
        },
        "required": [
          "host",
          "reason",
          "detail",
          "names",
          "subject",
          "issuer",
          "not_before",
          "not_after",
          "spki_sha256",
          "pinned"
        ],
        "description": "A gateway certificate that was refused, for a person to judge. Termless never accepts one on its own; an admin may pin its key.",
        "examples": [
          {
            "host": "mt5-demo.broker-example.com",
            "reason": "name_mismatch",
            "detail": "NotValidForNameContext",
            "names": [
              "*.mobile-demo.example.net",
              "mobile-demo.example.net"
            ],
            "subject": "CN=*.mobile-demo.example.net",
            "issuer": "CN=Example DV CA, O=Example Trust, C=LU",
            "not_before": 1759190400,
            "not_after": 1790726399,
            "spki_sha256": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7",
            "pinned": null
          }
        ]
      },
      "CertificateError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code. Matches the HTTP status.",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "real_account",
                  "not_found",
                  "method_not_allowed",
                  "conflict",
                  "rejected",
                  "too_many_requests",
                  "internal",
                  "broker_error",
                  "disconnected",
                  "busy",
                  "stopping",
                  "timeout",
                  "unconfirmed",
                  "trading_paused",
                  "key_limit",
                  "untrusted_certificate",
                  "certificate_changed",
                  "browser_only"
                ]
              },
              "message": {
                "type": "string",
                "description": "What went wrong, in a sentence a person can read."
              }
            },
            "required": [
              "code",
              "message"
            ]
          },
          "certificate": {
            "$ref": "#/components/schemas/Certificate"
          }
        },
        "required": [
          "error",
          "certificate"
        ],
        "description": "502 untrusted_certificate or certificate_changed: the error and the certificate.",
        "examples": [
          {
            "error": {
              "code": "untrusted_certificate",
              "message": "the certificate of mt5-demo.broker-example.com is not trusted: it is for another name; ..."
            },
            "certificate": {
              "host": "mt5-demo.broker-example.com",
              "reason": "name_mismatch",
              "detail": "NotValidForNameContext",
              "names": [
                "*.mobile-demo.example.net",
                "mobile-demo.example.net"
              ],
              "subject": "CN=*.mobile-demo.example.net",
              "issuer": "CN=Example DV CA, O=Example Trust, C=LU",
              "not_before": 1759190400,
              "not_after": 1790726399,
              "spki_sha256": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7",
              "pinned": null
            }
          }
        ]
      },
      "TrustRequest": {
        "type": "object",
        "properties": {
          "fingerprint": {
            "type": "string",
            "description": "The key to pin: spki_sha256 from a refused check (64 hex; sha256: and colons allowed)."
          }
        },
        "required": [
          "fingerprint"
        ],
        "examples": [
          {
            "fingerprint": "94f8fc63b835599dd9a14fbd30445e94040d65b2801597b764aae9bfb779d4e7"
          }
        ]
      },
      "TrustResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "description": "True: pinned."
          },
          "server": {
            "type": "string",
            "description": "The server named in the path."
          },
          "host": {
            "type": "string",
            "description": "Its host."
          },
          "port": {
            "type": "integer",
            "description": "Its port."
          },
          "tls_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Its TLS name, if any."
          },
          "pin_sha256": {
            "type": "string",
            "description": "The pinned key."
          },
          "accounts_restarted": {
            "type": "integer",
            "description": "Accounts on that gateway that logged in again with the pin."
          },
          "servers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "server": {
                  "type": "string",
                  "description": "Trade server name."
                },
                "type": {
                  "type": "string",
                  "description": "demo or real.",
                  "enum": [
                    "demo",
                    "real"
                  ]
                }
              },
              "required": [
                "server",
                "type"
              ]
            },
            "description": "Servers the host's page lists (saved with the pin)."
          }
        },
        "required": [
          "ok",
          "server",
          "host",
          "port",
          "tls_name",
          "pin_sha256",
          "accounts_restarted",
          "servers"
        ]
      },
      "ServerCheck": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "description": "True when the host serves an MT5 web terminal."
          },
          "host": {
            "type": "string",
            "description": "The host that was checked."
          },
          "port": {
            "type": "integer",
            "description": "The port that was checked."
          },
          "company": {
            "type": "string",
            "description": "Broker company name from the terminal page."
          },
          "build": {
            "type": "integer",
            "description": "Web terminal build."
          },
          "servers": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "server": {
                  "type": "string",
                  "description": "Trade server name."
                },
                "type": {
                  "type": "string",
                  "description": "demo or real, from the server's name (Demo, Trial or Contest in it means demo), not from the page.",
                  "enum": [
                    "demo",
                    "real"
                  ]
                }
              },
              "required": [
                "server",
                "type"
              ]
            },
            "description": "Trade servers this host answers for. They are saved to the directory."
          },
          "tls_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "The TLS name used, for an IP access point."
          },
          "pin_sha256": {
            "type": [
              "string",
              "null"
            ],
            "description": "The pinned key the host was checked with, if any."
          }
        },
        "required": [
          "ok",
          "host",
          "port",
          "company",
          "build",
          "servers",
          "tls_name",
          "pin_sha256"
        ],
        "examples": [
          {
            "ok": true,
            "host": "mt5-demo01.pepperstone.com",
            "port": 443,
            "company": "Pepperstone Group Limited",
            "build": 6090,
            "servers": [
              {
                "server": "Pepperstone-Demo",
                "type": "demo"
              }
            ],
            "tls_name": null,
            "pin_sha256": null
          }
        ]
      },
      "AccountStatus": {
        "type": "object",
        "properties": {
          "connected": {
            "type": "boolean",
            "description": "Whether the session to the broker is up right now."
          },
          "since": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds (UTC) when the current connection came up. null while disconnected."
          },
          "reconnects": {
            "type": "integer",
            "description": "Automatic reconnects since the server started."
          },
          "ping_ms": {
            "type": [
              "number",
              "null"
            ],
            "description": "Last heartbeat round trip in milliseconds. null before the first one."
          },
          "server_build": {
            "type": [
              "integer",
              "null"
            ],
            "description": "MT5 build the broker's server reported. null before the first login."
          },
          "last_error": {
            "type": [
              "string",
              "null"
            ],
            "description": "Why the last connection attempt failed or the connection dropped. null while connected."
          },
          "subscribed": {
            "type": "integer",
            "description": "Number of symbols with a live price subscription."
          },
          "login_rejected": {
            "type": "boolean",
            "description": "True after the broker refused the login. A refusal within an hour of losing a working connection (a broker restarting refuses logins with code 2 for seconds to minutes) is tried again after 10, 20, 30 and 60 s, then every minute for code 2 until an hour after the loss (0.6.3), then every 5 minutes; any other refusal only every 5 minutes, so a wrong password cannot get the account locked."
          },
          "retry_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds (UTC) of the next connection attempt while disconnected, else null."
          }
        },
        "required": [
          "connected",
          "since",
          "reconnects",
          "ping_ms",
          "server_build",
          "last_error",
          "subscribed",
          "login_rejected",
          "retry_at"
        ],
        "examples": [
          {
            "connected": true,
            "since": 1790968298,
            "reconnects": 0,
            "ping_ms": 14.2,
            "server_build": 6090,
            "last_error": null,
            "subscribed": 2,
            "login_rejected": false,
            "retry_at": null
          }
        ]
      },
      "Account": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Your id for the account, used in every URL. a-z, 0-9 and -, up to 48 characters."
          },
          "label": {
            "type": "string",
            "description": "Display name."
          },
          "login": {
            "type": "integer",
            "description": "MT5 login number."
          },
          "server": {
            "type": "string",
            "description": "Trade server name, for example Pepperstone-Demo."
          },
          "host": {
            "type": "string",
            "description": "Web terminal host the session connects to."
          },
          "port": {
            "type": "integer",
            "description": "Port, usually 443."
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Symbols kept subscribed for live prices (the watchlist)."
          },
          "enabled": {
            "type": "boolean",
            "description": "When false the server keeps the account but does not connect it."
          },
          "created_at": {
            "type": "integer",
            "description": "When the account was added, unix seconds (UTC)."
          },
          "tls_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "For an IP access point: the name on the gateway's certificate. null for a named host."
          },
          "trade_real": {
            "type": "boolean",
            "description": "Whether trading is allowed when the broker reports this account as real money (account type real or preliminary). Off by default: every route that needs the trade scope then answers 403 real_account. Demo and contest accounts trade either way, and reading is never affected."
          },
          "new_trades_paused": {
            "type": "boolean",
            "description": "New trades are paused (0.6.0): an order that would open something answers 403 trading_paused and is not sent; closing, changing stops and cancelling still work."
          },
          "pinned": {
            "type": "boolean",
            "description": "The gateway's certificate key was pinned by an admin (see the server directory)."
          },
          "status": {
            "$ref": "#/components/schemas/AccountStatus"
          },
          "clock": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the trade server's clock relates to UTC, for the *_utc fields (0.7.0): ny7 (New York plus 7 hours on the US calendar: IC Markets, Pepperstone), utc (Exness), or null for none. With a rule, answers and streams carry time_utc beside time, time_utc_msc beside time_msc (and the same for time_setup, time_done, time_update, and expiration_utc beside a pending order's expiration), each worked out by itself from the time-zone database; a time in New York's repeated autumn hour uses the earlier offset and adds <name>_utc_ambiguous: true. Without one, no UTC fields: Termless never guesses a broker's clock.",
            "enum": [
              "ny7",
              "utc",
              null
            ]
          }
        },
        "required": [
          "id",
          "label",
          "login",
          "server",
          "host",
          "port",
          "symbols",
          "enabled",
          "created_at",
          "tls_name",
          "trade_real",
          "new_trades_paused",
          "clock",
          "pinned",
          "status"
        ],
        "description": "The password is write-only: never returned, stored encrypted with a per-install key.",
        "examples": [
          {
            "id": "pepperstone-12345678",
            "label": "Pepperstone demo",
            "login": 12345678,
            "server": "Pepperstone-Demo",
            "host": "mt5-demo01.pepperstone.com",
            "port": 443,
            "symbols": [
              "XAUUSD",
              "EURUSD"
            ],
            "enabled": true,
            "created_at": 1790881742,
            "tls_name": null,
            "trade_real": false,
            "new_trades_paused": false,
            "clock": null,
            "pinned": false,
            "status": {
              "connected": true,
              "since": 1790968298,
              "reconnects": 0,
              "ping_ms": 14.2,
              "server_build": 6090,
              "last_error": null,
              "subscribed": 2,
              "login_rejected": false,
              "retry_at": null
            }
          }
        ]
      },
      "AccountCreate": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Your id for the account: a-z, 0-9 and -, up to 48 characters. Defaults to the server's first word and the login, for example pepperstone-12345678.",
            "pattern": "^[a-z0-9][a-z0-9-]*$",
            "maxLength": 48
          },
          "label": {
            "type": "string",
            "description": "Display name. Defaults to the server and login."
          },
          "login": {
            "type": "integer",
            "description": "MT5 login number (a numeric string also works)."
          },
          "password": {
            "type": "string",
            "description": "MT5 password (master or investor). Write-only.",
            "writeOnly": true
          },
          "server": {
            "type": "string",
            "description": "Trade server name exactly as the broker spells it."
          },
          "host": {
            "type": "string",
            "description": "Web terminal host. Looked up from server (this install's directory, then the built-in list) when omitted; 400 if it cannot be found."
          },
          "port": {
            "type": "integer",
            "description": "Port. Defaults to the directory's port, else 443."
          },
          "tls_name": {
            "type": "string",
            "description": "For an IP access point: the name on its certificate. Defaults to the directory's for that host."
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Symbols to keep subscribed (the watchlist)."
          },
          "enabled": {
            "type": "boolean",
            "description": "false saves the account without connecting it.",
            "default": true
          },
          "trade_real": {
            "type": "boolean",
            "description": "Allow trading when the broker reports the account as real money. Off by default; demo and contest accounts trade either way.",
            "default": false
          },
          "clock": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the trade server's clock relates to UTC, for the *_utc fields (0.7.0): ny7 (New York plus 7 hours on the US calendar: IC Markets, Pepperstone), utc (Exness), or null for none. With a rule, answers and streams carry time_utc beside time, time_utc_msc beside time_msc (and the same for time_setup, time_done, time_update, and expiration_utc beside a pending order's expiration), each worked out by itself from the time-zone database; a time in New York's repeated autumn hour uses the earlier offset and adds <name>_utc_ambiguous: true. Without one, no UTC fields: Termless never guesses a broker's clock.",
            "enum": [
              "ny7",
              "utc",
              null
            ]
          }
        },
        "required": [
          "login",
          "password",
          "server"
        ],
        "examples": [
          {
            "label": "Pepperstone demo",
            "login": 12345678,
            "password": "your MT5 password",
            "server": "Pepperstone-Demo",
            "symbols": [
              "XAUUSD",
              "EURUSD"
            ]
          }
        ]
      },
      "AccountPatch": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "description": "Display name."
          },
          "password": {
            "type": "string",
            "description": "New MT5 password. Write-only. Logs in again.",
            "writeOnly": true
          },
          "server": {
            "type": "string",
            "description": "Trade server name. Logs in again; the host is looked up when host is not sent."
          },
          "host": {
            "type": "string",
            "description": "Web terminal host. Logs in again."
          },
          "port": {
            "type": "integer",
            "description": "Port. Logs in again."
          },
          "tls_name": {
            "type": "string",
            "description": "The name on the gateway's certificate, for an IP access point; an empty string clears it. Logs in again."
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Replaces the whole watchlist and starts streaming new symbols without logging in again."
          },
          "enabled": {
            "type": "boolean",
            "description": "false logs out and parks the account, true connects it again."
          },
          "trade_real": {
            "type": "boolean",
            "description": "true allows trading when the broker reports the account as real money; false turns it off again. Takes effect at once, without logging in again."
          },
          "new_trades_paused": {
            "type": "boolean",
            "description": "true refuses orders that would open something (403 trading_paused, not sent) while closing, changing stops and cancelling still work; false lets them through again (0.6.0). At once, no new login."
          },
          "clock": {
            "type": [
              "string",
              "null"
            ],
            "description": "How the trade server's clock relates to UTC, for the *_utc fields (0.7.0): ny7 (New York plus 7 hours on the US calendar: IC Markets, Pepperstone), utc (Exness), or null for none. With a rule, answers and streams carry time_utc beside time, time_utc_msc beside time_msc (and the same for time_setup, time_done, time_update, and expiration_utc beside a pending order's expiration), each worked out by itself from the time-zone database; a time in New York's repeated autumn hour uses the earlier offset and adds <name>_utc_ambiguous: true. Without one, no UTC fields: Termless never guesses a broker's clock. null takes it away; at once, open streams too.",
            "enum": [
              "ny7",
              "utc",
              null
            ]
          }
        },
        "description": "Send only the fields you want to change.",
        "examples": [
          {
            "symbols": [
              "XAUUSD",
              "EURUSD",
              "GBPUSD"
            ]
          },
          {
            "trade_real": true
          },
          {
            "new_trades_paused": true
          }
        ]
      },
      "Summary": {
        "type": "object",
        "properties": {
          "login": {
            "type": "integer",
            "description": "MT5 login number."
          },
          "name": {
            "type": "string",
            "description": "Account holder name at the broker."
          },
          "server": {
            "type": "string",
            "description": "Trade server name."
          },
          "company": {
            "type": "string",
            "description": "Broker company name."
          },
          "currency": {
            "type": "string",
            "description": "Deposit currency."
          },
          "leverage": {
            "type": "integer",
            "description": "Leverage, for example 200 for 1:200."
          },
          "balance": {
            "type": "number",
            "description": "Balance without open positions."
          },
          "credit": {
            "type": "number",
            "description": "Credit from the broker."
          },
          "profit": {
            "type": "number",
            "description": "Floating profit of open positions, live."
          },
          "equity": {
            "type": "number",
            "description": "balance + credit + profit, live."
          },
          "margin": {
            "type": "number",
            "description": "Margin in use, live."
          },
          "margin_free": {
            "type": "number",
            "description": "equity - margin."
          },
          "margin_level": {
            "type": "number",
            "description": "equity / margin x 100, in percent. 0 with no margin in use."
          },
          "margin_so_call": {
            "type": "number",
            "description": "Margin call level."
          },
          "margin_so_so": {
            "type": "number",
            "description": "Stop out level."
          },
          "trade_allowed": {
            "type": "boolean",
            "description": "Whether the broker allows trading on this account."
          },
          "demo": {
            "type": "boolean",
            "description": "True for a demo account."
          },
          "hedging": {
            "type": "boolean",
            "description": "True for a hedging account, false for netting."
          },
          "server_offset": {
            "type": "integer",
            "description": "Trade server clock, in seconds east of UTC. Subtract it from any market or trade time to get UTC. From the account record, read again at least hourly, and checked against live ticks (a tick's server time minus its arrival, to the quarter hour): when they disagree the ticks win while a tick agreed in the last 10 minutes, then the record. It is the offset now; times from before the broker's last summer-time switch were stamped with the old one."
          },
          "positions": {
            "type": "integer",
            "description": "Open positions."
          },
          "orders": {
            "type": "integer",
            "description": "Pending orders."
          }
        },
        "required": [
          "login",
          "name",
          "server",
          "company",
          "currency",
          "leverage",
          "balance",
          "credit",
          "profit",
          "equity",
          "margin",
          "margin_free",
          "margin_level",
          "margin_so_call",
          "margin_so_so",
          "trade_allowed",
          "demo",
          "hedging",
          "server_offset",
          "positions",
          "orders"
        ],
        "examples": [
          {
            "login": 12345678,
            "name": "Demo Trader",
            "server": "Pepperstone-Demo",
            "company": "Pepperstone Group Limited",
            "currency": "USD",
            "leverage": 200,
            "balance": 10412.58,
            "credit": 0.0,
            "profit": 238.11,
            "equity": 10650.69,
            "margin": 878.93,
            "margin_free": 9771.76,
            "margin_level": 1211.78,
            "margin_so_call": 100.0,
            "margin_so_so": 50.0,
            "trade_allowed": true,
            "demo": true,
            "hedging": true,
            "server_offset": 10800,
            "positions": 3,
            "orders": 2
          }
        ]
      },
      "SymbolBrief": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Symbol name, for example XAUUSD."
          },
          "description": {
            "type": "string",
            "description": "Broker's description."
          },
          "path": {
            "type": "string",
            "description": "Folder in the broker's symbol tree."
          },
          "digits": {
            "type": "integer",
            "description": "Price decimals."
          }
        },
        "required": [
          "name",
          "description",
          "path",
          "digits"
        ],
        "examples": [
          {
            "name": "XAUUSD",
            "description": "Gold vs US Dollar",
            "path": "Metals\\XAUUSD",
            "digits": 2
          }
        ]
      },
      "SymbolSpec": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Symbol name."
          },
          "description": {
            "type": "string",
            "description": "Broker's description."
          },
          "path": {
            "type": "string",
            "description": "Folder in the broker's symbol tree."
          },
          "digits": {
            "type": "integer",
            "description": "Price decimals."
          },
          "point": {
            "type": "number",
            "description": "Smallest price step, 10^-digits."
          },
          "contract_size": {
            "type": "number",
            "description": "Units per 1.00 lot."
          },
          "tick_size": {
            "type": "number",
            "description": "Smallest price change. The point when the broker does not send one."
          },
          "tick_value": {
            "type": [
              "number",
              "null"
            ],
            "description": "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": {
            "type": "string",
            "description": "Base currency."
          },
          "currency_profit": {
            "type": "string",
            "description": "Profit currency."
          },
          "currency_margin": {
            "type": "string",
            "description": "Margin currency."
          },
          "volume_min": {
            "type": "number",
            "description": "Smallest order, in lots."
          },
          "volume_max": {
            "type": "number",
            "description": "Largest order, in lots."
          },
          "volume_step": {
            "type": "number",
            "description": "Lot step."
          },
          "volume_limit": {
            "type": "number",
            "description": "Largest total of open positions and pending orders in one direction, in lots. 0 = no limit."
          },
          "trade_mode": {
            "type": "string",
            "description": "Whether trading is allowed. unknown only for a value MetaTrader does not define.",
            "enum": [
              "full",
              "long_only",
              "short_only",
              "close_only",
              "disabled",
              "unknown"
            ]
          },
          "execution": {
            "type": "string",
            "description": "Execution mode. unknown only for a value MetaTrader does not define.",
            "enum": [
              "market",
              "instant",
              "request",
              "exchange",
              "unknown"
            ]
          },
          "filling": {
            "type": "array",
            "items": {
              "type": "string",
              "description": "Filling mode.",
              "enum": [
                "fok",
                "ioc",
                "return"
              ]
            },
            "description": "Filling modes the symbol allows."
          },
          "stops_level": {
            "type": "integer",
            "description": "Minimum distance of SL and TP from the price, in points."
          },
          "freeze_level": {
            "type": "integer",
            "description": "Distance in points inside which orders cannot be changed."
          },
          "swap_long": {
            "type": "number",
            "description": "Swap for long positions, in the unit swap_mode names."
          },
          "swap_short": {
            "type": "number",
            "description": "Swap for short positions, in the unit swap_mode names."
          },
          "swap_mode": {
            "type": "string",
            "description": "The unit of swap_long and swap_short. unknown only for a value MetaTrader does not define.",
            "enum": [
              "disabled",
              "points",
              "symbol_currency",
              "margin_currency",
              "deposit_currency",
              "interest_current",
              "interest_open",
              "reopen_current",
              "reopen_bid",
              "profit_currency",
              "unknown"
            ]
          },
          "swap_3day": {
            "type": [
              "string",
              "null"
            ],
            "description": "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": {
            "type": "number",
            "description": "Initial margin setting of the symbol, as the broker sends it."
          },
          "margin_maintenance": {
            "type": "number",
            "description": "Maintenance margin setting, as the broker sends it."
          },
          "margin_hedged": {
            "type": "number",
            "description": "Margin for a hedged pair of positions (one lot each way), as the broker sends it."
          },
          "margin_rate_buy": {
            "type": "number",
            "description": "Initial margin rate for a buy (the same as margin_rates.buy)."
          },
          "margin_rate_sell": {
            "type": "number",
            "description": "Initial margin rate for a sell (the same as margin_rates.sell)."
          },
          "margin_rates": {
            "type": "object",
            "properties": {
              "buy": {
                "type": "number",
                "description": "Initial margin rate for a buy."
              },
              "sell": {
                "type": "number",
                "description": "Initial margin rate for a sell."
              },
              "buy_limit": {
                "type": "number",
                "description": "Initial margin rate for a buy limit."
              },
              "sell_limit": {
                "type": "number",
                "description": "Initial margin rate for a sell limit."
              },
              "buy_stop": {
                "type": "number",
                "description": "Initial margin rate for a buy stop."
              },
              "sell_stop": {
                "type": "number",
                "description": "Initial margin rate for a sell stop."
              },
              "buy_stop_limit": {
                "type": "number",
                "description": "Initial margin rate for a buy stop limit."
              },
              "sell_stop_limit": {
                "type": "number",
                "description": "Initial margin rate for a sell stop limit."
              }
            },
            "required": [
              "buy",
              "sell",
              "buy_limit",
              "sell_limit",
              "buy_stop",
              "sell_stop",
              "buy_stop_limit",
              "sell_stop_limit"
            ],
            "description": "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."
          },
          "expiration": {
            "type": "array",
            "items": {
              "type": "string",
              "description": "Expiry mode.",
              "enum": [
                "gtc",
                "day",
                "specified",
                "specified_day"
              ]
            },
            "description": "The expiry modes a pending order on this symbol may use."
          },
          "order_types": {
            "type": "array",
            "items": {
              "type": "string",
              "description": "Order type.",
              "enum": [
                "market",
                "limit",
                "stop",
                "stop_limit",
                "sl",
                "tp",
                "close_by"
              ]
            },
            "description": "The order types the symbol takes."
          },
          "sessions": {
            "type": "object",
            "properties": {
              "quote": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "description": "[open_min, close_min]",
                    "minItems": 2,
                    "maxItems": 2
                  },
                  "description": "Sessions for one weekday."
                },
                "description": "Quote sessions: 7 lists, one per weekday, Sunday first, each a list of [open_min, close_min] in minutes from midnight, trade server time.",
                "minItems": 7,
                "maxItems": 7
              },
              "trade": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    },
                    "description": "[open_min, close_min]",
                    "minItems": 2,
                    "maxItems": 2
                  },
                  "description": "Sessions for one weekday."
                },
                "description": "Trade sessions, same shape as quote.",
                "minItems": 7,
                "maxItems": 7
              }
            },
            "required": [
              "quote",
              "trade"
            ]
          },
          "tradeable": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "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": {
            "type": "integer",
            "description": "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)."
          }
        },
        "required": [
          "name",
          "description",
          "path",
          "digits",
          "point",
          "contract_size",
          "tick_size",
          "tick_value",
          "currency_base",
          "currency_profit",
          "currency_margin",
          "volume_min",
          "volume_max",
          "volume_step",
          "volume_limit",
          "trade_mode",
          "execution",
          "filling",
          "stops_level",
          "freeze_level",
          "swap_long",
          "swap_short",
          "swap_mode",
          "swap_3day",
          "margin_initial",
          "margin_maintenance",
          "margin_hedged",
          "margin_rate_buy",
          "margin_rate_sell",
          "margin_rates",
          "expiration",
          "order_types",
          "sessions",
          "tradeable"
        ],
        "description": "With the broker's group overrides applied.",
        "examples": [
          {
            "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
          }
        ]
      },
      "Quote": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "bid": {
            "type": [
              "number",
              "null"
            ],
            "description": "Bid price. null when the symbol has no price yet."
          },
          "ask": {
            "type": [
              "number",
              "null"
            ],
            "description": "Ask price. null when the symbol has no price yet."
          },
          "last": {
            "type": [
              "number",
              "null"
            ],
            "description": "Last deal price. 0 for most forex and CFD symbols; null when the symbol has no price yet."
          },
          "time": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds, trade server clock."
          },
          "time_msc": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix milliseconds, trade server clock."
          },
          "tradeable": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "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": [
          "symbol",
          "bid",
          "ask",
          "last",
          "time",
          "time_msc",
          "tradeable"
        ],
        "examples": [
          {
            "symbol": "XAUUSD",
            "bid": 2391.42,
            "ask": 2391.6,
            "last": 0,
            "time": 1790981179,
            "time_msc": 1790981179473,
            "tradeable": true
          }
        ]
      },
      "Candle": {
        "type": "object",
        "properties": {
          "time": {
            "type": "integer",
            "description": "Bar open time, unix seconds, trade server clock."
          },
          "open": {
            "type": "number",
            "description": "Open."
          },
          "high": {
            "type": "number",
            "description": "High."
          },
          "low": {
            "type": "number",
            "description": "Low."
          },
          "close": {
            "type": "number",
            "description": "Close."
          },
          "tick_volume": {
            "type": "integer",
            "description": "Tick count in the bar."
          },
          "real_volume": {
            "type": "integer",
            "description": "Exchange volume. 0 for most CFD symbols."
          },
          "spread": {
            "type": "integer",
            "description": "Always 0: the web protocol's bars carry no spread (MetaTrader builds bars from the bid)."
          },
          "complete": {
            "type": "boolean",
            "description": "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": {
            "type": "integer",
            "description": "Bar open time in UTC, unix seconds; only with the account's clock rule (0.7.0)."
          },
          "time_utc_ambiguous": {
            "type": "boolean",
            "description": "true when the time falls in New York's repeated autumn hour (0.7.0)."
          }
        },
        "required": [
          "time",
          "open",
          "high",
          "low",
          "close",
          "tick_volume",
          "real_volume",
          "spread",
          "complete"
        ]
      },
      "Candles": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name, as the broker spells it."
          },
          "timeframe": {
            "type": "string",
            "description": "Timeframe.",
            "enum": [
              "M1",
              "M2",
              "M3",
              "M4",
              "M5",
              "M6",
              "M10",
              "M12",
              "M15",
              "M20",
              "M30",
              "H1",
              "H2",
              "H3",
              "H4",
              "H6",
              "H8",
              "H12",
              "D1",
              "W1",
              "MN1"
            ]
          },
          "candles": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Candle"
            },
            "description": "Bars, oldest first. Each says whether it is complete."
          }
        },
        "required": [
          "symbol",
          "timeframe",
          "candles"
        ],
        "examples": [
          {
            "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
              }
            ]
          }
        ]
      },
      "Tick": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "bid": {
            "type": "number",
            "description": "Bid price."
          },
          "ask": {
            "type": "number",
            "description": "Ask price."
          },
          "last": {
            "type": "number",
            "description": "Last deal price. 0 for most forex and CFD symbols."
          },
          "time_msc": {
            "type": "integer",
            "description": "Unix milliseconds, trade server clock."
          }
        },
        "required": [
          "symbol",
          "bid",
          "ask",
          "last",
          "time_msc"
        ],
        "description": "A price change: the data of `event: tick` on the SSE stream. With the account's clock rule (0.7.0), UTC fields come beside it (see the account's clock). (time_utc_msc)",
        "examples": [
          {
            "symbol": "XAUUSD",
            "bid": 2391.42,
            "ask": 2391.6,
            "last": 0,
            "time_msc": 1790981179473
          }
        ]
      },
      "HistoryTick": {
        "type": "object",
        "properties": {
          "time": {
            "type": "integer",
            "description": "Unix seconds, trade server clock."
          },
          "time_msc": {
            "type": "integer",
            "description": "Unix milliseconds, trade server clock."
          },
          "bid": {
            "type": "number",
            "description": "Bid after the tick (the previous one when the tick did not change it)."
          },
          "ask": {
            "type": "number",
            "description": "Ask after the tick (the previous one when the tick did not change it)."
          },
          "last": {
            "type": "number",
            "description": "Last deal price after the tick. 0 for most forex and CFD symbols."
          },
          "volume": {
            "type": "integer",
            "description": "The tick's volume; 0 unless the tick changed it (flag 16)."
          },
          "flags": {
            "type": "integer",
            "description": "MetaTrader's TICK_FLAG_* for what the tick changed, added together: 2 bid, 4 ask, 8 last, 16 volume."
          },
          "volume_raw": {
            "type": "integer",
            "description": "The broker's volume number (lots times 10^8), as volume (0.7.0)."
          },
          "volume_real": {
            "type": "number",
            "description": "The volume in lots (0.7.0)."
          }
        },
        "required": [
          "time",
          "time_msc",
          "bid",
          "ask",
          "last",
          "volume",
          "flags",
          "volume_raw",
          "volume_real"
        ],
        "description": "One kept tick (GET /ticks), in the shape of copy_ticks_from's rows.",
        "examples": [
          {
            "time": 1790981179,
            "time_msc": 1790981179473,
            "bid": 2391.42,
            "ask": 2391.6,
            "last": 0,
            "volume": 0,
            "volume_raw": 0,
            "volume_real": 0.0,
            "flags": 6
          }
        ]
      },
      "TickHistory": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name, as the broker spells it."
          },
          "kept_from_msc": {
            "type": [
              "integer",
              "null"
            ],
            "description": "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": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/HistoryTick"
            },
            "description": "Ticks, oldest first."
          }
        },
        "required": [
          "symbol",
          "kept_from_msc",
          "ticks"
        ],
        "description": "The ticks termlessd kept for one symbol (the web protocol serves no tick history). Since 0.7.0 a symbol's ticks are kept from its first GET /ticks read on and dropped when it stops streaming, so a first read is often empty: the newest 1,000 per symbol by default, 100,000 over all of an account's symbols. A reconnect starts it again.",
        "examples": [
          {
            "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
              }
            ]
          }
        ]
      },
      "BookLevel": {
        "type": "object",
        "properties": {
          "type": {
            "type": "integer",
            "description": "MetaTrader's BOOK_TYPE_*: 1 sell, 2 buy, 3 sell market, 4 buy market.",
            "enum": [
              1,
              2,
              3,
              4
            ]
          },
          "side": {
            "type": "string",
            "description": "sell for types 1 and 3, buy for 2 and 4.",
            "enum": [
              "sell",
              "buy"
            ]
          },
          "price": {
            "type": "number",
            "description": "The level's price."
          },
          "volume": {
            "type": "integer",
            "description": "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": {
            "type": "number",
            "description": "The same, exactly."
          },
          "lots": {
            "type": "number",
            "description": "The units over the symbol's contract size (0.7.0)."
          }
        },
        "required": [
          "type",
          "side",
          "price",
          "volume",
          "volume_dbl",
          "lots"
        ],
        "description": "One price level of an order book, as market_book_get's BookInfo.",
        "examples": [
          {
            "type": 1,
            "side": "sell",
            "price": 2391.8,
            "volume": 250,
            "volume_dbl": 250.0,
            "lots": 2.5
          }
        ]
      },
      "Book": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name, as the broker spells it."
          },
          "time": {
            "type": "integer",
            "description": "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": {
            "type": "integer",
            "description": "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": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BookLevel"
            },
            "description": "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": [
          "symbol",
          "time",
          "time_msc",
          "levels"
        ],
        "description": "A symbol's order book (depth of market), GET /book.",
        "examples": [
          {
            "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
              }
            ]
          },
          {
            "symbol": "XAUUSD",
            "time": 0,
            "time_msc": 0,
            "levels": []
          }
        ]
      },
      "StreamStatus": {
        "type": "object",
        "properties": {
          "connected": {
            "type": "boolean",
            "description": "Whether the account is connected to the broker."
          },
          "ping_ms": {
            "type": [
              "number",
              "null"
            ],
            "description": "Last heartbeat round trip in milliseconds."
          },
          "id": {
            "type": "string",
            "description": "Only on the first status, and only when the stream follows trades or orders: where the stream starts in the account's trade event numbering. The client's own cursor when it resumed (after= or Last-Event-ID), else the newest event id (<epoch>:0 before the first event), so a client holds a cursor before any trade happens. On SSE the same value is the event's id: line."
          },
          "reason": {
            "type": "string",
            "description": "Only on the last status before the stream ends. account changed: the account was deleted or logs in with new details; server stopping: the server is shutting down; key revoked, key changed, signed out (0.6.0): the key that opened it was deleted or may no longer read this account, or the dashboard session ended. Reconnect to follow the account (EventSource does this by itself).",
            "enum": [
              "account changed",
              "server stopping",
              "key revoked",
              "key changed",
              "signed out"
            ]
          }
        },
        "required": [
          "connected",
          "ping_ms"
        ],
        "description": "The data of `event: status` on the SSE stream: sent first, then whenever connected changes, and once more (connected false, with a reason) when the stream ends.",
        "examples": [
          {
            "connected": true,
            "ping_ms": 14.2,
            "id": "1790968290117:40"
          },
          {
            "connected": false,
            "ping_ms": null,
            "reason": "account changed"
          }
        ]
      },
      "Resync": {
        "type": "object",
        "properties": {
          "seq": {
            "type": "integer",
            "description": "Its place in the account's numbering: its own seq for a resync the server recorded (after a gap: the broker link came back, the server restarted, the account's session started again; or when the server fell behind the broker), else the newest seq when it was sent."
          },
          "id": {
            "type": "string",
            "description": "<epoch>:<seq>. Carry on from this id."
          },
          "reason": {
            "type": "string",
            "description": "Why. Recorded in the numbering (and replayed like trade events): \"the broker link came back; ...\", \"the server restarted; ...\", \"the account's session started again; ...\" (each after the deals made during the gap, sent first as trade events marked caught_up), \"the server fell behind the broker's trade pushes\". Sent to one client only: \"that id is from another numbering (the account now logs in to another broker account, or its kept events were lost)\" (an id from another epoch: the account was added again, or logs in to another broker account), \"that id is newer than anything this account has sent\", \"more happened since that id than the server keeps\", \"this stream fell behind; read the account again\"."
          }
        },
        "required": [
          "seq",
          "id",
          "reason"
        ],
        "description": "The data of a `resync` event (with events=trades; WebSocket: type resync): trade events were or may have been missed and cannot be replayed. Read positions, orders and deals again, then go on from `id`. After a gap the deals the broker made meanwhile come first as trade events marked `caught_up`; pending orders placed or removed and stops moved during the gap have no history, so the resync still follows them.",
        "examples": [
          {
            "seq": 49,
            "id": "1790968290117:49",
            "reason": "the broker link came back; its trade pushes sent while it was down are not replayed (the deals made meanwhile came first, marked caught_up)"
          },
          {
            "seq": 49,
            "id": "1790968290117:49",
            "reason": "the server restarted; trade pushes sent while it was stopped are not replayed (the deals made meanwhile came first, marked caught_up)"
          },
          {
            "seq": 3,
            "id": "1791012001502:3",
            "reason": "that id is from another numbering (the account now logs in to another broker account, or its kept events were lost)"
          }
        ]
      },
      "TradesSince": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "The newest event's id (<epoch>:0 before the first). Ask again with after=<this>."
          },
          "events": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "type": "object",
                  "properties": {
                    "event": {
                      "type": "string",
                      "description": "trade or resync: which of the two the rest of the object is.",
                      "enum": [
                        "trade",
                        "resync"
                      ]
                    }
                  },
                  "required": [
                    "event"
                  ]
                },
                {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/TradeEvent"
                    },
                    {
                      "$ref": "#/components/schemas/Resync"
                    }
                  ]
                }
              ]
            },
            "description": "The events after `after`, oldest first: each a TradeEvent or a Resync with `event` beside its fields. Without after: every event kept (up to 1,024). Empty when resync is set."
          },
          "resync": {
            "type": [
              "string",
              "null"
            ],
            "description": "null, or why the events since after cannot be given (another epoch: the account was added again or logs in to another broker account; an id newer than anything sent; more happened than the server keeps). Then read positions, orders and deals again and carry on from id. A restart of the server does not change the epoch: an id from before it still resumes."
          }
        },
        "required": [
          "id",
          "events",
          "resync"
        ],
        "description": "The answer of GET /trades: the account's numbered trade events for a client that polls instead of streaming.",
        "examples": [
          {
            "id": "1790968290117:43",
            "events": [
              {
                "event": "trade",
                "seq": 42,
                "id": "1790968290117:42",
                "what": "opened",
                "kind": "deal",
                "deal": {
                  "ticket": 81200118,
                  "order": 51830012,
                  "position_id": 51830012,
                  "symbol": "XAUUSD",
                  "type": "buy",
                  "entry": "in",
                  "volume": 0.2,
                  "price": 2385.0,
                  "profit": 0.0,
                  "commission": -0.7,
                  "swap": 0.0,
                  "fee": 0.0,
                  "magic": 0,
                  "comment": "breakout",
                  "reason": "web",
                  "time": 1790975498,
                  "time_msc": 1790975498123
                },
                "balance": 10412.58,
                "credit": 0.0,
                "position": {
                  "ticket": 51830012,
                  "symbol": "XAUUSD",
                  "side": "buy",
                  "volume": 0.2,
                  "price_open": 2385.0,
                  "price_current": 2385.0,
                  "sl": 2380.0,
                  "tp": 2420.0,
                  "profit": 0.0,
                  "swap": 0.0,
                  "commission": -0.7,
                  "comment": "breakout",
                  "magic": 0,
                  "reason": "web",
                  "identifier": 51830012,
                  "time": 1790975498,
                  "time_msc": 1790975498123,
                  "time_update": 1790975498,
                  "open": true
                }
              },
              {
                "event": "trade",
                "seq": 43,
                "id": "1790968290117:43",
                "what": "updated",
                "kind": "position",
                "position": {
                  "ticket": 51830012,
                  "symbol": "XAUUSD",
                  "side": "buy",
                  "volume": 0.2,
                  "price_open": 2385.0,
                  "price_current": 2391.42,
                  "sl": 2386.0,
                  "tp": 2420.0,
                  "profit": 128.4,
                  "swap": -1.12,
                  "commission": -1.4,
                  "comment": "breakout",
                  "magic": 0,
                  "reason": "web",
                  "identifier": 51830012,
                  "time": 1790975498,
                  "time_msc": 1790975498123,
                  "time_update": 1790981102,
                  "open": true
                }
              }
            ],
            "resync": null
          },
          {
            "id": "1791012001502:3",
            "events": [],
            "resync": "that id is from another numbering (the account now logs in to another broker account, or its kept events were lost)"
          }
        ]
      },
      "TradeEvent": {
        "type": "object",
        "properties": {
          "seq": {
            "type": "integer",
            "description": "1, 2, 3, ... per account. The newest 1,024 events are kept in the database, so the numbering carries on across a restart or an upgrade; it starts again only when the account is added again or logs in to another broker account (login or server)."
          },
          "id": {
            "type": "string",
            "description": "<epoch>:<seq>, epoch being the unix ms when this numbering began. On SSE also the event's id: line, which EventSource sends back as Last-Event-ID; any client can resume with after=<id>, from before a restart too."
          },
          "what": {
            "type": "string",
            "description": "What happened. For a pending order (kind order): placed, modified or removed while it is live; filled, cancelled, expired, rejected (or done) when it moves to history. For a deal (kind deal): opened, partial, closed, reversed, or balance for a balance, credit or commission deal. For kind position: updated.",
            "enum": [
              "placed",
              "modified",
              "removed",
              "filled",
              "cancelled",
              "expired",
              "rejected",
              "done",
              "opened",
              "partial",
              "closed",
              "reversed",
              "balance",
              "deal",
              "updated"
            ]
          },
          "kind": {
            "type": "string",
            "description": "order for an order push, deal for a deal push, position for a position the broker changed without a deal (its SL or TP moved, or the step just before a close; the broker sends it as a deal record with ticket 0 and balance 0, which before 0.2.2 came out as a phantom deal opened).",
            "enum": [
              "order",
              "deal",
              "position"
            ]
          },
          "pending": {
            "type": "boolean",
            "description": "With kind order: true for a limit, stop or stop-limit order, false for a market buy or sell (or a close-by). A market order is placed, taken off the book and filed as filled (or cancelled) in the same moment, each step an order event with pending false and, once done, volume 0 (volume_initial is what was asked); a UI shows the deal event for it and skips these."
          },
          "order": {
            "$ref": "#/components/schemas/Order"
          },
          "state": {
            "type": "string",
            "description": "With kind order: the order's MetaTrader state.",
            "enum": [
              "started",
              "placed",
              "cancelled",
              "partial",
              "filled",
              "rejected",
              "expired",
              "request",
              "unknown"
            ]
          },
          "deal": {
            "$ref": "#/components/schemas/Deal"
          },
          "position": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Position"
              },
              {
                "type": "object",
                "properties": {
                  "open": {
                    "type": "boolean",
                    "description": "False once the position is closed."
                  }
                },
                "required": [
                  "open"
                ]
              }
            ],
            "description": "With kind deal: the position the deal touched; with kind position: the position that changed. With an extra `open`. A closed one (open false) carries its last known values (open price, SL, TP, time, comment, magic) with volume 0, where the broker sends zeros. Absent for a balance deal."
          },
          "positions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Position"
            },
            "description": "Other positions the same push updated (a netting account)."
          },
          "balance": {
            "type": "number",
            "description": "With kind deal: the account's balance after the deal. Never on kind position, nor on a caught_up deal."
          },
          "credit": {
            "type": "number",
            "description": "With kind deal: the account's credit after the deal. Never on kind position, nor on a caught_up deal."
          },
          "caught_up": {
            "type": "boolean",
            "description": "Present and true on a deal the broker made during a gap (the broker link was down, the server was stopped, or the account's session started again) and that was read back from the account's history after it: kind deal with `what` and `deal` only (a close is partial while its position is still open), oldest first, before the gap's resync. A deal already sent is never sent again, and nothing older than the oldest event the server keeps for the account (or the start of its numbering) is sent. Up to 7 days back and 500 deals; more than that sends only the resync."
          }
        },
        "required": [
          "seq",
          "id",
          "what",
          "kind"
        ],
        "description": "The data of a `trade` event (`events=trades`): one per broker trade push, as it is applied, numbered per account. An order push carries `order`, `state` and `pending`; a deal push carries `deal`, `balance`, `credit` and usually `position`; a position update carries `position` only; a deal caught up after a gap carries `deal` and `caught_up: true`. For a market order show the deal; for a pending order show its order events (`pending: true`) and, when it fills, the deal; a position update needs no line of its own.",
        "examples": [
          {
            "seq": 42,
            "id": "1790968290117:42",
            "what": "opened",
            "kind": "deal",
            "deal": {
              "ticket": 81200118,
              "order": 51830012,
              "position_id": 51830012,
              "symbol": "XAUUSD",
              "type": "buy",
              "entry": "in",
              "volume": 0.2,
              "price": 2385.0,
              "profit": 0.0,
              "commission": -0.7,
              "swap": 0.0,
              "fee": 0.0,
              "magic": 0,
              "comment": "breakout",
              "reason": "web",
              "time": 1790975498,
              "time_msc": 1790975498123
            },
            "balance": 10412.58,
            "credit": 0.0,
            "position": {
              "ticket": 51830012,
              "symbol": "XAUUSD",
              "side": "buy",
              "volume": 0.2,
              "price_open": 2385.0,
              "price_current": 2385.0,
              "sl": 2380.0,
              "tp": 2420.0,
              "profit": 0.0,
              "swap": 0.0,
              "commission": -0.7,
              "comment": "breakout",
              "magic": 0,
              "reason": "web",
              "identifier": 51830012,
              "time": 1790975498,
              "time_msc": 1790975498123,
              "time_update": 1790975498,
              "open": true
            }
          },
          {
            "seq": 41,
            "id": "1790968290117:41",
            "what": "placed",
            "kind": "order",
            "pending": true,
            "order": {
              "ticket": 51830020,
              "symbol": "XAUUSD",
              "type": "buy_limit",
              "side": "buy",
              "volume": 0.1,
              "volume_initial": 0.1,
              "price": 2365.0,
              "stop_limit": 0,
              "sl": 2350.0,
              "tp": 2410.0,
              "expiration": 0,
              "comment": "dip buy",
              "magic": 0,
              "reason": "web",
              "time_setup": 1790977698,
              "time_setup_msc": 1790977698412
            },
            "state": "placed"
          },
          {
            "seq": 45,
            "id": "1790968290117:45",
            "what": "filled",
            "kind": "order",
            "pending": false,
            "order": {
              "ticket": 51830031,
              "symbol": "XAUUSD",
              "type": "buy",
              "side": "buy",
              "volume": 0.0,
              "volume_initial": 0.1,
              "price": 2391.6,
              "stop_limit": 0,
              "sl": 2380.0,
              "tp": 2420.0,
              "expiration": 0,
              "comment": "breakout",
              "magic": 0,
              "reason": "web",
              "time_setup": 1790981179,
              "time_setup_msc": 1790981179261
            },
            "state": "filled"
          },
          {
            "seq": 43,
            "id": "1790968290117:43",
            "what": "updated",
            "kind": "position",
            "position": {
              "ticket": 51830012,
              "symbol": "XAUUSD",
              "side": "buy",
              "volume": 0.2,
              "price_open": 2385.0,
              "price_current": 2391.42,
              "sl": 2386.0,
              "tp": 2420.0,
              "profit": 128.4,
              "swap": -1.12,
              "commission": -1.4,
              "comment": "breakout",
              "magic": 0,
              "reason": "web",
              "identifier": 51830012,
              "time": 1790975498,
              "time_msc": 1790975498123,
              "time_update": 1790981102,
              "open": true
            }
          },
          {
            "seq": 47,
            "id": "1790968290117:47",
            "what": "closed",
            "kind": "deal",
            "deal": {
              "ticket": 81200152,
              "order": 51830050,
              "position_id": 51830012,
              "symbol": "XAUUSD",
              "type": "sell",
              "entry": "out",
              "volume": 0.2,
              "price": 2380.0,
              "profit": -100.0,
              "commission": -0.7,
              "swap": -1.12,
              "fee": 0.0,
              "magic": 0,
              "comment": "[sl 2380.00]",
              "reason": "sl",
              "time": 1790990841,
              "time_msc": 1790990841207
            },
            "balance": 10310.76,
            "credit": 0.0,
            "position": {
              "ticket": 51830012,
              "symbol": "XAUUSD",
              "side": "buy",
              "volume": 0.0,
              "price_open": 2385.0,
              "price_current": 2391.42,
              "sl": 2380.0,
              "tp": 2420.0,
              "profit": 128.4,
              "swap": -1.12,
              "commission": -1.4,
              "comment": "breakout",
              "magic": 0,
              "reason": "web",
              "identifier": 51830012,
              "time": 1790975498,
              "time_msc": 1790975498123,
              "time_update": 1790975498,
              "open": false
            }
          },
          {
            "seq": 48,
            "id": "1790968290117:48",
            "what": "closed",
            "kind": "deal",
            "deal": {
              "ticket": 81200152,
              "order": 51830050,
              "position_id": 51830012,
              "symbol": "XAUUSD",
              "type": "sell",
              "entry": "out",
              "volume": 0.2,
              "price": 2380.0,
              "profit": -100.0,
              "commission": -0.7,
              "swap": -1.12,
              "fee": 0.0,
              "magic": 0,
              "comment": "[sl 2380.00]",
              "reason": "sl",
              "time": 1790990841,
              "time_msc": 1790990841207
            },
            "caught_up": true
          }
        ]
      },
      "AccountSnapshot": {
        "type": "object",
        "properties": {
          "login": {
            "type": "integer",
            "description": "MT5 login number."
          },
          "name": {
            "type": "string",
            "description": "Account holder name at the broker."
          },
          "server": {
            "type": "string",
            "description": "Trade server name."
          },
          "company": {
            "type": "string",
            "description": "Broker company name."
          },
          "currency": {
            "type": "string",
            "description": "Deposit currency."
          },
          "leverage": {
            "type": "integer",
            "description": "Leverage, for example 200 for 1:200."
          },
          "balance": {
            "type": "number",
            "description": "Balance without open positions."
          },
          "credit": {
            "type": "number",
            "description": "Credit from the broker."
          },
          "profit": {
            "type": "number",
            "description": "Floating profit of open positions, live."
          },
          "equity": {
            "type": "number",
            "description": "balance + credit + profit, live."
          },
          "margin": {
            "type": "number",
            "description": "Margin in use, live."
          },
          "margin_free": {
            "type": "number",
            "description": "equity - margin."
          },
          "margin_level": {
            "type": "number",
            "description": "equity / margin x 100, in percent. 0 with no margin in use."
          },
          "margin_so_call": {
            "type": "number",
            "description": "Margin call level."
          },
          "margin_so_so": {
            "type": "number",
            "description": "Stop out level."
          },
          "trade_allowed": {
            "type": "boolean",
            "description": "Whether the broker allows trading on this account."
          },
          "demo": {
            "type": "boolean",
            "description": "True for a demo account."
          },
          "hedging": {
            "type": "boolean",
            "description": "True for a hedging account, false for netting."
          },
          "server_offset": {
            "type": "integer",
            "description": "Trade server clock, in seconds east of UTC. Subtract it from any market or trade time to get UTC. From the account record, read again at least hourly, and checked against live ticks (a tick's server time minus its arrival, to the quarter hour): when they disagree the ticks win while a tick agreed in the last 10 minutes, then the record. It is the offset now; times from before the broker's last summer-time switch were stamped with the old one."
          },
          "positions": {
            "type": "integer",
            "description": "Open positions."
          },
          "orders": {
            "type": "integer",
            "description": "Pending orders."
          },
          "time_ms": {
            "type": "integer",
            "description": "When it was computed, unix milliseconds (UTC)."
          }
        },
        "required": [
          "login",
          "name",
          "server",
          "company",
          "currency",
          "leverage",
          "balance",
          "credit",
          "profit",
          "equity",
          "margin",
          "margin_free",
          "margin_level",
          "margin_so_call",
          "margin_so_so",
          "trade_allowed",
          "demo",
          "hedging",
          "server_offset",
          "positions",
          "orders",
          "time_ms"
        ],
        "description": "The data of an `account` event (`events=account`): the account summary with live profit, equity and margin, right after the stream opens and then whenever a value changed, checked every 500 ms at most.",
        "examples": [
          {
            "login": 12345678,
            "name": "Demo Trader",
            "server": "Pepperstone-Demo",
            "company": "Pepperstone Group Limited",
            "currency": "USD",
            "leverage": 200,
            "balance": 10412.58,
            "credit": 0.0,
            "profit": 238.11,
            "equity": 10650.69,
            "margin": 878.93,
            "margin_free": 9771.76,
            "margin_level": 1211.78,
            "margin_so_call": 100.0,
            "margin_so_so": 50.0,
            "trade_allowed": true,
            "demo": true,
            "hedging": true,
            "server_offset": 10800,
            "positions": 3,
            "orders": 2,
            "time_ms": 1790981179473
          }
        ]
      },
      "PositionsSnapshot": {
        "type": "object",
        "properties": {
          "positions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Position"
            },
            "description": "Every open position with live profit and price_current."
          },
          "time_ms": {
            "type": "integer",
            "description": "When it was computed, unix milliseconds (UTC)."
          }
        },
        "required": [
          "positions",
          "time_ms"
        ],
        "description": "The data of a `positions` event (`events=positions`): every open position with live P/L, on the same 500 ms rhythm as `account`, only when something changed. A UI never computes P/L itself.",
        "examples": [
          {
            "positions": [
              {
                "ticket": 51830012,
                "symbol": "XAUUSD",
                "side": "buy",
                "volume": 0.2,
                "price_open": 2385.0,
                "price_current": 2391.42,
                "sl": 2380.0,
                "tp": 2420.0,
                "profit": 128.4,
                "swap": -1.12,
                "commission": -1.4,
                "comment": "breakout",
                "magic": 0,
                "reason": "web",
                "identifier": 51830012,
                "time": 1790975498,
                "time_msc": 1790975498123,
                "time_update": 1790975498
              }
            ],
            "time_ms": 1790981179473
          }
        ]
      },
      "OrdersSnapshot": {
        "type": "object",
        "properties": {
          "orders": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Order"
            },
            "description": "Every pending order (limit, stop, stop limit), as `GET /orders` lists them."
          },
          "time_ms": {
            "type": "integer",
            "description": "When it was read, unix milliseconds (UTC)."
          }
        },
        "required": [
          "orders",
          "time_ms"
        ],
        "description": "The data of an `orders` event (`events=orders`): once right after the first status, then whenever a broker trade push added, changed or removed a pending order (and after a reconnect when the book changed meanwhile). Sent only when the list differs from the last one sent; orders carry no live price, so ticks never send one. Redraw from each snapshot.",
        "examples": [
          {
            "orders": [
              {
                "ticket": 51830020,
                "symbol": "XAUUSD",
                "type": "buy_limit",
                "side": "buy",
                "volume": 0.1,
                "volume_initial": 0.1,
                "price": 2365.0,
                "stop_limit": 0,
                "sl": 2350.0,
                "tp": 2410.0,
                "expiration": 0,
                "comment": "dip buy",
                "magic": 0,
                "reason": "web",
                "time_setup": 1790977698,
                "time_setup_msc": 1790977698412
              }
            ],
            "time_ms": 1790977698430
          },
          {
            "orders": [],
            "time_ms": 1790981179473
          }
        ]
      },
      "StreamConnection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "A number for the stream, unique until the server restarts."
          },
          "kind": {
            "type": "string",
            "description": "sse for /stream, ws for /ws.",
            "enum": [
              "sse",
              "ws"
            ]
          },
          "who": {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "description": "key, or dashboard for the dashboard's own streams.",
                "enum": [
                  "key",
                  "dashboard"
                ]
              },
              "key_id": {
                "type": "string",
                "description": "The key's id (absent for the dashboard)."
              },
              "name": {
                "type": "string",
                "description": "The key's name, or dashboard."
              }
            },
            "required": [
              "kind",
              "name"
            ]
          },
          "ip": {
            "type": "string",
            "description": "The client's address (behind --trust-proxy, the proxy header's)."
          },
          "user_agent": {
            "type": "string",
            "description": "The client's User-Agent (cut to 200 characters)."
          },
          "account": {
            "type": "string",
            "description": "The account streamed."
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The symbols it receives ticks for (they change with WebSocket subscribe and unsubscribe)."
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "ticks",
                "bars",
                "trades",
                "account",
                "positions",
                "orders"
              ]
            },
            "description": "What it asked for with events=."
          },
          "batch_ms": {
            "type": "integer",
            "description": "SSE batch window asked for; 0 writes every frame at once."
          },
          "opened_at": {
            "type": "integer",
            "description": "When it opened, unix milliseconds (UTC)."
          },
          "sent": {
            "type": "object",
            "properties": {
              "messages": {
                "type": "integer",
                "description": "Everything delivered except heartbeats: ticks, events and the rest (status, subscribed, command answers)."
              },
              "bytes": {
                "type": "integer",
                "description": "Bytes written, heartbeats included."
              },
              "ticks": {
                "type": "integer",
                "description": "Tick messages."
              },
              "events": {
                "type": "integer",
                "description": "trade, account, positions and orders messages."
              }
            },
            "required": [
              "messages",
              "bytes",
              "ticks",
              "events"
            ]
          },
          "last_sent_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When the last message went out, unix milliseconds (UTC), to about 0.1 s. null before the first."
          },
          "rate_per_s": {
            "type": "number",
            "description": "Messages a second over the last 10 s (or over the stream's life when it is younger)."
          },
          "coalesced": {
            "type": "integer",
            "description": "Ticks this stream never saw because it fell behind (the newest per symbol was kept)."
          }
        },
        "required": [
          "id",
          "kind",
          "who",
          "ip",
          "user_agent",
          "account",
          "symbols",
          "events",
          "batch_ms",
          "opened_at",
          "sent",
          "last_sent_at",
          "rate_per_s",
          "coalesced"
        ],
        "description": "An open stream and what it has sent.",
        "examples": [
          {
            "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
          }
        ]
      },
      "KeyTraffic": {
        "type": "object",
        "properties": {
          "key_id": {
            "type": "string",
            "description": "Key id."
          },
          "name": {
            "type": "string",
            "description": "Key name."
          },
          "scope": {
            "type": "string",
            "description": "read, trade or admin.",
            "enum": [
              "read",
              "trade",
              "admin"
            ]
          },
          "accounts": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            },
            "description": "Accounts it is limited to; null = every account."
          },
          "streams_open": {
            "type": "integer",
            "description": "Streams it has open now."
          },
          "stream_bytes": {
            "type": "integer",
            "description": "Bytes its open streams have sent."
          },
          "requests_1h": {
            "type": "integer",
            "description": "Requests in the last hour."
          },
          "requests_24h": {
            "type": "integer",
            "description": "Requests in the last 24 hours (since the start, if that is later)."
          },
          "errors_1h": {
            "type": "integer",
            "description": "Requests in the last hour answered 400 or above."
          },
          "bytes_out_1h": {
            "type": "integer",
            "description": "Response body bytes in the last hour (streams not included)."
          },
          "last_request_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Its last request, unix milliseconds (UTC). null if none since the start."
          },
          "last_ip": {
            "type": [
              "string",
              "null"
            ],
            "description": "The address of its last request."
          },
          "top_routes_1h": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "route": {
                  "type": "string",
                  "description": "Method and route template."
                },
                "count": {
                  "type": "integer",
                  "description": "Requests in the last hour."
                }
              },
              "required": [
                "route",
                "count"
              ]
            },
            "description": "Its busiest routes in the last hour, at most 5."
          }
        },
        "required": [
          "key_id",
          "name",
          "scope",
          "accounts",
          "streams_open",
          "stream_bytes",
          "requests_1h",
          "requests_24h",
          "errors_1h",
          "bytes_out_1h",
          "last_request_at",
          "last_ip",
          "top_routes_1h"
        ],
        "description": "One key's traffic since the server started (zeros when unused).",
        "examples": [
          {
            "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
              }
            ]
          }
        ]
      },
      "Connections": {
        "type": "object",
        "properties": {
          "time_ms": {
            "type": "integer",
            "description": "Now, unix milliseconds (UTC)."
          },
          "since_ms": {
            "type": "integer",
            "description": "When the server started: every counter here begins then; nothing is kept across a restart."
          },
          "streams": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StreamConnection"
            },
            "description": "Open streams, newest first."
          },
          "keys": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/KeyTraffic"
            },
            "description": "Every key in the keys table."
          },
          "dashboard": {
            "type": "object",
            "properties": {
              "sessions_active": {
                "type": "integer",
                "description": "Dashboard sessions signed in."
              },
              "streams_open": {
                "type": "integer",
                "description": "Streams the dashboard has open."
              },
              "stream_bytes": {
                "type": "integer",
                "description": "Bytes those streams have sent."
              },
              "requests_1h": {
                "type": "integer",
                "description": "Dashboard requests in the last hour."
              },
              "requests_24h": {
                "type": "integer",
                "description": "Dashboard requests in the last 24 hours."
              },
              "errors_1h": {
                "type": "integer",
                "description": "Of them, answered 400 or above."
              },
              "bytes_out_1h": {
                "type": "integer",
                "description": "Response body bytes in the last hour."
              },
              "last_request_at": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The dashboard's last request, unix milliseconds (UTC)."
              }
            },
            "required": [
              "sessions_active",
              "streams_open",
              "stream_bytes",
              "requests_1h",
              "requests_24h",
              "errors_1h",
              "bytes_out_1h",
              "last_request_at"
            ]
          }
        },
        "required": [
          "time_ms",
          "since_ms",
          "streams",
          "keys",
          "dashboard"
        ],
        "description": "Who is connected and what they receive, live and in memory since the server started. Key secrets never appear.",
        "examples": [
          {
            "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
            }
          }
        ]
      },
      "TrafficRequest": {
        "type": "object",
        "properties": {
          "at": {
            "type": "integer",
            "description": "When it was answered, unix milliseconds (UTC)."
          },
          "method": {
            "type": "string",
            "description": "HTTP method."
          },
          "route": {
            "type": "string",
            "description": "Method and the route template it matched, for example GET /api/v1/accounts/{id}/quotes; (no route) when none matched."
          },
          "path": {
            "type": "string",
            "description": "The path asked for, with its query (key= removed, cut to 300 characters)."
          },
          "status": {
            "type": "integer",
            "description": "HTTP status answered."
          },
          "latency_ms": {
            "type": "number",
            "description": "Time to the response's headers, milliseconds."
          },
          "bytes": {
            "type": "integer",
            "description": "Response body bytes (0 for a stream; see its own counters)."
          },
          "ip": {
            "type": "string",
            "description": "The client's address."
          },
          "account": {
            "type": [
              "string",
              "null"
            ],
            "description": "The account in the path, if any."
          }
        },
        "required": [
          "at",
          "method",
          "route",
          "path",
          "status",
          "latency_ms",
          "bytes",
          "ip",
          "account"
        ],
        "examples": [
          {
            "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"
          }
        ]
      },
      "KeyTrafficLog": {
        "type": "object",
        "properties": {
          "key_id": {
            "type": "string",
            "description": "Key id."
          },
          "name": {
            "type": "string",
            "description": "Key name."
          },
          "time_ms": {
            "type": "integer",
            "description": "Now, unix milliseconds (UTC)."
          },
          "since_ms": {
            "type": "integer",
            "description": "When the server started."
          },
          "requests": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TrafficRequest"
            },
            "description": "Its last requests, newest first (up to 500 are kept)."
          },
          "streams": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StreamConnection"
            },
            "description": "Its open streams."
          }
        },
        "required": [
          "key_id",
          "name",
          "time_ms",
          "since_ms",
          "requests",
          "streams"
        ],
        "examples": [
          {
            "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
              }
            ]
          }
        ]
      },
      "WsMessage": {
        "description": "What the server sends on the WebSocket, one JSON object per message, told apart by type. First a status, then subscribed, then any trade events replayed for `after=` (or a resync), then ticks (and the trade, account, positions and orders events asked for with `events=`; orders right after subscribed and the replay); status again whenever connected changes.",
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "const": "status",
                "description": "Connection state."
              },
              "connected": {
                "type": "boolean",
                "description": "Whether the account is connected to the broker."
              },
              "ping_ms": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Last heartbeat round trip in milliseconds."
              },
              "id": {
                "type": "string",
                "description": "Only on the first status, when the socket follows trades or orders: where it starts in the account's trade event numbering (as on SSE)."
              },
              "reason": {
                "type": "string",
                "description": "Only on the last status before the socket closes: account changed (deleted, or logs in with new details), server stopping, or (0.6.0) key revoked, key changed, signed out.",
                "enum": [
                  "account changed",
                  "server stopping",
                  "key revoked",
                  "key changed",
                  "signed out"
                ]
              }
            },
            "required": [
              "type",
              "connected",
              "ping_ms"
            ],
            "title": "status"
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "const": "subscribed",
                "description": "The symbols now streaming, after the open or a subscribe/unsubscribe."
              },
              "symbols": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Every symbol on this socket."
              }
            },
            "required": [
              "type",
              "symbols"
            ],
            "title": "subscribed"
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "const": "tick",
                "description": "A price change."
              },
              "symbol": {
                "type": "string",
                "description": "Symbol name."
              },
              "bid": {
                "type": "number",
                "description": "Bid price."
              },
              "ask": {
                "type": "number",
                "description": "Ask price."
              },
              "last": {
                "type": "number",
                "description": "Last deal price. 0 for most forex and CFD symbols."
              },
              "time_msc": {
                "type": "integer",
                "description": "Unix milliseconds, trade server clock."
              }
            },
            "required": [
              "type",
              "symbol",
              "bid",
              "ask",
              "last",
              "time_msc"
            ],
            "title": "tick"
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "gap",
                    "description": "Ticks this socket missed."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/Gap"
              }
            ],
            "title": "gap",
            "description": "A Gap with `type: \"gap\"` (0.7.0)."
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "bar",
                    "description": "A bar of a series (with events=bars)."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/Bar"
              }
            ],
            "title": "bar",
            "description": "A Bar with `type: \"bar\"` (0.7.0)."
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "bars_gap",
                    "description": "Bars a series cannot send."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/BarsGap"
              }
            ],
            "title": "bars_gap",
            "description": "A BarsGap with `type: \"bars_gap\"` (0.7.0)."
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "const": "bars",
                "description": "The bar series now on the socket, after a bars or unbars message (0.7.0)."
              },
              "series": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Every series, SYMBOL:TF."
              }
            },
            "required": [
              "type",
              "series"
            ],
            "title": "bars"
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "trade",
                    "description": "A broker trade push (with events=trades)."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/TradeEvent"
              }
            ],
            "title": "trade",
            "description": "A TradeEvent with `type: \"trade\"`."
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "resync",
                    "description": "Missed trade events cannot be replayed (with events=trades)."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/Resync"
              }
            ],
            "title": "resync",
            "description": "A Resync with `type: \"resync\"`: read positions, orders and deals again."
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "account",
                    "description": "The account summary, live (with events=account)."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/AccountSnapshot"
              }
            ],
            "title": "account",
            "description": "An AccountSnapshot with `type: \"account\"`."
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "positions",
                    "description": "Every open position, live (with events=positions)."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/PositionsSnapshot"
              }
            ],
            "title": "positions",
            "description": "A PositionsSnapshot with `type: \"positions\"`."
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "orders",
                    "description": "Every pending order (with events=orders)."
                  }
                },
                "required": [
                  "type"
                ]
              },
              {
                "$ref": "#/components/schemas/OrdersSnapshot"
              }
            ],
            "title": "orders",
            "description": "An OrdersSnapshot with `type: \"orders\"`."
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "const": "error",
                "description": "A message the server could not act on."
              },
              "message": {
                "type": "string",
                "description": "What went wrong."
              }
            },
            "required": [
              "type",
              "message"
            ],
            "title": "error"
          }
        ],
        "examples": [
          {
            "type": "status",
            "connected": true,
            "ping_ms": 14.2,
            "id": "1790968290117:40"
          },
          {
            "type": "subscribed",
            "symbols": [
              "EURUSD",
              "XAUUSD"
            ]
          },
          {
            "type": "tick",
            "symbol": "XAUUSD",
            "bid": 2391.42,
            "ask": 2391.6,
            "last": 0,
            "time_msc": 1790981179473
          },
          {
            "seq": 41,
            "id": "1790968290117:41",
            "what": "placed",
            "kind": "order",
            "pending": true,
            "order": {
              "ticket": 51830020,
              "symbol": "XAUUSD",
              "type": "buy_limit",
              "side": "buy",
              "volume": 0.1,
              "volume_initial": 0.1,
              "price": 2365.0,
              "stop_limit": 0,
              "sl": 2350.0,
              "tp": 2410.0,
              "expiration": 0,
              "comment": "dip buy",
              "magic": 0,
              "reason": "web",
              "time_setup": 1790977698,
              "time_setup_msc": 1790977698412
            },
            "state": "placed",
            "type": "trade"
          }
        ]
      },
      "WsCommand": {
        "type": "object",
        "properties": {
          "subscribe": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Symbols to add (at most 200 on one socket)."
          },
          "unsubscribe": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Symbols to drop. Applied before subscribe when both are sent."
          },
          "bars": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Bar series to add, SYMBOL:TF (0.7.0; the socket must be opened with events=bars). At most 100 a socket."
          },
          "unbars": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Bar series to drop (0.7.0)."
          }
        },
        "description": "What a client may send on the WebSocket. The answer is subscribed with the whole list, or an error.",
        "examples": [
          {
            "subscribe": [
              "GBPUSD"
            ]
          },
          {
            "unsubscribe": [
              "EURUSD"
            ]
          }
        ]
      },
      "Position": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "integer",
            "description": "Position ticket."
          },
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "side": {
            "type": "string",
            "description": "Direction.",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots."
          },
          "price_open": {
            "type": "number",
            "description": "Open price."
          },
          "price_current": {
            "type": "number",
            "description": "Current close price (bid for a buy, ask for a sell)."
          },
          "sl": {
            "type": "number",
            "description": "Stop loss price, 0 when none."
          },
          "tp": {
            "type": "number",
            "description": "Take profit price, 0 when none."
          },
          "profit": {
            "type": "number",
            "description": "Floating profit in the deposit currency, live."
          },
          "swap": {
            "type": "number",
            "description": "Swap so far."
          },
          "commission": {
            "type": "number",
            "description": "Commission so far."
          },
          "comment": {
            "type": "string",
            "description": "Comment. The broker keeps 31 characters; for an order sent through Termless with a longer comment, Termless keeps the full text and puts it back here when the broker's is its start."
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol cannot send one, so the broker stores 0; for an order sent through Termless with a magic number, Termless keeps it and puts it back here (the broker's own wins when it is not 0)."
          },
          "reason": {
            "type": "string",
            "description": "Why it came about: client (a desktop terminal), mobile, web (anything sent through Termless), expert, sl and tp (closed at the stop loss or take profit), stop_out, and rarer ones. The wire carries the trade server's own numbers (web 17, SL 3, TP 4), not the official DEAL_REASON_* values, so read the word.",
            "enum": [
              "client",
              "mobile",
              "web",
              "expert",
              "sl",
              "tp",
              "stop_out",
              "rollover",
              "vmargin",
              "split",
              "corporate_action",
              "dealer",
              "gateway",
              "signal",
              "settlement",
              "transfer",
              "sync",
              "external_client",
              "external_service",
              "migration",
              "unknown"
            ]
          },
          "identifier": {
            "type": "integer",
            "description": "Position id; the deals of this position carry it as position_id."
          },
          "time": {
            "type": "integer",
            "description": "Open time, unix seconds, trade server clock."
          },
          "time_msc": {
            "type": "integer",
            "description": "Open time, unix milliseconds, trade server clock."
          },
          "time_update": {
            "type": "integer",
            "description": "Last change, unix seconds, trade server clock."
          }
        },
        "required": [
          "ticket",
          "symbol",
          "side",
          "volume",
          "price_open",
          "price_current",
          "sl",
          "tp",
          "profit",
          "swap",
          "commission",
          "comment",
          "magic",
          "reason",
          "identifier",
          "time",
          "time_msc",
          "time_update"
        ],
        "examples": [
          {
            "ticket": 51830012,
            "symbol": "XAUUSD",
            "side": "buy",
            "volume": 0.2,
            "price_open": 2385.0,
            "price_current": 2391.42,
            "sl": 2380.0,
            "tp": 2420.0,
            "profit": 128.4,
            "swap": -1.12,
            "commission": -1.4,
            "comment": "breakout",
            "magic": 0,
            "reason": "web",
            "identifier": 51830012,
            "time": 1790975498,
            "time_msc": 1790975498123,
            "time_update": 1790975498
          }
        ]
      },
      "Order": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "integer",
            "description": "Order ticket."
          },
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "type": {
            "type": "string",
            "description": "Order type. `GET /orders` and `orders` events list pending orders only (limit, stop, stop limit); in a `trade` event a market order is `buy` or `sell` (with `pending: false`).",
            "enum": [
              "buy_limit",
              "sell_limit",
              "buy_stop",
              "sell_stop",
              "buy_stop_limit",
              "sell_stop_limit",
              "buy",
              "sell",
              "close_by"
            ]
          },
          "side": {
            "type": "string",
            "description": "Direction.",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots still to fill."
          },
          "volume_initial": {
            "type": "number",
            "description": "Lots when placed."
          },
          "price": {
            "type": "number",
            "description": "Trigger price."
          },
          "stop_limit": {
            "type": "number",
            "description": "Limit price for stop limit orders, 0 otherwise."
          },
          "sl": {
            "type": "number",
            "description": "Stop loss price, 0 when none."
          },
          "tp": {
            "type": "number",
            "description": "Take profit price, 0 when none."
          },
          "expiration": {
            "type": "integer",
            "description": "Expiry, unix seconds, trade server clock. 0 = good till cancelled."
          },
          "comment": {
            "type": "string",
            "description": "Comment. The broker keeps 31 characters; for an order sent through Termless with a longer comment, Termless keeps the full text and puts it back here when the broker's is its start."
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol cannot send one, so the broker stores 0; for an order sent through Termless with a magic number, Termless keeps it and puts it back here (the broker's own wins when it is not 0). An order that closed a tagged position (its stop, its target) gets the magic but keeps its own comment."
          },
          "reason": {
            "type": "string",
            "description": "Why it came about: client (a desktop terminal), mobile, web (anything sent through Termless), expert, sl and tp (closed at the stop loss or take profit), stop_out, and rarer ones. The wire carries the trade server's own numbers (web 17, SL 3, TP 4), not the official DEAL_REASON_* values, so read the word.",
            "enum": [
              "client",
              "mobile",
              "web",
              "expert",
              "sl",
              "tp",
              "stop_out",
              "rollover",
              "vmargin",
              "split",
              "corporate_action",
              "dealer",
              "gateway",
              "signal",
              "settlement",
              "transfer",
              "sync",
              "external_client",
              "external_service",
              "migration",
              "unknown"
            ]
          },
          "time_setup": {
            "type": "integer",
            "description": "When the order was placed, unix seconds, trade server clock."
          },
          "time_setup_msc": {
            "type": "integer",
            "description": "When the order was placed, unix milliseconds, trade server clock."
          }
        },
        "required": [
          "ticket",
          "symbol",
          "type",
          "side",
          "volume",
          "volume_initial",
          "price",
          "stop_limit",
          "sl",
          "tp",
          "expiration",
          "comment",
          "magic",
          "reason",
          "time_setup",
          "time_setup_msc"
        ],
        "examples": [
          {
            "ticket": 51830020,
            "symbol": "XAUUSD",
            "type": "buy_limit",
            "side": "buy",
            "volume": 0.1,
            "volume_initial": 0.1,
            "price": 2365.0,
            "stop_limit": 0,
            "sl": 2350.0,
            "tp": 2410.0,
            "expiration": 0,
            "comment": "dip buy",
            "magic": 0,
            "reason": "web",
            "time_setup": 1790977698,
            "time_setup_msc": 1790977698412
          }
        ]
      },
      "HistoryOrder": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "integer",
            "description": "Order ticket."
          },
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "type": {
            "type": "string",
            "description": "Order type. Market orders are filed here too: buy, sell or close_by.",
            "enum": [
              "buy_limit",
              "sell_limit",
              "buy_stop",
              "sell_stop",
              "buy_stop_limit",
              "sell_stop_limit",
              "buy",
              "sell",
              "close_by"
            ]
          },
          "side": {
            "type": "string",
            "description": "Direction.",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots left unfilled when it left the book (0 for a filled order)."
          },
          "volume_initial": {
            "type": "number",
            "description": "Lots when placed."
          },
          "price": {
            "type": "number",
            "description": "Trigger price."
          },
          "stop_limit": {
            "type": "number",
            "description": "Limit price for stop limit orders, 0 otherwise."
          },
          "sl": {
            "type": "number",
            "description": "Stop loss price, 0 when none."
          },
          "tp": {
            "type": "number",
            "description": "Take profit price, 0 when none."
          },
          "expiration": {
            "type": "integer",
            "description": "Expiry, unix seconds, trade server clock. 0 = good till cancelled."
          },
          "comment": {
            "type": "string",
            "description": "Comment. The broker keeps 31 characters; for an order sent through Termless with a longer comment, Termless keeps the full text and puts it back here when the broker's is its start."
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol cannot send one, so the broker stores 0; for an order sent through Termless with a magic number, Termless keeps it and puts it back here (the broker's own wins when it is not 0). An order that closed a tagged position (its stop, its target) gets the magic but keeps its own comment."
          },
          "reason": {
            "type": "string",
            "description": "Why it came about: client (a desktop terminal), mobile, web (anything sent through Termless), expert, sl and tp (closed at the stop loss or take profit), stop_out, and rarer ones. The wire carries the trade server's own numbers (web 17, SL 3, TP 4), not the official DEAL_REASON_* values, so read the word.",
            "enum": [
              "client",
              "mobile",
              "web",
              "expert",
              "sl",
              "tp",
              "stop_out",
              "rollover",
              "vmargin",
              "split",
              "corporate_action",
              "dealer",
              "gateway",
              "signal",
              "settlement",
              "transfer",
              "sync",
              "external_client",
              "external_service",
              "migration",
              "unknown"
            ]
          },
          "time_setup": {
            "type": "integer",
            "description": "When the order was placed, unix seconds, trade server clock."
          },
          "time_setup_msc": {
            "type": "integer",
            "description": "When the order was placed, unix milliseconds, trade server clock."
          },
          "state": {
            "type": "string",
            "description": "The order's MetaTrader state when it left the book: filled, cancelled, expired, rejected or partial (partly filled); started, placed and request are states an order passes through on its way; unknown only for a value MetaTrader does not define.",
            "enum": [
              "started",
              "placed",
              "cancelled",
              "partial",
              "filled",
              "rejected",
              "expired",
              "request",
              "unknown"
            ]
          },
          "time_done": {
            "type": "integer",
            "description": "When it left the book, unix seconds, trade server clock."
          },
          "time_done_msc": {
            "type": "integer",
            "description": "When it left the book, unix milliseconds, trade server clock."
          },
          "position_id": {
            "type": "integer",
            "description": "The position it opened or closed; 0 for an order that never filled."
          }
        },
        "required": [
          "ticket",
          "symbol",
          "type",
          "side",
          "volume",
          "volume_initial",
          "price",
          "stop_limit",
          "sl",
          "tp",
          "expiration",
          "comment",
          "magic",
          "reason",
          "time_setup",
          "time_setup_msc",
          "state",
          "time_done",
          "time_done_msc",
          "position_id"
        ],
        "description": "An order that left the book (GET /orders/history): the order shape plus how and when it ended and its position.",
        "examples": [
          {
            "ticket": 51830012,
            "symbol": "XAUUSD",
            "type": "buy",
            "side": "buy",
            "volume": 0.0,
            "volume_initial": 0.2,
            "price": 2385.0,
            "stop_limit": 0,
            "sl": 2380.0,
            "tp": 2420.0,
            "expiration": 0,
            "comment": "breakout",
            "magic": 0,
            "reason": "web",
            "time_setup": 1790975498,
            "time_setup_msc": 1790975497981,
            "state": "filled",
            "time_done": 1790975498,
            "time_done_msc": 1790975498123,
            "position_id": 51830012
          },
          {
            "ticket": 51830007,
            "symbol": "XAUUSD",
            "type": "sell_stop",
            "side": "sell",
            "volume": 0.1,
            "volume_initial": 0.1,
            "price": 2371.5,
            "stop_limit": 0,
            "sl": 2380.0,
            "tp": 2350.0,
            "expiration": 0,
            "comment": "breakdown",
            "magic": 0,
            "reason": "web",
            "time_setup": 1790962100,
            "time_setup_msc": 1790962100544,
            "state": "cancelled",
            "time_done": 1790970120,
            "time_done_msc": 1790970120310,
            "position_id": 0
          }
        ]
      },
      "Deal": {
        "type": "object",
        "properties": {
          "ticket": {
            "type": "integer",
            "description": "Deal ticket."
          },
          "order": {
            "type": "integer",
            "description": "Order that made the deal."
          },
          "position_id": {
            "type": "integer",
            "description": "Position the deal belongs to (its identifier)."
          },
          "symbol": {
            "type": "string",
            "description": "Symbol name. Empty for balance operations."
          },
          "type": {
            "type": "string",
            "description": "The MetaTrader deal type, lowercase. unknown only for a value MetaTrader does not define.",
            "enum": [
              "buy",
              "sell",
              "balance",
              "credit",
              "charge",
              "correction",
              "bonus",
              "commission",
              "commission_daily",
              "commission_monthly",
              "commission_agent_daily",
              "commission_agent_monthly",
              "interest",
              "buy_canceled",
              "sell_canceled",
              "dividend",
              "dividend_franked",
              "tax",
              "unknown"
            ]
          },
          "entry": {
            "type": "string",
            "description": "in opens, out closes, inout reverses, out_by closes by an opposite position. unknown only for a value MetaTrader does not define.",
            "enum": [
              "in",
              "out",
              "inout",
              "out_by",
              "unknown"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots."
          },
          "price": {
            "type": "number",
            "description": "Deal price."
          },
          "profit": {
            "type": "number",
            "description": "Realised profit in the deposit currency."
          },
          "commission": {
            "type": "number",
            "description": "Commission."
          },
          "swap": {
            "type": "number",
            "description": "Swap."
          },
          "fee": {
            "type": "number",
            "description": "Fee."
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol cannot send one, so the broker stores 0; for an order sent through Termless with a magic number, Termless keeps it and puts it back here (the broker's own wins when it is not 0). A closing deal (a close at the stop loss or take profit included) gets the magic of the position it closed."
          },
          "comment": {
            "type": "string",
            "description": "Comment. The opening deal of an order sent through Termless with a comment past 31 characters gets the full text back; a closing deal keeps its own (IC Markets and Pepperstone write [sl 4129.45] or [tp ...] there on a close by stop, but read reason)."
          },
          "reason": {
            "type": "string",
            "description": "Why it came about: client (a desktop terminal), mobile, web (anything sent through Termless), expert, sl and tp (closed at the stop loss or take profit), stop_out, and rarer ones. The wire carries the trade server's own numbers (web 17, SL 3, TP 4), not the official DEAL_REASON_* values, so read the word.",
            "enum": [
              "client",
              "mobile",
              "web",
              "expert",
              "sl",
              "tp",
              "stop_out",
              "rollover",
              "vmargin",
              "split",
              "corporate_action",
              "dealer",
              "gateway",
              "signal",
              "settlement",
              "transfer",
              "sync",
              "external_client",
              "external_service",
              "migration",
              "unknown"
            ]
          },
          "time": {
            "type": "integer",
            "description": "Unix seconds, trade server clock."
          },
          "time_msc": {
            "type": "integer",
            "description": "Unix milliseconds, trade server clock."
          }
        },
        "required": [
          "ticket",
          "order",
          "position_id",
          "symbol",
          "type",
          "entry",
          "volume",
          "price",
          "profit",
          "commission",
          "swap",
          "fee",
          "magic",
          "comment",
          "reason",
          "time",
          "time_msc"
        ],
        "examples": [
          {
            "ticket": 81200118,
            "order": 51830012,
            "position_id": 51830012,
            "symbol": "XAUUSD",
            "type": "buy",
            "entry": "in",
            "volume": 0.2,
            "price": 2385.0,
            "profit": 0.0,
            "commission": -0.7,
            "swap": 0.0,
            "fee": 0.0,
            "magic": 0,
            "comment": "breakout",
            "reason": "web",
            "time": 1790975498,
            "time_msc": 1790975498123
          },
          {
            "ticket": 81200152,
            "order": 51830050,
            "position_id": 51830012,
            "symbol": "XAUUSD",
            "type": "sell",
            "entry": "out",
            "volume": 0.2,
            "price": 2380.0,
            "profit": -100.0,
            "commission": -0.7,
            "swap": -1.12,
            "fee": 0.0,
            "magic": 0,
            "comment": "[sl 2380.00]",
            "reason": "sl",
            "time": 1790990841,
            "time_msc": 1790990841207
          }
        ]
      },
      "Calc": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name, as the broker spells it."
          },
          "side": {
            "type": "string",
            "description": "Direction.",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "type": {
            "type": "string",
            "description": "The MetaTrader order type the side and type make.",
            "enum": [
              "buy",
              "sell",
              "buy_limit",
              "sell_limit",
              "buy_stop",
              "sell_stop",
              "buy_stop_limit",
              "sell_stop_limit"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots."
          },
          "price": {
            "type": "number",
            "description": "The open price used: the one asked for, else the current ask for a buy and bid for a sell."
          },
          "margin": {
            "type": [
              "number",
              "null"
            ],
            "description": "The margin the trade needs once it is open, at price, in the account currency, rounded to its digits (order_calc_margin with the market type of its side): for a pending type, what the position needs when the order fills. null when no symbol converts the margin currency to the account's."
          },
          "margin_pending": {
            "type": [
              "number",
              "null"
            ],
            "description": "For a pending type: what the broker holds while the order waits (its type's own rate, margin_rates in the spec; 0 at the brokers seen, so nothing). null for a market order, or when no symbol converts the margin currency."
          },
          "close": {
            "type": [
              "number",
              "null"
            ],
            "description": "The closing price asked for; null without one."
          },
          "profit": {
            "type": [
              "number",
              "null"
            ],
            "description": "What the order makes from price to close, in the account currency, rounded to its digits (order_calc_profit). null without close, or when no symbol converts the profit currency to the account's."
          },
          "currency": {
            "type": "string",
            "description": "The account currency the numbers are in."
          }
        },
        "required": [
          "symbol",
          "side",
          "type",
          "volume",
          "price",
          "margin",
          "margin_pending",
          "close",
          "profit",
          "currency"
        ],
        "description": "order_calc_margin and order_calc_profit in one answer (GET /calc).",
        "examples": [
          {
            "symbol": "XAUUSD",
            "side": "buy",
            "type": "buy",
            "volume": 0.1,
            "price": 2391.6,
            "margin": 119.58,
            "margin_pending": null,
            "close": 2400.0,
            "profit": 84.0,
            "currency": "USD"
          },
          {
            "symbol": "XAUUSD",
            "side": "buy",
            "type": "buy_limit",
            "volume": 0.1,
            "price": 2365.0,
            "margin": 118.25,
            "margin_pending": 0.0,
            "close": null,
            "profit": null,
            "currency": "USD"
          }
        ]
      },
      "OrderCheck": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "description": "True when retcode is 0: sent now, the order would pass these checks."
          },
          "retcode": {
            "type": "integer",
            "description": "0 when every check passes, else the first that failed: 10014 invalid volume, 10017 trading disabled, 10044 close only, 10042 long only, 10043 short only, 10018 market closed, 10015 invalid price (a pending price on the wrong side of the market), 10016 invalid stops (a stop-loss or take-profit on the wrong side of its price or closer than stops_level), 10019 not enough money.",
            "enum": [
              0,
              10014,
              10017,
              10042,
              10043,
              10044,
              10018,
              10015,
              10016,
              10019
            ]
          },
          "comment": {
            "type": "string",
            "description": "The result in words.",
            "enum": [
              "Done",
              "Invalid volume",
              "Trade disabled",
              "Only position closing is allowed",
              "Only long positions are allowed",
              "Only short positions are allowed",
              "Market closed",
              "Invalid price",
              "Invalid stops",
              "No money"
            ]
          },
          "balance": {
            "type": "number",
            "description": "Balance now."
          },
          "equity": {
            "type": "number",
            "description": "Equity now, live."
          },
          "profit": {
            "type": "number",
            "description": "Floating profit now, live."
          },
          "margin": {
            "type": "number",
            "description": "Margin in use with the order (includes request_margin)."
          },
          "margin_free": {
            "type": "number",
            "description": "equity - margin, with the order. Below 0 is 10019 for an order that opens something."
          },
          "margin_level": {
            "type": "number",
            "description": "equity / margin x 100 with the order, in percent. 0 with no margin."
          },
          "request_margin": {
            "type": "number",
            "description": "The margin the order itself needs: for a pending order what the broker holds while it waits (usually 0). 0 for an action that opens nothing, and when an earlier check failed."
          }
        },
        "required": [
          "ok",
          "retcode",
          "comment",
          "balance",
          "equity",
          "profit",
          "margin",
          "margin_free",
          "margin_level",
          "request_margin"
        ],
        "description": "What sending an order_send request would do to the account (POST /order_check), in the account currency. The order is not sent.",
        "examples": [
          {
            "ok": true,
            "retcode": 0,
            "comment": "Done",
            "balance": 10412.58,
            "equity": 10650.69,
            "profit": 238.11,
            "margin": 998.51,
            "margin_free": 9652.18,
            "margin_level": 1066.66,
            "request_margin": 119.58
          },
          {
            "ok": false,
            "retcode": 10014,
            "comment": "Invalid volume",
            "balance": 10412.58,
            "equity": 10650.69,
            "profit": 238.11,
            "margin": 878.93,
            "margin_free": 9771.76,
            "margin_level": 1211.78,
            "request_margin": 0.0
          },
          {
            "ok": false,
            "retcode": 10016,
            "comment": "Invalid stops",
            "balance": 10412.58,
            "equity": 10650.69,
            "profit": 238.11,
            "margin": 878.93,
            "margin_free": 9771.76,
            "margin_level": 1211.78,
            "request_margin": 0.0
          }
        ]
      },
      "TradeResult": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "description": "True when the broker placed (10008), did (10009) or partly did (10010) the request. Test this, not one code: brokers answer a placed pending order with 10008 or 10009."
          },
          "retcode": {
            "type": "integer",
            "description": "MetaTrader return code. 10009 = done, 10008 = placed. See x-retcodes for the rest."
          },
          "retcode_text": {
            "type": "string",
            "description": "The return code in words."
          },
          "deal": {
            "type": "integer",
            "description": "Deal ticket, 0 when no deal was made."
          },
          "order": {
            "type": "integer",
            "description": "Order ticket."
          },
          "volume": {
            "type": "number",
            "description": "Lots done."
          },
          "price": {
            "type": "number",
            "description": "Price done."
          },
          "bid": {
            "type": "number",
            "description": "Bid when the broker handled the request."
          },
          "ask": {
            "type": "number",
            "description": "Ask when the broker handled the request."
          },
          "comment": {
            "type": "string",
            "description": "Broker's comment."
          },
          "request_id": {
            "type": "integer",
            "description": "The broker's id for the request."
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Present only when something in the request was changed or cannot be kept, on a 200 and a 422 alike: a comment over 31 characters (\"comment is N characters; the broker keeps the first 31, termlessd keeps the full text for this order\", without the second half for an order that neither opens nor closes anything); a magic number on a market or pending order (\"magic is not sent to the broker (MetaTrader's web protocol has no field for it); termlessd keeps it for this order\"); a type_filling the symbol does not allow, when order_send named one (\"ORDER_FILLING_FOK is not allowed for EURUSD; sent ORDER_FILLING_IOC\"); an expiry with seconds (\"the broker keeps expiry times to the whole minute: <unix s>\")."
          }
        },
        "required": [
          "ok",
          "retcode",
          "retcode_text",
          "deal",
          "order",
          "volume",
          "price",
          "bid",
          "ask",
          "comment",
          "request_id"
        ],
        "examples": [
          {
            "ok": true,
            "retcode": 10009,
            "retcode_text": "Request completed",
            "deal": 81200131,
            "order": 51830031,
            "volume": 0.1,
            "price": 2391.6,
            "bid": 2391.42,
            "ask": 2391.6,
            "comment": "Request completed",
            "request_id": 31
          },
          {
            "ok": true,
            "retcode": 10009,
            "retcode_text": "Request completed",
            "deal": 81200131,
            "order": 51830031,
            "volume": 0.1,
            "price": 2391.6,
            "bid": 2391.42,
            "ask": 2391.6,
            "comment": "Request completed",
            "request_id": 31,
            "warnings": [
              "comment is 40 characters; the broker keeps the first 31, termlessd keeps the full text for this order",
              "magic is not sent to the broker (MetaTrader's web protocol has no field for it); termlessd keeps it for this order"
            ]
          }
        ]
      },
      "TradeRejected": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean",
            "description": "True when the broker placed (10008), did (10009) or partly did (10010) the request. Test this, not one code: brokers answer a placed pending order with 10008 or 10009."
          },
          "retcode": {
            "type": "integer",
            "description": "MetaTrader return code. 10009 = done, 10008 = placed. See x-retcodes for the rest."
          },
          "retcode_text": {
            "type": "string",
            "description": "The return code in words."
          },
          "deal": {
            "type": "integer",
            "description": "Deal ticket, 0 when no deal was made."
          },
          "order": {
            "type": "integer",
            "description": "Order ticket."
          },
          "volume": {
            "type": "number",
            "description": "Lots done."
          },
          "price": {
            "type": "number",
            "description": "Price done."
          },
          "bid": {
            "type": "number",
            "description": "Bid when the broker handled the request."
          },
          "ask": {
            "type": "number",
            "description": "Ask when the broker handled the request."
          },
          "comment": {
            "type": "string",
            "description": "Broker's comment."
          },
          "request_id": {
            "type": "integer",
            "description": "The broker's id for the request."
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Present only when something in the request was changed or cannot be kept, on a 200 and a 422 alike: a comment over 31 characters (\"comment is N characters; the broker keeps the first 31, termlessd keeps the full text for this order\", without the second half for an order that neither opens nor closes anything); a magic number on a market or pending order (\"magic is not sent to the broker (MetaTrader's web protocol has no field for it); termlessd keeps it for this order\"); a type_filling the symbol does not allow, when order_send named one (\"ORDER_FILLING_FOK is not allowed for EURUSD; sent ORDER_FILLING_IOC\"); an expiry with seconds (\"the broker keeps expiry times to the whole minute: <unix s>\")."
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Machine-readable error code. Matches the HTTP status.",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "forbidden",
                  "real_account",
                  "not_found",
                  "method_not_allowed",
                  "conflict",
                  "rejected",
                  "too_many_requests",
                  "internal",
                  "broker_error",
                  "disconnected",
                  "busy",
                  "stopping",
                  "timeout",
                  "unconfirmed",
                  "trading_paused",
                  "key_limit",
                  "untrusted_certificate",
                  "certificate_changed",
                  "browser_only"
                ]
              },
              "message": {
                "type": "string",
                "description": "What went wrong, in a sentence a person can read."
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "ok",
          "retcode",
          "retcode_text",
          "deal",
          "order",
          "volume",
          "price",
          "bid",
          "ask",
          "comment",
          "request_id",
          "error"
        ],
        "description": "The answer to a trade the broker refused (422): the trade result, with ok false, plus an error whose code is rejected.",
        "examples": [
          {
            "ok": false,
            "retcode": 10014,
            "retcode_text": "Invalid volume",
            "deal": 0,
            "order": 0,
            "volume": 0,
            "price": 0,
            "bid": 2391.42,
            "ask": 2391.6,
            "comment": "Invalid volume",
            "request_id": 32,
            "error": {
              "code": "rejected",
              "message": "the broker refused the request: Invalid volume (10014)"
            }
          }
        ]
      },
      "MarketOrder": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "side": {
            "type": "string",
            "description": "Direction.",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots, for example 0.10."
          },
          "price": {
            "type": "number",
            "description": "Price sent with the request. Leave it out to fill at market."
          },
          "sl": {
            "type": "number",
            "description": "Stop loss price."
          },
          "tp": {
            "type": "number",
            "description": "Take profit price."
          },
          "deviation": {
            "type": "integer",
            "description": "Largest slippage you accept, in points.",
            "default": 20
          },
          "comment": {
            "type": "string",
            "description": "Comment, up to 255 characters (more is 400). The broker keeps the first 31; for a market or pending order Termless keeps the full text and puts it back on the order, its position, its opening deal and the stream events. Longer than 31 adds a warning to the answer.",
            "maxLength": 255
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol's trade request has no field for it, so the broker stores 0; for a market or pending order Termless keeps it and puts it back on the order, its position, its deals and the stream events (MetaTrader's own apps still show 0). Sending one adds a warning to the answer."
          }
        },
        "required": [
          "symbol",
          "side",
          "volume"
        ],
        "description": "Opens a position at market.",
        "title": "Market order",
        "not": {
          "required": [
            "type"
          ],
          "properties": {
            "type": {
              "enum": [
                "limit",
                "stop",
                "stop_limit"
              ]
            }
          }
        },
        "examples": [
          {
            "symbol": "XAUUSD",
            "side": "buy",
            "volume": 0.1,
            "sl": 2380.0,
            "tp": 2420.0,
            "comment": "breakout"
          }
        ]
      },
      "PendingOrder": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "side": {
            "type": "string",
            "description": "Direction.",
            "enum": [
              "buy",
              "sell"
            ]
          },
          "volume": {
            "type": "number",
            "description": "Lots."
          },
          "type": {
            "type": "string",
            "description": "limit, stop or stop_limit. Its presence makes the order pending.",
            "enum": [
              "limit",
              "stop",
              "stop_limit"
            ]
          },
          "price": {
            "type": "number",
            "description": "Trigger price."
          },
          "stop_limit": {
            "type": "number",
            "description": "Limit price, required for stop_limit only."
          },
          "sl": {
            "type": "number",
            "description": "Stop loss price."
          },
          "tp": {
            "type": "number",
            "description": "Take profit price."
          },
          "expiration": {
            "type": "integer",
            "description": "Expiry, unix seconds, trade server clock. Omit (or 0) for good till cancelled. The broker keeps whole minutes; one with seconds gets a warning naming the minute."
          },
          "comment": {
            "type": "string",
            "description": "Comment, up to 255 characters (more is 400). The broker keeps the first 31; for a market or pending order Termless keeps the full text and puts it back on the order, its position, its opening deal and the stream events. Longer than 31 adds a warning to the answer.",
            "maxLength": 255
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol's trade request has no field for it, so the broker stores 0; for a market or pending order Termless keeps it and puts it back on the order, its position, its deals and the stream events (MetaTrader's own apps still show 0). Sending one adds a warning to the answer."
          }
        },
        "required": [
          "symbol",
          "side",
          "volume",
          "type",
          "price"
        ],
        "description": "Places a pending order.",
        "title": "Pending order",
        "examples": [
          {
            "symbol": "XAUUSD",
            "side": "buy",
            "volume": 0.1,
            "type": "limit",
            "price": 2365.0,
            "sl": 2350.0,
            "tp": 2410.0
          }
        ]
      },
      "OrderModify": {
        "type": "object",
        "properties": {
          "price": {
            "type": "number",
            "description": "New trigger price."
          },
          "stop_limit": {
            "type": "number",
            "description": "New limit price (stop limit orders)."
          },
          "sl": {
            "type": "number",
            "description": "New stop loss, 0 removes it."
          },
          "tp": {
            "type": "number",
            "description": "New take profit, 0 removes it."
          },
          "expiration": {
            "type": "integer",
            "description": "New expiry, unix seconds, trade server clock. 0 = good till cancelled."
          }
        },
        "description": "Send only what changes; omitted fields keep their value.",
        "examples": [
          {
            "price": 2360.0,
            "sl": 2345.0
          }
        ]
      },
      "PositionModify": {
        "type": "object",
        "properties": {
          "sl": {
            "type": "number",
            "description": "New stop loss, 0 removes it."
          },
          "tp": {
            "type": "number",
            "description": "New take profit, 0 removes it."
          }
        },
        "description": "Send sl, tp or both; an omitted one keeps its value, 0 removes it.",
        "examples": [
          {
            "sl": 2386.0,
            "tp": 2425.0
          }
        ]
      },
      "OrderSendRequest": {
        "type": "object",
        "properties": {
          "action": {
            "type": [
              "integer",
              "string"
            ],
            "description": "TRADE_ACTION_*: 1 deal (market), 5 pending, 6 sltp, 7 modify, 8 remove, 10 close_by. A number or the official name, for example TRADE_ACTION_DEAL."
          },
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "volume": {
            "type": "number",
            "description": "Lots."
          },
          "type": {
            "type": [
              "integer",
              "string"
            ],
            "description": "ORDER_TYPE_*: 0 buy, 1 sell, 2 buy_limit, 3 sell_limit, 4 buy_stop, 5 sell_stop, 6 buy_stop_limit, 7 sell_stop_limit, 8 close_by. A number or the official name, for example ORDER_TYPE_SELL."
          },
          "price": {
            "type": "number",
            "description": "Price."
          },
          "stoplimit": {
            "type": "number",
            "description": "Limit price of a stop limit order. stop_limit also works."
          },
          "sl": {
            "type": "number",
            "description": "Stop loss."
          },
          "tp": {
            "type": "number",
            "description": "Take profit."
          },
          "deviation": {
            "type": "integer",
            "description": "Largest slippage, in points."
          },
          "type_filling": {
            "type": [
              "integer",
              "string"
            ],
            "description": "ORDER_FILLING_*: 0 FOK, 1 IOC, 2 return, 3 BOC. A number or the official name, for example ORDER_FILLING_IOC. A mode the symbol does not allow is replaced by one it does (IOC, then FOK, then return), as the web terminal does, and the answer's warnings name the mode sent. A pending order goes out as return unless the symbol is exchange-executed."
          },
          "type_time": {
            "type": [
              "integer",
              "string"
            ],
            "description": "ORDER_TIME_*: 0 GTC, 1 day, 2 specified, 3 specified day. A number or the official name, for example ORDER_TIME_GTC."
          },
          "expiration": {
            "type": "integer",
            "description": "Expiry, unix seconds, trade server clock. The broker keeps whole minutes; one with seconds gets a warning."
          },
          "comment": {
            "type": "string",
            "description": "Comment, up to 255 characters (more is 400). The broker keeps the first 31; for a market or pending order Termless keeps the full text and puts it back on the order, its position, its opening deal and the stream events. Longer than 31 adds a warning to the answer.",
            "maxLength": 255
          },
          "magic": {
            "type": "integer",
            "description": "Magic number. The web protocol's trade request has no field for it, so the broker stores 0; for a market or pending order Termless keeps it and puts it back on the order, its position, its deals and the stream events (MetaTrader's own apps still show 0). Sending one adds a warning to the answer."
          },
          "position": {
            "type": "integer",
            "description": "Position ticket, to close or modify a position."
          },
          "position_by": {
            "type": "integer",
            "description": "Opposite position ticket, for close_by."
          },
          "order": {
            "type": "integer",
            "description": "Order ticket, to modify or remove a pending order."
          }
        },
        "required": [
          "action"
        ],
        "description": "The request dict of the official MetaTrader5 Python package's order_send(), with the same field names. Enum fields take the integer constants or their names; numbers may also be sent as strings.",
        "examples": [
          {
            "action": "TRADE_ACTION_DEAL",
            "symbol": "XAUUSD",
            "volume": 0.1,
            "type": "ORDER_TYPE_BUY",
            "price": 2391.6,
            "sl": 2380.0,
            "tp": 2420.0,
            "deviation": 20,
            "type_filling": "ORDER_FILLING_IOC",
            "type_time": 0,
            "comment": "from mt5 script",
            "magic": 7
          }
        ],
        "additionalProperties": false
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Key id, used to revoke it."
          },
          "name": {
            "type": "string",
            "description": "What the key is for."
          },
          "prefix": {
            "type": "string",
            "description": "The key's first 12 characters (tl_ and 9 more), to recognise it."
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "description": "Scope.",
              "enum": [
                "read",
                "trade",
                "admin"
              ]
            },
            "description": "One scope."
          },
          "accounts": {
            "type": [
              "array",
              "null"
            ],
            "description": "Account ids the key may use. null = every account.",
            "items": {
              "type": "string"
            }
          },
          "created_at": {
            "type": "integer",
            "description": "Unix seconds (UTC)."
          },
          "last_used_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Unix seconds (UTC) of the last request, null if never used."
          },
          "max_volume": {
            "type": [
              "number",
              "null"
            ],
            "description": "The most lots one order that opens something may have (0.6.0); null: no limit."
          },
          "max_open_per_min": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The most orders that open something this key may send in 60 s (0.6.0); null: no limit."
          },
          "max_daily_loss": {
            "type": [
              "number",
              "null"
            ],
            "description": "The most the account may lose in a forex day (from 17:00 New York, account currency) before this key opens nothing (0.7.0); null: no limit."
          },
          "max_drawdown_pct": {
            "type": [
              "number",
              "null"
            ],
            "description": "The most percent the account's equity may fall below its high since the limit was set before this key opens nothing (0.7.0); null: no limit."
          },
          "limits_since": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When the drawdown limit was set, unix milliseconds; its high counts from then (0.7.0)."
          }
        },
        "required": [
          "id",
          "name",
          "prefix",
          "scopes",
          "accounts",
          "created_at",
          "last_used_at",
          "max_volume",
          "max_open_per_min",
          "max_daily_loss",
          "max_drawdown_pct",
          "limits_since"
        ],
        "examples": [
          {
            "id": "key_3f9a1c07",
            "name": "EA bridge (gold)",
            "prefix": "tl_4be1a09c7",
            "scopes": [
              "trade"
            ],
            "accounts": [
              "pepperstone-12345678"
            ],
            "created_at": 1790709498,
            "last_used_at": 1790974298,
            "max_volume": 0.5,
            "max_open_per_min": 10,
            "max_daily_loss": 500.0,
            "max_drawdown_pct": null,
            "limits_since": null
          }
        ]
      },
      "ApiKeyUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "A new name, up to 80 characters."
          },
          "scopes": {
            "description": "Exactly one scope, as on create.",
            "oneOf": [
              {
                "const": [
                  "read"
                ]
              },
              {
                "const": [
                  "trade"
                ]
              },
              {
                "const": [
                  "admin"
                ]
              }
            ]
          },
          "accounts": {
            "description": "The account ids it may use; null or [] for every account. Not allowed with admin (400); an unknown id is 400 too.",
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "max_volume": {
            "description": "The most lots per order that opens something; null for no limit.",
            "oneOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "max_open_per_min": {
            "description": "The most orders that open something in 60 s, 1 to 600; null for no limit.",
            "oneOf": [
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 600
              },
              {
                "type": "null"
              }
            ]
          },
          "max_daily_loss": {
            "description": "A positive amount in the account's currency; past it (from the forex day's start) orders that open something answer 403 key_limit, not sent (0.7.0). null or left out: no limit.",
            "oneOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "max_drawdown_pct": {
            "description": "More than 0, at most 100: past that many percent below the equity's high since it was set, orders that open something answer 403 key_limit, not sent (0.7.0). Setting or changing it starts its high afresh.",
            "oneOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 100
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "description": "Any of the fields; the ones left out stay as they are (0.6.0).",
        "additionalProperties": false,
        "examples": [
          {
            "scopes": [
              "read"
            ]
          },
          {
            "accounts": [
              "pepperstone-12345678"
            ]
          },
          {
            "accounts": null
          }
        ]
      },
      "ApiKeyCreate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "What the key is for, for example \"EA bridge (gold)\". Up to 80 characters."
          },
          "scopes": {
            "description": "Exactly one scope. trade includes read; admin includes everything. Defaults to [\"read\"].",
            "oneOf": [
              {
                "const": [
                  "read"
                ]
              },
              {
                "const": [
                  "trade"
                ]
              },
              {
                "const": [
                  "admin"
                ]
              }
            ]
          },
          "accounts": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Limit the key to these account ids. Omit for every account. Not allowed with admin (400); an unknown id is 400 too."
          },
          "max_volume": {
            "type": "number",
            "description": "The most lots one order that opens something may have; above it the order answers 403 key_limit and is not sent. Closing is never limited. Omit for no limit (0.6.0)."
          },
          "max_open_per_min": {
            "type": "integer",
            "description": "The most orders that open something this key may send in 60 s, 1 to 600; past it 429 key_limit with Retry-After, not sent. Omit for no limit (0.6.0)."
          },
          "max_daily_loss": {
            "description": "A positive amount in the account's currency; past it (from the forex day's start) orders that open something answer 403 key_limit, not sent (0.7.0). null or left out: no limit.",
            "oneOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0
              },
              {
                "type": "null"
              }
            ]
          },
          "max_drawdown_pct": {
            "description": "More than 0, at most 100: past that many percent below the equity's high since it was set, orders that open something answer 403 key_limit, not sent (0.7.0). Setting or changing it starts its high afresh.",
            "oneOf": [
              {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 100
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "name"
        ],
        "examples": [
          {
            "name": "EA bridge (gold)",
            "scopes": [
              "trade"
            ],
            "accounts": [
              "pepperstone-12345678"
            ],
            "max_volume": 0.5,
            "max_open_per_min": 10
          }
        ]
      },
      "ApiKeyCreated": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiKey"
          },
          {
            "type": "object",
            "properties": {
              "key": {
                "type": "string",
                "description": "The full key, tl_ and 48 hex characters. It is shown only in this response, so store it now.",
                "pattern": "^tl_[0-9a-f]{48}$"
              }
            },
            "required": [
              "key"
            ]
          }
        ],
        "examples": [
          {
            "id": "key_3f9a1c07",
            "name": "EA bridge (gold)",
            "prefix": "tl_4be1a09c7",
            "scopes": [
              "trade"
            ],
            "accounts": [
              "pepperstone-12345678"
            ],
            "created_at": 1790981179,
            "last_used_at": null,
            "max_volume": 0.5,
            "max_open_per_min": 10,
            "max_daily_loss": 500.0,
            "max_drawdown_pct": null,
            "limits_since": null,
            "key": "tl_4be1a09c7d2e5f8b1a3c6e9d0f2b4a7c8e1d3f5a7b9c0e2d"
          }
        ]
      },
      "Ready": {
        "type": "object",
        "properties": {
          "account": {
            "type": "string",
            "description": "Account id."
          },
          "checked_at": {
            "type": "integer",
            "description": "When this was worked out, unix milliseconds (UTC)."
          },
          "ready_to_read": {
            "type": "boolean",
            "description": "Reads of this account work now: false when any reason blocks read."
          },
          "ready_to_trade": {
            "type": "boolean",
            "description": "An order sent now can reach the broker and be accepted on the account side: false when any reason blocks read or trade."
          },
          "reasons": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReadyReason"
            },
            "description": "Why not, and warnings. Empty when all is well."
          },
          "link": {
            "type": "object",
            "properties": {
              "connected": {
                "type": "boolean",
                "description": "Whether the session's link to the broker is up."
              },
              "since": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "When the current connection came up, unix seconds (UTC); null while disconnected."
              },
              "connected_for_s": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Seconds since then; null while disconnected."
              },
              "ping_ms": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Last heartbeat round trip; null while disconnected."
              },
              "reconnects": {
                "type": "integer",
                "description": "Reconnects since the session started."
              },
              "last_frame_age_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Milliseconds since the last frame of any kind from the broker; null while disconnected."
              },
              "ping_pending_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "How long the oldest unanswered ping has waited, in milliseconds; null when none is waiting (0.6.0). Past 2,000 the reasons carry ping_overdue."
              },
              "pings_missed": {
                "type": "integer",
                "description": "Pings missed in a row; the link is cut at two (0.6.0)."
              },
              "last_error": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The last error, only while disconnected."
              },
              "retry_at": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The next connection attempt, unix seconds (UTC), only while disconnected."
              }
            },
            "required": [
              "connected",
              "since",
              "connected_for_s",
              "ping_ms",
              "reconnects",
              "last_frame_age_ms",
              "ping_pending_ms",
              "pings_missed",
              "last_error",
              "retry_at"
            ]
          },
          "login": {
            "type": "object",
            "properties": {
              "logged_in": {
                "type": "boolean",
                "description": "The session holds a logged-in link."
              },
              "rejected": {
                "type": "boolean",
                "description": "The last refusal was of the login details."
              }
            },
            "required": [
              "logged_in",
              "rejected"
            ]
          },
          "server": {
            "type": "object",
            "properties": {
              "build": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The broker's server build; null before the first connect."
              },
              "build_verified": {
                "type": "boolean",
                "description": "A build Termless's decoding has been checked against live."
              },
              "verified_builds": {
                "type": "array",
                "items": {
                  "type": "integer"
                },
                "description": "The builds checked against live (health::VERIFIED_BUILDS)."
              }
            },
            "required": [
              "build",
              "build_verified",
              "verified_builds"
            ]
          },
          "trading": {
            "type": "object",
            "properties": {
              "allowed": {
                "type": "boolean",
                "description": "Every check on the trade side passes."
              },
              "account_trade_allowed": {
                "type": "boolean",
                "description": "The broker allows trading on the account."
              },
              "investor": {
                "type": "boolean",
                "description": "Logged in with the investor (read-only) password."
              },
              "demo": {
                "type": "boolean",
                "description": "A demo or contest account."
              },
              "real_money": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "demo, allowed (real money with trade_real on), blocked (real money with it off); null before the account record is read.",
                "enum": [
                  "demo",
                  "allowed",
                  "blocked",
                  null
                ]
              },
              "key_can_trade": {
                "type": "boolean",
                "description": "The caller's scope is trade or admin."
              }
            },
            "required": [
              "allowed",
              "account_trade_allowed",
              "investor",
              "demo",
              "real_money",
              "key_can_trade"
            ]
          },
          "prices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReadyPrice"
            },
            "description": "The watched symbols, then the asked ones that are not watched."
          },
          "undecoded_last_hour": {
            "type": "integer",
            "description": "Frames from this account the client could not decode in the last hour."
          }
        },
        "required": [
          "account",
          "checked_at",
          "ready_to_read",
          "ready_to_trade",
          "reasons",
          "link",
          "login",
          "server",
          "trading",
          "prices",
          "undecoded_last_hour"
        ],
        "description": "A bot's pre-flight check, answered from memory with no broker round trip.",
        "examples": [
          {
            "account": "pepperstone-12345678",
            "checked_at": 1792300000123,
            "ready_to_read": true,
            "ready_to_trade": true,
            "reasons": [],
            "link": {
              "connected": true,
              "since": 1792290000,
              "connected_for_s": 10000,
              "ping_ms": 12.4,
              "reconnects": 2,
              "last_frame_age_ms": 800,
              "ping_pending_ms": null,
              "pings_missed": 0,
              "last_error": null,
              "retry_at": null
            },
            "login": {
              "logged_in": true,
              "rejected": false
            },
            "server": {
              "build": 6090,
              "build_verified": true,
              "verified_builds": [
                6090,
                6182,
                6230
              ]
            },
            "trading": {
              "allowed": true,
              "account_trade_allowed": true,
              "investor": false,
              "demo": true,
              "real_money": "demo",
              "key_can_trade": true
            },
            "prices": [
              {
                "symbol": "XAUUSD",
                "watched": true,
                "asked": true,
                "last_tick_age_ms": 812,
                "market_open": true,
                "market_source": "sessions",
                "fresh": true
              },
              {
                "symbol": "EURUSD",
                "watched": true,
                "asked": false,
                "last_tick_age_ms": 240,
                "market_open": true,
                "market_source": "sessions",
                "fresh": true
              }
            ],
            "undecoded_last_hour": 0
          },
          {
            "account": "pepperstone-12345678",
            "checked_at": 1792300000123,
            "ready_to_read": true,
            "ready_to_trade": false,
            "reasons": [
              {
                "code": "market_closed",
                "blocks": "trade",
                "symbol": "EURUSD",
                "message": "EURUSD's market is closed now (its trading sessions say so); orders would be refused"
              }
            ],
            "link": {
              "connected": true,
              "since": 1792290000,
              "connected_for_s": 10000,
              "ping_ms": 12.4,
              "reconnects": 2,
              "last_frame_age_ms": 800,
              "ping_pending_ms": null,
              "pings_missed": 0,
              "last_error": null,
              "retry_at": null
            },
            "login": {
              "logged_in": true,
              "rejected": false
            },
            "server": {
              "build": 6090,
              "build_verified": true,
              "verified_builds": [
                6090,
                6182,
                6230
              ]
            },
            "trading": {
              "allowed": true,
              "account_trade_allowed": true,
              "investor": false,
              "demo": true,
              "real_money": "demo",
              "key_can_trade": true
            },
            "prices": [
              {
                "symbol": "EURUSD",
                "watched": true,
                "asked": true,
                "last_tick_age_ms": 172800000,
                "market_open": false,
                "market_source": "sessions",
                "fresh": true
              }
            ],
            "undecoded_last_hour": 0
          },
          {
            "account": "pepperstone-12345678",
            "checked_at": 1792300000123,
            "ready_to_read": false,
            "ready_to_trade": false,
            "reasons": [
              {
                "code": "disconnected",
                "blocks": "read",
                "message": "pepperstone-12345678 is not connected to Pepperstone-Demo (last error: connect failed: tcp connect to mt5-demo01.pepperstone.com:443 timed out); the next try is in 8 s"
              }
            ],
            "link": {
              "connected": false,
              "since": null,
              "connected_for_s": null,
              "ping_ms": null,
              "reconnects": 3,
              "last_frame_age_ms": null,
              "ping_pending_ms": null,
              "pings_missed": 0,
              "last_error": "connect failed: tcp connect to mt5-demo01.pepperstone.com:443 timed out",
              "retry_at": 1792300008
            },
            "login": {
              "logged_in": false,
              "rejected": false
            },
            "server": {
              "build": 6090,
              "build_verified": true,
              "verified_builds": [
                6090,
                6182,
                6230
              ]
            },
            "trading": {
              "allowed": true,
              "account_trade_allowed": true,
              "investor": false,
              "demo": true,
              "real_money": "demo",
              "key_can_trade": true
            },
            "prices": [
              {
                "symbol": "XAUUSD",
                "watched": true,
                "asked": true,
                "last_tick_age_ms": 812,
                "market_open": true,
                "market_source": "sessions",
                "fresh": true
              },
              {
                "symbol": "EURUSD",
                "watched": true,
                "asked": false,
                "last_tick_age_ms": 240,
                "market_open": true,
                "market_source": "sessions",
                "fresh": true
              }
            ],
            "undecoded_last_hour": 0
          }
        ]
      },
      "ReadyReason": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "description": "What it is. Blocks read: turned_off, disconnected, login_rejected. Blocks trade (an order would certainly fail): trade_disabled, investor_login, real_account_blocked, key_read_only, account_not_loaded, market_closed, unknown_symbol. Notes: price_stale and no_price (an asked symbol's price is old or missing; since 0.5.1 a note, since a market order still fills at the broker's price), build_unverified, undecoded_frames, link_quiet, connected_recently.",
            "enum": [
              "turned_off",
              "disconnected",
              "login_rejected",
              "trade_disabled",
              "investor_login",
              "real_account_blocked",
              "key_read_only",
              "account_not_loaded",
              "market_closed",
              "price_stale",
              "no_price",
              "unknown_symbol",
              "build_unverified",
              "undecoded_frames",
              "link_quiet",
              "ping_overdue",
              "connected_recently",
              "new_trades_paused"
            ]
          },
          "blocks": {
            "type": "string",
            "description": "read (reading and trading both fail), trade, or none (a note).",
            "enum": [
              "read",
              "trade",
              "none"
            ]
          },
          "message": {
            "type": "string",
            "description": "One plain sentence for people and logs."
          },
          "symbol": {
            "type": "string",
            "description": "The symbol, on the per-symbol reasons only."
          }
        },
        "required": [
          "code",
          "blocks",
          "message"
        ],
        "examples": [
          {
            "code": "market_closed",
            "blocks": "trade",
            "symbol": "EURUSD",
            "message": "EURUSD's market is closed now (its trading sessions say so); orders would be refused"
          }
        ]
      },
      "ReadyPrice": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "watched": {
            "type": "boolean",
            "description": "On the account's watchlist (streamed)."
          },
          "asked": {
            "type": "boolean",
            "description": "Named in symbols=."
          },
          "last_tick_age_ms": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Milliseconds since its last tick; null before the first."
          },
          "market_open": {
            "type": [
              "boolean",
              "null"
            ],
            "description": "Whether its market is open now; null when that cannot be told."
          },
          "market_source": {
            "type": [
              "string",
              "null"
            ],
            "description": "sessions (the spec's quote sessions, on the broker's clock), heuristic (no spec loaded yet: the forex week, Sunday 17:00 to Friday 17:00 New York time), or null.",
            "enum": [
              "sessions",
              "heuristic",
              null
            ]
          },
          "fresh": {
            "type": "boolean",
            "description": "A tick came within 120 s, or the market is closed (a closed market is never stale). Information: nothing is blocked on it (since 0.5.1)."
          }
        },
        "required": [
          "symbol",
          "watched",
          "asked",
          "last_tick_age_ms",
          "market_open",
          "market_source",
          "fresh"
        ],
        "examples": [
          {
            "symbol": "XAUUSD",
            "watched": true,
            "asked": true,
            "last_tick_age_ms": 812,
            "market_open": true,
            "market_source": "sessions",
            "fresh": true
          }
        ]
      },
      "StatusReport": {
        "type": "object",
        "properties": {
          "verdict": {
            "type": "string",
            "description": "down when every enabled account is down (and at least one is enabled), degraded when any account is down or degraded or Termless wrote a crash report in the last 24 hours, healthy otherwise (also with no accounts).",
            "enum": [
              "healthy",
              "degraded",
              "down"
            ]
          },
          "summary": {
            "type": "string",
            "description": "One plain sentence for people."
          },
          "checked_at": {
            "type": "integer",
            "description": "When this was worked out, unix milliseconds (UTC)."
          },
          "termless": {
            "type": "object",
            "properties": {
              "version": {
                "type": "string",
                "description": "Server version."
              },
              "started_at": {
                "type": "integer",
                "description": "When this run started, unix seconds (UTC)."
              },
              "uptime_s": {
                "type": "integer",
                "description": "Seconds since then."
              },
              "rss_kb": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Resident memory in KB; null off Linux."
              },
              "rss_peak_kb": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The most resident memory since the start, in KB; null off Linux."
              },
              "restarts_30d": {
                "type": "integer",
                "description": "Starts of the server in the last 30 days (the audit trail's start rows); the first start of an install is not a restart."
              },
              "unclean_exits_30d": {
                "type": "integer",
                "description": "Runs in the last 30 days that ended without shutting down (killed, crashed, out of memory, power lost)."
              },
              "last_start_at": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The latest start, unix milliseconds (UTC)."
              },
              "crash_reports_24h": {
                "type": "integer",
                "description": "Crash reports written in the last 24 hours: a panic termlessd survived, or an unclean exit found at a start (they are under GET /diagnostics). One makes the verdict degraded."
              },
              "errors_1h": {
                "type": "integer",
                "description": "Error lines in termlessd's log in the last hour: counted, not judged."
              },
              "trail_rows_dropped": {
                "type": "integer",
                "description": "Audit rows, events and samples dropped since the start because the trails writer fell behind (its queue holds 50,000; 0.6.0). Anything above 0 means the database is slow or full."
              }
            },
            "required": [
              "version",
              "started_at",
              "uptime_s",
              "rss_kb",
              "rss_peak_kb",
              "restarts_30d",
              "unclean_exits_30d",
              "last_start_at",
              "crash_reports_24h",
              "errors_1h",
              "trail_rows_dropped"
            ]
          },
          "accounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AccountHealth"
            },
            "description": "The accounts the caller may use."
          }
        },
        "required": [
          "verdict",
          "summary",
          "checked_at",
          "termless",
          "accounts"
        ],
        "description": "Termless and each broker link, over time: uptime, outages and their causes, prices, order latency, protocol drift.",
        "examples": [
          {
            "verdict": "healthy",
            "summary": "All good: 1 account connected, 99.86% up over the last 24 hours.",
            "checked_at": 1792300000123,
            "termless": {
              "version": "0.6.2",
              "started_at": 1792200000,
              "uptime_s": 100000,
              "rss_kb": 16384,
              "rss_peak_kb": 20480,
              "restarts_30d": 3,
              "unclean_exits_30d": 0,
              "last_start_at": 1792200000000,
              "crash_reports_24h": 0,
              "errors_1h": 0,
              "trail_rows_dropped": 0
            },
            "accounts": [
              {
                "id": "pepperstone-12345678",
                "label": "Pepperstone demo",
                "server": "Pepperstone-Demo",
                "broker": "Pepperstone",
                "enabled": true,
                "verdict": "healthy",
                "summary": "Connected for 2 h 46 min, ping 12 ms.",
                "connected": true,
                "since": 1792290000,
                "ping_ms": 12.4,
                "tracked_since": 1790000000000,
                "uptime": {
                  "1h": {
                    "percent": 100.0,
                    "up_ms": 3600000,
                    "down_ms": 0,
                    "measured_ms": 3600000,
                    "reconnects": 0,
                    "outages": 0,
                    "longest_outage_ms": 0
                  },
                  "24h": {
                    "percent": 99.86,
                    "up_ms": 86280000,
                    "down_ms": 120000,
                    "measured_ms": 86400000,
                    "reconnects": 1,
                    "outages": 1,
                    "longest_outage_ms": 120000
                  },
                  "7d": {
                    "percent": 99.97,
                    "up_ms": 604620000,
                    "down_ms": 180000,
                    "measured_ms": 604800000,
                    "reconnects": 3,
                    "outages": 2,
                    "longest_outage_ms": 120000
                  },
                  "30d": {
                    "percent": 99.95,
                    "up_ms": 2590710000,
                    "down_ms": 1290000,
                    "measured_ms": 2592000000,
                    "reconnects": 9,
                    "outages": 6,
                    "longest_outage_ms": 600000
                  }
                },
                "days": [
                  {
                    "date": "2026-09-19",
                    "from": 1789776000000,
                    "percent": null,
                    "up_ms": 0,
                    "down_ms": 0,
                    "measured_ms": 0,
                    "outages": 0
                  },
                  {
                    "date": "2026-10-18",
                    "from": 1792281600000,
                    "percent": 99.35,
                    "up_ms": 18280000,
                    "down_ms": 120000,
                    "measured_ms": 18400000,
                    "outages": 1
                  }
                ],
                "outages": [
                  {
                    "from": 1792291200000,
                    "to": 1792291320000,
                    "duration_ms": 120000,
                    "ongoing": false,
                    "start_estimated": false,
                    "detected_at": null,
                    "cause": "broker_maintenance",
                    "message": "Pepperstone restarted its servers; back after 2 min.",
                    "detail": "login refused (code 2) for 1 min after the link dropped"
                  },
                  {
                    "from": 1792199996000,
                    "to": 1792200001200,
                    "duration_ms": 5200,
                    "ongoing": false,
                    "start_estimated": false,
                    "detected_at": null,
                    "cause": "termless_restart",
                    "message": "Termless restarted; back after 5 s.",
                    "detail": "termlessd stopped (upgrade or restart)"
                  }
                ],
                "ticks": {
                  "per_min": 384.0,
                  "seen": 1234567,
                  "last_tick_age_ms": 400,
                  "feed_quiet": false,
                  "symbols": [
                    {
                      "symbol": "EURUSD",
                      "last_tick_age_ms": 400,
                      "market_open": true,
                      "fresh": true
                    },
                    {
                      "symbol": "XAUUSD",
                      "last_tick_age_ms": 812,
                      "market_open": true,
                      "fresh": true
                    }
                  ]
                },
                "orders": {
                  "window_h": 24,
                  "count": 12,
                  "done": 11,
                  "rejected": 1,
                  "timeout": 0,
                  "failed": 0,
                  "latency_ms": {
                    "p50": 41,
                    "p95": 120,
                    "max": 133
                  }
                },
                "protocol": {
                  "build": 6090,
                  "build_verified": true,
                  "undecoded_1h": 0,
                  "undecoded_24h": 0,
                  "undecoded_by_command": []
                },
                "pings_missed": 2,
                "trades_unconfirmed": 0,
                "trades_late": 0,
                "command_waits": 1840,
                "command_wait_ms": 3120
              }
            ]
          }
        ]
      },
      "AccountHealth": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Account id."
          },
          "label": {
            "type": "string",
            "description": "Display name."
          },
          "server": {
            "type": "string",
            "description": "Trade server name."
          },
          "broker": {
            "type": "string",
            "description": "The server name's first word (Pepperstone-Demo is Pepperstone), used in the sentences."
          },
          "enabled": {
            "type": "boolean",
            "description": "False when an admin turned it off."
          },
          "verdict": {
            "type": "string",
            "description": "down: enabled and not connected. degraded: connected but an unverified build, undecoded frames in the last hour, its price feed stopped (ticks.feed_quiet), ping over 1000 ms, or under 99% up over the last hour. off: turned off. healthy otherwise.",
            "enum": [
              "healthy",
              "degraded",
              "down",
              "off"
            ]
          },
          "summary": {
            "type": "string",
            "description": "One plain sentence for people."
          },
          "connected": {
            "type": "boolean",
            "description": "Whether the link is up now."
          },
          "since": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When the current connection came up, unix seconds (UTC)."
          },
          "ping_ms": {
            "type": [
              "number",
              "null"
            ],
            "description": "Last heartbeat round trip."
          },
          "tracked_since": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Where the 30-day numbers start: 30 days ago, or later when the account was added or its connection history starts inside that window; unix milliseconds (UTC); null with no history."
          },
          "uptime": {
            "type": "object",
            "properties": {
              "1h": {
                "$ref": "#/components/schemas/UptimeWindow"
              },
              "24h": {
                "$ref": "#/components/schemas/UptimeWindow"
              },
              "7d": {
                "$ref": "#/components/schemas/UptimeWindow"
              },
              "30d": {
                "$ref": "#/components/schemas/UptimeWindow"
              }
            },
            "required": [
              "1h",
              "24h",
              "7d",
              "30d"
            ],
            "description": "Each window ends now."
          },
          "days": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UptimeDay"
            },
            "description": "The last 30 UTC days, oldest first; today runs up to now.",
            "minItems": 30,
            "maxItems": 30
          },
          "outages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Outage"
            },
            "description": "Newest first: those overlapping the last 30 days, at most 50."
          },
          "ticks": {
            "type": "object",
            "properties": {
              "per_min": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Ticks over the last minute; null until a minute of samples exists."
              },
              "seen": {
                "type": "integer",
                "description": "Ticks since the session started."
              },
              "last_tick_age_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Age of the newest tick of any symbol; null before one."
              },
              "feed_quiet": {
                "type": "boolean",
                "description": "Connected over 120 s and every watched symbol whose market is open has gone 120 s without a tick: the feed stopped while the link stays up. One quiet symbol is the market (since 0.5.1)."
              },
              "symbols": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "symbol": {
                      "type": "string",
                      "description": "Symbol name."
                    },
                    "last_tick_age_ms": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Milliseconds since its last tick."
                    },
                    "market_open": {
                      "type": [
                        "boolean",
                        "null"
                      ],
                      "description": "As in /ready."
                    },
                    "fresh": {
                      "type": "boolean",
                      "description": "As in /ready."
                    }
                  },
                  "required": [
                    "symbol",
                    "last_tick_age_ms",
                    "market_open",
                    "fresh"
                  ]
                },
                "description": "The watchlist."
              }
            },
            "required": [
              "per_min",
              "seen",
              "last_tick_age_ms",
              "feed_quiet",
              "symbols"
            ]
          },
          "orders": {
            "type": "object",
            "properties": {
              "window_h": {
                "type": "integer",
                "description": "24."
              },
              "count": {
                "type": "integer",
                "description": "Trade requests sent through this server in the window (from the audit trail)."
              },
              "done": {
                "type": "integer",
                "description": "The broker executed or placed it."
              },
              "rejected": {
                "type": "integer",
                "description": "The broker refused it (422)."
              },
              "timeout": {
                "type": "integer",
                "description": "No answer (504)."
              },
              "failed": {
                "type": "integer",
                "description": "Anything else: busy, disconnected, a 502."
              },
              "latency_ms": {
                "type": [
                  "object",
                  "null"
                ],
                "description": "The broker round trip over done and rejected requests; null when there were none.",
                "properties": {
                  "p50": {
                    "type": "integer",
                    "description": "Median."
                  },
                  "p95": {
                    "type": "integer",
                    "description": "95th percentile."
                  },
                  "max": {
                    "type": "integer",
                    "description": "Slowest."
                  }
                }
              }
            },
            "required": [
              "window_h",
              "count",
              "done",
              "rejected",
              "timeout",
              "failed",
              "latency_ms"
            ]
          },
          "pings_missed": {
            "type": "integer",
            "description": "Heartbeat pings the broker did not answer in time since the server started (0.6.0); two in a row cut the link."
          },
          "trades_unconfirmed": {
            "type": "integer",
            "description": "Trades answered 504 unconfirmed since the start (0.6.0)."
          },
          "trades_late": {
            "type": "integer",
            "description": "Of them, those whose final result came later (0.6.0)."
          },
          "command_waits": {
            "type": "integer",
            "description": "Requests that waited for their command's turn since the start (most wait no time; 0.6.0)."
          },
          "command_wait_ms": {
            "type": "integer",
            "description": "The time they waited, in all, in milliseconds (0.6.0)."
          },
          "protocol": {
            "type": "object",
            "properties": {
              "build": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "The broker's server build."
              },
              "build_verified": {
                "type": "boolean",
                "description": "A build Termless has been checked against (see /ready)."
              },
              "undecoded_1h": {
                "type": "integer",
                "description": "Undecodable frames in the last hour."
              },
              "undecoded_24h": {
                "type": "integer",
                "description": "Undecodable frames in the last 24 hours."
              },
              "undecoded_by_command": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "command": {
                      "type": "integer",
                      "description": "Protocol command id."
                    },
                    "count": {
                      "type": "integer",
                      "description": "Frames."
                    }
                  },
                  "required": [
                    "command",
                    "count"
                  ]
                },
                "description": "Last 24 hours, by command."
              }
            },
            "required": [
              "build",
              "build_verified",
              "undecoded_1h",
              "undecoded_24h",
              "undecoded_by_command"
            ]
          }
        },
        "required": [
          "id",
          "label",
          "server",
          "broker",
          "enabled",
          "verdict",
          "summary",
          "connected",
          "since",
          "ping_ms",
          "tracked_since",
          "uptime",
          "days",
          "outages",
          "ticks",
          "orders",
          "protocol",
          "pings_missed",
          "trades_unconfirmed",
          "trades_late",
          "command_waits",
          "command_wait_ms"
        ],
        "description": "One account in GET /status.",
        "examples": [
          {
            "id": "pepperstone-12345678",
            "label": "Pepperstone demo",
            "server": "Pepperstone-Demo",
            "broker": "Pepperstone",
            "enabled": true,
            "verdict": "healthy",
            "summary": "Connected for 2 h 46 min, ping 12 ms.",
            "connected": true,
            "since": 1792290000,
            "ping_ms": 12.4,
            "tracked_since": 1790000000000,
            "uptime": {
              "1h": {
                "percent": 100.0,
                "up_ms": 3600000,
                "down_ms": 0,
                "measured_ms": 3600000,
                "reconnects": 0,
                "outages": 0,
                "longest_outage_ms": 0
              },
              "24h": {
                "percent": 99.86,
                "up_ms": 86280000,
                "down_ms": 120000,
                "measured_ms": 86400000,
                "reconnects": 1,
                "outages": 1,
                "longest_outage_ms": 120000
              },
              "7d": {
                "percent": 99.97,
                "up_ms": 604620000,
                "down_ms": 180000,
                "measured_ms": 604800000,
                "reconnects": 3,
                "outages": 2,
                "longest_outage_ms": 120000
              },
              "30d": {
                "percent": 99.95,
                "up_ms": 2590710000,
                "down_ms": 1290000,
                "measured_ms": 2592000000,
                "reconnects": 9,
                "outages": 6,
                "longest_outage_ms": 600000
              }
            },
            "days": [
              {
                "date": "2026-09-19",
                "from": 1789776000000,
                "percent": null,
                "up_ms": 0,
                "down_ms": 0,
                "measured_ms": 0,
                "outages": 0
              },
              {
                "date": "2026-10-18",
                "from": 1792281600000,
                "percent": 99.35,
                "up_ms": 18280000,
                "down_ms": 120000,
                "measured_ms": 18400000,
                "outages": 1
              }
            ],
            "outages": [
              {
                "from": 1792291200000,
                "to": 1792291320000,
                "duration_ms": 120000,
                "ongoing": false,
                "start_estimated": false,
                "detected_at": null,
                "cause": "broker_maintenance",
                "message": "Pepperstone restarted its servers; back after 2 min.",
                "detail": "login refused (code 2) for 1 min after the link dropped"
              },
              {
                "from": 1792199996000,
                "to": 1792200001200,
                "duration_ms": 5200,
                "ongoing": false,
                "start_estimated": false,
                "detected_at": null,
                "cause": "termless_restart",
                "message": "Termless restarted; back after 5 s.",
                "detail": "termlessd stopped (upgrade or restart)"
              }
            ],
            "ticks": {
              "per_min": 384.0,
              "seen": 1234567,
              "last_tick_age_ms": 400,
              "feed_quiet": false,
              "symbols": [
                {
                  "symbol": "EURUSD",
                  "last_tick_age_ms": 400,
                  "market_open": true,
                  "fresh": true
                },
                {
                  "symbol": "XAUUSD",
                  "last_tick_age_ms": 812,
                  "market_open": true,
                  "fresh": true
                }
              ]
            },
            "orders": {
              "window_h": 24,
              "count": 12,
              "done": 11,
              "rejected": 1,
              "timeout": 0,
              "failed": 0,
              "latency_ms": {
                "p50": 41,
                "p95": 120,
                "max": 133
              }
            },
            "protocol": {
              "build": 6090,
              "build_verified": true,
              "undecoded_1h": 0,
              "undecoded_24h": 0,
              "undecoded_by_command": []
            },
            "pings_missed": 2,
            "trades_unconfirmed": 0,
            "trades_late": 0,
            "command_waits": 1840,
            "command_wait_ms": 3120
          }
        ]
      },
      "UptimeWindow": {
        "type": "object",
        "properties": {
          "percent": {
            "type": [
              "number",
              "null"
            ],
            "description": "up_ms / measured_ms x 100, 2 decimals; null when nothing was measured."
          },
          "up_ms": {
            "type": "integer",
            "description": "Connected."
          },
          "down_ms": {
            "type": "integer",
            "description": "Not connected, Termless's own downtime included."
          },
          "measured_ms": {
            "type": "integer",
            "description": "The window less the time before the account was added (or before its history starts) and the time it was turned off."
          },
          "reconnects": {
            "type": "integer",
            "description": "Links that came back inside the window."
          },
          "outages": {
            "type": "integer",
            "description": "Outages overlapping the window."
          },
          "longest_outage_ms": {
            "type": "integer",
            "description": "The longest of them, clipped to the window."
          }
        },
        "required": [
          "percent",
          "up_ms",
          "down_ms",
          "measured_ms",
          "reconnects",
          "outages",
          "longest_outage_ms"
        ],
        "examples": [
          {
            "percent": 99.86,
            "up_ms": 86280000,
            "down_ms": 120000,
            "measured_ms": 86400000,
            "reconnects": 1,
            "outages": 1,
            "longest_outage_ms": 120000
          }
        ]
      },
      "UptimeDay": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string",
            "description": "The UTC day, YYYY-MM-DD.",
            "format": "date"
          },
          "from": {
            "type": "integer",
            "description": "Its 00:00 UTC, unix milliseconds."
          },
          "percent": {
            "type": [
              "number",
              "null"
            ],
            "description": "As in a window; null for a day with nothing measured."
          },
          "up_ms": {
            "type": "integer",
            "description": "Connected."
          },
          "down_ms": {
            "type": "integer",
            "description": "Not connected."
          },
          "measured_ms": {
            "type": "integer",
            "description": "Measured time in the day (today: up to now)."
          },
          "outages": {
            "type": "integer",
            "description": "Outages overlapping the day."
          }
        },
        "required": [
          "date",
          "from",
          "percent",
          "up_ms",
          "down_ms",
          "measured_ms",
          "outages"
        ],
        "examples": [
          {
            "date": "2026-10-18",
            "from": 1792281600000,
            "percent": 99.35,
            "up_ms": 18280000,
            "down_ms": 120000,
            "measured_ms": 18400000,
            "outages": 1
          },
          {
            "date": "2026-09-19",
            "from": 1789776000000,
            "percent": null,
            "up_ms": 0,
            "down_ms": 0,
            "measured_ms": 0,
            "outages": 0
          }
        ]
      },
      "Outage": {
        "type": "object",
        "properties": {
          "from": {
            "type": "integer",
            "description": "When the link was lost (or Termless stopped), unix milliseconds (UTC)."
          },
          "to": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When it was connected again; null while it lasts."
          },
          "duration_ms": {
            "type": "integer",
            "description": "to - from, or up to now while it lasts."
          },
          "ongoing": {
            "type": "boolean",
            "description": "True while it lasts."
          },
          "start_estimated": {
            "type": "boolean",
            "description": "True when from is an estimate (0.6.0): a link cut for missed pings is down from its first unanswered ping, 12 to 17 s before the cut."
          },
          "detected_at": {
            "type": [
              "integer",
              "null"
            ],
            "description": "When the drop was noticed (the cut), unix milliseconds (UTC), if from is an estimate; else null."
          },
          "cause": {
            "type": "string",
            "description": "broker_maintenance (logins refused with code 2 right after the drop, or the forex weekend break), broker_unreachable (TCP, TLS or the WebSocket upgrade failed or timed out), broker_unresponsive (connected but the broker stopped answering), termless_restart (Termless stopped, restarted, upgraded or was killed, or the account's session started again), network (name lookups failing, no route, connections reset), login_refused (the login details refused), unknown.",
            "enum": [
              "broker_maintenance",
              "broker_unreachable",
              "broker_unresponsive",
              "termless_restart",
              "network",
              "login_refused",
              "unknown"
            ]
          },
          "message": {
            "type": "string",
            "description": "One plain sentence for people."
          },
          "detail": {
            "type": [
              "string",
              "null"
            ],
            "description": "The technical reason seen (the lost event's reason, the connect errors)."
          }
        },
        "required": [
          "from",
          "to",
          "duration_ms",
          "ongoing",
          "start_estimated",
          "detected_at",
          "cause",
          "message",
          "detail"
        ],
        "examples": [
          {
            "from": 1792291200000,
            "to": 1792291320000,
            "duration_ms": 120000,
            "ongoing": false,
            "start_estimated": false,
            "detected_at": null,
            "cause": "broker_maintenance",
            "message": "Pepperstone restarted its servers; back after 2 min.",
            "detail": "login refused (code 2) for 1 min after the link dropped"
          },
          {
            "from": 1792199996000,
            "to": 1792200001200,
            "duration_ms": 5200,
            "ongoing": false,
            "start_estimated": false,
            "detected_at": null,
            "cause": "termless_restart",
            "message": "Termless restarted; back after 5 s.",
            "detail": "termlessd stopped (upgrade or restart)"
          }
        ]
      },
      "Gap": {
        "type": "object",
        "properties": {
          "reason": {
            "type": "string",
            "description": "behind: this stream fell behind and kept only the newest tick per symbol; reconnect: the broker link was down; fanout: the account's fan-out fell behind the session.",
            "enum": [
              "behind",
              "reconnect",
              "fanout"
            ]
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "behind: the symbols that lost ticks; otherwise every symbol of the stream."
          },
          "dropped": {
            "type": [
              "integer",
              "null"
            ],
            "description": "behind: how many ticks this stream lost; null when nobody can count them."
          },
          "from_msc": {
            "type": "integer",
            "description": "behind: the first dropped tick's time; otherwise the last tick this stream got before. Ticks' own clock."
          },
          "to_msc": {
            "type": "integer",
            "description": "behind: the last dropped tick's time; otherwise the first tick after, which follows this event."
          },
          "from_utc_msc": {
            "type": "integer",
            "description": "from_msc in UTC; only with the account's clock rule (0.7.1)."
          },
          "to_utc_msc": {
            "type": "integer",
            "description": "to_msc in UTC; only with the account's clock rule (0.7.1)."
          },
          "from_utc_ambiguous": {
            "type": "boolean",
            "description": "true when from_msc falls in New York's repeated autumn hour (0.7.1)."
          },
          "to_utc_ambiguous": {
            "type": "boolean",
            "description": "true when to_msc falls in New York's repeated autumn hour (0.7.1)."
          }
        },
        "required": [
          "reason",
          "symbols",
          "dropped",
          "from_msc",
          "to_msc"
        ],
        "description": "Ticks a stream missed (0.7.0): `event: gap` on SSE, `type: gap` on the WebSocket. They are never replayed: the broker keeps no tick history.",
        "examples": [
          {
            "reason": "reconnect",
            "symbols": [
              "XAUUSD"
            ],
            "dropped": null,
            "from_msc": 1790981170212,
            "to_msc": 1790981191408
          }
        ]
      },
      "Bar": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "timeframe": {
            "type": "string",
            "description": "Timeframe.",
            "enum": [
              "M1",
              "M2",
              "M3",
              "M4",
              "M5",
              "M6",
              "M10",
              "M12",
              "M15",
              "M20",
              "M30",
              "H1",
              "H2",
              "H3",
              "H4",
              "H6",
              "H8",
              "H12",
              "D1",
              "W1",
              "MN1"
            ]
          },
          "time": {
            "type": "integer",
            "description": "Bar open time, unix seconds, trade server clock."
          },
          "open": {
            "type": "number",
            "description": "Open."
          },
          "high": {
            "type": "number",
            "description": "High."
          },
          "low": {
            "type": "number",
            "description": "Low."
          },
          "close": {
            "type": "number",
            "description": "Close."
          },
          "tick_volume": {
            "type": "integer",
            "description": "Tick count in the bar."
          },
          "real_volume": {
            "type": "integer",
            "description": "Exchange volume."
          },
          "state": {
            "type": "string",
            "description": "forming: built from the bids, at most four a second per series; closed: the broker's bar once its period ended (plus 2 s), sent once per period, or later for a period whose tick came late (0.7.1: bars can arrive out of time order, place each by time); corrected: the broker's bar differs from the one sent (read again a minute later, or after the server clock went back).",
            "enum": [
              "forming",
              "closed",
              "corrected"
            ]
          }
        },
        "required": [
          "symbol",
          "timeframe",
          "time",
          "open",
          "high",
          "low",
          "close",
          "tick_volume",
          "real_volume",
          "state"
        ],
        "description": "A bar of a bar series (0.7.0, events=bars): `event: bar` on SSE, `type: bar` on the WebSocket.",
        "examples": [
          {
            "symbol": "XAUUSD",
            "timeframe": "M1",
            "time": 1790981160,
            "open": 2391.2,
            "high": 2391.9,
            "low": 2391.1,
            "close": 2391.42,
            "tick_volume": 112,
            "real_volume": 0,
            "state": "forming"
          }
        ]
      },
      "BarsGap": {
        "type": "object",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Symbol name."
          },
          "timeframe": {
            "type": "string",
            "description": "Timeframe.",
            "enum": [
              "M1",
              "M2",
              "M3",
              "M4",
              "M5",
              "M6",
              "M10",
              "M12",
              "M15",
              "M20",
              "M30",
              "H1",
              "H2",
              "H3",
              "H4",
              "H6",
              "H8",
              "H12",
              "D1",
              "W1",
              "MN1"
            ]
          },
          "from": {
            "type": "integer",
            "description": "The first missed bar's open time."
          },
          "to": {
            "type": "integer",
            "description": "The last missed bar's open time."
          },
          "from_utc": {
            "type": "integer",
            "description": "from in UTC; only with the account's clock rule (0.7.1)."
          },
          "to_utc": {
            "type": "integer",
            "description": "to in UTC; only with the account's clock rule (0.7.1)."
          },
          "from_utc_ambiguous": {
            "type": "boolean",
            "description": "true when from falls in New York's repeated autumn hour (0.7.1)."
          },
          "to_utc_ambiguous": {
            "type": "boolean",
            "description": "true when to falls in New York's repeated autumn hour (0.7.1)."
          }
        },
        "required": [
          "symbol",
          "timeframe",
          "from",
          "to"
        ],
        "description": "Bars a series cannot send (0.7.0): over 500 missed during an outage, a stream far behind, or (0.7.1) a bar that could not be read again or a minute of failed reads. Read the range by REST.",
        "examples": [
          {
            "symbol": "XAUUSD",
            "timeframe": "M1",
            "from": 1790944800,
            "to": 1790981100
          }
        ]
      },
      "OverviewAccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Account id."
          },
          "summary": {
            "$ref": "#/components/schemas/Summary"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Error code."
              },
              "message": {
                "type": "string",
                "description": "What went wrong."
              },
              "status": {
                "type": "integer",
                "description": "The HTTP status the summary route would answer."
              }
            },
            "required": [
              "code",
              "message",
              "status"
            ]
          }
        },
        "required": [
          "id"
        ],
        "description": "One account: its summary, or why there is none (not connected, for example)."
      },
      "Overview": {
        "type": "object",
        "properties": {
          "accounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OverviewAccount"
            },
            "description": "Every enabled account the caller may read."
          }
        },
        "required": [
          "accounts"
        ],
        "examples": [
          {
            "accounts": [
              {
                "id": "pepperstone-12345678",
                "summary": {
                  "login": 12345678,
                  "name": "Demo Trader",
                  "server": "Pepperstone-Demo",
                  "company": "Pepperstone Group Limited",
                  "currency": "USD",
                  "leverage": 200,
                  "balance": 10412.58,
                  "credit": 0.0,
                  "profit": 238.11,
                  "equity": 10650.69,
                  "margin": 878.93,
                  "margin_free": 9771.76,
                  "margin_level": 1211.78,
                  "margin_so_call": 100.0,
                  "margin_so_so": 50.0,
                  "trade_allowed": true,
                  "demo": true,
                  "hedging": true,
                  "server_offset": 10800,
                  "positions": 3,
                  "orders": 2
                }
              }
            ]
          }
        ]
      },
      "StatsDay": {
        "type": "object",
        "properties": {
          "day": {
            "type": "string",
            "description": "YYYY-MM-DD: the forex day under a clock rule, else the server's date."
          },
          "profit": {
            "type": "number",
            "description": "What the trades closed that day made."
          },
          "trades": {
            "type": "integer",
            "description": "Trades closed that day."
          }
        },
        "required": [
          "day",
          "profit",
          "trades"
        ]
      },
      "Stats": {
        "type": "object",
        "properties": {
          "trades": {
            "type": "integer",
            "description": "Positions with a closing deal in the range."
          },
          "wins": {
            "type": "integer",
            "description": "Trades that made money."
          },
          "losses": {
            "type": "integer",
            "description": "Trades that lost money."
          },
          "win_rate": {
            "type": [
              "number",
              "null"
            ],
            "description": "Percent of trades won; null with no trades."
          },
          "profit_factor": {
            "type": [
              "number",
              "null"
            ],
            "description": "What the wins made over what the losses lost; null with no losses."
          },
          "avg_win": {
            "type": [
              "number",
              "null"
            ],
            "description": "Per winning trade."
          },
          "avg_loss": {
            "type": [
              "number",
              "null"
            ],
            "description": "Per losing trade (negative)."
          },
          "gross_profit": {
            "type": "number",
            "description": "What the wins made."
          },
          "gross_loss": {
            "type": "number",
            "description": "What the losses lost (negative)."
          },
          "net": {
            "type": "number",
            "description": "The trades' results together."
          },
          "max_drawdown": {
            "type": "number",
            "description": "The largest fall of the closed results from a high, in time order (positive)."
          },
          "by_day": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StatsDay"
            },
            "description": "Each day with a closed trade, oldest first."
          },
          "from": {
            "type": "integer",
            "description": "Range start, unix seconds, server time."
          },
          "to": {
            "type": "integer",
            "description": "Range end."
          },
          "from_utc": {
            "type": "integer",
            "description": "Range start in UTC; only with the account's clock rule (0.7.1)."
          },
          "to_utc": {
            "type": "integer",
            "description": "Range end in UTC; only with the account's clock rule (0.7.1)."
          },
          "from_utc_ambiguous": {
            "type": "boolean",
            "description": "true when from falls in New York's repeated autumn hour (0.7.1)."
          },
          "to_utc_ambiguous": {
            "type": "boolean",
            "description": "true when to falls in New York's repeated autumn hour (0.7.1)."
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "description": "The account's currency."
          }
        },
        "required": [
          "trades",
          "wins",
          "losses",
          "win_rate",
          "profit_factor",
          "avg_win",
          "avg_loss",
          "gross_profit",
          "gross_loss",
          "net",
          "max_drawdown",
          "by_day",
          "from",
          "to",
          "currency"
        ],
        "description": "A trade is a position with a closing deal in the range; its result is every deal of it the history read holds (profit, swap, commission, fee; the read starts 7 days early so an opening commission counts), its time its last closing deal's.",
        "examples": [
          {
            "trades": 5,
            "wins": 3,
            "losses": 2,
            "win_rate": 60.0,
            "profit_factor": 2.02,
            "avg_win": 29.0,
            "avg_loss": -21.5,
            "gross_profit": 87.0,
            "gross_loss": -43.0,
            "net": 44.0,
            "max_drawdown": 32.0,
            "by_day": [
              {
                "day": "2026-11-30",
                "profit": 16.0,
                "trades": 2
              },
              {
                "day": "2026-12-01",
                "profit": 28.0,
                "trades": 3
              }
            ],
            "from": 1793780000,
            "to": 1796372000,
            "currency": "USD"
          }
        ]
      },
      "SpecItem": {
        "oneOf": [
          {
            "allOf": [
              {
                "$ref": "#/components/schemas/SymbolSpec"
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Symbol name."
                  },
                  "fetched_at_ms": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "When it was read from the broker, unix ms."
                  }
                },
                "required": [
                  "name",
                  "fetched_at_ms"
                ]
              }
            ],
            "title": "spec"
          },
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "description": "The name as asked."
              },
              "error": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Error code."
                  },
                  "message": {
                    "type": "string",
                    "description": "What went wrong."
                  }
                },
                "required": [
                  "code",
                  "message"
                ]
              }
            },
            "required": [
              "name",
              "error"
            ],
            "title": "error"
          }
        ],
        "description": "A spec as GET /symbols/{symbol} gives it, plus its name and when it was read; or an error for a name the broker does not know."
      },
      "CandleBatchRequest": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "symbol": {
                  "type": "string",
                  "description": "Symbol name."
                },
                "timeframe": {
                  "type": "string",
                  "description": "Timeframe (default M5).",
                  "enum": [
                    "M1",
                    "M2",
                    "M3",
                    "M4",
                    "M5",
                    "M6",
                    "M10",
                    "M12",
                    "M15",
                    "M20",
                    "M30",
                    "H1",
                    "H2",
                    "H3",
                    "H4",
                    "H6",
                    "H8",
                    "H12",
                    "D1",
                    "W1",
                    "MN1"
                  ]
                },
                "from": {
                  "type": "integer",
                  "description": "Range start, unix seconds, server time."
                },
                "to": {
                  "type": "integer",
                  "description": "Range end."
                }
              },
              "required": [
                "symbol",
                "from",
                "to"
              ]
            },
            "description": "1 to 20 ranges, at most 200,000 bars in all (each item's whole range counts).",
            "minItems": 1,
            "maxItems": 20
          }
        },
        "required": [
          "items"
        ],
        "additionalProperties": false,
        "examples": [
          {
            "items": [
              {
                "symbol": "XAUUSD",
                "timeframe": "M5",
                "from": 1790894400,
                "to": 1790980800
              },
              {
                "symbol": "EURUSD",
                "timeframe": "H1",
                "from": 1790376000,
                "to": 1790980800
              }
            ]
          }
        ]
      },
      "CandleBatchItem": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "symbol": {
                "type": "string",
                "description": "Symbol name, as the broker spells it."
              },
              "timeframe": {
                "type": "string",
                "description": "Timeframe.",
                "enum": [
                  "M1",
                  "M2",
                  "M3",
                  "M4",
                  "M5",
                  "M6",
                  "M10",
                  "M12",
                  "M15",
                  "M20",
                  "M30",
                  "H1",
                  "H2",
                  "H3",
                  "H4",
                  "H6",
                  "H8",
                  "H12",
                  "D1",
                  "W1",
                  "MN1"
                ]
              },
              "from": {
                "type": "integer",
                "description": "As asked."
              },
              "to": {
                "type": "integer",
                "description": "As asked."
              },
              "truncated": {
                "type": "boolean",
                "description": "The range held more than 50,000 bars; the newest are kept."
              },
              "candles": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Candle"
                },
                "description": "Bars, oldest first."
              }
            },
            "required": [
              "symbol",
              "timeframe",
              "from",
              "to",
              "truncated",
              "candles"
            ],
            "title": "candles"
          },
          {
            "type": "object",
            "properties": {
              "symbol": {
                "type": "string",
                "description": "The name as asked."
              },
              "timeframe": {
                "type": "string",
                "description": "Timeframe."
              },
              "from": {
                "type": "integer",
                "description": "As asked."
              },
              "to": {
                "type": "integer",
                "description": "As asked."
              },
              "error": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Error code."
                  },
                  "message": {
                    "type": "string",
                    "description": "What went wrong."
                  },
                  "status": {
                    "type": "integer",
                    "description": "The HTTP status a single read would answer."
                  }
                },
                "required": [
                  "code",
                  "message",
                  "status"
                ]
              }
            },
            "required": [
              "symbol",
              "timeframe",
              "from",
              "to",
              "error"
            ],
            "title": "error"
          }
        ]
      },
      "CandleBatch": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CandleBatchItem"
            },
            "description": "One per range asked, in order."
          }
        },
        "required": [
          "items"
        ]
      }
    },
    "responses": {
      "BadRequest": {
        "description": "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).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "bad_request",
                "message": "volume must be a positive number"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "Unauthorized": {
        "description": "No valid API key or session.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unauthorized",
                "message": "sign in, or send an API key as Authorization: Bearer <key>"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "Forbidden": {
        "description": "The key lacks the scope, or may not use this account, or a cookie request came from another site.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "forbidden",
                "message": "this needs the trade scope; this key has read"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "NotFound": {
        "description": "No such account, symbol, ticket, key or route.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "no account with id pepperstone-live"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "MethodNotAllowed": {
        "description": "The path exists but does not take this method. Any route can answer it.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "method_not_allowed",
                "message": "/api/v1/keys does not take PUT"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "Conflict": {
        "description": "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.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "conflict",
                "message": "an account with id pepperstone-12345678 already exists"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "Rejected": {
        "description": "The broker refused the trade. The body is the trade result (ok false, the retcode) plus error. Do not resend it unchanged.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/TradeRejected"
            },
            "example": {
              "ok": false,
              "retcode": 10014,
              "retcode_text": "Invalid volume",
              "deal": 0,
              "order": 0,
              "volume": 0,
              "price": 0,
              "bid": 2391.42,
              "ask": 2391.6,
              "comment": "Invalid volume",
              "request_id": 32,
              "error": {
                "code": "rejected",
                "message": "the broker refused the request: Invalid volume (10014)"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "TooManyRequests": {
        "description": "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.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "too_many_requests",
                "message": "too many wrong tries; try again in 15 minutes"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          },
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          }
        }
      },
      "Internal": {
        "description": "The server hit an internal error. Any route can answer it; a panic also saves a crash report (see Diagnostics).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "internal",
                "message": "database error (see the server log)"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "BrokerError": {
        "description": "The broker's server failed or answered with something unexpected.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "broker_error",
                "message": "could not read the broker's reply: unexpected end of body"
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "Disconnected": {
        "description": "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).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "disconnected": {
                "value": {
                  "error": {
                    "code": "disconnected",
                    "message": "pepperstone-12345678 is not connected to Pepperstone-Demo right now; it reconnects on its own"
                  }
                }
              },
              "busy": {
                "value": {
                  "error": {
                    "code": "busy",
                    "message": "earlier requests of command 11 were still waiting for the broker (it takes one at a time per account); this one waited its whole turn and was not sent, so sending it again is safe"
                  }
                }
              },
              "stopping": {
                "value": {
                  "error": {
                    "code": "stopping",
                    "message": "termlessd is stopping; the request was not sent, send it again once it is back"
                  }
                }
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "Timeout": {
        "description": "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.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "timeout": {
                "value": {
                  "error": {
                    "code": "timeout",
                    "message": "the broker did not answer command 12 in time"
                  }
                }
              },
              "unconfirmed": {
                "value": {
                  "error": {
                    "code": "unconfirmed",
                    "message": "the broker took the request but its final result did not come; check positions and orders before sending it again"
                  }
                }
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      },
      "ForbiddenTrade": {
        "description": "forbidden: the key lacks the trade scope, or may not use this account, or a cookie request came from another site. real_account: the broker reports this account as real money (or preliminary) and trading on it is off until an admin sets `trade_real: true` on the account; nothing was sent. Demo and contest accounts trade either way.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "forbidden": {
                "value": {
                  "error": {
                    "code": "forbidden",
                    "message": "this needs the trade scope; this key has read"
                  }
                }
              },
              "real_account": {
                "value": {
                  "error": {
                    "code": "real_account",
                    "message": "pepperstone-12345678 is a real-money account and trading on it is off; an admin turns it on in the account's settings (PATCH /api/v1/accounts/pepperstone-12345678 with trade_real: true)"
                  }
                }
              }
            }
          }
        },
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        }
      }
    },
    "headers": {
      "X-Request-Id": {
        "description": "The request's id: yours when you sent one (1 to 64 characters of A-Z a-z 0-9 - _ . :), else 16 hex characters the server made. The same id is on every log line the request wrote and on every audit row it caused.",
        "schema": {
          "type": "string"
        }
      },
      "Idempotent-Replayed": {
        "description": "`true` when this response was stored by an earlier request with the same Idempotency-Key and replayed; the broker was not asked again.",
        "schema": {
          "type": "string",
          "const": "true"
        }
      },
      "Retry-After": {
        "description": "Seconds until the lockout ends or a stream slot may be free.",
        "schema": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "securitySchemes": {
      "bearerKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Termless API key",
        "description": "An API key (`tl_` and 48 hex characters) from the dashboard (API keys page) or POST /api/v1/keys. 30 unknown keys from one IP in 15 minutes lock it out for 15 minutes (429; a valid key from that IP still works)."
      },
      "queryKey": {
        "type": "apiKey",
        "in": "query",
        "name": "key",
        "description": "The same API key as a query parameter. Only the stream and WebSocket routes read it (other routes accept the parameter and ignore it)."
      },
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "termless_session",
        "description": "The dashboard's HttpOnly, SameSite=Strict session cookie from POST /api/v1/session (30 days). Acts like an admin key. A write or WebSocket with it whose Origin is another site is refused (403)."
      }
    }
  },
  "x-timeframes": [
    "M1",
    "M2",
    "M3",
    "M4",
    "M5",
    "M6",
    "M10",
    "M12",
    "M15",
    "M20",
    "M30",
    "H1",
    "H2",
    "H3",
    "H4",
    "H6",
    "H8",
    "H12",
    "D1",
    "W1",
    "MN1"
  ],
  "x-retcodes": {
    "10004": "Requote",
    "10006": "Request rejected",
    "10007": "Request cancelled by trader",
    "10008": "Order placed",
    "10009": "Request completed",
    "10010": "Only part of the request was completed",
    "10011": "Request processing error",
    "10012": "Request cancelled by timeout",
    "10013": "Invalid request",
    "10014": "Invalid volume",
    "10015": "Invalid price",
    "10016": "Invalid stops",
    "10017": "Trade disabled",
    "10018": "Market is closed",
    "10019": "Not enough money",
    "10020": "Prices changed",
    "10021": "No quotes to process the request",
    "10022": "Invalid order expiration date",
    "10023": "Order state changed",
    "10024": "Too frequent requests",
    "10025": "No changes in request",
    "10026": "Autotrading disabled by server",
    "10027": "Autotrading disabled by client",
    "10028": "Request locked for processing",
    "10029": "Order or position frozen",
    "10030": "Unsupported filling mode",
    "10031": "No connection with the trade server",
    "10032": "Operation allowed only for live accounts",
    "10033": "Pending order limit reached",
    "10034": "Volume limit reached",
    "10035": "Incorrect or prohibited order type",
    "10036": "Position already closed",
    "10038": "Close volume exceeds the position volume",
    "10039": "A close order already exists for this position",
    "10040": "Position limit reached",
    "10041": "Pending order activation request rejected, order cancelled",
    "10042": "Only long positions are allowed",
    "10043": "Only short positions are allowed",
    "10044": "Only position closing is allowed",
    "10045": "Position closing allowed only by FIFO rule",
    "10046": "Opposite positions on one symbol are not allowed"
  }
}
