npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

trading212

v1.0.7

Published

Trading212 unofficial api

Downloads

11

Readme

About

This module aims to utilize and expose Trading212's RESTFul API and WebSocket APIs to allow users to easily interact with the API to create for instance a custom UI, automated trading, Discord bot, or what ever

Table of Contents

  1. About
  2. Example UI App
  3. Disclaimer
  4. Installing
  5. Usage/Features
  6. Missing features
  7. Discord
  8. Donate
  9. Trading212 referral

Uiapp

For an example app which uses this API, check out my other project Trading212 UI UI

Disclaimer

This code is work in progress. I am in no way affiliated with trading212 and trading212 does not endorse this project.
Use this code at your own risk. I afford no guarantee that the code is stable or error free.

Installing

You must first have NodeJS and NPM installed

npm install trading212

alternatively

download the project source from this repo and then create a trading212 folder within your node_modules folder

Features

Setup

//Setup
//Get these values from your browser cookie at live.trading212.com (F12 -> Application -> Storage -> Cookies)
const CUSTOMER_SESSION = "ab01-cde3-f45g-6789-hijkl1337";
const TRADING212_SESSION_LIVE = "ab01-cde3-f45g-6789-hijkl1337";

//Create handle and client
const trading212Handler = require('trading212');
const trading212 = new trading212Handler('live', CUSTOMER_SESSION, TRADING212_SESSION_LIVE);

Rest

Equitydata

Get all data (name, description, ticker, company history, etc) for equities available

let result = trading212.getAvailableEquities();

Restprices

Get Bid Ask Prices

let result = trading212.getCurrentPrice(["GME_US_EQ", "AMC_US_EQ"]);

//REST api

//Get current price
trading212.getCurrentPrice(["GME_US_EQ"]);
//Listen for response
trading212.on('price', (data) => {
  //data.ticker // GME_US_EQ
  //data.bid // Bid price
  //data.ask // Ask price
});

Restbuy

Place BUY order

//Place limit buy of 5 $GME @ $50
let ticker = "GME_US_EQ";
let orderType = "LIMIT";
let stopPrice = null;
let limitPrice = "50";
let quantity = 5;
let timeValidity = "DAY";
trading212.placeOrder(ticker, orderType, stopPrice, limitPrice, quantity, timeValidity);
//If order fails
trading212.on('order-failture', (data) => {
  //Axios error
});
//If order succeeds
trading212.on('account', (data) => {
  //data.orders
  //data.positions
  //console.log(data);
});

Restsell

Place SELL order


//Place limit sell of 5 $GME @ $50
let ticker = "GME_US_EQ";
let orderType = "LIMIT";
let stopPrice = null;
let limitPrice = "50";
let quantity = -5;
let timeValidity = "DAY";
trading212.placeOrder(ticker, orderType, stopPrice, limitPrice, quantity, timeValidity);
//If order fails
trading212.on('order-failture', (data) {
  //Axios error
});
//If order succeeds
trading212.on('account', (data) => {
  //data.orders
  //data.positions
  //console.log(data);
});

Deleteorder

Delete an order using the REST API

let order = account.orders[0];//Find order
let orderId = order.orderId;
trading212.deleteOrder(orderId);
//success
trading212.on('account', (data) => {
  //account data, containing positions, orders
  console.log(data);
})
trading212.on('order-failure', (err) {
  //error object
  //console.log(err);
})

Hotlist

Get rising (falling to come) stocks

let range = 'hourly';
//let range = 'daily';
let delta = 1;//1 hour, see https://www.trading212.com/en/hotlist
trading212.getHotlist(range, delta);
trading212.on('hotlist', (period, delta, data) => {
    //do stuff
});

Websocketapi

Websocketestablished

//WebSocket
trading212.on('platform-subscribed', () => {//Trading212 WebSocket established
  //Logic for when connection is established
});

Accountevents

Listen for account events. This data contains your available cash, invested cash, open positions, orders, etc

trading212.on('account', (data) => {
  console.log(data);
})
//Todo: document data structure

Pricesubscribe

Subscribe to one (or more) symbols

let subscribeSymbols = [
  "GME_US_EQ",
  "AMC_US_EQ",
]
trading212.bulkSubscribe(subscribeSymbols);//Subscribe to price feeds for this ticker

Priceevents

Listen for price events

 //Listen for price events from trading212 websocket (must subscribe to ticker by using #bulkSubscribe
trading212.on('price', (data) => {
  console.log(data.ticker);//Symbol/Ticker for equity
  console.log(data.ask);//Asking price
  console.log(data.bid);//Bidding price
});

websocketroutes

Subscribe to websocket routes

trading212.subscribeRoute('WEBPLATFORM');//This route is subscribed automatically when the websocket is opened. Gives data such as orders complete and watchlists
trading212.subscribeRoute('ACCOUNT');//This route is subscribed automatically when the websocket is opened. Gives data for the account such as available cash, invested, positions, orders. Listen with trading212.on('account', (data) => {})
//Document more routes

Missingfeatures

Missing features

  • Market orders
  • Charting
  • Caching
  • Better internal functions (get equity/price data from cache)
  • Much more

Discord

Join the discord to make suggestions, offer help or report bugs
https://discord.gg/sgr43Yv3ue

Donate

Donate Bitcoin to help this project bc1q03vpdg8e7xq7uh9myh7dx6atfx2me94v69rah6

Referral

If don't have a Trading212 account already, you can use my referral link and we'll both get a share