From 6f17626fbd6533c270a6ee3abc72f326ce306471 Mon Sep 17 00:00:00 2001 From: amit21 Date: Mon, 4 Feb 2019 19:18:15 +0200 Subject: [PATCH 1/2] added 2 news functions reqNewsProviders reqHistoricalNews --- lib/controller.js | 2 +- lib/incoming.js | 2348 +++++++++++++++++++++++---------------------- lib/index.js | 9 + lib/outgoing.js | 2250 ++++++++++++++++++++++--------------------- 4 files changed, 2338 insertions(+), 2271 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index efe1bc2..3d0ddec 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -44,6 +44,7 @@ Controller.prototype._api = function (data) { if (_.has(this._outgoing.constructor.prototype, data.func)) { func = this._outgoing[data.func]; if (_.isFunction(func)) { + // console.log('data.func',data.func) return func.apply(this._outgoing, data.args); } } @@ -57,7 +58,6 @@ Controller.prototype._connect = function () { this.emitError('Cannot connect if already connected.'); } }; - Controller.prototype._disconnect = function () { if (this._socket._connected) { this._socket.disconnect(); diff --git a/lib/incoming.js b/lib/incoming.js index 6e1127a..85a6e5b 100644 --- a/lib/incoming.js +++ b/lib/incoming.js @@ -4,1463 +4,1511 @@ var C = require('./constants'); var errors = require('./errors'); function Incoming(controller) { - this._controller = controller; + this._controller = controller; - this._dataQueue = []; - this._emitQueue = []; + this._dataQueue = []; + this._emitQueue = []; } Incoming.prototype._ACCT_DOWNLOAD_END = function () { - var version = this.dequeueInt(); - var accountName = this.dequeue(); + var version = this.dequeueInt(); + var accountName = this.dequeue(); - this._emit('accountDownloadEnd', accountName); + this._emit('accountDownloadEnd', accountName); }; Incoming.prototype._ACCOUNT_SUMMARY = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var account = this.dequeue(); - var tag = this.dequeue(); - var value = this.dequeue(); - var currency = this.dequeue(); - - this._emit('accountSummary', reqId, account, tag, value, currency); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var account = this.dequeue(); + var tag = this.dequeue(); + var value = this.dequeue(); + var currency = this.dequeue(); + + this._emit('accountSummary', reqId, account, tag, value, currency); }; Incoming.prototype._ACCOUNT_UPDATE_MULTI_END = function () { - var version = this.dequeueInt(); - var reqId = this.dequeue(); + var version = this.dequeueInt(); + var reqId = this.dequeue(); - this._emit('accountUpdateMultiEnd', reqId); + this._emit('accountUpdateMultiEnd', reqId); }; Incoming.prototype._ACCOUNT_UPDATE_MULTI = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var account = this.dequeue(); - var modelCode = this.dequeue(); - var key = this.dequeue(); - var value = this.dequeue(); - var currency = this.dequeue(); - - this._emit('accountUpdateMulti', reqId, account, modelCode, key, value, currency); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var account = this.dequeue(); + var modelCode = this.dequeue(); + var key = this.dequeue(); + var value = this.dequeue(); + var currency = this.dequeue(); + + this._emit('accountUpdateMulti', reqId, account, modelCode, key, value, currency); }; Incoming.prototype._ACCOUNT_SUMMARY_END = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); - this._emit('accountSummaryEnd', reqId); + this._emit('accountSummaryEnd', reqId); }; Incoming.prototype._ACCT_UPDATE_TIME = function () { - var version = this.dequeueInt(); - var timeStamp = this.dequeue(); + var version = this.dequeueInt(); + var timeStamp = this.dequeue(); - this._emit('updateAccountTime', timeStamp); + this._emit('updateAccountTime', timeStamp); }; Incoming.prototype._ACCT_VALUE = function () { - var version = this.dequeueInt(); - var key = this.dequeue(); - var value = this.dequeue(); - var currency = this.dequeue(); - var accountName = null; + var version = this.dequeueInt(); + var key = this.dequeue(); + var value = this.dequeue(); + var currency = this.dequeue(); + var accountName = null; - if (version >= 2) { - accountName = this.dequeue(); - } + if (version >= 2) { + accountName = this.dequeue(); + } - this._emit('updateAccountValue', key, value, currency, accountName); + this._emit('updateAccountValue', key, value, currency, accountName); }; Incoming.prototype._COMMISSION_REPORT = function () { - var version = this.dequeueInt(); + var version = this.dequeueInt(); - var commissionReport = {}; - commissionReport.execId = this.dequeue(); - commissionReport.commission = this.dequeueFloat(); - commissionReport.currency = this.dequeue(); - commissionReport.realizedPNL = this.dequeueFloat(); - commissionReport.yield = this.dequeueFloat(); - commissionReport.yieldRedemptionDate = this.dequeueInt(); + var commissionReport = {}; + commissionReport.execId = this.dequeue(); + commissionReport.commission = this.dequeueFloat(); + commissionReport.currency = this.dequeue(); + commissionReport.realizedPNL = this.dequeueFloat(); + commissionReport.yield = this.dequeueFloat(); + commissionReport.yieldRedemptionDate = this.dequeueInt(); - this._emit('commissionReport', commissionReport); + this._emit('commissionReport', commissionReport); }; Incoming.prototype._BOND_CONTRACT_DATA = function () { - var version = this.dequeueInt(); - var reqId = -1; - var i; - - if (version >= 3) { - reqId = this.dequeueInt(); - } - - var contract = { - summary: {} - }; - - contract.summary.symbol = this.dequeue(); - contract.summary.secType = this.dequeue(); - contract.cusip = this.dequeue(); - contract.coupon = this.dequeueFloat(); - contract.maturity = this.dequeue(); - contract.issueDate = this.dequeue(); - contract.ratings = this.dequeue(); - contract.bondType = this.dequeue(); - contract.couponType = this.dequeue(); - contract.convertible = this.dequeueBool(); - contract.callable = this.dequeueBool(); - contract.putable = this.dequeueBool(); - contract.descAppend = this.dequeue(); - contract.summary.exchange = this.dequeue(); - contract.summary.currency = this.dequeue(); - contract.marketName = this.dequeue(); - contract.summary.tradingClass = this.dequeue(); - contract.summary.conId = this.dequeueInt(); - contract.minTick = this.dequeueFloat(); - contract.orderTypes = this.dequeue(); - contract.validExchanges = this.dequeue(); - - if (version >= 2) { - contract.nextOptionDate = this.dequeue(); - contract.nextOptionType = this.dequeue(); - contract.nextOptionPartial = this.dequeueBool(); - contract.notes = this.dequeue(); - } - - if(version >= 4) { - contract.longName = this.dequeue(); - } - - if (version >= 6) { - contract.evRule = this.dequeue(); - contract.evMultiplier = this.dequeueFloat(); - } - - var secIdListCount; - var tagValue; - - if (version >= 5) { - secIdListCount = this.dequeueInt(); - - if (secIdListCount > 0) { - contract.secIdList = []; - - while (secIdListCount--) { - tagValue = {}; - tagValue.tag = this.dequeue(); - tagValue.value = this.dequeue(); - contract.secIdList.push(tagValue); - } - } - } - - this._emit('bondContractDetails', reqId, contract); + var version = this.dequeueInt(); + var reqId = -1; + var i; + + if (version >= 3) { + reqId = this.dequeueInt(); + } + + var contract = { + summary: {} + }; + + contract.summary.symbol = this.dequeue(); + contract.summary.secType = this.dequeue(); + contract.cusip = this.dequeue(); + contract.coupon = this.dequeueFloat(); + contract.maturity = this.dequeue(); + contract.issueDate = this.dequeue(); + contract.ratings = this.dequeue(); + contract.bondType = this.dequeue(); + contract.couponType = this.dequeue(); + contract.convertible = this.dequeueBool(); + contract.callable = this.dequeueBool(); + contract.putable = this.dequeueBool(); + contract.descAppend = this.dequeue(); + contract.summary.exchange = this.dequeue(); + contract.summary.currency = this.dequeue(); + contract.marketName = this.dequeue(); + contract.summary.tradingClass = this.dequeue(); + contract.summary.conId = this.dequeueInt(); + contract.minTick = this.dequeueFloat(); + contract.orderTypes = this.dequeue(); + contract.validExchanges = this.dequeue(); + + if (version >= 2) { + contract.nextOptionDate = this.dequeue(); + contract.nextOptionType = this.dequeue(); + contract.nextOptionPartial = this.dequeueBool(); + contract.notes = this.dequeue(); + } + + if (version >= 4) { + contract.longName = this.dequeue(); + } + + if (version >= 6) { + contract.evRule = this.dequeue(); + contract.evMultiplier = this.dequeueFloat(); + } + + var secIdListCount; + var tagValue; + + if (version >= 5) { + secIdListCount = this.dequeueInt(); + + if (secIdListCount > 0) { + contract.secIdList = []; + + while (secIdListCount--) { + tagValue = {}; + tagValue.tag = this.dequeue(); + tagValue.value = this.dequeue(); + contract.secIdList.push(tagValue); + } + } + } + + this._emit('bondContractDetails', reqId, contract); }; Incoming.prototype._CONTRACT_DATA = function () { - var version = this.dequeueInt(); - var reqId = -1; - - if (version >= 3) { - reqId = this.dequeueInt(); - } - - var contract = { - summary: {} - }; - - contract.summary.symbol = this.dequeue(); - contract.summary.secType = this.dequeue(); - contract.summary.expiry = this.dequeue(); - contract.summary.strike = this.dequeueFloat(); - contract.summary.right = this.dequeue(); - contract.summary.exchange = this.dequeue(); - contract.summary.currency = this.dequeue(); - contract.summary.localSymbol = this.dequeue(); - contract.marketName = this.dequeue(); - contract.summary.tradingClass = this.dequeue(); - contract.summary.conId = this.dequeueInt(); - contract.minTick = this.dequeueFloat(); - contract.summary.multiplier = this.dequeue(); - contract.orderTypes = this.dequeue(); - contract.validExchanges = this.dequeue(); - - if (version >= 2) { - contract.priceMagnifier = this.dequeueInt(); - } - - if (version >= 4) { - contract.underConId = this.dequeueInt(); - } - - if (version >= 5) { - contract.longName = this.dequeue(); - contract.summary.primaryExch = this.dequeue(); - } - - if (version >= 6) { - contract.contractMonth = this.dequeue(); - contract.industry = this.dequeue(); - contract.category = this.dequeue(); - contract.subcategory = this.dequeue(); - contract.timeZoneId = this.dequeue(); - contract.tradingHours = this.dequeue(); - contract.liquidHours = this.dequeue(); - } - - if (version >= 8) { - contract.evRule = this.dequeue(); - contract.evMultiplier = this.dequeueFloat(); - } - - var secIdListCount; - var tagValue; - var i; - - if (version >= 7) { - secIdListCount = this.dequeueInt(); - if (secIdListCount > 0) { - contract.secIdList = []; - for (i = 0; i < secIdListCount; ++i) { - tagValue = {}; - tagValue.tag = this.dequeue(); - tagValue.value = this.dequeue(); - contract.secIdList.push(tagValue); - } - } - } - - this._emit('contractDetails', reqId, contract); + var version = this.dequeueInt(); + var reqId = -1; + + if (version >= 3) { + reqId = this.dequeueInt(); + } + + var contract = { + summary: {} + }; + + contract.summary.symbol = this.dequeue(); + contract.summary.secType = this.dequeue(); + contract.summary.expiry = this.dequeue(); + contract.summary.strike = this.dequeueFloat(); + contract.summary.right = this.dequeue(); + contract.summary.exchange = this.dequeue(); + contract.summary.currency = this.dequeue(); + contract.summary.localSymbol = this.dequeue(); + contract.marketName = this.dequeue(); + contract.summary.tradingClass = this.dequeue(); + contract.summary.conId = this.dequeueInt(); + contract.minTick = this.dequeueFloat(); + contract.summary.multiplier = this.dequeue(); + contract.orderTypes = this.dequeue(); + contract.validExchanges = this.dequeue(); + + if (version >= 2) { + contract.priceMagnifier = this.dequeueInt(); + } + + if (version >= 4) { + contract.underConId = this.dequeueInt(); + } + + if (version >= 5) { + contract.longName = this.dequeue(); + contract.summary.primaryExch = this.dequeue(); + } + + if (version >= 6) { + contract.contractMonth = this.dequeue(); + contract.industry = this.dequeue(); + contract.category = this.dequeue(); + contract.subcategory = this.dequeue(); + contract.timeZoneId = this.dequeue(); + contract.tradingHours = this.dequeue(); + contract.liquidHours = this.dequeue(); + } + + if (version >= 8) { + contract.evRule = this.dequeue(); + contract.evMultiplier = this.dequeueFloat(); + } + + var secIdListCount; + var tagValue; + var i; + + if (version >= 7) { + secIdListCount = this.dequeueInt(); + if (secIdListCount > 0) { + contract.secIdList = []; + for (i = 0; i < secIdListCount; ++i) { + tagValue = {}; + tagValue.tag = this.dequeue(); + tagValue.value = this.dequeue(); + contract.secIdList.push(tagValue); + } + } + } + + this._emit('contractDetails', reqId, contract); }; Incoming.prototype._CONTRACT_DATA_END = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); - this._emit('contractDetailsEnd', reqId); + this._emit('contractDetailsEnd', reqId); }; Incoming.prototype._CURRENT_TIME = function () { - var version = this.dequeueInt(); - var time = this.dequeueInt(); + var version = this.dequeueInt(); + var time = this.dequeueInt(); - this._emit('currentTime', time); + this._emit('currentTime', time); }; Incoming.prototype._DELTA_NEUTRAL_VALIDATION = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); - var underComp = {}; - underComp.conId = this.dequeueInt(); - underComp.delta = this.dequeueFloat(); - underComp.price = this.dequeueFloat(); + var underComp = {}; + underComp.conId = this.dequeueInt(); + underComp.delta = this.dequeueFloat(); + underComp.price = this.dequeueFloat(); - this._emit('deltaNeutralValidation', reqId, underComp); + this._emit('deltaNeutralValidation', reqId, underComp); }; Incoming.prototype._ERR_MSG = function () { - var errorCode; - var errorMsg; - var id; - var version = this.dequeueInt(); - - if (version < 2) { - errorMsg = this.dequeue(); - this._controller.emitError(errorMsg); - } else { - id = this.dequeueInt(); - errorCode = this.dequeueInt(); - errorMsg = this.dequeue(); - this._controller.emitError(errorMsg, { - id: id, - code: errorCode - }); - } + var errorCode; + var errorMsg; + var id; + var version = this.dequeueInt(); + + if (version < 2) { + errorMsg = this.dequeue(); + this._controller.emitError(errorMsg); + } else { + id = this.dequeueInt(); + errorCode = this.dequeueInt(); + errorMsg = this.dequeue(); + this._controller.emitError(errorMsg, { + id: id, + code: errorCode + }); + } }; Incoming.prototype._EXECUTION_DATA = function () { - var version = this.dequeueInt(); + var version = this.dequeueInt(); + + var reqId = -1; - var reqId = -1; + if (version >= 7) { + reqId = this.dequeueInt(); + } - if (version >= 7) { - reqId = this.dequeueInt(); - } + var orderId = this.dequeueInt(); - var orderId = this.dequeueInt(); + // read contract fields + var contract = {}; - // read contract fields - var contract = {}; + if (version >= 5) { + contract.conId = this.dequeueInt(); + } - if (version >= 5) { - contract.conId = this.dequeueInt(); - } + contract.symbol = this.dequeue(); + contract.secType = this.dequeue(); + contract.expiry = this.dequeue(); + contract.strike = this.dequeueFloat(); + contract.right = this.dequeue(); - contract.symbol = this.dequeue(); - contract.secType = this.dequeue(); - contract.expiry = this.dequeue(); - contract.strike = this.dequeueFloat(); - contract.right = this.dequeue(); + if (version >= 9) { + contract.multiplier = this.dequeue(); + } - if (version >= 9) { - contract.multiplier = this.dequeue(); - } + contract.exchange = this.dequeue(); + contract.currency = this.dequeue(); + contract.localSymbol = this.dequeue(); + + if (version >= 10) { + contract.tradingClass = this.dequeue(); + } - contract.exchange = this.dequeue(); - contract.currency = this.dequeue(); - contract.localSymbol = this.dequeue(); + var exec = {}; - if (version >= 10) { - contract.tradingClass = this.dequeue(); - } - - var exec = {}; - - exec.orderId = orderId; - exec.execId = this.dequeue(); - exec.time = this.dequeue(); - exec.acctNumber = this.dequeue(); - exec.exchange = this.dequeue(); - exec.side = this.dequeue(); - exec.shares = this.dequeue(); - exec.price = this.dequeueFloat(); - - if (version >= 2) { - exec.permId = this.dequeueInt(); - } - - if (version >= 3) { - exec.clientId = this.dequeueInt(); - } - - if (version >= 4) { - exec.liquidation = this.dequeueInt(); - } - - if (version >= 6) { - exec.cumQty = this.dequeueInt(); - exec.avgPrice = this.dequeueFloat(); - } - - if (version >= 8) { - exec.orderRef = this.dequeue(); - } - - if (version >= 9) { - exec.evRule = this.dequeue(); - exec.evMultiplier = this.dequeueFloat(); - } - - this._emit('execDetails', reqId, contract, exec); + exec.orderId = orderId; + exec.execId = this.dequeue(); + exec.time = this.dequeue(); + exec.acctNumber = this.dequeue(); + exec.exchange = this.dequeue(); + exec.side = this.dequeue(); + exec.shares = this.dequeue(); + exec.price = this.dequeueFloat(); + + if (version >= 2) { + exec.permId = this.dequeueInt(); + } + + if (version >= 3) { + exec.clientId = this.dequeueInt(); + } + + if (version >= 4) { + exec.liquidation = this.dequeueInt(); + } + + if (version >= 6) { + exec.cumQty = this.dequeueInt(); + exec.avgPrice = this.dequeueFloat(); + } + + if (version >= 8) { + exec.orderRef = this.dequeue(); + } + + if (version >= 9) { + exec.evRule = this.dequeue(); + exec.evMultiplier = this.dequeueFloat(); + } + + this._emit('execDetails', reqId, contract, exec); }; Incoming.prototype._EXECUTION_DATA_END = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); - this._emit('execDetailsEnd', reqId); + this._emit('execDetailsEnd', reqId); }; Incoming.prototype._FUNDAMENTAL_DATA = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var data = this.dequeue(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var data = this.dequeue(); - this._emit('fundamentalData', reqId, data); + this._emit('fundamentalData', reqId, data); }; Incoming.prototype._HISTORICAL_DATA = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var completedIndicator = 'finished'; - var startDateStr; - var endDateStr; - - if (version >= 2) { - startDateStr = this.dequeue(); - endDateStr = this.dequeue(); - completedIndicator += '-' + startDateStr + '-' + endDateStr; - } - - var itemCount = this.dequeueInt(); - var date; - var open; - var high; - var low; - var close; - var volume; - var WAP; - var hasGaps; - var barCount; - - while (itemCount--) { - date = this.dequeue(); - open = this.dequeueFloat(); - high = this.dequeueFloat(); - low = this.dequeueFloat(); - close = this.dequeueFloat(); - volume = this.dequeueInt(); - WAP = this.dequeueFloat(); - hasGaps = this.dequeueBool(); - barCount = -1; + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var completedIndicator = 'finished'; + var startDateStr; + var endDateStr; - if (version >= 3) { - barCount = this.dequeueInt(); + if (version >= 2) { + startDateStr = this.dequeue(); + endDateStr = this.dequeue(); + completedIndicator += '-' + startDateStr + '-' + endDateStr; } - this._emit('historicalData', reqId, date, open, high, low, close, volume, barCount, WAP, hasGaps); - } + var itemCount = this.dequeueInt(); + var date; + var open; + var high; + var low; + var close; + var volume; + var WAP; + var hasGaps; + var barCount; + + while (itemCount--) { + date = this.dequeue(); + open = this.dequeueFloat(); + high = this.dequeueFloat(); + low = this.dequeueFloat(); + close = this.dequeueFloat(); + volume = this.dequeueInt(); + WAP = this.dequeueFloat(); + hasGaps = this.dequeueBool(); + barCount = -1; + + if (version >= 3) { + barCount = this.dequeueInt(); + } - // send end of dataset marker - this._emit('historicalData', reqId, completedIndicator, -1, -1, -1, -1, -1, -1, -1, false); + this._emit('historicalData', reqId, date, open, high, low, close, volume, barCount, WAP, hasGaps); + } + + // send end of dataset marker + this._emit('historicalData', reqId, completedIndicator, -1, -1, -1, -1, -1, -1, -1, false); }; -Incoming.prototype._HISTORICAL_TICKS_LAST = function() { - var reqId = this.dequeueInt(); - var tickCount = this.dequeueInt(); - - var date; - var mask; - var price; - var size; - var exchange; - var specialConditions; - - while (tickCount--) { - date = this.dequeue(); - mask = this.dequeueInt(); - price = this.dequeueFloat(); - size = this.dequeueInt(); - exchange = this.dequeue(); - specialConditions = this.dequeue(); - - this._emit('historicalTickTradeData', reqId, date, mask, price, size, exchange, specialConditions); - } - - var done = this.dequeueBool(); - - if (done) { - this._emit('historicalTickDataEnd', reqId); - } +Incoming.prototype._HISTORICAL_TICKS_LAST = function () { + var reqId = this.dequeueInt(); + var tickCount = this.dequeueInt(); + + var date; + var mask; + var price; + var size; + var exchange; + var specialConditions; + + while (tickCount--) { + date = this.dequeue(); + mask = this.dequeueInt(); + price = this.dequeueFloat(); + size = this.dequeueInt(); + exchange = this.dequeue(); + specialConditions = this.dequeue(); + + this._emit('historicalTickTradeData', reqId, date, mask, price, size, exchange, specialConditions); + } + + var done = this.dequeueBool(); + + if (done) { + this._emit('historicalTickDataEnd', reqId); + } }; -Incoming.prototype._HISTORICAL_TICKS_BID_ASK = function() { - var reqId = this.dequeueInt(); - var tickCount = this.dequeueInt(); - - var date; - var mask; - var priceBid; - var sizeBid; - var priceAsk; - var sizeAsk; - - while (tickCount--) { - date = this.dequeue(); - mask = this.dequeueInt(); - priceBid = this.dequeueFloat(); - priceAsk = this.dequeueFloat(); - sizeBid = this.dequeueInt(); - sizeAsk = this.dequeueInt(); - this._emit('historicalTickBidAskData', reqId, date, mask, priceBid, priceAsk, sizeBid, sizeAsk); - } - - var done = this.dequeueBool(); - - if (done) { - this._emit('historicalTickDataEnd', reqId); - } +Incoming.prototype._HISTORICAL_TICKS_BID_ASK = function () { + var reqId = this.dequeueInt(); + var tickCount = this.dequeueInt(); + + var date; + var mask; + var priceBid; + var sizeBid; + var priceAsk; + var sizeAsk; + + while (tickCount--) { + date = this.dequeue(); + mask = this.dequeueInt(); + priceBid = this.dequeueFloat(); + priceAsk = this.dequeueFloat(); + sizeBid = this.dequeueInt(); + sizeAsk = this.dequeueInt(); + this._emit('historicalTickBidAskData', reqId, date, mask, priceBid, priceAsk, sizeBid, sizeAsk); + } + + var done = this.dequeueBool(); + + if (done) { + this._emit('historicalTickDataEnd', reqId); + } }; -Incoming.prototype._HISTORICAL_TICKS = function() { // MIDPOINT (size appears to always be zero) - var reqId = this.dequeueInt(); - var tickCount = this.dequeueInt(); +Incoming.prototype._HISTORICAL_TICKS = function () { // MIDPOINT (size appears to always be zero) + var reqId = this.dequeueInt(); + var tickCount = this.dequeueInt(); - var date; - var price; - var size; + var date; + var price; + var size; - while (tickCount--) { - date = this.dequeue(); - this.dequeueInt();//for consistency - price = this.dequeueFloat(); - size = this.dequeueInt(); - - this._emit('historicalTickMidPointData', reqId, date, price, size); - } + while (tickCount--) { + date = this.dequeue(); + this.dequeueInt();//for consistency + price = this.dequeueFloat(); + size = this.dequeueInt(); - var done = this.dequeueBool(); + this._emit('historicalTickMidPointData', reqId, date, price, size); + } + + var done = this.dequeueBool(); - if (done) { - this._emit('historicalTickDataEnd', reqId); - } + if (done) { + this._emit('historicalTickDataEnd', reqId); + } }; Incoming.prototype._TICK_BY_TICK = function () { - var reqId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var time = this.dequeue(); - - var mask; - - switch (tickType){ - case 0: // None - break; - case 1: // Last - case 2: // Alllast - var price = this.dequeueFloat(); - var size = this.dequeueInt(); - mask = this.dequeueInt(); - var pastLimit = (mask & (1 << 0)) !== 0; - var unreported = (mask & (1 << 1)) !== 0; - var exchange = this.dequeue(); - var specialConditions = this.dequeue(); - - this._emit('tickByTickAllLast', reqId, tickType, time, price, size, { pastLimit, unreported }, exchange, specialConditions); - break; - case 3: // BidAsk - var bidPrice = this.dequeueFloat(); - var askPrice = this.dequeueFloat(); - var bidSize = this.dequeueInt(); - var askSize = this.dequeueInt(); - mask = this.dequeueInt(); - var bidPastLow = (mask & (1 << 0)) !== 0; - var askPastHigh = (mask & (1 << 1)) !== 0; - - this._emit('tickByTickBidAsk', reqId, time, bidPrice, askPrice, bidSize, askSize, { bidPastLow, askPastHigh }); - break; - case 4: // MidPoint - var midPoint = this.dequeueFloat(); - - this._emit('tickByTickMidPoint', reqId, time, midPoint); - break; - } + var reqId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var time = this.dequeue(); + + var mask; + + switch (tickType) { + case 0: // None + break; + case 1: // Last + case 2: // Alllast + var price = this.dequeueFloat(); + var size = this.dequeueInt(); + mask = this.dequeueInt(); + var pastLimit = (mask & (1 << 0)) !== 0; + var unreported = (mask & (1 << 1)) !== 0; + var exchange = this.dequeue(); + var specialConditions = this.dequeue(); + + this._emit('tickByTickAllLast', reqId, tickType, time, price, size, { + pastLimit, + unreported + }, exchange, specialConditions); + break; + case 3: // BidAsk + var bidPrice = this.dequeueFloat(); + var askPrice = this.dequeueFloat(); + var bidSize = this.dequeueInt(); + var askSize = this.dequeueInt(); + mask = this.dequeueInt(); + var bidPastLow = (mask & (1 << 0)) !== 0; + var askPastHigh = (mask & (1 << 1)) !== 0; + + this._emit('tickByTickBidAsk', reqId, time, bidPrice, askPrice, bidSize, askSize, { + bidPastLow, + askPastHigh + }); + break; + case 4: // MidPoint + var midPoint = this.dequeueFloat(); + + this._emit('tickByTickMidPoint', reqId, time, midPoint); + break; + } }; -Incoming.prototype._HEAD_TIMESTAMP = function() { - var reqId = this.dequeueInt(); - var headTimestamp = this.dequeue(); - this._emit('headTimestamp', reqId, headTimestamp); +Incoming.prototype._HEAD_TIMESTAMP = function () { + var reqId = this.dequeueInt(); + var headTimestamp = this.dequeue(); + this._emit('headTimestamp', reqId, headTimestamp); }; Incoming.prototype._MANAGED_ACCTS = function () { - var version = this.dequeueInt(); - var accountsList = this.dequeue(); + var version = this.dequeueInt(); + var accountsList = this.dequeue(); - this._emit('managedAccounts', accountsList); + this._emit('managedAccounts', accountsList); }; Incoming.prototype._MARKET_DATA_TYPE = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var marketDataType = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var marketDataType = this.dequeueInt(); - this._emit('marketDataType', reqId, marketDataType); + this._emit('marketDataType', reqId, marketDataType); }; Incoming.prototype._MARKET_DEPTH = function () { - var version = this.dequeueInt(); - var id = this.dequeueInt(); - var position = this.dequeueInt(); - var operation = this.dequeueInt(); - var side = this.dequeueInt(); - var price = this.dequeueFloat(); - var size = this.dequeueInt(); - - this._emit('updateMktDepth', id, position, operation, side, price, size); + var version = this.dequeueInt(); + var id = this.dequeueInt(); + var position = this.dequeueInt(); + var operation = this.dequeueInt(); + var side = this.dequeueInt(); + var price = this.dequeueFloat(); + var size = this.dequeueInt(); + + this._emit('updateMktDepth', id, position, operation, side, price, size); }; Incoming.prototype._MARKET_DEPTH_L2 = function () { - var version = this.dequeueInt(); - var id = this.dequeueInt(); - var position = this.dequeueInt(); - var marketMaker = this.dequeue(); - var operation = this.dequeueInt(); - var side = this.dequeueInt(); - var price = this.dequeueFloat(); - var size = this.dequeueInt(); - - this._emit('updateMktDepthL2', id, position, marketMaker, operation, side, price, size); + var version = this.dequeueInt(); + var id = this.dequeueInt(); + var position = this.dequeueInt(); + var marketMaker = this.dequeue(); + var operation = this.dequeueInt(); + var side = this.dequeueInt(); + var price = this.dequeueFloat(); + var size = this.dequeueInt(); + + this._emit('updateMktDepthL2', id, position, marketMaker, operation, side, price, size); }; Incoming.prototype._NEWS_BULLETINS = function () { - var version = this.dequeueInt(); - var newsMsgId = this.dequeueInt(); - var newsMsgType = this.dequeueInt(); - var newsMessage = this.dequeue(); - var originatingExch = this.dequeue(); + var version = this.dequeueInt(); + var newsMsgId = this.dequeueInt(); + var newsMsgType = this.dequeueInt(); + var newsMessage = this.dequeue(); + var originatingExch = this.dequeue(); - this._emit('updateNewsBulletin', newsMsgId, newsMsgType, newsMessage, originatingExch); + this._emit('updateNewsBulletin', newsMsgId, newsMsgType, newsMessage, originatingExch); }; +Incoming.prototype._NEWS_PROVIDERS = function () { + const providers = []; + try { + let i; + while (i = this.dequeue()) { + providers.push(i); + } + } catch (e) { + } + this._emit('reqNewsProviders', providers); +}; +Incoming.prototype._HISTORICAL_NEWS = function () { + const providers = []; + for (let i = 0; i < 300; i++) { + const headline = {}; + this.dequeue(); + headline.date = this.dequeue(); + if (headline.date === '0') { + break; + } + this.dequeue(); + this.dequeue(); + headline.title = this.dequeue(); + this.dequeue(); + + providers.push(headline); + } + this._emit('reqHistoricalNews', providers); +}; + + Incoming.prototype._NEXT_VALID_ID = function () { - var version = this.dequeueInt(); - var orderId = this.dequeueInt(); + var version = this.dequeueInt(); + var orderId = this.dequeueInt(); - this._emit('nextValidId', orderId); + this._emit('nextValidId', orderId); }; Incoming.prototype._OPEN_ORDER = function () { - var i; + var i; - // read version - var version = this.dequeueInt(); + // read version + var version = this.dequeueInt(); - // read order id - var order = {}; - order.orderId = this.dequeueInt(); + // read order id + var order = {}; + order.orderId = this.dequeueInt(); - // read contract fields - var contract = {}; + // read contract fields + var contract = {}; - if (version >= 17) { - contract.conId = this.dequeueInt(); - } + if (version >= 17) { + contract.conId = this.dequeueInt(); + } - contract.symbol = this.dequeue(); - contract.secType = this.dequeue(); - contract.expiry = this.dequeue(); - contract.strike = this.dequeueFloat(); - contract.right = this.dequeue(); + contract.symbol = this.dequeue(); + contract.secType = this.dequeue(); + contract.expiry = this.dequeue(); + contract.strike = this.dequeueFloat(); + contract.right = this.dequeue(); - if (version >= 32) { - contract.multiplier = this.dequeue(); - } + if (version >= 32) { + contract.multiplier = this.dequeue(); + } - contract.exchange = this.dequeue(); - contract.currency = this.dequeue(); + contract.exchange = this.dequeue(); + contract.currency = this.dequeue(); - if (version >= 2) { - contract.localSymbol = this.dequeue(); - } + if (version >= 2) { + contract.localSymbol = this.dequeue(); + } - if (version >= 32) { - contract.tradingClass = this.dequeue(); - } - - // read order fields - order.action = this.dequeue(); - order.totalQuantity = this.dequeueInt(); - order.orderType = this.dequeue(); - - if (version < 29) { - order.lmtPrice = this.dequeueFloat(); - } else { - order.lmtPrice = this.dequeueFloat() || Number.MAX_VALUE; - } - - if (version < 30) { - order.auxPrice = this.dequeueFloat(); - } else { - order.auxPrice = this.dequeueFloat() || Number.MAX_VALUE; - } - - order.tif = this.dequeue(); - order.ocaGroup = this.dequeue(); - order.account = this.dequeue(); - order.openClose = this.dequeue(); - order.origin = this.dequeueInt(); - order.orderRef = this.dequeue(); - - if (version >= 3) { - order.clientId = this.dequeueInt(); - } - - if (version >= 4) { - order.permId = this.dequeueInt(); - - if (version < 18) { - // will never happen - /* order.ignoreRth = */ this.dequeueBool(); + if (version >= 32) { + contract.tradingClass = this.dequeue(); + } + + // read order fields + order.action = this.dequeue(); + order.totalQuantity = this.dequeueInt(); + order.orderType = this.dequeue(); + + if (version < 29) { + order.lmtPrice = this.dequeueFloat(); } else { - order.outsideRth = this.dequeueBool(); - } - - order.hidden = this.dequeueBool(); - order.discretionaryAmt = this.dequeueFloat(); - } - - if (version >= 5) { - order.goodAfterTime = this.dequeue(); - } - - if (version >= 6) { - // skip deprecated sharesAllocation field - this.dequeue(); - } - - if (version >= 7) { - order.faGroup = this.dequeue(); - order.faMethod = this.dequeue(); - order.faPercentage = this.dequeue(); - order.faProfile = this.dequeue(); - } - - if (version >= 8) { - order.goodTillDate = this.dequeue(); - } - - if (version >= 9) { - order.rule80A = this.dequeue(); - order.percentOffset = this.dequeueFloat() || Number.MAX_VALUE; - order.settlingFirm = this.dequeue(); - order.shortSaleSlot = this.dequeueInt(); - order.designatedLocation = this.dequeue(); - - if (this._controller._serverVersion === 51) { - this.dequeueInt(); // exemptCode - } else if (version >= 23) { - order.exemptCode = this.dequeueInt(); - } - - order.auctionStrategy = this.dequeueInt(); - order.startingPrice = this.dequeueFloat() || Number.MAX_VALUE; - order.stockRefPrice = this.dequeueFloat() || Number.MAX_VALUE; - order.delta = this.dequeueFloat() || Number.MAX_VALUE; - order.stockRangeLower = this.dequeueFloat() || Number.MAX_VALUE; - order.stockRangeUpper = this.dequeueFloat() || Number.MAX_VALUE; - order.displaySize = this.dequeueInt(); - - if (version < 18) { - // will never happen - /* order.rthOnly = */ this.dequeueBool(); - } - - order.blockOrder = this.dequeueBool(); - order.sweepToFill = this.dequeueBool(); - order.allOrNone = this.dequeueBool(); - order.minQty = this.dequeueInt() || Number.MAX_VALUE; - order.ocaType = this.dequeueInt(); - order.eTradeOnly = this.dequeueBool(); - order.firmQuoteOnly = this.dequeueBool(); - order.nbboPriceCap = this.dequeueFloat() || Number.MAX_VALUE; - } - - if (version >= 10) { - order.parentId = this.dequeueInt(); - order.triggerMethod = this.dequeueInt(); - } - - var receivedInt; - - if (version >= 11) { - order.volatility = this.dequeueFloat() || Number.MAX_VALUE; - order.volatilityType = this.dequeueInt(); - - if (version === 11) { - receivedInt = this.dequeueInt(); - order.deltaNeutralOrderType = (receivedInt === 0 ? 'NONE' : 'MKT'); - } else { // version 12 and up - order.deltaNeutralOrderType = this.dequeue(); - order.deltaNeutralAuxPrice = this.dequeueFloat() || Number.MAX_VALUE; - - if (version >= 27 && !_.isEmpty(order.deltaNeutralOrderType)) { - order.deltaNeutralConId = this.dequeueInt(); - order.deltaNeutralSettlingFirm = this.dequeue(); - order.deltaNeutralClearingAccount = this.dequeue(); - order.deltaNeutralClearingIntent = this.dequeue(); - } - - if (version >= 31 && !_.isEmpty(order.deltaNeutralOrderType)) { - order.deltaNeutralOpenClose = this.dequeue(); - order.deltaNeutralShortSale = this.dequeueBool(); - order.deltaNeutralShortSaleSlot = this.dequeueInt(); - order.deltaNeutralDesignatedLocation = this.dequeue(); - } - } - - order.continuousUpdate = this.dequeueInt(); - - if (this._controller._serverVersion === 26) { - order.stockRangeLower = this.dequeueFloat(); - order.stockRangeUpper = this.dequeueFloat(); - } - - order.referencePriceType = this.dequeueInt(); - } - - if (version >= 13) { - order.trailStopPrice = this.dequeueFloat() || Number.MAX_VALUE; - } - - if (version >= 30) { - order.trailingPercent = this.dequeueFloat() || Number.MAX_VALUE; - } - - if (version >= 14) { - order.basisPoints = this.dequeueFloat() || Number.MAX_VALUE; - order.basisPointsType = this.dequeueInt() || Number.MAX_VALUE; - contract.comboLegsDescrip = this.dequeue(); - } - - var comboLeg; - var comboLegsCount; - var orderComboLeg; - var orderComboLegsCount; - var price; - - if (version >= 29) { - comboLegsCount = this.dequeueInt(); - - if (comboLegsCount > 0) { - contract.comboLegs = []; - - for (i = 0; i < comboLegsCount; ++i) { - comboLeg = {}; - comboLeg.conId = this.dequeueInt(); - comboLeg.ratio = this.dequeueInt(); - comboLeg.action = this.dequeue(); - comboLeg.exchange = this.dequeue(); - comboLeg.openClose = this.dequeueInt(); - comboLeg.shortSaleSlot = this.dequeueInt(); - comboLeg.designatedLocation = this.dequeue(); - comboLeg.exemptCode = this.dequeueInt(); - contract.comboLegs.push(comboLeg); - } - } - - orderComboLegsCount = this.dequeueInt(); - - if (orderComboLegsCount > 0) { - order.orderComboLegs = []; - - for (i = 0; i < orderComboLegsCount; ++i) { - orderComboLeg = {}; - order.price = this.dequeueFloat() || Number.MAX_VALUE; - order.orderComboLegs.push(orderComboLeg); - } - } - } - - var smartComboRoutingParamsCount; - var tagValue; - - if (version >= 26) { - smartComboRoutingParamsCount = this.dequeueInt(); - if (smartComboRoutingParamsCount > 0) { - order.smartComboRoutingParams = []; + order.lmtPrice = this.dequeueFloat() || Number.MAX_VALUE; + } - for (i = 0; i < smartComboRoutingParamsCount; ++i) { - tagValue = {}; - tagValue.tag = this.dequeue(); - tagValue.value = this.dequeue(); - order.smartComboRoutingParams.push(tagValue); - } - } - } - - if (version >= 15) { - if (version >= 20) { - order.scaleInitLevelSize = this.dequeueInt() || Number.MAX_VALUE; - order.scaleSubsLevelSize = this.dequeueInt() || Number.MAX_VALUE; + if (version < 30) { + order.auxPrice = this.dequeueFloat(); } else { - var notSuppScaleNumComponents = this.dequeueInt() || Number.MAX_VALUE; - order.scaleInitLevelSize = this.dequeueInt() || Number.MAX_VALUE; + order.auxPrice = this.dequeueFloat() || Number.MAX_VALUE; + } + + order.tif = this.dequeue(); + order.ocaGroup = this.dequeue(); + order.account = this.dequeue(); + order.openClose = this.dequeue(); + order.origin = this.dequeueInt(); + order.orderRef = this.dequeue(); + + if (version >= 3) { + order.clientId = this.dequeueInt(); + } + + if (version >= 4) { + order.permId = this.dequeueInt(); + + if (version < 18) { + // will never happen + /* order.ignoreRth = */ + this.dequeueBool(); + } else { + order.outsideRth = this.dequeueBool(); + } + + order.hidden = this.dequeueBool(); + order.discretionaryAmt = this.dequeueFloat(); + } + + if (version >= 5) { + order.goodAfterTime = this.dequeue(); + } + + if (version >= 6) { + // skip deprecated sharesAllocation field + this.dequeue(); + } + + if (version >= 7) { + order.faGroup = this.dequeue(); + order.faMethod = this.dequeue(); + order.faPercentage = this.dequeue(); + order.faProfile = this.dequeue(); + } + + if (version >= 8) { + order.goodTillDate = this.dequeue(); + } + + if (version >= 9) { + order.rule80A = this.dequeue(); + order.percentOffset = this.dequeueFloat() || Number.MAX_VALUE; + order.settlingFirm = this.dequeue(); + order.shortSaleSlot = this.dequeueInt(); + order.designatedLocation = this.dequeue(); + + if (this._controller._serverVersion === 51) { + this.dequeueInt(); // exemptCode + } else if (version >= 23) { + order.exemptCode = this.dequeueInt(); + } + + order.auctionStrategy = this.dequeueInt(); + order.startingPrice = this.dequeueFloat() || Number.MAX_VALUE; + order.stockRefPrice = this.dequeueFloat() || Number.MAX_VALUE; + order.delta = this.dequeueFloat() || Number.MAX_VALUE; + order.stockRangeLower = this.dequeueFloat() || Number.MAX_VALUE; + order.stockRangeUpper = this.dequeueFloat() || Number.MAX_VALUE; + order.displaySize = this.dequeueInt(); + + if (version < 18) { + // will never happen + /* order.rthOnly = */ + this.dequeueBool(); + } + + order.blockOrder = this.dequeueBool(); + order.sweepToFill = this.dequeueBool(); + order.allOrNone = this.dequeueBool(); + order.minQty = this.dequeueInt() || Number.MAX_VALUE; + order.ocaType = this.dequeueInt(); + order.eTradeOnly = this.dequeueBool(); + order.firmQuoteOnly = this.dequeueBool(); + order.nbboPriceCap = this.dequeueFloat() || Number.MAX_VALUE; + } + + if (version >= 10) { + order.parentId = this.dequeueInt(); + order.triggerMethod = this.dequeueInt(); + } + + var receivedInt; + + if (version >= 11) { + order.volatility = this.dequeueFloat() || Number.MAX_VALUE; + order.volatilityType = this.dequeueInt(); + + if (version === 11) { + receivedInt = this.dequeueInt(); + order.deltaNeutralOrderType = (receivedInt === 0 ? 'NONE' : 'MKT'); + } else { // version 12 and up + order.deltaNeutralOrderType = this.dequeue(); + order.deltaNeutralAuxPrice = this.dequeueFloat() || Number.MAX_VALUE; + + if (version >= 27 && !_.isEmpty(order.deltaNeutralOrderType)) { + order.deltaNeutralConId = this.dequeueInt(); + order.deltaNeutralSettlingFirm = this.dequeue(); + order.deltaNeutralClearingAccount = this.dequeue(); + order.deltaNeutralClearingIntent = this.dequeue(); + } + + if (version >= 31 && !_.isEmpty(order.deltaNeutralOrderType)) { + order.deltaNeutralOpenClose = this.dequeue(); + order.deltaNeutralShortSale = this.dequeueBool(); + order.deltaNeutralShortSaleSlot = this.dequeueInt(); + order.deltaNeutralDesignatedLocation = this.dequeue(); + } + } + + order.continuousUpdate = this.dequeueInt(); + + if (this._controller._serverVersion === 26) { + order.stockRangeLower = this.dequeueFloat(); + order.stockRangeUpper = this.dequeueFloat(); + } + + order.referencePriceType = this.dequeueInt(); + } + + if (version >= 13) { + order.trailStopPrice = this.dequeueFloat() || Number.MAX_VALUE; + } + + if (version >= 30) { + order.trailingPercent = this.dequeueFloat() || Number.MAX_VALUE; + } + + if (version >= 14) { + order.basisPoints = this.dequeueFloat() || Number.MAX_VALUE; + order.basisPointsType = this.dequeueInt() || Number.MAX_VALUE; + contract.comboLegsDescrip = this.dequeue(); + } + + var comboLeg; + var comboLegsCount; + var orderComboLeg; + var orderComboLegsCount; + var price; + + if (version >= 29) { + comboLegsCount = this.dequeueInt(); + + if (comboLegsCount > 0) { + contract.comboLegs = []; + + for (i = 0; i < comboLegsCount; ++i) { + comboLeg = {}; + comboLeg.conId = this.dequeueInt(); + comboLeg.ratio = this.dequeueInt(); + comboLeg.action = this.dequeue(); + comboLeg.exchange = this.dequeue(); + comboLeg.openClose = this.dequeueInt(); + comboLeg.shortSaleSlot = this.dequeueInt(); + comboLeg.designatedLocation = this.dequeue(); + comboLeg.exemptCode = this.dequeueInt(); + contract.comboLegs.push(comboLeg); + } + } + + orderComboLegsCount = this.dequeueInt(); + + if (orderComboLegsCount > 0) { + order.orderComboLegs = []; + + for (i = 0; i < orderComboLegsCount; ++i) { + orderComboLeg = {}; + order.price = this.dequeueFloat() || Number.MAX_VALUE; + order.orderComboLegs.push(orderComboLeg); + } + } + } + + var smartComboRoutingParamsCount; + var tagValue; + + if (version >= 26) { + smartComboRoutingParamsCount = this.dequeueInt(); + if (smartComboRoutingParamsCount > 0) { + order.smartComboRoutingParams = []; + + for (i = 0; i < smartComboRoutingParamsCount; ++i) { + tagValue = {}; + tagValue.tag = this.dequeue(); + tagValue.value = this.dequeue(); + order.smartComboRoutingParams.push(tagValue); + } + } + } + + if (version >= 15) { + if (version >= 20) { + order.scaleInitLevelSize = this.dequeueInt() || Number.MAX_VALUE; + order.scaleSubsLevelSize = this.dequeueInt() || Number.MAX_VALUE; + } else { + var notSuppScaleNumComponents = this.dequeueInt() || Number.MAX_VALUE; + order.scaleInitLevelSize = this.dequeueInt() || Number.MAX_VALUE; + } + order.scalePriceIncrement = this.dequeueFloat() || Number.MAX_VALUE; } - order.scalePriceIncrement = this.dequeueFloat() || Number.MAX_VALUE; - } - if (version >= 28 && order.scalePriceIncrement > 0.0 && order.scalePriceIncrement !== Number.MAX_VALUE) { - order.scalePriceAdjustValue = this.dequeueFloat() || Number.MAX_VALUE; - order.scalePriceAdjustInterval = this.dequeueInt() || Number.MAX_VALUE; - order.scaleProfitOffset = this.dequeueFloat() || Number.MAX_VALUE; - order.scaleAutoReset = this.dequeueBool(); - order.scaleInitPosition = this.dequeueInt() || Number.MAX_VALUE; - order.scaleInitFillQty = this.dequeueInt() || Number.MAX_VALUE; - order.scaleRandomPercent = this.dequeueBool(); - } + if (version >= 28 && order.scalePriceIncrement > 0.0 && order.scalePriceIncrement !== Number.MAX_VALUE) { + order.scalePriceAdjustValue = this.dequeueFloat() || Number.MAX_VALUE; + order.scalePriceAdjustInterval = this.dequeueInt() || Number.MAX_VALUE; + order.scaleProfitOffset = this.dequeueFloat() || Number.MAX_VALUE; + order.scaleAutoReset = this.dequeueBool(); + order.scaleInitPosition = this.dequeueInt() || Number.MAX_VALUE; + order.scaleInitFillQty = this.dequeueInt() || Number.MAX_VALUE; + order.scaleRandomPercent = this.dequeueBool(); + } - if (version >= 24) { - order.hedgeType = this.dequeue(); + if (version >= 24) { + order.hedgeType = this.dequeue(); - if (!_.isEmpty(order.hedgeType)) { - order.hedgeParam = this.dequeue(); + if (!_.isEmpty(order.hedgeType)) { + order.hedgeParam = this.dequeue(); + } } - } - if (version >= 25) { - order.optOutSmartRouting = this.dequeueBool(); - } + if (version >= 25) { + order.optOutSmartRouting = this.dequeueBool(); + } - if (version >= 19) { - order.clearingAccount = this.dequeue(); - order.clearingIntent = this.dequeue(); - } + if (version >= 19) { + order.clearingAccount = this.dequeue(); + order.clearingIntent = this.dequeue(); + } - if (version >= 22) { - order.notHeld = this.dequeueBool(); - } + if (version >= 22) { + order.notHeld = this.dequeueBool(); + } - var underComp; + var underComp; - if (version >= 20) { - if (this.dequeueBool()) { - underComp = {}; - underComp.conId = this.dequeueInt(); - underComp.delta = this.dequeueFloat(); - underComp.price = this.dequeueFloat(); - contract.underComp = underComp; + if (version >= 20) { + if (this.dequeueBool()) { + underComp = {}; + underComp.conId = this.dequeueInt(); + underComp.delta = this.dequeueFloat(); + underComp.price = this.dequeueFloat(); + contract.underComp = underComp; + } } - } - var algoParamsCount; + var algoParamsCount; - if (version >= 21) { - order.algoStrategy = this.dequeue(); + if (version >= 21) { + order.algoStrategy = this.dequeue(); - if (!_.isEmpty(order.algoStrategy)) { - algoParamsCount = this.dequeueInt(); + if (!_.isEmpty(order.algoStrategy)) { + algoParamsCount = this.dequeueInt(); - if (algoParamsCount > 0) { - order.algoParams = []; + if (algoParamsCount > 0) { + order.algoParams = []; - for (i = 0; i < algoParamsCount; ++i) { - tagValue = {}; - tagValue.tag = this.dequeue(); - tagValue.value = this.dequeue(); - order.algoParams.push(tagValue); + for (i = 0; i < algoParamsCount; ++i) { + tagValue = {}; + tagValue.tag = this.dequeue(); + tagValue.value = this.dequeue(); + order.algoParams.push(tagValue); + } + } } - } - } - } - - var orderState = {}; - - if (version >= 16) { - order.whatIf = this.dequeueBool(); - orderState.status = this.dequeue(); - orderState.initMargin = this.dequeue(); - orderState.maintMargin = this.dequeue(); - orderState.equityWithLoan = this.dequeue(); - orderState.commission = this.dequeueFloat() || Number.MAX_VALUE; - orderState.minCommission = this.dequeueFloat() || Number.MAX_VALUE; - orderState.maxCommission = this.dequeueFloat() || Number.MAX_VALUE; - orderState.commissionCurrency = this.dequeue(); - orderState.warningText = this.dequeue(); - } - - this._emit('openOrder', order.orderId, contract, order, orderState); + } + + var orderState = {}; + + if (version >= 16) { + order.whatIf = this.dequeueBool(); + orderState.status = this.dequeue(); + orderState.initMargin = this.dequeue(); + orderState.maintMargin = this.dequeue(); + orderState.equityWithLoan = this.dequeue(); + orderState.commission = this.dequeueFloat() || Number.MAX_VALUE; + orderState.minCommission = this.dequeueFloat() || Number.MAX_VALUE; + orderState.maxCommission = this.dequeueFloat() || Number.MAX_VALUE; + orderState.commissionCurrency = this.dequeue(); + orderState.warningText = this.dequeue(); + } + + this._emit('openOrder', order.orderId, contract, order, orderState); }; Incoming.prototype._OPEN_ORDER_END = function () { - var version = this.dequeueInt(); + var version = this.dequeueInt(); - this._emit('openOrderEnd'); + this._emit('openOrderEnd'); }; Incoming.prototype._ORDER_STATUS = function () { - var version = this.dequeueInt(); - var id = this.dequeueInt(); - var status = this.dequeue(); - var filled = this.dequeueInt(); - var remaining = this.dequeueInt(); - var avgFillPrice = this.dequeueFloat(); + var version = this.dequeueInt(); + var id = this.dequeueInt(); + var status = this.dequeue(); + var filled = this.dequeueInt(); + var remaining = this.dequeueInt(); + var avgFillPrice = this.dequeueFloat(); - var permId = 0; + var permId = 0; - if (version >= 2) { - permId = this.dequeueInt(); - } + if (version >= 2) { + permId = this.dequeueInt(); + } - var parentId = 0; + var parentId = 0; - if (version >= 3) { - parentId = this.dequeueInt(); - } + if (version >= 3) { + parentId = this.dequeueInt(); + } - var lastFillPrice = 0; + var lastFillPrice = 0; - if (version >= 4) { - lastFillPrice = this.dequeueFloat(); - } + if (version >= 4) { + lastFillPrice = this.dequeueFloat(); + } - var clientId = 0; + var clientId = 0; - if (version >= 5) { - clientId = this.dequeueInt(); - } + if (version >= 5) { + clientId = this.dequeueInt(); + } - var whyHeld = null; + var whyHeld = null; - if (version >= 6) { - whyHeld = this.dequeue(); - } + if (version >= 6) { + whyHeld = this.dequeue(); + } - this._emit('orderStatus', id, status, filled, remaining, avgFillPrice, - permId, parentId, lastFillPrice, clientId, whyHeld); + this._emit('orderStatus', id, status, filled, remaining, avgFillPrice, + permId, parentId, lastFillPrice, clientId, whyHeld); }; Incoming.prototype._PORTFOLIO_VALUE = function () { - var version = this.dequeueInt(); + var version = this.dequeueInt(); - var contract = {}; + var contract = {}; - if (version >= 6) { - contract.conId = this.dequeueInt(); - } + if (version >= 6) { + contract.conId = this.dequeueInt(); + } - contract.symbol = this.dequeue(); - contract.secType = this.dequeue(); - contract.expiry = this.dequeue(); - contract.strike = this.dequeueFloat(); - contract.right = this.dequeue(); + contract.symbol = this.dequeue(); + contract.secType = this.dequeue(); + contract.expiry = this.dequeue(); + contract.strike = this.dequeueFloat(); + contract.right = this.dequeue(); - if (version >= 7) { - contract.multiplier = this.dequeue(); - contract.primaryExch = this.dequeue(); - } + if (version >= 7) { + contract.multiplier = this.dequeue(); + contract.primaryExch = this.dequeue(); + } - contract.currency = this.dequeue(); + contract.currency = this.dequeue(); - if (version >= 2) { - contract.localSymbol = this.dequeue(); - } + if (version >= 2) { + contract.localSymbol = this.dequeue(); + } - if (version >= 8) { - contract.tradingClass = this.dequeue(); - } + if (version >= 8) { + contract.tradingClass = this.dequeue(); + } - var position = this.dequeueInt(); - var marketPrice = this.dequeueFloat(); - var marketValue = this.dequeueFloat(); - var averageCost = 0.0; - var unrealizedPNL = 0.0; - var realizedPNL = 0.0; + var position = this.dequeueInt(); + var marketPrice = this.dequeueFloat(); + var marketValue = this.dequeueFloat(); + var averageCost = 0.0; + var unrealizedPNL = 0.0; + var realizedPNL = 0.0; - if (version >= 3) { - averageCost = this.dequeueFloat(); - unrealizedPNL = this.dequeueFloat(); - realizedPNL = this.dequeueFloat(); - } + if (version >= 3) { + averageCost = this.dequeueFloat(); + unrealizedPNL = this.dequeueFloat(); + realizedPNL = this.dequeueFloat(); + } - var accountName = null; + var accountName = null; - if (version >= 4) { - accountName = this.dequeue(); - } + if (version >= 4) { + accountName = this.dequeue(); + } - if (version === 6 && this._controller._serverVersion === 39) { - contract.primaryExch = this.dequeue(); - } + if (version === 6 && this._controller._serverVersion === 39) { + contract.primaryExch = this.dequeue(); + } - this._emit('updatePortfolio', contract, position, marketPrice, marketValue, - averageCost, unrealizedPNL, realizedPNL, accountName); + this._emit('updatePortfolio', contract, position, marketPrice, marketValue, + averageCost, unrealizedPNL, realizedPNL, accountName); }; Incoming.prototype._POSITION = function () { - var version = this.dequeueInt(); - var account = this.dequeue(); - var contract = {}; - - contract.conId = this.dequeueInt(); - contract.symbol = this.dequeue(); - contract.secType = this.dequeue(); - contract.expiry = this.dequeue(); - contract.strike = this.dequeueFloat(); - contract.right = this.dequeue(); - contract.multiplier = this.dequeue(); - contract.exchange = this.dequeue(); - contract.currency = this.dequeue(); - contract.localSymbol = this.dequeue(); - if (version >= 2) { - contract.tradingClass = this.dequeue(); - } + var version = this.dequeueInt(); + var account = this.dequeue(); + var contract = {}; - var pos = this.dequeueInt(); - var avgCost = 0; - if (version >= 3) { - avgCost = this.dequeueFloat(); - } + contract.conId = this.dequeueInt(); + contract.symbol = this.dequeue(); + contract.secType = this.dequeue(); + contract.expiry = this.dequeue(); + contract.strike = this.dequeueFloat(); + contract.right = this.dequeue(); + contract.multiplier = this.dequeue(); + contract.exchange = this.dequeue(); + contract.currency = this.dequeue(); + contract.localSymbol = this.dequeue(); + if (version >= 2) { + contract.tradingClass = this.dequeue(); + } + + var pos = this.dequeueInt(); + var avgCost = 0; + if (version >= 3) { + avgCost = this.dequeueFloat(); + } - this._emit('position', account, contract, pos, avgCost); + this._emit('position', account, contract, pos, avgCost); }; Incoming.prototype._POSITION_END = function () { - var version = this.dequeueInt(); + var version = this.dequeueInt(); - this._emit('positionEnd'); + this._emit('positionEnd'); }; Incoming.prototype._POSITION_MULTI = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var account = this.dequeue(); - var modelCode = null; - var contract = {}; - - contract.conId = this.dequeueInt(); - contract.symbol = this.dequeue(); - contract.secType = this.dequeue(); - contract.expiry = this.dequeue(); - contract.strike = this.dequeueFloat(); - contract.right = this.dequeue(); - contract.multiplier = this.dequeue(); - contract.exchange = this.dequeue(); - contract.currency = this.dequeue(); - contract.localSymbol = this.dequeue(); - contract.tradingClass = this.dequeue(); - - var pos = this.dequeueInt(); - var avgCost = 0; - avgCost = this.dequeueFloat(); - - this._emit('positionMulti', reqId, account, modelCode, contract, pos, avgCost); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var account = this.dequeue(); + var modelCode = null; + var contract = {}; + + contract.conId = this.dequeueInt(); + contract.symbol = this.dequeue(); + contract.secType = this.dequeue(); + contract.expiry = this.dequeue(); + contract.strike = this.dequeueFloat(); + contract.right = this.dequeue(); + contract.multiplier = this.dequeue(); + contract.exchange = this.dequeue(); + contract.currency = this.dequeue(); + contract.localSymbol = this.dequeue(); + contract.tradingClass = this.dequeue(); + + var pos = this.dequeueInt(); + var avgCost = 0; + avgCost = this.dequeueFloat(); + + this._emit('positionMulti', reqId, account, modelCode, contract, pos, avgCost); }; Incoming.prototype._POSITION_MULTI_END = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); - this._emit('positionMultiEnd', reqId); + this._emit('positionMultiEnd', reqId); }; Incoming.prototype._REAL_TIME_BARS = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var time = this.dequeueInt(); - var open = this.dequeueFloat(); - var high = this.dequeueFloat(); - var low = this.dequeueFloat(); - var close = this.dequeueFloat(); - var volume = this.dequeueInt(); - var wap = this.dequeueFloat(); - var count = this.dequeueInt(); - - this._emit('realtimeBar', reqId, time, open, high, low, close, volume, wap, count); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var time = this.dequeueInt(); + var open = this.dequeueFloat(); + var high = this.dequeueFloat(); + var low = this.dequeueFloat(); + var close = this.dequeueFloat(); + var volume = this.dequeueInt(); + var wap = this.dequeueFloat(); + var count = this.dequeueInt(); + + this._emit('realtimeBar', reqId, time, open, high, low, close, volume, wap, count); }; Incoming.prototype._RECEIVE_FA = function () { - var version = this.dequeueInt(); - var faDataType = this.dequeueInt(); - var xml = this.dequeue(); + var version = this.dequeueInt(); + var faDataType = this.dequeueInt(); + var xml = this.dequeue(); - this._emit('receiveFA', faDataType, xml); + this._emit('receiveFA', faDataType, xml); }; Incoming.prototype._SCANNER_DATA = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var numberOfElements = this.dequeueInt(); - - var rank; - - while (numberOfElements--) { - var contract = { - summary: {} - }; - rank = this.dequeueInt(); - if (version >= 3) { - contract.summary.conId = this.dequeueInt(); - } - - contract.summary.symbol = this.dequeue(); - contract.summary.secType = this.dequeue(); - contract.summary.expiry = this.dequeue(); - contract.summary.strike = this.dequeueFloat(); - contract.summary.right = this.dequeue(); - contract.summary.exchange = this.dequeue(); - contract.summary.currency = this.dequeue(); - contract.summary.localSymbol = this.dequeue(); - contract.marketName = this.dequeue(); - contract.summary.tradingClass = this.dequeue(); + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var numberOfElements = this.dequeueInt(); + + var rank; + + while (numberOfElements--) { + var contract = { + summary: {} + }; + rank = this.dequeueInt(); + if (version >= 3) { + contract.summary.conId = this.dequeueInt(); + } - var distance = this.dequeue(); - var benchmark = this.dequeue(); - var projection = this.dequeue(); - var legsStr = null; + contract.summary.symbol = this.dequeue(); + contract.summary.secType = this.dequeue(); + contract.summary.expiry = this.dequeue(); + contract.summary.strike = this.dequeueFloat(); + contract.summary.right = this.dequeue(); + contract.summary.exchange = this.dequeue(); + contract.summary.currency = this.dequeue(); + contract.summary.localSymbol = this.dequeue(); + contract.marketName = this.dequeue(); + contract.summary.tradingClass = this.dequeue(); + + var distance = this.dequeue(); + var benchmark = this.dequeue(); + var projection = this.dequeue(); + var legsStr = null; + + if (version >= 2) { + legsStr = this.dequeue(); + } - if (version >= 2) { - legsStr = this.dequeue(); + this._emit('scannerData', tickerId, rank, contract, distance, + benchmark, projection, legsStr); } - this._emit('scannerData', tickerId, rank, contract, distance, - benchmark, projection, legsStr); - } - - this._emit('scannerDataEnd', tickerId); + this._emit('scannerDataEnd', tickerId); }; Incoming.prototype._SCANNER_PARAMETERS = function () { - var version = this.dequeueInt(); - var xml = this.dequeue(); + var version = this.dequeueInt(); + var xml = this.dequeue(); - this._emit('scannerParameters', xml); + this._emit('scannerParameters', xml); }; -Incoming.prototype._SECURITY_DEFINITION_OPTION_PARAMETER = function() { - var reqId = this.dequeueInt(); - var exchange = this.dequeue(); - var underlyingConId = this.dequeueInt(); - var tradingClass = this.dequeue(); - var multiplier = this.dequeue(); - var expCount = this.dequeueInt(); - var expirations = []; - - for (var i = 0; i < expCount; i++) { - expirations.push(this.dequeue()); - } +Incoming.prototype._SECURITY_DEFINITION_OPTION_PARAMETER = function () { + var reqId = this.dequeueInt(); + var exchange = this.dequeue(); + var underlyingConId = this.dequeueInt(); + var tradingClass = this.dequeue(); + var multiplier = this.dequeue(); + var expCount = this.dequeueInt(); + var expirations = []; + + for (var i = 0; i < expCount; i++) { + expirations.push(this.dequeue()); + } - var strikeCount = this.dequeueInt(); - var strikes = []; - for (var j = 0; j < strikeCount; j++) { - strikes.push(this.dequeueFloat()); - } + var strikeCount = this.dequeueInt(); + var strikes = []; + for (var j = 0; j < strikeCount; j++) { + strikes.push(this.dequeueFloat()); + } - this._emit('securityDefinitionOptionParameter', reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes); + this._emit('securityDefinitionOptionParameter', reqId, exchange, underlyingConId, tradingClass, multiplier, expirations, strikes); }; -Incoming.prototype._SECURITY_DEFINITION_OPTION_PARAMETER_END = function() { - var reqId = this.dequeueInt(); - this._emit('securityDefinitionOptionParameterEnd', reqId); +Incoming.prototype._SECURITY_DEFINITION_OPTION_PARAMETER_END = function () { + var reqId = this.dequeueInt(); + this._emit('securityDefinitionOptionParameterEnd', reqId); }; Incoming.prototype._TICK_EFP = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var basisPoints = this.dequeueFloat(); - var formattedBasisPoints = this.dequeue(); - var impliedFuturesPrice = this.dequeueFloat(); - var holdDays = this.dequeueInt(); - var futureExpiry = this.dequeue(); - var dividendImpact = this.dequeueFloat(); - var dividendsToExpiry = this.dequeueFloat(); - - this._emit('tickEFP', tickerId, tickType, basisPoints, formattedBasisPoints, - impliedFuturesPrice, holdDays, futureExpiry, - dividendImpact, dividendsToExpiry); + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var basisPoints = this.dequeueFloat(); + var formattedBasisPoints = this.dequeue(); + var impliedFuturesPrice = this.dequeueFloat(); + var holdDays = this.dequeueInt(); + var futureExpiry = this.dequeue(); + var dividendImpact = this.dequeueFloat(); + var dividendsToExpiry = this.dequeueFloat(); + + this._emit('tickEFP', tickerId, tickType, basisPoints, formattedBasisPoints, + impliedFuturesPrice, holdDays, futureExpiry, + dividendImpact, dividendsToExpiry); }; Incoming.prototype._TICK_GENERIC = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var value = this.dequeueFloat(); + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var value = this.dequeueFloat(); - this._emit('tickGeneric', tickerId, tickType, value); + this._emit('tickGeneric', tickerId, tickType, value); }; Incoming.prototype._TICK_OPTION_COMPUTATION = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var impliedVol = this.dequeueFloat(); + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var impliedVol = this.dequeueFloat(); - if (impliedVol < 0) { // -1 is the "not yet computed" indicator - impliedVol = Number.MAX_VALUE; - } + if (impliedVol < 0) { // -1 is the "not yet computed" indicator + impliedVol = Number.MAX_VALUE; + } - var delta = this.dequeueFloat(); + var delta = this.dequeueFloat(); - if (Math.abs(delta) > 1) { // -2 is the "not yet computed" indicator - delta = Number.MAX_VALUE; - } + if (Math.abs(delta) > 1) { // -2 is the "not yet computed" indicator + delta = Number.MAX_VALUE; + } - var optPrice = Number.MAX_VALUE; - var pvDividend = Number.MAX_VALUE; - var gamma = Number.MAX_VALUE; - var vega = Number.MAX_VALUE; - var theta = Number.MAX_VALUE; - var undPrice = Number.MAX_VALUE; + var optPrice = Number.MAX_VALUE; + var pvDividend = Number.MAX_VALUE; + var gamma = Number.MAX_VALUE; + var vega = Number.MAX_VALUE; + var theta = Number.MAX_VALUE; + var undPrice = Number.MAX_VALUE; - if (version >= 6 || tickType === C.TICK_TYPE.MODEL_OPTION) { // introduced in version == 5 - optPrice = this.dequeueFloat(); + if (version >= 6 || tickType === C.TICK_TYPE.MODEL_OPTION) { // introduced in version == 5 + optPrice = this.dequeueFloat(); - if (optPrice < 0) { // -1 is the "not yet computed" indicator - optPrice = Number.MAX_VALUE; - } + if (optPrice < 0) { // -1 is the "not yet computed" indicator + optPrice = Number.MAX_VALUE; + } - pvDividend = this.dequeueFloat(); + pvDividend = this.dequeueFloat(); - if (pvDividend < 0) { // -1 is the "not yet computed" indicator - pvDividend = Number.MAX_VALUE; + if (pvDividend < 0) { // -1 is the "not yet computed" indicator + pvDividend = Number.MAX_VALUE; + } } - } - if (version >= 6) { - gamma = this.dequeueFloat(); + if (version >= 6) { + gamma = this.dequeueFloat(); - if (Math.abs(gamma) > 1) { // -2 is the "not yet computed" indicator - gamma = Number.MAX_VALUE; - } + if (Math.abs(gamma) > 1) { // -2 is the "not yet computed" indicator + gamma = Number.MAX_VALUE; + } - vega = this.dequeueFloat(); + vega = this.dequeueFloat(); - if (Math.abs(vega) > 1) { // -2 is the "not yet computed" indicator - vega = Number.MAX_VALUE; - } + if (Math.abs(vega) > 1) { // -2 is the "not yet computed" indicator + vega = Number.MAX_VALUE; + } - theta = this.dequeueFloat(); + theta = this.dequeueFloat(); - if (Math.abs(theta) > 1) { // -2 is the "not yet computed" indicator - theta = Number.MAX_VALUE; - } + if (Math.abs(theta) > 1) { // -2 is the "not yet computed" indicator + theta = Number.MAX_VALUE; + } - undPrice = this.dequeueFloat(); + undPrice = this.dequeueFloat(); - if (undPrice < 0) { // -1 is the "not yet computed" indicator - undPrice = Number.MAX_VALUE; + if (undPrice < 0) { // -1 is the "not yet computed" indicator + undPrice = Number.MAX_VALUE; + } } - } - this._emit('tickOptionComputation', tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice); + this._emit('tickOptionComputation', tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice); }; Incoming.prototype._TICK_PRICE = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var price = this.dequeueFloat(); - var size = 0; + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var price = this.dequeueFloat(); + var size = 0; - if (version >= 2) { - size = this.dequeueInt(); - } + if (version >= 2) { + size = this.dequeueInt(); + } - var canAutoExecute = 0; + var canAutoExecute = 0; - if (version >= 3) { - canAutoExecute = this.dequeueBool(); - } + if (version >= 3) { + canAutoExecute = this.dequeueBool(); + } - this._emit('tickPrice', tickerId, tickType, price, canAutoExecute); + this._emit('tickPrice', tickerId, tickType, price, canAutoExecute); - var sizeTickType = -1; + var sizeTickType = -1; - if (version >= 2) { - sizeTickType = -1 ; // not a tick + if (version >= 2) { + sizeTickType = -1; // not a tick + + switch (tickType) { + case 1: // BID + sizeTickType = 0; // BID_SIZE + break; + case 2: // ASK + sizeTickType = 3; // ASK_SIZE + break; + case 4: // LAST + sizeTickType = 5; // LAST_SIZE + break; + default: + break; + } - switch (tickType) { - case 1: // BID - sizeTickType = 0; // BID_SIZE - break; - case 2: // ASK - sizeTickType = 3; // ASK_SIZE - break; - case 4: // LAST - sizeTickType = 5; // LAST_SIZE - break; - default: - break; - } - - if (sizeTickType !== -1) { - this._emit('tickSize', tickerId, sizeTickType, size); - } - } + if (sizeTickType !== -1) { + this._emit('tickSize', tickerId, sizeTickType, size); + } + } }; Incoming.prototype._TICK_SIZE = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var size = this.dequeueInt(); + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var size = this.dequeueInt(); - this._emit('tickSize', tickerId, tickType, size); + this._emit('tickSize', tickerId, tickType, size); }; Incoming.prototype._TICK_SNAPSHOT_END = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); - this._emit('tickSnapshotEnd', reqId); + this._emit('tickSnapshotEnd', reqId); }; Incoming.prototype._TICK_STRING = function () { - var version = this.dequeueInt(); - var tickerId = this.dequeueInt(); - var tickType = this.dequeueInt(); - var value = this.dequeue(); + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var value = this.dequeue(); - this._emit('tickString', tickerId, tickType, value); + this._emit('tickString', tickerId, tickType, value); +}; + +Incoming.prototype._TICK_STRING = function () { + var version = this.dequeueInt(); + var tickerId = this.dequeueInt(); + var tickType = this.dequeueInt(); + var value = this.dequeue(); + + this._emit('tickString', tickerId, tickType, value); }; Incoming.prototype._DISPLAY_GROUP_LIST = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var list = this.dequeue(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var list = this.dequeue(); - this._emit('displayGroupList', reqId, list); + this._emit('displayGroupList', reqId, list); }; Incoming.prototype._DISPLAY_GROUP_UPDATED = function () { - var version = this.dequeueInt(); - var reqId = this.dequeueInt(); - var contractInfo = this.dequeue(); + var version = this.dequeueInt(); + var reqId = this.dequeueInt(); + var contractInfo = this.dequeue(); - this._emit('displayGroupUpdated', reqId, contractInfo); + this._emit('displayGroupUpdated', reqId, contractInfo); }; Incoming.prototype._emit = function () { - this._emitQueue.push(arguments); + this._emitQueue.push(arguments); }; Incoming.prototype.dequeue = function () { - if (this._dataQueue.length === 0) { - throw new errors.UnderrunError(); - } - var result = this._dataQueue.shift(); - return result; + if (this._dataQueue.length === 0) { + throw new errors.UnderrunError(); + } + var result = this._dataQueue.shift(); + return result; }; Incoming.prototype.dequeueBool = function () { - return !!parseInt(this.dequeue(), 10); + return !!parseInt(this.dequeue(), 10); }; Incoming.prototype.dequeueFloat = function () { - return parseFloat(this.dequeue()); + return parseFloat(this.dequeue()); }; Incoming.prototype.dequeueInt = function () { - return parseInt(this.dequeue(), 10); + return parseInt(this.dequeue(), 10); }; Incoming.prototype.enqueue = function (tokens) { - this._dataQueue = this._dataQueue.concat(tokens); + this._dataQueue = this._dataQueue.concat(tokens); }; Incoming.prototype.process = function () { - var constKey; - var token; - var dataQueueSnapshot; - - while (true) { - dataQueueSnapshot = this._dataQueue.slice(); - - try { - // Clear the Emit Queue; if this doesn't get cleared, it piles up whenever there's an error (added by heberallred) - this._emitQueue = []; - - token = this.dequeueInt(); - constKey = this._controller._ib.util.incomingToString(token); - - if (constKey && _.has(this.constructor.prototype, '_' + constKey) && _.isFunction(this['_' + constKey])) { - this['_' + constKey](); - } else { - this._controller.emitError('Unknown incoming first token: ' + token); - } - } catch (e) { - if (!(e instanceof errors.UnderrunError)) { - throw e; - } - // Put data back in the queue, and don't emit any events. - this._dataQueue = this._dataQueue.concat(dataQueueSnapshot); - return; - } - // Drain _emitQueue. - var toEmit = this._emitQueue; - this._emitQueue = []; - _.forEach(toEmit, (payload) => { - this._controller.emit.apply(this._controller, payload); - }); - } + var constKey; + var token; + var dataQueueSnapshot; + + while (true) { + dataQueueSnapshot = this._dataQueue.slice(); + + try { + // Clear the Emit Queue; if this doesn't get cleared, it piles up whenever there's an error (added by heberallred) + this._emitQueue = []; + + token = this.dequeueInt(); + constKey = this._controller._ib.util.incomingToString(token); + // console.log("constKey", constKey) + if (constKey && _.has(this.constructor.prototype, '_' + constKey) && _.isFunction(this['_' + constKey])) { + this['_' + constKey](); + } else { + this._controller.emitError('Unknown incoming first token: ' + token); + } + } catch (e) { + if (!(e instanceof errors.UnderrunError)) { + throw e; + } + // Put data back in the queue, and don't emit any events. + this._dataQueue = this._dataQueue.concat(dataQueueSnapshot); + return; + } + // Drain _emitQueue. + var toEmit = this._emitQueue; + this._emitQueue = []; + _.forEach(toEmit, (payload) => { + this._controller.emit.apply(this._controller, payload); + }); + } }; module.exports = Incoming; diff --git a/lib/index.js b/lib/index.js index 981fa41..08ea2a4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -244,6 +244,15 @@ IB.prototype.reqContractDetails = function (reqId, contract) { return this; }; +IB.prototype.reqNewsProviders = function(){ + this._send('reqNewsProviders'); + +} +IB.prototype.reqHistoricalNews = function(requestId, conId, providerCodes, startDateTime = '', endDateTime = '', totalResults = 10){ + this._send('reqHistoricalNews',requestId, conId, providerCodes, startDateTime , endDateTime , totalResults ,null); + +} + IB.prototype.reqCurrentTime = function () { this._send('reqCurrentTime'); diff --git a/lib/outgoing.js b/lib/outgoing.js index 1964af3..48fa14c 100644 --- a/lib/outgoing.js +++ b/lib/outgoing.js @@ -5,1488 +5,1498 @@ var rateLimit = require('function-rate-limit'); var C = require('./constants'); function _nullifyMax(number) { - if (number === Number.MAX_VALUE) { - return null; - } else { - return number; - } + if (number === Number.MAX_VALUE) { + return null; + } else { + return number; + } } function Outgoing(controller) { - this._controller = controller; + this._controller = controller; } Outgoing.prototype._send = rateLimit(C.MAX_REQ_PER_SECOND, 1000, function () { - var args = Array.prototype.slice.call(arguments); - this._controller.run('send', _.flatten(args)); + var args = Array.prototype.slice.call(arguments); + this._controller.run('send', _.flatten(args)); }); Outgoing.prototype.calculateImpliedVolatility = function (reqId, contract, optionPrice, underPrice) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_CALC_IMPLIED_VOLAT) { - return this._controller.emitError('It does not support calculate implied volatility requests.'); - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass)) { - return this._controller.emitError('It does not support tradingClass parameter in calculateImpliedVolatility.'); - } - } - - var version = 2; - - var args = [C.OUTGOING.REQ_CALC_IMPLIED_VOLAT, version, reqId]; - - // send contract fields - args.push(contract.conId); - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_CALC_IMPLIED_VOLAT) { + return this._controller.emitError('It does not support calculate implied volatility requests.'); + } + + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass)) { + return this._controller.emitError('It does not support tradingClass parameter in calculateImpliedVolatility.'); + } + } + + var version = 2; - args.push(optionPrice); - args.push(underPrice); + var args = [C.OUTGOING.REQ_CALC_IMPLIED_VOLAT, version, reqId]; - this._send(args); + // send contract fields + args.push(contract.conId); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } + + args.push(optionPrice); + args.push(underPrice); + + this._send(args); }; Outgoing.prototype.calculateOptionPrice = function (reqId, contract, volatility, underPrice) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_CALC_OPTION_PRICE) { - return this._controller.emitError('It does not support calculate option price requests.'); - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass)) { - return this._controller.emitError('It does not support tradingClass parameter in calculateOptionPrice.'); - } - } - - var version = 2; - - var args = [C.OUTGOING.REQ_CALC_OPTION_PRICE, version, reqId]; - - // send contract fields - args.push(contract.conId); - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_CALC_OPTION_PRICE) { + return this._controller.emitError('It does not support calculate option price requests.'); + } + + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass)) { + return this._controller.emitError('It does not support tradingClass parameter in calculateOptionPrice.'); + } + } + + var version = 2; + + var args = [C.OUTGOING.REQ_CALC_OPTION_PRICE, version, reqId]; + + // send contract fields + args.push(contract.conId); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); - args.push(volatility); - args.push(underPrice); + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - this._send(args); + args.push(volatility); + args.push(underPrice); + + this._send(args); }; Outgoing.prototype.cancelAccountSummary = function (reqId) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { - return this._controller.emitError('It does not support account summary cancellation.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { + return this._controller.emitError('It does not support account summary cancellation.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_ACCOUNT_SUMMARY, version, reqId); + this._send(C.OUTGOING.CANCEL_ACCOUNT_SUMMARY, version, reqId); }; Outgoing.prototype.cancelAccountUpdatesMulti = function (reqId) { - var version = 2; + var version = 2; - this._send(C.OUTGOING.CANCEL_ACCOUNT_UPDATES_MULTI, version, reqId); + this._send(C.OUTGOING.CANCEL_ACCOUNT_UPDATES_MULTI, version, reqId); }; Outgoing.prototype.cancelPositionsMulti = function (reqId) { - var version = 2; + var version = 2; - this._send(C.OUTGOING.CANCEL_POSITIONS_MULTI, version, reqId); + this._send(C.OUTGOING.CANCEL_POSITIONS_MULTI, version, reqId); }; Outgoing.prototype.cancelCalculateImpliedVolatility = function (reqId) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.CANCEL_CALC_IMPLIED_VOLAT) { - return this._controller.emitError('It does not support calculate implied volatility cancellation.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.CANCEL_CALC_IMPLIED_VOLAT) { + return this._controller.emitError('It does not support calculate implied volatility cancellation.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_CALC_IMPLIED_VOLAT, version, reqId); + this._send(C.OUTGOING.CANCEL_CALC_IMPLIED_VOLAT, version, reqId); }; Outgoing.prototype.cancelCalculateOptionPrice = function (reqId) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.CANCEL_CALC_OPTION_PRICE) { - return this._controller.emitError('It does not support calculate option price cancellation.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.CANCEL_CALC_OPTION_PRICE) { + return this._controller.emitError('It does not support calculate option price cancellation.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_CALC_OPTION_PRICE, version, reqId); + this._send(C.OUTGOING.CANCEL_CALC_OPTION_PRICE, version, reqId); }; Outgoing.prototype.cancelFundamentalData = function (reqId) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.FUNDAMENTAL_DATA) { - return this._controller.emitError('It does not support fundamental data requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.FUNDAMENTAL_DATA) { + return this._controller.emitError('It does not support fundamental data requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_FUNDAMENTAL_DATA, version, reqId); + this._send(C.OUTGOING.CANCEL_FUNDAMENTAL_DATA, version, reqId); }; Outgoing.prototype.cancelHistoricalData = function (tickerId) { - if (this._controller._serverVersion < 24) { - return this._controller.emitError('It does not support historical data query cancellation.'); - } + if (this._controller._serverVersion < 24) { + return this._controller.emitError('It does not support historical data query cancellation.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_HISTORICAL_DATA, version, tickerId); + this._send(C.OUTGOING.CANCEL_HISTORICAL_DATA, version, tickerId); }; Outgoing.prototype.cancelMktData = function (tickerId) { - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_MKT_DATA, version, tickerId); + this._send(C.OUTGOING.CANCEL_MKT_DATA, version, tickerId); }; Outgoing.prototype.cancelMktDepth = function (tickerId) { - if (this._controller._serverVersion < 6) { - return this._controller.emitError('This feature is only available for versions of TWS >=6.'); - } + if (this._controller._serverVersion < 6) { + return this._controller.emitError('This feature is only available for versions of TWS >=6.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_MKT_DEPTH, version, tickerId); + this._send(C.OUTGOING.CANCEL_MKT_DEPTH, version, tickerId); }; Outgoing.prototype.cancelNewsBulletins = function () { - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_NEWS_BULLETINS, version); + this._send(C.OUTGOING.CANCEL_NEWS_BULLETINS, version); }; Outgoing.prototype.cancelOrder = function (id) { - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_ORDER, version, id); + this._send(C.OUTGOING.CANCEL_ORDER, version, id); }; Outgoing.prototype.cancelPositions = function () { - if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { - return this._controller.emitError('It does not support position cancellation.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { + return this._controller.emitError('It does not support position cancellation.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_POSITIONS, version); + this._send(C.OUTGOING.CANCEL_POSITIONS, version); }; Outgoing.prototype.cancelRealTimeBars = function (tickerId) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REAL_TIME_BARS) { - return this._controller.emitError('It does not support realtime bar data query cancellation.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REAL_TIME_BARS) { + return this._controller.emitError('It does not support realtime bar data query cancellation.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_REAL_TIME_BARS, version, tickerId); + this._send(C.OUTGOING.CANCEL_REAL_TIME_BARS, version, tickerId); }; Outgoing.prototype.cancelScannerSubscription = function (tickerId) { - if (this._controller._serverVersion < 24) { - return this._controller.emitError('It does not support API scanner subscription.'); - } + if (this._controller._serverVersion < 24) { + return this._controller.emitError('It does not support API scanner subscription.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.CANCEL_SCANNER_SUBSCRIPTION, version, tickerId); + this._send(C.OUTGOING.CANCEL_SCANNER_SUBSCRIPTION, version, tickerId); }; Outgoing.prototype.exerciseOptions = function (tickerId, contract, exerciseAction, exerciseQuantity, account, override) { - var version = 2; + var version = 2; - if (this._controller._serverVersion < 21) { - return this._controller.emitError('It does not support options exercise from the API.'); - } + if (this._controller._serverVersion < 21) { + return this._controller.emitError('It does not support options exercise from the API.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { - return this._controller.emitError('It does not support conId and tradingClass parameters in exerciseOptions.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { + return this._controller.emitError('It does not support conId and tradingClass parameters in exerciseOptions.'); + } } - } - var args = [C.OUTGOING.EXERCISE_OPTIONS, version, tickerId]; + var args = [C.OUTGOING.EXERCISE_OPTIONS, version, tickerId]; - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.conId); - } - - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.currency); - args.push(contract.localSymbol); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.conId); + } - args.push(exerciseAction); - args.push(exerciseQuantity); - args.push(account); - args.push(override); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.currency); + args.push(contract.localSymbol); + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - this._send(args); + args.push(exerciseAction); + args.push(exerciseQuantity); + args.push(account); + args.push(override); + + this._send(args); }; Outgoing.prototype.placeOrder = function (id, contract, order) { + if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_ORDERS) { + if (order.scaleInitLevelSize !== Number.MAX_VALUE || + order.scalePriceIncrement !== Number.MAX_VALUE) { + return this._controller.emitError('It does not support Scale orders.'); + } + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_ORDERS) { - if (order.scaleInitLevelSize !== Number.MAX_VALUE || - order.scalePriceIncrement !== Number.MAX_VALUE) { - return this._controller.emitError('It does not support Scale orders.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SSHORT_COMBO_LEGS) { + if (_.isArray(contract.comboLegs)) { + contract.comboLegs.forEach(function (comboLeg) { + if (comboLeg.shortSaleSlot !== 0 || !_.isEmpty(comboLeg.designatedLocation)) { + return this._controller.emitError('It does not support SSHORT flag for combo legs.'); + } + }.bind(this)); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SSHORT_COMBO_LEGS) { - if (_.isArray(contract.comboLegs)) { - contract.comboLegs.forEach(function (comboLeg) { - if (comboLeg.shortSaleSlot !== 0 || !_.isEmpty(comboLeg.designatedLocation)) { - return this._controller.emitError('It does not support SSHORT flag for combo legs.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.WHAT_IF_ORDERS) { + if (order.whatIf) { + return this._controller.emitError('It does not support what-if orders.'); } - }.bind(this)); } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.WHAT_IF_ORDERS) { - if (order.whatIf) { - return this._controller.emitError('It does not support what-if orders.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.UNDER_COMP) { + if (contract.underComp) { + return this._controller.emitError('It does not support delta-neutral orders.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.UNDER_COMP) { - if (contract.underComp) { - return this._controller.emitError('It does not support delta-neutral orders.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_ORDERS2) { + if (order.scaleSubsLevelSize !== Number.MAX_VALUE) { + return this._controller.emitError('It does not support Subsequent Level Size for Scale orders.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_ORDERS2) { - if (order.scaleSubsLevelSize !== Number.MAX_VALUE) { - return this._controller.emitError('It does not support Subsequent Level Size for Scale orders.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.ALGO_ORDERS) { + if (!_.isEmpty(order.algoStrategy)) { + return this._controller.emitError('It does not support algo orders.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.ALGO_ORDERS) { - if (!_.isEmpty(order.algoStrategy)) { - return this._controller.emitError('It does not support algo orders.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.NOT_HELD) { + if (order.notHeld) { + return this._controller.emitError('It does not support notHeld parameter.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.NOT_HELD) { - if (order.notHeld) { - return this._controller.emitError('It does not support notHeld parameter.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SEC_ID_TYPE) { + if (!_.isEmpty(contract.secIdType) || !_.isEmpty(contract.secId)) { + return this._controller.emitError('It does not support secIdType and secId parameters.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SEC_ID_TYPE) { - if (!_.isEmpty(contract.secIdType) || !_.isEmpty(contract.secId)) { - return this._controller.emitError('It does not support secIdType and secId parameters.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.PLACE_ORDER_CONID) { + if (contract.conId > 0) { + return this._controller.emitError('It does not support conId parameter.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.PLACE_ORDER_CONID) { - if (contract.conId > 0) { - return this._controller.emitError('It does not support conId parameter.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SSHORTX) { + if (order.exemptCode !== -1) { + return this._controller.emitError('It does not support exemptCode parameter.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SSHORTX) { - if (order.exemptCode !== -1) { - return this._controller.emitError('It does not support exemptCode parameter.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SSHORTX) { + if (_.isArray(contract.comboLegs)) { + contract.comboLegs.forEach(function (comboLeg) { + if (comboLeg.exemptCode !== -1) { + return this._controller.emitError('It does not support exemptCode parameter.'); + } + }.bind(this)); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SSHORTX) { - if (_.isArray(contract.comboLegs)) { - contract.comboLegs.forEach(function (comboLeg) { - if (comboLeg.exemptCode !== -1) { - return this._controller.emitError('It does not support exemptCode parameter.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.HEDGE_ORDERS) { + if (!_.isEmpty(order.hedgeType)) { + return this._controller.emitError('It does not support hedge orders.'); } - }.bind(this)); - } - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.HEDGE_ORDERS) { - if (!_.isEmpty(order.hedgeType)) { - return this._controller.emitError('It does not support hedge orders.'); - } - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.OPT_OUT_SMART_ROUTING) { - if (order.optOutSmartRouting) { - return this._controller.emitError('It does not support optOutSmartRouting parameter.'); - } - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.DELTA_NEUTRAL_CONID) { - if (order.deltaNeutralConId > 0 || - !_.isEmpty(order.deltaNeutralSettlingFirm) || - !_.isEmpty(order.deltaNeutralClearingAccount) || - !_.isEmpty(order.deltaNeutralClearingIntent)) { - return this._controller.emitError('It does not support deltaNeutral parameters: ConId, SettlingFirm, ClearingAccount, ClearingIntent.'); - } - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.DELTA_NEUTRAL_OPEN_CLOSE) { - if (!_.isEmpty(order.deltaNeutralOpenClose) || - order.deltaNeutralShortSale || - order.deltaNeutralShortSaleSlot > 0 || - !_.isEmpty(order.deltaNeutralDesignatedLocation)) { - return this._controller.emitError('It does not support deltaNeutral parameters: OpenClose, ShortSale, ShortSaleSlot, DesignatedLocation.'); - } - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_ORDERS3) { - if (order.scalePriceIncrement > 0 && order.scalePriceIncrement !== Number.MAX_VALUE) { - if (order.scalePriceAdjustValue !== Number.MAX_VALUE || - order.scalePriceAdjustInterval !== Number.MAX_VALUE || - order.scaleProfitOffset !== Number.MAX_VALUE || - order.scaleAutoReset || - order.scaleInitPosition !== Number.MAX_VALUE || - order.scaleInitFillQty !== Number.MAX_VALUE || - order.scaleRandomPercent) { - return this._controller.emitError('It does not support Scale order parameters: PriceAdjustValue, PriceAdjustInterval, ProfitOffset, AutoReset, InitPosition, InitFillQty and RandomPercent'); - } - } - } - - if (this._controller._serverVersion < C.MIN_SERVER_VER.ORDER_COMBO_LEGS_PRICE && - _.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - if (_.isArray(order.orderComboLegs)) { - order.orderComboLegs.forEach(function (orderComboLeg) { - if (orderComboLeg.price !== Number.MAX_VALUE) { - return this._controller.emitError('It does not support per-leg prices for order combo legs.'); + } + + if (this._controller._serverVersion < C.MIN_SERVER_VER.OPT_OUT_SMART_ROUTING) { + if (order.optOutSmartRouting) { + return this._controller.emitError('It does not support optOutSmartRouting parameter.'); } - }.bind(this)); } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRAILING_PERCENT) { - if (order.trailingPercent !== Number.MAX_VALUE) { - return this._controller.emitError('It does not support trailing percent parameter.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.DELTA_NEUTRAL_CONID) { + if (order.deltaNeutralConId > 0 || + !_.isEmpty(order.deltaNeutralSettlingFirm) || + !_.isEmpty(order.deltaNeutralClearingAccount) || + !_.isEmpty(order.deltaNeutralClearingIntent)) { + return this._controller.emitError('It does not support deltaNeutral parameters: ConId, SettlingFirm, ClearingAccount, ClearingIntent.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass)) { - return this._controller.emitError('It does not support tradingClass parameters in placeOrder.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.DELTA_NEUTRAL_OPEN_CLOSE) { + if (!_.isEmpty(order.deltaNeutralOpenClose) || + order.deltaNeutralShortSale || + order.deltaNeutralShortSaleSlot > 0 || + !_.isEmpty(order.deltaNeutralDesignatedLocation)) { + return this._controller.emitError('It does not support deltaNeutral parameters: OpenClose, ShortSale, ShortSaleSlot, DesignatedLocation.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_TABLE) { - if (!_.isEmpty(order.scaleTable) || - !_.isEmpty(order.activeStartTime) || - !_.isEmpty(order.activeStopTime)) { - return this._controller.emitError('It does not support scaleTable, activeStartTime and activeStopTime parameters.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_ORDERS3) { + if (order.scalePriceIncrement > 0 && order.scalePriceIncrement !== Number.MAX_VALUE) { + if (order.scalePriceAdjustValue !== Number.MAX_VALUE || + order.scalePriceAdjustInterval !== Number.MAX_VALUE || + order.scaleProfitOffset !== Number.MAX_VALUE || + order.scaleAutoReset || + order.scaleInitPosition !== Number.MAX_VALUE || + order.scaleInitFillQty !== Number.MAX_VALUE || + order.scaleRandomPercent) { + return this._controller.emitError('It does not support Scale order parameters: PriceAdjustValue, PriceAdjustInterval, ProfitOffset, AutoReset, InitPosition, InitFillQty and RandomPercent'); + } + } } - } - var version = (this._controller._serverVersion < C.MIN_SERVER_VER.NOT_HELD ? 27 : 41); + if (this._controller._serverVersion < C.MIN_SERVER_VER.ORDER_COMBO_LEGS_PRICE && + _.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + if (_.isArray(order.orderComboLegs)) { + order.orderComboLegs.forEach(function (orderComboLeg) { + if (orderComboLeg.price !== Number.MAX_VALUE) { + return this._controller.emitError('It does not support per-leg prices for order combo legs.'); + } + }.bind(this)); + } + } - // send place order msg - var args = [C.OUTGOING.PLACE_ORDER, version, id]; + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRAILING_PERCENT) { + if (order.trailingPercent !== Number.MAX_VALUE) { + return this._controller.emitError('It does not support trailing percent parameter.'); + } + } - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.PLACE_ORDER_CONID) { - args.push(contract.conId); - } - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - if (this._controller._serverVersion >= 15) { - args.push(contract.multiplier); - } - args.push(contract.exchange); - if (this._controller._serverVersion >= 14) { - args.push(contract.primaryExch); - } - args.push(contract.currency); - if (this._controller._serverVersion >= 2) { - args.push(contract.localSymbol); - } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SEC_ID_TYPE){ - args.push(contract.secIdType); - args.push(contract.secId); - } - - // send main order fields - args.push(order.action); - args.push(order.totalQuantity); - args.push(order.orderType); - if (this._controller._serverVersion < C.MIN_SERVER_VER.ORDER_COMBO_LEGS_PRICE) { - args.push(order.lmtPrice === Number.MAX_VALUE ? 0 : order.lmtPrice); - } else { - args.push(_nullifyMax(order.lmtPrice)); - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRAILING_PERCENT) { - args.push(order.auxPrice === Number.MAX_VALUE ? 0 : order.auxPrice); - } else { - args.push(_nullifyMax(order.auxPrice)); - } - - // send extended order fields - args.push(order.tif); - args.push(order.ocaGroup); - args.push(order.account); - args.push(order.openClose); - args.push(order.origin); - args.push(order.orderRef); - args.push(order.transmit); - if (this._controller._serverVersion >= 4) { - args.push(order.parentId); - } - - if (this._controller._serverVersion >= 5) { - args.push(order.blockOrder); - args.push(order.sweepToFill); - args.push(order.displaySize); - args.push(order.triggerMethod); - if (this._controller._serverVersion < 38) { - // will never happen - args.push(/* order.ignoreRth */ false); - } else { - args.push(order.outsideRth); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass)) { + return this._controller.emitError('It does not support tradingClass parameters in placeOrder.'); + } } - } - if (this._controller._serverVersion >= 7) { - args.push(order.hidden); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.SCALE_TABLE) { + if (!_.isEmpty(order.scaleTable) || + !_.isEmpty(order.activeStartTime) || + !_.isEmpty(order.activeStopTime)) { + return this._controller.emitError('It does not support scaleTable, activeStartTime and activeStopTime parameters.'); + } + } + + var version = (this._controller._serverVersion < C.MIN_SERVER_VER.NOT_HELD ? 27 : 41); + + // send place order msg + var args = [C.OUTGOING.PLACE_ORDER, version, id]; - // Send combo legs for BAG requests - if (this._controller._serverVersion >= 8 && - _.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - if (!_.isArray(contract.comboLegs)) { - args.push(0); + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.PLACE_ORDER_CONID) { + args.push(contract.conId); + } + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + if (this._controller._serverVersion >= 15) { + args.push(contract.multiplier); + } + args.push(contract.exchange); + if (this._controller._serverVersion >= 14) { + args.push(contract.primaryExch); + } + args.push(contract.currency); + if (this._controller._serverVersion >= 2) { + args.push(contract.localSymbol); + } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SEC_ID_TYPE) { + args.push(contract.secIdType); + args.push(contract.secId); + } + + // send main order fields + args.push(order.action); + args.push(order.totalQuantity); + args.push(order.orderType); + if (this._controller._serverVersion < C.MIN_SERVER_VER.ORDER_COMBO_LEGS_PRICE) { + args.push(order.lmtPrice === Number.MAX_VALUE ? 0 : order.lmtPrice); } else { - args.push(contract.comboLegs.length); - - contract.comboLegs.forEach(function (comboLeg) { - args.push(comboLeg.conId); - args.push(comboLeg.ratio); - args.push(comboLeg.action); - args.push(comboLeg.exchange); - args.push(comboLeg.openClose); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SSHORT_COMBO_LEGS) { - args.push(comboLeg.shortSaleSlot); - args.push(comboLeg.designatedLocation); + args.push(_nullifyMax(order.lmtPrice)); + } + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRAILING_PERCENT) { + args.push(order.auxPrice === Number.MAX_VALUE ? 0 : order.auxPrice); + } else { + args.push(_nullifyMax(order.auxPrice)); + } + + // send extended order fields + args.push(order.tif); + args.push(order.ocaGroup); + args.push(order.account); + args.push(order.openClose); + args.push(order.origin); + args.push(order.orderRef); + args.push(order.transmit); + if (this._controller._serverVersion >= 4) { + args.push(order.parentId); + } + + if (this._controller._serverVersion >= 5) { + args.push(order.blockOrder); + args.push(order.sweepToFill); + args.push(order.displaySize); + args.push(order.triggerMethod); + if (this._controller._serverVersion < 38) { + // will never happen + args.push(/* order.ignoreRth */ false); + } else { + args.push(order.outsideRth); + } + } + + if (this._controller._serverVersion >= 7) { + args.push(order.hidden); + } + + // Send combo legs for BAG requests + if (this._controller._serverVersion >= 8 && + _.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + if (!_.isArray(contract.comboLegs)) { + args.push(0); + } else { + args.push(contract.comboLegs.length); + + contract.comboLegs.forEach(function (comboLeg) { + args.push(comboLeg.conId); + args.push(comboLeg.ratio); + args.push(comboLeg.action); + args.push(comboLeg.exchange); + args.push(comboLeg.openClose); + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SSHORT_COMBO_LEGS) { + args.push(comboLeg.shortSaleSlot); + args.push(comboLeg.designatedLocation); + } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SSHORTX_OLD) { + args.push(comboLeg.exemptCode); + } + }.bind(this)); } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SSHORTX_OLD) { - args.push(comboLeg.exemptCode); + } + + // Send order combo legs for BAG requests + if (this._controller._serverVersion >= C.MIN_SERVER_VER.ORDER_COMBO_LEGS_PRICE && + _.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + if (!_.isArray(order.orderComboLegs)) { + args.push(0); + } else { + args.push(order.orderComboLegs.length); + order.orderComboLegs.forEach(function (orderComboLeg) { + args.push(_nullifyMax(orderComboLeg.price)); + }); } - }.bind(this)); } - } - // Send order combo legs for BAG requests - if (this._controller._serverVersion >= C.MIN_SERVER_VER.ORDER_COMBO_LEGS_PRICE && - _.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - if (!_.isArray(order.orderComboLegs)) { - args.push(0); - } else { - args.push(order.orderComboLegs.length); - order.orderComboLegs.forEach(function (orderComboLeg) { - args.push(_nullifyMax(orderComboLeg.price)); - }); - } - } - - var smartComboRoutingParamsCount; - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SMART_COMBO_ROUTING_PARAMS && - _.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - smartComboRoutingParamsCount = !_.isArray(order.smartComboRoutingParams) ? 0 : order.smartComboRoutingParams.length; - args.push(smartComboRoutingParamsCount); - - if (smartComboRoutingParamsCount > 0) { - order.smartComboRoutingParams.forEach(function (tagValue) { - args.push(tagValue.tag); - args.push(tagValue.value); - }); - } - } - - if (this._controller._serverVersion >= 9) { - // send deprecated sharesAllocation field - args.push(''); - } - - if (this._controller._serverVersion >= 10) { - args.push(order.discretionaryAmt); - } - - if (this._controller._serverVersion >= 11) { - args.push(order.goodAfterTime); - } - - if (this._controller._serverVersion >= 12) { - args.push(order.goodTillDate); - } - - if (this._controller._serverVersion >= 13) { - args.push(order.faGroup); - args.push(order.faMethod); - args.push(order.faPercentage); - args.push(order.faProfile); - } - - if (this._controller._serverVersion >= 18) { // institutional short sale slot fields. - args.push(order.shortSaleSlot); // 0 only for retail, 1 or 2 only for institution. - args.push(order.designatedLocation); // only populate when order.shortSaleSlot = 2. - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SSHORTX_OLD) { - args.push(order.exemptCode); - } - - var lower; - var upper; - - if (this._controller._serverVersion >= 19) { - args.push(order.ocaType); - - if (this._controller._serverVersion < 38) { - // will never happen - args.push(/* order.rthOnly */ false); - } - - args.push(order.rule80A); - args.push(order.settlingFirm); - args.push(order.allOrNone); - args.push(_nullifyMax(order.minQty)); - args.push(_nullifyMax(order.percentOffset)); - args.push(order.eTradeOnly); - args.push(order.firmQuoteOnly); - args.push(_nullifyMax(order.nbboPriceCap)); - args.push(_nullifyMax(order.auctionStrategy)); - args.push(_nullifyMax(order.startingPrice)); - args.push(_nullifyMax(order.stockRefPrice)); - args.push(_nullifyMax(order.delta)); - - // Volatility orders had specific watermark price attribs in server version 26 - lower = ((this._controller._serverVersion === 26 && order.orderType === 'VOL') ? - Number.MAX_VALUE : - order.stockRangeLower); - upper = (this._controller._serverVersion === 26 && order.orderType === 'VOL') ? - Number.MAX_VALUE : - order.stockRangeUpper; - args.push(_nullifyMax(lower)); - args.push(_nullifyMax(upper)); - } - - if (this._controller._serverVersion >= 22) { - args.push(order.overridePercentageConstraints); - } - - if (this._controller._serverVersion >= 26) { // Volatility orders - args.push(_nullifyMax(order.volatility)); - args.push(_nullifyMax(order.volatilityType)); - - if (this._controller._serverVersion < 28) { - args.push(order.deltaNeutralOrderType.toUpperCase() === 'MKT'); - } else { - args.push(order.deltaNeutralOrderType); - args.push(_nullifyMax(order.deltaNeutralAuxPrice)); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.DELTA_NEUTRAL_CONID && - !_.isEmpty(order.deltaNeutralOrderType)){ - args.push(order.deltaNeutralConId); - args.push(order.deltaNeutralSettlingFirm); - args.push(order.deltaNeutralClearingAccount); - args.push(order.deltaNeutralClearingIntent); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.DELTA_NEUTRAL_OPEN_CLOSE && - !_.isEmpty(order.deltaNeutralOrderType)){ - args.push(order.deltaNeutralOpenClose); - args.push(order.deltaNeutralShortSale); - args.push(order.deltaNeutralShortSaleSlot); - args.push(order.deltaNeutralDesignatedLocation); - } - } - - args.push(order.continuousUpdate); - - if (this._controller._serverVersion === 26) { - // Volatility orders had specific watermark price attribs in server version 26 - lower = (order.orderType === 'VOL' ? order.stockRangeLower : Number.MAX_VALUE); - upper = (order.orderType === 'VOL' ? order.stockRangeUpper : Number.MAX_VALUE); - args.push(_nullifyMax(lower)); - args.push(_nullifyMax(upper)); - } - - args.push(_nullifyMax(order.referencePriceType)); - } - - if (this._controller._serverVersion >= 30) { // TRAIL_STOP_LIMIT stop price - args.push(_nullifyMax(order.trailStopPrice)); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRAILING_PERCENT){ - args.push(_nullifyMax(order.trailingPercent)); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_ORDERS) { - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_ORDERS2) { - args.push(_nullifyMax(order.scaleInitLevelSize)); - args.push(_nullifyMax(order.scaleSubsLevelSize)); - } else { - args.push(''); - args.push(_nullifyMax(order.scaleInitLevelSize)); - } - args.push(_nullifyMax(order.scalePriceIncrement)); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_ORDERS3 && - order.scalePriceIncrement > 0.0 && - order.scalePriceIncrement !== Number.MAX_VALUE) { - args.push(_nullifyMax(order.scalePriceAdjustValue)); - args.push(_nullifyMax(order.scalePriceAdjustInterval)); - args.push(_nullifyMax(order.scaleProfitOffset)); - args.push(order.scaleAutoReset); - args.push(_nullifyMax(order.scaleInitPosition)); - args.push(_nullifyMax(order.scaleInitFillQty)); - args.push(order.scaleRandomPercent); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_TABLE) { - args.push(order.scaleTable); - args.push(order.activeStartTime); - args.push(order.activeStopTime); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.HEDGE_ORDERS) { - args.push(order.hedgeType); - if (!_.isEmpty(order.hedgeType)) { - args.push(order.hedgeParam); - } - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.OPT_OUT_SMART_ROUTING) { - args.push(order.optOutSmartRouting); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.PTA_ORDERS) { - args.push(order.clearingAccount); - args.push(order.clearingIntent); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.NOT_HELD) { - args.push(order.notHeld); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.UNDER_COMP) { - if (_.isPlainObject(contract.underComp) && !_.isEmpty(contract.underComp)) { - args.push(true); - args.push(contract.underComp.conId); - args.push(contract.underComp.delta); - args.push(contract.underComp.price); - } else { - args.push(false); + var smartComboRoutingParamsCount; + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SMART_COMBO_ROUTING_PARAMS && + _.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + smartComboRoutingParamsCount = !_.isArray(order.smartComboRoutingParams) ? 0 : order.smartComboRoutingParams.length; + args.push(smartComboRoutingParamsCount); + + if (smartComboRoutingParamsCount > 0) { + order.smartComboRoutingParams.forEach(function (tagValue) { + args.push(tagValue.tag); + args.push(tagValue.value); + }); + } + } + + if (this._controller._serverVersion >= 9) { + // send deprecated sharesAllocation field + args.push(''); + } + + if (this._controller._serverVersion >= 10) { + args.push(order.discretionaryAmt); + } + + if (this._controller._serverVersion >= 11) { + args.push(order.goodAfterTime); } - } - var algoParamsCount; + if (this._controller._serverVersion >= 12) { + args.push(order.goodTillDate); + } + + if (this._controller._serverVersion >= 13) { + args.push(order.faGroup); + args.push(order.faMethod); + args.push(order.faPercentage); + args.push(order.faProfile); + } + + if (this._controller._serverVersion >= 18) { // institutional short sale slot fields. + args.push(order.shortSaleSlot); // 0 only for retail, 1 or 2 only for institution. + args.push(order.designatedLocation); // only populate when order.shortSaleSlot = 2. + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SSHORTX_OLD) { + args.push(order.exemptCode); + } + + var lower; + var upper; + + if (this._controller._serverVersion >= 19) { + args.push(order.ocaType); + + if (this._controller._serverVersion < 38) { + // will never happen + args.push(/* order.rthOnly */ false); + } + + args.push(order.rule80A); + args.push(order.settlingFirm); + args.push(order.allOrNone); + args.push(_nullifyMax(order.minQty)); + args.push(_nullifyMax(order.percentOffset)); + args.push(order.eTradeOnly); + args.push(order.firmQuoteOnly); + args.push(_nullifyMax(order.nbboPriceCap)); + args.push(_nullifyMax(order.auctionStrategy)); + args.push(_nullifyMax(order.startingPrice)); + args.push(_nullifyMax(order.stockRefPrice)); + args.push(_nullifyMax(order.delta)); + + // Volatility orders had specific watermark price attribs in server version 26 + lower = ((this._controller._serverVersion === 26 && order.orderType === 'VOL') ? + Number.MAX_VALUE : + order.stockRangeLower); + upper = (this._controller._serverVersion === 26 && order.orderType === 'VOL') ? + Number.MAX_VALUE : + order.stockRangeUpper; + args.push(_nullifyMax(lower)); + args.push(_nullifyMax(upper)); + } + + if (this._controller._serverVersion >= 22) { + args.push(order.overridePercentageConstraints); + } + + if (this._controller._serverVersion >= 26) { // Volatility orders + args.push(_nullifyMax(order.volatility)); + args.push(_nullifyMax(order.volatilityType)); + + if (this._controller._serverVersion < 28) { + args.push(order.deltaNeutralOrderType.toUpperCase() === 'MKT'); + } else { + args.push(order.deltaNeutralOrderType); + args.push(_nullifyMax(order.deltaNeutralAuxPrice)); + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.DELTA_NEUTRAL_CONID && + !_.isEmpty(order.deltaNeutralOrderType)) { + args.push(order.deltaNeutralConId); + args.push(order.deltaNeutralSettlingFirm); + args.push(order.deltaNeutralClearingAccount); + args.push(order.deltaNeutralClearingIntent); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.DELTA_NEUTRAL_OPEN_CLOSE && + !_.isEmpty(order.deltaNeutralOrderType)) { + args.push(order.deltaNeutralOpenClose); + args.push(order.deltaNeutralShortSale); + args.push(order.deltaNeutralShortSaleSlot); + args.push(order.deltaNeutralDesignatedLocation); + } + } + + args.push(order.continuousUpdate); + + if (this._controller._serverVersion === 26) { + // Volatility orders had specific watermark price attribs in server version 26 + lower = (order.orderType === 'VOL' ? order.stockRangeLower : Number.MAX_VALUE); + upper = (order.orderType === 'VOL' ? order.stockRangeUpper : Number.MAX_VALUE); + args.push(_nullifyMax(lower)); + args.push(_nullifyMax(upper)); + } + + args.push(_nullifyMax(order.referencePriceType)); + } + + if (this._controller._serverVersion >= 30) { // TRAIL_STOP_LIMIT stop price + args.push(_nullifyMax(order.trailStopPrice)); + } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.ALGO_ORDERS) { - args.push(order.algoStrategy); - if (!_.isEmpty(order.algoStrategy)) { - algoParamsCount = (!_.isArray(order.algoParams) ? 0 : order.algoParams.length); - args.push(algoParamsCount); - if (algoParamsCount > 0) { - order.algoParams.forEach(function (tagValue) { - args.push(tagValue.tag); - args.push(tagValue.value); - }); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRAILING_PERCENT) { + args.push(_nullifyMax(order.trailingPercent)); } - } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.WHAT_IF_ORDERS) { - args.push(order.whatIf); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_ORDERS) { + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_ORDERS2) { + args.push(_nullifyMax(order.scaleInitLevelSize)); + args.push(_nullifyMax(order.scaleSubsLevelSize)); + } else { + args.push(''); + args.push(_nullifyMax(order.scaleInitLevelSize)); + } + args.push(_nullifyMax(order.scalePriceIncrement)); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_ORDERS3 && + order.scalePriceIncrement > 0.0 && + order.scalePriceIncrement !== Number.MAX_VALUE) { + args.push(_nullifyMax(order.scalePriceAdjustValue)); + args.push(_nullifyMax(order.scalePriceAdjustInterval)); + args.push(_nullifyMax(order.scaleProfitOffset)); + args.push(order.scaleAutoReset); + args.push(_nullifyMax(order.scaleInitPosition)); + args.push(_nullifyMax(order.scaleInitFillQty)); + args.push(order.scaleRandomPercent); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SCALE_TABLE) { + args.push(order.scaleTable); + args.push(order.activeStartTime); + args.push(order.activeStopTime); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.HEDGE_ORDERS) { + args.push(order.hedgeType); + if (!_.isEmpty(order.hedgeType)) { + args.push(order.hedgeParam); + } + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.OPT_OUT_SMART_ROUTING) { + args.push(order.optOutSmartRouting); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.PTA_ORDERS) { + args.push(order.clearingAccount); + args.push(order.clearingIntent); + } - this._send(args); + if (this._controller._serverVersion >= C.MIN_SERVER_VER.NOT_HELD) { + args.push(order.notHeld); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.UNDER_COMP) { + if (_.isPlainObject(contract.underComp) && !_.isEmpty(contract.underComp)) { + args.push(true); + args.push(contract.underComp.conId); + args.push(contract.underComp.delta); + args.push(contract.underComp.price); + } else { + args.push(false); + } + } + + var algoParamsCount; + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.ALGO_ORDERS) { + args.push(order.algoStrategy); + if (!_.isEmpty(order.algoStrategy)) { + algoParamsCount = (!_.isArray(order.algoParams) ? 0 : order.algoParams.length); + args.push(algoParamsCount); + if (algoParamsCount > 0) { + order.algoParams.forEach(function (tagValue) { + args.push(tagValue.tag); + args.push(tagValue.value); + }); + } + } + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.WHAT_IF_ORDERS) { + args.push(order.whatIf); + } + + this._send(args); }; Outgoing.prototype.replaceFA = function (faDataType, xml) { - if (this._controller._serverVersion < 13) { - return this._controller.emitError('This feature is only available for versions of TWS >= 13.'); - } + if (this._controller._serverVersion < 13) { + return this._controller.emitError('This feature is only available for versions of TWS >= 13.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REPLACE_FA, version, faDataType, xml); + this._send(C.OUTGOING.REPLACE_FA, version, faDataType, xml); }; Outgoing.prototype.reqAccountSummary = function (reqId, group, tags) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { - return this._controller.emitError('It does not support account summary requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { + return this._controller.emitError('It does not support account summary requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_ACCOUNT_SUMMARY, version, reqId, group, tags); + this._send(C.OUTGOING.REQ_ACCOUNT_SUMMARY, version, reqId, group, tags); }; Outgoing.prototype.reqAccountUpdates = function (subscribe, acctCode) { - var version = 2; + var version = 2; - if (this._controller._serverVersion >= 9) { - this._send(C.OUTGOING.REQ_ACCOUNT_DATA, version, subscribe, acctCode); - } else { - this._send(C.OUTGOING.REQ_ACCOUNT_DATA, version, subscribe); - } + if (this._controller._serverVersion >= 9) { + this._send(C.OUTGOING.REQ_ACCOUNT_DATA, version, subscribe, acctCode); + } else { + this._send(C.OUTGOING.REQ_ACCOUNT_DATA, version, subscribe); + } }; Outgoing.prototype.reqAccountUpdatesMulti = function (reqId, acctCode, modelCode, ledgerAndNLV) { - var version = 2; - this._send(C.OUTGOING.REQ_ACCOUNT_UPDATES_MULTI, version, reqId, acctCode, modelCode, ledgerAndNLV); + var version = 2; + this._send(C.OUTGOING.REQ_ACCOUNT_UPDATES_MULTI, version, reqId, acctCode, modelCode, ledgerAndNLV); }; Outgoing.prototype.reqAllOpenOrders = function () { - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_ALL_OPEN_ORDERS, version); + this._send(C.OUTGOING.REQ_ALL_OPEN_ORDERS, version); }; Outgoing.prototype.reqAutoOpenOrders = function (bAutoBind) { - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_AUTO_OPEN_ORDERS, version, bAutoBind); + this._send(C.OUTGOING.REQ_AUTO_OPEN_ORDERS, version, bAutoBind); }; -Outgoing.prototype.reqHeadTimestamp = function(reqId, contract, whatToShow, useRTH, formatDate) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_HEAD_TIMESTAMP) { - // We don't currently support the v100 extended handshake so our server version shows up as < 100. - // However, this functionality still works so we skip the version check for now. - //return this._controller.emitError('It does not support reqHeadTimeStamp'); - } - - var args = [C.OUTGOING.REQ_HEAD_TIMESTAMP, - reqId, - contract.conId, - contract.symbol, - contract.secType, - contract.lastTradeDateOrContractMonth, - contract.strike, - contract.right, - contract.multiplier, - contract.exchange, - contract.primaryExchange, - contract.currency, - contract.localSymbol, - contract.tradingClass, - contract.includeExpired, - useRTH, - whatToShow, - formatDate]; - - this._send(args); +Outgoing.prototype.reqHeadTimestamp = function (reqId, contract, whatToShow, useRTH, formatDate) { + if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_HEAD_TIMESTAMP) { + // We don't currently support the v100 extended handshake so our server version shows up as < 100. + // However, this functionality still works so we skip the version check for now. + //return this._controller.emitError('It does not support reqHeadTimeStamp'); + } + var args = [C.OUTGOING.REQ_HEAD_TIMESTAMP, + reqId, + contract.conId, + contract.symbol, + contract.secType, + contract.lastTradeDateOrContractMonth, + contract.strike, + contract.right, + contract.multiplier, + contract.exchange, + contract.primaryExchange, + contract.currency, + contract.localSymbol, + contract.tradingClass, + contract.includeExpired, + useRTH, + whatToShow, + formatDate]; + + this._send(args); }; Outgoing.prototype.reqContractDetails = function (reqId, contract) { - if (this._controller._serverVersion < 4) { - return this._controller.emitError('This feature is only available for versions of TWS >=4'); - } + if (this._controller._serverVersion < 4) { + return this._controller.emitError('This feature is only available for versions of TWS >=4'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.SEC_ID_TYPE) { - if (!_.isEmpty(contract.secIdType) || !_.isEmpty(contract.secId)) { - return this._controller.emitError('It does not support secIdType and secId parameters.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.SEC_ID_TYPE) { + if (!_.isEmpty(contract.secIdType) || !_.isEmpty(contract.secId)) { + return this._controller.emitError('It does not support secIdType and secId parameters.'); + } } - } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass)) { - return this._controller.emitError('It does not support tradingClass parameter in reqContractDetails.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass)) { + return this._controller.emitError('It does not support tradingClass parameter in reqContractDetails.'); + } } - } - var version = 7; + var version = 7; - // send req mkt data msg - var args = [C.OUTGOING.REQ_CONTRACT_DATA, version]; + // send req mkt data msg + var args = [C.OUTGOING.REQ_CONTRACT_DATA, version]; - if (this._controller._serverVersion >= C.MIN_SERVER_VER.CONTRACT_DATA_CHAIN) { - args.push(reqId); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.CONTRACT_DATA_CHAIN) { + args.push(reqId); + } - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.CONTRACT_CONID) { - args.push(contract.conId); - } + // send contract fields + console.log(this._controller._serverVersion) + if (this._controller._serverVersion >= C.MIN_SERVER_VER.CONTRACT_CONID) { + args.push(contract.conId); + } - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); - if (this._controller._serverVersion >= 15) { - args.push(contract.multiplier); - } + if (this._controller._serverVersion >= 15) { + args.push(contract.multiplier); + } - args.push(contract.exchange); - args.push(contract.currency); - args.push(contract.localSymbol); + args.push(contract.exchange); + args.push(contract.currency); + args.push(contract.localSymbol); - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - if (this._controller._serverVersion >= 31) { - args.push(contract.includeExpired); - } + if (this._controller._serverVersion >= 31) { + args.push(contract.includeExpired); + } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SEC_ID_TYPE) { - args.push(contract.secIdType); - args.push(contract.secId); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SEC_ID_TYPE) { + args.push(contract.secIdType); + args.push(contract.secId); + } - this._send(args); + this._send(args); }; Outgoing.prototype.reqCurrentTime = function () { - if (this._controller._serverVersion < 33) { - return this._controller.emitError('It does not support current time requests.'); - } + if (this._controller._serverVersion < 33) { + return this._controller.emitError('It does not support current time requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_CURRENT_TIME, version); + this._send(C.OUTGOING.REQ_CURRENT_TIME, version); }; Outgoing.prototype.reqExecutions = function (reqId, filter) { - // NOTE: Time format must be 'yyyymmdd-hh:mm:ss' E.g. '20030702-14:55' + // NOTE: Time format must be 'yyyymmdd-hh:mm:ss' E.g. '20030702-14:55' - var version = 3; + var version = 3; - // send req open orders msg - var args = [C.OUTGOING.REQ_EXECUTIONS, version]; + // send req open orders msg + var args = [C.OUTGOING.REQ_EXECUTIONS, version]; - if (this._controller._serverVersion >= C.MIN_SERVER_VER.EXECUTION_DATA_CHAIN) { - args.push(reqId); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.EXECUTION_DATA_CHAIN) { + args.push(reqId); + } - // Send the execution rpt filter data (srv v9 and above) - args.push(filter.clientId); - args.push(filter.acctCode); - args.push(filter.time); - args.push(filter.symbol); - args.push(filter.secType); - args.push(filter.exchange); - args.push(filter.side); + // Send the execution rpt filter data (srv v9 and above) + args.push(filter.clientId); + args.push(filter.acctCode); + args.push(filter.time); + args.push(filter.symbol); + args.push(filter.secType); + args.push(filter.exchange); + args.push(filter.side); - this._send(args); + this._send(args); }; Outgoing.prototype.reqFundamentalData = function (reqId, contract, reportType) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.FUNDAMENTAL_DATA) { - return this._controller.emitError('It does not support fundamental data requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.FUNDAMENTAL_DATA) { + return this._controller.emitError('It does not support fundamental data requests.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (contract.conId > 0) { - return this._controller.emitError('It does not support conId parameter in reqFundamentalData.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (contract.conId > 0) { + return this._controller.emitError('It does not support conId parameter in reqFundamentalData.'); + } } - } - var version = 2; + var version = 2; - // send req fund data msg - var args = [C.OUTGOING.REQ_FUNDAMENTAL_DATA, version, reqId]; + // send req fund data msg + var args = [C.OUTGOING.REQ_FUNDAMENTAL_DATA, version, reqId]; - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.conId); - } + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.conId); + } - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); - args.push(reportType); + args.push(reportType); - this._send(args); + this._send(args); }; Outgoing.prototype.reqGlobalCancel = function () { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_GLOBAL_CANCEL) { - return this._controller.emitError('It does not support globalCancel requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_GLOBAL_CANCEL) { + return this._controller.emitError('It does not support globalCancel requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_GLOBAL_CANCEL, version); + this._send(C.OUTGOING.REQ_GLOBAL_CANCEL, version); }; Outgoing.prototype.reqHistoricalData = function (tickerId, contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate, keepUpToDate) { - var version = 6; + var version = 6; - if (this._controller._serverVersion < 16) { - return this._controller.emitError('It does not support historical data backfill.'); - } + if (this._controller._serverVersion < 16) { + return this._controller.emitError('It does not support historical data backfill.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { - return this._controller.emitError('It does not support conId and tradingClass parameters in reqHistroricalData.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { + return this._controller.emitError('It does not support conId and tradingClass parameters in reqHistroricalData.'); + } } - } - var args = [C.OUTGOING.REQ_HISTORICAL_DATA, version, tickerId]; + var args = [C.OUTGOING.REQ_HISTORICAL_DATA, version, tickerId]; - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.conId); - } - - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.conId); + } - if (this._controller._serverVersion >= 31) { - args.push(!!contract.includeExpired); - } + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); - if (this._controller._serverVersion >= 20) { - args.push(endDateTime); - args.push(barSizeSetting); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - args.push(durationStr); - args.push(useRTH); - args.push(whatToShow); + if (this._controller._serverVersion >= 31) { + args.push(!!contract.includeExpired); + } - if (this._controller._serverVersion > 16) { - args.push(formatDate); - } + if (this._controller._serverVersion >= 20) { + args.push(endDateTime); + args.push(barSizeSetting); + } - if (_.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - if (!_.isArray(contract.comboLegs)) { - args.push(0); - } else { - args.push(contract.comboLegs.length); + args.push(durationStr); + args.push(useRTH); + args.push(whatToShow); - contract.comboLegs.forEach(function (comboLeg) { - args.push(comboLeg.conId); - args.push(comboLeg.ratio); - args.push(comboLeg.action); - args.push(comboLeg.exchange); - }); + if (this._controller._serverVersion > 16) { + args.push(formatDate); } - } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SYNT_REALTIME_BARS) { - args.push(keepUpToDate); - } + if (_.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + if (!_.isArray(contract.comboLegs)) { + args.push(0); + } else { + args.push(contract.comboLegs.length); + + contract.comboLegs.forEach(function (comboLeg) { + args.push(comboLeg.conId); + args.push(comboLeg.ratio); + args.push(comboLeg.action); + args.push(comboLeg.exchange); + }); + } + } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.LINKING) { - args.push(''); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SYNT_REALTIME_BARS) { + args.push(keepUpToDate); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.LINKING) { + args.push(''); + } - this._send(args); + this._send(args); }; Outgoing.prototype.reqHistoricalTicks = function (tickerId, contract, startDateTime, endDateTime, - numberOfTicks, whatToShow, useRTH, ignoreSize) { + numberOfTicks, whatToShow, useRTH, ignoreSize) { + + if (this._controller._serverVersion < 73) { + return this._controller.emitError('It does not support historical tick data backfill.'); + } - if (this._controller._serverVersion < 73) { - return this._controller.emitError('It does not support historical tick data backfill.'); - } + var args = [C.OUTGOING.REQ_HISTORICAL_TICKS, tickerId]; - var args = [C.OUTGOING.REQ_HISTORICAL_TICKS, tickerId]; + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.conId); + } - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.conId); - } - - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); - args.push(contract.tradingClass); - args.push(contract.includeExpired); - - args.push(startDateTime); - args.push(endDateTime); - - args.push(numberOfTicks); - args.push(whatToShow); - args.push(useRTH); - - if (_.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - if (!_.isArray(contract.comboLegs)) { - args.push(0); - } else { - args.push(contract.comboLegs.length); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); + args.push(contract.tradingClass); + args.push(contract.includeExpired); - contract.comboLegs.forEach(function (comboLeg) { - args.push(comboLeg.conId); - args.push(comboLeg.ratio); - args.push(comboLeg.action); - args.push(comboLeg.exchange); - }); + args.push(startDateTime); + args.push(endDateTime); + + args.push(numberOfTicks); + args.push(whatToShow); + args.push(useRTH); + + if (_.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + if (!_.isArray(contract.comboLegs)) { + args.push(0); + } else { + args.push(contract.comboLegs.length); + + contract.comboLegs.forEach(function (comboLeg) { + args.push(comboLeg.conId); + args.push(comboLeg.ratio); + args.push(comboLeg.action); + args.push(comboLeg.exchange); + }); + } } - } - args.push(ignoreSize); + args.push(ignoreSize); - if (this._controller._serverVersion >= C.MIN_SERVER_VER.LINKING) { - args.push(''); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.LINKING) { + args.push(''); + } - this._send(args); + this._send(args); }; -Outgoing.prototype.reqTickByTickData = function (tickerId, contract, tickType, numberOfTicks, ignoreSize){ - if (this._controller._serverVersion < 73) { - return this._controller.emitError('It does not support tick by tick data.'); - } - - var args = [C.OUTGOING.REQ_TICK_BY_TICK_DATA, tickerId]; - - // send contract fields - args.push(contract.conId); - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); - args.push(contract.tradingClass); - - args.push(tickType); - args.push(numberOfTicks); - args.push(ignoreSize); - - this._send(args); +Outgoing.prototype.reqTickByTickData = function (tickerId, contract, tickType, numberOfTicks, ignoreSize) { + if (this._controller._serverVersion < 73) { + return this._controller.emitError('It does not support tick by tick data.'); + } + + var args = [C.OUTGOING.REQ_TICK_BY_TICK_DATA, tickerId]; + + // send contract fields + args.push(contract.conId); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); + args.push(contract.tradingClass); + + args.push(tickType); + args.push(numberOfTicks); + args.push(ignoreSize); + + this._send(args); }; Outgoing.prototype.cancelTickByTickData = function (tickerId) { - if (this._controller._serverVersion < 73) { - return this._controller.emitError('It does not support tick by tick data.'); - } + if (this._controller._serverVersion < 73) { + return this._controller.emitError('It does not support tick by tick data.'); + } - var args = [C.OUTGOING.CANCEL_TICK_BY_TICK_DATA, tickerId]; - - this._send(args); + var args = [C.OUTGOING.CANCEL_TICK_BY_TICK_DATA, tickerId]; + + this._send(args); }; Outgoing.prototype.reqIds = function (numIds) { - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_IDS, version, numIds); + this._send(C.OUTGOING.REQ_IDS, version, numIds); }; Outgoing.prototype.reqManagedAccts = function () { - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_MANAGED_ACCTS, version); + this._send(C.OUTGOING.REQ_MANAGED_ACCTS, version); }; Outgoing.prototype.reqMarketDataType = function (marketDataType) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_MARKET_DATA_TYPE) { - return this._controller.emitError('It does not support marketDataType requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_MARKET_DATA_TYPE) { + return this._controller.emitError('It does not support marketDataType requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_MARKET_DATA_TYPE, version, marketDataType); + this._send(C.OUTGOING.REQ_MARKET_DATA_TYPE, version, marketDataType); }; Outgoing.prototype.reqMktData = function (tickerId, contract, genericTickList, snapshot, regulatorySnapshot) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.SNAPSHOT_MKT_DATA && snapshot) { - return this._controller.emitError('It does not support snapshot market data requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.SNAPSHOT_MKT_DATA && snapshot) { + return this._controller.emitError('It does not support snapshot market data requests.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.UNDER_COMP) { - return this._controller.emitError('It does not support delta-neutral orders.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.UNDER_COMP) { + return this._controller.emitError('It does not support delta-neutral orders.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_MKT_DATA_CONID) { - return this._controller.emitError('It does not support conId parameter.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REQ_MKT_DATA_CONID) { + return this._controller.emitError('It does not support conId parameter.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass)) { - return this._controller.emitError('It does not support tradingClass parameter in reqMarketData.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass)) { + return this._controller.emitError('It does not support tradingClass parameter in reqMarketData.'); + } } - } - var version = 11; + var version = 11; - var args = [C.OUTGOING.REQ_MKT_DATA, version, tickerId]; + var args = [C.OUTGOING.REQ_MKT_DATA, version, tickerId]; - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.REQ_MKT_DATA_CONID) { - args.push(contract.conId); - } - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - - if (this._controller._serverVersion >= 15) { - args.push(contract.multiplier); - } + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.REQ_MKT_DATA_CONID) { + args.push(contract.conId); + } + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + + if (this._controller._serverVersion >= 15) { + args.push(contract.multiplier); + } - args.push(contract.exchange); + args.push(contract.exchange); - if (this._controller._serverVersion >= 14) { - args.push(contract.primaryExch); - } + if (this._controller._serverVersion >= 14) { + args.push(contract.primaryExch); + } - args.push(contract.currency); + args.push(contract.currency); - if (this._controller._serverVersion >= 2) { - args.push(contract.localSymbol); - } + if (this._controller._serverVersion >= 2) { + args.push(contract.localSymbol); + } - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - if (this._controller._serverVersion >= 8 && - _.isString(contract.secType) && - C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { - if (!_.isArray(contract.comboLegs)) { - args.push(0); - } else { - args.push(contract.comboLegs.length); - contract.comboLegs.forEach(function (comboLeg) { - args.push(comboLeg.conId); - args.push(comboLeg.ratio); - args.push(comboLeg.action); - args.push(comboLeg.exchange); - }); - } - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.UNDER_COMP) { - if (_.isPlainObject(contract.underComp)) { - args.push(true); - args.push(contract.underComp.conId); - args.push(contract.underComp.delta); - args.push(contract.underComp.price); - } else { - args.push(false); - } - } - - if (this._controller._serverVersion >= 31) { - /* - * Note: Even though SHORTABLE tick type supported only - * starting server version 33 it would be relatively - * expensive to expose this restriction here. - * - * Therefore we are relying on TWS doing validation. - */ - args.push(genericTickList); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.SNAPSHOT_MKT_DATA) { - args.push(snapshot); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.REQ_SMART_COMPONENTS) { - args.push(regulatorySnapshot); - } - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.LINKING) { - args.push(''); - } - - this._send(args); + if (this._controller._serverVersion >= 8 && + _.isString(contract.secType) && + C.BAG_SEC_TYPE.toUpperCase() === contract.secType.toUpperCase()) { + if (!_.isArray(contract.comboLegs)) { + args.push(0); + } else { + args.push(contract.comboLegs.length); + contract.comboLegs.forEach(function (comboLeg) { + args.push(comboLeg.conId); + args.push(comboLeg.ratio); + args.push(comboLeg.action); + args.push(comboLeg.exchange); + }); + } + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.UNDER_COMP) { + if (_.isPlainObject(contract.underComp)) { + args.push(true); + args.push(contract.underComp.conId); + args.push(contract.underComp.delta); + args.push(contract.underComp.price); + } else { + args.push(false); + } + } + + if (this._controller._serverVersion >= 31) { + /* + * Note: Even though SHORTABLE tick type supported only + * starting server version 33 it would be relatively + * expensive to expose this restriction here. + * + * Therefore we are relying on TWS doing validation. + */ + args.push(genericTickList); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.SNAPSHOT_MKT_DATA) { + args.push(snapshot); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.REQ_SMART_COMPONENTS) { + args.push(regulatorySnapshot); + } + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.LINKING) { + args.push(''); + } + + this._send(args); }; Outgoing.prototype.reqMktDepth = function (tickerId, contract, numRows) { - if (this._controller._serverVersion < 6) { - return this._controller.emitError('This feature is only available for versions of TWS >=6'); - } + if (this._controller._serverVersion < 6) { + return this._controller.emitError('This feature is only available for versions of TWS >=6'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { - return this._controller.emitError('It does not support conId and tradingClass parameters in reqMktDepth.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { + return this._controller.emitError('It does not support conId and tradingClass parameters in reqMktDepth.'); + } } - } - var version = 4; + var version = 4; - // send req mkt data msg - var args = [C.OUTGOING.REQ_MKT_DEPTH, version, tickerId]; + // send req mkt data msg + var args = [C.OUTGOING.REQ_MKT_DEPTH, version, tickerId]; - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.conId); - } + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.conId); + } - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); - if (this._controller._serverVersion >= 15) { - args.push(contract.multiplier); - } + if (this._controller._serverVersion >= 15) { + args.push(contract.multiplier); + } - args.push(contract.exchange); - args.push(contract.currency); - args.push(contract.localSymbol); + args.push(contract.exchange); + args.push(contract.currency); + args.push(contract.localSymbol); - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - if (this._controller._serverVersion >= 19) { - args.push(numRows); - } + if (this._controller._serverVersion >= 19) { + args.push(numRows); + } - this._send(args); + this._send(args); }; + +Outgoing.prototype.reqNewsProviders = function () { + var version = 1; + + this._send(C.OUTGOING.REQ_NEWS_PROVIDERS); +} +Outgoing.prototype.reqHistoricalNews = function (requestId, conId, providerCodes, startDateTime = '', endDateTime = '', totalResults = 10) { + + this._send(C.OUTGOING.REQ_HISTORICAL_NEWS,requestId, conId, providerCodes, startDateTime , endDateTime , totalResults ); +} + Outgoing.prototype.reqNewsBulletins = function (allMsgs) { - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_NEWS_BULLETINS, version, allMsgs); + this._send(C.OUTGOING.REQ_NEWS_BULLETINS, version, allMsgs); }; Outgoing.prototype.reqOpenOrders = function () { - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_OPEN_ORDERS, version); + this._send(C.OUTGOING.REQ_OPEN_ORDERS, version); }; Outgoing.prototype.reqPositions = function () { - if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { - return this._controller.emitError('It does not support position requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { + return this._controller.emitError('It does not support position requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_POSITIONS, version); + this._send(C.OUTGOING.REQ_POSITIONS, version); }; Outgoing.prototype.reqPositionsMulti = function (reqId, account, modelCode) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { - return this._controller.emitError('It does not support position requests.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.ACCT_SUMMARY) { + return this._controller.emitError('It does not support position requests.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_POSITIONS_MULTI, version, reqId, account, modelCode); + this._send(C.OUTGOING.REQ_POSITIONS_MULTI, version, reqId, account, modelCode); }; Outgoing.prototype.reqRealTimeBars = function (tickerId, contract, barSize, whatToShow, useRTH) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.REAL_TIME_BARS) { - return this._controller.emitError('It does not support real time bars.'); - } + if (this._controller._serverVersion < C.MIN_SERVER_VER.REAL_TIME_BARS) { + return this._controller.emitError('It does not support real time bars.'); + } - if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { - if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { - return this._controller.emitError('It does not support conId and tradingClass parameters in reqRealTimeBars.'); + if (this._controller._serverVersion < C.MIN_SERVER_VER.TRADING_CLASS) { + if (!_.isEmpty(contract.tradingClass) || contract.conId > 0) { + return this._controller.emitError('It does not support conId and tradingClass parameters in reqRealTimeBars.'); + } } - } - var version = 2; + var version = 2; - // send req mkt data msg - var args = [C.OUTGOING.REQ_REAL_TIME_BARS, version, tickerId]; + // send req mkt data msg + var args = [C.OUTGOING.REQ_REAL_TIME_BARS, version, tickerId]; - // send contract fields - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.conId); - } - - args.push(contract.symbol); - args.push(contract.secType); - args.push(contract.expiry); - args.push(contract.strike); - args.push(contract.right); - args.push(contract.multiplier); - args.push(contract.exchange); - args.push(contract.primaryExch); - args.push(contract.currency); - args.push(contract.localSymbol); - - if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { - args.push(contract.tradingClass); - } + // send contract fields + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.conId); + } + + args.push(contract.symbol); + args.push(contract.secType); + args.push(contract.expiry); + args.push(contract.strike); + args.push(contract.right); + args.push(contract.multiplier); + args.push(contract.exchange); + args.push(contract.primaryExch); + args.push(contract.currency); + args.push(contract.localSymbol); + + if (this._controller._serverVersion >= C.MIN_SERVER_VER.TRADING_CLASS) { + args.push(contract.tradingClass); + } - args.push(barSize); // this parameter is not currently used - args.push(whatToShow); - args.push(useRTH); + args.push(barSize); // this parameter is not currently used + args.push(whatToShow); + args.push(useRTH); - this._send(args); + this._send(args); }; Outgoing.prototype.reqScannerParameters = function () { - if (this._controller._serverVersion < 24) { - return this._controller.emitError('It does not support API scanner subscription.'); - } + if (this._controller._serverVersion < 24) { + return this._controller.emitError('It does not support API scanner subscription.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_SCANNER_PARAMETERS, version); + this._send(C.OUTGOING.REQ_SCANNER_PARAMETERS, version); }; Outgoing.prototype.reqScannerSubscription = function (tickerId, subscription) { - if (this._controller._serverVersion < 24) { - return this._controller.emitError('It does not support API scanner subscription.'); - } - - var version = 3; - - var args = [C.OUTGOING.REQ_SCANNER_SUBSCRIPTION, version, tickerId]; - - args.push(_nullifyMax(subscription.numberOfRows)); - args.push(subscription.instrument); - args.push(subscription.locationCode); - args.push(subscription.scanCode); - args.push(_nullifyMax(subscription.abovePrice)); - args.push(_nullifyMax(subscription.belowPrice)); - args.push(_nullifyMax(subscription.aboveVolume)); - args.push(_nullifyMax(subscription.marketCapAbove)); - args.push(_nullifyMax(subscription.marketCapBelow)); - args.push(subscription.moodyRatingAbove); - args.push(subscription.moodyRatingBelow); - args.push(subscription.spRatingAbove); - args.push(subscription.spRatingBelow); - args.push(subscription.maturityDateAbove); - args.push(subscription.maturityDateBelow); - args.push(_nullifyMax(subscription.couponRateAbove)); - args.push(_nullifyMax(subscription.couponRateBelow)); - args.push(subscription.excludeConvertible); - - if (this._controller._serverVersion >= 25) { - args.push(_nullifyMax(subscription.averageOptionVolumeAbove)); - args.push(subscription.scannerSettingPairs); - } - - if (this._controller._serverVersion >= 27) { - args.push(subscription.stockTypeFilter); - } - - this._send(args); + if (this._controller._serverVersion < 24) { + return this._controller.emitError('It does not support API scanner subscription.'); + } + + var version = 3; + + var args = [C.OUTGOING.REQ_SCANNER_SUBSCRIPTION, version, tickerId]; + + args.push(_nullifyMax(subscription.numberOfRows)); + args.push(subscription.instrument); + args.push(subscription.locationCode); + args.push(subscription.scanCode); + args.push(_nullifyMax(subscription.abovePrice)); + args.push(_nullifyMax(subscription.belowPrice)); + args.push(_nullifyMax(subscription.aboveVolume)); + args.push(_nullifyMax(subscription.marketCapAbove)); + args.push(_nullifyMax(subscription.marketCapBelow)); + args.push(subscription.moodyRatingAbove); + args.push(subscription.moodyRatingBelow); + args.push(subscription.spRatingAbove); + args.push(subscription.spRatingBelow); + args.push(subscription.maturityDateAbove); + args.push(subscription.maturityDateBelow); + args.push(_nullifyMax(subscription.couponRateAbove)); + args.push(_nullifyMax(subscription.couponRateBelow)); + args.push(subscription.excludeConvertible); + + if (this._controller._serverVersion >= 25) { + args.push(_nullifyMax(subscription.averageOptionVolumeAbove)); + args.push(subscription.scannerSettingPairs); + } + + if (this._controller._serverVersion >= 27) { + args.push(subscription.stockTypeFilter); + } + + this._send(args); }; Outgoing.prototype.requestFA = function (faDataType) { - if (this._controller._serverVersion < 13) { - return this._controller.emitError('This feature is only available for versions of TWS >= 13.'); - } + if (this._controller._serverVersion < 13) { + return this._controller.emitError('This feature is only available for versions of TWS >= 13.'); + } - var version = 1; + var version = 1; - this._send(C.OUTGOING.REQ_FA, version, faDataType); + this._send(C.OUTGOING.REQ_FA, version, faDataType); }; Outgoing.prototype.setServerLogLevel = function (logLevel) { - var version = 1; + var version = 1; - this._send(C.OUTGOING.SET_SERVER_LOGLEVEL, version, logLevel); + this._send(C.OUTGOING.SET_SERVER_LOGLEVEL, version, logLevel); }; Outgoing.prototype.queryDisplayGroups = function (reqId) { - this._send(C.OUTGOING.QUERY_DISPLAY_GROUPS, 1, reqId); + this._send(C.OUTGOING.QUERY_DISPLAY_GROUPS, 1, reqId); }; Outgoing.prototype.updateDisplayGroup = function (reqId, contractInfo) { - this._send(C.OUTGOING.UPDATE_DISPLAY_GROUP, 1, reqId, contractInfo); + this._send(C.OUTGOING.UPDATE_DISPLAY_GROUP, 1, reqId, contractInfo); }; Outgoing.prototype.subscribeToGroupEvents = function (reqId, groupId) { - this._send(C.OUTGOING.SUBSCRIBE_TO_GROUP_EVENTS, 1, reqId, groupId); + this._send(C.OUTGOING.SUBSCRIBE_TO_GROUP_EVENTS, 1, reqId, groupId); }; Outgoing.prototype.unsubscribeToGroupEvents = function (reqId) { - this._send(C.OUTGOING.UNSUBSCRIBE_FROM_GROUP_EVENTS, 1, reqId); + this._send(C.OUTGOING.UNSUBSCRIBE_FROM_GROUP_EVENTS, 1, reqId); }; -Outgoing.prototype.reqSecDefOptParams = function(reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId) { - if (this._controller._serverVersion < C.MIN_SERVER_VER.SEC_DEF_OPT_PARAMS_REQ) { - // We don't currently support the v100 extended handshake so our server version shows up as < 100. - // However, this functionality still works so we skip the version check for now. - // - //return this._controller.emitError('It does not support reqSecDefOptParams.'); - } - this._send(C.OUTGOING.REQ_SEC_DEF_OPT_PARAMS, reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId); +Outgoing.prototype.reqSecDefOptParams = function (reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId) { + if (this._controller._serverVersion < C.MIN_SERVER_VER.SEC_DEF_OPT_PARAMS_REQ) { + // We don't currently support the v100 extended handshake so our server version shows up as < 100. + // However, this functionality still works so we skip the version check for now. + // + //return this._controller.emitError('It does not support reqSecDefOptParams.'); + } + this._send(C.OUTGOING.REQ_SEC_DEF_OPT_PARAMS, reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId); }; module.exports = Outgoing; From ea07530eaa1283df55d37f1b0c9ee41345405aa6 Mon Sep 17 00:00:00 2001 From: amit21 Date: Mon, 4 Feb 2019 19:19:27 +0200 Subject: [PATCH 2/2] added 2 news functions reqNewsProviders reqHistoricalNews --- package-lock.json | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 61c8a80..b44b9a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ib", - "version": "0.2.5", + "version": "0.2.7", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -123,7 +123,8 @@ "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", - "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==" + "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", + "dev": true }, "aws-sign2": { "version": "0.7.0", @@ -2937,9 +2938,9 @@ } }, "sprintf-js": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.1.tgz", - "integrity": "sha1-Nr54Mgr+WAH2zqPueLblqrlA6gw=", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", + "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==", "dev": true }, "sshpk": { @@ -3294,9 +3295,9 @@ "optional": true }, "underscore.string": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.4.tgz", - "integrity": "sha1-LCo/n4PmR2L9xF5s6sZRQoZCE9s=", + "version": "3.3.5", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.3.5.tgz", + "integrity": "sha512-g+dpmgn+XBneLmXXo+sGlW5xQEt4ErkS3mgeN2GFbremYeMBSJKr9Wf2KJplQVaiPY/f7FN6atosWYNm9ovrYg==", "dev": true, "requires": { "sprintf-js": "^1.0.3",