@stoqey/ib 1.3.6 → 1.3.7
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/dist/api/api.d.ts +16 -3
- package/dist/api/api.js +13 -2
- package/dist/api/api.js.map +1 -1
- package/dist/api/contract/cfd.js +2 -3
- package/dist/api/contract/cfd.js.map +1 -1
- package/dist/api/contract/combo.js +2 -3
- package/dist/api/contract/combo.js.map +1 -1
- package/dist/api/contract/fop.js +3 -4
- package/dist/api/contract/fop.js.map +1 -1
- package/dist/api/contract/ind.js +2 -3
- package/dist/api/contract/ind.js.map +1 -1
- package/dist/api/contract/option.js +2 -3
- package/dist/api/contract/option.js.map +1 -1
- package/dist/api/contract/stock.js +2 -3
- package/dist/api/contract/stock.js.map +1 -1
- package/dist/api/data/enum/event-name.d.ts +3 -1
- package/dist/api/data/enum/event-name.js +2 -0
- package/dist/api/data/enum/event-name.js.map +1 -1
- package/dist/api/data/enum/min-server-version.js +3 -2
- package/dist/api/data/enum/min-server-version.js.map +1 -1
- package/dist/api/order/market.js +3 -4
- package/dist/api/order/market.js.map +1 -1
- package/dist/api/order/stop.js +3 -4
- package/dist/api/order/stop.js.map +1 -1
- package/dist/api/order/stopLimit.js +3 -4
- package/dist/api/order/stopLimit.js.map +1 -1
- package/dist/api/order/trailingStop.js +3 -4
- package/dist/api/order/trailingStop.js.map +1 -1
- package/dist/api-next/api-next.d.ts +8 -2
- package/dist/api-next/api-next.js +115 -80
- package/dist/api-next/api-next.js.map +1 -1
- package/dist/api-next/common/error.d.ts +2 -0
- package/dist/common/configuration.js +4 -1
- package/dist/common/configuration.js.map +1 -1
- package/dist/common/errorCode.js +3 -2
- package/dist/common/errorCode.js.map +1 -1
- package/dist/common/logger.js +10 -7
- package/dist/common/logger.js.map +1 -1
- package/dist/core/api-next/auto-connection.js +2 -2
- package/dist/core/api-next/auto-connection.js.map +1 -1
- package/dist/core/api-next/subscription-registry.js +1 -2
- package/dist/core/api-next/subscription-registry.js.map +1 -1
- package/dist/core/api-next/subscription.js +1 -2
- package/dist/core/api-next/subscription.js.map +1 -1
- package/dist/core/io/controller.js +4 -6
- package/dist/core/io/controller.js.map +1 -1
- package/dist/core/io/decoder.d.ts +9 -5
- package/dist/core/io/decoder.js +38 -22
- package/dist/core/io/decoder.js.map +1 -1
- package/dist/core/io/encoder.d.ts +1 -0
- package/dist/core/io/encoder.js +31 -27
- package/dist/core/io/encoder.js.map +1 -1
- package/dist/core/io/enum/in-msg-id.d.ts +2 -1
- package/dist/core/io/enum/in-msg-id.js +1 -0
- package/dist/core/io/enum/in-msg-id.js.map +1 -1
- package/dist/core/io/socket.js +15 -15
- package/dist/core/io/socket.js.map +1 -1
- package/dist/tests/unit/api/api.test.js +31 -54
- package/dist/tests/unit/api/api.test.js.map +1 -1
- package/dist/tests/unit/api/connect.test.js +40 -14
- package/dist/tests/unit/api/connect.test.js.map +1 -1
- package/dist/tests/unit/api/market-data.test.d.ts +1 -0
- package/dist/tests/unit/api/market-data.test.js +84 -0
- package/dist/tests/unit/api/market-data.test.js.map +1 -0
- package/dist/tests/unit/api/order/placeOrder.test.js +91 -24
- package/dist/tests/unit/api/order/placeOrder.test.js.map +1 -1
- package/dist/tests/unit/api/order/reqAllOpenOrders.test.js +22 -23
- package/dist/tests/unit/api/order/reqAllOpenOrders.test.js.map +1 -1
- package/dist/tests/unit/api-next/get-account-summary.test.js +21 -24
- package/dist/tests/unit/api-next/get-account-summary.test.js.map +1 -1
- package/dist/tests/unit/api-next/get-contract-details.test.js +1 -1
- package/dist/tests/unit/api-next/get-contract-details.test.js.map +1 -1
- package/dist/tests/unit/api-next/get-market-data.test.js +1 -1
- package/dist/tests/unit/api-next/get-market-data.test.js.map +1 -1
- package/dist/tests/unit/api-next/get-positions.test.js +8 -9
- package/dist/tests/unit/api-next/get-positions.test.js.map +1 -1
- package/dist/tests/unit/api-next/place-order.test.js +3 -3
- package/dist/tests/unit/api-next/place-order.test.js.map +1 -1
- package/dist/tools/account-summary.js +2 -4
- package/dist/tools/account-summary.js.map +1 -1
- package/dist/tools/common/ib-api-next-app.d.ts +4 -0
- package/dist/tools/common/ib-api-next-app.js +43 -12
- package/dist/tools/common/ib-api-next-app.js.map +1 -1
- package/dist/tools/contract-details.js +2 -26
- package/dist/tools/contract-details.js.map +1 -1
- package/dist/tools/get-head-timestamp.js +2 -26
- package/dist/tools/get-head-timestamp.js.map +1 -1
- package/dist/tools/historical-data-updates.js +1 -2
- package/dist/tools/historical-data-updates.js.map +1 -1
- package/dist/tools/historical-ticks-bid-ask.js +1 -2
- package/dist/tools/historical-ticks-bid-ask.js.map +1 -1
- package/dist/tools/historical-ticks-last.js +2 -4
- package/dist/tools/historical-ticks-last.js.map +1 -1
- package/dist/tools/historical-ticks-mid.js +1 -2
- package/dist/tools/historical-ticks-mid.js.map +1 -1
- package/dist/tools/{market-data-single.js → market-data-snapshot.js} +9 -35
- package/dist/tools/market-data-snapshot.js.map +1 -0
- package/dist/tools/market-data.js +7 -40
- package/dist/tools/market-data.js.map +1 -1
- package/dist/tools/market-depth.js +2 -4
- package/dist/tools/market-depth.js.map +1 -1
- package/dist/tools/modify-order.js +1 -2
- package/dist/tools/modify-order.js.map +1 -1
- package/dist/tools/open-orders-auto.js +1 -2
- package/dist/tools/open-orders-auto.js.map +1 -1
- package/dist/tools/open-orders.js +4 -2
- package/dist/tools/open-orders.js.map +1 -1
- package/dist/tools/place-order.d.ts +1 -1
- package/dist/tools/place-order.js +23 -19
- package/dist/tools/place-order.js.map +1 -1
- package/dist/tools/pnl-single.js +1 -2
- package/dist/tools/pnl-single.js.map +1 -1
- package/dist/tools/pnl.js +1 -2
- package/dist/tools/pnl.js.map +1 -1
- package/dist/tools/positions.js +1 -2
- package/dist/tools/positions.js.map +1 -1
- package/dist/tools/sec-def-opt-params.js +1 -2
- package/dist/tools/sec-def-opt-params.js.map +1 -1
- package/dist/tools/user-info.d.ts +4 -0
- package/dist/tools/user-info.js +52 -0
- package/dist/tools/user-info.js.map +1 -0
- package/package.json +51 -53
- package/dist/tools/market-data-single.js.map +0 -1
- /package/dist/tools/{market-data-single.d.ts → market-data-snapshot.d.ts} +0 -0
|
@@ -59,7 +59,6 @@ class IBApiNext {
|
|
|
59
59
|
* @param options Creation options.
|
|
60
60
|
*/
|
|
61
61
|
constructor(options) {
|
|
62
|
-
var _a, _b, _c;
|
|
63
62
|
this._nextReqId = 1;
|
|
64
63
|
/**
|
|
65
64
|
* The IBApi error [[Subject]].
|
|
@@ -85,13 +84,12 @@ class IBApiNext {
|
|
|
85
84
|
/** accountSummary event handler */
|
|
86
85
|
this.onAccountSummary = (subscriptions, reqId, account, tag, value, currency) => {
|
|
87
86
|
// get the subscription
|
|
88
|
-
var _a;
|
|
89
87
|
const subscription = subscriptions.get(reqId);
|
|
90
88
|
if (!subscription) {
|
|
91
89
|
return;
|
|
92
90
|
}
|
|
93
91
|
// update latest value on cache
|
|
94
|
-
const cached =
|
|
92
|
+
const cached = subscription.lastAllValue ?? new mutable_account_summary_1.MutableAccountSummaries();
|
|
95
93
|
const lastValue = cached
|
|
96
94
|
.getOrAdd(account, () => new mutable_account_summary_1.MutableAccountSummaryTagValues())
|
|
97
95
|
.getOrAdd(tag, () => new mutable_account_summary_1.MutableAccountSummaryValues());
|
|
@@ -137,10 +135,9 @@ class IBApiNext {
|
|
|
137
135
|
this.onUpdateAccountValue = (subscriptions, tag, value, currency, account) => {
|
|
138
136
|
this.logger.debug(LOG_TAG, `onUpdateAccountValue(${tag}, ${value}, ${currency}, ${account})`);
|
|
139
137
|
subscriptions.forEach((subscription) => {
|
|
140
|
-
var _a, _b;
|
|
141
138
|
// update latest value on cache
|
|
142
|
-
const all =
|
|
143
|
-
const cached =
|
|
139
|
+
const all = subscription.lastAllValue ?? {};
|
|
140
|
+
const cached = all?.value ?? new mutable_account_summary_1.MutableAccountSummaries();
|
|
144
141
|
const lastValue = cached
|
|
145
142
|
.getOrAdd(account, () => new mutable_account_summary_1.MutableAccountSummaryTagValues())
|
|
146
143
|
.getOrAdd(tag, () => new mutable_account_summary_1.MutableAccountSummaryValues());
|
|
@@ -191,15 +188,23 @@ class IBApiNext {
|
|
|
191
188
|
*/
|
|
192
189
|
this.onUpdatePortfolio = (subscriptions, contract, pos, marketPrice, marketValue, avgCost, unrealizedPNL, realizedPNL, account) => {
|
|
193
190
|
this.logger.debug(LOG_TAG, `onUpdatePortfolio(${contract.symbol}, ${pos}, ${marketPrice}, ${marketValue}, ${avgCost}, ${unrealizedPNL}, ${realizedPNL}, ${account})`);
|
|
194
|
-
const updatedPosition = {
|
|
191
|
+
const updatedPosition = {
|
|
192
|
+
account,
|
|
193
|
+
contract,
|
|
194
|
+
pos,
|
|
195
|
+
avgCost,
|
|
196
|
+
marketPrice,
|
|
197
|
+
marketValue,
|
|
198
|
+
unrealizedPNL,
|
|
199
|
+
realizedPNL,
|
|
200
|
+
};
|
|
195
201
|
// notify all subscribers
|
|
196
202
|
subscriptions.forEach((subscription) => {
|
|
197
203
|
// update latest value on cache
|
|
198
|
-
var _a, _b;
|
|
199
204
|
let hasAdded = false;
|
|
200
205
|
let hasRemoved = false;
|
|
201
|
-
const all =
|
|
202
|
-
const cached =
|
|
206
|
+
const all = subscription.lastAllValue ?? {};
|
|
207
|
+
const cached = all?.portfolio ?? new mutable_account_positions_update_1.MutableAccountPositions();
|
|
203
208
|
const accountPositions = cached.getOrAdd(account, () => []);
|
|
204
209
|
const changePositionIndex = accountPositions.findIndex((p) => p.contract.conId == contract.conId);
|
|
205
210
|
if (changePositionIndex === -1) {
|
|
@@ -222,19 +227,31 @@ class IBApiNext {
|
|
|
222
227
|
if (hasAdded) {
|
|
223
228
|
subscription.next({
|
|
224
229
|
all: all,
|
|
225
|
-
added: {
|
|
230
|
+
added: {
|
|
231
|
+
portfolio: new mutable_account_positions_update_1.MutableAccountPositions([
|
|
232
|
+
[account, [updatedPosition]],
|
|
233
|
+
]),
|
|
234
|
+
},
|
|
226
235
|
});
|
|
227
236
|
}
|
|
228
237
|
else if (hasRemoved) {
|
|
229
238
|
subscription.next({
|
|
230
239
|
all: all,
|
|
231
|
-
removed: {
|
|
240
|
+
removed: {
|
|
241
|
+
portfolio: new mutable_account_positions_update_1.MutableAccountPositions([
|
|
242
|
+
[account, [updatedPosition]],
|
|
243
|
+
]),
|
|
244
|
+
},
|
|
232
245
|
});
|
|
233
246
|
}
|
|
234
247
|
else {
|
|
235
248
|
subscription.next({
|
|
236
249
|
all: all,
|
|
237
|
-
changed: {
|
|
250
|
+
changed: {
|
|
251
|
+
portfolio: new mutable_account_positions_update_1.MutableAccountPositions([
|
|
252
|
+
[account, [updatedPosition]],
|
|
253
|
+
]),
|
|
254
|
+
},
|
|
238
255
|
});
|
|
239
256
|
}
|
|
240
257
|
});
|
|
@@ -250,9 +267,8 @@ class IBApiNext {
|
|
|
250
267
|
this.onUpdateAccountTime = (subscriptions, timeStamp) => {
|
|
251
268
|
this.logger.debug(LOG_TAG, `onUpdateAccountTime(${timeStamp})`);
|
|
252
269
|
subscriptions.forEach((sub) => {
|
|
253
|
-
var _a;
|
|
254
270
|
const changed = { timestamp: timeStamp };
|
|
255
|
-
const all =
|
|
271
|
+
const all = sub.lastAllValue ?? {};
|
|
256
272
|
all.timestamp = changed.timestamp;
|
|
257
273
|
sub.next({
|
|
258
274
|
all: all,
|
|
@@ -278,10 +294,9 @@ class IBApiNext {
|
|
|
278
294
|
// notify all subscribers
|
|
279
295
|
subscriptions.forEach((subscription) => {
|
|
280
296
|
// update latest value on cache
|
|
281
|
-
var _a;
|
|
282
297
|
let hasAdded = false;
|
|
283
298
|
let hasRemoved = false;
|
|
284
|
-
const cached =
|
|
299
|
+
const cached = subscription.lastAllValue ?? new mutable_account_positions_update_1.MutableAccountPositions();
|
|
285
300
|
const accountPositions = cached.getOrAdd(account, () => []);
|
|
286
301
|
const changePositionIndex = accountPositions.findIndex((p) => p.contract.conId == contract.conId);
|
|
287
302
|
if (changePositionIndex === -1) {
|
|
@@ -323,13 +338,12 @@ class IBApiNext {
|
|
|
323
338
|
/** contractDetails event handler */
|
|
324
339
|
this.onContractDetails = (subscriptions, reqId, details) => {
|
|
325
340
|
// get the subscription
|
|
326
|
-
var _a;
|
|
327
341
|
const subscription = subscriptions.get(reqId);
|
|
328
342
|
if (!subscription) {
|
|
329
343
|
return;
|
|
330
344
|
}
|
|
331
345
|
// append to list
|
|
332
|
-
const cached =
|
|
346
|
+
const cached = subscription.lastAllValue ?? [];
|
|
333
347
|
cached.push(details);
|
|
334
348
|
// sent change to subscribers
|
|
335
349
|
subscription.next({
|
|
@@ -338,26 +352,24 @@ class IBApiNext {
|
|
|
338
352
|
};
|
|
339
353
|
/** contractDetailsEnd event handler */
|
|
340
354
|
this.onContractDetailsEnd = (subscriptions, reqId) => {
|
|
341
|
-
|
|
342
|
-
(_a = subscriptions.get(reqId)) === null || _a === void 0 ? void 0 : _a.complete();
|
|
355
|
+
subscriptions.get(reqId)?.complete();
|
|
343
356
|
};
|
|
344
357
|
/** securityDefinitionOptionParameter event handler */
|
|
345
358
|
this.onSecurityDefinitionOptionParameter = (subscriptions, reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes) => {
|
|
346
359
|
// get the subscription
|
|
347
|
-
var _a;
|
|
348
360
|
const subscription = subscriptions.get(reqId);
|
|
349
361
|
if (!subscription) {
|
|
350
362
|
return;
|
|
351
363
|
}
|
|
352
364
|
// append to list
|
|
353
|
-
const cached =
|
|
365
|
+
const cached = subscription.lastAllValue ?? [];
|
|
354
366
|
cached.push({
|
|
355
367
|
exchange: exchange,
|
|
356
368
|
underlyingConId: underlyingConId,
|
|
357
369
|
tradingClass: tradingClass,
|
|
358
370
|
multiplier: parseInt(multiplier),
|
|
359
371
|
expirations: expirations,
|
|
360
|
-
strikes: strikes
|
|
372
|
+
strikes: strikes,
|
|
361
373
|
});
|
|
362
374
|
// sent change to subscribers
|
|
363
375
|
subscription.next({
|
|
@@ -366,8 +378,7 @@ class IBApiNext {
|
|
|
366
378
|
};
|
|
367
379
|
/** securityDefinitionOptionParameterEnd event handler */
|
|
368
380
|
this.onSecurityDefinitionOptionParameterEnd = (subscriptions, reqId) => {
|
|
369
|
-
|
|
370
|
-
(_a = subscriptions.get(reqId)) === null || _a === void 0 ? void 0 : _a.complete();
|
|
381
|
+
subscriptions.get(reqId)?.complete();
|
|
371
382
|
};
|
|
372
383
|
/** pnl event handler. */
|
|
373
384
|
this.onPnL = (subscriptions, reqId, dailyPnL, unrealizedPnL, realizedPnL) => {
|
|
@@ -402,7 +413,6 @@ class IBApiNext {
|
|
|
402
413
|
/** tickPrice, tickSize and tickGeneric event handler */
|
|
403
414
|
this.onTick = (subscriptions, reqId, tickType, value) => {
|
|
404
415
|
// convert -1 on Bid/Ask to undefined
|
|
405
|
-
var _a;
|
|
406
416
|
if (value === -1 &&
|
|
407
417
|
(tickType === _1.IBApiTickType.BID ||
|
|
408
418
|
tickType === _1.IBApiTickType.DELAYED_BID ||
|
|
@@ -416,7 +426,7 @@ class IBApiNext {
|
|
|
416
426
|
return;
|
|
417
427
|
}
|
|
418
428
|
// update latest value on cache
|
|
419
|
-
const cached =
|
|
429
|
+
const cached = subscription.lastAllValue ?? new mutable_market_data_1.MutableMarketData();
|
|
420
430
|
const hasChanged = cached.has(tickType);
|
|
421
431
|
const updatedValue = {
|
|
422
432
|
value,
|
|
@@ -440,7 +450,6 @@ class IBApiNext {
|
|
|
440
450
|
/** tickOptionComputationHandler event handler */
|
|
441
451
|
this.onTickOptionComputation = (subscriptions, reqId, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice) => {
|
|
442
452
|
// get subscription
|
|
443
|
-
var _a;
|
|
444
453
|
const subscription = subscriptions.get(reqId);
|
|
445
454
|
if (!subscription) {
|
|
446
455
|
return;
|
|
@@ -471,7 +480,10 @@ class IBApiNext {
|
|
|
471
480
|
], [
|
|
472
481
|
_1.IBApiNextTickType.BID_OPTION_GAMMA,
|
|
473
482
|
{ value: gamma, ingressTm: now },
|
|
474
|
-
], [_1.IBApiNextTickType.BID_OPTION_VEGA, { value: vega, ingressTm: now }], [
|
|
483
|
+
], [_1.IBApiNextTickType.BID_OPTION_VEGA, { value: vega, ingressTm: now }], [
|
|
484
|
+
_1.IBApiNextTickType.BID_OPTION_THETA,
|
|
485
|
+
{ value: theta, ingressTm: now },
|
|
486
|
+
]);
|
|
475
487
|
break;
|
|
476
488
|
case _1.IBApiTickType.DELAYED_BID_OPTION:
|
|
477
489
|
ticks.push([
|
|
@@ -507,7 +519,10 @@ class IBApiNext {
|
|
|
507
519
|
], [
|
|
508
520
|
_1.IBApiNextTickType.ASK_OPTION_GAMMA,
|
|
509
521
|
{ value: gamma, ingressTm: now },
|
|
510
|
-
], [_1.IBApiNextTickType.ASK_OPTION_VEGA, { value: vega, ingressTm: now }], [
|
|
522
|
+
], [_1.IBApiNextTickType.ASK_OPTION_VEGA, { value: vega, ingressTm: now }], [
|
|
523
|
+
_1.IBApiNextTickType.ASK_OPTION_THETA,
|
|
524
|
+
{ value: theta, ingressTm: now },
|
|
525
|
+
]);
|
|
511
526
|
break;
|
|
512
527
|
case _1.IBApiTickType.DELAYED_ASK_OPTION:
|
|
513
528
|
ticks.push([
|
|
@@ -613,7 +628,7 @@ class IBApiNext {
|
|
|
613
628
|
break;
|
|
614
629
|
}
|
|
615
630
|
// update latest value on cache
|
|
616
|
-
const cached =
|
|
631
|
+
const cached = subscription.lastAllValue ?? new mutable_market_data_1.MutableMarketData();
|
|
617
632
|
const added = new mutable_market_data_1.MutableMarketData();
|
|
618
633
|
const changed = new mutable_market_data_1.MutableMarketData();
|
|
619
634
|
ticks.forEach((tick) => {
|
|
@@ -636,8 +651,7 @@ class IBApiNext {
|
|
|
636
651
|
};
|
|
637
652
|
/** tickSnapshotEnd event handler */
|
|
638
653
|
this.onTickSnapshotEnd = (subscriptions, reqId) => {
|
|
639
|
-
|
|
640
|
-
(_a = subscriptions.get(reqId)) === null || _a === void 0 ? void 0 : _a.complete();
|
|
654
|
+
subscriptions.get(reqId)?.complete();
|
|
641
655
|
};
|
|
642
656
|
/**
|
|
643
657
|
* @deprecated please use getMarketDataSnapshot instead of getMarketDataSingle.
|
|
@@ -657,7 +671,6 @@ class IBApiNext {
|
|
|
657
671
|
/** historicalData event handler */
|
|
658
672
|
this.onHistoricalData = (subscriptions, reqId, time, open, high, low, close, volume, count, WAP) => {
|
|
659
673
|
// get subscription
|
|
660
|
-
var _a;
|
|
661
674
|
const subscription = subscriptions.get(reqId);
|
|
662
675
|
if (!subscription) {
|
|
663
676
|
return;
|
|
@@ -667,7 +680,7 @@ class IBApiNext {
|
|
|
667
680
|
subscription.complete();
|
|
668
681
|
}
|
|
669
682
|
else {
|
|
670
|
-
const all =
|
|
683
|
+
const all = subscription.lastAllValue ?? [];
|
|
671
684
|
const current = { time };
|
|
672
685
|
if (open !== -1) {
|
|
673
686
|
current.open = open;
|
|
@@ -699,13 +712,12 @@ class IBApiNext {
|
|
|
699
712
|
/** historicalDataUpdate event handler */
|
|
700
713
|
this.onHistoricalDataUpdate = (subscriptions, reqId, time, open, high, low, close, volume, count, WAP) => {
|
|
701
714
|
// get subscription
|
|
702
|
-
var _a;
|
|
703
715
|
const subscription = subscriptions.get(reqId);
|
|
704
716
|
if (!subscription) {
|
|
705
717
|
return;
|
|
706
718
|
}
|
|
707
719
|
// update bar
|
|
708
|
-
const current =
|
|
720
|
+
const current = subscription.lastAllValue ?? {};
|
|
709
721
|
current.time = time;
|
|
710
722
|
current.open = open !== -1 ? open : undefined;
|
|
711
723
|
current.high = high !== -1 ? high : undefined;
|
|
@@ -793,14 +805,13 @@ class IBApiNext {
|
|
|
793
805
|
};
|
|
794
806
|
/** marketDepthL2 event handler */
|
|
795
807
|
this.onUpdateMktDepthL2 = (subscriptions, tickerId, position, marketMaker, operation, side, price, size, isSmartDepth) => {
|
|
796
|
-
var _a;
|
|
797
808
|
// get subscription
|
|
798
809
|
const subscription = subscriptions.get(tickerId);
|
|
799
810
|
if (!subscription) {
|
|
800
811
|
return;
|
|
801
812
|
}
|
|
802
813
|
// update cached
|
|
803
|
-
const cached =
|
|
814
|
+
const cached = subscription.lastAllValue ?? {
|
|
804
815
|
bids: new Map(),
|
|
805
816
|
asks: new Map(),
|
|
806
817
|
};
|
|
@@ -902,12 +913,17 @@ class IBApiNext {
|
|
|
902
913
|
*/
|
|
903
914
|
this.onOpenOrder = (subscriptions, orderId, contract, order, orderState) => {
|
|
904
915
|
subscriptions.forEach((sub) => {
|
|
905
|
-
|
|
906
|
-
const allOrders = (_a = sub.lastAllValue) !== null && _a !== void 0 ? _a : [];
|
|
916
|
+
const allOrders = sub.lastAllValue ?? [];
|
|
907
917
|
const changeOrderIndex = allOrders.findIndex((p) => p.order.permId == order.permId);
|
|
908
918
|
if (changeOrderIndex === -1) {
|
|
909
919
|
// new open order - add it
|
|
910
|
-
const addedOrder = {
|
|
920
|
+
const addedOrder = {
|
|
921
|
+
orderId,
|
|
922
|
+
contract,
|
|
923
|
+
order,
|
|
924
|
+
orderState,
|
|
925
|
+
orderStatus: undefined,
|
|
926
|
+
};
|
|
911
927
|
allOrders.push(addedOrder);
|
|
912
928
|
sub.next({
|
|
913
929
|
all: allOrders,
|
|
@@ -959,7 +975,7 @@ class IBApiNext {
|
|
|
959
975
|
* This is probably unused now.
|
|
960
976
|
* Neither reqAllOpenOrders, reqAutoOpenOrders nor reqOpenOrders documentation reference this event.
|
|
961
977
|
* Even getAutoOpenOrders(true) doesn't call it!
|
|
962
|
-
|
|
978
|
+
*/
|
|
963
979
|
this.logger.warn(LOG_TAG, `Unexpected onOrderBound(${orderId}, ${apiClientId}, ${apiOrderId}) called.`);
|
|
964
980
|
};
|
|
965
981
|
/**
|
|
@@ -990,15 +1006,14 @@ class IBApiNext {
|
|
|
990
1006
|
lastFillPrice: undefined,
|
|
991
1007
|
clientId,
|
|
992
1008
|
whyHeld,
|
|
993
|
-
mktCapPrice
|
|
1009
|
+
mktCapPrice,
|
|
994
1010
|
};
|
|
995
1011
|
if (filled) {
|
|
996
1012
|
orderStatus.avgFillPrice = avgFillPrice;
|
|
997
1013
|
orderStatus.lastFillPrice = lastFillPrice;
|
|
998
1014
|
}
|
|
999
1015
|
subscriptions.forEach((sub) => {
|
|
1000
|
-
|
|
1001
|
-
const allOrders = (_a = sub.lastAllValue) !== null && _a !== void 0 ? _a : [];
|
|
1016
|
+
const allOrders = sub.lastAllValue ?? [];
|
|
1002
1017
|
const changeOrderIndex = allOrders.findIndex((p) => p.order.permId == permId);
|
|
1003
1018
|
if (changeOrderIndex !== -1) {
|
|
1004
1019
|
const updatedOrder = allOrders[changeOrderIndex];
|
|
@@ -1042,8 +1057,7 @@ class IBApiNext {
|
|
|
1042
1057
|
*/
|
|
1043
1058
|
this.onExecDetails = (subscriptions, reqId, contract, execution) => {
|
|
1044
1059
|
subscriptions.forEach((sub) => {
|
|
1045
|
-
|
|
1046
|
-
const allTrades = (_a = sub.lastAllValue) !== null && _a !== void 0 ? _a : [];
|
|
1060
|
+
const allTrades = sub.lastAllValue ?? [];
|
|
1047
1061
|
allTrades.push({ reqId, contract, execution });
|
|
1048
1062
|
sub.next({
|
|
1049
1063
|
all: allTrades,
|
|
@@ -1067,8 +1081,7 @@ class IBApiNext {
|
|
|
1067
1081
|
/** comissionReport event handler. */
|
|
1068
1082
|
this.onComissionReport = (subscriptions, commissionReport) => {
|
|
1069
1083
|
subscriptions.forEach((sub) => {
|
|
1070
|
-
|
|
1071
|
-
const commissionReports = (_a = sub.lastAllValue) !== null && _a !== void 0 ? _a : [];
|
|
1084
|
+
const commissionReports = sub.lastAllValue ?? [];
|
|
1072
1085
|
commissionReports.push(commissionReport);
|
|
1073
1086
|
sub.next({
|
|
1074
1087
|
all: commissionReports,
|
|
@@ -1079,24 +1092,37 @@ class IBApiNext {
|
|
|
1079
1092
|
this.onSymbolSamples = (subscriptions, reqId, contractDescriptions) => {
|
|
1080
1093
|
const sub = subscriptions.get(reqId);
|
|
1081
1094
|
subscriptions.delete(reqId);
|
|
1082
|
-
sub
|
|
1095
|
+
sub?.next({
|
|
1083
1096
|
all: contractDescriptions,
|
|
1084
1097
|
});
|
|
1085
|
-
sub
|
|
1098
|
+
sub?.complete();
|
|
1086
1099
|
};
|
|
1087
|
-
|
|
1100
|
+
/** userInfo event handler. */
|
|
1101
|
+
this.onUserInfo = (subscriptions, reqId, whiteBrandingId) => {
|
|
1102
|
+
const sub = subscriptions.get(reqId);
|
|
1103
|
+
subscriptions.delete(reqId);
|
|
1104
|
+
sub?.next({
|
|
1105
|
+
all: whiteBrandingId,
|
|
1106
|
+
});
|
|
1107
|
+
sub?.complete();
|
|
1108
|
+
};
|
|
1109
|
+
this.logger = new logger_1.IBApiNextLogger(options?.logger ?? new console_logger_1.ConsoleLogger());
|
|
1088
1110
|
// create the IBApiAutoConnection and subscription registry
|
|
1089
|
-
this.api = new auto_connection_1.IBApiAutoConnection(
|
|
1111
|
+
this.api = new auto_connection_1.IBApiAutoConnection(options?.reconnectInterval ?? 0, (options?.connectionWatchdogInterval ?? 0) * 1000, this.logger, options);
|
|
1090
1112
|
this.subscriptions = new subscription_registry_1.IBApiNextSubscriptionRegistry(this.api, this);
|
|
1091
1113
|
// setup error event handler (bound to lifetime of IBApiAutoConnection so we never unregister)
|
|
1092
|
-
this.api.on(__1.EventName.error, (error, code, reqId) => {
|
|
1093
|
-
|
|
1094
|
-
|
|
1114
|
+
this.api.on(__1.EventName.error, (error, code, reqId, advancedOrderReject) => {
|
|
1115
|
+
const apiError = {
|
|
1116
|
+
error,
|
|
1117
|
+
code,
|
|
1118
|
+
reqId,
|
|
1119
|
+
advancedOrderReject,
|
|
1120
|
+
};
|
|
1095
1121
|
// handle warnings - they are also reported on TWS error callback, but we DO NOT want to emit
|
|
1096
1122
|
// it as error into the subject (and cancel the subscription).
|
|
1097
|
-
if ((code >= 2100 && code < 3000)
|
|
1098
|
-
|
|
1099
|
-
|
|
1123
|
+
if ((code >= 2100 && code < 3000) ||
|
|
1124
|
+
code === __1.ErrorCode.PART_OF_REQUESTED_DATA_NOT_SUBSCRIBED ||
|
|
1125
|
+
code === __1.ErrorCode.DISPLAYING_DELAYED_DATA) {
|
|
1100
1126
|
this.logger.warn(TWS_LOG_TAG, `${error.message} - Code: ${code} - ReqId: ${reqId}`);
|
|
1101
1127
|
return;
|
|
1102
1128
|
}
|
|
@@ -1184,8 +1210,7 @@ class IBApiNext {
|
|
|
1184
1210
|
return (0, rxjs_1.lastValueFrom)(this.subscriptions
|
|
1185
1211
|
.register(() => {
|
|
1186
1212
|
this.api.reqCurrentTime();
|
|
1187
|
-
}, undefined, [[__1.EventName.currentTime, this.onCurrentTime]], "
|
|
1188
|
-
)
|
|
1213
|
+
}, undefined, [[__1.EventName.currentTime, this.onCurrentTime]], "getCurrentTime")
|
|
1189
1214
|
.pipe((0, operators_1.map)((v) => v.all)), {
|
|
1190
1215
|
defaultValue: 0,
|
|
1191
1216
|
});
|
|
@@ -1197,8 +1222,7 @@ class IBApiNext {
|
|
|
1197
1222
|
return (0, rxjs_1.lastValueFrom)(this.subscriptions
|
|
1198
1223
|
.register(() => {
|
|
1199
1224
|
this.api.reqManagedAccts();
|
|
1200
|
-
}, undefined, [[__1.EventName.managedAccounts, this.onManagedAccts]], "getManagedAccounts"
|
|
1201
|
-
)
|
|
1225
|
+
}, undefined, [[__1.EventName.managedAccounts, this.onManagedAccts]], "getManagedAccounts")
|
|
1202
1226
|
.pipe((0, operators_1.map)((v) => v.all)), {
|
|
1203
1227
|
defaultValue: [],
|
|
1204
1228
|
});
|
|
@@ -1277,8 +1301,7 @@ class IBApiNext {
|
|
|
1277
1301
|
[__1.EventName.updatePortfolio, this.onUpdatePortfolio],
|
|
1278
1302
|
[__1.EventName.updateAccountTime, this.onUpdateAccountTime],
|
|
1279
1303
|
[__1.EventName.accountDownloadEnd, this.onAccountDownloadEnd],
|
|
1280
|
-
],
|
|
1281
|
-
);
|
|
1304
|
+
], acctCode ? `getAccountUpdates+${acctCode}` : "getAccountUpdates");
|
|
1282
1305
|
}
|
|
1283
1306
|
/**
|
|
1284
1307
|
* Create subscription to receive the positions on all accessible accounts.
|
|
@@ -1328,8 +1351,14 @@ class IBApiNext {
|
|
|
1328
1351
|
.register((reqId) => {
|
|
1329
1352
|
this.api.reqSecDefOptParams(reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId);
|
|
1330
1353
|
}, undefined, [
|
|
1331
|
-
[
|
|
1332
|
-
|
|
1354
|
+
[
|
|
1355
|
+
__1.EventName.securityDefinitionOptionParameter,
|
|
1356
|
+
this.onSecurityDefinitionOptionParameter,
|
|
1357
|
+
],
|
|
1358
|
+
[
|
|
1359
|
+
__1.EventName.securityDefinitionOptionParameterEnd,
|
|
1360
|
+
this.onSecurityDefinitionOptionParameterEnd,
|
|
1361
|
+
],
|
|
1333
1362
|
])
|
|
1334
1363
|
.pipe((0, operators_1.map)((v) => v.all)), {
|
|
1335
1364
|
defaultValue: [],
|
|
@@ -1428,7 +1457,6 @@ class IBApiNext {
|
|
|
1428
1457
|
[__1.EventName.tickGeneric, this.onTick],
|
|
1429
1458
|
[__1.EventName.tickOptionComputation, this.onTickOptionComputation],
|
|
1430
1459
|
[__1.EventName.tickSnapshotEnd, this.onTickSnapshotEnd],
|
|
1431
|
-
// [EventName.error, this.onMarketDataError]
|
|
1432
1460
|
], snapshot || regulatorySnapshot
|
|
1433
1461
|
? undefined
|
|
1434
1462
|
: `${JSON.stringify(contract)}:${genericTickList}`);
|
|
@@ -1635,8 +1663,7 @@ class IBApiNext {
|
|
|
1635
1663
|
return (0, rxjs_1.lastValueFrom)(this.subscriptions
|
|
1636
1664
|
.register(() => {
|
|
1637
1665
|
this.api.reqMktDepthExchanges();
|
|
1638
|
-
}, undefined, [[__1.EventName.mktDepthExchanges, this.onMktDepthExchanges]], "
|
|
1639
|
-
)
|
|
1666
|
+
}, undefined, [[__1.EventName.mktDepthExchanges, this.onMktDepthExchanges]], "getMarketDepthExchanges")
|
|
1640
1667
|
.pipe((0, operators_1.map)((v) => v.all)), {
|
|
1641
1668
|
defaultValue: [],
|
|
1642
1669
|
});
|
|
@@ -1695,8 +1722,7 @@ class IBApiNext {
|
|
|
1695
1722
|
[__1.EventName.orderStatus, this.onOrderStatus],
|
|
1696
1723
|
[__1.EventName.orderBound, this.onOrderBound],
|
|
1697
1724
|
[__1.EventName.openOrderEnd, this.onOpenOrderEnd],
|
|
1698
|
-
], "getAllOpenOrders"
|
|
1699
|
-
)
|
|
1725
|
+
], "getAllOpenOrders")
|
|
1700
1726
|
.pipe((0, operators_1.map)((v) => v.all)), {
|
|
1701
1727
|
defaultValue: [],
|
|
1702
1728
|
});
|
|
@@ -1706,15 +1732,13 @@ class IBApiNext {
|
|
|
1706
1732
|
* For client ID 0, this will bind previous manual TWS orders.
|
|
1707
1733
|
*/
|
|
1708
1734
|
getOpenOrders() {
|
|
1709
|
-
return this.subscriptions
|
|
1710
|
-
.register(() => {
|
|
1735
|
+
return this.subscriptions.register(() => {
|
|
1711
1736
|
this.api.reqOpenOrders();
|
|
1712
1737
|
}, undefined, [
|
|
1713
1738
|
[__1.EventName.openOrder, this.onOpenOrder],
|
|
1714
1739
|
[__1.EventName.orderStatus, this.onOrderStatus],
|
|
1715
1740
|
[__1.EventName.orderBound, this.onOrderBound],
|
|
1716
|
-
], "getOpenOrders"
|
|
1717
|
-
);
|
|
1741
|
+
], "getOpenOrders");
|
|
1718
1742
|
}
|
|
1719
1743
|
/**
|
|
1720
1744
|
* Requests status updates AND (IB documentation not correct on this point) future orders placed from TWS. Can only be used with client ID 0.
|
|
@@ -1731,8 +1755,7 @@ class IBApiNext {
|
|
|
1731
1755
|
[__1.EventName.openOrder, this.onOpenOrder],
|
|
1732
1756
|
[__1.EventName.orderStatus, this.onOrderStatus],
|
|
1733
1757
|
[__1.EventName.orderBound, this.onOrderBound],
|
|
1734
|
-
], "getAutoOpenOrders"
|
|
1735
|
-
);
|
|
1758
|
+
], "getAutoOpenOrders");
|
|
1736
1759
|
}
|
|
1737
1760
|
/**
|
|
1738
1761
|
* Requests the next valid order ID at the current moment.
|
|
@@ -1844,6 +1867,18 @@ class IBApiNext {
|
|
|
1844
1867
|
}, undefined, [[__1.EventName.symbolSamples, this.onSymbolSamples]])
|
|
1845
1868
|
.pipe((0, operators_1.map)((v) => v.all)));
|
|
1846
1869
|
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Get the user info of the logged user.
|
|
1872
|
+
*/
|
|
1873
|
+
getUserInfo() {
|
|
1874
|
+
return (0, rxjs_1.lastValueFrom)(this.subscriptions
|
|
1875
|
+
.register((reqId) => {
|
|
1876
|
+
this.api.reqUserInfo(reqId);
|
|
1877
|
+
}, undefined, [[__1.EventName.userInfo, this.onUserInfo]], "getUserInfo")
|
|
1878
|
+
.pipe((0, operators_1.map)((v) => v.all)), {
|
|
1879
|
+
defaultValue: undefined,
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1847
1882
|
}
|
|
1848
1883
|
exports.IBApiNext = IBApiNext;
|
|
1849
1884
|
//# sourceMappingURL=api-next.js.map
|