IB@stoqey/ib
@stoqey/ib (Low-Level SDK)Getting Started

Migration Guide (1.1.x -> 1.2.x)

Upgrading @stoqey/ib from v1.1.x to v1.2.x and breaking changes handling.

Upgrading to @stoqey/ib 1.2.x

Starting with version 1.2.1, @stoqey/ib introduced an important change to align better with standard JavaScript and TypeScript conventions.


Breaking Change: Number.MAX_VALUE replaced with undefined

Background

Versions up to 1.1.x returned Number.MAX_VALUE (1.7976931348623157e+308) for values that were unavailable or omitted by TWS. This was originally done to mirror Interactive Brokers' official Java SDK interface definitions.

However, using Number.MAX_VALUE in JavaScript/TypeScript caused confusion and subtle calculation bugs. In @stoqey/ib v1.2.1+, all missing numeric values are returned as undefined instead.


Code Example Comparison

Before (v1.1.x)

In v1.1.x, you had to check whether values equaled Number.MAX_VALUE:

ib.on(EventName.pnlSingle, (reqId, pos, dailyPnL, unrealizedPnL, realizedPnL, value) => {
  if (unrealizedPnL !== Number.MAX_VALUE) {
    console.log(`Unrealized PnL: $${unrealizedPnL}`);
  }
});

After (v1.2.x+)

In v1.2.x+, signatures include optional undefined types:

ib.on(
  EventName.pnlSingle,
  (
    reqId: number,
    pos: number,
    dailyPnL: number,
    unrealizedPnL: number | undefined,
    realizedPnL: number | undefined,
    value: number
  ) => {
    if (unrealizedPnL !== undefined) {
      console.log(`Unrealized PnL: $${unrealizedPnL}`);
    }
  }
);

What you need to update

  1. Remove Number.MAX_VALUE checks: Replace any val === Number.MAX_VALUE comparisons with val === undefined or optional chaining val ?? default.
  2. Update Type Annotations: Ensure your event handler parameters allow number | undefined for PnL, price, and position metrics.

On this page