Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple @stoqey/ib wrapper 🚩

License

NotificationsYou must be signed in to change notification settings

stoqey/ibkr

Repository files navigation

Join Stoqey #welcomeNPM

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, setIBKR_HOST andIBKR_PORT,IBKR_CLIENT_ID(Optional, it'll use 0 by default), andDEBUG for logs, like this

IBKR_HOST=localhostIBKR_PORT=7497IBKR_CLIENT_ID=123DEBUG=ibkr*

Initialize

importibkrfrom'@stoqey/ibkr';awaitibkr();// your code

Accounts Summary e.t.c

import{AccountSummary}from"@stoqey/ibkr";constaccountInstance=AccountSummary.Instance;// account summaries is automatically updated for youconstaccountSummaries=accountInstance.accountSummary;constaccountId=accountSummaries.accountId;consttotalCashValue=accountSummaries.TotalCashValue.value;

Portfolios

import{Portfolios}from"@stoqey/ibkr";// Get current portfoliosconstportfolios=Portfolios.Instance;// positions is automatically updated for youconstaccountPortfolios=portfolios.positions;

Historical Data + Realtime price updates

  • Market data
import{MarketDataManager}from'@stoqey/ibkr';// 1. Get market data managerconstmkdManager=MarketDataManager.Instance;// 2. Get market data async promiseconstdata=awaitmkdManager.getHistoricalData(contract,endDateTime,durationStr,barSizeSetting,whatToShow,useRTH);
  • Real-time price updates
import{MarketDataManager,IBKREvents,IBKREVENTS}from'@stoqey/ibkr';// 1. Get IBKR eventsconstibkrEvents=IBKREvents.Instance;// 2. Get market data managerconstmkdManager=MarketDataManager.Instance;// 3. Request historical data updatesawaitmkdManager.getHistoricalDataUpdates(contract,barSizeSetting,whatToShow);// 3. Subscribe for historical data updatesibkrEvents.on(IBKREVENTS.IBKR_BAR,(bar:MarketData)=>{// use the historical data updates here});// 4. get the cached marketdataconstcachedData=awaitmkdManager.historicalData(contract,start,end)
// Unsubscribe from historical data updatesmkdManager.removeHistoricalDataUpdates(contract);

Contracts

import{MarketDataManager}from'@stoqey/ibkr';// 1. Get market data managerconstmkdManager=MarketDataManager.Instance;constcontract={symbol:"PLTR",secType:"STK"};constcontractDetails=awaitmkdManager.getContract(contract);//  or e.g optionsconstcontractDetails=awaitmkdManager.getContract({currency:'USD',exchange:'SMART',multiplier:100,right:'C',secType:'OPT',strike:300,symbol:'AAPL'});// e.g forexconstcontractDetails=awaitmkdManager.getContract({"symbol":"GBP","secType":"CASH","currency":"USD",});

Orders

import{Orders,OrderStock,IBKREvents,IBKREVENTS}from'@stoqey/ibkr';// 1. Get IBKR eventsconstibkrEvents=IBKREvents.Instance;// 2. Get orders managerconstordersManager=Orders.Instance;// 3. Place orderconstcontract=awaitmkdManager.getContract({symbol:ticker,secType:"STK"/* STK, OPT, FUT, etc. */,exchange:"SMART"/* SMART, NYSE, NASDAQ, etc. */,currency:"USD"/* USD, EUR, GBP, etc. */})constmyOrder={  action,// 1. BUY, 2. SELLtotalQuantity: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 draftoutsideRth:false,// true to allow execution outside regular trading hours, false otherwisetif:"DAY",// DAY (day order), GTC (good till canceled), IOC (immediate or cancel), etc.};constplacedOrder=awaitordersManager.placeOrder(contract,myOrder);// 4. Modify orderconstmodifyOrder=awaitordersManager.modifyOrder(id,contract,myOrder);// get orders, this is automatically updatedconstorders=ordersManager.orders;// get filled orders(trades), this is automatically updatedconsttrades=ordersManager.trades;// subscribe for trades, when orders are filled in real timeibkrEvents.on(IBKREVENTS.IBKR_SAVE_TRADE,(bar:Trade)=>{// use trade here});// other methods e.t.c....awaitordersManager.cancelOrder(orderId)awaitordersManager.cancelAllOrders()

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

3. Debug

We usedebug library for logging.Run withDEBUG=ibkr:* to see all logs, orDEBUG=ibkr:info for less verbose logs.

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

Stoqey Inc

Sponsor this project

  •  
  •  

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp