@stoqey/ib (Low-Level SDK)Core Architecture
Contracts & Financial Instruments
Defining Contract objects for Stocks, Options, Futures, Forex, and Crypto in @stoqey/ib.
The Contract Interface
A Contract object defines financial instruments (stocks, options, futures, forex pairs, indices, etc.) to trade or retrieve market data for.
import { Contract, SecType } from "@stoqey/ib";
const appleStock: Contract = {
symbol: "AAPL",
secType: SecType.STK,
currency: "USD",
exchange: "SMART",
};Security Types (SecType)
@stoqey/ib exports the SecType enum with supported asset classes:
SecType Enum | Asset Description |
|---|---|
SecType.STK | Stock / Equity |
SecType.OPT | Options |
SecType.FUT | Futures |
SecType.IND | Index |
SecType.CASH | Forex Currency Pair |
SecType.CFD | Contract for Difference |
SecType.CRYPTO | Cryptocurrency |
SecType.BOND | Fixed Income Bond |
Contract Examples
Stock Example
const stockContract: Contract = {
symbol: "TSLA",
secType: SecType.STK,
currency: "USD",
exchange: "SMART", // SMART routing automatically picks optimal exchange
primaryExch: "NASDAQ",
};Forex Pair Example
const forexContract: Contract = {
symbol: "EUR",
secType: SecType.CASH,
currency: "USD",
exchange: "IDEALPRO",
};Stock Option Example
const optionContract: Contract = {
symbol: "AAPL",
secType: SecType.OPT,
currency: "USD",
exchange: "SMART",
lastTradeDateOrContractMonth: "20261218", // YYYYMMDD
strike: 250,
right: OptionRight.CALL, // 'C' or 'P'
multiplier: 100,
};Requesting Contract Details
To resolve full TWS details (conId, minTick, trading hours, multiplier) for ambiguous contracts, use reqContractDetails:
import { IBApi, EventName, Contract, ContractDetails } from "@stoqey/ib";
ib.on(EventName.contractDetails, (reqId: number, details: ContractDetails) => {
console.log(`Resolved ConId: ${details.contract.conId}`);
console.log(`Long Name: ${details.longName}`);
console.log(`Min Tick: ${details.minTick}`);
});
ib.reqContractDetails(1, stockContract);