{
  "openapi": "3.0.3",
  "info": {
    "title": "API2Trade MT5 API",
    "description": "Your MetaTrader 5 account as an API. Each instance is connected to exactly one broker account — use it to read the account, pull market data, and trade.\n\n**Getting started**\n1. Click **Authorize** (top right) and paste your API key — every *Try it out* request on this page will then work. From code, send the key as the `X-API-Key` header on each request.\n2. Check the connection: `GET /AccountSummary` returns your balance, equity and leverage.\n\n**Reading data** — account state (`/AccountSummary`, `/OpenedOrders`, `/OrderHistory`), live prices (`/getQuote`), candles (`/PriceHistory`) and instrument details (`/symbols`, `/SymbolInfo`).\n\n**Trading** — `/OrderSend` places a market or pending order, `/OrderModify` changes stop-loss / take-profit / pending price, `/OrderClose` closes a position (fully or partially) or deletes a pending order. Important: a `200` response only means MT5 answered — check the body to know whether the broker accepted it. `success` is `true` for `retcode` `10009` (done) or `10008` (placed); the `outcome` field classifies the result further as `applied` / `no_change` / `partial` / `rejected` (`no_change` = `10025`, an idempotent no-op — the requested SL/TP/price already match, safe to treat as applied). `operation` accepts `Buy`, `Sell`, `BuyLimit`, `SellLimit`, `BuyStop`, `SellStop`, `BuyStopLimit`, `SellStopLimit` (capitalization doesn't matter).\n\n**Panic button** — `POST /CloseAll` (empty body `{{}}` allowed) closes every open position in one pass, optionally filtered by `symbol` / `magic`, optionally deleting pendings too.\n\n**Live streams** — open a WebSocket to `/ws?api_key=<your key>` and subscribe to ticks, candles, account updates, trade events, pending orders and connection status. `/ws-tester` is a small page to try it in the browser.\n\n**Good to know**\n- Volumes are in lots (`0.01` = one micro lot).\n- Timestamps are ISO-8601 in your broker's server time.\n- `timeframe` accepts `M1`, `M5`, `M15`, `M30`, `H1`, `H4`, `D1`, `W1`, `MN1` — or simply `5min`, `1h`, `1d`.\n- Errors always have the same shape: `error` code, human-readable `message`, and a `command_id` you can quote when reporting issues.\n- Trading endpoints return `503` while the trading engine is still starting up — give a freshly created instance 1–3 minutes.\n- Trade calls wait up to 60 s for the broker's dealer; every other endpoint answers within 15 s. **The 504s on a trade mean different things, so branch on the `error` code, never on the status alone:** `MRPC_ABANDONED` and `MRPC_TIMEOUT` mean the request never reached the dealer and will **not** execute later, so it is safe to re-send; `MRPC_TRADE_OUTCOME_UNKNOWN` means it **was** handed to the trade server and no verdict came back, so an order may be live. Never re-send that one blindly: repeat it with the same `clientOrderId`, which answers with its real outcome and never trades twice, or reconcile first via `/OpenedOrders` and `/OrderHistory`.\n- **Send every `/OrderSend` with a `clientOrderId`.** A repeat with the same id within 10 minutes places nothing new and returns the first answer, so retrying after a timeout or a dropped connection is safe.\n- **MT5 executes trades in parallel.** A burst executes concurrently instead of one order at a time, so replies within a burst can arrive out of the order you sent them: correlate on `order` / `deal` (or your `clientOrderId`), never on arrival. Requests on the same ticket are still executed one at a time, and a heavy burst can return the broker's `10024` (too frequent requests), which you should retry with backoff. `bridge.asyncTrades` in `/status` says whether this account executes in parallel; MT4 accounts always execute one at a time.\n- API keys come in two levels: the account's full key unlocks everything on this page, while a **read-only** key can call every data endpoint and stream but gets `403 READ_ONLY_KEY` on `/OrderSend`, `/OrderModify` and `/OrderClose`.",
    "license": {
      "name": "Proprietary"
    },
    "version": "0.18.3"
  },
  "servers": [
    {
      "url": "https://api.api2trade.com/v2/{account_id}"
    }
  ],
  "paths": {
    "/AccountInfo": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Static identity and configuration of the connected account.",
        "description": "The account's *who and how* — name, login, broker company/server,\ncurrency, leverage, account type, **margin mode** (netting/hedging/\nexchange), stop-out configuration, and trade permissions. These rarely\nchange. For the live balance/equity/margin figures use\n`/AccountSummary` instead; for whether the account is logged in at all,\nuse `/status`.",
        "operationId": "account_info",
        "responses": {
          "200": {
            "description": "Account identity + configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountInfoData"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/AccountSummary": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Snapshot of the connected trading account.",
        "description": "Returns the current balance, equity, margin, free margin, floating\nprofit, leverage, account currency, broker name, server name, and\ntrade-allowed flags. Reflects broker-side state at call time — no\ncaching.",
        "operationId": "account_summary",
        "responses": {
          "200": {
            "description": "Live account snapshot.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountSummaryData"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/CloseAll": {
      "post": {
        "tags": [
          "trading"
        ],
        "summary": "Close every open position — the panic button.",
        "description": "Optionally filtered by `symbol` and/or `magic`, and optionally also\ndeleting pending orders. Runs as ONE pass; the reply carries\na per-ticket result for every attempted close/delete, plus counts.\nPositions opened while the pass is running are not covered — check\n`/OpenedOrders` afterwards if that matters.",
        "operationId": "close_all",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CloseAllBody"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Per-ticket outcomes — inspect each `retcode`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CloseAllSummary"
                }
              }
            }
          },
          "503": {
            "description": "The trading engine is not ready yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "No reply in time — but closing CONTINUES to completion on the account. Check `/OpenedOrders` to see what remains open before acting again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OpenedOrders": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "All open positions and active pending orders.",
        "description": "Returns one row per position (already-filled trade) and one row per\npending order (limit / stop / stop-limit). Each row carries `ticket`,\n`symbol`, `type` (`Buy`/`Sell`/`BuyLimit`/…), `volume` (lots), open\nprice, current price, SL/TP, swap, floating profit, comment, and\nmagic number. Pending orders show their trigger price in the open-\nprice field.",
        "operationId": "opened_orders",
        "responses": {
          "200": {
            "description": "Open positions plus active pending orders.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/OpenedOrder"
                  }
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OrderCalcMargin": {
      "get": {
        "tags": [
          "trading"
        ],
        "summary": "Required margin for a hypothetical order.",
        "description": "Asks MT5 to compute the broker-side margin needed to open `volume`\nlots of `symbol` at `price` in the given `operation` direction.\nReturns the margin in the account currency. **Does not place an\norder** — purely a sizing/risk query.",
        "operationId": "order_calc_margin",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "description": "Symbol name as listed by `/symbols` (e.g. `EURUSD`).",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "operation",
            "in": "query",
            "description": "Order direction: `Buy`, `Sell`, `BuyLimit`, `SellLimit`,\n`BuyStop`, `SellStop`, `BuyStopLimit`, `SellStopLimit`\n(case- and separator-insensitive).",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "volume",
            "in": "query",
            "description": "Volume in lots.",
            "required": true,
            "schema": {
              "type": "number",
              "format": "double"
            }
          },
          {
            "name": "price",
            "in": "query",
            "description": "Hypothetical entry price (account-quote currency).",
            "required": true,
            "schema": {
              "type": "number",
              "format": "double"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Required margin in account currency.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MarginResult"
                }
              }
            }
          },
          "400": {
            "description": "Unknown `operation` value.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OrderCalcProfit": {
      "get": {
        "tags": [
          "trading"
        ],
        "summary": "Projected P&L for a hypothetical open→close move.",
        "description": "Asks MT5 to compute the profit/loss if `volume` lots of `symbol`\nwere opened at `priceOpen` and closed at `priceClose` in the given\ndirection. Returns profit in account currency. **Does not place an\norder** — useful for sizing and UI.",
        "operationId": "order_calc_profit",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "description": "Symbol name as listed by `/symbols` (e.g. `EURUSD`).",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "operation",
            "in": "query",
            "description": "Order direction: `Buy` or `Sell` (case-insensitive). Pending\nvariants are accepted but only the direction is used.",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "volume",
            "in": "query",
            "description": "Volume in lots.",
            "required": true,
            "schema": {
              "type": "number",
              "format": "double"
            }
          },
          {
            "name": "priceOpen",
            "in": "query",
            "description": "Hypothetical open price.",
            "required": true,
            "schema": {
              "type": "number",
              "format": "double"
            }
          },
          {
            "name": "priceClose",
            "in": "query",
            "description": "Hypothetical close price.",
            "required": true,
            "schema": {
              "type": "number",
              "format": "double"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Projected profit in account currency.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfitResult"
                }
              }
            }
          },
          "400": {
            "description": "Unknown `operation` value.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OrderClose": {
      "post": {
        "tags": [
          "trading"
        ],
        "summary": "Close a position or delete a pending order.",
        "description": "One endpoint covers both — the action is inferred from the ticket\ntype:\n- **Position ticket** → closes the position. Supply `volume` for a\npartial close (must respect the symbol's `volumeStep`); omit or\npass `0` for a full close.\n- **Pending-order ticket** → deletes the order. `volume` is ignored.\n\nWith `pendingOnly: true` only the second applies, also to a partly\nfilled order (the filled part stays open). A ticket that is only a\nposition (its order filled a moment ago) is refused with **409\n`MRPC_NOT_PENDING`** and stays open.\n\nInspect `success`/`retcode` on the response.",
        "operationId": "order_close",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderCloseBody"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "MT5 trade result — inspect `success` and `retcode`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderSendResult"
                }
              }
            }
          },
          "400": {
            "description": "Validation failed (e.g. missing `ticket`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "409": {
            "description": "`pendingOnly` and the ticket is a position, not a pending order (`MRPC_NOT_PENDING`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "503": {
            "description": "The trading engine is not ready yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OrderHistory": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Closed deals in a time range.",
        "description": "Returns DEAL entries (executions), not ORDER entries — pending\norders that never filled don't appear here. Each row has `ticket`,\n`position` (the id shared by a round-trip's `In`/`Out` rows — the\njoin key to the WS `trade` events and `/PositionHistory`), `symbol`,\n`type` (`Buy`/`Sell`), `volume`, `price`, `sl`/`tp`, `profit`,\n`commission`, `swap`, `magic`, `comment`, and the deal `time`. Omit\nboth bounds to fetch all-time history.",
        "operationId": "order_history",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "Inclusive lower bound (broker server time). Accepts ISO-8601\n(`2026-01-01T00:00:00Z`) or `YYYY-MM-DD`. Empty/absent → epoch.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Inclusive upper bound (broker server time). Same formats as\n`from`. Empty/absent → now.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Closed deals executed in the requested window.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/HistoryTrade"
                  }
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OrderModify": {
      "post": {
        "tags": [
          "trading"
        ],
        "summary": "Modify an existing position or pending order.",
        "description": "The ticket type decides what's modifiable:\n- **Position ticket** → only `stopLoss` and `takeProfit`.\n- **Pending-order ticket** → `price`, `stopLimitPrice`, `expiration`,\n`stopLoss`, `takeProfit`.\n\nOmit a field to keep its current value. Inspect `success`/`retcode`\non the response — a `200` only proves a reply arrived, not that the\nbroker accepted the change.",
        "operationId": "order_modify",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderModifyBody"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "MT5 trade result — inspect `success` and `retcode`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderSendResult"
                }
              }
            }
          },
          "400": {
            "description": "Validation failed (e.g. missing `ticket`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "503": {
            "description": "The trading engine is not ready yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/OrderSend": {
      "post": {
        "tags": [
          "trading"
        ],
        "summary": "Submit a market or pending order.",
        "description": "A `200` response only means MT5 answered — **always inspect `success`\nand `retcode`** to confirm the broker accepted it.\n\n**Required fields by operation**\n- Market (`Buy`/`Sell`): `symbol`, `volume`. `price` is ignored.\n- Pending (`*Limit`/`*Stop`): `symbol`, `volume`, `price`.\n- StopLimit (`BuyStopLimit`/`SellStopLimit`): additionally\n`stopLimitPrice`.\n\n**Optional fields**\n- `slippage` (default 10 points), `stopLoss`, `takeProfit`,\n`expiration` (date string — absent ⇒ good-till-cancelled),\n`comment`, `expertId` (a.k.a. `magic`, also accepts `magicNumber`).\n- `clientOrderId`: makes the request safe to repeat after a timeout —\nsee the field.\n- `execution`: `EA` (default) or `Manual` — see below.\n\n**`execution: \"Manual\"`** — for brokers that block expert trading.\nThe order is entered in MetaTrader's own New Order dialog and Buy/Sell\npressed there, so the broker records a manual order (`ORDER_REASON_CLIENT`).\nMarket orders only (`Buy`/`Sell`, with optional `stopLoss`,\n`takeProfit`, `comment`); magic is always 0, so `expertId` is\nrefused. Before the click every value is read back from the dialog;\nif one does not match, nothing is sent and the reply is\n`500 MRPC_MANUAL_NOT_SENT`. The reply otherwise has the usual shape:\n`comment` is the dialog's own result line, a rejection carries the\nmatching retcode where the text names one (else 10006). Takes about\n1–3 s, during which other trade commands wait.\n\nReturns `503` while the trading engine is not ready yet.",
        "operationId": "order_send",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderSendBody"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "MT5 trade result — inspect `success` and `retcode`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderSendResult"
                }
              }
            }
          },
          "400": {
            "description": "Validation failed (unknown operation, missing price for pending, non-positive volume, …).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "409": {
            "description": "`clientOrderId` already used for a different order.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "503": {
            "description": "The trading engine is not ready yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/PendingOrders": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Active pending orders, with their expiry.",
        "description": "The pending rows of `/OpenedOrders` plus what copying an order needs:\nthe stop-limit price, initial and remaining volume, and the expiry —\nits kind, server time and real UTC. The `orders` WebSocket topic\nopens with the same rows, then reports every change as an `order`\nevent.",
        "operationId": "pending_orders",
        "responses": {
          "200": {
            "description": "Active pending orders.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/PendingOrder"
                  }
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/PositionHistory": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Closed trades (round-trip positions) in a time window.",
        "description": "Unlike `/OrderHistory` — which is the raw *deal* log (one row per\nexecution, two per round-trip) — this returns **one row per closed\nposition**, the view a trading-history screen wants: `positionId`,\n`symbol`, `type` (`Buy`/`Sell`), `volume`, open/close price + time,\n`sl`/`tp` (the levels the position carried when it closed), and\nP/L split into `profit` (gross), `swap`, `commission`, and `netProfit`\n(the sum — what hit the balance). Reconstructed by grouping deals on\nthe MT5 position id, so a position opened before `from` but closed\ninside the window is still returned complete. Deposits/withdrawals are\nexcluded. The window filters on the *close* time; omit both bounds for\nall-time.",
        "operationId": "position_history",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "Inclusive lower bound (broker server time). Accepts ISO-8601\n(`2026-01-01T00:00:00Z`) or `YYYY-MM-DD`. Empty/absent → epoch.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Inclusive upper bound (broker server time). Same formats as\n`from`. Empty/absent → now.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Closed round-trip positions in the window.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/PositionTrade"
                  }
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/PriceHistory": {
      "get": {
        "tags": [
          "market"
        ],
        "summary": "OHLC bars for a symbol and timeframe.",
        "description": "Returns one candle per bar in the requested window. Fields:\n`time` (bar open, server time), `open`, `high`, `low`, `close`,\n`tickVolume`, `realVolume`, `spread`.\n\nMT5 fetches missing history from the broker on demand, so wide\nranges on small timeframes can take several seconds. An empty\nresponse is normal when the requested window predates the broker's\nretained history or covers a closed market.",
        "operationId": "price_history",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "description": "Symbol name as listed by `/symbols` (e.g. `EURUSD`).",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "timeframe",
            "in": "query",
            "description": "Bar timeframe. MT5 labels (`M1`, `M5`, `M15`, `M30`, `H1`, `H4`,\n`D1`, `W1`, `MN1`) or human forms (`5min`, `1h`, `1d`).",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Inclusive lower bound (broker server time). ISO-8601 or\n`YYYY-MM-DD`. Empty/absent → epoch.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Inclusive upper bound (broker server time). Same formats as\n`from`. Empty/absent → now.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OHLC bars covering the requested window.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Candle"
                  }
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/ServerTimezone": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Broker server time and its offset from UTC.",
        "description": "Returns `serverTime` (ISO-8601 in broker server time — the trailing\n`Z` is stylistic, matching the rest of the API) and\n`utcOffsetSeconds`, computed as `TimeTradeServer() - TimeGMT()`. Use\nthe offset to translate any of the other endpoints' `Z`-labelled\ntimestamps to real UTC: `utc = serverTime - utcOffsetSeconds`.\n\nCommon values: `0` for a UTC broker, `7200` for a UTC+2 broker,\n`10800` during summer (UTC+3). Most MetaTrader brokers run on EET\n(UTC+2 / UTC+3 with DST).",
        "operationId": "server_timezone",
        "responses": {
          "200": {
            "description": "Broker server clock and UTC offset.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServerTimezoneData"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/SymbolInfo": {
      "get": {
        "tags": [
          "market"
        ],
        "summary": "Contract specification for a symbol.",
        "description": "Returns broker-side contract specs: `digits`, `point`, `spread`,\n`contractSize`, `tickSize`, `tickValue`, swap rates,\n`volumeMin` / `volumeMax` / `volumeStep`, `tradeMode`, base/quote/\nprofit currencies. Call this before `/OrderSend` to validate\nvolumes and round prices to the right precision.\n\nWith `symbols=A,B,C` instead of `symbol` it answers for all of them\nin one call — `{symbols: [...], errors: [{symbol, error, message}]}`\n— and puts them all into Market Watch first, like `/SymbolSelect`.",
        "operationId": "symbol_info",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "description": "Symbol name as listed by `/symbols` (e.g. `EURUSD`).",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          },
          {
            "name": "symbols",
            "in": "query",
            "description": "Several symbols, comma-separated (`EURUSD,GBPUSD`), instead of\n`symbol` — at most 100. The reply is then a `SymbolInfoBulk`.",
            "required": false,
            "schema": {
              "type": "string",
              "nullable": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Contract specification for the symbol (with `symbols`: a `SymbolInfoBulk`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SymbolInfoData"
                }
              }
            }
          },
          "400": {
            "description": "Neither or both of `symbol` and `symbols`, or too many symbols.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/SymbolSelect": {
      "post": {
        "tags": [
          "market"
        ],
        "summary": "Put symbols into Market Watch, ready to trade.",
        "description": "A symbol outside Market Watch gets no quotes, so the first order or\n`/SymbolInfo` on it waits for its first tick. Selecting the symbols a\nclient will trade ahead of time (a copier: its masters' symbols on\nevery follower, at start) moves that wait out of the first trade. All\nsymbols are selected in one pass, which then waits up to 1 s,\nonce, for the fresh ones to quote. They stay selected.\n\nA bulk `/SymbolInfo` warms symbols up the same way.",
        "operationId": "symbol_select",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SymbolSelectBody"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "One row per symbol, in request order.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SymbolSelectResult"
                  }
                }
              }
            }
          },
          "400": {
            "description": "No symbols, too many, or a name with a comma.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/getQuote": {
      "get": {
        "tags": [
          "market"
        ],
        "summary": "Latest tick for a symbol.",
        "description": "Returns the most recent `bid`, `ask`, `last`, `volume`, and broker\nserver `time` for `symbol`. If the symbol isn't yet in Market Watch\nit is enabled on demand, which may add a small delay on the\nfirst call.\n\nFor continuous tick streaming use the WebSocket `prices` topic.",
        "operationId": "get_quote",
        "parameters": [
          {
            "name": "symbol",
            "in": "query",
            "description": "Symbol name as listed by `/symbols` (e.g. `EURUSD`, `XAUUSD`).",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Most recent tick for the symbol.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteData"
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    },
    "/status": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Health of this account's connection.",
        "description": "Is the connection alive, connected to the broker, and is the trading\naccount logged in? **Always returns HTTP 200** (even when the\nconnection is down) — the failure detail is in the body. Read the\ntop-level `status` field: `ready`, `starting` (logged in, still\nsyncing), `degraded` (connection up but broker/login down), or `down`\n(connection not answering). Uptime monitors that need an HTTP status\ncode instead can use the open `/healthz` (fully ready) and `/livez`\n(answering at all) endpoints.",
        "operationId": "status",
        "responses": {
          "200": {
            "description": "Health snapshot — inspect the `status` field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatusResponse"
                }
              }
            }
          }
        }
      }
    },
    "/symbols": {
      "get": {
        "tags": [
          "market"
        ],
        "summary": "Every symbol the broker offers — the whole catalog, not just Market Watch",
        "description": "Symbols with trading disabled are left out.\n\nUse the returned names verbatim with `/getQuote`, `/SymbolInfo`,\n`/PriceHistory`, and `/OrderSend`. A symbol outside Market Watch has\nno quotes until it is added — `/SymbolSelect` adds several at once\nand waits until they quote.",
        "operationId": "symbols",
        "responses": {
          "200": {
            "description": "Every symbol the broker offers (not only Market Watch).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          },
          "504": {
            "description": "The connection did not answer in time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorBody"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AccountHealth": {
        "type": "object",
        "required": [
          "loggedIn",
          "login",
          "currency",
          "type",
          "tradeAllowed",
          "authError"
        ],
        "properties": {
          "authError": {
            "type": "string",
            "description": "Why the broker refused the last login, in the broker's own words\n(e.g. `Invalid account` for a wrong login or password).\nEmpty while `logged_in`, and before the first refusal."
          },
          "currency": {
            "type": "string",
            "description": "Account currency. Blank unless `logged_in` (stale otherwise)."
          },
          "loggedIn": {
            "type": "boolean",
            "description": "The trading account is authorized (connected and a login is loaded)."
          },
          "login": {
            "type": "integer",
            "format": "int64",
            "description": "MT5 account number being used. Set even when `logged_in` is false\n(it's the account the connection is set up to log into); `0` only\nwhen the connection itself is down."
          },
          "tradeAllowed": {
            "type": "boolean",
            "description": "Trading is permitted for this account right now. `false` unless\n`logged_in`."
          },
          "type": {
            "type": "string",
            "description": "`Demo`, `Real`, or `Contest`. Blank unless `logged_in` (stale\notherwise — MT5 keeps a last-known trade-mode for the login)."
          }
        }
      },
      "AccountInfoData": {
        "type": "object",
        "description": "`/AccountInfo` reply — the connected account's static identity and\nconfiguration (distinct from the live financials in\n`/AccountSummary`). Values are meaningful once the account is logged\nin — check `/status` (`account.loggedIn`) on a fresh connection.",
        "required": [
          "name",
          "login",
          "server",
          "company",
          "currency",
          "currencyDigits",
          "leverage",
          "type",
          "marginMode",
          "marginSoMode",
          "marginCallLevel",
          "stopOutLevel",
          "tradeAllowed",
          "tradeExpert",
          "limitOrders",
          "fifoClose"
        ],
        "properties": {
          "company": {
            "type": "string",
            "description": "Broker company name."
          },
          "currency": {
            "type": "string"
          },
          "currencyDigits": {
            "type": "integer",
            "format": "int64",
            "description": "Decimal places for money values in this account's currency."
          },
          "fifoClose": {
            "type": "boolean",
            "description": "Positions must be closed FIFO (US-style)."
          },
          "leverage": {
            "type": "integer",
            "format": "int64",
            "description": "Account leverage, e.g. `200` for 1:200."
          },
          "limitOrders": {
            "type": "integer",
            "format": "int64",
            "description": "Max simultaneously-active pending orders (`0` = unlimited)."
          },
          "login": {
            "type": "integer",
            "format": "int64",
            "description": "MT5 account number."
          },
          "marginCallLevel": {
            "type": "number",
            "format": "double",
            "description": "Margin-call level (in `marginSoMode` units)."
          },
          "marginMode": {
            "type": "string",
            "description": "Position accounting: `Netting`, `Hedging`, or `Exchange`. Decides\nwhether an opposite order nets an existing position or opens a new\none — clients running trade logic need this."
          },
          "marginSoMode": {
            "type": "string",
            "description": "Stop-out trigger basis: `Percent` (of margin level) or `Money`."
          },
          "name": {
            "type": "string",
            "description": "Account holder name."
          },
          "server": {
            "type": "string",
            "description": "Broker server, e.g. `TegasFX-Main-UK`."
          },
          "stopOutLevel": {
            "type": "number",
            "format": "double",
            "description": "Stop-out level (in `marginSoMode` units)."
          },
          "tradeAllowed": {
            "type": "boolean",
            "description": "Trading permitted for this account (broker-side flag)."
          },
          "tradeExpert": {
            "type": "boolean",
            "description": "Automated trading (Expert Advisors) permitted for this account."
          },
          "type": {
            "type": "string",
            "description": "`Demo`, `Real`, or `Contest`."
          }
        }
      },
      "AccountSummaryData": {
        "type": "object",
        "description": "`/AccountSummary` reply: a live financial snapshot of the account.",
        "required": [
          "balance",
          "credit",
          "profit",
          "equity",
          "margin",
          "freeMargin",
          "marginLevel",
          "leverage",
          "currency",
          "type"
        ],
        "properties": {
          "balance": {
            "type": "number",
            "format": "double"
          },
          "credit": {
            "type": "number",
            "format": "double"
          },
          "currency": {
            "type": "string"
          },
          "equity": {
            "type": "number",
            "format": "double"
          },
          "freeMargin": {
            "type": "number",
            "format": "double"
          },
          "leverage": {
            "type": "integer",
            "format": "int64"
          },
          "margin": {
            "type": "number",
            "format": "double"
          },
          "marginLevel": {
            "type": "number",
            "format": "double"
          },
          "profit": {
            "type": "number",
            "format": "double"
          },
          "type": {
            "type": "string"
          }
        }
      },
      "BridgeHealth": {
        "type": "object",
        "required": [
          "version",
          "tradeEaReady",
          "tradeEaHeartbeatAgeMs",
          "symbolsSynced",
          "asyncTrades",
          "tradeInFlight",
          "oldestTradeInFlightAgeMs",
          "dealerRttMsEwma",
          "tradeRequestsSent",
          "lateTradeVerdicts",
          "tradeQueueDepth",
          "nonTradeQueueDepth",
          "tradeDeferred"
        ],
        "properties": {
          "asyncTrades": {
            "type": "boolean",
            "description": "Trades are executed in parallel, so several trade requests can be\nat the dealer at once. When false, trades execute strictly one\nafter another (one dealer round-trip each)."
          },
          "dealerRttMsEwma": {
            "type": "integer",
            "format": "int64",
            "description": "Dealer round-trip time (moving average), milliseconds (-1 = no\nsample yet)."
          },
          "lateTradeVerdicts": {
            "type": "integer",
            "format": "int64",
            "description": "Dealer verdicts that arrived after the API had stopped waiting\nfor them. Non-zero means some trade executed unobserved — check\n`/OpenedOrders` and `/OrderHistory`."
          },
          "nonTradeQueueDepth": {
            "type": "integer",
            "format": "int64",
            "description": "Read commands waiting to be processed."
          },
          "oldestTradeInFlightAgeMs": {
            "type": "integer",
            "format": "int64",
            "description": "Age of the oldest request still awaiting a verdict, milliseconds\n(-1 = nothing in flight). THIS is the stall signal to alert on:\na value far above `dealerRttMsEwma` means the dealer has gone\nquiet, and parallel execution pauses until it answers."
          },
          "symbolsSynced": {
            "type": "boolean",
            "description": "The broker symbol list has synced at least once."
          },
          "tradeDeferred": {
            "type": "integer",
            "format": "int64",
            "description": "Trade commands held back because another request on\nthe same ticket is still at the dealer. These have left the queue\nbut have not been sent, so they are counted in neither\n`tradeQueueDepth` nor `tradeInFlight`. Always 0 on MT4."
          },
          "tradeEaHeartbeatAgeMs": {
            "type": "integer",
            "format": "int64",
            "description": "Milliseconds since the trading engine last made progress (-1 =\nnot started). Informational: a large age with `tradeEaReady: true`\nmeans it is either blocked in a long dealer call or stuck — worth\nalerting on."
          },
          "tradeEaReady": {
            "type": "boolean",
            "description": "The trading engine is up — `/OrderSend` etc. are ready."
          },
          "tradeInFlight": {
            "type": "integer",
            "format": "int64",
            "description": "Trade requests currently awaiting a dealer verdict."
          },
          "tradeQueueDepth": {
            "type": "integer",
            "format": "int64",
            "description": "Trade commands waiting to be executed."
          },
          "tradeRequestsSent": {
            "type": "integer",
            "format": "int64",
            "description": "Trade commands sent for execution since the connection started,\ncounted at dispatch. Live in both execution modes and on MT4 and\nMT5, so it means the same thing wherever you read it. Note\nthat one command is one count: a `/CloseAll` closing 40 positions\ncounts once, not 40 times."
          },
          "version": {
            "type": "string",
            "description": "Version of this API (semver)."
          }
        }
      },
      "BrokerHealth": {
        "type": "object",
        "required": [
          "connected",
          "server"
        ],
        "properties": {
          "connected": {
            "type": "boolean",
            "description": "Connected to the broker's trade server."
          },
          "server": {
            "type": "string",
            "description": "Broker server name the account is on, e.g. `TegasFX-Main-UK`."
          }
        }
      },
      "Candle": {
        "type": "object",
        "description": "One OHLC bar of `/PriceHistory`. `time` is the bar's open time\n(ISO-8601).",
        "required": [
          "time",
          "open",
          "high",
          "low",
          "close",
          "tickVolume",
          "realVolume",
          "spread"
        ],
        "properties": {
          "close": {
            "type": "number",
            "format": "double"
          },
          "high": {
            "type": "number",
            "format": "double"
          },
          "low": {
            "type": "number",
            "format": "double"
          },
          "open": {
            "type": "number",
            "format": "double"
          },
          "realVolume": {
            "type": "integer",
            "format": "int64"
          },
          "spread": {
            "type": "integer",
            "format": "int64"
          },
          "tickVolume": {
            "type": "integer",
            "format": "int64"
          },
          "time": {
            "type": "string"
          }
        }
      },
      "CloseAllBody": {
        "type": "object",
        "description": "`POST /CloseAll` request body. All fields optional — send an empty\nobject `{}` (with `Content-Type: application/json`) to close every\nopen position on the account.",
        "properties": {
          "deletePending": {
            "type": "boolean",
            "description": "Also delete pending orders matching the filters (default false).",
            "nullable": true
          },
          "magic": {
            "type": "integer",
            "format": "int64",
            "description": "Only act on orders with this exact magic number — 0 matches\nmanually-opened orders. Omit the field entirely for no filter.",
            "nullable": true
          },
          "symbol": {
            "type": "string",
            "description": "Only act on this symbol (omit = all symbols).",
            "nullable": true
          }
        }
      },
      "CloseAllResult": {
        "type": "object",
        "description": "One `/CloseAll` action outcome.",
        "required": [
          "ticket",
          "kind",
          "success",
          "retcode",
          "retcodeDescription"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "description": "`position` (closed) or `pending` (deleted)."
          },
          "retcode": {
            "type": "integer",
            "format": "int64"
          },
          "retcodeDescription": {
            "type": "string"
          },
          "success": {
            "type": "boolean"
          },
          "ticket": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "CloseAllSummary": {
        "type": "object",
        "description": "`/CloseAll` reply — every matched position (and pending order, when\n`deletePending` was set) with its close/delete outcome.",
        "required": [
          "requested",
          "closed",
          "failed",
          "results"
        ],
        "properties": {
          "closed": {
            "type": "integer",
            "format": "int64",
            "description": "Attempts the broker accepted."
          },
          "failed": {
            "type": "integer",
            "format": "int64",
            "description": "Attempts the broker rejected — inspect `results`."
          },
          "requested": {
            "type": "integer",
            "format": "int64",
            "description": "Orders matched by the filters and attempted."
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CloseAllResult"
            }
          }
        }
      },
      "CommissionRule": {
        "type": "object",
        "description": "One broker commission rule for a symbol, as configured server-side\n(MT5 `SymbolInfoCommissions`). A symbol can carry several rules;\neach has its own tiers.",
        "required": [
          "currency",
          "rangeMode",
          "chargeMode",
          "entryMode",
          "directionMode",
          "profitMode",
          "tiers"
        ],
        "properties": {
          "chargeMode": {
            "type": "string",
            "description": "When the commission is charged: instant / daily / monthly\n(`ENUM_SYMBOL_COMMISSION_CHARGE_MODE` constant name)."
          },
          "currency": {
            "type": "string",
            "description": "Commission currency of the rule."
          },
          "directionMode": {
            "type": "string",
            "description": "Applies to buys, sells, or both\n(`ENUM_SYMBOL_COMMISSION_DIRECTION_MODE` constant name)."
          },
          "entryMode": {
            "type": "string",
            "description": "Charged on entry, exit, or both\n(`ENUM_SYMBOL_COMMISSION_ENTRY_MODE` constant name)."
          },
          "profitMode": {
            "type": "string",
            "description": "Applies to all deals, profitable only, or losing only\n(`ENUM_SYMBOL_COMMISSION_PROFIT_MODE` constant name)."
          },
          "rangeMode": {
            "type": "string",
            "description": "What the tier ranges are measured in\n(`ENUM_SYMBOL_COMMISSION_RANGE_MODE` constant name)."
          },
          "tiers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CommissionTier"
            }
          }
        }
      },
      "CommissionTier": {
        "type": "object",
        "description": "One tier of a commission rule — a value and the volume/turnover range\nit applies to. Enum fields carry MetaTrader's own constant names (e.g.\n`SYMBOL_COMMISSION_MODE_MONEY`) so nothing is lost in translation.",
        "required": [
          "mode",
          "volumeType",
          "value",
          "minValue",
          "maxValue",
          "rangeFrom",
          "rangeTo",
          "currency"
        ],
        "properties": {
          "currency": {
            "type": "string",
            "description": "Currency of `value` for money-based modes."
          },
          "maxValue": {
            "type": "number",
            "format": "double",
            "description": "Upper cap on the charged amount (0 = none)."
          },
          "minValue": {
            "type": "number",
            "format": "double",
            "description": "Lower cap on the charged amount (0 = none)."
          },
          "mode": {
            "type": "string",
            "description": "Calculation basis, e.g. money / percent / pips\n(`ENUM_SYMBOL_COMMISSION_MODE` constant name)."
          },
          "rangeFrom": {
            "type": "number",
            "format": "double",
            "description": "Tier range start (volume/turnover, per the rule's `rangeMode`)."
          },
          "rangeTo": {
            "type": "number",
            "format": "double",
            "description": "Tier range end (0 = unbounded)."
          },
          "value": {
            "type": "number",
            "format": "double",
            "description": "Commission value in the units implied by `mode`."
          },
          "volumeType": {
            "type": "string",
            "description": "How the value is applied: per deal / by volume / by turnover\n(`ENUM_SYMBOL_COMMISSION_VOLUME_TYPE` constant name)."
          }
        }
      },
      "ErrorBody": {
        "type": "object",
        "description": "JSON error envelope for REST replies: a fixed `error` code to branch\non, a human-readable `message`, and a `command_id` to quote when\nreporting a problem.",
        "required": [
          "error",
          "message",
          "command_id"
        ],
        "properties": {
          "command_id": {
            "type": "integer",
            "format": "int64"
          },
          "error": {
            "type": "string",
            "description": "Short error code, e.g. `MRPC_TIMEOUT`, `MRPC_VALIDATION`."
          },
          "message": {
            "type": "string"
          }
        }
      },
      "HistoryTrade": {
        "type": "object",
        "description": "One row of `/OrderHistory`: a historical deal. `time` is ISO-8601.",
        "required": [
          "ticket",
          "order",
          "position",
          "symbol",
          "type",
          "entry",
          "volume",
          "price",
          "sl",
          "tp",
          "commission",
          "swap",
          "profit",
          "magic",
          "comment",
          "time"
        ],
        "properties": {
          "comment": {
            "type": "string"
          },
          "commission": {
            "type": "number",
            "format": "double"
          },
          "entry": {
            "type": "string"
          },
          "magic": {
            "type": "integer",
            "format": "int64"
          },
          "order": {
            "type": "integer",
            "format": "int64"
          },
          "position": {
            "type": "integer",
            "format": "int64",
            "description": "`DEAL_POSITION_ID` — the join key linking this deal to its\nposition (`In` and `Out` rows of one round-trip share it, and it\nmatches the WS `trade` event's `position` and\n`/PositionHistory.positionId`). Exit deals carry no magic/comment\n(MT5 semantics), so this is the only REST-side correlation\ncarrier on closes."
          },
          "price": {
            "type": "number",
            "format": "double"
          },
          "profit": {
            "type": "number",
            "format": "double"
          },
          "sl": {
            "type": "number",
            "format": "double",
            "description": "Stop Loss (`0` = none). Entry deals carry the opening order's\nlevel, exit deals the position's level when it closed\n(`DEAL_SL`)."
          },
          "swap": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "ticket": {
            "type": "integer",
            "format": "int64"
          },
          "time": {
            "type": "string"
          },
          "tp": {
            "type": "number",
            "format": "double",
            "description": "Take Profit on this row (`0` = none)."
          },
          "type": {
            "type": "string"
          },
          "volume": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "MarginResult": {
        "type": "object",
        "required": [
          "symbol",
          "operation",
          "volume",
          "price",
          "margin",
          "currency"
        ],
        "properties": {
          "currency": {
            "type": "string"
          },
          "margin": {
            "type": "number",
            "format": "double"
          },
          "operation": {
            "type": "string"
          },
          "price": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "volume": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "OpenedOrder": {
        "type": "object",
        "description": "One row of `/OpenedOrders`: an open market position or a pending\norder. `kind` discriminates the two; `swap`/`profit` are 0 for\npending orders. `openTime` is ISO-8601 (broker server time).",
        "required": [
          "ticket",
          "symbol",
          "type",
          "kind",
          "lots",
          "openPrice",
          "currentPrice",
          "stopLoss",
          "takeProfit",
          "swap",
          "profit",
          "magic",
          "comment",
          "openTime"
        ],
        "properties": {
          "comment": {
            "type": "string"
          },
          "currentPrice": {
            "type": "number",
            "format": "double"
          },
          "kind": {
            "type": "string"
          },
          "lots": {
            "type": "number",
            "format": "double"
          },
          "magic": {
            "type": "integer",
            "format": "int64"
          },
          "openPrice": {
            "type": "number",
            "format": "double"
          },
          "openTime": {
            "type": "string"
          },
          "profit": {
            "type": "number",
            "format": "double"
          },
          "stopLoss": {
            "type": "number",
            "format": "double"
          },
          "swap": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "takeProfit": {
            "type": "number",
            "format": "double"
          },
          "ticket": {
            "type": "integer",
            "format": "int64"
          },
          "type": {
            "type": "string"
          }
        }
      },
      "OrderCloseBody": {
        "type": "object",
        "required": [
          "ticket"
        ],
        "properties": {
          "pendingOnly": {
            "type": "boolean",
            "description": "Only delete a pending order. A ticket whose order has filled into\na position by now is left open and refused with `409\nMRPC_NOT_PENDING`, so a cancel that crosses a fill keeps the fill.",
            "nullable": true
          },
          "slippage": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "ticket": {
            "type": "integer",
            "format": "int64",
            "description": "Position ticket (closes it) or pending-order ticket (deletes it)."
          },
          "volume": {
            "type": "number",
            "format": "double",
            "description": "Partial close volume; omit / 0 = full close. Ignored for pendings.",
            "nullable": true
          }
        }
      },
      "OrderEvent": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PendingOrder"
          },
          {
            "type": "object",
            "required": [
              "event",
              "position"
            ],
            "properties": {
              "event": {
                "type": "string",
                "description": "`placed`, `modified` (price, stops, expiry, volume or type),\n`deleted`, `expired` or `triggered`."
              },
              "position": {
                "type": "integer",
                "format": "int64",
                "description": "`triggered`: the position its fill opened or added to — MT4 keeps\nthe ticket, so there it is the order's own. 0 otherwise."
              }
            }
          }
        ],
        "description": "An `order` event on the `orders` stream."
      },
      "OrderModifyBody": {
        "type": "object",
        "required": [
          "ticket"
        ],
        "properties": {
          "expiration": {
            "type": "string",
            "description": "New expiration (date string, broker server time) — pending orders only.",
            "nullable": true
          },
          "expirationUtc": {
            "type": "string",
            "description": "New expiration in real UTC instead (ISO-8601, e.g.\n`2026-11-03T17:00:00Z`). Not together with `expiration`.",
            "nullable": true
          },
          "price": {
            "type": "number",
            "format": "double",
            "description": "New price — pending orders only.",
            "nullable": true
          },
          "stopLimitPrice": {
            "type": "number",
            "format": "double",
            "description": "New StopLimit price — *StopLimit pending orders only.",
            "nullable": true
          },
          "stopLoss": {
            "type": "number",
            "format": "double",
            "description": "New SL/TP (omit to keep current). For positions only SL/TP apply.",
            "nullable": true
          },
          "takeProfit": {
            "type": "number",
            "format": "double",
            "nullable": true
          },
          "ticket": {
            "type": "integer",
            "format": "int64",
            "description": "Position or pending-order ticket."
          }
        }
      },
      "OrderSendBody": {
        "type": "object",
        "required": [
          "symbol",
          "operation",
          "volume"
        ],
        "properties": {
          "clientOrderId": {
            "type": "string",
            "description": "Your id for this order (1–64 characters). Repeating a request with\nthe same id within 10 minutes places nothing new: it is answered\nwith the first request's outcome (header `Idempotent-Replayed:\ntrue`), waiting for it if it is still being executed. Reusing an\nid for a different order is a `409`.",
            "nullable": true
          },
          "comment": {
            "type": "string",
            "nullable": true
          },
          "execution": {
            "type": "string",
            "description": "How the order is placed: `EA` (default) sends it as an expert\norder, the normal way; `Manual` places it through MetaTrader's own\nNew Order dialog, for brokers that block expert trading\n(`tradeExpert: false` on `/AccountInfo`, expert orders fail with\nretcode 10026). A Manual order is a market order (`Buy`/`Sell`)\nand always has magic 0; `slippage` does not apply.",
            "nullable": true
          },
          "expertId": {
            "type": "integer",
            "format": "int64",
            "description": "Magic number. Accepts `expertId`, `magic`, `expertID`.",
            "nullable": true
          },
          "expiration": {
            "type": "string",
            "description": "Date string in broker server time; absent → good-till-cancelled.",
            "nullable": true
          },
          "expirationUtc": {
            "type": "string",
            "description": "The expiry in real UTC instead (ISO-8601, e.g.\n`2026-11-03T17:00:00Z`), converted with the server's current\noffset. Not together with `expiration`.",
            "nullable": true
          },
          "operation": {
            "type": "string",
            "description": "Buy, Sell, BuyLimit, SellLimit, BuyStop, SellStop, BuyStopLimit,\nSellStopLimit (case/separator-insensitive)."
          },
          "price": {
            "type": "number",
            "format": "double",
            "description": "Required for pending orders; ignored for market orders.",
            "nullable": true
          },
          "slippage": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "stopLimitPrice": {
            "type": "number",
            "format": "double",
            "description": "Required for *StopLimit operations.",
            "nullable": true
          },
          "stopLoss": {
            "type": "number",
            "format": "double",
            "nullable": true
          },
          "symbol": {
            "type": "string",
            "description": "Symbol to trade, e.g. `EURUSD`."
          },
          "takeProfit": {
            "type": "number",
            "format": "double",
            "nullable": true
          },
          "volume": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "OrderSendResult": {
        "type": "object",
        "description": "Result of `POST /OrderSend`. Mirrors the salient `MqlTradeResult`\nfields. `success` is derived from `retcode` (DONE/PLACED); `outcome`\nclassifies it further (see `trade_outcome`). `price` is the fill\nprice for market orders and the resting price for pending orders;\n`comment` is the broker's message about the operation (empty on\nMT4, which has no such message).",
        "required": [
          "success",
          "outcome",
          "retcode",
          "retcodeDescription",
          "deal",
          "order",
          "volume",
          "price",
          "bid",
          "ask",
          "comment",
          "position",
          "time",
          "remainderTicket"
        ],
        "properties": {
          "ask": {
            "type": "number",
            "format": "double"
          },
          "bid": {
            "type": "number",
            "format": "double"
          },
          "clientOrderId": {
            "type": "string",
            "description": "The request's `clientOrderId`, when it carried one.",
            "nullable": true
          },
          "comment": {
            "type": "string"
          },
          "deal": {
            "type": "integer",
            "format": "int64"
          },
          "order": {
            "type": "integer",
            "format": "int64"
          },
          "outcome": {
            "type": "string",
            "description": "`\"applied\"` | `\"no_change\"` | `\"partial\"` | `\"rejected\"` — see `trade_outcome`."
          },
          "position": {
            "type": "integer",
            "format": "int64",
            "description": "Position the trade opened, changed or closed (`DEAL_POSITION_ID`);\n0 for a pending order, or when the deal record was not in history\nyet and the position could not be told from the order."
          },
          "price": {
            "type": "number",
            "format": "double"
          },
          "remainderTicket": {
            "type": "integer",
            "format": "int64",
            "description": "MT4 only (a partial close moves the rest to a new ticket); 0 here."
          },
          "retcode": {
            "type": "integer",
            "format": "int64"
          },
          "retcodeDescription": {
            "type": "string"
          },
          "success": {
            "type": "boolean"
          },
          "time": {
            "type": "string",
            "description": "When the order filled, ms precision, broker server time like every\nother time here; empty when nothing filled (modify, pending order,\nrejection) or the deal record was not in history yet."
          },
          "timeUtc": {
            "type": "string",
            "description": "`time` in real UTC, converted with the server's current offset;\nabsent until that offset is known (the connection's first\nsecond) and when `time` is empty.",
            "nullable": true
          },
          "volume": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "PendingOrder": {
        "type": "object",
        "description": "An active pending order: a `/PendingOrders` row, a row of the\n`orders` stream's snapshot, and the body of every `order` event.",
        "required": [
          "ticket",
          "symbol",
          "type",
          "volumeInitial",
          "volume",
          "price",
          "stopLimitPrice",
          "sl",
          "tp",
          "expirationMode",
          "expiration",
          "expirationUtc",
          "magic",
          "comment",
          "time"
        ],
        "properties": {
          "comment": {
            "type": "string"
          },
          "expiration": {
            "type": "string",
            "description": "When it expires, broker server time like every other time here;\nempty when it does not."
          },
          "expirationMode": {
            "type": "string",
            "description": "`gtc`, `day`, `specified` or `specifiedDay` (see `/SymbolInfo`\n`expirationModes`)."
          },
          "expirationUtc": {
            "type": "string",
            "description": "The same moment in real UTC — comparable across brokers."
          },
          "magic": {
            "type": "integer",
            "format": "int64"
          },
          "price": {
            "type": "number",
            "format": "double",
            "description": "The price it triggers at."
          },
          "sl": {
            "type": "number",
            "format": "double"
          },
          "stopLimitPrice": {
            "type": "number",
            "format": "double",
            "description": "The limit price a stop-limit order turns into; 0 otherwise."
          },
          "symbol": {
            "type": "string"
          },
          "ticket": {
            "type": "integer",
            "format": "int64"
          },
          "time": {
            "type": "string",
            "description": "When it was placed, broker server time."
          },
          "timeUtc": {
            "type": "string",
            "description": "`time` in real UTC, converted with the server's current offset;\nabsent until that offset is known (the connection's first\nsecond) and when `time` is empty.",
            "nullable": true
          },
          "tp": {
            "type": "number",
            "format": "double"
          },
          "type": {
            "type": "string",
            "description": "`BuyLimit`, `SellLimit`, `BuyStop`, `SellStop`, `BuyStopLimit` or\n`SellStopLimit`."
          },
          "volume": {
            "type": "number",
            "format": "double",
            "description": "Lots still to fill."
          },
          "volumeInitial": {
            "type": "number",
            "format": "double",
            "description": "Lots when placed."
          }
        }
      },
      "PositionTrade": {
        "type": "object",
        "description": "One closed round-trip position of `/PositionHistory`, reconstructed by\ngrouping deals on `DEAL_POSITION_ID`. `profit` is the gross price P/L;\n`netProfit = profit + swap + commission` is what actually hit the\nbalance (summed across the position's whole lifetime). `type` is the\nposition direction (`Buy` = long, `Sell` = short). `openPrice`/\n`closePrice` are volume-weighted across scale-in / partial-close fills.\n`openTime` is the first entry, `closeTime` the last exit. Times are\nISO-8601 (broker server time).",
        "required": [
          "positionId",
          "symbol",
          "type",
          "volume",
          "openTime",
          "openPrice",
          "closeTime",
          "closePrice",
          "sl",
          "tp",
          "profit",
          "swap",
          "commission",
          "netProfit",
          "magic",
          "comment"
        ],
        "properties": {
          "closePrice": {
            "type": "number",
            "format": "double"
          },
          "closeTime": {
            "type": "string"
          },
          "comment": {
            "type": "string"
          },
          "commission": {
            "type": "number",
            "format": "double"
          },
          "magic": {
            "type": "integer",
            "format": "int64"
          },
          "netProfit": {
            "type": "number",
            "format": "double",
            "description": "`profit + swap + commission` — the net effect on the balance."
          },
          "openPrice": {
            "type": "number",
            "format": "double"
          },
          "openTime": {
            "type": "string"
          },
          "positionId": {
            "type": "integer",
            "format": "int64"
          },
          "profit": {
            "type": "number",
            "format": "double",
            "description": "Gross price profit (sum of the position's deal profits)."
          },
          "sl": {
            "type": "number",
            "format": "double",
            "description": "Stop Loss the position carried when it closed (`0` = none)."
          },
          "swap": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "tp": {
            "type": "number",
            "format": "double",
            "description": "Take Profit the position carried when it closed (`0` = none)."
          },
          "type": {
            "type": "string"
          },
          "volume": {
            "type": "number",
            "format": "double",
            "description": "Volume opened (lots)."
          }
        }
      },
      "ProfitResult": {
        "type": "object",
        "required": [
          "symbol",
          "operation",
          "volume",
          "priceOpen",
          "priceClose",
          "profit",
          "currency"
        ],
        "properties": {
          "currency": {
            "type": "string"
          },
          "operation": {
            "type": "string"
          },
          "priceClose": {
            "type": "number",
            "format": "double"
          },
          "priceOpen": {
            "type": "number",
            "format": "double"
          },
          "profit": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "volume": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "QuoteData": {
        "type": "object",
        "description": "One row of `/getQuote`: the latest tick for a symbol. `time` is\nISO-8601, the tick's broker server time.",
        "required": [
          "symbol",
          "bid",
          "ask",
          "time",
          "last",
          "volume"
        ],
        "properties": {
          "ask": {
            "type": "number",
            "format": "double"
          },
          "bid": {
            "type": "number",
            "format": "double"
          },
          "last": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "time": {
            "type": "string"
          },
          "volume": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "ServerTimezoneData": {
        "type": "object",
        "description": "`/ServerTimezone` — broker server clock + offset to UTC.\n\n`server_time` is broker server time as ISO-8601, labelled `Z` like\nevery other time in this API — the `Z` is stylistic;\n`utc_offset_seconds` is the source of truth for the real offset\n(server time minus UTC), e.g. `7200` for a broker on UTC+2.",
        "required": [
          "serverTime",
          "utcOffsetSeconds"
        ],
        "properties": {
          "serverTime": {
            "type": "string"
          },
          "utcOffsetSeconds": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "StatusResponse": {
        "type": "object",
        "description": "`/status` — a point-in-time health snapshot of this account's\nconnection.\n\n`status` is a coarse roll-up for dashboards: `ready` (fully\noperational), `starting` (logged in but still syncing symbols or\nstarting the trading engine), `degraded` (connection alive but the\nbroker link or account login is down), or `down` (the connection did\nnot answer — stuck or still starting). The endpoint always returns\nHTTP 200; read this field, not the status code.",
        "required": [
          "status",
          "terminal",
          "broker",
          "account",
          "bridge",
          "serverTime"
        ],
        "properties": {
          "account": {
            "$ref": "#/components/schemas/AccountHealth"
          },
          "bridge": {
            "$ref": "#/components/schemas/BridgeHealth"
          },
          "broker": {
            "$ref": "#/components/schemas/BrokerHealth"
          },
          "serverTime": {
            "type": "string",
            "description": "Broker server time (ISO-8601). Empty when the connection is down."
          },
          "status": {
            "type": "string"
          },
          "terminal": {
            "$ref": "#/components/schemas/TerminalHealth"
          }
        }
      },
      "SymbolError": {
        "type": "object",
        "required": [
          "symbol",
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Error code, as `ErrorBody.error`."
          },
          "message": {
            "type": "string"
          },
          "symbol": {
            "type": "string"
          }
        }
      },
      "SymbolInfoBulk": {
        "type": "object",
        "description": "`/SymbolInfo?symbols=…` reply.",
        "required": [
          "symbols",
          "errors"
        ],
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SymbolError"
            },
            "description": "The symbols that did not, with the error a single `/SymbolInfo`\nwould have answered."
          },
          "symbols": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SymbolInfoData"
            },
            "description": "The symbols that resolved, in request order."
          }
        }
      },
      "SymbolInfoData": {
        "type": "object",
        "description": "`/SymbolInfo` — contract specification for one symbol.",
        "required": [
          "symbol",
          "description",
          "digits",
          "point",
          "tickSize",
          "tickValue",
          "contractSize",
          "volumeMin",
          "volumeMax",
          "volumeStep",
          "stopsLevel",
          "freezeLevel",
          "spread",
          "tradeMode",
          "swapLong",
          "swapShort",
          "bid",
          "ask",
          "currencyBase",
          "currencyProfit",
          "currencyMargin",
          "orderModes",
          "expirationModes",
          "fillingModes",
          "commissions",
          "sessions"
        ],
        "properties": {
          "ask": {
            "type": "number",
            "format": "double"
          },
          "bid": {
            "type": "number",
            "format": "double"
          },
          "commissions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CommissionRule"
            },
            "description": "The broker's commission rules for this symbol, straight from the\nserver's symbol specification (MetaTrader build 6060+; empty when\nthe broker publishes none or the build is older)."
          },
          "contractSize": {
            "type": "number",
            "format": "double"
          },
          "currencyBase": {
            "type": "string"
          },
          "currencyMargin": {
            "type": "string"
          },
          "currencyProfit": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "digits": {
            "type": "integer",
            "format": "int64"
          },
          "expirationModes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Pending-order expiry kinds: `gtc` (until cancelled), `day` (end of\nthe trading day), `specified` (date and time), `specifiedDay`\n(end of a given day)."
          },
          "fillingModes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Fill policies: `fok`, `ioc`, `boc`. Empty on MT4, which has none."
          },
          "freezeLevel": {
            "type": "integer",
            "format": "int64"
          },
          "orderModes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Order kinds the broker takes on this symbol: `market`, `limit`,\n`stop`, `stopLimit`, `sl`, `tp`, `closeBy`."
          },
          "point": {
            "type": "number",
            "format": "double"
          },
          "sessions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TradingSession"
            },
            "description": "Trading-session windows per weekday, in the broker's server time."
          },
          "spread": {
            "type": "integer",
            "format": "int64"
          },
          "stopsLevel": {
            "type": "integer",
            "format": "int64"
          },
          "swapLong": {
            "type": "number",
            "format": "double"
          },
          "swapShort": {
            "type": "number",
            "format": "double"
          },
          "symbol": {
            "type": "string"
          },
          "tickSize": {
            "type": "number",
            "format": "double"
          },
          "tickValue": {
            "type": "number",
            "format": "double"
          },
          "tradeMode": {
            "type": "string"
          },
          "volumeMax": {
            "type": "number",
            "format": "double"
          },
          "volumeMin": {
            "type": "number",
            "format": "double"
          },
          "volumeStep": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "SymbolSelectBody": {
        "type": "object",
        "description": "`POST /SymbolSelect` request body.",
        "required": [
          "symbols"
        ],
        "properties": {
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Symbol names as listed by `/symbols` — at most 100."
          }
        }
      },
      "SymbolSelectResult": {
        "type": "object",
        "description": "One row of a `/SymbolSelect` reply.",
        "required": [
          "symbol",
          "selected",
          "quoting"
        ],
        "properties": {
          "quoting": {
            "type": "boolean",
            "description": "It had a live bid/ask by the time the reply was sent. A freshly\nselected symbol may need a moment longer — or never quote, for a\nname the broker lists but does not feed."
          },
          "selected": {
            "type": "boolean",
            "description": "The symbol is in Market Watch (false: unknown to this broker)."
          },
          "symbol": {
            "type": "string"
          }
        }
      },
      "TerminalHealth": {
        "type": "object",
        "required": [
          "alive",
          "build",
          "pingMs"
        ],
        "properties": {
          "alive": {
            "type": "boolean",
            "description": "The connection answered (it is processing requests). When false,\nevery field below is last-known/empty."
          },
          "build": {
            "type": "integer",
            "format": "int64",
            "description": "MetaTrader build number, e.g. `5836`. 0 when down."
          },
          "pingMs": {
            "type": "integer",
            "format": "int64",
            "description": "Last measured round-trip to the broker, milliseconds. 0 when down."
          }
        }
      },
      "TradingSession": {
        "type": "object",
        "description": "One trading-session window of a symbol (server time). Days are\n`SUNDAY` … `SATURDAY`; a 24-hour market shows `00:00`–`24:00`.",
        "required": [
          "day",
          "from",
          "to"
        ],
        "properties": {
          "day": {
            "type": "string",
            "description": "Weekday, e.g. `MONDAY`."
          },
          "from": {
            "type": "string",
            "description": "Session start `HH:MM` in the broker's server time."
          },
          "to": {
            "type": "string",
            "description": "Session end `HH:MM` (`24:00` = end of day)."
          }
        }
      }
    },
    "securitySchemes": {
      "api_key": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Account owner's API key — full, or read-only (read-only keys get 403 on the trading endpoints). The ?api_key= query parameter is accepted too (WebSocket clients have no other option)."
      }
    }
  },
  "security": [
    {
      "api_key": []
    }
  ],
  "tags": [
    {
      "name": "account",
      "description": "Account state, open trades, deal history."
    },
    {
      "name": "market",
      "description": "Quotes, OHLC bars, symbol contract specs."
    },
    {
      "name": "trading",
      "description": "Margin/profit calculation and placing, modifying and closing orders."
    },
    {
      "name": "system",
      "description": "Is the connection alive, connected to the broker, and logged in?"
    }
  ]
}
