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.12pip install requests export FIVESOCKET_KEY="mt5_live_..."
mt5.py and run python mt5.py.12345678910111213141516171819202122232425262728293031import 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"])
202 account_warming means the session is logging in to your broker. Repeat the same read after Retry-After.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.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.12345678910111213141516171819202122232425import 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"])
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.