trading212-api

Trading 212 API for TypeScript

Language Details License Package Version


This Trading 212 API can be used with TypeScript and comes with many useful features such as automatic reconnects and response validation.

  • Documented. Get started with demo scripts and generated documentation.
  • Maintained. Automated security updates. No threats from outdated dependencies.
  • Modern. HTTP client with Promise API. Don't lose yourself in callback hell.
  • Reliable. Follows semantic versioning. Get notified about breaking changes.
  • Robust. Automatic requests retries are built-in. No problems if your Wi-Fi is gone.
  • Tested. Unit test coverage to guarantee core functionaly.
  • Typed. Source code is 100% TypeScript. No need to install external typings.

npm

npm install trading212-api

The demo section provides many examples on how to use "trading212-api". There is also an automatically generated API documentation. For a quick start, here is a simple example for a REST request:

import {APIClient} from 'trading212-api';

const baseURL = APIClient.URL_LIVE;
const client = new APIClient(baseURL, 'apiKey');

const info = await client.rest.account.getInfo();
console.log(info);

If cloning the project locally, you can also add a .env file to configure the API client (see .env.defaults). This allows you to run all demo scripts.

Example

npm run demo:account

This library utilizes axios for HTTP calls. You can configure the axios instance using interceptors if needed. Retries are handled by axios-retry, and payloads are validated with Zod. Unit tests are implemented with nock.

Here are some best practices PRs that show how to add endpoints: