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 🙏

© 2026 – Pkg Stats / Ryan Hefner

t212-sdk

v0.1.4

Published

The developer-first TypeScript SDK for Trading 212 — fully typed, zero deps, built-in rate limiting. Automate orders, positions, and portfolio data.

Readme


Why t212-sdk?

You shouldn't need to reverse-engineer HTTP quirks, guess response shapes, or babysit rate limits while building a trading bot, portfolio dashboard, or rebalance script.

t212-sdk wraps the Trading 212 Public API in a clean, typed client so you can focus on strategy — not plumbing.

| | | |---|---| | Fully typed | Orders, positions, instruments, history — autocomplete everywhere | | Zero dependencies | Native fetch. No axios, no bloat. ~15KB bundled | | Rate limits handled | Serial queue + header-aware pacing + auto-retry on 429 | | Paper & live | Flip environment: "demo" or "live" — same API surface | | Pagination built-in | One page, all pages, or async iterators — your call | | ESM + CJS | Works in Node 18+, Bun, modern bundlers |

  you  ──▶  t212-sdk  ──▶  Trading 212
            auth · queue · types
            JSON ──▶ TypeScript

Install

npm install t212-sdk
# or
pnpm add t212-sdk
# or
yarn add t212-sdk
# or
bun add t212-sdk

Quick start

60 seconds from install to your first API call.

import { T212 } from "t212-sdk";

const client = new T212({
  apiKey: process.env.T212_API_KEY!,
  apiSecret: process.env.T212_API_SECRET!,
  environment: "demo", // paper trading — swap to "live" when ready
});

// Account snapshot
const summary = await client.account.getSummary();
console.log(`Portfolio value: ${summary.totalValue} ${summary.currency}`);

// Place a fractional market order
const order = await client.orders.placeMarket({
  ticker: "AAPL_US_EQ",
  quantity: 0.1,
});
console.log(`Order ${order.id} · ${order.status}`);

Get API keys: Trading 212 app → Settings → API (Beta).
Supports Invest and Stocks ISA accounts.


Features at a glance

| | | |---|---| | account | getSummary · getInfo · getCash | | orders | list · get · placeMarket · placeLimit · placeStop · placeStopLimit · cancel | | instruments | list · exchanges · findByTicker | | positions | list | | history | paginated + *All + async iterators for orders, dividends, transactions | | history.exports | list · request |


Authentication

Trading 212 uses HTTP Basic auth:

| Option | Role | |---|---| | apiKey | Username | | apiSecret | Password | | environment | "demo"demo.trading212.com · "live"live.trading212.com |

Always test in demo first. Real money lives on live.


Orders

Positive quantity = buy. Negative = sell. Fractional shares supported.

// Limit buy — expires end of day
await client.orders.placeLimit({
  ticker: "AAPL_US_EQ",
  quantity: 1,
  limitPrice: 150,
  timeValidity: "DAY",
});

// Stop-loss sell
await client.orders.placeStop({
  ticker: "AAPL_US_EQ",
  quantity: -1,
  stopPrice: 140,
  timeValidity: "GTC",
});

// Cancel
await client.orders.cancel(orderId);

Pagination

Historical data is cursor-paginated. Pick your style:

// Single page
const page = await client.history.orders({ limit: 50 });

// Every item, all pages
const all = await client.history.ordersAll({ limit: 50 });

// Stream — memory friendly
for await (const { order, fill } of client.history.ordersItems({ limit: 50 })) {
  console.log(order.id, fill?.price);
}

Rate limits — we got you

Trading 212 rate-limits per account. t212-sdk handles it for you:

  • Requests run through a serial queue
  • Pacing follows x-ratelimit-* response headers
  • 429 responses trigger wait + automatic retry

You write business logic. The SDK stays out of the way.

import { T212Error } from "t212-sdk";

try {
  await client.orders.get(123);
} catch (error) {
  if (error instanceof T212Error && error.isRateLimited) {
    // Rare — SDK retries automatically; this is the escape hatch
  }
}

API coverage

| Resource | Methods | | --- | --- | | account | getSummary, getInfo, getCash | | orders | list, get, placeMarket, placeLimit, placeStop, placeStopLimit, cancel | | instruments | list, exchanges, findByTicker | | positions | list | | history | orders, ordersAll, ordersPages, ordersItems, dividends, dividendsAll, dividendsItems, transactions, transactionsAll, transactionsItems | | history.exports | list, request | | pies | deprecated Trading 212 endpoints |


Integration tests

Real API tests against the demo environment only — T212_ENVIRONMENT=live is ignored.

cp .env.example .env
# T212_API_KEY + T212_API_SECRET from your demo account

npm test

| Variable | Required | Default | |---|---|---| | T212_API_KEY | yes | — | | T212_API_SECRET | yes | — | | T212_TEST_TICKER | no | AAPL_US_EQ |

Write tests place a far OTM limit order and cancel it in the same run.


Requirements

  • Node.js 18+ (or any runtime with global fetch)
  • Trading 212 Invest or Stocks ISA with API access enabled

Disclaimer

This is an unofficial SDK. Not affiliated with Trading 212.
Trading involves risk. Test thoroughly in demo before going live. You are responsible for your trades.