@huskly/ibkr-client 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/ibkr/ibkrClient.d.ts +3 -2
- package/dist/ibkr/ibkrClient.d.ts.map +1 -1
- package/dist/ibkr/ibkrClient.js +66 -19
- package/dist/ibkr/ibkrClient.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,13 +65,16 @@ routing, and caching. Public request types are the caller contract: this package
|
|
|
65
65
|
use TypeScript and pass values accepted by those types. Provider responses remain untrusted and are
|
|
66
66
|
validated at runtime. Its broker-neutral account API includes:
|
|
67
67
|
|
|
68
|
-
- `getAccountBalances()` and `getPositions()` for account state.
|
|
68
|
+
- `getAccountBalances()` and `getPositions()` for account state. Each position carries its current
|
|
69
|
+
session's broker contract ID for exact follow-up reads. Account balances include typed
|
|
69
70
|
`margin.total`, `margin.securities`, and `margin.commodities` snapshots with IBKR's available
|
|
70
71
|
funds, buying power, excess liquidity, cushion, SMA, equity-with-loan, Reg-T, initial- and
|
|
71
72
|
maintenance-margin, full, look-ahead, and leverage values. Margin values are `null` when IBKR
|
|
72
73
|
omits or returns an invalid value; numeric zero remains `0`.
|
|
73
|
-
- `getQuotes()` and `searchInstruments()` for equity/ETF discovery and quotes.
|
|
74
|
-
|
|
74
|
+
- `getQuotes()` and `searchInstruments()` for equity/ETF discovery and quotes. Quote requests accept
|
|
75
|
+
a symbol and an optional broker ID. A broker ID reads that exact contract without symbol
|
|
76
|
+
discovery. A request without one can also resolve a complete OSI option symbol without loading
|
|
77
|
+
its option chain.
|
|
75
78
|
- `fetchTransactionHistory()` for normalized portfolio transactions.
|
|
76
79
|
- `fetchOrders()` for normalized live orders, including aggregate `WORKING`
|
|
77
80
|
matching across IBKR's active order states.
|
|
@@ -86,7 +89,9 @@ The reusable `IbkrClient` also exposes typed, read-only strategy data:
|
|
|
86
89
|
bid/ask/mid prices, delta, session volume, and open interest.
|
|
87
90
|
- `getOptionQuote(...)` resolves and prices one exact contract with the same market-data shape.
|
|
88
91
|
It uses one security-definition request after the per-underlying session search. It does not load
|
|
89
|
-
the complete option chain.
|
|
92
|
+
the complete option chain. When an exact ticker has listings in more than one market, option
|
|
93
|
+
discovery selects the one listing with `SMART` option routing. It rejects the result if `SMART`
|
|
94
|
+
does not identify one listing.
|
|
90
95
|
- `getOptionContract(conid)` maps a broker conid back to durable OSI identity.
|
|
91
96
|
|
|
92
97
|
### Broker-neutral derivative discovery
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IbkrOauth1Config } from "./oauthConfig.js";
|
|
2
|
-
import type { AccountBalances, ActiveDerivativeOrder, AuthStatus, BrokerAccountOrders, BrokerClient, BrokerInstrument, BrokerInstrumentSearchProjection, BrokerOrdersOptions, BrokerPosition, BrokerQuote, BrokerTransactionHistory, DerivativeContract, DerivativeContractQuery, DerivativeComboExecutionRequest, DerivativeComboReconciliation, DerivativeComboReconciliationRequest, DerivativeComboPreviewRequest, DerivativeComboPreviewResult, DerivativeContingentChildOrderRequest, DerivativeContingentParentOrderRequest, DerivativeDiscoveryClient, DerivativeExecutionClient, DerivativeExecution, DerivativeExecutionQuery, DerivativeMultiOrderResult, DerivativeOrderGraphLookup, DerivativeOrderGraphRequest, DerivativeOrderGraphResult, DerivativeOrderGraphWarningContinuation, DerivativeOrderCancellationResult, DerivativeOrderCancelRequest, DerivativeOrderLifecycle, DerivativeOrderLookup, DerivativeOrderSubmissionResult, DerivativeSingleOrderRequest, DerivativePreviewClient, DerivativeExpiry, DerivativeExpiryQuery, DerivativeQuote, DerivativeReferenceQuote, OptionContract, OptionMarketQuote, OptionQuoteRequest, OptionRight, PriceHistoryBar, PriceHistoryRequest, TradingDiagnostics } from "../types.js";
|
|
2
|
+
import type { AccountBalances, ActiveDerivativeOrder, AuthStatus, BrokerAccountOrders, BrokerClient, BrokerInstrument, BrokerInstrumentSearchProjection, BrokerOrdersOptions, BrokerPosition, BrokerQuote, BrokerQuoteRequest, BrokerTransactionHistory, DerivativeContract, DerivativeContractQuery, DerivativeComboExecutionRequest, DerivativeComboReconciliation, DerivativeComboReconciliationRequest, DerivativeComboPreviewRequest, DerivativeComboPreviewResult, DerivativeContingentChildOrderRequest, DerivativeContingentParentOrderRequest, DerivativeDiscoveryClient, DerivativeExecutionClient, DerivativeExecution, DerivativeExecutionQuery, DerivativeMultiOrderResult, DerivativeOrderGraphLookup, DerivativeOrderGraphRequest, DerivativeOrderGraphResult, DerivativeOrderGraphWarningContinuation, DerivativeOrderCancellationResult, DerivativeOrderCancelRequest, DerivativeOrderLifecycle, DerivativeOrderLookup, DerivativeOrderSubmissionResult, DerivativeSingleOrderRequest, DerivativePreviewClient, DerivativeExpiry, DerivativeExpiryQuery, DerivativeQuote, DerivativeReferenceQuote, OptionContract, OptionMarketQuote, OptionQuoteRequest, OptionRight, PriceHistoryBar, PriceHistoryRequest, TradingDiagnostics } from "../types.js";
|
|
3
3
|
import { type IbkrRequestSchedulerOptions, type IbkrRequestTelemetry } from "./requestScheduler.js";
|
|
4
4
|
interface IbkrRequestInput {
|
|
5
5
|
path: string;
|
|
@@ -97,7 +97,8 @@ export declare class IbkrClient implements BrokerClient, DerivativeDiscoveryClie
|
|
|
97
97
|
/** Return { conid: day P&L }. Snapshots need a warm-up call before data lands. */
|
|
98
98
|
private fetchDayPnl;
|
|
99
99
|
private normalizePosition;
|
|
100
|
-
getQuotes(
|
|
100
|
+
getQuotes(requests: readonly BrokerQuoteRequest[]): Promise<Record<string, BrokerQuote>>;
|
|
101
|
+
private fetchQuotes;
|
|
101
102
|
/** Resolve equity/ETF symbols to IBKR contracts via `trsrv/stocks`. */
|
|
102
103
|
searchInstruments(symbol: string, projection?: BrokerInstrumentSearchProjection): Promise<BrokerInstrument[]>;
|
|
103
104
|
fetchTransactionHistory(startDate: Date, endDate: Date): Promise<BrokerTransactionHistory[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ibkrClient.d.ts","sourceRoot":"","sources":["../../src/ibkr/ibkrClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAGrB,UAAU,EACV,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,gCAAgC,EAGhC,mBAAmB,EACnB,cAAc,EACd,WAAW,
|
|
1
|
+
{"version":3,"file":"ibkrClient.d.ts","sourceRoot":"","sources":["../../src/ibkr/ibkrClient.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAGrB,UAAU,EACV,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,gCAAgC,EAGhC,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,kBAAkB,EAElB,wBAAwB,EAGxB,kBAAkB,EAClB,uBAAuB,EACvB,+BAA+B,EAC/B,6BAA6B,EAC7B,oCAAoC,EACpC,6BAA6B,EAC7B,4BAA4B,EAC5B,qCAAqC,EAErC,sCAAsC,EACtC,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,EAGxB,0BAA0B,EAE1B,0BAA0B,EAE1B,2BAA2B,EAC3B,0BAA0B,EAC1B,uCAAuC,EACvC,iCAAiC,EACjC,4BAA4B,EAC5B,wBAAwB,EACxB,qBAAqB,EAErB,+BAA+B,EAC/B,4BAA4B,EAE5B,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,wBAAwB,EACxB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EAEX,eAAe,EACf,mBAAmB,EACnB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;IAUtB,6EAA6E;IAC7E,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,yEAAyE;IACzE,SAAS,CAAC,GAAG,IAAI,MAAM;IAIvB,2EAA2E;IAC3E,SAAS,CAAC,MAAM,IAAI,MAAM;IAI1B,OAAO,CAAC,cAAc;IAsDtB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,cAAc;IAmBtB,iEAAiE;cACjD,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;IAInE,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC;IAIrD,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,oBAAoB;IAiB5B,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,mBAAmB;IAqB3B,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,WAAW;CAuBpB"}
|
package/dist/ibkr/ibkrClient.js
CHANGED
|
@@ -1262,7 +1262,14 @@ export class IbkrClient {
|
|
|
1262
1262
|
async getPositions(symbol) {
|
|
1263
1263
|
const accountId = await this.getAccountId();
|
|
1264
1264
|
const rows = await this.fetchAllPositions(accountId);
|
|
1265
|
-
const
|
|
1265
|
+
for (const position of rows) {
|
|
1266
|
+
if (position.conid === undefined ||
|
|
1267
|
+
!Number.isSafeInteger(position.conid) ||
|
|
1268
|
+
position.conid <= 0) {
|
|
1269
|
+
throw new Error(`IBKR returned an invalid position contract id for ${position.contractDesc ?? "-"}`);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
const dayPnl = await this.fetchDayPnl(rows.map((position) => String(position.conid)));
|
|
1266
1273
|
let positions = rows.map((p) => this.normalizePosition(p, dayPnl));
|
|
1267
1274
|
if (symbol) {
|
|
1268
1275
|
const upper = symbol.toUpperCase();
|
|
@@ -1312,7 +1319,11 @@ export class IbkrClient {
|
|
|
1312
1319
|
const symbol = assetClass === "OPT"
|
|
1313
1320
|
? (extractOsiPositionSymbol(contractDescription) ?? contractDescription)
|
|
1314
1321
|
: contractDescription;
|
|
1322
|
+
if (p.conid === undefined || !Number.isSafeInteger(p.conid) || p.conid <= 0) {
|
|
1323
|
+
throw new Error(`IBKR returned an invalid position contract id for ${symbol}`);
|
|
1324
|
+
}
|
|
1315
1325
|
return {
|
|
1326
|
+
brokerId: String(p.conid),
|
|
1316
1327
|
symbol,
|
|
1317
1328
|
assetType: ASSET_CLASS_LABELS[assetClass] ?? (assetClass || "-"),
|
|
1318
1329
|
longQuantity: qty > 0 ? qty : 0,
|
|
@@ -1321,16 +1332,43 @@ export class IbkrClient {
|
|
|
1321
1332
|
...(p.multiplier === undefined ? {} : { multiplier: p.multiplier }),
|
|
1322
1333
|
marketPrice: toNumber(p.mktPrice),
|
|
1323
1334
|
marketValue: toNumber(p.mktValue),
|
|
1324
|
-
currentDayProfitLoss:
|
|
1335
|
+
currentDayProfitLoss: dayPnl.get(p.conid) ?? 0,
|
|
1325
1336
|
openProfitLoss: toNumber(p.unrealizedPnl),
|
|
1326
1337
|
};
|
|
1327
1338
|
}
|
|
1328
|
-
async getQuotes(
|
|
1329
|
-
const
|
|
1330
|
-
const
|
|
1331
|
-
|
|
1339
|
+
async getQuotes(requests) {
|
|
1340
|
+
const unique = new Map();
|
|
1341
|
+
for (const request of requests) {
|
|
1342
|
+
if (!request.symbol.trim())
|
|
1343
|
+
throw new Error("A quote request symbol is required");
|
|
1344
|
+
const existing = unique.get(request.symbol);
|
|
1345
|
+
if (existing !== undefined && existing.brokerId !== request.brokerId) {
|
|
1346
|
+
throw new Error(`Conflicting IBKR broker contract ids for ${request.symbol}`);
|
|
1347
|
+
}
|
|
1348
|
+
unique.set(request.symbol, request);
|
|
1349
|
+
}
|
|
1350
|
+
const contracts = await Promise.all([...unique.values()].map(async (request) => {
|
|
1351
|
+
if (request.brokerId === undefined)
|
|
1352
|
+
return this.resolveQuoteContract(request.symbol);
|
|
1353
|
+
if (!/^[1-9]\d*$/.test(request.brokerId)) {
|
|
1354
|
+
throw new Error(`Invalid IBKR broker contract id: ${request.brokerId}`);
|
|
1355
|
+
}
|
|
1356
|
+
const conid = Number(request.brokerId);
|
|
1357
|
+
if (!Number.isSafeInteger(conid) || conid <= 0) {
|
|
1358
|
+
throw new Error(`Invalid IBKR broker contract id: ${request.brokerId}`);
|
|
1359
|
+
}
|
|
1360
|
+
return {
|
|
1361
|
+
requestedSymbol: request.symbol,
|
|
1362
|
+
symbol: request.symbol,
|
|
1363
|
+
conid,
|
|
1364
|
+
};
|
|
1365
|
+
}));
|
|
1366
|
+
return this.fetchQuotes(contracts.filter((contract) => contract !== undefined));
|
|
1367
|
+
}
|
|
1368
|
+
async fetchQuotes(contracts) {
|
|
1369
|
+
if (!contracts.length)
|
|
1332
1370
|
return {};
|
|
1333
|
-
const conids =
|
|
1371
|
+
const conids = contracts.map((contract) => contract.conid).join(",");
|
|
1334
1372
|
const params = { conids, fields: QUOTE_FIELDS };
|
|
1335
1373
|
await this.req({ path: "iserver/marketdata/snapshot", params }); // warm up
|
|
1336
1374
|
await this.wait(2000);
|
|
@@ -1341,16 +1379,15 @@ export class IbkrClient {
|
|
|
1341
1379
|
const snapshotByConid = new Map(snapshots
|
|
1342
1380
|
.filter((snapshot) => snapshot.conid !== undefined)
|
|
1343
1381
|
.map((snapshot) => [snapshot.conid, snapshot]));
|
|
1344
|
-
const histories = await Promise.all(
|
|
1382
|
+
const histories = await Promise.all(contracts.map((contract) => this.fetchQuoteHistory(contract.conid)));
|
|
1345
1383
|
const quotes = {};
|
|
1346
|
-
for (const [index, contract] of
|
|
1384
|
+
for (const [index, contract] of contracts.entries()) {
|
|
1347
1385
|
const snapshot = snapshotByConid.get(contract.conid);
|
|
1348
1386
|
if (snapshot === undefined)
|
|
1349
1387
|
continue;
|
|
1350
1388
|
const history = histories[index];
|
|
1351
1389
|
const quote = this.normalizeQuote(contract, snapshot, history);
|
|
1352
1390
|
quotes[contract.requestedSymbol] = quote;
|
|
1353
|
-
quotes[contract.symbol] = quote;
|
|
1354
1391
|
}
|
|
1355
1392
|
return quotes;
|
|
1356
1393
|
}
|
|
@@ -3335,22 +3372,32 @@ export class IbkrClient {
|
|
|
3335
3372
|
return [];
|
|
3336
3373
|
}
|
|
3337
3374
|
const sections = item["sections"];
|
|
3338
|
-
if (!Array.isArray(sections)
|
|
3339
|
-
!sections.some((section) => isUnknownRecord(section) &&
|
|
3340
|
-
typeof section["secType"] === "string" &&
|
|
3341
|
-
section["secType"].trim().toUpperCase() === "OPT")) {
|
|
3375
|
+
if (!Array.isArray(sections))
|
|
3342
3376
|
return [];
|
|
3343
|
-
|
|
3377
|
+
const optionSections = sections.flatMap((section) => {
|
|
3378
|
+
if (!isUnknownRecord(section))
|
|
3379
|
+
return [];
|
|
3380
|
+
const secType = section["secType"];
|
|
3381
|
+
if (typeof secType !== "string" || secType.trim().toUpperCase() !== "OPT")
|
|
3382
|
+
return [];
|
|
3383
|
+
const exchange = section["exchange"];
|
|
3384
|
+
return [{ exchange: typeof exchange === "string" ? exchange : null }];
|
|
3385
|
+
});
|
|
3386
|
+
if (!optionSections.length)
|
|
3387
|
+
return [];
|
|
3388
|
+
const supportsSmart = optionSections.some(({ exchange }) => exchange?.split(";").some((name) => name.trim().toUpperCase() === "SMART") ?? false);
|
|
3344
3389
|
const conid = Number(item["conid"]);
|
|
3345
|
-
return Number.isSafeInteger(conid) && conid > 0 ? [{ conid, symbol }] : [];
|
|
3390
|
+
return Number.isSafeInteger(conid) && conid > 0 ? [{ conid, symbol, supportsSmart }] : [];
|
|
3346
3391
|
});
|
|
3347
3392
|
const unique = [
|
|
3348
3393
|
...new Map(candidates.map((candidate) => [candidate.conid, candidate])).values(),
|
|
3349
3394
|
];
|
|
3350
|
-
|
|
3351
|
-
|
|
3395
|
+
const smart = unique.filter((candidate) => candidate.supportsSmart);
|
|
3396
|
+
const eligible = smart.length > 0 ? smart : unique;
|
|
3397
|
+
if (eligible.length !== 1) {
|
|
3398
|
+
throw new Error(`IBKR option underlying identity is ${eligible.length ? "ambiguous" : "missing"} for ${symbol}`);
|
|
3352
3399
|
}
|
|
3353
|
-
const [underlying] =
|
|
3400
|
+
const [underlying] = eligible;
|
|
3354
3401
|
if (underlying === undefined)
|
|
3355
3402
|
throw new Error(`IBKR lost the selected underlying for ${symbol}`);
|
|
3356
3403
|
return underlying;
|