- Notifications
You must be signed in to change notification settings - Fork13
Interactive Brokers wrapper 🚩
License
NotificationsYou must be signed in to change notification settings
stoqey/ibkr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is using @stoqey/ib IBKR client for node, via the newer IbApiNext in a simpler way.
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({...})constmyOrder={...}constplacedOrder=awaitordersManager.placeOrder(contract,myOrder);// 4. Modify orderconstmodifyOrder=awaitordersManager.placeOrder(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()
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.
About
Interactive Brokers wrapper 🚩
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published