This Trading 212 API can be used with TypeScript and comes with many useful features such as automatic reconnects and response validation.
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: