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.
npx @kkkermit/trading212.js doctor --env-file .envThe doctor
Section titled “The doctor”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 demoEach 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.
The account, positions and orders
Section titled “The account, positions and orders”npx trading212 summary --env-file .envnpx trading212 positionsnpx trading212 orders --jsonTicker Quantity Average price Price Value ProfitAAPL_US_EQ 2.5 230.00 230.00 575.00 0.00summary 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 helpIt 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.
Exit codes
Section titled “Exit codes”| 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 |