ChartnautDocs

Demo accounts

A demo account trades live market prices with simulated money. You create them for a user, they trade in Chartnaut, and fills happen on Chartnaut's servers at real prices. Needs demo_accounts:write to create and act, demo_accounts:read to read.

Create

curl https://api.chartnaut.com/partner/v1/accounts \
  -H "Authorization: Bearer cn_partner_live_XXXX" \
  -H "Idempotency-Key: live-week-user-8812" \
  -H "Content-Type: application/json" \
  -d '{
    "user": "ext:user-8812",
    "display_name": "Live week",
    "starting_balance": 25000,
    "leverage": 100,
    "rules": [
      { "type": "daily_loss", "limit": 1000, "on_breach": "block_order" },
      { "type": "max_drawdown", "limit": 2500, "mode": "trailing", "on_breach": "close_and_end" }
    ],
    "labels": { "event": "live-week" }
  }'

Field

Meaning

display_name

Required, up to 64 characters. The user sees it among their accounts

starting_balance

USD, from 100 to 10,000,000. Left out, it is 100,000

leverage

From 1 to 500. Left out, it is 50

rules

Any rules

locked

Default true

external_ref

Your id for it, unique across your accounts

labels

Up to 20. Keys are 1 to 40 lower-case letters, digits or _ . -, starting with a letter or digit; values are strings up to 100 bytes

A new account is locked unless you send "locked": false, so you can open a whole event at once. The user sees it among their accounts in Chartnaut, marked Locked by your name while it is locked. Demo accounts are in USD and never use the user's plan slots or live-account credits.

The answer is 201 with the account, read as below. Each user can hold 5 active or locked accounts from you, and you 2,000 in all: past that, 422 partner_limit with details.limit and details.max. A reused external_ref is 409 conflict. Invalid rules are 400 invalid_request with details.field pointing into rules. Any other bad field, an unknown one included, is 400 invalid_request with the field named in message and no details.

POST /accounts/batch takes up to 500 and answers each item on its own, in order, with 200, the same as sessions: {"data": [{"index": 0, "id": "acc_…"}, {"index": 1, "error": {"code": "partner_limit", "message": "…", "details": {…}}}]}. Each item is made in its own transaction, so a refused item never stops the others.

Read and list

GET /accounts/acc_5521 returns the balance, a valuation with equity, floating P&L and margin as of the latest prices, the open positions, lock state, rules and a breaches summary with the count and the time of the latest. valuation is left out when the account can't be valued right now, and positions when none are open.

GET /accounts?label.event=live-week lists yours, newest first, for users who still grant demo_accounts:read. You can also filter by user and status. A list item has the balance, lock state and rules, but no valuation, positions or breaches: for equity, read each account.

/accounts/{id}/trades pages through closed trades, newest first, each with instrument, side (Long or Short) and realized_pnl. Add since=2026-11-17T00:00:00Z for trades closed from then on. /accounts/{id}/breaches pages through breaches, newest first.

PATCH /accounts/{id} with {"labels": {…}} merges labels; set a key to null to remove it. The answer is the account as a list item gives it.

The user's own accounts

With accounts:read, GET /accounts?origin=user&user=ext:user-8812 lists the user's own accounts: their own Chartnaut Demo account and every broker account they linked, but none you created. Each has id, broker (such as chartnaut_demo, mt5 or ctrader), display_name, currency, balance, equity, starting_balance, leverage and created_at, oldest first. label.* and status filters are ignored.

With the same permission, GET /accounts/{id} reads one of them, GET /accounts/{id}/positions its open positions and GET /accounts/{id}/trades its closed trades, newest first. You can read them and never act on them. An account of someone who isn't linked to you is 404 not_found; a linked user who didn't grant accounts:read is 403 scope_not_granted. See Accounts.

Lock, unlock and close everything

POST /accounts/actions takes ids or labels plus expected_count, like sessions. If expected_count is given and a different number of accounts match, nothing happens and you get 409 expected_count_mismatch.

{ "action": "close_all", "labels": { "event": "live-week" }, "expected_count": 120 }

The answer has a result per account: {"data": [{"id": "acc_5521", "result": "closed"}, …]}.

result

Meaning

locked, unlocked

This call locked or unlocked it

closed

close_all locked it and nothing is left open

closing

close_all locked it, but positions are still closing, for example in a closed market. error says why when it can. Read the account later

already

It was already in that state, or it has ended

not_found

Not one of yours, or its user no longer grants demo_accounts:write

error

Something failed; error says what. Retry that id

  • Lock freezes the account. The user can place, change, cancel or close nothing, and nothing fills: an entry, stop or target the price crosses stays armed and fills after an unlock, if the price is still there. A margin stop-out still runs.

  • Unlock lets trading resume.

  • close_all locks the account, cancels positions whose entry hasn't filled and closes the rest at market. It works on locked accounts and is safe to run twice. Accounts it can't finish within 20 seconds are handed on and answer closing.

close_all counts toward 2,000 items an hour, shared with session end. Past that, nothing happens yet: it answers 202 with {"pending_action_id": …} until Chartnaut approves it.

When a user unlinks, the accounts you made for them lock.

A live event

  1. POST /accounts/batch with a label, locked.

  2. At the start, unlock by label with expected_count.

  3. Poll GET /accounts?label.event=live-week for balances, and read each account for equity.

  4. At the end, close_all by label with expected_count.