The terminal object
The terminal object is what <Terminal>'s useTerminal() gives you, and what createTerminal() returns without React. Everything else hangs off it: terminal.chart(id), terminal.orders, terminal.replay and the rest.
Without React
import { createTerminal } from "@chartnaut/charts";
const terminal = createTerminal(document.getElementById("terminal")!, {
charts: { main: { symbol: "NAS100", timeframe: "15m" } },
timezone: "America/New_York",
});
terminal.chart("main").setTimeframe("1h"); // waits until the terminal is ready
terminal.on("session_ended", (e) => console.log("Session over:", e.data.status));It takes the same options as <Terminal>'s props. With no frameUrl or getFrameUrl it asks your server at /api/chartnaut/frame. Without a bundler, load it from a script tag: <script src="https://terminal.chartnaut.com/embed.js"></script> puts Chartnaut.createTerminal on window.
Ready and status
import { createTerminal } from "@chartnaut/charts";
const terminal = createTerminal(document.getElementById("terminal")!, {});
terminal.subscribe((s) => console.log(s.status, s.reason ?? ""));
terminal.ready.then((ready) => console.log("Session", ready.session_id));terminal.status is { status, ready, settled, reason }. It starts at booting and becomes ready once the terminal is open, or refused with a reason. terminal.ready is a promise for the same moment.
Calls made before ready are held and sent once it is, for up to 30 seconds (readyTimeoutMs), then they fail with not_ready.
Events
on returns a function that stops listening. once hears the next one only. off(type) stops every listener of that type.
import { createTerminal } from "@chartnaut/charts";
const terminal = createTerminal(document.getElementById("terminal")!, {});
const off = terminal.on("symbol_changed", (e) => {
if (e.data.cause === "command") return; // an echo of your own setSymbol
console.log(`${e.data.chart_id} now shows ${e.data.symbol}`);
});
terminal.once("ready", () => console.log("Open"));
terminal.on("*", (e) => console.log(e.type));
off();Every change event carries cause: user (the person did it), command (your code), link (a linked chart followed another) or upgrade. Every event carries seq and event_id, and time in unix seconds: replay time in a backtest.
Events are hints for your interface. For anything that matters, such as prizes or payouts, read the facts from your server with @chartnaut/node.
The handles have events on the thing they're about, with camelCase names: chart.on("symbolChange"), script.on("event"), position.on("pnl"). The global names are the wire's, in snake_case.
Raw commands
Every command the terminal takes is one send away, typed for the ones the SDK knows:
import { ChartnautCommandError, createTerminal } from "@chartnaut/charts";
const terminal = createTerminal(document.getElementById("terminal")!, {
charts: { main: { symbol: "NAS100", timeframe: "15m" } },
});
async function onlyTheTradesPanel() {
try {
await terminal.send("open_panel", { panel: "trades" });
} catch (e) {
if (e instanceof ChartnautCommandError && e.is("notAllowed")) console.log(e.reason, e.message);
}
}
onlyTheTradesPanel();The commands this terminal takes are in ready.commands. A command it refuses with rate_limited, and a read it refuses with not_ready while the session loads, are sent again for up to 15 seconds. Pass { retry: false } as the third argument to get the first refusal. Reads wait 5 seconds for a reply, orders and closes 20, close_all 30.
What the user may do: can
import { createTerminal } from "@chartnaut/charts";
const terminal = createTerminal(document.getElementById("terminal")!, {});
terminal.ready.then(() => {
const orders = terminal.can("orders.place");
if (!orders.yes) console.log("No orders here:", orders.reason);
console.log("Order flow:", terminal.can("features.order_flow").yes);
});can answers from the capabilities the terminal sent on ready and updates when they change (capabilities_changed): the mode, the session, the user's plan, the scopes they granted and the features they have.
Many changes as one: apply
import { createTerminal } from "@chartnaut/charts";
const terminal = createTerminal(document.getElementById("terminal")!, {});
terminal.apply({
layout: "2h",
charts: { main: { symbol: "EURUSD", timeframe: "15m" }, htf: { symbol: "EURUSD", timeframe: "4h" } },
appearance: { preset: "Chalk" },
}).then((r) => r.warnings.forEach((w) => console.warn(w.path, w.message)));The layout, every chart's change, the appearance and the interface land as one change, each chart loading once. Parts that couldn't apply come back in warnings; the rest applies.
Dev mode
dev: true logs every command, reply and event, names options the terminal ignored, adds a fix line to each error, and warns when the terminal's parent has no height. Turn it off in production.
The rest of the object
Property | What it is | Page |
|---|---|---|
| Charts, the layout, link groups and the look | |
| Every script on every chart | |
| Market data | |
| Backtests | |
| The saved setup | |
| Chartnaut's Trades panel over the charts | |
| Load another address, or take the terminal off the page |
