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

@stoqey/ibkr

v2.5.8

Published

NodeJS Interactive Brokers wrapper & utilities using @stoqey/ib

Readme

Overview

A modern, TypeScript-based Node.js client for Interactive Brokers (IBKR) that provides a simplified interface to the IBKR API. This package is a wrapper around @stoqey/ib, which implements the official IBKR API. It offers a more developer-friendly way to interact with Interactive Brokers' trading platform, abstracting away the complexity of the underlying API.

Key Features

| | Feature | | :---: | --------------------------------------------- | | ✅ | Accounts | | ✅ | Portfolios | | ✅ | Orders | | ✅ | Historical Data | | ✅ | Realtime price updates | | ✅ | Contracts (stocks/forex/options/index .e.t.c) | | ⬜️ | Mosaic Market scanner | | ⬜️ | News |

1. Install

npm i @stoqey/ibkr

2. Usage

Create a .env in the root dir of your project, set IBKR_HOST and IBKR_PORT, IBKR_CLIENT_ID(Optional, it'll use 0 by default), and DEBUG for logs, like this

IBKR_HOST=localhost
IBKR_PORT=7497
IBKR_CLIENT_ID=123
DEBUG=ibkr* 

Initialize

import ibkr from '@stoqey/ibkr';

await ibkr();

// your code

Accounts Summary e.t.c

import { AccountSummary } from  "@stoqey/ibkr";

const accountInstance = AccountSummary.Instance;

// account summaries is automatically updated for you
const accountSummaries = accountInstance.accountSummary;

const accountId = accountSummaries.accountId;

const totalCashValue = accountSummaries.TotalCashValue.value;

Portfolios

import { Portfolios } from  "@stoqey/ibkr";
// Get current portfolios
const portfolios = Portfolios.Instance;

// positions is automatically updated for you
const accountPortfolios = portfolios.positions;

Historical Data + Realtime price updates

  • Market data
import { MarketDataManager } from '@stoqey/ibkr';

// 1. Get market data manager
const mkdManager = MarketDataManager.Instance;

// 2. Get market data async promise
const data = await mkdManager.getHistoricalData(contract, endDateTime, durationStr, barSizeSetting, whatToShow,useRTH );
  • Real-time price updates
import { MarketDataManager, IBKREvents, IBKREVENTS } from '@stoqey/ibkr';

// 1. Get IBKR events
const ibkrEvents = IBKREvents.Instance;

// 2. Get market data manager
const mkdManager = MarketDataManager.Instance;

// 3. Request historical data updates
await mkdManager.getHistoricalDataUpdates(contract,barSizeSetting, whatToShow);

// 3. Subscribe for historical data updates
ibkrEvents.on(IBKREVENTS.IBKR_BAR, (bar: MarketData) => {
     // use the historical data updates here
});

// 4. get the cached marketdata
const cachedData = await mkdManager.historicalData(contract, start, end)
// Unsubscribe from historical data updates
mkdManager.removeHistoricalDataUpdates(contract);

Contracts

import { MarketDataManager } from '@stoqey/ibkr';

// 1. Get market data manager
const mkdManager = MarketDataManager.Instance;

const contract = {
  symbol: "PLTR",
  secType: "STK"
};

const contractDetails = await mkdManager.getContract(contract);

//  or e.g options
const contractDetails = await mkdManager.getContract({
    currency: 'USD',
    exchange: 'SMART',
    multiplier: 100,
    right: 'C',
    secType: 'OPT',
    strike: 300,
    symbol: 'AAPL'
});

// e.g forex
const contractDetails = await mkdManager.getContract({
    "symbol":"GBP",
    "secType":"CASH",
    "currency":"USD",
});

Orders

import { Orders, OrderStock, IBKREvents, IBKREVENTS } from '@stoqey/ibkr';

// 1. Get IBKR events
const ibkrEvents = IBKREvents.Instance;

// 2. Get orders manager
const ordersManager = Orders.Instance;

// 3. Place order
const contract = await mkdManager.getContract({
  symbol: ticker,
  secType: "STK" /* STK, OPT, FUT, etc. */,
  exchange: "SMART" /* SMART, NYSE, NASDAQ, etc. */,
  currency: "USD"  /* USD, EUR, GBP, etc. */
})
const myOrder = {
  action, // 1. BUY, 2. SELL
  totalQuantity: quantity,
  orderType: price ? OrderType.LIMIT : OrderType.MARKET, // 1. MARKET, 2. LIMIT, 3. STOP, etc.
  ...(price && { lmtPrice: price }),
  transmit: true, // true to submit order immediately, false to save as draft
  outsideRth: false, // true to allow execution outside regular trading hours, false otherwise
  tif: "DAY", // DAY (day order), GTC (good till canceled), IOC (immediate or cancel), etc.
};

const placedOrder = await ordersManager.placeOrder(contract, myOrder);

// 4. Modify order
const modifyOrder = await ordersManager.modifyOrder(id, contract, myOrder);

// get orders, this is automatically updated
const orders = ordersManager.orders;

// get filled orders(trades), this is automatically updated
const trades = ordersManager.trades;

// subscribe for trades, when orders are filled in real time
ibkrEvents.on(IBKREVENTS.IBKR_SAVE_TRADE, (bar: Trade) => {
     // use trade here
});

// other methods e.t.c....
await ordersManager.cancelOrder(orderId)

await ordersManager.cancelAllOrders()        

Quickstart Sample App: See this API in action with our companion Sample Application. Also, see any .test.ts file for examples

3. Debug

We use debug library for logging. Run with DEBUG=ibkr:* to see all logs, or DEBUG=ibkr:info for less verbose logs.

See change log for updates

Community

Join our Discord community to get help, share ideas, and connect with other developers:

Join our Discord server

  • Get help with implementation
  • Share your projects
  • Connect with other developers
  • Stay updated on new releases
  • Contribute to discussions