Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

Interactive Brokers wrapper 🚩

License

NotificationsYou must be signed in to change notification settings

stoqey/ibkr

Repository files navigation

NPM

Run IBKR in style

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

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({...})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

3. Debug

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

Stoqey Inc


[8]ページ先頭

©2009-2025 Movatter.jp