IB@stoqey/ib
@stoqey/ibkr (High-Level Wrapper)Events & Event Bus

IBKREvents Central Event Bus

Listening for real-time account, portfolio, order, trade, and market data events via IBKREvents.

Overview

IBKREvents.Instance is the central event bus in @stoqey/ibkr.

Internal managers automatically handle TWS socket traffic and update local state caches. Whenever local state is updated (or a trade is executed), an event is dispatched on IBKREvents.Instance.


Event Catalog & Payloads

Event (IBKREVENTS)Payload TypeDescription
IBKR_CONNECTEDvoidEmitted when socket connects or successfully reconnects.
IBKR_ACCOUNT_UPDATED{ updatedAt: Date }Emitted when account summary values change.
IBKR_POSITIONS_UPDATED{ updatedAt: Date }Emitted when open portfolio positions change.
IBKR_OPEN_ORDERS_UPDATED{ updatedAt: Date }Emitted when active open orders change.
IBKR_COMPLETED_TRADES_UPDATED{ updatedAt: Date }Emitted when filled trades list updates.
IBKR_SAVE_TRADETradeEmitted immediately when an order fill is executed.
IBKR_BARMarketDataEmitted when real-time bar or tick-aggregated bar updates.

Code Example

import ibkr, { IBKREvents, IBKREVENTS } from "@stoqey/ibkr";
import type { MarketData, Trade } from "@stoqey/ibkr";

const ibkrEvents = IBKREvents.Instance;

// 1. Connection Event
ibkrEvents.on(IBKREVENTS.IBKR_CONNECTED, () => {
  console.log("Connected to IBKR Gateway!");
});

// 2. Real-time Trade Execution Event
ibkrEvents.on(IBKREVENTS.IBKR_SAVE_TRADE, (trade: Trade) => {
  console.log(`Trade Filled! ${trade.action} ${trade.quantity} x ${trade.instrument?.symbol} @ $${trade.price}`);
});

// 3. Real-time Market Bar Event
ibkrEvents.on(IBKREVENTS.IBKR_BAR, (bar: MarketData) => {
  console.log(`[Bar] ${bar.instrument?.symbol} Close: $${bar.close} | Vol: ${bar.volume}`);
});

await ibkr();

On this page