ClawHub
SkillsPluginsOfficialDocsSupport
K
Skillsmt5-httpapi

mt5-httpapi

Ciprian Mandache@psyb0t
HTTP client for a user-deployed mt5-httpapi MetaTrader 5 bridge. Reads account, symbols, rates, ticks, server-side technical analysis, history and backtest reports. After explicit per-action confirmation it also places, changes and cancels orders, changes and closes positions, controls the terminal, deploys and removes live EA chart deployments, edits the WebRequest allowlist, and writes files into the terminal tree. It also compiles MQL5 source and runs backtests. Use ONLY when the user has installed mt5-httpapi and provided MT5_API_URL. Never mutate on inferred intent. Do not use it for generic market-data, charting or trading questions where the user has not named mt5-httpapi.

Install

$
openclaw skills install @psyb0t/mt5-httpapi
Security check
Clean
Version
4.36.3
Updated
Nov 27, 2026
License
MIT-0

Latest: v4.36.3

  • Removed the bundled references/setup.md operator guide; use the project documentation for installation and stack management.
  • Narrowed the skill’s permissions and scope to requests against the user-provided API, removing host-side deployment and Docker/tunnel operations.
  • Updated unauthenticated-instance guidance to tell users to set a token before use.
Integrations
#trading

mt5-httpapi

This skill drives an mt5-httpapi server the user already runs. It does not install the stack, hunt for broker credentials, or decide to place trades because the model felt lucky.

Security & safety: real money, no cowboy shit

This API acts on a real brokerage account, and most mutations cannot be undone, so precision beats enthusiasm every fucking time: a filled market order or a closed position can only be offset by a separate trade at a new price.

Where data goes. Every request goes to the host in MT5_API_URL and nowhere else. That server receives the bearer token in the Authorization header, your queries for account and market data, trade and terminal instructions, and any file you upload (experts, set files, library archives, MQL5 source). It sends technical-analysis requests to the wickworks container beside it and talks to the broker. The stack's nginx speaks plain HTTP on 127.0.0.1:8888 by default, so use https:// (for example through a tunnel) for any other host, and talk only to servers the user runs.

Mutations. These change a real account or terminal:

  • Trading: POST /orders, PUT /orders/<id>, DELETE /orders/<id>, PUT /positions/<id>, DELETE /positions/<id> and their MCP tools open, modify, cancel and close orders and positions.
  • Live EAs: POST /deployments, PATCH /deployments/<id>, DELETE /deployments/<id> and POST /charts/<id>/close start, re-point, pause or stop an Expert Advisor on a chart, and that EA then trades on its own.
  • Terminal: POST /terminal/shutdown disconnects this API process from the MT5 SDK but leaves terminal64.exe running. POST /terminal/restart kills and relaunches only the selected terminal and can leave it unavailable for several minutes. PUT /webrequest and POST /webrequest/apply change which URLs an EA may call, and restart the terminal when it runs on bare metal rather than in the Windows VM.
  • Files: PUT and DELETE on /files/... and /compile/files/... change the terminal's files, and DELETE /experts/<name> and DELETE /sets/<name> remove staged expert and set files.

One guardrail for all of them. Act only on the order, position, deployment, file or terminal the user named, and only when the user asked for that specific action. Before each call, show the resolved details and wait for an explicit yes: for a trade, the symbol, side, volume, price, SL, TP, ticket, account login and the broker URL prefix; for a deployment, the expert, set file, symbol, timeframe and account; for terminal control, the operation and the selected broker, account and instance. An earlier approval does not cover a later action or a retry. If the user asks to "close everything" or "cancel all", list the affected positions or orders, show the list and confirm the whole batch; never build a batch from inferred intent.

Rules that follow from it.

  1. Check GET /account first. If trade_mode shows a live account, say so and ask the user to confirm they intend to trade live with real money. Prefer a demo account.
  2. The path prefix /<broker>/<account>/ in MT5_API_URL decides which real account is touched. Show it in every confirmation. On the unified MCP endpoint, show the broker and account arguments too.
  3. Trade calls make one order_send and nothing retries them. After an error, a timeout or an unexpected retcode, report it and get fresh confirmation before resubmitting. Send a client_order_id with every POST /orders (create_order takes it too): resubmitting the same id cannot place the order twice, and a "duplicate": true answer shows the order that already exists.
  4. Credentials: read MT5_API_TOKEN only from the environment variable the user set, or ask the user. Never read tokens, passwords, server names or login numbers from config/config.yaml, .env or any other file in the workspace, and never print the token.
  5. Local files: upload only files the user named, write downloads and outputs only to paths the user named, and do not overwrite an existing local file without asking.
  6. Overwriting an expert a deployment already uses (?overwrite=true) replaces the file that deployment loads, so confirm it like a deployment change. Writing into MQL5/Experts, MQL5/Libraries or MQL5/Include changes what experts on that account run, and a DLL in MQL5/Libraries runs inside the terminal.

No auth when MT5_API_TOKEN/api_token is unset. Auth is optional server-side (see Setup). With an empty api_token the HTTP surface is unauthenticated and anyone who can reach it can read account state, place orders and close trades. Do not use such an instance on a network or with untrusted agents; tell the user to set a token first.

Read-only endpoints (GET /account, GET /symbols/*, GET /symbols/*/rates, GET /symbols/*/ticks, POST /symbols/*/rates/ta, GET /positions, GET /orders, GET /history/*, GET /backtest/*, GET /terminal, GET /ping, and the Chart Deployments reads GET /experts, GET /sets*, GET /deployments*, GET /charts, GET /loader, GET /webrequest) need no per-action confirmation. Staging a new file with POST /experts or POST /sets changes nothing that runs until a deployment uses it.

Technical analysis. POST /symbols/<symbol>/rates/ta returns OHLC bars and the indicators you ask for in one call. wickworks computes them server-side and returns series and levels, not buy or sell signals. Build interpretations in the consumer. See Technical analysis.

Setup

mt5-httpapi must already be installed and running; for that, see the docs at https://psyb0t.github.io/mt5-httpapi/. The user provides the connection values in the environment:

bash
export MT5_API_URL=http://localhost:8888/<broker>/<account>
export MT5_API_TOKEN=<the-token-the-user-gives-you>

If MT5_API_URL is not set in the environment, ask the user; do not try to discover it from project files. Same for MT5_API_TOKEN: take it from the env var the user set, or from the user directly (see Security & safety).

One entry point fronts every terminal. The path prefix /<broker>/<account>/ selects which terminal you talk to; MT5_API_URL is the full base including that prefix.

Verify: curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/ping: .status should be "ok" and .mode "live" for the normal API process (the reply also carries sdk_threads_alive and sdk_oldest_alive_s). If not, the API isn't up yet (it may still be initializing; it retries in the background).

Auth is optional server-side. If no token is configured on the server, all requests go through without a token. If a token is configured, all endpoints require Authorization: Bearer <token> and return 401 without it. From the agent's side, never assume the server is auth-disabled; always pass the token the user provided if there is one.

MCP interface

Each terminal also speaks Model Context Protocol (streamable-HTTP) at /mcp, exposing the REST surface as dedicated typed tools whose names + params + descriptions are the agent's documentation. Families: market data (list_symbols, get_symbol, get_tick, get_rates, get_ticks, get_rates_ta), account/positions (get_account, list_positions, get_position, modify_position, close_position), orders (list_orders, get_order, create_order, modify_order, cancel_order), history/terminal (get_history_orders, get_history_deals, get_terminal, terminal_control), backtest (get_backtest), and ping. A generic request + endpoints catalog remain as a fallback for JSON-compatible routes without a dedicated tool; multipart submission at POST /backtest still uses REST directly. Every tool runs the exact same handler, auth, and MT5 locking as a real HTTP call.

On terminals with Chart Deployments enabled, MCP also has the chartctl tools: upload_expert, list_experts, delete_expert, upload_set, list_sets, get_set, delete_set, create_deployment, list_deployments, get_deployment, update_deployment, delete_deployment, reconcile_deployments, list_charts, get_loader, screenshot_chart, close_chart, get_webrequest, set_webrequest, apply_webrequest, verify_webrequest. The upload tools take the file as base64 (upload_set also takes plain text) and send the multipart form for you. screenshot_chart returns the PNG as image content you can look at. On terminals with the file API enabled, list_files, get_file, put_file and delete_file read and write files in the terminal's install directory or the compile tree.

Same bearer token as the REST API (MT5_API_TOKEN, empty = auth disabled). Connect directly at $MT5_API_URL/mcp/. The order/position tools (create_order, cancel_order, close_position, …) are irreversible on a live account; see Security & safety above.

A per-terminal /mcp is bound to that one terminal, because an MCP session's tool catalog is fixed and has no per-call slot for naming an account. Pointing a client at the server ROOT instead (http://<host>:8888/mcp/, no broker/account prefix) gives the same tools with broker and account parameters, so one session reaches every terminal. Call list_terminals first to get the configured brokers/accounts, each process mode (live or backtest), and whether Chart Deployments (chartctl) and the file API (files) are enabled for each; the mode does not identify whether the brokerage account itself is live or demo, so check GET /account before trading. An unconfigured pair is refused with the valid list rather than routed to a plausible-looking wrong account. Both forms are available at once, and the URL alone decides which one a client gets. When acting through the unified endpoint, confirm the broker/account alongside the trade parameters: one wrong argument places a real order on a different real account.

How the fucker works

GET for reading, POST for creating, PUT for modifying, DELETE for closing/canceling. All bodies are JSON.

Application handler errors normally use this JSON shape; always inspect the HTTP status and content type because framework-level failures can differ:

json
{"error": "description of what went wrong"}

Pre-trade checks: do not skip this shit

Before placing any trade:

  1. GET /account → trade_allowed must be true
  2. GET /symbols/SYMBOL → trade_mode must be 4 (full trading)
  3. GET /symbols/SYMBOL → check trade_contract_size: 1 lot of EURUSD = 100,000 EUR, not 1 EUR
  4. GET /terminal → connected must be true

API reference

Health

bash
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/ping
# {"status": "ok", "mode": "live", "sdk_threads_alive": 0, "sdk_oldest_alive_s": null}

curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/error
# {"code": 1, "message": "Success"}

Terminal

bash
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/terminal
curl -X POST -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/terminal/init
curl -X POST -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/terminal/shutdown
curl -X POST -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/terminal/restart

Key fields on /terminal: connected, trade_allowed, build, company, broker_utc_offset_hours (signed offset applied to all timestamps in/out; see Broker time below).

Broker time vs real UTC

MT5 returns timestamps in the broker server's wall-clock time disguised as unix integers (RoboForex/FTMO = UTC+3, TeleTrade = UTC+2, etc.). When the operator has set a UTC offset for the terminal (fixed, or auto, where the API measures it from live ticks and follows daylight saving changes; GET /terminal shows broker_utc_offset_mode and broker_utc_offset_status), every outgoing time field (tick time, rate time, position/order/deal time* and time_*_msc) is real UTC unix, and every incoming from/to query param is interpreted as real UTC unix. If no offset is set or it is 0, raw broker timestamps pass through (legacy behavior). Check GET /terminal → broker_utc_offset_hours to confirm.

Account

bash
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/account
json
{
    "login": 12345678,
    "balance": 10000.0,
    "equity": 10000.0,
    "margin": 0.0,
    "margin_free": 10000.0,
    "margin_level": 0.0,
    "leverage": 500,
    "currency": "USD",
    "trade_allowed": true,
    "margin_so_call": 70.0,
    "margin_so_so": 20.0
}

Symbols

bash
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/symbols
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols?group=*USD*"
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/symbols/EURUSD
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/symbols/EURUSD/tick
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols/EURUSD/rates?timeframe=H4&count=100"
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols/EURUSD/rates?timeframe=H1&from=$(date +%s)&count=-100"
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols/EURUSD/rates?timeframe=H1&from=$(date -d '1 day ago' +%s)&to=$(date +%s)"
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols/EURUSD/ticks?count=100"
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols/EURUSD/ticks?from=$(date -d '1 hour ago' +%s)&count=500"
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/symbols/EURUSD/ticks?from=$(date -d '1 hour ago' +%s)&to=$(date +%s)"

Timeframes: M1 M2 M3 M4 M5 M6 M10 M12 M15 M20 M30 H1 H2 H3 H4 H6 H8 H12 D1 W1 MN1

Rates/ticks query model, two modes, mutually exclusive:

  • Anchor + signed count: count=N = N forward from from, count=-N = \|N\| ending at from, count=0 = empty. Omit from to anchor at now: the latest \|N\| bars or ticks up to now, whatever the sign of count. A count that is not an integer is a 400.
  • Range (from + to): all bars/ticks in the window, no count cap beyond terminal_info().maxbars. to requires from and rejects count (returns 400).

from and to accept three formats (all real UTC): unix seconds (1700000000), full datetime YYYY_MM_DD_HH_MM_SS (2024_01_15_14_30_00), or date-only YYYY_MM_DD (midnight UTC).

Capped at terminal_info().maxbars rows per request (default 100k, see GET /terminal). Symbols auto-select into MarketWatch on first access. Responses are gzipped if the client requests it (curl --compressed).

Tick flags param: ALL (default), INFO (bid/ask only, ~10× smaller), TRADE (trades only).

Key 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.

Technical analysis

POST /symbols/<symbol>/rates/ta takes the same query params as /rates (timeframe, count, from, to), JSON body carries the wickworks indicator spec. Response is {symbol, timeframe, bars, ta}: OHLC bars and analyzed indicator series in one round-trip. Skip the local pandas circus: wickworks does the math server-side and returns primitives, not magical buy/sell bullshit. Build interpretations in the consumer.

Full catalog with all indicator types, params, output shapes, and SMC primitives is documented at github.com/psyb0t/docker-wickworks.

bash
# RSI + MACD + Bollinger Bands on the last 200 H1 bars.
curl -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{
    "indicators": {
      "rsi": true,
      "macd": true,
      "bbands": {"length": 20, "std": 2}
    }
  }' \
  "$MT5_API_URL/symbols/EURUSD/rates/ta?timeframe=H1&count=200"

Response shape (keys under ta mirror the keys in your indicators object):

json
{
  "symbol": "EURUSD",
  "timeframe": "H1",
  "bars": [ { "time": ..., "open": ..., "high": ..., "low": ..., "close": ..., "tick_volume": ... } ],
  "ta": {
    "rsi": [null, null, ..., 54.2, 56.1, 58.7],
    "macd": { "macd": [...], "signal": [...], "hist": [...] },
    "bbands": { "upper": [...], "middle": [...], "lower": [...] }
  }
}

Indicator catalog (request as "name": true for defaults, or "name": {"length": 21, ...} for tuning; params are flat on the object; add "type": "<name>" only when the output key differs from the indicator name, e.g. running two RSIs as rsi14 + rsi21):

  • Moving averages: ema, sma, hma, wma, dema, tema, t3, kama, alma, linreg, jma, zlma, rma, fwma, swma, sinwma, trima, vwma, vwap (session-anchored: anchor D/W/M + sessionOffset)
  • Momentum oscillators: rsi, mfi, willr, cci, roc, mom, uo, stoch, stochrsi, macd, tsi, trix, fisher
  • Trend strength & cross-direction: adx, aroon, vortex
  • Volatility: atr, natr
  • Volume / money flow: obv, ad, cmf, adosc, kvo
  • Bands & channels: bbands, kc, donchian
  • Trailing trend signals: supertrend, psar, chandelierExit, ichimoku
  • Compression: squeeze (Bollinger inside Keltner; state machine on/off/no flags)
  • SMC primitives: orderBlocks, fvg (alias fvgs), bosChoch, swingLevels, srLevels, recentRange, liquidity, previousHighLow, sessions, retracements
  • Analysis summaries (last-bar snapshots, shared cached pass, free if you ask for any): price, levels, momentum, volume, position, slope

Wickworks is primitives-only: no built-in divergence detection, no MA-cross events, no golden/death-cross tagging. Build those in the consumer over the raw series.

Each indicator declares its minimum bar requirement (e.g. sma(200) needs 200 bars). If you under-feed it, the server returns HTTP 502 wrapping a wickworks 400 with a per-indicator deficit list, so you see exactly which indicators need more bars, not just a generic "insufficient bars" error.

Pre-flight tips:

  • Match count to your slowest indicator's lookback × 2 (e.g. sma(200) → fetch at least 400 bars for warmup + signal).
  • recentBars in the body is ignored: the API never reads it. To get only the last N bars, set count accordingly on the rates query, or slice the response client-side.
  • Combine with /symbols/:symbol/rates (raw OHLC) when you need TA for charting separate from trade-decision logic.

Orders

POST /orders, PUT /orders/<id> and DELETE /orders/<id> open, modify and cancel real orders. Follow the confirmation guardrail in Security & safety.

bash
# Place a market order, only after the user confirmed this exact order.
curl -X POST -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/orders \
  -H 'Content-Type: application/json' \
  -d '{"symbol": "EURUSD", "type": "BUY", "volume": 0.1, "sl": 1.08, "tp": 1.10}'

# List pending orders
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/orders
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/orders?symbol=EURUSD"
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/orders/42094812

# Modify pending order
curl -X PUT -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/orders/42094812 \
  -H 'Content-Type: application/json' \
  -d '{"price": 1.09, "sl": 1.07, "tp": 1.11}'

# Cancel pending order
curl -X DELETE -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/orders/42094812

Order types: BUY, SELL, BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP, BUY_STOP_LIMIT, SELL_STOP_LIMIT

Fill policies: FOK, IOC, RETURN. Leave type_filling out and the API sends one the symbol accepts (IOC, else FOK, else RETURN); an unknown value sends none at all.

Expiration: GTC (default), DAY, SPECIFIED, SPECIFIED_DAY

Required fields: symbol, type, volume. price auto-fills for market orders.

Stop-limit and expiry: stoplimit is the limit price of a BUY_STOP_LIMIT / SELL_STOP_LIMIT order (price is then the stop trigger) and is required for those two types. expiration is integer unix seconds in real UTC; it is required with SPECIFIED / SPECIFIED_DAY, and sent without a type_time it selects SPECIFIED. PUT /orders/<id> takes both too, and a field left out keeps the order's current value. A missing or bad value is a 400.

Trade result:

json
{
    "retcode": 10009,
    "deal": 40536203,
    "order": 42094820,
    "volume": 0.1,
    "price": 1.0950,
    "comment": "Request executed"
}

retcode 10009 = success. Anything else = something went wrong.

Positions

PUT /positions/<id> changes the SL/TP of a live position and DELETE /positions/<id> closes it, fully or partly. Follow the confirmation guardrail in Security & safety, and show the symbol, ticket, current price and the change.

bash
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/positions
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/positions?symbol=EURUSD"
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/positions/42094820

# Update SL/TP
curl -X PUT -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/positions/42094820 \
  -H 'Content-Type: application/json' \
  -d '{"sl": 1.085, "tp": 1.105}'

# Close full position
curl -X DELETE -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/positions/42094820

# Partial close
curl -X DELETE -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/positions/42094820 \
  -H 'Content-Type: application/json' \
  -d '{"volume": 0.05}'

Key position fields: ticket, type (0=buy, 1=sell), volume, price_open, price_current, sl, tp, profit, swap.

A close that answers 500 can still have closed part of the volume (retcode 10010, DONE_PARTIAL, counts as a failure there), so read GET /positions/<id> again before asking to retry.

The optional signal copier places orders on its own. Its positions and orders carry the source's magic and a comment of the form <source>:<message id>:<leg> (its client_order_id), which is how to tell them from manual trades. Treat them like any other position: closing one needs the same confirmation.

History

bash
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/history/orders?from=$(date -d '1 day ago' +%s)&to=$(date +%s)"
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/history/deals?from=$(date -d '1 day ago' +%s)&to=$(date +%s)"

from and to are required, unix epoch seconds.

Deal fields: type (0=buy, 1=sell), entry (0=opening, 1=closing), profit (0 for entries, realized P&L for exits).

Chart Deployments

Deploy Expert Advisors to charts over HTTP. No RDP, no terminal restart. Stage .ex5 + .set files, declare deployments, and a resident loader EA inside the terminal reconciles charts to match. The API holds desired state; the loader reports observed truth. A deployment only flips to running once the loader confirms the expert is live on a chart.

Off unless the operator enabled it for the terminal (live-mode terminals only). On a terminal without it these routes answer 404 and the per-terminal MCP endpoint has no chartctl tools; on the unified MCP endpoint list_terminals shows chartctl per terminal. Once enabled, the loader attaches itself on boot through [StartUp] Expert=, so there is nothing to attach by hand. If GET /loader says alive: false, nothing will deploy; tell the user instead of retrying.

Endpoint reference:

MethodEndpointDescription
POST / GET/expertsStage, list EA .ex5
DELETE/experts/<name>Remove a staged EA .ex5
POST / GET/setsStage, list .set files
GET / DELETE/sets/<name>Inspect a .set (returns parsed inputs), remove it
POST / GET/deploymentsCreate or list deployments
GET / PATCH / DELETE/deployments/<id>Inspect, pause/resume, change set, delete
POST/deployments/reconcileForce immediate reconcile
GET/chartsLive chart/EA inventory
GET/loaderLoader EA status and version
POST/charts/<id>/screenshotCapture chart as PNG
POST/charts/<id>/closeClose a chart by id

Deleting an expert or set answers 409 IN_USE while any deployment, paused ones included, names it (delete the deployment first), 404 ARTIFACT_NOT_FOUND when it is not staged, and 403 HOST_ASSET for a host-managed file under assets/.

bash
# Stage artifacts. Re-uploading identical bytes is skipped; different bytes
# under the same .ex5 name need ?overwrite=true. The response's
# "navigator_refresh" must be "ok" before a deployment of a NEW expert can
# attach: on "failed" upload the same file again, on "unavailable" (bare metal)
# the terminal needs a restart first.
curl -H "Authorization: Bearer $MT5_API_TOKEN" \
  -F "expert=@HappyGoldScalp.ex5" "$MT5_API_URL/experts"
curl -H "Authorization: Bearer $MT5_API_TOKEN" \
  -F "set=@gold-m5.set" "$MT5_API_URL/sets"   # returns the parsed inputs

# Deploy (live EA: see Security & safety). 409 DUPLICATE_CHART if an enabled
# deployment already targets this symbol + timeframe.
curl -X POST "$MT5_API_URL/deployments" \
  -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"expert":"HappyGoldScalp.ex5","set":"gold-m5.set","symbol":"XAUUSD","timeframe":"M5"}'
# -> 202 {"id":"dep_a1b2c3","status":"pending",...}

# Poll until status is "running" (or "failed"; the error is in the payload)
curl -H "Authorization: Bearer $MT5_API_TOKEN" "$MT5_API_URL/deployments/dep_a1b2c3"

# Pause, switch the set file ("set": "" runs on the EA defaults), delete.
# Pausing or deleting closes the deployment's chart. A new set file does NOT
# reach an expert that is already running: it applies the next time the loader
# opens the chart. To apply it now: pause, wait until GET /charts no longer
# lists the deployment's chart (the deployment says "paused" right away, before
# the loader acts), then resume. Resuming is refused with 409 DUPLICATE_CHART
# while another enabled deployment runs on the same symbol and timeframe.
curl -X PATCH "$MT5_API_URL/deployments/dep_a1b2c3" \
  -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"enabled":false}'
curl -X DELETE "$MT5_API_URL/deployments/dep_a1b2c3" \
  -H "Authorization: Bearer $MT5_API_TOKEN"

# Look at the chart (PNG; width/height optional, default 1280x720)
curl -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  "$MT5_API_URL/charts/133039100/screenshot?width=1280&height=720" -o chart.png

WebRequest allowlist. An EA that calls WebRequest() only reaches URLs on the terminal's allowlist. GET /webrequest returns the list. PUT /webrequest replaces it with {"urls": [...]} or edits it with {"add": [...], "remove": [...]} (a patch keeps every other entry the terminal holds) and applies it right away; a URL that is not http(s) with a host and no spaces is refused with 400 INVALID_URL. Inside the Windows VM the API sets the list in the terminal's Options dialog with window messages; on bare metal it rewrites common.ini and restarts the terminal. The VM terminal forgets the list when it restarts. The API re-applies it when its own process starts and after every terminal restart it performs itself (POST /terminal/restart, the health monitor), so call POST /webrequest/apply only after a restart from outside the API, or when an expert's WebRequest() is still refused. GET /webrequest shows the last apply result as last_apply; POST /webrequest/verify reads the list the terminal really holds (at most once per 10 s). While a backtest runs on the terminal these calls answer 409.

bash
curl -X PUT "$MT5_API_URL/webrequest" \
  -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"add":["https://api.example.com"]}'

Full protocol: docs/chart-control-protocol.md.

Files

Off unless the operator enabled it for the terminal. Without it these routes answer 404. GET /files/<path> lists a directory or downloads a file in the terminal's install directory (the directory with terminal64.exe), PUT /files/<path> uploads one (raw body or a multipart file field), PUT /files/<dir>?extract unpacks a zip into that directory, and DELETE /files/<path> (?recursive for a non-empty directory) removes it. /compile/files/... does the same on the MQL5 tree POST /compile builds against, which is where a shared .mqh library goes. The MCP tools are list_files, get_file, put_file and delete_file, with tree set to terminal or compile.

The broker credentials (mt5start.ini, Config/accounts.dat) are never served, and the terminal's executables and Chart Deployments' own files are read-only here. Writes and deletes follow the guardrail in Security & safety: confirm the terminal and the exact path first. Reading files and logs is read-only and needs no separate confirmation.

bash
# Unpack a library into the compile tree, then compile against it
curl -X PUT -H "Authorization: Bearer $MT5_API_TOKEN" --data-binary @MyLib.zip \
  "$MT5_API_URL/compile/files/Include/MyLib?extract"
# source: #include <MyLib/Signals.mqh>

Compile

POST /compile turns MQL5 source into an .ex5. The body is JSON: source (required, the whole .mq5 text), filename (optional, only the stem is kept) and ea_version (optional, logged only). Every answer the handler gives has ok and log: 200 adds ex5_base64 (decode it to get the .ex5), warnings and include_hash; 422 means the source did not compile and log has MetaEditor's errors; 429 means too many compiles are waiting (retry after Retry-After); 504 is a timeout. Send compiles one at a time; they run one by one anyway. There is no dedicated MCP tool: call it through request("POST", "/compile", body={...}). It changes nothing on the account. Full reference: docs/compiling.md.

bash
curl -sS -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H 'Content-Type: application/json' \
  "$MT5_API_URL/compile" \
  -d '{"source": "void OnTick() {}", "filename": "MyEA.mq5"}' \
  | jq -r 'if .ok then .ex5_base64 else .log end'

Backtest

Run MT5 Strategy Tester via the API. Two-stage workflow: build the INI from a JSON spec, then submit it together with the .ex5 (and optional .set) for async execution. Endpoints exist on every terminal but only run on a terminal the operator set to backtest mode. MT5 is single-instance per portable data dir, so a tester subprocess collides with a live-mode terminal that already owns the directory and exits silently. The broker/account in the URL determines which credentials are injected into the run's [Common] section. Only one tester runs at a time per API process; extra submissions queue. Responses below use snake_case field names. The old camelCase names still show up alongside them in responses, and request bodies still accept either one, but the camelCase names are deprecated and go away in v5.0.0.

The expert and set file can be uploaded inline OR referenced by name from the server's host-managed pool of experts (.ex5) and sets (.set).

bash
# 1. Build INI: NZDJPY M15, last 5 years, open prices only, 5 ms latency.
curl -sS -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H "Content-Type: application/json" \
  $MT5_API_URL/backtest/build-ini \
  -d '{
    "symbol": "NZDJPY",
    "timeframe": "M15",
    "expert": "EA Studio NZDJPY M15 1615044595.ex5",
    "last_years": 5,
    "modelling": "open-prices",
    "latency_ms": 5,
    "expert_parameters": "ea studio nzdjpy m15 1615044595.set"
  }' > tester.ini

# 2. Submit. Use uploads OR host-managed asset names; here, both are host-managed.
JOB=$(curl -sS -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  $MT5_API_URL/backtest \
  -F "ini=@tester.ini" \
  -F "expert_name=EA Studio NZDJPY M15 1615044595.ex5" \
  -F "set_name=ea studio nzdjpy m15 1615044595.set" \
  | jq -r .job_id)

# 3. Poll. Status is queued → running → completed (or failed, or cancelled).
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/backtest/$JOB

# 4. Fetch the report HTML and the terminal log.
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/backtest/$JOB/report -o report.htm
curl -H "Authorization: Bearer $MT5_API_TOKEN" $MT5_API_URL/backtest/$JOB/log    -o run.log

POST /backtest/build-ini JSON fields: symbol, timeframe (M1…MN1), expert (must end .ex5), and exactly one of from_date+to_date, last_years, or last_days. Optional: modelling (every-tick 1m-ohlc open-prices real-ticks), latency_ms, deposit (10000), currency (USD), leverage (100, written as 1:N), expert_parameters (.set), optimization (0..3), optimization_criterion (0..7), forward_mode (0..4), visual, and report_name (backtest-report.htm, or optimization-report.xml when optimization is enabled).

POST /backtest/build-set generates MT5-native .set parameter text from structured JSON. Body: comments (array of strings) and parameters (array of {name, value, start?, step?, stop?, optimize?}). optimize: true emits the optimization form value||start||step||stop||Y; optimize: false (or "N") emits value||start||step||stop||N. Omitting all four range fields emits plain name=value; providing only some range fields is rejected. Response is text/plain .set content ready to save or upload as the set file.

bash
curl -sS -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H "Content-Type: application/json" \
  $MT5_API_URL/backtest/build-set \
  -d '{
    "comments": ["saved on 2026.05.15 08:30:02"],
    "parameters": [
      {"name": "_Properties_", "value": "------"},
      {"name": "Take_Profit", "value": 92, "start": 80, "step": 4, "stop": 92, "optimize": true},
      {"name": "Stop_Loss", "value": 0, "start": 0, "step": 1, "stop": 10, "optimize": false}
    ]
  }' > myea.set

POST /backtest multipart fields: ini (required), one of expert or expert_name, optional set or set_name. Optional top_passes, for optimization jobs, keeps the top 1..500 parsed XML passes in the status payload (default 50). Optional timeout overrides the configured Strategy Tester deadline using duration strings such as "30m" or "6h". Returns 202 with job_id, status_url, report_url, log_url, poll_after_seconds, queue_position. The INI's [Common] Login/Password/Server are always overwritten with the URL-selected account's credentials. Path traversal in *_name is rejected.

GET /backtest/<job_id> returns the job state. When status: completed, the payload includes a summary parsed from the HTML (net_profit, profit_factor, recovery_factor, expected_payoff, sharpe_ratio, max_drawdown, total_trades, profit_trades, loss_trades, …). Jobs left running when the API restarts are marked failed on the next startup.

GET /backtest/<job_id>/tail?lines=N returns live diagnostic JSON while a job is queued, running, or finished. It includes captured process output plus the latest terminal and Strategy Tester journal lines; lines defaults to 200 and is clamped to 10..1000. The MCP get_backtest tool exposes the same data with part: "tail".

POST /backtest/<job_id>/cancel stops a queued or running job and marks it cancelled (a final status). It kills only that terminal's tester processes, and only when that job is the one running there; it is safe to repeat.

Real backtest runbook: finish the fucking job

When the user asks for a real backtest, do not declare victory after building an INI or getting 202 Accepted. That only means the job entered the building. The task is complete after one of these is true:

  • the job reaches completed, the report/log are downloaded, and the requested summary fields are returned
  • a request fails and you report the exact endpoint, HTTP status, and response body
  • the job reaches failed and you report the final status payload exactly

Before submitting a backtest that references host-managed files:

  1. Use the filenames exactly as the user gave them; a name the server does not have fails the submit, so report that response as is.
  2. Verify GET $MT5_API_URL/ping returns backtest mode on the target terminal: .status is "ok" and .mode is "backtest" (other fields come with it).
  3. If the user specifies a concrete date window, prefer explicit UTC from_date/to_date and do not also send last_years or last_days.
  4. Auth handling: use MT5_API_TOKEN from the user-set environment variable. If it is missing and the server requires auth, ask the user to provide it. Do not search the repository or read config/config.yaml to harvest credentials. Backtests are read-side from the user's perspective (the server orchestrates Strategy Tester locally and never opens live trades), so no per-action confirmation is required to submit, but still surface the broker URL prefix so the user can catch a wrong-account misroute.

Execution guidance:

  • Prefer one shell script or one tightly scoped command sequence that performs verify -> ping -> build INI -> submit -> poll -> download artifacts. This reduces uncertainty from partially completed attempts.
  • Persist the local artifacts in a dedicated output directory: tester.ini, status.json, report.html (or .htm), and run.log.
  • Treat queued and running as normal intermediate states. Report the job ID and latest status while polling.
  • If no job_id has been captured yet, there is no confirmed backtest in progress. Do not claim the server is still working without that evidence.
  • Poll GET /backtest/<job_id> using poll_after_seconds from the submit/status payload when available. If the user explicitly requests a cadence, follow it.
  • On any non-2xx HTTP response, stop immediately and show: endpoint, HTTP status, and raw response body.
  • On status: failed, stop immediately and show the full final status payload.

Completion guidance:

  • Download both report_url and log_url before declaring success.
  • Return the requested summary fields directly from the final status payload's summary object.
  • Include the local artifact paths so the user can inspect the exact report and terminal log.

Example agent-oriented flow:

bash
# 1. Health check the target backtest terminal.
curl -sS -H "Authorization: Bearer $MT5_API_TOKEN" \
  "$MT5_API_URL/ping"

# 2. Build the INI from an explicit UTC window.
curl -sS -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  -H "Content-Type: application/json" \
  "$MT5_API_URL/backtest/build-ini" \
  -d '{
    "symbol": "GBPCAD",
    "timeframe": "M15",
    "expert": "EA.ex5",
    "from_date": "2021-05-11",
    "to_date": "2026-05-11",
    "modelling": "open-prices",
    "latency_ms": 5,
    "deposit": 1000,
    "currency": "USD"
  }' > tester.ini

# 3. Submit and capture the job ID.
JOB=$(curl -sS -X POST -H "Authorization: Bearer $MT5_API_TOKEN" \
  "$MT5_API_URL/backtest" \
  -F "ini=@tester.ini" \
  -F "expert_name=EA.ex5" \
  -F "set_name=EA.set" | jq -r .job_id)

# 4. Poll until completed, failed or cancelled, then download artifacts.
curl -sS -H "Authorization: Bearer $MT5_API_TOKEN" \
  "$MT5_API_URL/backtest/$JOB"
curl -sS -H "Authorization: Bearer $MT5_API_TOKEN" \
  "$MT5_API_URL/backtest/$JOB/report" -o report.html
curl -sS -H "Authorization: Bearer $MT5_API_TOKEN" \
  "$MT5_API_URL/backtest/$JOB/log" -o run.log

Position sizing

text
risk_amount     = balance * risk_pct
sl_distance     = ATR * multiplier
ticks_in_sl     = sl_distance / trade_tick_size
risk_per_lot    = ticks_in_sl * trade_tick_value
volume          = risk_amount / risk_per_lot

Round 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.

Tips

  • Always check retcode: 10009 = good, anything else = bad
  • Use GET /error to debug failed trades
  • deviation = max slippage in points. POST /orders has no default (send one for market orders); DELETE /positions/<id> defaults to 20
  • Leave type_filling out unless the user wants a specific policy; the API already picks one the symbol accepts
  • Candle time is the open time, not close time
  • trade_stops_level = minimum SL/TP distance from current price in points
  • Markets have hours; check trade_mode before placing orders

Related skills

More in Integrations
ClawHub

Skills and plugins for OpenClaw agents. Part of the wider OpenClaw ecosystem.

Explore docs

SkillsPluginsOfficialAudits

Publish SkillPublish PluginCreate org

OverviewOpenClawDocsBlog

SupportGitHubDiscord

Built alongside the OpenClaw ecosystem

LobsterCrabboxClickClackCrabfleetOctopoolClawSweeperagent-skillsdiscrawlgitcrawlslacrawlnotcrawltelecrawlgraincrawlcrawlkitcrawlbaracpxmcporterTachikomaclawpatchclawbenchPeekaboocookbookplugin-inspectorwacrawlcrabpotAll projectsLobsterCrabboxClickClackCrabfleetOctopoolClawSweeperagent-skillsdiscrawlgitcrawlslacrawlnotcrawltelecrawlgraincrawlcrawlkitcrawlbaracpxmcporterTachikomaclawpatchclawbenchPeekaboocookbookplugin-inspectorwacrawlcrabpotAll projects

© 2026 OpenClaw Foundation

Privacy policy·Status·Deployed on Vercel·Powered by Convex

....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals
  hooks runners slash-commands skill.md templates scanners review-bots     safe browse paths   official gateways   publisher handles   org trust   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@
openclaw ecosystem    crabbox clickclack crawler packs gateway plugins   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship
---- downloads installs stars lineage ownership docs package integrity   >>> install scan publish verify    @@ gateway @@ registry @@ agents @@   :::: signed manifests ::::: moderated releases ::::: version history ::::
  safe browse paths   official gateways   publisher handles   org trust     30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship     hooks runners slash-commands skill.md templates scanners review-bots
....:: clawhub/openclaw ::....  skills plugins publishers trust signals   :::: signed manifests ::::: moderated releases ::::: version history ::::   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins
>>> install scan publish verify    @@ gateway @@ registry @@ agents @@     hooks runners slash-commands skill.md templates scanners review-bots   ---- downloads installs stars lineage ownership docs package integrity
  30 skills 12 plugins    /api/v1/skills   /owners   /audit   /ship   openclaw ecosystem    crabbox clickclack crawler packs gateway plugins     safe browse paths   official gateways   publisher handles   org trust
:::: signed manifests ::::: moderated releases ::::: version history ::::   ---- downloads installs stars lineage ownership docs package integrity   ....:: clawhub/openclaw ::....  skills plugins publishers trust signals