UNPKG

@stoqey/ib

Version:

Interactive Brokers TWS/IB Gateway API client library for Node.js (TS)

1,021 lines 102 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Encoder = exports.OUT_MSG_ID = void 0; const market_scanner_1 = require("../../api-next/market-scanner/market-scanner"); const fa_data_type_1 = __importDefault(require("../../api/data/enum/fa-data-type")); const min_server_version_1 = __importDefault(require("../../api/data/enum/min-server-version")); const sec_type_1 = __importDefault(require("../../api/data/enum/sec-type")); const order_condition_type_1 = require("../../api/order/enum/order-condition-type"); const orderType_1 = require("../../api/order/enum/orderType"); const order_1 = require("../../api/order/order"); const errorCode_1 = require("../../common/errorCode"); /** * @internal * * Outgoing message IDs. */ var OUT_MSG_ID; (function (OUT_MSG_ID) { OUT_MSG_ID[OUT_MSG_ID["REQ_MKT_DATA"] = 1] = "REQ_MKT_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_MKT_DATA"] = 2] = "CANCEL_MKT_DATA"; OUT_MSG_ID[OUT_MSG_ID["PLACE_ORDER"] = 3] = "PLACE_ORDER"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_ORDER"] = 4] = "CANCEL_ORDER"; OUT_MSG_ID[OUT_MSG_ID["REQ_OPEN_ORDERS"] = 5] = "REQ_OPEN_ORDERS"; OUT_MSG_ID[OUT_MSG_ID["REQ_ACCOUNT_DATA"] = 6] = "REQ_ACCOUNT_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_EXECUTIONS"] = 7] = "REQ_EXECUTIONS"; OUT_MSG_ID[OUT_MSG_ID["REQ_IDS"] = 8] = "REQ_IDS"; OUT_MSG_ID[OUT_MSG_ID["REQ_CONTRACT_DATA"] = 9] = "REQ_CONTRACT_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_MKT_DEPTH"] = 10] = "REQ_MKT_DEPTH"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_MKT_DEPTH"] = 11] = "CANCEL_MKT_DEPTH"; OUT_MSG_ID[OUT_MSG_ID["REQ_NEWS_BULLETINS"] = 12] = "REQ_NEWS_BULLETINS"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_NEWS_BULLETINS"] = 13] = "CANCEL_NEWS_BULLETINS"; OUT_MSG_ID[OUT_MSG_ID["SET_SERVER_LOGLEVEL"] = 14] = "SET_SERVER_LOGLEVEL"; OUT_MSG_ID[OUT_MSG_ID["REQ_AUTO_OPEN_ORDERS"] = 15] = "REQ_AUTO_OPEN_ORDERS"; OUT_MSG_ID[OUT_MSG_ID["REQ_ALL_OPEN_ORDERS"] = 16] = "REQ_ALL_OPEN_ORDERS"; OUT_MSG_ID[OUT_MSG_ID["REQ_MANAGED_ACCTS"] = 17] = "REQ_MANAGED_ACCTS"; OUT_MSG_ID[OUT_MSG_ID["REQ_FA"] = 18] = "REQ_FA"; OUT_MSG_ID[OUT_MSG_ID["REPLACE_FA"] = 19] = "REPLACE_FA"; OUT_MSG_ID[OUT_MSG_ID["REQ_HISTORICAL_DATA"] = 20] = "REQ_HISTORICAL_DATA"; OUT_MSG_ID[OUT_MSG_ID["EXERCISE_OPTIONS"] = 21] = "EXERCISE_OPTIONS"; OUT_MSG_ID[OUT_MSG_ID["REQ_SCANNER_SUBSCRIPTION"] = 22] = "REQ_SCANNER_SUBSCRIPTION"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_SCANNER_SUBSCRIPTION"] = 23] = "CANCEL_SCANNER_SUBSCRIPTION"; OUT_MSG_ID[OUT_MSG_ID["REQ_SCANNER_PARAMETERS"] = 24] = "REQ_SCANNER_PARAMETERS"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_HISTORICAL_DATA"] = 25] = "CANCEL_HISTORICAL_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_CURRENT_TIME"] = 49] = "REQ_CURRENT_TIME"; OUT_MSG_ID[OUT_MSG_ID["REQ_REAL_TIME_BARS"] = 50] = "REQ_REAL_TIME_BARS"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_REAL_TIME_BARS"] = 51] = "CANCEL_REAL_TIME_BARS"; OUT_MSG_ID[OUT_MSG_ID["REQ_FUNDAMENTAL_DATA"] = 52] = "REQ_FUNDAMENTAL_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_FUNDAMENTAL_DATA"] = 53] = "CANCEL_FUNDAMENTAL_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_CALC_IMPLIED_VOLAT"] = 54] = "REQ_CALC_IMPLIED_VOLAT"; OUT_MSG_ID[OUT_MSG_ID["REQ_CALC_OPTION_PRICE"] = 55] = "REQ_CALC_OPTION_PRICE"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_CALC_IMPLIED_VOLAT"] = 56] = "CANCEL_CALC_IMPLIED_VOLAT"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_CALC_OPTION_PRICE"] = 57] = "CANCEL_CALC_OPTION_PRICE"; OUT_MSG_ID[OUT_MSG_ID["REQ_GLOBAL_CANCEL"] = 58] = "REQ_GLOBAL_CANCEL"; OUT_MSG_ID[OUT_MSG_ID["REQ_MARKET_DATA_TYPE"] = 59] = "REQ_MARKET_DATA_TYPE"; OUT_MSG_ID[OUT_MSG_ID["REQ_POSITIONS"] = 61] = "REQ_POSITIONS"; OUT_MSG_ID[OUT_MSG_ID["REQ_ACCOUNT_SUMMARY"] = 62] = "REQ_ACCOUNT_SUMMARY"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_ACCOUNT_SUMMARY"] = 63] = "CANCEL_ACCOUNT_SUMMARY"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_POSITIONS"] = 64] = "CANCEL_POSITIONS"; OUT_MSG_ID[OUT_MSG_ID["VERIFY_REQUEST"] = 65] = "VERIFY_REQUEST"; OUT_MSG_ID[OUT_MSG_ID["VERIFY_MESSAGE"] = 66] = "VERIFY_MESSAGE"; OUT_MSG_ID[OUT_MSG_ID["QUERY_DISPLAY_GROUPS"] = 67] = "QUERY_DISPLAY_GROUPS"; OUT_MSG_ID[OUT_MSG_ID["SUBSCRIBE_TO_GROUP_EVENTS"] = 68] = "SUBSCRIBE_TO_GROUP_EVENTS"; OUT_MSG_ID[OUT_MSG_ID["UPDATE_DISPLAY_GROUP"] = 69] = "UPDATE_DISPLAY_GROUP"; OUT_MSG_ID[OUT_MSG_ID["UNSUBSCRIBE_FROM_GROUP_EVENTS"] = 70] = "UNSUBSCRIBE_FROM_GROUP_EVENTS"; OUT_MSG_ID[OUT_MSG_ID["START_API"] = 71] = "START_API"; OUT_MSG_ID[OUT_MSG_ID["VERIFY_AND_AUTH_REQUEST"] = 72] = "VERIFY_AND_AUTH_REQUEST"; OUT_MSG_ID[OUT_MSG_ID["VERIFY_AND_AUTH_MESSAGE"] = 73] = "VERIFY_AND_AUTH_MESSAGE"; OUT_MSG_ID[OUT_MSG_ID["REQ_POSITIONS_MULTI"] = 74] = "REQ_POSITIONS_MULTI"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_POSITIONS_MULTI"] = 75] = "CANCEL_POSITIONS_MULTI"; OUT_MSG_ID[OUT_MSG_ID["REQ_ACCOUNT_UPDATES_MULTI"] = 76] = "REQ_ACCOUNT_UPDATES_MULTI"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_ACCOUNT_UPDATES_MULTI"] = 77] = "CANCEL_ACCOUNT_UPDATES_MULTI"; OUT_MSG_ID[OUT_MSG_ID["REQ_SEC_DEF_OPT_PARAMS"] = 78] = "REQ_SEC_DEF_OPT_PARAMS"; OUT_MSG_ID[OUT_MSG_ID["REQ_SOFT_DOLLAR_TIERS"] = 79] = "REQ_SOFT_DOLLAR_TIERS"; OUT_MSG_ID[OUT_MSG_ID["REQ_FAMILY_CODES"] = 80] = "REQ_FAMILY_CODES"; OUT_MSG_ID[OUT_MSG_ID["REQ_MATCHING_SYMBOLS"] = 81] = "REQ_MATCHING_SYMBOLS"; OUT_MSG_ID[OUT_MSG_ID["REQ_MKT_DEPTH_EXCHANGES"] = 82] = "REQ_MKT_DEPTH_EXCHANGES"; OUT_MSG_ID[OUT_MSG_ID["REQ_SMART_COMPONENTS"] = 83] = "REQ_SMART_COMPONENTS"; OUT_MSG_ID[OUT_MSG_ID["REQ_NEWS_ARTICLE"] = 84] = "REQ_NEWS_ARTICLE"; OUT_MSG_ID[OUT_MSG_ID["REQ_NEWS_PROVIDERS"] = 85] = "REQ_NEWS_PROVIDERS"; OUT_MSG_ID[OUT_MSG_ID["REQ_HISTORICAL_NEWS"] = 86] = "REQ_HISTORICAL_NEWS"; OUT_MSG_ID[OUT_MSG_ID["REQ_HEAD_TIMESTAMP"] = 87] = "REQ_HEAD_TIMESTAMP"; OUT_MSG_ID[OUT_MSG_ID["REQ_HISTOGRAM_DATA"] = 88] = "REQ_HISTOGRAM_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_HISTOGRAM_DATA"] = 89] = "CANCEL_HISTOGRAM_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_HEAD_TIMESTAMP"] = 90] = "CANCEL_HEAD_TIMESTAMP"; OUT_MSG_ID[OUT_MSG_ID["REQ_MARKET_RULE"] = 91] = "REQ_MARKET_RULE"; OUT_MSG_ID[OUT_MSG_ID["REQ_PNL"] = 92] = "REQ_PNL"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_PNL"] = 93] = "CANCEL_PNL"; OUT_MSG_ID[OUT_MSG_ID["REQ_PNL_SINGLE"] = 94] = "REQ_PNL_SINGLE"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_PNL_SINGLE"] = 95] = "CANCEL_PNL_SINGLE"; OUT_MSG_ID[OUT_MSG_ID["REQ_HISTORICAL_TICKS"] = 96] = "REQ_HISTORICAL_TICKS"; OUT_MSG_ID[OUT_MSG_ID["REQ_TICK_BY_TICK_DATA"] = 97] = "REQ_TICK_BY_TICK_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_TICK_BY_TICK_DATA"] = 98] = "CANCEL_TICK_BY_TICK_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_COMPLETED_ORDERS"] = 99] = "REQ_COMPLETED_ORDERS"; OUT_MSG_ID[OUT_MSG_ID["REQ_WSH_META_DATA"] = 100] = "REQ_WSH_META_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_WSH_META_DATA"] = 101] = "CANCEL_WSH_META_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_WSH_EVENT_DATA"] = 102] = "REQ_WSH_EVENT_DATA"; OUT_MSG_ID[OUT_MSG_ID["CANCEL_WSH_EVENT_DATA"] = 103] = "CANCEL_WSH_EVENT_DATA"; OUT_MSG_ID[OUT_MSG_ID["REQ_USER_INFO"] = 104] = "REQ_USER_INFO"; })(OUT_MSG_ID || (exports.OUT_MSG_ID = OUT_MSG_ID = {})); /** * @internal * Undefined integer value */ const Integer_MAX_VALUE = 2147483647; /** * @internal * * Helper function to nullify a number of Number.MAX_VALUE * * Note that this is still there for legacy reason. * With v1.2.1, Number.MAX_VALUE has been dropped and replaced with undefined on decoder-side, * but we still support it on encoder-side to avoid any unreasonably large numbers submitted to * TWS if any client code was not migrated. */ function nullifyMax(number) { if (number === Number.MAX_VALUE) { return null; } else { return number; } } /** * @internal * * Class for encoding messages and sending raw token data back to */ class Encoder { /** * Create an [[Encoder]] object for encoding messages to token data. * * @param callback A [[EncoderCallbacks]] implementation. */ constructor(callback) { this.callback = callback; } /** Get the API server version. */ get serverVersion() { return this.callback.serverVersion; } /** * Send a message to the server connection. * * @param args Array of tokens to send. */ sendMsg(...args) { this.callback.sendMsg(args); } /** * Emit an error event to public API interface. * * @param errMsg The error test message. * @param data Additional error data (optional). */ emitError(errMsg, code, reqId) { this.callback.emitError(`Server Version ${this.serverVersion}: ${errMsg}`, code, reqId ?? errorCode_1.ErrorCode.NO_VALID_ID); } /** * Encode a [[Contract]] to an array of tokens. */ encodeContract(contract) { return [ contract.conId, contract.symbol, contract.secType, contract.lastTradeDateOrContractMonth, contract.strike, contract.right, contract.multiplier, contract.exchange, contract.primaryExch, contract.currency, contract.localSymbol, contract.tradingClass, contract.includeExpired ? 1 : 0, ]; } /** * Encode a [[TagValue]] array to a string token. */ encodeTagValues(tagValues) { let result = ""; tagValues?.forEach((tv) => { result += `${tv.tag}=${tv.value};`; }); return result; } /** * @@internal * * Helper function convert an array of [[TagValue]] to a flat [tag,value] tuple array. */ /* function tagValuesToTokens(tagValues: TagValue[]): unknown[] { const result: unknown[] = new Array(tagValues.length * 2); let pos = 0; for (let i = 0; i < tagValues.length; i++) { result[pos++] = tagValues[i].tag; result[pos++] = tagValues[i].tag; } return result; }*/ /** * Encode a calculateImpliedVolatility message to an array of tokens. */ calculateImpliedVolatility(reqId, contract, optionPrice, underPrice, //reserved for future use, must be blank impliedVolatilityOptions) { if (this.serverVersion < min_server_version_1.default.REQ_CALC_IMPLIED_VOLAT) { return this.emitError("It does not support calculate implied volatility requests.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } if (this.serverVersion < min_server_version_1.default.TRADING_CLASS) { if (contract.tradingClass === undefined || contract.tradingClass === "") { return this.emitError("It does not support tradingClass parameter in calculateImpliedVolatility.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } } const version = 2; const tokens = [ OUT_MSG_ID.REQ_CALC_IMPLIED_VOLAT, version, reqId, ]; // send contract fields tokens.push(contract.conId); tokens.push(contract.symbol); tokens.push(contract.secType); tokens.push(contract.lastTradeDateOrContractMonth); tokens.push(contract.strike); tokens.push(contract.right); tokens.push(contract.multiplier); tokens.push(contract.exchange); tokens.push(contract.primaryExch); tokens.push(contract.currency); tokens.push(contract.localSymbol); if (this.serverVersion >= min_server_version_1.default.TRADING_CLASS) { tokens.push(contract.tradingClass); } tokens.push(optionPrice); tokens.push(underPrice); if (this.serverVersion >= min_server_version_1.default.LINKING) { tokens.push(this.encodeTagValues(impliedVolatilityOptions)); } this.sendMsg(tokens); } /** * Encode a calculateOptionPrice message to an array of tokens. */ calculateOptionPrice(reqId, contract, volatility, underPrice, //reserved for future use, must be blank optionPriceOptions) { if (this.serverVersion < min_server_version_1.default.REQ_CALC_OPTION_PRICE) { return this.emitError("It does not support calculate option price requests.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } if (this.serverVersion < min_server_version_1.default.TRADING_CLASS) { if (contract.tradingClass) { return this.emitError("It does not support tradingClass parameter in calculateOptionPrice.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } } const version = 2; const tokens = [ OUT_MSG_ID.REQ_CALC_OPTION_PRICE, version, reqId, ]; // send contract fields tokens.push(contract.conId); tokens.push(contract.symbol); tokens.push(contract.secType); tokens.push(contract.lastTradeDateOrContractMonth); tokens.push(contract.strike); tokens.push(contract.right); tokens.push(contract.multiplier); tokens.push(contract.exchange); tokens.push(contract.primaryExch); tokens.push(contract.currency); tokens.push(contract.localSymbol); if (this.serverVersion >= min_server_version_1.default.TRADING_CLASS) { tokens.push(contract.tradingClass); } tokens.push(volatility); tokens.push(underPrice); if (this.serverVersion >= min_server_version_1.default.LINKING) { tokens.push(this.encodeTagValues(optionPriceOptions)); } this.sendMsg(tokens); } /** * Encode a CANCEL_ACCOUNT_SUMMARY message to an array of tokens. */ cancelAccountSummary(reqId) { if (this.serverVersion < min_server_version_1.default.ACCT_SUMMARY) { return this.emitError("It not support account summary cancellation.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_ACCOUNT_SUMMARY, version, reqId); } /** * Encode a CANCEL_ACCOUNT_UPDATES_MULTI message to an array of tokens. */ cancelAccountUpdatesMulti(reqId) { const version = 2; this.sendMsg(OUT_MSG_ID.CANCEL_ACCOUNT_UPDATES_MULTI, version, reqId); } /** * Encode a CANCEL_CALC_IMPLIED_VOLAT message to an array of tokens. */ cancelCalculateImpliedVolatility(reqId) { if (this.serverVersion < min_server_version_1.default.CANCEL_CALC_IMPLIED_VOLAT) { return this.emitError("It does not support calculate implied volatility cancellation.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_CALC_IMPLIED_VOLAT, version, reqId); } /** * Encode a CANCEL_CALC_OPTION_PRICE message to an array of tokens. */ cancelCalculateOptionPrice(reqId) { if (this.serverVersion < min_server_version_1.default.CANCEL_CALC_OPTION_PRICE) { return this.emitError("It does not support calculate option price cancellation.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_CALC_OPTION_PRICE, version, reqId); } /** * Encode a CANCEL_FUNDAMENTAL_DATA message to an array of tokens. */ cancelFundamentalData(reqId) { if (this.serverVersion < min_server_version_1.default.FUNDAMENTAL_DATA) { return this.emitError("It does not support fundamental data requests.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_FUNDAMENTAL_DATA, version, reqId); } /** * Encode a CANCEL_HISTORICAL_DATA message to an array of tokens. */ cancelHistoricalData(reqId) { if (this.serverVersion < 24) { return this.emitError("It does not support historical data query cancellation.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_HISTORICAL_DATA, version, reqId); } /** * Encode a CANCEL_MKT_DATA message to an array of tokens. */ cancelMktData(reqId) { const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_MKT_DATA, version, reqId); } /** * Encode a CANCEL_MKT_DEPTH message to an array of tokens. */ cancelMktDepth(reqId, isSmartDepth) { if (this.serverVersion < 6) { return this.emitError("This feature is only available for versions of TWS >=6.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } if (this.serverVersion < min_server_version_1.default.SMART_DEPTH && isSmartDepth) { return this.emitError("It does not support SMART depth cancel.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; const tokens = [OUT_MSG_ID.CANCEL_MKT_DEPTH, version, reqId]; if (this.serverVersion >= min_server_version_1.default.SMART_DEPTH) { tokens.push(isSmartDepth); } this.sendMsg(tokens); } /** * Encode a CANCEL_NEWS_BULLETINS message to an array of tokens. */ cancelNewsBulletins() { const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_NEWS_BULLETINS, version); } /** * Encode a CANCEL_ORDER message to an array of tokens. */ cancelOrder(orderId, orderCancel) { if (this.serverVersion < min_server_version_1.default.MANUAL_ORDER_TIME && orderCancel.manualOrderCancelTime?.length) { return this.emitError("It does not support manual order cancel time attribute", errorCode_1.ErrorCode.UPDATE_TWS, orderId); } if (this.serverVersion < min_server_version_1.default.CME_TAGGING_FIELDS) { if (orderCancel.extOperator?.length || orderCancel.manualOrderIndicator != undefined) { return this.emitError("It does not support ext operator and manual order indicator parameters", errorCode_1.ErrorCode.UPDATE_TWS, orderId); } } const version = 1; // send cancel order msg const tokens = [OUT_MSG_ID.CANCEL_ORDER]; if (this.serverVersion < min_server_version_1.default.CME_TAGGING_FIELDS) tokens.push(version); tokens.push(orderId); if (this.serverVersion >= min_server_version_1.default.MANUAL_ORDER_TIME) tokens.push(orderCancel.manualOrderCancelTime); if (this.serverVersion >= min_server_version_1.default.RFQ_FIELDS && this.serverVersion < min_server_version_1.default.UNDO_RFQ_FIELDS) { tokens.push(""); tokens.push(""); tokens.push(Integer_MAX_VALUE); } if (this.serverVersion >= min_server_version_1.default.CME_TAGGING_FIELDS) { tokens.push(orderCancel.extOperator); tokens.push(orderCancel.manualOrderIndicator ?? Integer_MAX_VALUE); } this.sendMsg(tokens); } /** * Encode a CANCEL_POSITIONS message to an array of tokens. */ cancelPositions() { if (this.serverVersion < min_server_version_1.default.ACCT_SUMMARY) { return this.emitError("It does not support position cancellation.", errorCode_1.ErrorCode.UPDATE_TWS); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_POSITIONS, version); } /** * Encode a CANCEL_REAL_TIME_BARS message to an array of tokens. */ cancelRealTimeBars(reqId) { if (this.serverVersion < min_server_version_1.default.REAL_TIME_BARS) { return this.emitError("It does not support realtime bar data query cancellation.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_REAL_TIME_BARS, version, reqId); } /** * Encode a CANCEL_SCANNER_SUBSCRIPTION message to an array of tokens. */ cancelScannerSubscription(reqId) { if (this.serverVersion < 24) { return this.emitError("It does not support API scanner subscription.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } const version = 1; this.sendMsg(OUT_MSG_ID.CANCEL_SCANNER_SUBSCRIPTION, version, reqId); } /** * Encode a EXERCISE_OPTIONS message to an array of tokens. */ exerciseOptions(reqId, contract, exerciseAction, exerciseQuantity, account, override, manualOrderTime = "", customerAccount = "", professionalCustomer = false) { const version = 2; if (this.serverVersion < 21) { return this.emitError("It does not support options exercise from the API.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } if (this.serverVersion < min_server_version_1.default.TRADING_CLASS) { if (!!contract.tradingClass || contract.conId != undefined) { return this.emitError("It does not support conId and tradingClass parameters in exerciseOptions.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } } if (this.serverVersion < min_server_version_1.default.MANUAL_ORDER_TIME_EXERCISE_OPTIONS && manualOrderTime) { return this.emitError("It does not support manual order time parameter in exerciseOptions.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } if (this.serverVersion < min_server_version_1.default.CUSTOMER_ACCOUNT) { if (customerAccount) { return this.emitError("It does not support customer account parameter in exerciseOptions.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } } if (this.serverVersion < min_server_version_1.default.PROFESSIONAL_CUSTOMER) { if (professionalCustomer) { return this.emitError("It does not support professional customer parameter in exerciseOptions.", errorCode_1.ErrorCode.UPDATE_TWS, reqId); } } const tokens = [OUT_MSG_ID.EXERCISE_OPTIONS, version, reqId]; // send contract fields if (this.serverVersion >= min_server_version_1.default.TRADING_CLASS) { tokens.push(contract.conId); } tokens.push(contract.symbol); tokens.push(contract.secType); tokens.push(contract.lastTradeDateOrContractMonth); tokens.push(contract.strike); tokens.push(contract.right); tokens.push(contract.multiplier); tokens.push(contract.exchange); tokens.push(contract.currency); tokens.push(contract.localSymbol); if (this.serverVersion >= min_server_version_1.default.TRADING_CLASS) { tokens.push(contract.tradingClass); } tokens.push(exerciseAction); tokens.push(exerciseQuantity); tokens.push(account); tokens.push(override); if (this.serverVersion >= min_server_version_1.default.MANUAL_ORDER_TIME_EXERCISE_OPTIONS) { tokens.push(manualOrderTime); } if (this.serverVersion >= min_server_version_1.default.CUSTOMER_ACCOUNT) { tokens.push(customerAccount); } if (this.serverVersion >= min_server_version_1.default.PROFESSIONAL_CUSTOMER) { tokens.push(professionalCustomer); } this.sendMsg(tokens); } /** * Encode a PLACE_ORDER message to an array of tokens. */ placeOrder(id, contract, order) { if (this.serverVersion < min_server_version_1.default.SCALE_ORDERS) { if (order.scaleInitLevelSize !== undefined || order.scalePriceIncrement !== undefined) { return this.emitError("It does not support Scale orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SSHORT_COMBO_LEGS) { contract.comboLegs?.forEach((comboLeg) => { if (comboLeg.shortSaleSlot || !!comboLeg.designatedLocation) { return this.emitError("It does not support SSHORT flag for combo legs.", errorCode_1.ErrorCode.UPDATE_TWS, id); } }); } if (this.serverVersion < min_server_version_1.default.WHAT_IF_ORDERS) { if (order.whatIf) { return this.emitError("It does not support what-if orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.DELTA_NEUTRAL) { if (contract.deltaNeutralContract) { return this.emitError("It does not support delta-neutral orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SCALE_ORDERS2) { if (order.scaleSubsLevelSize !== undefined) { return this.emitError("It does not support Subsequent Level Size for Scale orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.ALGO_ORDERS) { if (order.algoStrategy) { return this.emitError("It does not support algo orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.NOT_HELD) { if (order.notHeld) { return this.emitError("It does not support notHeld parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SEC_ID_TYPE) { if (!!contract.secIdType || !!contract.secId) { return this.emitError("It does not support secIdType and secId parameters.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.PLACE_ORDER_CONID) { if (contract.conId != undefined) { return this.emitError("It does not support conId parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SSHORTX) { if (order.exemptCode !== -1) { return this.emitError("It does not support exemptCode parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SSHORTX) { contract.comboLegs?.forEach((comboLeg) => { if (comboLeg.exemptCode !== -1) { return this.emitError("It does not support exemptCode parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } }); } if (this.serverVersion < min_server_version_1.default.HEDGE_ORDERS) { if (order.hedgeType) { return this.emitError("It does not support hedge orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.OPT_OUT_SMART_ROUTING) { if (order.optOutSmartRouting) { return this.emitError("It does not support optOutSmartRouting parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.DELTA_NEUTRAL_CONID) { if (order.deltaNeutralConId != undefined || !!order.deltaNeutralSettlingFirm || !!order.deltaNeutralClearingAccount || !!order.deltaNeutralClearingIntent) { return this.emitError("It does not support deltaNeutral parameters: ConId, SettlingFirm, ClearingAccount, ClearingIntent.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.DELTA_NEUTRAL_OPEN_CLOSE) { if (!!order.deltaNeutralOpenClose || order.deltaNeutralShortSale || order.deltaNeutralShortSaleSlot != undefined || !!order.deltaNeutralDesignatedLocation) { return this.emitError("It does not support deltaNeutral parameters: OpenClose, ShortSale, ShortSaleSlot, DesignatedLocation.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SCALE_ORDERS3) { if (order.scalePriceIncrement != undefined && order.scalePriceIncrement !== undefined) { if (order.scalePriceAdjustValue !== undefined || order.scalePriceAdjustInterval !== undefined || order.scaleProfitOffset !== undefined || order.scaleAutoReset || order.scaleInitPosition !== undefined || order.scaleInitFillQty !== undefined || order.scaleRandomPercent) { return this.emitError("It does not support Scale order parameters: PriceAdjustValue, PriceAdjustInterval, ProfitOffset, AutoReset, InitPosition, InitFillQty and RandomPercent", errorCode_1.ErrorCode.UPDATE_TWS, id); } } } if (this.serverVersion < min_server_version_1.default.ORDER_COMBO_LEGS_PRICE && sec_type_1.default.BAG === contract.secType?.toUpperCase()) { order.orderComboLegs?.forEach((orderComboLeg) => { if (orderComboLeg.price !== undefined) { return this.emitError("It does not support per-leg prices for order combo legs.", errorCode_1.ErrorCode.UPDATE_TWS, id); } }); } if (this.serverVersion < min_server_version_1.default.TRAILING_PERCENT) { if (order.trailingPercent !== undefined) { return this.emitError("It does not support trailing percent parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.TRADING_CLASS) { if (contract.tradingClass) { return this.emitError("It does not support tradingClass parameters in placeOrder.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.SCALE_TABLE) { if (!!order.scaleTable || !!order.activeStartTime || !!order.activeStopTime) { return this.emitError("It does not support scaleTable, activeStartTime and activeStopTime parameters.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.ALGO_ID && !!order.algoId) { return this.emitError("It does not support algoId parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.SCALE_TABLE) { if (!!order.scaleTable || order.activeStartTime?.length || order.activeStopTime?.length) { return this.emitError("It does not support scaleTable, activeStartTime and activeStopTime parameters.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.ORDER_SOLICITED) { if (order.solicited) { return this.emitError("It does not support order solicited parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.MODELS_SUPPORT) { if (order.modelCode) { return this.emitError("It does not support model code parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.EXT_OPERATOR && !!order.extOperator) { return this.emitError("It does not support ext operator", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.SOFT_DOLLAR_TIER && (!!order.softDollarTier?.name || !!order.softDollarTier?.value)) { return this.emitError("It does not support soft dollar tier", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.CASH_QTY) { if (order.cashQty !== undefined) { return this.emitError("It does not support cash quantity parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.DECISION_MAKER && (!!order.mifid2DecisionMaker || !!order.mifid2DecisionAlgo)) { return this.emitError("It does not support MIFID II decision maker parameters", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.MIFID_EXECUTION && (!!order.mifid2ExecutionTrader || !!order.mifid2ExecutionAlgo)) { return this.emitError("It does not support MIFID II execution parameters", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.AUTO_PRICE_FOR_HEDGE && order.dontUseAutoPriceForHedge) { return this.emitError("It does not support don't use auto price for hedge parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.ORDER_CONTAINER && order.isOmsContainer) { return this.emitError("It does not support oms container parameter.", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.D_PEG_ORDERS && order.discretionaryUpToLimitPrice) { return this.emitError("It does not support D-Peg orders.", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.PRICE_MGMT_ALGO && order.usePriceMgmtAlgo != null) { return this.emitError("It does not support price management algo parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.DURATION && order.duration != undefined) { return this.emitError("It does not support duration attribute", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.POST_TO_ATS && order.postToAts != undefined) { return this.emitError("It does not support postToAts attribute", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.AUTO_CANCEL_PARENT && order.autoCancelParent != null) { return this.emitError("It does not support autoCancelParent attribute", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.ADVANCED_ORDER_REJECT && order.advancedErrorOverride != undefined) { return this.emitError("It does not support advanced error override attribute", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.MANUAL_ORDER_TIME && order.manualOrderTime?.length) { return this.emitError("It does not support manual order time attribute", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.PEGBEST_PEGMID_OFFSETS && (order.minTradeQty !== undefined || order.minCompeteSize !== undefined || order.competeAgainstBestOffset !== undefined || order.midOffsetAtWhole !== undefined || order.midOffsetAtHalf !== undefined)) { return this.emitError("It does not support PEG BEST / PEG MID order parameters: minTradeQty, minCompeteSize, competeAgainstBestOffset, midOffsetAtWhole and midOffsetAtHalf", errorCode_1.ErrorCode.UPDATE_TWS, id); } if (this.serverVersion < min_server_version_1.default.CUSTOMER_ACCOUNT) { if (order.customerAccount) { return this.emitError("It does not support customer account parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.PROFESSIONAL_CUSTOMER) { if (order.professionalCustomer) { return this.emitError("It does not support professional customer parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.INCLUDE_OVERNIGHT) { if (order.includeOvernight) { return this.emitError("It does not support include overnight parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } } if (this.serverVersion < min_server_version_1.default.CME_TAGGING_FIELDS) { if (order.manualOrderIndicator) { return this.emitError("It does not support manual order indicator parameter", errorCode_1.ErrorCode.UPDATE_TWS, id); } } const version = this.serverVersion < min_server_version_1.default.NOT_HELD ? 27 : 45; // send place order msg const tokens = [OUT_MSG_ID.PLACE_ORDER]; if (this.serverVersion < min_server_version_1.default.ORDER_CONTAINER) { tokens.push(version); } tokens.push(id); // send contract fields if (this.serverVersion >= min_server_version_1.default.PLACE_ORDER_CONID) { tokens.push(contract.conId); } tokens.push(contract.symbol); tokens.push(contract.secType); tokens.push(contract.lastTradeDateOrContractMonth); tokens.push(contract.strike); tokens.push(contract.right); if (this.serverVersion >= 15) { tokens.push(contract.multiplier); } tokens.push(contract.exchange); if (this.serverVersion >= 14) { tokens.push(contract.primaryExch); } tokens.push(contract.currency); if (this.serverVersion >= 2) { tokens.push(contract.localSymbol); } if (this.serverVersion >= min_server_version_1.default.TRADING_CLASS) { tokens.push(contract.tradingClass); } if (this.serverVersion >= min_server_version_1.default.SEC_ID_TYPE) { tokens.push(contract.secIdType); tokens.push(contract.secId); } // send main order fields tokens.push(order.action); if (this.serverVersion >= min_server_version_1.default.FRACTIONAL_POSITIONS) { tokens.push(order.totalQuantity); } else { tokens.push(order.totalQuantity ? Math.round(order.totalQuantity) : undefined); } tokens.push(order.orderType); if (this.serverVersion < min_server_version_1.default.ORDER_COMBO_LEGS_PRICE) { tokens.push(order.lmtPrice ?? 0); } else { tokens.push(nullifyMax(order.lmtPrice)); } if (this.serverVersion < min_server_version_1.default.TRAILING_PERCENT) { tokens.push(order.auxPrice ?? 0); } else { tokens.push(nullifyMax(order.auxPrice)); } // send extended order fields tokens.push(order.tif); tokens.push(order.ocaGroup); tokens.push(order.account); tokens.push(order.openClose); tokens.push(order.origin); tokens.push(order.orderRef); tokens.push(order.transmit); if (this.serverVersion >= 4) { tokens.push(order.parentId); } if (this.serverVersion >= 5) { tokens.push(order.blockOrder); tokens.push(order.sweepToFill); tokens.push(order.displaySize); tokens.push(order.triggerMethod); if (this.serverVersion < 38) { // will never happen tokens.push(/* order.ignoreRth */ false); } else { tokens.push(order.outsideRth); } } if (this.serverVersion >= 7) { tokens.push(order.hidden); } // Send combo legs for BAG requests if (this.serverVersion >= 8 && sec_type_1.default.BAG === contract.secType?.toUpperCase()) { if (!contract.comboLegs?.length) { tokens.push(0); } else { tokens.push(contract.comboLegs.length); contract.comboLegs.forEach((comboLeg) => { tokens.push(comboLeg.conId); tokens.push(comboLeg.ratio); tokens.push(comboLeg.action); tokens.push(comboLeg.exchange); tokens.push(comboLeg.openClose); if (this.serverVersion >= min_server_version_1.default.SSHORT_COMBO_LEGS) { tokens.push(comboLeg.shortSaleSlot); tokens.push(comboLeg.designatedLocation); } if (this.serverVersion >= min_server_version_1.default.SSHORTX_OLD) { tokens.push(comboLeg.exemptCode); } }); } } // Send order combo legs for BAG requests if (this.serverVersion >= min_server_version_1.default.ORDER_COMBO_LEGS_PRICE && sec_type_1.default.BAG === contract.secType?.toUpperCase()) { if (!order.orderComboLegs?.length) { tokens.push(0); } else { tokens.push(order.orderComboLegs.length); order.orderComboLegs.forEach(function (orderComboLeg) { tokens.push(nullifyMax(orderComboLeg.price)); }); } } if (this.serverVersion >= min_server_version_1.default.SMART_COMBO_ROUTING_PARAMS && sec_type_1.default.BAG === contract.secType?.toUpperCase()) { const smartComboRoutingParamsCount = !order.smartComboRoutingParams ? 0 : order.smartComboRoutingParams.length; tokens.push(smartComboRoutingParamsCount); if (smartComboRoutingParamsCount > 0) { order.smartComboRoutingParams?.forEach((param) => { tokens.push(param.tag); tokens.push(param.value); }); } } if (this.serverVersion >= 9) { // send deprecated sharesAllocation field tokens.push(""); } if (this.serverVersion >= 10) { tokens.push(order.discretionaryAmt); } if (this.serverVersion >= 11) { tokens.push(order.goodAfterTime); } if (this.serverVersion >= 12) { tokens.push(order.goodTillDate); } if (this.serverVersion >= 13) { // srv v13 and above tokens.push(order.faGroup); tokens.push(order.faMethod); tokens.push(order.faPercentage); if (this.serverVersion < min_server_version_1.default.FA_PROFILE_DESUPPORT) tokens.push(""); // send deprecated faProfile field } if (this.serverVersion >= min_server_version_1.default.MODELS_SUPPORT) { tokens.push(order.modelCode); } if (this.serverVersion >= 18) { // institutional short sale slot fields. tokens.push(order.shortSaleSlot); // 0 only for retail, 1 or 2 only for institution. tokens.push(order.designatedLocation); // only populate when order.shortSaleSlot = 2. } if (this.serverVersion >= min_server_version_1.default.SSHORTX_OLD) { tokens.push(order.exemptCode); } if (this.serverVersion >= 19) { tokens.push(order.ocaType); if (this.serverVersion < 38) { // will never happen tokens.push(/* order.rthOnly */ false); } tokens.push(order.rule80A); tokens.push(order.settlingFirm); tokens.push(order.allOrNone); tokens.push(nullifyMax(order.minQty)); tokens.push(nullifyMax(order.percentOffset)); tokens.push(order.eTradeOnly); tokens.push(order.firmQuoteOnly); tokens.push(nullifyMax(order.nbboPriceCap)); tokens.push(nullifyMax(order.auctionStrategy)); tokens.push(nullifyMax(order.startingPrice)); tokens.push(nullifyMax(order.stockRefPrice)); tokens.push(nullifyMax(order.delta)); // Volatility orders had specific watermark price attribs in server version 26 const lower = this.serverVersion === 26 && (0, orderType_1.isVolOrder)(order.orderType) ? undefined : order.stockRangeLower; const upper = this.serverVersion === 26 && (0, orderType_1.isVolOrder)(order.orderType) ? undefined : order.stockRangeUpper; tokens.push(lower); tokens.push(upper); } if (this.serverVersion >= 22) { tokens.push(order.overridePercentageConstraints); } if (this.serverVersion >= 26) { // Volatility orders tokens.push(nullifyMax(order.volatility)); tokens.push(nullifyMax(order.volatilityType)); if (this.serverVersion < 28) { tokens.push(order.deltaNeutralOrderType?.toUpperCase() === "MKT"); } else { tokens.push(order.deltaNeutralOrderType); tokens.push(nullifyMax(order.deltaNeutralAuxPrice)); if (this.serverVersion >= min_server_version_1.default.DELTA_NEUTRAL_CONID && !!order.deltaNeutralOrderType) { tokens.push(order.deltaNeutralConId); tokens.push(order.deltaNeutralSettlingFirm); tokens.push(order.deltaNeutralClearingAccount); tokens.push(order.deltaNeutralClearingIntent); } if (this.serverVersion >= min_server_version_1.default.DELTA_NEUTRAL_OPEN_CLOSE && !!order.deltaNeutralOrderType) { tokens.push(order.deltaNeutralOpenClose); tokens.push(order.deltaNeutralShortSale); tokens.push(order.deltaNeutralShortSaleSlot); tokens.push(order.deltaNeutralDesignatedLocation); } } tokens.push(order.continuousUpdate); if (this.serverVersion === 26) { // Volatility orders had specific watermark price attribs in server version 26 const lower = (0, orderType_1.isVolOrder)(order.orderType) ? order.stockRangeLower : undefined; const upper = (0, orderType_1.isVolOrder)(order.orderType) ? order.stockRangeUpper : undefined; tokens.push(nullifyMax(lower)); tokens.push(nullifyMax(upper)); } tokens.push(nullifyMax(order.referencePriceType)); } if (this.serverVersion >= 30) { // TRAIL_STOP_LIMIT stop price tokens.push(nullifyMax(order.trailStopPrice)); } if (this.serverVersion >= min_server_version_1.default.TRAILING_PERCENT) { tokens.push(nullifyMax(order.trailingPercent)); } if (this.serverVersion >= min_server_version_1.default.SCALE_ORDERS) { if (this.serverVersion >= min_server_version_1.default.SCALE_ORDERS2) { tokens.push(nullifyMax(order.scaleInitLevelSize)); tokens.push(nullifyMax(order.scaleSubsLevelSize)); } else { tokens.push(""); tokens.push(nullifyMax(order.scaleInitLevelSize)); } tokens.push(nullifyMax(order.scalePriceIncrement)); } if (this.serverVersion >= min_server_version_1.default.SCALE_ORDERS3 && order.scalePriceIncrement !== undefined) { tokens.push(nullifyMax(order.scalePriceAdjustValue)); tokens.push(nullifyMax(order.scalePriceAdjustInterval)); tokens.push(nullifyMax(order.scaleProfitOffset)); tokens.push(order.scaleAutoReset); tokens.push(nullifyMax(order.scaleInitPosition)); tokens.push(nullifyMax(order.scaleInitFillQty)); tokens.push(order.scaleRandomPercent); } if (this.serverVersion >= min_server_version_1.default.SCALE_TABLE) { tokens.push(order.scaleTable); tokens.push(order.activeStartTime); tokens.push(order.activeStopTime); } if (this.serverVersion >= min_server_version_1.default.HEDGE_ORDERS) { tokens.push(order.hedgeType); if (order.hedgeType) { tokens.push(order.hedgeParam); } } if (this.serverVersion >= min_server_version_1.default.OPT_OUT_SMART_ROUTING) { tokens.push(order.optOutSmartRouting); } if (this.serverVersion >= min_server_version_1.default.PTA_ORDERS) { tokens.push(order.clearingAccount); tokens.push(order.clearingIntent); } if (this.serverVersion >= min_server_version_1.default.NOT_HELD) { tokens.push(order.notHeld); } if (this.serverVersion >= min_server_version_1.default.DELTA_NEUTRAL) { if (contract.deltaNeutralContract) { tokens.push(true); tokens.push(contract.deltaNeutralContract.