Skip to content

The command line

The package includes a trading212 command. It only ever reads: no command places or cancels an order, and none prints your key or secret.

Terminal window
npx @kkkermit/trading212.js doctor --env-file .env

doctor signs in, then tries one read for each permission and reports which are missing.

trading212.js 0.1.0 doctor
✓ settings: environment demo, key 37 characters, secret 43 characters
✓ sign in: account 12345678 (GBP) on demo
✓ portfolio: allowed
✗ history:dividends: not on this key (create one with "history:dividends" ticked)
· exports: live only
· orders:execute: not checked: it would need a real order
✓ trading: orders can be placed on demo

Each check is marked ✓ (passed), ✗ (failed or missing), ⚠ (a warning) or · (skipped). --json prints { version, ok, checks } instead, where each check is { name, status, detail }, for scripts.

Terminal window
npx trading212 summary --env-file .env
npx trading212 positions
npx trading212 orders --json
Ticker Quantity Average price Price Value Profit
AAPL_US_EQ 2.5 230.00 230.00 575.00 0.00

summary shows the account’s cash, value and profit, positions the open positions, and orders the orders still working. With --json, each prints exactly what Trading 212 returned, for scripts. They use a client with trading off, so they cannot trade even on demo.

trading212 <command> [options]
Commands:
doctor Check your API key, environment and permissions
summary Show the account's cash, value and profit
positions List open positions
orders List pending orders
version Print the version
Options:
--env <name> demo or live (overrides T212_ENV; demo when neither is set)
--env-file <path> Load variables from a file first, such as .env
--json Print the result as JSON
-h, --help Show this help

It reads T212_ENV, T212_API_KEY and T212_API_SECRET, or T212_DEMO_* and T212_LIVE_*; see Configuration. With neither --env nor T212_ENV, it uses demo. Variables already set in your shell win over the file, and the file never changes the process’s environment. T212_LOG=debug writes the client’s log lines to stderr, so --json output stays clean.

With the package installed in a project, npx trading212 doctor runs the same command.

Code Means
0 It worked; for the doctor, even if a permission is missing
1 The settings are wrong, the key does not sign in, or a read failed
2 The command was used wrongly: no command, an unknown one, or a bad option