New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@stoqey/ibkr

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoqey/ibkr

NodeJS Interactive Brokers wrapper & utilities

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-70.59%
Maintainers
1
Weekly downloads
 
Created
Source

IBKR: Interactive Brokers

NPM

Run IBKR in style

This is an event-based ibkr client for node

  • Accounts
  • Portfolios
  • Orders/Trades
  • Historical Data + Realtime price updates
  • Contracts

1. Install

npm i @stoqey/ibkr

2. Usage

Initialize

import ibkr, { AccountSummary, IBKREVENTS, IbkrEvents, HistoryData, PortFolioUpdate, getContractDetails } from '@stoqey/ibkr';

const ibkrEvents = IbkrEvents.Instance;

// 1. Async 
await ibkr({ port: IB_PORT, host: IB_HOST });

// 2. Callback
ibkr({ port: IB_PORT, host: IB_HOST }).then(started => {
  
    if(!started){
          // Error IBKR has not started
          console.log('error cannot start ibkr');
        //   Not to proceed if not connected with interactive brokers
          return process.exit(1);
    }

    // Your code here

})

Accounts, Summary e.t.c

const accountId = AccountSummary.Instance.accountSummary.AccountId;
const totalCashValue = AccountSummary.Instance.accountSummary.TotalCashValue;

Portfolios


// Get current portfolios
const portfolios = Portfolios.Instance;
const accountPortfolios = await portfolios.getPortfolios();

// Subscribe to portfolio updates
ibkrEvents.on(IBKREVENTS.PORTFOLIOS, (porfolios: PortFolioUpdate[]) => {
      // use porfolios  updates here
})

Historical Data + Realtime price updates

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

// 1. Async 
const myData = await AccountHistoryData.Instance.getHistoricalData(symbol);

// 2. raw callback events
// Requeust market data
ibkrEvents.emit(IBKREVENTS.GET_MARKET_DATA, { symbol: 'AAPL' });

// Subscribe to market data
ibkrEvents.on(IBKREVENTS.ON_MARKET_DATA, ({ symbol, marketData }) => {
    //  Use the data here
})
  • Real-time price updates
import { PriceUpdates } from '@stoqey/ibkr';

PriceUpdates.Instance; // init

// subscribe for price updates
ibkrEvents.on(IBKREVENTS.ON_PRICE_UPDATES, (priceUpdates) => {
     // use the price updates here
 });

//  Request price updates
ibkrEvents.emit(IBKREVENTS.SUBSCRIBE_PRICE_UPDATES, { symbol: 'AAPL' });

Contracts

 const contractDetails = await getContractDetails('AAPL');

Orders/Trades

import { OrderTrade, OrderStock } from '@stoqey/ibkr';

const orderTrade = OrderTrade.Instance;

const myStockOrder: OrderStock = { ... }

const placedOrder = await orderTrade.placeOrder(myStockOrder);
          

OrderStock

const stockOrderBuyOut: OrderStock = {
    symbol: symbol,
    action: "SELL",
    type: "market",
    parameters: ["1", "9999"], // 'SELL', 1, 9999,
    size: 3,
    capital: 1000,
    exitTrade: true,
    exitParams: {
        entryTime: new Date(),
        entryPrice: 0,
        exitTime: new Date(),
        exitPrice: 0
    }
}

type

  • limit ('SELL', 1, 9999) like in example above
  • market (action, quantity, transmitOrder, goodAfterTime, goodTillDate)
  • marketClose (action, quantity, price, transmitOrder)
  • stop (action, quantity, price, transmitOrder, parentId, tif)
  • stopLimit (action, quantity, limitPrice, stopPrice, transmitOrder, parentId, tif)
  • trailingStop (action, quantity, auxPrice, tif, transmitOrder, parentId)

Order events

  • Order filled
ibkrEvents.on(IBKREVENTS.ORDER_FILLED, (data) => {

});
  • Order status
ibkrEvents.on(IBKREVENTS.ORDER_STATUS, (data) => {

});
  • Open Orders updates
ibkrEvents.on(IBKREVENTS.OPEN_ORDERS, (data) => {

});

see any .test.ts file for examples

Stoqey Inc

Keywords

FAQs

Package last updated on 14 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc