@stoqey/ibkr (High-Level Wrapper)Getting Started
Installation & Quickstart
How to install @stoqey/ibkr and initialize the client connection.
Package Installation
Install @stoqey/ibkr using your preferred Node.js package manager:
# npm
npm install @stoqey/ibkr
# yarn
yarn add @stoqey/ibkr
# pnpm
pnpm add @stoqey/ibkrInitializing @stoqey/ibkr
@stoqey/ibkr provides a single asynchronous entry point ibkr() that establishes socket connections to Interactive Brokers and initializes all cached state managers (AccountSummary, Portfolios, MarketDataManager, Orders).
Method 1: Environment Variables (Default)
Create a .env file in the root of your project:
IBKR_HOST=127.0.0.1
IBKR_PORT=7497
IBKR_CLIENT_ID=0Initialize @stoqey/ibkr in code:
import ibkr from "@stoqey/ibkr";
async function main() {
// Connects to IBKR using .env options
await ibkr();
console.log("IBKR Client Connected & Managers Initialized!");
}
main();Method 2: Programmatic Options
You can pass creation options directly to ibkr():
import ibkr from "@stoqey/ibkr";
await ibkr({
host: "127.0.0.1",
port: 7497,
clientId: 123,
reconnectInterval: 5000,
connectionWatchdogInterval: 1,
});What Happens During Initialization?
When await ibkr() resolves:
- TCP socket connection is established to TWS or IB Gateway.
AccountSummary.Instancestarts listening and caching account balances.Portfolios.Instancerequests current open positions and caches portfolio state.Orders.Instancesubscribes to live open orders and filled trade events.MarketDataManager.Instancebecomes ready for contract lookup and quote streaming.IBKREvents.Instancefires theIBKR_CONNECTEDevent.