Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork15
A simple @stoqey/ib wrapper 🚩
License
stoqey/ibkr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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.
Feature | |
---|---|
✅ | Accounts |
✅ | Portfolios |
✅ | Orders |
✅ | Historical Data |
✅ | Realtime price updates |
✅ | Contracts (stocks/forex/options/index .e.t.c) |
⬜️ | Mosaic Market scanner |
⬜️ | News |
npm i @stoqey/ibkr
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*
importibkrfrom'@stoqey/ibkr';awaitibkr();// your code
import{AccountSummary}from"@stoqey/ibkr";constaccountInstance=AccountSummary.Instance;// account summaries is automatically updated for youconstaccountSummaries=accountInstance.accountSummary;constaccountId=accountSummaries.accountId;consttotalCashValue=accountSummaries.TotalCashValue.value;
import{Portfolios}from"@stoqey/ibkr";// Get current portfoliosconstportfolios=Portfolios.Instance;// positions is automatically updated for youconstaccountPortfolios=portfolios.positions;
- 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);
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",});
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
We usedebug library for logging.Run withDEBUG=ibkr:*
to see all logs, orDEBUG=ibkr:info
for less verbose logs.
Join our Discord community to get help, share ideas, and connect with other developers:
- Get help with implementation
- Share your projects
- Connect with other developers
- Stay updated on new releases
- Contribute to discussions
About
A simple @stoqey/ib wrapper 🚩
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.