ChartnautDocs

Accounts

Two kinds of account reach your server: demo accounts you create for a user, to run a challenge or a live competition, and the user's own broker accounts, which you can read. Both are cn.accounts in @chartnaut/node, and both take ids like acc_5521.

Demo accounts you create

The user's own accounts

What they are

Chartnaut demo accounts trading live prices with simulated money

Their Chartnaut Demo account and every broker account they linked (MT4, MT5, cTrader, TradeLocker, Rithmic)

Permissions the user grants

demo_accounts:write to create and act, demo_accounts:read to read

accounts:read

You can

Create, read, lock, unlock, close everything, label

Read the balance, open positions and closed trades. Nothing else

Where the user trades

In Chartnaut, among their accounts

Wherever they trade today

All three permissions are restricted. They work in Test straight away; for Live, open your project's Permissions tab and click Request access beside each under Ask us for more. Add them to the scopes your link asks for. A user who linked before you added one links again to grant it.

Demo accounts

import { Chartnaut } from "@chartnaut/node";

const cn = new Chartnaut(); // reads CHARTNAUT_SECRET_KEY

const account = await cn.accounts.create({
  user: "ext:user-8812",
  display_name: "Live week",
  starting_balance: 25_000,
  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" },
});
console.log(account.id); // acc_…
  • Locked by default. A new account is locked until you unlock it, so a whole event opens at once. Send locked: false to open it straight away. While it's locked, the user sees it among their accounts marked Locked by your project's name.

  • Defaults: USD, a starting balance of 100,000 and leverage of 50. display_name is required, up to 64 characters.

  • Rules are the same as for backtests: daily loss, max drawdown, max position size, max open positions and profit target. See rules.

  • Limits: each user holds up to 5 active or locked accounts from you, and you 2,000 in all. Demo accounts never use the user's plan slots.

  • In batches: cn.accounts.createBatch(items) takes up to 500 and answers each one on its own.

The user trades the account in Chartnaut itself, not in the terminal on your page: in your page's terminal, orders place in backtests only.

Read them

import { Chartnaut } from "@chartnaut/node";

const cn = new Chartnaut();
const id = "acc_5521";

const live = await cn.accounts.get(id);
console.log(live.balance, live.valuation?.equity, live.positions?.length);

const { data: closed } = await cn.accounts.trades(id, { since: "2026-11-17T00:00:00Z" });
const { data: breaches } = await cn.accounts.breaches(id);
const { data: entrants } = await cn.accounts.list({ labels: { event: "live-week" } });

get has the balance, a valuation (equity, floating P&L and margin at the latest prices), the open positions, lock state, rules and a breaches summary. A list item has the balance, lock state and rules only: read each account for its equity. Trades and breaches come newest first, a page at a time.

Lock, unlock and close everything

import { Chartnaut } from "@chartnaut/node";

const cn = new Chartnaut();

const cup = { labels: { event: "live-week" }, expected_count: 120 };
await cn.accounts.unlock(cup);   // the event opens
await cn.accounts.closeAll(cup); // the event ends: locks, then closes every position at market

By labels, expected_count is required: if a different number of accounts match, nothing happens and you get 409 expected_count_mismatch, so a mistyped label can't touch the wrong accounts. Each account answers on its own: locked, unlocked, closed, closing (positions still closing, for example in a closed market: read it later), already, not_found or error.

  • Lock freezes the account. Nothing places, changes, cancels or fills. A margin stop-out still runs.

  • Unlock lets trading resume.

  • Close everything locks the account, cancels entries that haven't filled and closes the rest at market. It's safe to run twice.

When a user unlinks, the accounts you made for them lock. Full field-by-field detail: Demo accounts.

Their own broker accounts

import { Chartnaut } from "@chartnaut/node";

const cn = new Chartnaut();

const { data: accounts } = await cn.accounts.listUserAccounts("ext:user-8812");
for (const a of accounts) {
  const { data: open } = await cn.accounts.positions(a.id);
  const { data: closed } = await cn.accounts.trades(a.id, { since: "2026-11-01T00:00:00Z" });
  console.log(a.broker, a.display_name, a.balance, open.length, "open,", closed.length, "closed");
}
  • The list has each account's broker (such as chartnaut_demo, mt5 or ctrader), display_name, currency, balance, equity, starting_balance, leverage and created_at, oldest first. Accounts you created aren't in it.

  • One account: cn.accounts.getUserAccount(id).

  • Open positions: cn.accounts.positions(id), each with the instrument, the broker's own symbol, side, quantity, entry price and when it opened.

  • Closed trades: cn.accounts.trades(id), newest first, in the same shape as a demo account's.

Balances and positions are as Chartnaut last stored them from the broker. It's read only: nothing here can place, change or close anything on a user's own account. An account of someone who isn't linked to your project reads as 404 not_found; a linked user who didn't grant accounts:read is 403 scope_not_granted.

Every call above is in the API reference, with the errors it can answer.