Skip to content

Safety Model

SimonTarara62 edited this page Nov 29, 2026 · 6 revisions

Safety Model

This server brokers real trading credentials and can place real orders, so it is built to refuse by default and require explicit, narrow opt-in at every step. This page explains the guardrails; see Error Reference for the exact errors they raise when they trigger.

⚠️ Trading is risky. These guardrails reduce the blast radius of mistakes and bugs — they do not make trading safe. Always start on a demo account, and only enable live trading once you understand every setting below.

Trading is off by default

Trading is refused (TradingDisabledError) unless both of the following are true:

  • CAP_ALLOW_TRADING=true is set, and
  • the instrument's EPIC is present in CAP_ALLOWED_EPICS (a comma-separated allowlist), or that variable is set to ALL.

CAP_ALLOW_TRADING is checked on every trading call (preview, execute, close, cancel, amend); with it off nothing can be opened, closed, or amended, while market data, positions, orders, and history can still be read. The allowlist is checked when a preview is made and again when it is executed: an EPIC outside it fails the preview check epic_allowed, and is refused at execute with EPIC_NOT_ALLOWED, even with trading enabled. Closing, cancelling and amending are not checked against the allowlist, so what is already open can always be managed.

Two-phase execution

Every trade goes through two distinct tool calls, never one:

  1. Preview (cap_trade_preview_position / cap_trade_preview_working_order) validates the trade against the broker without executing it, and returns a preview reference.
  2. Execute (cap_trade_execute_position / cap_trade_execute_working_order) places the previously previewed trade, and requires confirm=true in the call. Without it, the tool raises ConfirmRequiredError and does nothing.

The same confirm=true requirement applies to every other mutating tool — closing a position, cancelling or amending an order, changing account preferences, topping up a demo balance, and watchlist writes. There is no single tool call that both decides and executes a trade; an agent (or a careless script) cannot skip straight to execution.

One preview, one order

A preview can be executed once. A second execute call with the same preview is refused with PREVIEW_ALREADY_USED, and no order is sent. The setting CAP_PREVIEW_REUSE controls this:

Mode Behaviour
block (default) One execution per preview. A repeat is refused with PREVIEW_ALREADY_USED.
allow A preview can be executed repeatedly until it expires (the behaviour before 0.5.0).
ask Reserved for a later release. It behaves like block today.

If the outcome of an execute call is unknown (timeout, network error, broker 5xx), the preview stays used. Check cap_trade_positions_list and cap_trade_orders_list, then create a new preview. If the broker rejected the order (HTTP 4xx), the preview can be executed again. A REJECTED deal confirmation (the broker accepted the request and then rejected the deal) still uses the preview: create a new one.

The mark is stored in the SDK's state file, so it survives a server restart. The daily-order limit, the size limits and the EPIC allowlist are checked when a preview is created and again when it is executed, against the settings in force at that moment: previews made in advance cannot add up past the daily limit, and a preview made before you narrowed a setting is refused at execute (RISK_LIMIT or EPIC_NOT_ALLOWED, nothing sent). Executes run one at a time within a server process, so parallel calls cannot pass the daily limit either; two server processes sharing one state file are not coordinated. The open-position limit is checked when a position is executed. A repeat after the first order filled the open-position cap returns RISK_LIMIT, not PREVIEW_ALREADY_USED. Errors from broker-backed tools reach the client as <CODE>: <message>; the cap_stream_* tools return errors as data (with error, code and message), and resource reads are not prefixed.

If an execute result ever already has an account key, the marker is added as account_marker instead, so the broker's own data is never overwritten.

Caps

Even with trading enabled and the EPIC allowed, the server enforces limits so a single bad decision — automated or human — can't do unbounded damage:

  • a maximum position size and maximum working-order size per trade,
  • a cap on the number of open positions at once,
  • a cap on the number of orders placed per day.

These are configured via CAP_MAX_POSITION_SIZE, CAP_MAX_WORKING_ORDER_SIZE, CAP_MAX_OPEN_POSITIONS, and CAP_MAX_ORDERS_PER_DAY — see Configuration Reference for defaults. Exceeding one raises RiskLimitError.

Limits per environment (from 0.9.0 with capitalcom-cli 0.8)

If you do not set a limit yourself, the default depends on CAP_ENV. A value you set always wins.

Limit Setting Demo Live
Orders per day CAP_MAX_ORDERS_PER_DAY 200 20
Open positions CAP_MAX_OPEN_POSITIONS 10 3
Order size CAP_MAX_POSITION_SIZE, CAP_MAX_WORKING_ORDER_SIZE 100000 1.0

On a live account these limits protect real money; raising one raises your real-money risk. The Claude Desktop bundle sets them from its form: see Bundle Settings.

What a preview checks, and what an amend keeps (0.9.0)

  • A preview is tied to the account it was made on. Executing it after you switched account is refused with PREVIEW_ACCOUNT_MISMATCH; switch back or create a new preview.
  • A failed preview cannot be executed. Executing one raises PREVIEW_CHECKS_FAILED, and the message lists each failed check.
  • Closed markets. A position preview fails the market_open check when the market is closed. A working-order preview does not: a working order can be previewed and placed on a closed market (the broker accepts it). The SDK could not verify this beyond the cases tried on release day.
  • Conflicting stop or take-profit inputs (a level together with a distance or amount) fail the exclusive_inputs check before anything is sent to the broker.
  • Amend keeps what you do not mention. cap_trade_positions_amend and cap_trade_orders_amend now re-send the current stop, take-profit and expiry for fields you leave out, because the broker removes anything an amend omits. To remove a stop or take-profit, pass remove_stop or remove_profit. Carrying a trailing stop through an amend is best effort: the SDK could not verify it against the broker on release day, and the re-sent distance is the current gap, which can be tighter than the original trail. On a working order a trailing stop becomes a fixed stop.

Dry run

Setting CAP_DRY_RUN=true blocks all executions regardless of the other settings — useful for exercising an agent's full decision flow (search, preview, reasoning) without ever letting an execute call reach the broker. A blocked dry-run call raises DryRunError.

Demo-first

CAP_ENV=demo (the init wizard's default) points the server at Capital.com's demo environment, where trades use simulated funds. Treat CAP_ENV=live as a deliberate, separate opt-in you make only after you trust your configuration and workflow — never the starting point.

Ambiguous confirmations: reconcile, don't retry

A deal confirmation can come back as TIMEOUT — the server genuinely doesn't know whether the order reached the broker. In that case, do not blindly retry the same execute call, since the original order may already be live and a retry could double it up. Instead, reconcile: check cap_trade_positions_list / cap_trade_orders_list (or cap_trade_confirm_get / cap_trade_confirm_wait with the original reference) to see what actually happened before deciding on a next action.

Audit log

An optional, append-only record of trade changes the server completed.

Turn it on by setting the environment variable CAP_AUDIT_LOG to a file path for the server process — in your MCP client's env block (see Client Setup) or in the shell that starts the server. It is an environment variable, not a setting in the credentials file, and it is off by default.

What is recorded: one JSON object per line for every executed trade change — execute-position, execute-order, close, cancel, amend-position, amend-order.

Field Meaning
timestamp UTC time, ISO 8601
command which of the six operations ran
env demo or live
account the account id the change applied to
status the broker's outcome, e.g. ACCEPTED, REJECTED or TIMEOUT
epic, size instrument and size, when the operation has them
preview_id, deal_reference identifiers, when available

What is not recorded: previews, attempts blocked by the safety checks, read-only calls, and calls that fail with an error — including a network failure after the order was sent. The broker's own history is the authoritative record; use the log alongside it, not instead of it.

Privacy: the file never contains API keys, passwords or session tokens. It does contain your account id and deal references, so keep it private. The server creates it with your default file permissions; create it yourself with 0600 permissions or keep it in a private directory.

Reliability: writing is best-effort. If the file cannot be written, the server logs a warning and the trade proceeds unchanged. The file is not rotated; archive or truncate it yourself.

See also

Clone this wiki locally