@stoqey/ib 1.2.34 → 1.2.36
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 +55 -2
- package/dist/api/api.js +44 -3
- package/dist/api/api.js.map +1 -1
- package/dist/api/contract/contractDetails.d.ts +12 -8
- package/dist/api/data/enum/event-name.d.ts +7 -1
- package/dist/api/data/enum/event-name.js +6 -0
- package/dist/api/data/enum/event-name.js.map +1 -1
- package/dist/api/data/enum/min-server-version.d.ts +15 -1
- package/dist/api/data/enum/min-server-version.js +14 -0
- package/dist/api/data/enum/min-server-version.js.map +1 -1
- package/dist/api/historical/HistoricalSession.d.ts +6 -0
- package/dist/api/historical/HistoricalSession.js +3 -0
- package/dist/api/historical/HistoricalSession.js.map +1 -0
- package/dist/api/order/order.d.ts +4 -0
- package/dist/common/errorCode.d.ts +10 -1
- package/dist/common/errorCode.js +10 -0
- package/dist/common/errorCode.js.map +1 -1
- package/dist/core/io/decoder.d.ts +23 -0
- package/dist/core/io/decoder.js +145 -11
- package/dist/core/io/decoder.js.map +1 -1
- package/dist/core/io/encoder.d.ts +11 -2
- package/dist/core/io/encoder.js +83 -12
- package/dist/core/io/encoder.js.map +1 -1
- package/dist/core/io/enum/in-msg-id.d.ts +5 -1
- package/dist/core/io/enum/in-msg-id.js +4 -0
- package/dist/core/io/enum/in-msg-id.js.map +1 -1
- package/package.json +1 -1
package/dist/core/io/decoder.js
CHANGED
|
@@ -242,6 +242,14 @@ class Decoder {
|
|
|
242
242
|
return this.decodeMsg_COMPLETED_ORDER();
|
|
243
243
|
case in_msg_id_1.IN_MSG_ID.COMPLETED_ORDERS_END:
|
|
244
244
|
return this.decodeMsg_COMPLETED_ORDERS_END();
|
|
245
|
+
case in_msg_id_1.IN_MSG_ID.REPLACE_FA_END:
|
|
246
|
+
return this.decodeMsg_REPLACE_FA_END();
|
|
247
|
+
case in_msg_id_1.IN_MSG_ID.WSH_META_DATA:
|
|
248
|
+
return this.decodeMsg_WSH_META_DATA();
|
|
249
|
+
case in_msg_id_1.IN_MSG_ID.WSH_EVENT_DATA:
|
|
250
|
+
return this.decodeMsg_WSH_EVENT_DATA();
|
|
251
|
+
case in_msg_id_1.IN_MSG_ID.HISTORICAL_SCHEDULE:
|
|
252
|
+
return this.decodeMsg_HISTORICAL_SCHEDULE();
|
|
245
253
|
default:
|
|
246
254
|
this.callback.emitError(`No parser implementation found for token: ${in_msg_id_1.IN_MSG_ID[msgId]} (${msgId}).`, errorCode_1.ErrorCode.UNKNOWN_ID, -1);
|
|
247
255
|
}
|
|
@@ -297,6 +305,23 @@ class Decoder {
|
|
|
297
305
|
get serverVersion() {
|
|
298
306
|
return this.callback.serverVersion;
|
|
299
307
|
}
|
|
308
|
+
decodeUnicodeEscapedString(str) {
|
|
309
|
+
let v = str;
|
|
310
|
+
try {
|
|
311
|
+
while (true) {
|
|
312
|
+
const escapeIndex = v.indexOf("\\u");
|
|
313
|
+
if (escapeIndex == -1
|
|
314
|
+
|| v.length - escapeIndex < 6) {
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
const escapeString = v.substring(escapeIndex, escapeIndex + 6);
|
|
318
|
+
const hexVal = parseInt(escapeString.replace("\\u", ""), 16);
|
|
319
|
+
v = v.replace(escapeString, String.fromCharCode(hexVal));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch (e) { }
|
|
323
|
+
return v;
|
|
324
|
+
}
|
|
300
325
|
/**
|
|
301
326
|
* Read a string token from queue.
|
|
302
327
|
*/
|
|
@@ -357,6 +382,18 @@ class Decoder {
|
|
|
357
382
|
const val = parseInt(token, 10);
|
|
358
383
|
return val === Number.MAX_VALUE ? undefined : val;
|
|
359
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Read a token from queue and return it as integer value.
|
|
387
|
+
*
|
|
388
|
+
* Returns Number.MAX_VALUE if the token is empty.
|
|
389
|
+
*/
|
|
390
|
+
readIntMax() {
|
|
391
|
+
const token = this.readStr();
|
|
392
|
+
if (!token || token === "") {
|
|
393
|
+
return Number.MAX_VALUE;
|
|
394
|
+
}
|
|
395
|
+
return parseInt(token, 10);
|
|
396
|
+
}
|
|
360
397
|
/**
|
|
361
398
|
* Read a token from queue and return it as integer value.
|
|
362
399
|
*
|
|
@@ -495,7 +532,10 @@ class Decoder {
|
|
|
495
532
|
else {
|
|
496
533
|
const id = this.readInt();
|
|
497
534
|
const code = this.readInt();
|
|
498
|
-
|
|
535
|
+
let msg = this.readStr();
|
|
536
|
+
if (this.serverVersion >= min_server_version_1.default.ENCODE_MSG_ASCII7) {
|
|
537
|
+
msg = this.decodeUnicodeEscapedString(msg);
|
|
538
|
+
}
|
|
499
539
|
if (id === -1) {
|
|
500
540
|
this.callback.emitInfo(msg);
|
|
501
541
|
}
|
|
@@ -585,6 +625,9 @@ class Decoder {
|
|
|
585
625
|
orderDecoder.readIsOmsContainer();
|
|
586
626
|
orderDecoder.readDiscretionaryUpToLimitPrice();
|
|
587
627
|
orderDecoder.readUsePriceMgmtAlgo();
|
|
628
|
+
orderDecoder.readDuration();
|
|
629
|
+
orderDecoder.readPostToAts();
|
|
630
|
+
orderDecoder.readAutoCancelParent(min_server_version_1.default.AUTO_CANCEL_PARENT);
|
|
588
631
|
this.emit(event_name_1.EventName.openOrder, order.orderId, contract, order, orderState);
|
|
589
632
|
}
|
|
590
633
|
/**
|
|
@@ -669,7 +712,10 @@ class Decoder {
|
|
|
669
712
|
* Decode a CONTRACT_DATA message from data queue and emit a contractDetails event.
|
|
670
713
|
*/
|
|
671
714
|
decodeMsg_CONTRACT_DATA() {
|
|
672
|
-
|
|
715
|
+
let version = 8;
|
|
716
|
+
if (this.serverVersion < min_server_version_1.default.SIZE_RULES) {
|
|
717
|
+
version = this.readInt();
|
|
718
|
+
}
|
|
673
719
|
let reqId = -1;
|
|
674
720
|
if (version >= 3) {
|
|
675
721
|
reqId = this.readInt();
|
|
@@ -689,8 +735,8 @@ class Decoder {
|
|
|
689
735
|
contract.contract.tradingClass = this.readStr();
|
|
690
736
|
contract.contract.conId = this.readInt();
|
|
691
737
|
contract.minTick = this.readDouble();
|
|
692
|
-
if (this.serverVersion >= min_server_version_1.default.MD_SIZE_MULTIPLIER) {
|
|
693
|
-
|
|
738
|
+
if ((this.serverVersion >= min_server_version_1.default.MD_SIZE_MULTIPLIER) && (this.serverVersion < min_server_version_1.default.SIZE_RULES)) {
|
|
739
|
+
this.readInt(); // mdSizeMultiplier - not used anymore
|
|
694
740
|
}
|
|
695
741
|
contract.contract.multiplier = this.readInt();
|
|
696
742
|
contract.orderTypes = this.readStr();
|
|
@@ -704,6 +750,9 @@ class Decoder {
|
|
|
704
750
|
if (version >= 5) {
|
|
705
751
|
contract.longName = this.readStr();
|
|
706
752
|
contract.contract.primaryExch = this.readStr();
|
|
753
|
+
if (this.serverVersion >= min_server_version_1.default.ENCODE_MSG_ASCII7) {
|
|
754
|
+
contract.longName = this.decodeUnicodeEscapedString(contract.longName);
|
|
755
|
+
}
|
|
707
756
|
}
|
|
708
757
|
if (version >= 6) {
|
|
709
758
|
contract.contractMonth = this.readStr();
|
|
@@ -743,6 +792,17 @@ class Decoder {
|
|
|
743
792
|
if (this.serverVersion >= min_server_version_1.default.REAL_EXPIRATION_DATE) {
|
|
744
793
|
contract.realExpirationDate = this.readStr();
|
|
745
794
|
}
|
|
795
|
+
if (this.serverVersion >= min_server_version_1.default.STOCK_TYPE) {
|
|
796
|
+
contract.stockType = this.readStr();
|
|
797
|
+
}
|
|
798
|
+
if (this.serverVersion >= min_server_version_1.default.FRACTIONAL_SIZE_SUPPORT && this.serverVersion < min_server_version_1.default.SIZE_RULES) {
|
|
799
|
+
this.readDouble(); // sizeMinTick - not used anymore
|
|
800
|
+
}
|
|
801
|
+
if (this.serverVersion >= min_server_version_1.default.SIZE_RULES) {
|
|
802
|
+
contract.minSize = this.readDouble();
|
|
803
|
+
contract.sizeIncrement = this.readDouble();
|
|
804
|
+
contract.suggestedSizeIncrement = this.readDouble();
|
|
805
|
+
}
|
|
746
806
|
}
|
|
747
807
|
this.emit(event_name_1.EventName.contractDetails, reqId, contract);
|
|
748
808
|
}
|
|
@@ -965,7 +1025,10 @@ class Decoder {
|
|
|
965
1025
|
* Decode a BOND_CONTRACT_DATA message from data queue and emit a bondContractDetails event.
|
|
966
1026
|
*/
|
|
967
1027
|
decodeMsg_BOND_CONTRACT_DATA() {
|
|
968
|
-
|
|
1028
|
+
let version = 6;
|
|
1029
|
+
if (this.serverVersion < min_server_version_1.default.SIZE_RULES) {
|
|
1030
|
+
version = this.readInt();
|
|
1031
|
+
}
|
|
969
1032
|
let reqId = -1;
|
|
970
1033
|
if (version >= 3) {
|
|
971
1034
|
reqId = this.readInt();
|
|
@@ -992,8 +1055,8 @@ class Decoder {
|
|
|
992
1055
|
contract.contract.tradingClass = this.readStr();
|
|
993
1056
|
contract.contract.conId = this.readInt();
|
|
994
1057
|
contract.minTick = this.readDouble();
|
|
995
|
-
if (this.serverVersion >= min_server_version_1.default.MD_SIZE_MULTIPLIER) {
|
|
996
|
-
|
|
1058
|
+
if ((this.serverVersion >= min_server_version_1.default.MD_SIZE_MULTIPLIER) && (this.serverVersion < min_server_version_1.default.SIZE_RULES)) {
|
|
1059
|
+
this.readInt(); // mdSizeMultiplier - not used anymore
|
|
997
1060
|
}
|
|
998
1061
|
contract.orderTypes = this.readStr();
|
|
999
1062
|
contract.validExchanges = this.readStr();
|
|
@@ -1029,6 +1092,11 @@ class Decoder {
|
|
|
1029
1092
|
if (this.serverVersion >= min_server_version_1.default.MARKET_RULES) {
|
|
1030
1093
|
contract.marketRuleIds = this.readStr();
|
|
1031
1094
|
}
|
|
1095
|
+
if (this.serverVersion >= min_server_version_1.default.SIZE_RULES) {
|
|
1096
|
+
contract.minSize = this.readDouble();
|
|
1097
|
+
contract.sizeIncrement = this.readDouble();
|
|
1098
|
+
contract.suggestedSizeIncrement = this.readDouble();
|
|
1099
|
+
}
|
|
1032
1100
|
this.emit(event_name_1.EventName.bondContractDetails, reqId, contract);
|
|
1033
1101
|
}
|
|
1034
1102
|
/**
|
|
@@ -1079,9 +1147,17 @@ class Decoder {
|
|
|
1079
1147
|
* Decode a TICK_OPTION_COMPUTATION message from data queue and emit a tickOptionComputation event.
|
|
1080
1148
|
*/
|
|
1081
1149
|
decodeMsg_TICK_OPTION_COMPUTATION() {
|
|
1082
|
-
|
|
1150
|
+
let version;
|
|
1151
|
+
if (this.serverVersion >= min_server_version_1.default.PRICE_BASED_VOLATILITY)
|
|
1152
|
+
version = Number.MAX_VALUE;
|
|
1153
|
+
else
|
|
1154
|
+
version = this.readInt();
|
|
1083
1155
|
const tickerId = this.readInt();
|
|
1084
1156
|
const tickType = this.readInt();
|
|
1157
|
+
let tickAttrib = Number.MAX_VALUE;
|
|
1158
|
+
if (this.serverVersion >= min_server_version_1.default.PRICE_BASED_VOLATILITY) {
|
|
1159
|
+
tickAttrib = this.readInt();
|
|
1160
|
+
}
|
|
1085
1161
|
let impliedVol = this.readDouble();
|
|
1086
1162
|
if (impliedVol == -1) {
|
|
1087
1163
|
// -1 is the "not yet computed" indicator
|
|
@@ -1134,7 +1210,7 @@ class Decoder {
|
|
|
1134
1210
|
undPrice = undefined;
|
|
1135
1211
|
}
|
|
1136
1212
|
}
|
|
1137
|
-
this.emit(event_name_1.EventName.tickOptionComputation, tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice);
|
|
1213
|
+
this.emit(event_name_1.EventName.tickOptionComputation, tickerId, tickType, tickAttrib, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice);
|
|
1138
1214
|
}
|
|
1139
1215
|
/**
|
|
1140
1216
|
* Decode a TICK_GENERIC message from data queue and emit a tickGeneric event.
|
|
@@ -2127,6 +2203,52 @@ class Decoder {
|
|
|
2127
2203
|
decodeMsg_COMPLETED_ORDERS_END() {
|
|
2128
2204
|
this.emit(event_name_1.EventName.completedOrdersEnd);
|
|
2129
2205
|
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Decode a REPLACE_FA_END message from data queue and a emit replaceFAEnd event.
|
|
2208
|
+
*/
|
|
2209
|
+
decodeMsg_REPLACE_FA_END() {
|
|
2210
|
+
const reqId = this.readInt();
|
|
2211
|
+
const text = this.readStr();
|
|
2212
|
+
this.emit(event_name_1.EventName.replaceFAEnd, reqId, text);
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Decode a WSH_META_DATA message from data queue and a emit wshMetaData event.
|
|
2216
|
+
*/
|
|
2217
|
+
decodeMsg_WSH_META_DATA() {
|
|
2218
|
+
const reqId = this.readInt();
|
|
2219
|
+
const dataJson = this.readStr();
|
|
2220
|
+
this.emit(event_name_1.EventName.wshMetaData, reqId, dataJson);
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* Decode a WSH_EVENT_DATA message from data queue and a emit wshEventData event.
|
|
2224
|
+
*/
|
|
2225
|
+
decodeMsg_WSH_EVENT_DATA() {
|
|
2226
|
+
const reqId = this.readInt();
|
|
2227
|
+
const dataJson = this.readStr();
|
|
2228
|
+
this.emit(event_name_1.EventName.wshEventData, reqId, dataJson);
|
|
2229
|
+
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Decode a HISTORICAL_SCHEDULE message from data queue and a emit historicalSchedule event.
|
|
2232
|
+
*/
|
|
2233
|
+
decodeMsg_HISTORICAL_SCHEDULE() {
|
|
2234
|
+
const reqId = this.readInt();
|
|
2235
|
+
const startDateTime = this.readStr();
|
|
2236
|
+
const endDateTime = this.readStr();
|
|
2237
|
+
const timeZone = this.readStr();
|
|
2238
|
+
const sessionsCount = this.readInt();
|
|
2239
|
+
const sessions = new Array(sessionsCount);
|
|
2240
|
+
for (let i = 0; i < sessionsCount; i++) {
|
|
2241
|
+
const sessionStartDateTime = this.readStr();
|
|
2242
|
+
const sessionEndDateTime = this.readStr();
|
|
2243
|
+
const sessionRefDate = this.readStr();
|
|
2244
|
+
sessions[i] = {
|
|
2245
|
+
startDateTime: sessionStartDateTime,
|
|
2246
|
+
endDateTime: sessionEndDateTime,
|
|
2247
|
+
refDate: sessionRefDate
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
this.emit(event_name_1.EventName.historicalSchedule, reqId, startDateTime, endDateTime, timeZone, sessions);
|
|
2251
|
+
}
|
|
2130
2252
|
/**
|
|
2131
2253
|
* Decode a [[Contract]] object from data queue.
|
|
2132
2254
|
*/
|
|
@@ -2914,8 +3036,10 @@ class OrderDecoder {
|
|
|
2914
3036
|
readRefFuturesConId() {
|
|
2915
3037
|
this.order.refFuturesConId = this.decoder.readInt();
|
|
2916
3038
|
}
|
|
2917
|
-
readAutoCancelParent() {
|
|
2918
|
-
this.
|
|
3039
|
+
readAutoCancelParent(minVersionAutoCancelParent) {
|
|
3040
|
+
if ((minVersionAutoCancelParent === undefined) || (this.serverVersion >= minVersionAutoCancelParent)) {
|
|
3041
|
+
this.order.autoCancelParent = this.decoder.readBool();
|
|
3042
|
+
}
|
|
2919
3043
|
}
|
|
2920
3044
|
readShareholder() {
|
|
2921
3045
|
this.order.shareholder = this.decoder.readStr();
|
|
@@ -2940,5 +3064,15 @@ class OrderDecoder {
|
|
|
2940
3064
|
this.order.usePriceMgmtAlgo = this.decoder.readBool();
|
|
2941
3065
|
}
|
|
2942
3066
|
}
|
|
3067
|
+
readDuration() {
|
|
3068
|
+
if (this.serverVersion >= min_server_version_1.default.DURATION) {
|
|
3069
|
+
this.order.duration = this.decoder.readInt();
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
readPostToAts() {
|
|
3073
|
+
if (this.serverVersion >= min_server_version_1.default.POST_TO_ATS) {
|
|
3074
|
+
this.order.postToAts = this.decoder.readIntMax();
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
2943
3077
|
}
|
|
2944
3078
|
//# sourceMappingURL=decoder.js.map
|