trading212-api
v1.1.0
Published
![Language Details](https://img.shields.io/github/languages/top/bennycode/trading212-api) ![License](https://img.shields.io/npm/l/trading212-api.svg) ![Package Version](https://img.shields.io/npm/v/trading212-api.svg)
Downloads
12
Readme
Trading 212 API for TypeScript
Motivation
This Trading 212 API can be used with TypeScript and comes with many useful features such as automatic reconnects and response validation.
Implemented Endpoints
- [x] Account Data
- [x] Equity Orders
- [x] Historical items
- [x] Instruments Metadata
- [x] Personal Portfolio
- [x] Pies
Features
- ✅ 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.
Usage
Installation
npm
npm install trading212-api
REST Example
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);
Development
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
Internals
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.
Contributions
Here are some best practices PRs that show how to add endpoints:
Resources
Documentation
- Docs: Trading212 API
- Forum: New Equity Trading API in Beta
- Blog: Reverse-Engineered Trading212’s Web APIs