ChartnautDocs

Chartnaut Partner API

Link your users' Chartnaut accounts, run backtest sessions and demo accounts for them, and embed Chartnaut in your site

Base URL and keys#

Base URL
https://api.chartnaut.com/partner/v1
Authentication
Authorization: Bearer $CHARTNAUT_SECRET_KEY
Version
1.0.0 · OpenAPI 3.1.0

The partner API. The regional hosts (eu-api.chartnaut.com, us-api.chartnaut.com) answer every call too. Link and frame-token answers carry an api_host; it is already inside frame_url, so you don't need to use it.

A secret key: cn_partner_test_… (Test) or cn_partner_live_… (Live), made on your project's Keys tab (Developers). Shown once, stored hashed. Server-side only: never in a browser, an app or a frame URL. Rotate by creating a new key, switching, then revoking the old one (both work in between). Authorization: Bearer cn_partner_live_….

The partner API is for companies that put Chartnaut inside their own product. Your server calls it with a secret partner key; your users link their own Chartnaut account to their account on your site, and you act for them within the scopes they granted.

Design rules:

  • Primitives, not products. We have backtest sessions and demo accounts. You create them for your users, attach labels, list by label and run bulk actions. Competitions, groups, leaderboards and scheduling are yours.
  • Reads are the truth; webhooks are hints. Every fact has a GET. Webhooks carry an event type and ids only, at least once, in no guaranteed order. The frame's postMessage events are hints too.
  • Ids carry a type prefix, so one kind can never be passed where another is meant: usr_42 (a Chartnaut user), ses_42 (a backtest session), acc_42 (a demo or linked account), brk_42 (a rule breach), alr_42 (an alert), alf_42 (an alert fire). Positions and orders inside a session or account are plain integers. Wherever a user is named you may instead use your own ref: ext:<external_user_ref> (URL-encode it in a path).
  • Every POST takes an Idempotency-Key (required). A retry with the same key, path and body within 24 hours returns the first response with Idempotent-Replayed: true; the same key with a different path or body is 422 idempotency_key_reused. PUT, PATCH and DELETE take no key.
  • Lists are cursor-paged. Pass next_cursor back as cursor; null means the last page. A full page always has a next_cursor, so the page after it can be empty. limit defaults to 50 (100 for trades, breaches and alert fires) and is capped at your page_size limit (200; never more than 500); a larger limit is cut to it, not refused. Cursors mark the last row you were given, not a position, so a page deep into a long history (a user with tens of thousands of trades) costs what the first does, and rows added while you page neither repeat nor go missing. A cursor belongs to the list that gave it: one from another list, or one you made up, is 400 invalid_request with details.field: "cursor". Lists never return more than a page; GET /scripts (an app holds at most 500 scripts) is answered whole.
  • Rate-limit headers (RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset) are on every response to a request whose key checked out. A 401, the 403 switched_off when the whole API is off for you, and the 429 for too many bad keys from one IP carry none. A 429 also carries Retry-After.
  • Money is a decimal number in the account's currency (USD today), at most two decimal places. Rules are checked in whole cents.
  • List order differs by list; each one says which. GET /sessions and GET /accounts are newest first; GET /users and alert fires are oldest first.
  • Unknown body fields are refused (400 invalid_request, with the field named in message, not in details).
  • Environments. Every object belongs to live or test; a key only sees its own environment. Only live exists today (cn_partner_live_… keys).
  • Users' plans apply to sessions. A session you create for a user follows that user's Chartnaut plan (date window, history, futures access). A refusal is 422 plan_limit with the reason. Demo accounts don't use the plan.

Scopes

Scope Shown to the user as
frame:instant Open Chartnaut inside <partner> without signing in each time
sessions:write Create backtests for you, and end, lock or unlock them
sessions:read See those backtests: trades, profit and loss, and rule breaks
demo_accounts:write Create demo accounts for you; lock, unlock and close them
demo_accounts:read See those demo accounts: balance, positions, trades, breaches
accounts:read See your connected broker accounts: balances, positions and trades
alerts:read See when your Chartnaut alerts go off
terminal:read See what you do in <partner>'s Chartnaut: your charts, scripts, drawings, watchlists and backtest trades
terminal:write Change your charts, scripts, drawings and watchlists, and place orders in your own backtests
frame:live Show you live Chartnaut charts inside <partner>

A call that needs a scope the user did not grant is 403 scope_not_granted with details.scope naming it. A user who isn't linked is 404 not_linked.

Sessions and demo accounts share most conventions: batch create answers per item, PATCH merges labels, trades use instrument and realized_pnl, breaches give limit and value in money, units or count. Known differences between the two (as built, 2026-11-18):

Sessions Demo accounts
Label keys 1–64 of A–Z a–z 0–9 _ . : - 1–40 of a–z 0–9 _ . -, starting with a letter or digit
Label values up to 200 characters up to 100 bytes
Trades and breaches lists oldest first newest first
side long, short Long, Short
Breach summary on a single read {count, last} (the newest breach) {count, latest_at}
Bulk action results done, already, not_found, not_linked, conflict, error locked, unlocked, closed, closing, already, not_found, error
A user who no longer grants the write scope, in a bulk action not_linked not_found (by labels: left out)
expected_count with ids 400 unless it equals the number of ids 409 expected_count_mismatch unless it equals the number found
Bulk 200 body {action, matched, data} {data}
Over the hourly ceiling (202) {pending_action_id, matched, message} {pending_action_id}
Trades since filter no yes

The frame

The frame is Chartnaut's own backtest screen in an iframe on your page. Two ways in:

  • First time (or no frame token): render frame_url from POST /links. The frame shows "Sign in with Chartnaut"; the user signs in in a new window on terminal.chartnaut.com, ticks the scopes and approves. The frame then opens on its own.
  • Every later open: get a frame token (POST /users/{user}/frame-token, needs frame:instant; valid 24 hours, the same token while it has over an hour left, so cache it) and render the frame_url it returns: https://terminal.chartnaut.com/embed/<partner>?api=<api_host>[&session=ses_…]#ft=<frame_token>. The token sits in the #fragment, so it never reaches a server log or a referrer. api points the frame at the user's own regional API host; render frame_url as given.

The iframe needs allow="clipboard-write; fullscreen". Only your registered frame origins may host it (frame-ancestors). Phones are not supported: the frame says so and posts device_unsupported. The script at https://terminal.chartnaut.com/embed.js does all of this: Chartnaut.embed(el, { frameUrl }), or Chartnaut.embed(el, { frameToken, partner, session }) (that form builds the address without api, so the frame falls back to the API host it last signed in on, else the default).

Events the frame posts to your page (hints)

The frame posts to window.parent once per registered origin, never with "*". Check event.origin === "https://terminal.chartnaut.com", event.source === iframe.contentWindow and event.data.source === "chartnaut". Every message has one shape (components.schemas.FrameEvent): { "source": "chartnaut", "type": "<event>", ...fields }, e.g. { "source": "chartnaut", "type": "fill", "session_id": "ses_42", "position_id": 7, "order_id": 9 }. They can be missed or repeated: read the session with GET /sessions/{id}. With embed.js: frame.on('fill', fn) calls fn({ type, data }), where data is the message without source and type.

Two pages post events. The sign-in page (/embed/<partner>) posts needs_link, signed_in, device_unsupported and its own error, each with session_id when the address named one. Once the session is open, the backtest screen posts the rest.

type When Fields
needs_link no usable frame token and no link (or the link can't be used): make a new link session_id?
signed_in the user approved in the window and the frame signed in session_id?
ready the session is open in the frame session_id
fill an order filled (entry, stop, target) session_id, position_id, order_id (each id an integer or null)
order an order was created, moved or cancelled session_id, position_id, order_id, change (created, price_changed, cancelled)
close a position closed, all or part session_id, position_id, partial
account balance or equity moved (at most once a second) session_id, at (replay time, unix seconds)
breach a rule breach the server recorded session_id, breach_id (brk_…, or null), rule_type, action, at (the bar's replay time, ISO 8601)
session_end the session ended session_id, status (ended, breached, completed_to_target)
locked / unlocked you locked or unlocked it session_id
continued_elsewhere another page (e.g. Chartnaut itself) took the session over session_id
error from the sign-in page the frame can't sign in here session_id?; code only when the browser can't hold the frame's sign-in: partitioned_unsupported (Safari before 26.2) or cookie_not_stored. Other sign-in-page errors (frames paused for you, another Chartnaut account already signed in to the frame, a refused token) carry no code
error from the backtest screen the frame stopped reason: signed_out (get a new frame token), wrong_mode, before_history, invalid_session, no_access or error
device_unsupported opened on a phone session_id?

Webhooks (hints)

See webhooks below. Every delivery is POST JSON to your endpoint with Chartnaut-Signature: t=<unix seconds>,v1=<hex>, Chartnaut-Event-Id: evt_… and Chartnaut-Event-Type: <type>. v1 is HMAC-SHA256 of "<t>.<raw body>" with the endpoint's signing secret, hex-encoded. While a secret is being rotated the header carries a second v1= signed with the previous secret; accept either. Reject a t more than 5 minutes from your clock. Answer 2xx within 10 seconds. Anything else is retried up to 24 attempts, waiting 30 seconds and doubling to at most 12 hours between them (about a week in all), then marked dead (resend from the portal). Deduplicate on id.

Errors#

Error. Every response to a request whose key checked out, errors included, carries RateLimit-Limit (requests a minute), RateLimit-Remaining and RateLimit-Reset (seconds until the minute resets). A 401, the 403 switched_off when the whole API is off for you, and the 429 for too many bad keys from one IP come before that check and carry none. A 429 also carries Retry-After (seconds).

Headers

RateLimit-Limitinteger
RateLimit-Remaininginteger
RateLimit-Resetinteger
Retry-Afterinteger

Body

object · Error
errorobject · ErrorBodyRequired
Show fields
codestringRequired

Stable. Branch on this, never on message.

Code Status Meaning
unauthorized 401 missing, unknown or revoked key (no RateLimit headers)
scope_not_granted 403 the user didn't grant details.scope
forbidden 403 your partner account isn't allowed this (details.reason, e.g. no_access for frame:live when live mode isn't enabled for you; details.scope)
permission_denied 403 this key lacks the key permission the call needs (details.permission, e.g. users:export; details.reason: "key_permission"): use a key that has it, or add it in the partner portal
not_managed 409 the call is for managed users only, and this user is linked (their own Chartnaut account and plan apply; details.reason: "not_managed")
switched_off 403 this part of the API is paused for you (everything, writes, frames, links, demo account creation, bulk actions); contact [email protected]
not_linked 404 the user isn't linked to you (details.user when the user was named in the request)
not_found 404 no such object for you; an id of the wrong type or shape is this too
conflict 409 external_ref already used (sessions: details.existing_id; accounts: details.field); the same Idempotency-Key still running; lock or unlock on an ended session
expected_count_mismatch 409 a bulk action matched a different number (details.expected, details.actual)
invalid_request 400 malformed body or unknown field (named in message, no details), a bad field (details.field where the endpoint names it), bad id, missing Idempotency-Key, invalid rules. Also 413 for a body over 2 MiB
idempotency_key_reused 422 the Idempotency-Key was used with a different path or body
plan_limit 422 / 403 the user's Chartnaut plan doesn't allow it (details.reason), or your developer plan's cap (details.owner: "developer", details.limit: apps (an app past your plan's count after a downgrade takes no new users), free_linked, managed_users, data; with used, cap). No auto top-up: upgrade on the Developers page
seat_limit 403 your Business seats are full this month (details.limit seats or pro_seats, used, cap): a new managed user can't start until you add seats; users active this month carry on
partner_limit 422 one of your partner limits (details.limit, and for demo accounts details.max)
rate_limited 429 your rate limit: details.limit is rate_minute or rate_burst. Also, with no details and Retry-After: 60, any call from an IP that sent 30 bad keys this minute, good keys included. See Retry-After
internal 500 retry; if it persists contact [email protected]
One of unauthorized scope_not_granted forbidden permission_denied not_managed not_linked plan_limit seat_limit partner_limit not_found conflict expected_count_mismatch rate_limited idempotency_key_reused switched_off invalid_request internal
messagestringRequired
detailsobject

Pagination#

cursorstring

Opaque cursor from a previous page's next_cursor on the same list. Anything else is 400 invalid_request.

limitinteger

Items a page. Above your page_size limit (200) it is cut to it; zero, negative or not a number means the default.

Default 501 to 200

A page carries

object · Page
next_cursorstringRequiredNullable

Idempotency#

Idempotency-Key header, required where listed

Required on every POST (400 invalid_request without it): any unique string of 1–255 visible ASCII characters (a UUID is ideal). Keys are per environment. A retry with the same key, path and body within 24 hours returns the first response with Idempotent-Replayed: true and runs nothing. The same key with a different path or body is 422 idempotency_key_reused; while the first request is still running, 409 conflict. 5xx and 429 answers are not stored, so a retry with the same key runs again.

Endpoints#

Links

Start linking a user's Chartnaut account to your user.

Webhooks

Test deliveries. Add endpoints and see their secrets on your project's Webhooks tab (Developers).