{"id":"f97d7dc2-8b1b-4adf-99df-5ff9a4683d51","entityType":"agent","slug":"clawhub-psyb0t-mt5-httpapi","name":"mt5-httpapi","canonicalUrl":"https://www.xpersona.co/agent/clawhub-psyb0t-mt5-httpapi","canonicalPath":"/agent/clawhub-psyb0t-mt5-httpapi","generatedAt":"2026-10-09T09:46:39.378Z","source":"CLAWHUB","claimStatus":"UNCLAIMED","verificationTier":"NONE","summary":{"evidence":{"source":"editorial-content","verified":true,"confidence":"high","updatedAt":"2026-04-15T00:45:39.800Z","emptyReason":null},"description":"MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp... Skill: mt5-httpapi Owner: psyb0t Summary: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp... Tags: latest:1.1.0 Version history: v1.1.0 | 2026-02-19T16:47:22.192Z | user Initial public release. - Added API reference covering health checks, account info, symbols, orders, positions, and history endpoints. - Inc","descriptionLabel":"Technical summary","evidenceSummary":"Capability contract not published. No trust telemetry is available yet. 552 downloads reported by the source. Last updated 4/15/2026.","installCommand":"clawhub skill install kn79dhvmpjng4rp2jjk8k0v5xx80ccbk:mt5-httpapi","sourceUrl":"https://clawhub.ai/psyb0t/mt5-httpapi","homepage":"https://clawhub.ai/psyb0t/mt5-httpapi","primaryLinks":[{"label":"View on ClawHub","url":"https://clawhub.ai/psyb0t/mt5-httpapi","kind":"source"}],"safetyScore":84,"overallRank":62,"popularityScore":55,"trustScore":null,"claimedByName":null,"isOwner":false,"seoDescription":"MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp..."},"coverage":{"evidence":{"source":"public-profile","verified":false,"confidence":"medium","updatedAt":"2026-04-15T00:45:39.800Z","emptyReason":null},"protocols":[{"protocol":"OPENCLEW","label":"OpenClaw","status":"self-declared","notes":"Declared in the public agent profile."}],"capabilities":[],"verifiedCount":0,"selfDeclaredCount":1,"capabilityMatrix":{"rows":[{"key":"OPENCLEW","type":"protocol","support":"unknown","confidenceSource":"profile","notes":"Listed on profile"}],"flattenedTokens":"protocol:OPENCLEW|unknown|profile"}},"adoption":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-04-15T00:45:39.800Z","emptyReason":null},"stars":null,"forks":null,"downloads":552,"packageName":null,"latestVersion":"1.1.0","tractionLabel":"552 downloads"},"release":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-03-01T04:46:01.584Z","emptyReason":null},"lastUpdatedAt":"2026-04-15T00:45:39.800Z","lastCrawledAt":"2026-03-01T04:46:01.584Z","lastIndexedAt":null,"nextCrawlAt":"2026-03-02T04:46:01.584Z","lastVerifiedAt":null,"highlights":[{"version":"1.1.0","createdAt":"2026-02-19T16:47:22.192Z","changelog":"Initial public release. - Added API reference covering health checks, account info, symbols, orders, positions, and history endpoints. - Included detailed field/key descriptions for safer pre-trade checks and parameter usage. - Provided concise setup instructions and example curl commands for all major endpoints. - Documented example position sizing calculations and helpful trading tips. - Added dedicated [references/setup.md] file for installation details.","fileCount":3,"zipByteSize":4062},{"version":"1.0.0","createdAt":"2026-02-15T08:30:30.099Z","changelog":"mt5-httpapi 1.0.0 initial release - Provides REST API access to MetaTrader 5 for market data retrieval and trading operations. - Supports getting account info, symbols, terminal state, market history, open positions, and more. - Enables placing, modifying, and closing orders on forex/crypto/stock markets via HTTP/JSON. - Designed for easy integration using curl or similar tools — no MT5 libraries or Windows dependencies required. - Includes environment variable setup instructions and clear API documentation.","fileCount":2,"zipByteSize":9151}]},"execution":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No published capability contract is available yet."},"installCommand":"clawhub skill install kn79dhvmpjng4rp2jjk8k0v5xx80ccbk:mt5-httpapi","setupComplexity":"low","setupSteps":["Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.","Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data."],"contract":{"contractStatus":"missing","authModes":[],"requires":[],"forbidden":[],"supportsMcp":false,"supportsA2a":false,"supportsStreaming":false,"inputSchemaRef":null,"outputSchemaRef":null,"dataRegion":null,"contractUpdatedAt":null,"sourceUpdatedAt":null,"freshnessSeconds":null},"invocationGuide":{"preferredApi":{"snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/trust"},"curlExamples":["curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/snapshot\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/contract\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/trust\""],"jsonRequestTemplate":{"query":"summarize this repo","constraints":{"maxLatencyMs":2000,"protocolPreference":["OPENCLEW"]}},"jsonResponseTemplate":{"ok":true,"result":{"summary":"...","confidence":0.9},"meta":{"source":"CLAWHUB","generatedAt":"2026-10-09T09:46:39.377Z"}},"retryPolicy":{"maxAttempts":3,"backoffMs":[500,1500,3500],"retryableConditions":["HTTP_429","HTTP_503","NETWORK_TIMEOUT"]}},"endpoints":{"dossierUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/dossier","snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-psyb0t-mt5-httpapi/trust"}},"reliability":{"evidence":{"source":"runtime-metrics","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No trust, reliability, or runtime telemetry is available."},"trust":{"status":"unavailable","handshakeStatus":"UNKNOWN","verificationFreshnessHours":null,"reputationScore":null,"p95LatencyMs":null,"successRate30d":null,"fallbackRate":null,"attempts30d":null,"trustUpdatedAt":null,"trustConfidence":"unknown","sourceUpdatedAt":null,"freshnessSeconds":null},"decisionGuardrails":{"doNotUseIf":["Contract metadata is missing or unavailable for deterministic execution."],"safeUseWhen":[],"riskFlags":["missing_or_unavailable_contract","trust_data_unavailable","schema_references_missing"],"operationalConfidence":"low"},"executionMetrics":{"observedLatencyMsP50":null,"observedLatencyMsP95":null,"estimatedCostUsd":null,"uptime30d":null,"rateLimitRpm":null,"rateLimitBurst":null,"lastVerifiedAt":null,"verificationSource":null},"runtimeMetrics":{"successRate":null,"avgLatencyMs":null,"avgCostUsd":null,"hallucinationRate":null,"retryRate":null,"disputeRate":null,"p50Latency":null,"p95Latency":null,"lastUpdated":null}},"benchmarks":{"evidence":{"source":"no-benchmark-data","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No benchmark suites or observed failure patterns are available."},"suites":[],"failurePatterns":[]},"artifacts":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"high","updatedAt":"2026-04-15T00:45:39.800Z","emptyReason":null},"readme":"Skill: mt5-httpapi\n\nOwner: psyb0t\n\nSummary: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp...\n\nTags: latest:1.1.0\n\nVersion history:\n\nv1.1.0 | 2026-02-19T16:47:22.192Z | user\n\nInitial public release.\n\n- Added API reference covering health checks, account info, symbols, orders, positions, and history endpoints.\n- Included detailed field/key descriptions for safer pre-trade checks and parameter usage.\n- Provided concise setup instructions and example curl commands for all major endpoints.\n- Documented example position sizing calculations and helpful trading tips.\n- Added dedicated [references/setup.md] file for installation details.\n\nv1.0.0 | 2026-02-15T08:30:30.099Z | user\n\nmt5-httpapi 1.0.0 initial release\n\n- Provides REST API access to MetaTrader 5 for market data retrieval and trading operations.\n- Supports getting account info, symbols, terminal state, market history, open positions, and more.\n- Enables placing, modifying, and closing orders on forex/crypto/stock markets via HTTP/JSON.\n- Designed for easy integration using curl or similar tools — no MT5 libraries or Windows dependencies required.\n- Includes environment variable setup instructions and clear API documentation.\n\nArchive index:\n\nArchive v1.1.0: 3 files, 4062 bytes\n\nFiles: references/setup.md (2335b), SKILL.md (5931b), _meta.json (130b)\n\nFile v1.1.0:SKILL.md\n\n---\nname: mt5-httpapi\ndescription: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/crypto/stock markets through MT5.\ncompatibility: Requires curl and a running mt5-httpapi instance. MT5_API_URL env var must be set.\nmetadata:\n  author: psyb0t\n  homepage: https://github.com/psyb0t/mt5-httpapi\n---\n\n# mt5-httpapi\n\nREST API on top of MetaTrader 5 running inside a Windows VM. Talk to it with plain HTTP/JSON — no MT5 libraries, no Windows, no bullshit. Just curl and go.\n\nFor installation and setup, see [references/setup.md](references/setup.md).\n\n## Setup\n\nThe API should already be running. Set the base URL:\n\n```bash\nexport MT5_API_URL=http://localhost:6542\n```\n\nEach terminal has its own port (configured in `terminals.json`). If running multiple terminals, set `MT5_API_URL` to the port for the terminal you want to talk to.\n\n**Verify:** `curl $MT5_API_URL/ping` — should return `{\"status\": \"ok\"}`. If not, the API isn't up yet (may still be initializing — it retries in the background).\n\n## How It Works\n\nGET for reading, POST for creating, PUT for modifying, DELETE for closing/canceling. All bodies are JSON.\n\nEvery error response:\n\n```json\n{\"error\": \"description of what went wrong\"}\n```\n\n## Pre-Trade Checks (DO NOT SKIP)\n\nBefore placing any trade:\n\n1. `GET /account` → `trade_allowed` must be `true`\n2. `GET /symbols/SYMBOL` → `trade_mode` must be `4` (full trading)\n3. `GET /symbols/SYMBOL` → check `trade_contract_size` — 1 lot of EURUSD = 100,000 EUR, not 1 EUR\n4. `GET /terminal` → `connected` must be `true`\n\n## API Reference\n\n### Health\n\n```bash\ncurl $MT5_API_URL/ping\n# {\"status\": \"ok\"}\n\ncurl $MT5_API_URL/error\n# {\"code\": 1, \"message\": \"Success\"}\n```\n\n### Terminal\n\n```bash\ncurl $MT5_API_URL/terminal\ncurl -X POST $MT5_API_URL/terminal/init\ncurl -X POST $MT5_API_URL/terminal/shutdown\n```\n\nKey fields on `/terminal`: `connected`, `trade_allowed`, `build`, `company`.\n\n### Account\n\n```bash\ncurl $MT5_API_URL/account\n```\n\n```json\n{\n    \"login\": 12345678,\n    \"balance\": 10000.0,\n    \"equity\": 10000.0,\n    \"margin\": 0.0,\n    \"margin_free\": 10000.0,\n    \"margin_level\": 0.0,\n    \"leverage\": 500,\n    \"currency\": \"USD\",\n    \"trade_allowed\": true,\n    \"margin_so_call\": 70.0,\n    \"margin_so_so\": 20.0\n}\n```\n\n### Symbols\n\n```bash\ncurl $MT5_API_URL/symbols\ncurl \"$MT5_API_URL/symbols?group=*USD*\"\ncurl $MT5_API_URL/symbols/EURUSD\ncurl $MT5_API_URL/symbols/EURUSD/tick\ncurl \"$MT5_API_URL/symbols/EURUSD/rates?timeframe=H4&count=100\"\ncurl \"$MT5_API_URL/symbols/EURUSD/ticks?count=100\"\n```\n\nTimeframes: `M1` `M2` `M3` `M4` `M5` `M6` `M10` `M12` `M15` `M20` `M30` `H1` `H2` `H3` `H4` `H6` `H8` `H12` `D1` `W1` `MN1`\n\nKey symbol fields: `bid`, `ask`, `digits`, `point`, `trade_contract_size`, `trade_tick_value`, `trade_tick_size`, `volume_min`, `volume_max`, `volume_step`, `spread`, `swap_long`, `swap_short`, `trade_stops_level`, `trade_mode`.\n\n### Orders\n\n```bash\n# Place market order\ncurl -X POST $MT5_API_URL/orders \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"symbol\": \"EURUSD\", \"type\": \"BUY\", \"volume\": 0.1, \"sl\": 1.08, \"tp\": 1.10}'\n\n# List pending orders\ncurl $MT5_API_URL/orders\ncurl \"$MT5_API_URL/orders?symbol=EURUSD\"\ncurl $MT5_API_URL/orders/42094812\n\n# Modify pending order\ncurl -X PUT $MT5_API_URL/orders/42094812 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"price\": 1.09, \"sl\": 1.07, \"tp\": 1.11}'\n\n# Cancel pending order\ncurl -X DELETE $MT5_API_URL/orders/42094812\n```\n\nOrder types: `BUY`, `SELL`, `BUY_LIMIT`, `SELL_LIMIT`, `BUY_STOP`, `SELL_STOP`, `BUY_STOP_LIMIT`, `SELL_STOP_LIMIT`\n\nFill policies: `FOK`, `IOC` (default), `RETURN`\n\nExpiration: `GTC` (default), `DAY`, `SPECIFIED`, `SPECIFIED_DAY`\n\nRequired fields: `symbol`, `type`, `volume`. `price` auto-fills for market orders.\n\nTrade result:\n\n```json\n{\n    \"retcode\": 10009,\n    \"deal\": 40536203,\n    \"order\": 42094820,\n    \"volume\": 0.1,\n    \"price\": 1.0950,\n    \"comment\": \"Request executed\"\n}\n```\n\n`retcode` 10009 = success. Anything else = something went wrong.\n\n### Positions\n\n```bash\ncurl $MT5_API_URL/positions\ncurl \"$MT5_API_URL/positions?symbol=EURUSD\"\ncurl $MT5_API_URL/positions/42094820\n\n# Update SL/TP\ncurl -X PUT $MT5_API_URL/positions/42094820 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"sl\": 1.085, \"tp\": 1.105}'\n\n# Close full position\ncurl -X DELETE $MT5_API_URL/positions/42094820\n\n# Partial close\ncurl -X DELETE $MT5_API_URL/positions/42094820 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"volume\": 0.05}'\n```\n\nKey position fields: `ticket`, `type` (0=buy, 1=sell), `volume`, `price_open`, `price_current`, `sl`, `tp`, `profit`, `swap`.\n\n### History\n\n```bash\ncurl \"$MT5_API_URL/history/orders?from=$(date -d '1 day ago' +%s)&to=$(date +%s)\"\ncurl \"$MT5_API_URL/history/deals?from=$(date -d '1 day ago' +%s)&to=$(date +%s)\"\n```\n\n`from` and `to` are required, unix epoch seconds.\n\nDeal fields: `type` (0=buy, 1=sell), `entry` (0=opening, 1=closing), `profit` (0 for entries, realized P&L for exits).\n\n## Position Sizing\n\n```\nrisk_amount     = balance * risk_pct\nsl_distance     = ATR * multiplier\nticks_in_sl     = sl_distance / trade_tick_size\nrisk_per_lot    = ticks_in_sl * trade_tick_value\nvolume          = risk_amount / risk_per_lot\n```\n\nRound down to nearest `volume_step`, clamp to `[volume_min, volume_max]`. Sanity check: `volume * trade_contract_size * price` should make sense relative to account balance.\n\n## Tips\n\n- Always check `retcode` — 10009 = good, anything else = bad\n- Use `GET /error` to debug failed trades\n- `deviation` on orders = max slippage in points (default 20, raise for volatile markets)\n- `type_filling` matters — try `FOK`, `IOC`, `RETURN` if orders get rejected\n- Candle `time` is the open time, not close time\n- `trade_stops_level` = minimum SL/TP distance from current price in points\n- Markets have hours — check `trade_mode` before placing orders\n\nFile v1.1.0:_meta.json\n\n{\n  \"ownerId\": \"kn79dhvmpjng4rp2jjk8k0v5xx80ccbk\",\n  \"slug\": \"mt5-httpapi\",\n  \"version\": \"1.1.0\",\n  \"publishedAt\": 1771519642192\n}\n\nFile v1.1.0:references/setup.md\n\n# mt5-httpapi setup\n\n## Requirements\n\n- Linux host with KVM enabled (`/dev/kvm`)\n- Docker + Docker Compose\n- ~10 GB disk (Windows ISO + VM storage)\n- 5 GB RAM (runs mostly on swap — tiny11 + debloat idles at ~1.4 GB)\n\n## Quick Install\n\n```bash\ngit clone https://github.com/psyb0t/mt5-httpapi\ncd mt5-httpapi\ncp config/accounts.json.example config/accounts.json\ncp config/terminals.example.json config/terminals.json\n# Edit both files with your broker credentials\n```\n\nDrop your broker's MT5 installer in `mt5installers/`, named `mt5setup-<broker>.exe`, then:\n\n```bash\nmake up\n```\n\nFirst run downloads tiny11 (~4 GB), installs Windows (~10 min), then sets up Python + MT5 automatically. On first boot it debloats Windows, reboots, installs MT5 terminals, reboots again, then starts everything. After that, boots in ~1 min.\n\n## Configuration\n\n### `config/accounts.json`\n\nBroker credentials organized by broker, then account name:\n\n```json\n{\n  \"roboforex\": {\n    \"main\": {\n      \"login\": 12345678,\n      \"password\": \"your_password\",\n      \"server\": \"RoboForex-Pro\"\n    }\n  }\n}\n```\n\n### `config/terminals.json`\n\nWhich terminals to run — each gets its own MT5 instance and API port:\n\n```json\n[\n  {\n    \"broker\": \"roboforex\",\n    \"account\": \"main\",\n    \"port\": 6542\n  },\n  {\n    \"broker\": \"roboforex\",\n    \"account\": \"demo\",\n    \"port\": 6543\n  }\n]\n```\n\n`broker` matches both the `mt5setup-<broker>.exe` installer name and the key in `accounts.json`. Each terminal installs to `<broker>/base/` and gets copied to `<broker>/<account>/` at startup so multiple accounts of the same broker don't conflict.\n\n## Ports\n\n| Port  | Service            |\n| ----- | ------------------ |\n| 8006  | noVNC (VM desktop) |\n| 6542+ | HTTP API per terminal (set in terminals.json) |\n\nnoVNC is mainly useful for watching the install progress. After that, just use the REST API.\n\n## Management\n\n```bash\nmake up          # start\nmake down        # stop\nmake logs        # tail logs\nmake status      # check status\nmake clean       # nuke VM disk (keeps ISO)\nmake distclean   # nuke everything including ISO\n```\n\n## Logs\n\nInside the VM shared folder (`data/metatrader5/logs/`):\n\n- `install.log` — MT5 installation progress\n- `setup.log` — boot-time setup output\n- `pip.log` — Python package install\n- `api-<broker>-<account>.log` — per-terminal API logs\n\nArchive v1.0.0: 2 files, 9151 bytes\n\nFiles: SKILL.md (26495b), _meta.json (130b)\n\nFile v1.0.0:SKILL.md\n\n---\nname: mt5-httpapi\ndescription: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/crypto/stock markets through MT5.\nhomepage: https://github.com/psyb0t/docker-metatrader5-httpapi\nuser-invocable: true\nmetadata:\n  { \"openclaw\": { \"emoji\": \"📈\", \"primaryEnv\": \"MT5_API_URL\", \"requires\": { \"bins\": [\"curl\"] } } }\n---\n\n# mt5-httpapi\n\nA REST API sitting on top of MetaTrader 5 running inside a Windows VM. You talk to it with plain HTTP/JSON — no MT5 libraries, no Windows, no bullshit. Just curl and go.\n\n## When To Use This Skill\n\n- You need market data (candles, ticks, symbol info)\n- You need to place, modify, or close trades\n- You need account info (balance, equity, margin)\n- You need to check open positions or pending orders\n- You need trade/deal history\n\n## When NOT To Use This Skill\n\n- Technical analysis calculations — do that yourself with the raw candle/tick data\n- Charting or visualization — this gives you data, not pictures\n- Backtesting — this is live/demo trading only\n\n## Setup\n\nThe API should already be running. Set the base URL:\n\n```bash\nexport MT5_API_URL=http://localhost:6542\n```\n\nOr via OpenClaw config (`~/.openclaw/openclaw.json`):\n\n```json\n{\n  \"skills\": {\n    \"entries\": {\n      \"mt5-httpapi\": {\n        \"env\": {\n          \"MT5_API_URL\": \"http://localhost:6542\"\n        }\n      }\n    }\n  }\n}\n```\n\n**Verify:** `curl $MT5_API_URL/ping` — if it responds, you're good. If it doesn't, the API isn't running. Tell the user to set it up: https://github.com/psyb0t/docker-metatrader5-httpapi\n\n## How It Works\n\nStandard REST API. GET for reading, POST for creating, PUT for modifying, DELETE for closing/canceling. All request/response bodies are JSON.\n\nEvery error response looks like:\n\n```json\n{\"error\": \"description of what went wrong\"}\n```\n\n## API Reference\n\n### Health\n\n```bash\n# Is the API alive?\ncurl $MT5_API_URL/ping\n```\n\nResponse:\n\n```json\n{\"status\": \"ok\"}\n```\n\n```bash\n# Last MT5 error (useful for debugging failed trades)\ncurl $MT5_API_URL/error\n```\n\nResponse:\n\n```json\n{\"code\": 1, \"message\": \"Success\"}\n```\n\n### Terminal\n\n```bash\n# Get terminal info\ncurl $MT5_API_URL/terminal\n```\n\nResponse:\n\n```json\n{\n    \"build\": 5602,\n    \"codepage\": 0,\n    \"commondata_path\": \"C:\\\\Users\\\\Docker\\\\AppData\\\\Roaming\\\\MetaQuotes\\\\Terminal\\\\Common\",\n    \"community_account\": false,\n    \"community_balance\": 0.0,\n    \"community_connection\": false,\n    \"company\": \"Your Broker Inc.\",\n    \"connected\": true,\n    \"data_path\": \"C:\\\\Users\\\\Docker\\\\Desktop\\\\Shared\\\\mybroker\",\n    \"dlls_allowed\": true,\n    \"email_enabled\": false,\n    \"ftp_enabled\": false,\n    \"language\": \"English\",\n    \"maxbars\": 100000,\n    \"mqid\": false,\n    \"name\": \"MyBroker MetaTrader 5\",\n    \"notifications_enabled\": false,\n    \"path\": \"C:\\\\Users\\\\Docker\\\\Desktop\\\\Shared\\\\mybroker\",\n    \"ping_last\": 0,\n    \"retransmission\": 0.003,\n    \"trade_allowed\": true,\n    \"tradeapi_disabled\": false\n}\n```\n\nThe most useful fields here: `connected` (is it connected to the broker), `trade_allowed` (can we trade), `company` (which broker).\n\n```bash\n# Initialize MT5 connection (usually auto-done, but use this if you get \"MT5 not initialized\" errors)\ncurl -X POST $MT5_API_URL/terminal/init\n```\n\nResponse:\n\n```json\n{\"success\": true}\n```\n\n```bash\n# Shut down MT5\ncurl -X POST $MT5_API_URL/terminal/shutdown\n```\n\nResponse:\n\n```json\n{\"success\": true}\n```\n\nYou almost never need to call `init` or `shutdown` manually. The API auto-initializes on first request. Only use `init` if something goes sideways, and `shutdown` if you explicitly want to kill the MT5 connection.\n\n### Account\n\n```bash\n# Get current account info\ncurl $MT5_API_URL/account\n```\n\nResponse:\n\n```json\n{\n    \"login\": 12345678,\n    \"name\": \"Your Name\",\n    \"server\": \"MyBroker-Server\",\n    \"company\": \"Your Broker Inc.\",\n    \"currency\": \"USD\",\n    \"currency_digits\": 2,\n    \"balance\": 10000.0,\n    \"credit\": 0.0,\n    \"profit\": 0.0,\n    \"equity\": 10000.0,\n    \"margin\": 0.0,\n    \"margin_free\": 10000.0,\n    \"margin_level\": 0.0,\n    \"margin_initial\": 0.0,\n    \"margin_maintenance\": 0.0,\n    \"margin_so_call\": 70.0,\n    \"margin_so_so\": 20.0,\n    \"margin_so_mode\": 0,\n    \"margin_mode\": 2,\n    \"assets\": 0.0,\n    \"liabilities\": 0.0,\n    \"commission_blocked\": 0.0,\n    \"leverage\": 500,\n    \"limit_orders\": 0,\n    \"trade_allowed\": true,\n    \"trade_expert\": true,\n    \"trade_mode\": 0,\n    \"fifo_close\": false\n}\n```\n\nKey fields:\n- `balance` — account balance (without open position P&L)\n- `equity` — balance + unrealized P&L from open positions\n- `margin` — currently used margin\n- `margin_free` — available margin for new trades\n- `margin_level` — margin level as percentage (equity/margin * 100)\n- `leverage` — account leverage (e.g. 500 = 1:500)\n- `currency` — account currency (USD, EUR, etc.)\n- `trade_allowed` — whether trading is enabled\n- `margin_so_call` — margin call level (%)\n- `margin_so_so` — stop out level (%)\n\n```bash\n# List saved accounts from config (passwords are NOT included)\ncurl $MT5_API_URL/account/list\n```\n\nResponse:\n\n```json\n{\n    \"main\": {\"login\": 12345678, \"server\": \"RoboForex-Pro\"},\n    \"demo\": {\"login\": 87654321, \"server\": \"RoboForex-Demo\"}\n}\n```\n\n```bash\n# Login with explicit credentials\ncurl -X POST $MT5_API_URL/account/login \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"login\": 12345678, \"password\": \"pass\", \"server\": \"BrokerName-Server\"}'\n```\n\n```bash\n# Login by saved account name (from account.json)\ncurl -X POST $MT5_API_URL/account/login/demo\n```\n\nLogin response:\n\n```json\n{\n    \"success\": true,\n    \"login\": 87654321,\n    \"server\": \"RoboForex-Demo\",\n    \"balance\": 10000.0\n}\n```\n\n### Symbols\n\n```bash\n# List all available symbols (returns array of symbol names)\ncurl $MT5_API_URL/symbols\n```\n\nResponse:\n\n```json\n[\"EURUSD\", \"GBPUSD\", \"ADAUSD\", \"BTCUSD\", ...]\n```\n\n```bash\n# Filter symbols by group pattern\ncurl \"$MT5_API_URL/symbols?group=*USD*\"\n```\n\n```bash\n# Get full details for a symbol\ncurl $MT5_API_URL/symbols/EURUSD\n```\n\nResponse (this is a big one):\n\n```json\n{\n    \"name\": \"EURUSD\",\n    \"description\": \"Euro vs US Dollar\",\n    \"path\": \"Markets\\\\Forex\\\\Major\\\\EURUSD\",\n    \"currency_base\": \"EUR\",\n    \"currency_profit\": \"USD\",\n    \"currency_margin\": \"EUR\",\n    \"digits\": 5,\n    \"point\": 1e-05,\n    \"spread\": 30,\n    \"spread_float\": true,\n    \"trade_contract_size\": 100000.0,\n    \"trade_tick_size\": 1e-05,\n    \"trade_tick_value\": 1.0,\n    \"trade_tick_value_profit\": 1.0,\n    \"trade_tick_value_loss\": 1.0,\n    \"volume_min\": 0.01,\n    \"volume_max\": 100.0,\n    \"volume_step\": 0.01,\n    \"volume_limit\": 0.0,\n    \"trade_mode\": 4,\n    \"trade_calc_mode\": 0,\n    \"trade_exemode\": 2,\n    \"trade_stops_level\": 1,\n    \"trade_freeze_level\": 0,\n    \"swap_long\": -11.0,\n    \"swap_short\": 1.14064,\n    \"swap_mode\": 1,\n    \"swap_rollover3days\": 3,\n    \"margin_initial\": 0.0,\n    \"margin_maintenance\": 0.0,\n    \"margin_hedged\": 50000.0,\n    \"filling_mode\": 3,\n    \"expiration_mode\": 15,\n    \"order_gtc_mode\": 0,\n    \"order_mode\": 127,\n    \"bid\": 1.18672,\n    \"ask\": 1.18702,\n    \"bidhigh\": 1.18845,\n    \"bidlow\": 1.1847,\n    \"askhigh\": 1.1885,\n    \"asklow\": 1.18475,\n    \"last\": 0.0,\n    \"lasthigh\": 0.0,\n    \"lastlow\": 0.0,\n    \"time\": 1771027139,\n    \"volume\": 0,\n    \"volumehigh\": 0,\n    \"volumelow\": 0,\n    \"select\": true,\n    \"visible\": true,\n    \"custom\": false,\n    \"chart_mode\": 0,\n    \"session_deals\": 0,\n    \"session_buy_orders\": 0,\n    \"session_sell_orders\": 0,\n    \"session_buy_orders_volume\": 0.0,\n    \"session_sell_orders_volume\": 0.0,\n    \"session_open\": 1.1869,\n    \"session_close\": 1.18698,\n    \"session_turnover\": 0.0,\n    \"session_volume\": 0.0,\n    \"session_interest\": 0.0,\n    \"session_aw\": 0.0,\n    \"session_price_settlement\": 0.0,\n    \"session_price_limit_min\": 0.0,\n    \"session_price_limit_max\": 0.0,\n    \"price_change\": -0.0219,\n    \"price_volatility\": 0.0,\n    \"price_theoretical\": 0.0,\n    \"price_sensitivity\": 0.0,\n    \"price_greeks_delta\": 0.0,\n    \"price_greeks_theta\": 0.0,\n    \"price_greeks_gamma\": 0.0,\n    \"price_greeks_vega\": 0.0,\n    \"price_greeks_omega\": 0.0,\n    \"price_greeks_rho\": 0.0,\n    \"bank\": \"\",\n    \"basis\": \"\",\n    \"category\": \"\",\n    \"exchange\": \"\",\n    \"formula\": \"\",\n    \"isin\": \"\",\n    \"page\": \"\",\n    \"trade_accrued_interest\": 0.0,\n    \"trade_face_value\": 0.0,\n    \"trade_liquidity_rate\": 0.0,\n    \"margin_hedged_use_leg\": false,\n    \"ticks_bookdepth\": 16\n}\n```\n\nKey fields for trading:\n- `bid`, `ask` — current prices\n- `digits` — price decimal places\n- `point` — smallest price change (e.g. 0.00001 for 5-digit forex)\n- `trade_tick_size` — minimum price movement\n- `trade_tick_value` — profit/loss per tick per 1 lot\n- `trade_contract_size` — contract size (e.g. 100000 for forex)\n- `volume_min`, `volume_max`, `volume_step` — lot size constraints\n- `spread` — current spread in points\n- `swap_long`, `swap_short` — overnight swap rates\n- `trade_stops_level` — minimum distance for SL/TP from current price (in points, 0 = no limit)\n- `trade_freeze_level` — distance from current price where orders can't be modified (in points)\n\n```bash\n# Get latest tick (bid/ask snapshot)\ncurl $MT5_API_URL/symbols/EURUSD/tick\n```\n\nResponse:\n\n```json\n{\n    \"time\": 1771146325,\n    \"bid\": 0.2973,\n    \"ask\": 0.2976,\n    \"last\": 0.0,\n    \"volume\": 0,\n    \"time_msc\": 1771146325123,\n    \"flags\": 6,\n    \"volume_real\": 0.0\n}\n```\n\n### Market Data — Candles (OHLCV)\n\n```bash\n# Get 100 M1 candles (default)\ncurl $MT5_API_URL/symbols/EURUSD/rates\n\n# Get 200 H4 candles\ncurl \"$MT5_API_URL/symbols/EURUSD/rates?timeframe=H4&count=200\"\n```\n\nAvailable timeframes: `M1` `M2` `M3` `M4` `M5` `M6` `M10` `M12` `M15` `M20` `M30` `H1` `H2` `H3` `H4` `H6` `H8` `H12` `D1` `W1` `MN1`\n\nResponse (array of candles):\n\n```json\n[\n    {\n        \"time\": 1771128000,\n        \"open\": 0.2962,\n        \"high\": 0.3006,\n        \"low\": 0.2922,\n        \"close\": 0.2979,\n        \"tick_volume\": 4755,\n        \"spread\": 30,\n        \"real_volume\": 0\n    }\n]\n```\n\n- `time` is the candle **open** time, unix epoch seconds\n- `tick_volume` is the number of ticks in the candle (use as volume proxy for forex)\n- `real_volume` is exchange-reported volume (0 for most forex)\n\n### Market Data — Ticks\n\n```bash\n# Get last 100 ticks\ncurl $MT5_API_URL/symbols/EURUSD/ticks\n\n# Get last 500 ticks\ncurl \"$MT5_API_URL/symbols/EURUSD/ticks?count=500\"\n```\n\nResponse (array of ticks):\n\n```json\n[\n    {\n        \"time\": 1771146325,\n        \"bid\": 0.2973,\n        \"ask\": 0.2976,\n        \"last\": 0.0,\n        \"volume\": 0,\n        \"time_msc\": 1771146325123,\n        \"flags\": 6,\n        \"volume_real\": 0.0\n    }\n]\n```\n\n- `time` — unix epoch seconds\n- `time_msc` — same timestamp in milliseconds for higher precision\n\n### Placing Orders\n\n```bash\n# Market buy\ncurl -X POST $MT5_API_URL/orders \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"symbol\": \"ADAUSD\", \"type\": \"BUY\", \"volume\": 1000}'\n\n# Market buy with SL and TP\ncurl -X POST $MT5_API_URL/orders \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"symbol\": \"ADAUSD\", \"type\": \"BUY\", \"volume\": 1000, \"sl\": 0.25, \"tp\": 0.35}'\n\n# Market sell\ncurl -X POST $MT5_API_URL/orders \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"symbol\": \"ADAUSD\", \"type\": \"SELL\", \"volume\": 1000}'\n\n# Pending buy limit (triggers when price drops to 0.28)\ncurl -X POST $MT5_API_URL/orders \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"symbol\": \"ADAUSD\", \"type\": \"BUY_LIMIT\", \"volume\": 1000, \"price\": 0.28, \"sl\": 0.25, \"tp\": 0.35}'\n```\n\nFull order body:\n\n```json\n{\n    \"symbol\": \"ADAUSD\",\n    \"type\": \"BUY\",\n    \"volume\": 1000,\n    \"price\": 0.28,\n    \"sl\": 0.25,\n    \"tp\": 0.35,\n    \"deviation\": 20,\n    \"magic\": 0,\n    \"comment\": \"\",\n    \"type_filling\": \"IOC\",\n    \"type_time\": \"GTC\"\n}\n```\n\n- Required: `symbol`, `type`, `volume`. Everything else is optional.\n- `price` gets auto-filled for market orders (uses current ask for BUY, bid for SELL).\n- `deviation` — max price slippage in points. If price moves more than this between request and execution, order gets rejected. Default: 20.\n- `magic` — expert advisor ID, use to tag orders from different strategies.\n- `type_filling` — how to fill the order if full volume isn't available.\n- `type_time` — when the order expires.\n\nOrder types:\n- Market: `BUY`, `SELL`\n- Pending: `BUY_LIMIT`, `SELL_LIMIT`, `BUY_STOP`, `SELL_STOP`, `BUY_STOP_LIMIT`, `SELL_STOP_LIMIT`\n\nFill policies: `FOK` (fill or kill — all or nothing), `IOC` (immediate or cancel — fill what you can, cancel rest, **default**), `RETURN` (fill what you can, leave rest as order)\n\nExpiration: `GTC` (good till cancelled, **default**), `DAY` (expires end of day), `SPECIFIED` (expires at specific time), `SPECIFIED_DAY` (expires at specific day)\n\n**Trade result** (returned on success):\n\n```json\n{\n    \"retcode\": 10009,\n    \"deal\": 40536194,\n    \"order\": 42094812,\n    \"volume\": 3100.0,\n    \"price\": 0.2989,\n    \"bid\": 0.2986,\n    \"ask\": 0.2989,\n    \"comment\": \"Request executed\",\n    \"request_id\": 1549268248,\n    \"retcode_external\": 0\n}\n```\n\n- `retcode` 10009 = success. Anything else = something went wrong, check `comment`.\n- `deal` — deal ticket (unique ID for the executed trade)\n- `order` — order ticket\n- `volume` — actually executed volume\n- `price` — execution price\n\n### Managing Pending Orders\n\n```bash\n# List all pending orders\ncurl $MT5_API_URL/orders\n\n# Filter by symbol\ncurl \"$MT5_API_URL/orders?symbol=EURUSD\"\n\n# Get specific order\ncurl $MT5_API_URL/orders/42094812\n```\n\nPending order object:\n\n```json\n{\n    \"ticket\": 42094812,\n    \"time_setup\": 1771147800,\n    \"time_setup_msc\": 1771147800123,\n    \"time_done\": 0,\n    \"time_done_msc\": 0,\n    \"time_expiration\": 0,\n    \"type\": 2,\n    \"type_time\": 0,\n    \"type_filling\": 1,\n    \"state\": 1,\n    \"magic\": 0,\n    \"position_id\": 0,\n    \"position_by_id\": 0,\n    \"reason\": 3,\n    \"volume_initial\": 1000.0,\n    \"volume_current\": 1000.0,\n    \"price_open\": 0.28,\n    \"sl\": 0.25,\n    \"tp\": 0.35,\n    \"price_current\": 0.2989,\n    \"price_stoplimit\": 0.0,\n    \"symbol\": \"ADAUSD\",\n    \"comment\": \"\",\n    \"external_id\": \"\"\n}\n```\n\nKey fields:\n- `ticket` — unique order ID, use this for modify/cancel\n- `type` — order type (0=BUY, 1=SELL, 2=BUY_LIMIT, 3=SELL_LIMIT, 4=BUY_STOP, 5=SELL_STOP, 6=BUY_STOP_LIMIT, 7=SELL_STOP_LIMIT)\n- `volume_initial` — originally requested volume\n- `volume_current` — remaining volume (less if partially filled)\n- `price_open` — order price\n- `sl`, `tp` — stop loss and take profit\n- `price_current` — current market price\n- `state` — order state (1=placed, 2=canceled, 3=partial, 4=filled, 5=rejected, 6=expired)\n\n```bash\n# Modify a pending order (change price, SL, TP)\ncurl -X PUT $MT5_API_URL/orders/42094812 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"price\": 0.29, \"sl\": 0.26, \"tp\": 0.36}'\n```\n\nAll fields optional. Only pass what you want to change.\n\n```bash\n# Cancel a pending order\ncurl -X DELETE $MT5_API_URL/orders/42094812\n```\n\nBoth return a trade result object (see above).\n\n### Managing Positions\n\n```bash\n# List all open positions\ncurl $MT5_API_URL/positions\n\n# Filter by symbol\ncurl \"$MT5_API_URL/positions?symbol=ADAUSD\"\n\n# Get specific position\ncurl $MT5_API_URL/positions/42094812\n```\n\nPosition object:\n\n```json\n{\n    \"ticket\": 42094812,\n    \"time\": 1771147866,\n    \"time_msc\": 1771147866130,\n    \"time_update\": 1771147866,\n    \"time_update_msc\": 1771147866130,\n    \"type\": 0,\n    \"magic\": 0,\n    \"identifier\": 42094812,\n    \"reason\": 3,\n    \"volume\": 3100.0,\n    \"price_open\": 0.2989,\n    \"sl\": 0.25,\n    \"tp\": 0.35,\n    \"price_current\": 0.2991,\n    \"swap\": 0.0,\n    \"profit\": 6.2,\n    \"symbol\": \"ADAUSD\",\n    \"comment\": \"\",\n    \"external_id\": \"\"\n}\n```\n\nKey fields:\n- `ticket` — unique position ID, use this for update/close\n- `type` — 0 = buy, 1 = sell\n- `volume` — current position size\n- `price_open` — entry price\n- `price_current` — current market price\n- `sl`, `tp` — stop loss and take profit (0.0 = not set)\n- `swap` — accumulated swap\n- `profit` — unrealized P&L in account currency\n- `time` — when the position was opened (unix epoch seconds)\n\n```bash\n# Update SL/TP on an open position\ncurl -X PUT $MT5_API_URL/positions/42094812 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"sl\": 0.27, \"tp\": 0.36}'\n```\n\nAll fields optional. Only pass what you want to change.\n\n```bash\n# Close entire position\ncurl -X DELETE $MT5_API_URL/positions/42094812\n\n# Partial close (close 500 out of 3100 volume)\ncurl -X DELETE $MT5_API_URL/positions/42094812 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"volume\": 500}'\n\n# Close with custom deviation (max price slippage)\ncurl -X DELETE $MT5_API_URL/positions/42094812 \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"deviation\": 50}'\n```\n\nAll fields optional. `volume` defaults to full position, `deviation` defaults to 20.\n\nBoth update and close return a trade result object (see above).\n\n### History\n\nBoth endpoints require `from` and `to` as unix epoch seconds.\n\n```bash\n# Get order history for the last 24 hours\ncurl \"$MT5_API_URL/history/orders?from=$(date -d '1 day ago' +%s)&to=$(date +%s)\"\n\n# Get deal history for the last 24 hours\ncurl \"$MT5_API_URL/history/deals?from=$(date -d '1 day ago' +%s)&to=$(date +%s)\"\n\n# Get deal history for a specific range\ncurl \"$MT5_API_URL/history/deals?from=1771060000&to=1771150000\"\n```\n\nHistory order object (completed/cancelled orders):\n\n```json\n{\n    \"ticket\": 42094812,\n    \"time_setup\": 1771147800,\n    \"time_setup_msc\": 1771147800123,\n    \"time_done\": 1771147866,\n    \"time_done_msc\": 1771147866130,\n    \"time_expiration\": 0,\n    \"type\": 0,\n    \"type_time\": 0,\n    \"type_filling\": 1,\n    \"state\": 4,\n    \"magic\": 0,\n    \"position_id\": 42094812,\n    \"position_by_id\": 0,\n    \"reason\": 3,\n    \"volume_initial\": 3100.0,\n    \"volume_current\": 0.0,\n    \"price_open\": 0.2989,\n    \"sl\": 0.25,\n    \"tp\": 0.35,\n    \"price_current\": 0.2989,\n    \"price_stoplimit\": 0.0,\n    \"symbol\": \"ADAUSD\",\n    \"comment\": \"Request executed\",\n    \"external_id\": \"\"\n}\n```\n\n- `state` 4 = filled, 2 = canceled, 5 = rejected, 6 = expired\n- `time_setup` = when the order was placed, `time_done` = when it was executed/cancelled\n- `volume_current` = 0 means fully filled\n\nDeal object (actual executed trades):\n\n```json\n{\n    \"ticket\": 40536194,\n    \"order\": 42094812,\n    \"time\": 1771147866,\n    \"time_msc\": 1771147866130,\n    \"type\": 0,\n    \"entry\": 0,\n    \"position_id\": 42094812,\n    \"symbol\": \"ADAUSD\",\n    \"volume\": 3100.0,\n    \"price\": 0.2989,\n    \"commission\": 0.0,\n    \"swap\": 0.0,\n    \"profit\": 0.0,\n    \"fee\": 0.0,\n    \"magic\": 0,\n    \"reason\": 3,\n    \"comment\": \"\",\n    \"external_id\": \"\"\n}\n```\n\n- `type` — 0 = buy, 1 = sell\n- `entry` — 0 = entry (opening), 1 = exit (closing), 2 = reverse, 3 = close by opposite\n- `profit` — realized P&L for this deal (0 for entries, actual P&L for exits)\n- `commission`, `swap`, `fee` — trading costs\n- `position_id` — links the deal to a position\n- `order` — links the deal to the order that triggered it\n\n## Pre-Trade Checks (DO NOT SKIP)\n\nBefore you place ANY trade, you MUST verify these things. Skipping this can lose real money.\n\n1. **Check if trading is enabled on the account:** `GET /account` → `trade_allowed` must be `true`. If it's `false`, you can't trade — don't even try.\n\n2. **Check if the symbol is open for trading:** `GET /symbols/SYMBOL` → check `trade_mode`. It must be 4 (full trading). Other values mean trading is restricted or disabled for that symbol. Markets have trading hours — forex is closed on weekends, stocks have exchange hours, crypto is usually 24/7 but not always.\n\n3. **Check the contract size:** `GET /symbols/SYMBOL` → `trade_contract_size`. This is critical. For forex it's usually 100,000 (meaning 1 lot = 100,000 units of the base currency). For crypto it might be 1 (meaning 1 lot = 1 coin). If you blindly send `\"volume\": 1000` thinking it's 1000 coins but the contract size is 100,000, you just opened a position worth 100,000,000 units. **Always check `trade_contract_size` and factor it into your position sizing.**\n\n4. **Check the terminal connection:** `GET /terminal` → `connected` must be `true`. If the terminal is disconnected from the broker, orders will fail.\n\n## Typical Workflow\n\n1. **Check the connection:** `GET /ping` — make sure the API responds\n2. **Check your account:** `GET /account` — verify `trade_allowed` is `true`, check `balance`, `equity`, `margin_free`\n3. **Check the terminal:** `GET /terminal` — verify `connected` is `true`\n4. **Get symbol specs:** `GET /symbols/SYMBOL` — verify `trade_mode` is 4 (trading enabled), check `trade_contract_size`, `trade_tick_value`, `volume_min`, `volume_step`\n5. **Get market data:** `GET /symbols/SYMBOL/rates?timeframe=H4&count=100` — pull candles for analysis\n6. **Get current price:** `GET /symbols/SYMBOL/tick` — latest bid/ask\n7. **Calculate your position size and risk** — use `trade_contract_size` and `trade_tick_value` from step 4. Don't guess.\n8. **Place the trade:** `POST /orders` with your symbol, type, volume, SL, TP\n9. **Monitor:** `GET /positions` to check open positions\n10. **Adjust:** `PUT /positions/:ticket` to move SL/TP\n11. **Close:** `DELETE /positions/:ticket` when you're done\n12. **Review:** `GET /history/deals` to check what happened\n\n## Position Sizing\n\nSay you want to risk 1% of your account on a trade with a stop loss at 3x ATR on H4:\n\n1. Get account balance: `GET /account` → `balance` field. Also verify `trade_allowed` is `true`.\n2. Get symbol specs: `GET /symbols/ADAUSD` → grab `trade_contract_size`, `trade_tick_value`, `trade_tick_size`, `volume_min`, `volume_max`, `volume_step`. Also verify `trade_mode` is 4.\n3. Get candles: `GET /symbols/ADAUSD/rates?timeframe=H4&count=15` → calculate ATR from high/low/close data (average true range over 14 periods)\n4. Calculate:\n   - `risk_amount = balance * 0.01`\n   - `sl_distance = ATR * 3`\n   - `ticks_in_sl = sl_distance / trade_tick_size`\n   - `risk_per_lot = ticks_in_sl * trade_tick_value` (this is how much you lose per 1 lot if SL is hit)\n   - `volume = risk_amount / risk_per_lot`\n   - **Sanity check:** `notional_value = volume * trade_contract_size * current_price` — make sure this isn't insane relative to your balance\n5. Round volume down to nearest `volume_step`, clamp between `volume_min` and `volume_max`\n6. Get current price: `GET /symbols/ADAUSD/tick` → use `ask` for buy, `bid` for sell\n7. Calculate SL price: `entry_price - sl_distance` for buy, `entry_price + sl_distance` for sell\n8. Send the order: `POST /orders` with symbol, type, volume, sl\n\n## Technical Analysis\n\nThis API gives you raw market data — it does NOT do TA for you. If you need indicators (ATR, RSI, MACD, Bollinger Bands, moving averages, etc.), grab the candle data from here and crunch it yourself.\n\nThere's a full working example in the repo at `examples/ta/` using [pandas-ta](https://github.com/twopirllc/pandas-ta) — check `indicators.py` for individual indicator functions, `signals.py` for signal detection, and `ta.py` to run it all.\n\n### Quick example\n\n```python\nimport pandas as pd\nimport pandas_ta as ta\nimport requests\n\n# Grab candles from the API\ncandles = requests.get(\"http://localhost:6542/symbols/EURUSD/rates?timeframe=H4&count=200\").json()\ndf = pd.DataFrame(candles)\n\n# ATR, RSI, MACD, Bollinger Bands, moving averages — one-liners\ndf[\"atr\"] = ta.atr(df[\"high\"], df[\"low\"], df[\"close\"], length=14)\ndf[\"rsi\"] = ta.rsi(df[\"close\"], length=14)\ndf = pd.concat([df, ta.macd(df[\"close\"])], axis=1)\ndf = pd.concat([df, ta.bbands(df[\"close\"], length=20, std=2)], axis=1)\ndf[\"sma_50\"] = ta.sma(df[\"close\"], length=50)\ndf[\"ema_21\"] = ta.ema(df[\"close\"], length=21)\ndf[\"mfi\"] = ta.mfi(df[\"high\"], df[\"low\"], df[\"close\"], df[\"tick_volume\"], length=14)\n```\n\nInstall: `pip install requests pandas pandas-ta`\n\n## Tips\n\n1. **ALWAYS check if trading is enabled before placing orders** — `GET /account` → `trade_allowed` must be `true`. `GET /symbols/SYMBOL` → `trade_mode` must be 4. If either is wrong, the trade will fail or worse — you'll get errors you don't understand.\n2. **ALWAYS check `trade_contract_size` before sizing your position** — this is the single easiest way to blow an account by accident. 1 lot of EURUSD = 100,000 EUR. 1 lot of BTCUSD might = 1 BTC. 1 lot of some index might = 10 contracts. Never assume. Always check.\n3. **ALWAYS check `retcode` in trade results** — 10009 means success, anything else is a problem\n4. **Use `GET /error` to debug** — when a trade fails, this tells you what MT5 is complaining about\n5. **Demo accounts first** — test your shit before going live\n6. **Markets have hours** — forex is closed on weekends (Friday ~22:00 UTC to Sunday ~22:00 UTC). Stocks follow exchange hours. Crypto is usually 24/7 but check the symbol's `trade_mode` to be sure. If you try to trade when the market is closed, the order will be rejected.\n7. **`deviation` matters for market orders** — if price moves more than `deviation` points between your request and execution, the order gets rejected. Default is 20, increase it for volatile markets.\n8. **`type_filling` matters** — some brokers only support certain fill policies. If your order gets rejected, try switching between `FOK`, `IOC`, and `RETURN`.\n9. **Partial closes are a thing** — you don't have to close an entire position, pass `volume` in the DELETE body\n10. **History needs explicit time range** — `from` and `to` are required, both unix epoch seconds\n11. **Candle `time` is the candle open time** — not close time\n12. **`time_msc` is milliseconds** — `time` is seconds, `time_msc` is the same timestamp in milliseconds\n13. **Check `trade_stops_level` on the symbol** — this is the minimum distance (in points) between current price and your SL/TP. If it's 10 and the point is 0.00001, your SL/TP must be at least 0.0001 away from current price.\n14. **Check `volume_step` before placing orders** — if `volume_step` is 0.01, you can't trade 0.015 lots. Round to the nearest step.\n15. **`margin_free` tells you how much you can trade** — if it's 0 or close to 0, you're maxed out\n16. **`profit` on positions is unrealized** — it changes with every tick. `profit` on deals is realized (final).\n17. **Do a sanity check on notional value** — before sending any order, calculate `volume * trade_contract_size * price` and make sure it's not absurd relative to the account balance. If your $10,000 account is about to open a $5,000,000 notional position, something is wrong with your math.\n\nFile v1.0.0:_meta.json\n\n{\n  \"ownerId\": \"kn79dhvmpjng4rp2jjk8k0v5xx80ccbk\",\n  \"slug\": \"mt5-httpapi\",\n  \"version\": \"1.0.0\",\n  \"publishedAt\": 1771144230099\n}","readmeExcerpt":"Skill: mt5-httpapi Owner: psyb0t Summary: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp... Tags: latest:1.1.0 Version history: v1.1.0 | 2026-02-19T16:47:22.192Z | user Initial public release. - Added API reference covering health checks, account info, symbols, orders, positions, and history endpoints. - Inc","codeSnippets":[],"executableExamples":[{"language":"bash","snippet":"export MT5_API_URL=http://localhost:6542"},{"language":"json","snippet":"{\"error\": \"description of what went wrong\"}"},{"language":"bash","snippet":"curl $MT5_API_URL/ping"},{"language":"bash","snippet":"curl $MT5_API_URL/error"},{"language":"bash","snippet":"curl $MT5_API_URL/ping\n# {\"status\": \"ok\"}\n\ncurl $MT5_API_URL/error\n# {\"code\": 1, \"message\": \"Success\"}"},{"language":"bash","snippet":"curl $MT5_API_URL/terminal"}],"parameters":null,"dependencies":[],"permissions":[],"extractedFiles":[{"path":"SKILL.md","content":"---\nname: mt5-httpapi\ndescription: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/crypto/stock markets through MT5.\ncompatibility: Requires curl and a running mt5-httpapi instance. MT5_API_URL env var must be set.\nmetadata:\n  author: psyb0t\n  homepage: https://github.com/psyb0t/mt5-httpapi\n---\n\n# mt5-httpapi\n\nREST API on top of MetaTrader 5 running inside a Windows VM. Talk to it with plain HTTP/JSON — no MT5 libraries, no Windows, no bullshit. Just curl and go.\n\nFor installation and setup, see [references/setup.md](references/setup.md).\n\n## Setup\n\nThe API should already be running. Set the base URL:\n\n```bash\nexport MT5_API_URL=http://localhost:6542\n```\n\nEach terminal has its own port (configured in `terminals.json`). If running multiple terminals, set `MT5_API_URL` to the port for the terminal you want to talk to.\n\n**Verify:** `curl $MT5_API_URL/ping` — should return `{\"status\": \"ok\"}`. If not, the API isn't up yet (may still be initializing — it retries in the background).\n\n## How It Works\n\nGET for reading, POST for creating, PUT for modifying, DELETE for closing/canceling. All bodies are JSON.\n\nEvery error response:\n\n```json\n{\"error\": \"description of what went wrong\"}\n```\n\n## Pre-Trade Checks (DO NOT SKIP)\n\nBefore placing any trade:\n\n1. `GET /account` → `trade_allowed` must be `true`\n2. `GET /symbols/SYMBOL` → `trade_mode` must be `4` (full trading)\n3. `GET /symbols/SYMBOL` → check `trade_contract_size` — 1 lot of EURUSD = 100,000 EUR, not 1 EUR\n4. `GET /terminal` → `connected` must be `true`\n\n## API Reference\n\n### Health\n\n```bash\ncurl $MT5_API_URL/ping\n# {\"status\": \"ok\"}\n\ncurl $MT5_API_URL/error\n# {\"code\": 1, \"message\": \"Success\"}\n```\n\n### Terminal\n\n```bash\ncurl $MT5_API_URL/terminal\ncurl -X POST $MT5_API_URL/terminal/init\ncurl -X POST $MT5_API_URL/terminal/shutdown\n```\n\nKey fields on `/terminal`: `connected`, `trade_allowed`, `build`, `company`.\n\n### Account\n\n```bash\ncurl $MT5_API_URL/account\n```\n\n```json\n{\n    \"login\": 12345678,\n    \"balance\": 10000.0,\n    \"equity\": 10000.0,\n    \"margin\": 0.0,\n    \"margin_free\": 10000.0,\n    \"margin_level\": 0.0,\n    \"leverage\": 500,\n    \"currency\": \"USD\",\n    \"trade_allowed\": true,\n    \"margin_so_call\": 70.0,\n    \"margin_so_so\": 20.0\n}\n```\n\n### Symbols\n\n```bash\ncurl $MT5_API_URL/symbols\ncurl \"$MT5_API_URL/symbols?group=*USD*\"\ncurl $MT5_API_URL/symbols/EURUSD\ncurl $MT5_API_URL/symbols/EURUSD/tick\ncurl \"$MT5_API_URL/symbols/EURUSD/rates?timeframe=H4&count=100\"\ncurl \"$MT5_API_URL/symbols/EURUSD/ticks?count=100\"\n```\n\nTimeframes: `M1` `M2` `M3` `M4` `M5` `M6` `M10` `M12` `M15` `M20` `M30` `H1` `H2` `H3` `H4` `H6` `H8` `H12` `D1` `W1` `MN1`\n\nKey symbol fields: `bid`, `ask`, `digits`, `point`, `trade_contract_size`, `trade_tick_value`, `trade_tick_size`, `volume_min`, `volume_max`, `volume_step`, `spread`, `swap_long`, `swap_short`, `trade_stops_level`, `trade_mode`.\n\n### Orders\n\n```bash\n# Place market order\nc"},{"path":"_meta.json","content":"{\n  \"ownerId\": \"kn79dhvmpjng4rp2jjk8k0v5xx80ccbk\",\n  \"slug\": \"mt5-httpapi\",\n  \"version\": \"1.1.0\",\n  \"publishedAt\": 1771519642192\n}"},{"path":"references/setup.md","content":"# mt5-httpapi setup\n\n## Requirements\n\n- Linux host with KVM enabled (`/dev/kvm`)\n- Docker + Docker Compose\n- ~10 GB disk (Windows ISO + VM storage)\n- 5 GB RAM (runs mostly on swap — tiny11 + debloat idles at ~1.4 GB)\n\n## Quick Install\n\n```bash\ngit clone https://github.com/psyb0t/mt5-httpapi\ncd mt5-httpapi\ncp config/accounts.json.example config/accounts.json\ncp config/terminals.example.json config/terminals.json\n# Edit both files with your broker credentials\n```\n\nDrop your broker's MT5 installer in `mt5installers/`, named `mt5setup-<broker>.exe`, then:\n\n```bash\nmake up\n```\n\nFirst run downloads tiny11 (~4 GB), installs Windows (~10 min), then sets up Python + MT5 automatically. On first boot it debloats Windows, reboots, installs MT5 terminals, reboots again, then starts everything. After that, boots in ~1 min.\n\n## Configuration\n\n### `config/accounts.json`\n\nBroker credentials organized by broker, then account name:\n\n```json\n{\n  \"roboforex\": {\n    \"main\": {\n      \"login\": 12345678,\n      \"password\": \"your_password\",\n      \"server\": \"RoboForex-Pro\"\n    }\n  }\n}\n```\n\n### `config/terminals.json`\n\nWhich terminals to run — each gets its own MT5 instance and API port:\n\n```json\n[\n  {\n    \"broker\": \"roboforex\",\n    \"account\": \"main\",\n    \"port\": 6542\n  },\n  {\n    \"broker\": \"roboforex\",\n    \"account\": \"demo\",\n    \"port\": 6543\n  }\n]\n```\n\n`broker` matches both the `mt5setup-<broker>.exe` installer name and the key in `accounts.json`. Each terminal installs to `<broker>/base/` and gets copied to `<broker>/<account>/` at startup so multiple accounts of the same broker don't conflict.\n\n## Ports\n\n| Port  | Service            |\n| ----- | ------------------ |\n| 8006  | noVNC (VM desktop) |\n| 6542+ | HTTP API per terminal (set in terminals.json) |\n\nnoVNC is mainly useful for watching the install progress. After that, just use the REST API.\n\n## Management\n\n```bash\nmake up          # start\nmake down        # stop\nmake logs        # tail logs\nmake status      # check status\nmake clean       # nuke VM disk (keeps ISO)\nmake distclean   # nuke everything including ISO\n```\n\n## Logs\n\nInside the VM shared folder (`data/metatrader5/logs/`):\n\n- `install.log` — MT5 installation progress\n- `setup.log` — boot-time setup output\n- `pip.log` — Python package install\n- `api-<broker>-<account>.log` — per-terminal API logs"}],"languages":[],"docsSourceLabel":"CLAWHUB","editorialOverview":"MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp... Skill: mt5-httpapi Owner: psyb0t Summary: MetaTrader 5 trading via REST API — get market data, place/modify/close orders, manage positions, pull history. Use when you need to interact with forex/cryp... Tags: latest:1.1.0 Version history: v1.1.0 | 2026-02-19T16:47:22.192Z | user Initial public release. - Added API reference covering health checks, account info, symbols, orders, positions, and history endpoints. - Inc","editorialQuality":{"score":100,"threshold":65,"status":"ready","wordCount":945,"uniquenessScore":56,"reasons":[]}},"media":{"evidence":{"source":"no-media","verified":false,"confidence":"low","updatedAt":"2026-04-15T00:45:39.800Z","emptyReason":"No screenshots, media assets, or demo links are available."},"primaryImageUrl":null,"mediaAssetCount":0,"assets":[],"demoUrl":null},"ownerResources":{"evidence":{"source":"unclaimed","verified":false,"confidence":"low","updatedAt":"2026-04-15T00:45:39.800Z","emptyReason":"This page has not been claimed by the agent owner."},"hasCustomPage":false,"customPageUpdatedAt":null,"customLinks":[],"structuredLinks":{"docsUrl":null,"demoUrl":null,"supportUrl":null,"pricingUrl":null,"statusUrl":null},"customPage":null},"relatedAgents":{"evidence":{"source":"protocol-neighbors","verified":false,"confidence":"medium","updatedAt":"2026-10-09T09:46:39.378Z","emptyReason":null},"items":[{"id":"b917f68a-ebff-438e-84f8-3f4b2494c0bc","entityType":"agent","canonicalPath":"/agent/activepieces-activepieces","slug":"activepieces-activepieces","name":"activepieces","description":"AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents","url":"https://github.com/activepieces/activepieces","homepage":"https://www.activepieces.com","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-15T02:22:12.426Z","createdAt":"2026-02-25T03:38:12.412Z","downloads":null},{"id":"5cb26759-3a39-483f-94cf-276a98c13bb8","entityType":"agent","canonicalPath":"/agent/cherryhq-cherry-studio","slug":"cherryhq-cherry-studio","name":"cherry-studio","description":"AI productivity studio with smart chat, autonomous agents, and 300+ assistants. Unified access to frontier LLMs","url":"https://github.com/CherryHQ/cherry-studio","homepage":"https://cherry-ai.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-11T14:38:40.986Z","createdAt":"2026-02-25T03:38:19.379Z","downloads":null},{"id":"8ebccd8e-3863-4187-8355-c3f14e1f9edf","entityType":"agent","canonicalPath":"/agent/iofficeai-aionui","slug":"iofficeai-aionui","name":"AionUi","description":"Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!","url":"https://github.com/iOfficeAI/AionUi","homepage":"https://www.aionui.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-10T18:48:31.762Z","createdAt":"2026-02-25T03:38:16.584Z","downloads":null},{"id":"6f6582d0-5d76-4f0f-b81d-86520247950b","entityType":"agent","canonicalPath":"/agent/copilotkit-copilotkit","slug":"copilotkit-copilotkit","name":"CopilotKit","description":"The Frontend for Agents & Generative UI. React + Angular","url":"https://github.com/CopilotKit/CopilotKit","homepage":"https://docs.copilotkit.ai","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-03-25T09:50:57.846Z","createdAt":"2026-02-25T03:39:14.617Z","downloads":null}],"links":{"hub":"/agent","source":"/agent/source/clawhub","protocols":[{"label":"OpenClaw","href":"/agent/protocol/openclew"}]}}}