ChartnautDocs

Backtest sessions

A session is a backtest you create for a user: a trading day, the markets they can use, a starting balance and any rules. The user plays it in the frame or in Chartnaut itself. Needs sessions:write to create and act, sessions:read to read.

Create

curl https://api.chartnaut.com/partner/v1/sessions \
  -H "Authorization: Bearer cn_partner_live_XXXX" \
  -H "Idempotency-Key: nov-open-user-8812" \
  -H "Content-Type: application/json" \
  -d '{
    "user": "ext:user-8812",
    "instruments": ["EURUSD"],
    "day": "2026-11-12",
    "starting_balance": 10000,
    "leverage": 100,
    "commission": { "type": "fixed", "value": 3.5 },
    "time_cap_minutes": 120,
    "rules": [{ "type": "daily_loss", "limit": 500, "on_breach": "close_and_end" }],
    "external_ref": "nov-open-8812",
    "labels": { "event": "nov-open", "round": "1" }
  }'

Field

Meaning

instruments

Up to 10 markets by their Chartnaut symbol, such as EURUSD. The symbol picker is held to these

day

A UTC date, such as 2026-11-12, for the whole day, or an exact UTC time for the 24 hours from it. Must be in the past

starting_balance

Required, up to 1,000,000,000

currency

Three letters, default USD

leverage

Default 100, up to 10,000

commission

Per side: fixed per lot, contract or share, or percentage of the trade's value

time_cap_minutes

Minutes of play from when the session is first opened, then it ends on its own. Up to 7 days; 0 or left out is no cap

blind

Hides the market, the date and prices

allow_skip

Whether the user can jump forward in time (default true)

name

Shown to the user. Defaults to your partner name and "session"

external_ref

Your id for it, unique across your sessions

labels

Up to 20. Keys are 1 to 64 letters, digits or _ . : -; values are strings up to 200 characters. Chartnaut never reads them

The answer is 201 with the session, read as below. A bad field is 400 invalid_request with details.field naming it, such as instruments[1]. A reused external_ref is 409 conflict with the session that holds it in details.existing_id. Each user can have 10 active or locked sessions from you, and you 10,000 in all: past that, 422 partner_limit.

The session follows the user's Chartnaut plan. A day outside their plan's window or history, or a market their account can't use, is 422 plan_limit with the reason in message.

POST /sessions/batch takes up to 500 items and answers each one on its own, in order, with 200: {"data": [{"index": 0, "id": "ses_…"}, {"index": 1, "error": {"code": "not_linked", "message": "…"}}]}. A body that doesn't parse, including an unknown field in any item, refuses the whole call with 400.

Read

GET /sessions/ses_90211 returns the status, replay_time, an account with balance, equity, realized_pnl and unrealized_pnl, the open_positions, closed-trade stats, the rules and a breaches summary with the count and the newest breach. Equity values open positions at the bar close at the replay time, which is saved every few seconds while the user plays. open_positions is left out when there are none.

/sessions/{id}/trades pages through closed trades, oldest first by replay time, each with instrument, side (long or short) and realized_pnl. /sessions/{id}/breaches pages through breaches, also oldest first.

List

GET /sessions?label.event=nov-open&status=active
GET /sessions?user=ext:user-8812

Lists are newest first and hold only sessions whose user is still linked and grants sessions:read. Several labels are combined with AND.

A list item is a summary. Its account has currency, balance and realized_pnl only, with no equity, and its stats counts trades only: the other stats are zero. There are no open positions, rules or breaches. Read the session for those.

PATCH /sessions/{id} with {"labels": {…}} merges into the labels: a key with a value sets it, a key set to null is removed, and keys you leave out stay. Nothing else changes after create.

Statuses

Status

Meaning

active

Playable

locked

Frozen by you, a rule or Chartnaut

ended

Ended by you or the user

breached

A close_and_end rule fired

completed_to_target

The profit target was reached and everything was closed

The last three are final.

Lock, unlock and end

curl https://api.chartnaut.com/partner/v1/sessions/actions \
  -H "Authorization: Bearer cn_partner_live_XXXX" \
  -H "Idempotency-Key: nov-open-lock-1" \
  -H "Content-Type: application/json" \
  -d '{ "action": "lock", "labels": { "event": "nov-open" }, "expected_count": 120 }'

Name sessions by ids (up to 1,000) or by labels, not both. Acting by labels needs expected_count: if a different number match, nothing happens and you get 409 expected_count_mismatch with the real count in details.actual. With ids, an expected_count must equal the number of ids, or it is 400 invalid_request.

The answer is {"action": "lock", "matched": 120, "data": [{"id": "ses_…", "result": "done"}, …]}, with a result per session:

result

Meaning

done

This call did it. An end also gives "status": "ended"

already

It was already in that state

not_found

Not one of your sessions

not_linked

Its user unlinked or doesn't grant sessions:write

conflict

It has ended, so it can't be locked or unlocked; error says so

error

Something failed. Retry that id

  • Lock freezes the session: no orders, edits, exits or fills, stops and targets included, and the replay can't move forward. An open frame freezes too.

  • Unlock resumes exactly where it stopped.

  • End is final. An open page closes positions at its price; otherwise Chartnaut closes them at the bar close at the replay time.

end counts toward 2,000 items an hour, shared with demo account close_all. Past that, nothing happens yet: the whole request waits for Chartnaut to approve it and answers 202 with pending_action_id, matched and a message.

The same session in Chartnaut

The user can open the session in Chartnaut itself. One page drives it at a time: the other shows Continued in Chartnaut with Take back, and the frame sends session_opened_elsewhere.