Skip to content

FAQ and troubleshooting

No. The library works in plain JavaScript; every example has a JavaScript tab. It ships its types, so editors such as VS Code still show every option and field as you type.

Yes. Every JavaScript example in these docs is CommonJS: const { Trading212 } = require("@kkkermit/trading212.js"), with the code that waits for Trading 212 inside an async function main() { … }, because CommonJS has no top-level await. Save it as a .cjs file and run it with node.

Not directly. Trading 212 refuses requests from web pages, and a key in a page is public, so the client refuses to start in a browser. Call it from your server, such as an API route, and have the page call that.

Node 22 or later. Bun and Deno work too.

Can I try it without a Trading 212 account?

Section titled “Can I try it without a Trading 212 account?”

Yes. The fake Trading 212 is the real client talking to an in-memory account; the first steps of Getting started use it.

Trading212.fromEnv() reads T212_ENV, T212_API_KEY and T212_API_SECRET, and Node does not load .env by itself. Run with node --env-file=.env app.cjs, or set the variables in your shell or host.

Trading 212 refused the key and secret. The usual causes, in order:

  1. The key was made for the other environment: a practice-mode key works on demo only, and a real-money key on live only.
  2. The secret was pasted into apiKey, or a space was copied with it. The client catches most of these and says so.
  3. The key was deleted in the app.

npx @kkkermit/trading212.js doctor --env-file .env checks all of these at once.

The key works but lacks a permission; error.scope names it. Make a new key in the app with that permission ticked. API coverage lists which method needs which.

The client only reads, which is the default on live. Create it with trading: "enabled" once you are ready, and preview orders with { dryRun: true } first.

Trading 212 refused the order and nothing was traded. error.reason says why, and error.hint what to do: not enough cash, selling more than you can, a closed market, or more than 4 decimal places.

The order may or may not have gone through: it timed out, or the connection dropped after it was sent. Check orders.list() and history.orders.list() before trying again; the safe resend recipe shows how.

A call would have had to wait longer than maxRateLimitWaitMs (60 s by default) for its budget. Call less often, or raise the limit. Remember every program using the same account shares one budget.

The feature exists on live only; CSV exports are the expected case.

…buy an amount of money’s worth, such as £50 of Apple?

Section titled “…buy an amount of money’s worth, such as £50 of Apple?”

The API only takes a number of shares. You can work one out from a price you already know, and round it down with truncateQuantity(50 / price).

await t212.orders.sellAll("AAPL_US_EQ"). It sells what is available, leaving shares in pies alone.

Pass logger: "debug", or set T212_LOG=debug when using Trading212.fromEnv(). See Logging and hooks.

orders.waitFor(order) waits for one order. To hear about every order, including ones placed in the app, use t212.watch.orders(); see Watching the account.

Keep it in .env or your host’s secret settings, never in code, and add .env to .gitignore. Give each program its own key with only the permissions it needs, and restrict keys to fixed IP addresses where you can. If a key leaks, delete it in the app straight away.

await t212.instruments.resolve("Apple"). See Instruments and market hours.

Open an issue on GitHub with the smallest code that shows it, ideally using the fake Trading 212, and the error’s toLog() output. Never include your key or secret.