UNPKG

ib-client

Version:

Interactive Brokers API client library for Node.js

1,492 lines (1,129 loc) 52 kB
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _events = require("events"); var _validators = require("./validators"); var _Socket = _interopRequireDefault(require("./Socket")); var _OutboundQueue = _interopRequireDefault(require("./OutboundQueue")); var _InboundQueue = _interopRequireDefault(require("./InboundQueue")); var _MessageEncoder = _interopRequireDefault(require("./MessageEncoder")); var _MessageDecoder = _interopRequireDefault(require("./MessageDecoder")); var _errors = require("./errors");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { "default": obj };}function _typeof(obj) {"@babel/helpers - typeof";if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {_typeof = function _typeof(obj) {return typeof obj;};} else {_typeof = function _typeof(obj) {return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;};}return _typeof(obj);}function _toConsumableArray(arr) {return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();}function _nonIterableSpread() {throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o, minLen) {if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(o);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);}function _iterableToArray(iter) {if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);}function _arrayWithoutHoles(arr) {if (Array.isArray(arr)) return _arrayLikeToArray(arr);}function _arrayLikeToArray(arr, len) {if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {arr2[i] = arr[i];}return arr2;}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}function _createClass(Constructor, protoProps, staticProps) {if (protoProps) _defineProperties(Constructor.prototype, protoProps);if (staticProps) _defineProperties(Constructor, staticProps);return Constructor;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function");}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });if (superClass) _setPrototypeOf(subClass, superClass);}function _setPrototypeOf(o, p) {_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {o.__proto__ = p;return o;};return _setPrototypeOf(o, p);}function _createSuper(Derived) {var hasNativeReflectConstruct = _isNativeReflectConstruct();return function _createSuperInternal() {var Super = _getPrototypeOf(Derived),result;if (hasNativeReflectConstruct) {var NewTarget = _getPrototypeOf(this).constructor;result = Reflect.construct(Super, arguments, NewTarget);} else {result = Super.apply(this, arguments);}return _possibleConstructorReturn(this, result);};}function _possibleConstructorReturn(self, call) {if (call && (_typeof(call) === "object" || typeof call === "function")) {return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self) {if (self === void 0) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct() {if (typeof Reflect === "undefined" || !Reflect.construct) return false;if (Reflect.construct.sham) return false;if (typeof Proxy === "function") return true;try {Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));return true;} catch (e) {return false;}}function _getPrototypeOf(o) {_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {return o.__proto__ || Object.getPrototypeOf(o);};return _getPrototypeOf(o);}var IBClient = /*#__PURE__*/function (_EventEmitter) {_inherits(IBClient, _EventEmitter);var _super = _createSuper(IBClient); function IBClient() {var _this;var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { socket: null, clientId: null, socketWrapper: null, messageEncoder: null, messageDecoder: null, inboundQueue: null, outboundQueue: null };_classCallCheck(this, IBClient); _this = _super.call(this); _this._clientId = options.clientId; _this._messageEncoder = options.messageEncoder || new _MessageEncoder["default"](); _this._messageDecoder = options.messageDecoder || new _MessageDecoder["default"](); _this._inboundQueue = options.inboundQueue || _this._initInboundQueue(); _this._socket = options.socketWrapper || _this._initSocket(options.socket); _this._outboundQueue = options.outboundQueue || _this._initOutboundQueue();return _this; }_createClass(IBClient, [{ key: "_initSocket", value: function _initSocket( options) {var _this2 = this; return new _Socket["default"](options). onError(function (err) {return _this2.emit('error', err);}). onConnected(function () {return _this2.emit('connected');}). onClose(function (err) {return _this2.emit('disconnected', err);}). onServerData(function (data) {var _this2$_messageDecode = _this2._messageDecoder.decodeServerVersion(data),serverVersion = _this2$_messageDecode.serverVersion; _this2._messageEncoder.setServerVersion(serverVersion); _this2._messageDecoder.setServerVersion(serverVersion); _this2.startAPI(); }). onResponse(function (data) {return _this2._inboundQueue.push(data);}); } }, { key: "_initInboundQueue", value: function _initInboundQueue() {var _this3 = this; return new _InboundQueue["default"](function (message, cb) {return _this3.onResponseMessage(message, cb);}); } }, { key: "_initOutboundQueue", value: function _initOutboundQueue() {var _this4 = this; return new _OutboundQueue["default"](function (message, cb) {return _this4.onSendMessage(message, cb);}, { preCondition: function preCondition(cb) {return cb(null, _this4._socket.isConnected());}, priority: function priority(message, cb) {return ['startAPI'].includes(message[1]) ? cb(null, 10) : cb(null, 5);} }); } }, { key: "_sendMessage", value: function _sendMessage() {var _this5 = this; var message = Array.from(arguments); this._outboundQueue.push(message).on('failure', function (err) {return _this5.emit('error', err);}); } }, { key: "onSendMessage", value: function onSendMessage( message, cb) {var _this6 = this; try {var _this$_messageEncoder = this._messageEncoder.encodeMessage(message),encoded = _this$_messageEncoder.message; this._socket.write(encoded, function (result) {return _this6.emit('sent', message, result);}); } catch (err) { this.emit('error', err); } cb(null, true); } }, { key: "onResponseMessage", value: function onResponseMessage( message, cb) { var result = this._messageDecoder.decodeMessage(message); this._emitResponseMessageEvent(result); cb(null, true); } }, { key: "_emitResponseMessageEvent", value: function _emitResponseMessageEvent( result) {var _this7 = this; if (!Array.isArray(result)) this._emitMessageEvent(result); result.map(function (msg) {return _this7._emitMessageEvent(msg);}); } }, { key: "_emitMessageEvent", value: function _emitMessageEvent( msg) { if (msg.params) { this.emit.apply(this, [msg.message].concat(_toConsumableArray(msg.params))); } else { this.emit(msg.message); } } }, { key: "connect", value: function connect() {var _this8 = this; this._socket.connect(function () {return _this8.sendV100APIHeader();}); return this; } }, { key: "disconnect", value: function disconnect() { this._socket.disconnect(); return this; } }, { key: "isConnected", value: function isConnected() { return this._socket.isConnected(); } }, { key: "sendV100APIHeader", value: function sendV100APIHeader() { var message = this._messageEncoder.sendV100APIHeader(); this._socket.write(message, function () {}); } }, { key: "startAPI", value: function startAPI() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_STARTAPI }, 'startAPI', this._clientId, '' // optionalCapabilities ); return this; } }, { key: "cancelScannerSubscription", value: function cancelScannerSubscription( tickerId) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANSCANNER }, 'cancelScannerSubscription', tickerId); return this; } }, { key: "reqScannerParameters", value: function reqScannerParameters() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQSCANNERPARAMETERS }, 'reqScannerParameters'); return this; } }, { key: "reqScannerSubscription", value: function reqScannerSubscription( tickerId, subscription, scannerSubscriptionOptions, scannerSubscriptionFilterOptions) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.UPDATE_TWS }, 'reqScannerSubscription', tickerId, subscription, scannerSubscriptionOptions, scannerSubscriptionFilterOptions); return this; } }, { key: "reqMktData", value: function reqMktData( tickerId, contract, genericTickList, snapshot, regulatorySnapshot, mktDataOptions) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)( typeof genericTickList === 'string', '"genericTickList" must be a string - ' + genericTickList); (0, _validators.validateInput)(typeof snapshot === 'boolean', '"snapshot" must be a boolean - ' + snapshot); (0, _validators.validateInput)( typeof regulatorySnapshot === 'boolean', '"regulatorySnapshot" must be a boolean - ' + regulatorySnapshot); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMKT }, 'reqMktData', tickerId, contract, genericTickList, snapshot, regulatorySnapshot, mktDataOptions); return this; } }, { key: "cancelHistoricalData", value: function cancelHistoricalData( tickerId) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANHISTDATA }, 'cancelHistoricalData', tickerId); return this; } }, { key: "cancelRealTimeBars", value: function cancelRealTimeBars( tickerId) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANRTBARS }, 'cancelRealTimeBars', tickerId); return this; } }, { key: "reqHistoricalData", value: function reqHistoricalData( tickerId, contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate, keepUpToDate, chartOptions) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)( typeof endDateTime === 'string', '"endDateTime" must be a string - ' + endDateTime); (0, _validators.validateInput)( typeof durationStr === 'string', '"durationStr" must be a string - ' + durationStr); (0, _validators.validateInput)( typeof barSizeSetting === 'string', '"barSizeSetting" must be a string - ' + barSizeSetting); (0, _validators.validateInput)(typeof whatToShow === 'string', '"whatToShow" must be a string - ' + whatToShow); (0, _validators.validateInput)(Number.isInteger(useRTH), '"useRTH" must be an integer - ' + useRTH); (0, _validators.validateInput)(Number.isInteger(formatDate), '"formatDate" must be an integer - ' + formatDate); (0, _validators.validateInput)( typeof keepUpToDate === 'boolean', '"keepUpToDate" must be an boolean - ' + keepUpToDate); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQHISTDATA }, 'reqHistoricalData', tickerId, contract, endDateTime, durationStr, barSizeSetting, whatToShow, useRTH, formatDate, keepUpToDate, chartOptions); return this; } }, { key: "reqHeadTimestamp", value: function reqHeadTimestamp( reqId, contract, whatToShow, useRTH, formatDate) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof whatToShow === 'string', '"whatToShow" must be a string - ' + whatToShow); (0, _validators.validateInput)(Number.isInteger(useRTH), '"useRTH" must be an integer - ' + useRTH); (0, _validators.validateInput)(Number.isInteger(formatDate), '"formatDate" must be an integer - ' + formatDate); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQHEADTIMESTAMP }, 'reqHeadTimestamp', reqId, contract, whatToShow, useRTH, formatDate); return this; } }, { key: "cancelHeadTimestamp", value: function cancelHeadTimestamp( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANHEADTIMESTAMP }, 'cancelHeadTimestamp', reqId); return this; } }, { key: "reqRealTimeBars", value: function reqRealTimeBars( tickerId, contract, barSize, whatToShow, useRTH, realTimeBarsOptions) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)(Number.isInteger(barSize), '"barSize" must be an integer - ' + barSize); (0, _validators.validateInput)(typeof whatToShow === 'string', '"whatToShow" must be a string - ' + whatToShow); (0, _validators.validateInput)(typeof useRTH === 'boolean', '"useRTH" must be a boolean - ' + useRTH); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQRTBARS }, 'reqRealTimeBars', tickerId, contract, barSize, whatToShow, useRTH, realTimeBarsOptions); return this; } }, { key: "reqContractDetails", value: function reqContractDetails( reqId, contract) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQCONTRACT }, 'reqContractDetails', reqId, contract); return this; } }, { key: "reqMktDepth", value: function reqMktDepth( tickerId, contract, numRows, isSmartDepth, mktDepthOptions) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)(Number.isInteger(numRows), '"numRows" must be an integer - ' + numRows); (0, _validators.validateInput)( typeof isSmartDepth === 'boolean', '"isSmartDepth" must be a boolean - ' + isSmartDepth); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMKTDEPTH }, 'reqMktDepth', tickerId, contract, numRows, isSmartDepth, mktDepthOptions); return this; } }, { key: "cancelMktData", value: function cancelMktData( tickerId) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANMKT }, 'cancelMktData', tickerId); return this; } }, { key: "cancelMktDepth", value: function cancelMktDepth( tickerId, isSmartDepth) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)( typeof isSmartDepth === 'boolean', '"isSmartDepth" must be a boolean - ' + isSmartDepth); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANMKTDEPTH }, 'cancelMktDepth', tickerId); return this; } }, { key: "exerciseOptions", value: function exerciseOptions( tickerId, contract, exerciseAction, exerciseQuantity, account, override) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)( Number.isInteger(exerciseAction), '"exerciseAction" must be an integer - ' + exerciseAction); (0, _validators.validateInput)( Number.isInteger(exerciseQuantity), '"exerciseQuantity" must be an integer - ' + exerciseQuantity); (0, _validators.validateInput)(typeof account === 'string', '"account" must be a string - ' + account); (0, _validators.validateInput)(Number.isInteger(override), '"override" must be an integer - ' + override); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMKT }, 'exerciseOptions', tickerId, contract, exerciseAction, exerciseQuantity, account, override); return this; } }, { key: "placeOrder", value: function placeOrder( id, contract, order) { (0, _validators.validateInput)(Number.isInteger(id), '"id" must be an integer - ' + id); this._sendMessage( { id: id, error: _errors.BROKER_ERRORS.FAIL_SEND_ORDER }, 'placeOrder', id, contract, order); return this; } }, { key: "reqAccountUpdates", value: function reqAccountUpdates( subscribe, acctCode) { (0, _validators.validateInput)(typeof subscribe === 'boolean', '"subscribe" must be a boolean - ' + subscribe); (0, _validators.validateInput)(typeof acctCode === 'string', '"acctCode" must be a string - ' + acctCode); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_ACCT }, 'reqAccountUpdates', subscribe, acctCode); return this; } }, { key: "reqExecutions", value: function reqExecutions( reqId, filter) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_EXEC }, 'reqExecutions', reqId, filter); return this; } }, { key: "cancelOrder", value: function cancelOrder( id) { (0, _validators.validateInput)(Number.isInteger(id), '"id" must be an integer - ' + id); this._sendMessage( { id: id, error: _errors.BROKER_ERRORS.FAIL_SEND_CORDER }, 'cancelOrder', id); return this; } }, { key: "reqOpenOrders", value: function reqOpenOrders() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_OORDER }, 'reqOpenOrders'); return this; } }, { key: "reqIds", value: function reqIds( numIds) { (0, _validators.validateInput)(Number.isInteger(numIds), '"numIds" must be an integer - ' + numIds); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_CORDER }, 'reqIds', numIds); return this; } }, { key: "reqNewsBulletins", value: function reqNewsBulletins( allMsgs) { (0, _validators.validateInput)(typeof allMsgs === 'boolean', '"allMsgs" must be a boolean - ' + allMsgs); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_CORDER }, 'reqNewsBulletins', allMsgs); return this; } }, { key: "cancelNewsBulletins", value: function cancelNewsBulletins() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_CORDER }, 'cancelNewsBulletins'); return this; } }, { key: "setServerLogLevel", value: function setServerLogLevel( logLevel) { (0, _validators.validateInput)(Number.isInteger(logLevel), '"logLevel" must be an integer - ' + logLevel); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_SERVER_LOG_LEVEL }, 'setServerLogLevel', logLevel); return this; } }, { key: "reqAutoOpenOrders", value: function reqAutoOpenOrders( bAutoBind) { (0, _validators.validateInput)(typeof bAutoBind === 'boolean', '"bAutoBind" must be a boolean - ' + bAutoBind); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_OORDER }, 'reqAutoOpenOrders', bAutoBind); return this; } }, { key: "reqAllOpenOrders", value: function reqAllOpenOrders() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_OORDER }, 'reqAllOpenOrders'); return this; } }, { key: "reqManagedAccts", value: function reqManagedAccts() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_OORDER }, 'reqManagedAccts'); return this; } }, { key: "requestFA", value: function requestFA( faDataType) { (0, _validators.validateInput)(Number.isInteger(faDataType), '"faDataType" must be an integer - ' + faDataType); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_FA_REQUEST }, 'requestFA', faDataType); return this; } }, { key: "replaceFA", value: function replaceFA( faDataType, xml) { (0, _validators.validateInput)(Number.isInteger(faDataType), '"faDataType" must be an integer - ' + faDataType); (0, _validators.validateInput)(typeof xml === 'string', '"xml" must be a string - ' + xml); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_FA_REPLACE }, 'replaceFA', faDataType, xml); return this; } }, { key: "reqCurrentTime", value: function reqCurrentTime() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQCURRTIME }, 'reqCurrentTime'); return this; } }, { key: "reqFundamentalData", value: function reqFundamentalData( reqId, contract, reportType) {var fundamentalDataOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof reportType === 'string', '"reportType" must be a string - ' + reportType); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQFUNDDATA }, 'reqFundamentalData', reqId, contract, reportType, fundamentalDataOptions); return this; } }, { key: "cancelFundamentalData", value: function cancelFundamentalData( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: FAIL_SEND_CANFUNDDATA }, 'cancelFundamentalData', reqId); return this; } }, { key: "calculateImpliedVolatility", value: function calculateImpliedVolatility( reqId, contract, optionPrice, underPrice) {var impliedVolatilityOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQCALCIMPLIEDVOLAT }, 'calculateImpliedVolatility', reqId, contract, optionPrice, underPrice, impliedVolatilityOptions); return this; } }, { key: "cancelCalculateImpliedVolatility", value: function cancelCalculateImpliedVolatility( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANCALCIMPLIEDVOLAT }, 'cancelCalculateImpliedVolatility', reqId); return this; } }, { key: "calculateOptionPrice", value: function calculateOptionPrice( reqId, contract, volatility, underPrice) {var optionPriceOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQCALCOPTIONPRICE }, 'calculateOptionPrice', reqId, contract, volatility, underPrice, optionPriceOptions); return this; } }, { key: "cancelCalculateOptionPrice", value: function cancelCalculateOptionPrice( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANCALCOPTIONPRICE }, 'cancelCalculateOptionPrice', reqId); return this; } }, { key: "reqGlobalCancel", value: function reqGlobalCancel() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQGLOBALCANCEL }, 'reqGlobalCancel'); return this; } }, { key: "reqMarketDataType", value: function reqMarketDataType( marketDataType) { (0, _validators.validateInput)( Number.isInteger(marketDataType), '"marketDataType" must be an integer - ' + marketDataType); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMARKETDATATYPE }, 'reqMarketDataType', marketDataType); return this; } }, { key: "reqPositions", value: function reqPositions() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQPOSITIONS }, 'reqPositions'); return this; } }, { key: "reqSecDefOptParams", value: function reqSecDefOptParams( reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)( typeof underlyingSymbol === 'string', '"underlyingSymbol" must be a string - ' + underlyingSymbol); (0, _validators.validateInput)( typeof futFopExchange === 'string', '"futFopExchange" must be a string - ' + futFopExchange); (0, _validators.validateInput)( typeof underlyingSecType === 'string', '"underlyingSecType" must be a string - ' + underlyingSecType); (0, _validators.validateInput)( Number.isInteger(underlyingConId), '"underlyingConId" must be an integer - ' + underlyingConId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQSECDEFOPTPARAMS }, 'reqSecDefOptParams', reqId, underlyingSymbol, futFopExchange, underlyingSecType, underlyingConId); return this; } }, { key: "reqSoftDollarTiers", value: function reqSoftDollarTiers( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQSOFTDOLLARTIERS }, 'reqSoftDollarTiers', reqId); return this; } }, { key: "cancelPositions", value: function cancelPositions() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_CANPOSITIONS }, 'cancelPositions'); return this; } }, { key: "reqPositionsMulti", value: function reqPositionsMulti( reqId, account, modelCode) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof account === 'string', '"account" must be a string - ' + account); (0, _validators.validateInput)( typeof modelCode === 'string' || _typeof(modelCode) === 'object', '"modelCode" must be a string or null - ' + modelCode); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQPOSITIONSMULTI }, 'reqPositionsMulti', reqId, account, modelCode); return this; } }, { key: "cancelPositionsMulti", value: function cancelPositionsMulti( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANPOSITIONSMULTI }, 'cancelPositionsMulti', reqId); return this; } }, { key: "cancelAccountUpdatesMulti", value: function cancelAccountUpdatesMulti( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANACCOUNTUPDATESMULTI }, 'cancelAccountUpdatesMulti', reqId); return this; } }, { key: "reqAccountUpdatesMulti", value: function reqAccountUpdatesMulti( reqId, acctCode, modelCode, ledgerAndNLV) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof acctCode === 'string', '"acctCode" must be a string - ' + acctCode); (0, _validators.validateInput)( typeof modelCode === 'string' || _typeof(modelCode) === 'object', '"modelCode" must be a string or null - ' + modelCode); (0, _validators.validateInput)( typeof ledgerAndNLV === 'boolean', '"ledgerAndNLV" must be a boolean - ' + ledgerAndNLV); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQACCOUNTUPDATESMULTI }, 'reqAccountUpdatesMulti', reqId, acctCode, modelCode, ledgerAndNLV); return this; } }, { key: "reqAccountSummary", value: function reqAccountSummary( reqId, group, tags) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof group === 'string', '"group" must be a string - ' + group); (0, _validators.validateInput)( Array.isArray(tags) || typeof tags === 'string', '"tags" must be array or string - ' + tags); if (Array.isArray(tags)) { tags = tags.join(','); } this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQACCOUNTDATA }, 'reqAccountSummary', reqId, group, tags); return this; } }, { key: "cancelAccountSummary", value: function cancelAccountSummary( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANACCOUNTDATA }, 'cancelAccountSummary', reqId); return this; } }, { key: "verifyRequest", value: function verifyRequest( apiName, apiVersion) { (0, _validators.validateInput)(typeof apiName === 'string', '"apiName" must be a string - ' + apiName); (0, _validators.validateInput)(typeof apiVersion === 'string', '"apiVersion" must be a string - ' + apiVersion); this._sendMessage( { id: EClientErrors.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_VERIFYREQUEST }, 'verifyRequest', apiName, apiVersion); return this; } }, { key: "verifyMessage", value: function verifyMessage( apiData) { (0, _validators.validateInput)(typeof apiData === 'string', '"apiData" must be a string - ' + apiData); this._sendMessage( { id: EClientErrors.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_VERIFYMESSAGE }, 'verifyMessage', apiData); return this; } }, { key: "verifyAndAuthRequest", value: function verifyAndAuthRequest( apiName, apiVersion, opaqueIsvKey) { (0, _validators.validateInput)(typeof apiName === 'string', '"apiName" must be a string - ' + apiName); (0, _validators.validateInput)(typeof apiVersion === 'string', '"apiVersion" must be a string - ' + apiVersion); (0, _validators.validateInput)( typeof opaqueIsvKey === 'string', '"opaqueIsvKey" must be a string - ' + opaqueIsvKey); this._sendMessage( { id: EClientErrors.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_VERIFYANDAUTHREQUEST }, 'verifyAndAuthRequest', apiName, apiVersion, opaqueIsvKey); return this; } }, { key: "verifyAndAuthMessage", value: function verifyAndAuthMessage( apiData, xyzResponse) { (0, _validators.validateInput)(typeof apiData === 'string', '"apiData" must be a string - ' + apiData); (0, _validators.validateInput)( typeof xyzResponse === 'string', '"xyzResponse" must be a string - ' + xyzResponse); this._sendMessage( { id: EClientErrors.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_VERIFYANDAUTHMESSAGE }, 'verifyAndAuthMessage', apiData, xyzResponse); return this; } }, { key: "queryDisplayGroups", value: function queryDisplayGroups( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_QUERYDISPLAYGROUPS }, 'queryDisplayGroups', reqId); return this; } }, { key: "subscribeToGroupEvents", value: function subscribeToGroupEvents( reqId, groupId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof groupId === 'string', '"groupId" must be an integer - ' + groupId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_SUBSCRIBETOGROUPEVENTS }, 'subscribeToGroupEvents', reqId, groupId); return this; } }, { key: "updateDisplayGroup", value: function updateDisplayGroup( reqId, contractInfo) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)( typeof contractInfo === 'string', '"contractInfo" must be an string - ' + contractInfo); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_UPDATEDISPLAYGROUP }, 'updateDisplayGroup', reqId, contractInfo); return this; } }, { key: "unsubscribeFromGroupEvents", value: function unsubscribeFromGroupEvents( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_UNSUBSCRIBEFROMGROUPEVENTS }, 'unsubscribeToGroupEvents', reqId); return this; } }, { key: "reqMatchingSymbols", value: function reqMatchingSymbols( reqId, pattern) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof pattern === 'string', '"pattern" must be a string - ' + pattern); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMATCHINGSYMBOLS }, 'reqMatchingSymbols', reqId, pattern); } }, { key: "reqFamilyCodes", value: function reqFamilyCodes() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQFAMILYCODES }, 'reqFamilyCodes', reqId, pattern); } }, { key: "reqMktDepthExchanges", value: function reqMktDepthExchanges() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMKTDEPTHEXCHANGES }, 'reqMktDepthExchanges'); } }, { key: "reqSmartComponents", value: function reqSmartComponents( reqId, bboExchange) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)( typeof bboExchange === 'string', '"bboExchange" must be a string - ' + bboExchange); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQSMARTCOMPONENTS }, 'reqSmartComponents', reqId, bboExchange); } }, { key: "reqNewsProviders", value: function reqNewsProviders() { this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQNEWSPROVIDERS }, 'reqNewsProviders'); } }, { key: "reqNewsArticle", value: function reqNewsArticle( reqId, providerCode) {var articleId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;var newsArticleOptions = arguments.length > 3 ? arguments[3] : undefined; (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)( typeof providerCode === 'string', '"providerCode" must be a string - ' + providerCode); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQNEWSARTICLE }, 'reqNewsArticle', reqId, providerCode, articleId, newsArticleOptions); } }, { key: "reqHistoricalNews", value: function reqHistoricalNews( reqId, conId, providerCode, startDateTime, endDateTime, totalResults) {var historicalNewsOptions = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null; (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(Number.isInteger(conId), '"conId" must be an integer - ' + conId); (0, _validators.validateInput)( typeof providerCode === 'string', '"providerCode" must be a string - ' + providerCode); (0, _validators.validateInput)( typeof startDateTime === 'string', '"startDateTime" must be a string - ' + providerCode); (0, _validators.validateInput)( typeof endDateTime === 'string', '"endDateTime" must be a string - ' + providerCode); (0, _validators.validateInput)( Number.isInteger(totalResults), '"totalResults" must be an integer - ' + totalResults); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQHISTORICALNEWS }, 'reqHistoricalNews', reqId, conId, providerCode, startDateTime, endDateTime, totalResults, historicalNewsOptions); } }, { key: "reqHistogramData", value: function reqHistogramData( reqId, contract, useRTH, timePeriod) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof useRTH === 'boolean', '"useRTH" must be an boolean - ' + useRTH); (0, _validators.validateInput)(typeof timePeriod === 'string', '"timePeriod" must be a string - ' + timePeriod); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQHISTDATA }, 'reqHistogramData', reqId, contract, useRTH, timePeriod); } }, { key: "cancelHistogramData", value: function cancelHistogramData( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANHISTDATA }, 'cancelHistogramData', reqId); } }, { key: "reqMarketRule", value: function reqMarketRule( marketRuleId) { (0, _validators.validateInput)( Number.isInteger(marketRuleId), '"marketRuleId" must be an integer - ' + marketRuleId); this._sendMessage( { id: _errors.BROKER_ERRORS.NO_VALID_ID, error: _errors.BROKER_ERRORS.FAIL_SEND_REQMARKETRULE }, 'reqMarketRule', marketRuleId); } }, { key: "reqPnL", value: function reqPnL( reqId, account, modelCode) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof account === 'string', '"account" must be a string - ' + account); (0, _validators.validateInput)(typeof modelCode === 'string', '"modelCode" must be a string - ' + modelCode); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQPNL }, 'reqPnL', reqId, account, modelCode); } }, { key: "cancelPnL", value: function cancelPnL( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANPNL }, 'reqPnL', reqId); } }, { key: "reqPnLSingle", value: function reqPnLSingle( reqId, account, modelCode, conId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); (0, _validators.validateInput)(typeof account === 'string', '"account" must be a string - ' + account); (0, _validators.validateInput)(typeof modelCode === 'string', '"modelCode" must be a string - ' + modelCode); (0, _validators.validateInput)(Number.isInteger(conId), '"conId" must be an integer - ' + conId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQPNL_SINGLE }, 'reqPnLSingle', reqId, account, modelCode, conId); } }, { key: "cancelPnLSingle", value: function cancelPnLSingle( reqId) { (0, _validators.validateInput)(Number.isInteger(reqId), '"reqId" must be an integer - ' + reqId); this._sendMessage( { id: reqId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANPNL_SINGLE }, 'cancelPnLSingle', reqId); } }, { key: "reqHistoricalTicks", value: function reqHistoricalTicks( tickerId, contract, startDateTime, endDateTime, numberOfTicks, whatToShow, useRTH, ignoreSize, miscOptions) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)( !startDateTime && endDateTime || startDateTime && !endDateTime, 'specify one of "startDateTime" or "endDateTime" (as a string) but not both - ' + startDateTime + ':' + endDateTime); (0, _validators.validateInput)( Number.isInteger(numberOfTicks), '"numberOfTicks" must be a number - ' + numberOfTicks); (0, _validators.validateInput)(typeof whatToShow === 'string', '"whatToShow" must be a string - ' + whatToShow); (0, _validators.validateInput)(Number.isInteger(useRTH), '"useRTH" must be an integer - ' + useRTH); (0, _validators.validateInput)( typeof ignoreSize === 'boolean', '"ignoreSize" must be an boolean - ' + ignoreSize); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_HISTORICAL_TICK }, 'reqHistoricalTicks', tickerId, contract, startDateTime, endDateTime, numberOfTicks, whatToShow, useRTH, ignoreSize, miscOptions); return this; } }, { key: "reqTickByTickData", value: function reqTickByTickData( tickerId, contract, tickType, numberOfTicks, ignoreSize) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); (0, _validators.validateInput)(typeof tickType === 'string', '"tickType" must be a string - ' + tickType); (0, _validators.validateInput)( Number.isInteger(numberOfTicks), '"numberOfTicks" must be a number - ' + numberOfTicks); (0, _validators.validateInput)( typeof ignoreSize === 'boolean', '"ignoreSize" must be an boolean - ' + ignoreSize); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_REQTICKBYTICK }, 'reqTickByTickData', tickerId, contract, tickType, numberOfTicks, ignoreSize); return this; } }, { key: "cancelTickByTickData", value: function cancelTickByTickData( tickerId) { (0, _validators.validateInput)(Number.isInteger(tickerId), '"tickerId" must be an integer - ' + tickerId); this._sendMessage( { id: tickerId, error: _errors.BROKER_ERRORS.FAIL_SEND_CANTICKBYTICK }, 'cancelTickByTickData', tickerId); return this; } // -------- }, { key: "saveTick", value: function saveTick( ticker, tickType, value) { switch (tickType) { case 0: if (!ticker.size) ticker.size = {}; ticker['size']['bid'] = value; break; case 1: if (!ticker.price) ticker.price = {}; ticker['price']['bid'] = value; break; case 2: if (!ticker.price) ticker.price = {}; ticker['price']['ask'] = value; break; case 3: if (!ticker.size) ticker.size = {}; ticker['size']['ask'] = value; break; case 4: if (!ticker.price) ticker.price = {}; ticker['price']['last'] = value; break; case 5: if (!ticker.size) ticker.size = {}; ticker['size']['last'] = value; break; case 6: if (!ticker.price) ticker.price = {}; ticker['price']['high'] = value; break; case 7: if (!ticker.price) ticker.price = {}; ticker['price']['low'] = value; break; case 8: ticker['volume'] = value; break; case 9: if (!ticker.price) ticker.price = {}; ticker['price']['close'] = value; break; case 10: this._saveTickOption(ticker, 'bid', value); break; case 11: this._saveTickOption(ticker, 'ask', value); break; case 12: this._saveTickOption(ticker, 'last', value); break; case 13: this._saveTickOption(ticker, 'model', value); break; case 14: if (!ticker.price) ticker.price = {}; ticker['price']['open'] = value; break; // TODO 15-20 needs implementation case 21: ticker['avgVolume'] = value; break; case 22: ticker['openInterest'] = value; break; case 23: ticker['optionHV'] = value; break; case 24: ticker['optio