Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

Python quickstart

FiveSocket is plain HTTPS, so Python needs only requests. It runs the same on Linux, macOS, Windows, Docker and serverless, because the MT5 terminal runs at FiveSocket and not on your machine. There is no FiveSocket Python package and the MetaQuotes MetaTrader5 package is not involved.
For the longer guide with pandas and order examples, see the MT5 API for Python.

Before you start

  • Link an MT5 account with its login, password and exact server name, in the control app or with the quickstart.
  • Create an API key with the accounts:read and data:read scopes. See authentication.
pip install requests export FIVESOCKET_KEY="mt5_live_..."

Read balance, positions and candles

Save this as mt5.py and run python mt5.py.
import os import time import requests BASE = "https://api.fivesocket.com/v1" session = requests.Session() session.headers["Authorization"] = f"Bearer {os.environ['FIVESOCKET_KEY']}" def get(path, **params): for attempt in range(6): response = session.get(f"{BASE}{path}", params=params, timeout=60) if response.status_code in (202, 429, 503) and attempt < 5: wait = response.headers.get("Retry-After", "") time.sleep(int(wait) if wait.isdigit() and int(wait) > 0 else 2**attempt) continue response.raise_for_status() return response.json() account_id = get("/accounts")["data"][0]["id"] balance = get(f"/accounts/{account_id}/balance") print(balance["balance"], balance["equity"], balance["currency"]) for position in get(f"/accounts/{account_id}/positions")["positions"]: print(position["symbol"], position["side"], position["volume"], position["profit"]) candles = get(f"/accounts/{account_id}/candles", symbol="EURUSD", timeframe="H1", count=200) print(len(candles["data"]), candles["data"][-1]["close"])
What the helper handles:
  • 202 account_warming means the session is logging in to your broker. Repeat the same read after Retry-After.
  • 429 rate_limit_exceeded and 503 responses also carry Retry-After. See errors and limits.
  • Money, prices and volumes are decimal strings. Convert them with decimal.Decimal or float as your code needs.
symbol must be the exact name your broker uses, such as EURUSD or EURUSDm. An unknown name returns 404 symbol_not_found with suggestions from the account's own symbol list.

Place an order

Orders need a key with the trading:execute scope and a trading policy on the account. Send the policy once, then the order. Every write needs an Idempotency-Key header, and clientOrderId must be unique for the account.
import os import requests BASE = "https://api.fivesocket.com/v1" ACCOUNT = os.environ["FIVESOCKET_ACCOUNT_ID"] auth = {"Authorization": f"Bearer {os.environ['FIVESOCKET_KEY']}"} policy = requests.put( f"{BASE}/accounts/{ACCOUNT}/execution", headers={**auth, "Idempotency-Key": "enable-1"}, json={"symbols": [{"symbol": "EURUSD", "maxVolume": "0.10"}]}, timeout=60, ) policy.raise_for_status() order = requests.post( f"{BASE}/accounts/{ACCOUNT}/execution/orders", headers={**auth, "Idempotency-Key": "order-1"}, json={"clientOrderId": "order-1", "symbol": "EURUSD", "side": "buy", "type": "market", "volume": "0.10"}, timeout=240, ) order.raise_for_status() command = order.json() print(command["outcome"], command["commandId"])
A 202 response with outcome: "commit_unknown" means the broker's reply was lost. Do not send a new order. Poll GET /v1/accounts/{accountId}/execution/commands/{commandId} until the outcome is final.
Use a demo account first. An order sent to a live account is a real trade.

Next

  • Prop firm accounts covers the order guard for FTMO, FundedNext and The5ers programs.
  • Google Sheets and n8n use the same endpoints without Python.
  • The API Reference tab lists every request and response field.