ib-client
Version:
Interactive Brokers API client library for Node.js
155 lines (132 loc) • 12.6 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.InputTypeError = exports.UnderrunError = exports.BrokerError = exports.BROKER_ERRORS = void 0;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 _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}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 _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 _wrapNativeSuper(Class) {var _cache = typeof Map === "function" ? new Map() : undefined;_wrapNativeSuper = function _wrapNativeSuper(Class) {if (Class === null || !_isNativeFunction(Class)) return Class;if (typeof Class !== "function") {throw new TypeError("Super expression must either be null or a function");}if (typeof _cache !== "undefined") {if (_cache.has(Class)) return _cache.get(Class);_cache.set(Class, Wrapper);}function Wrapper() {return _construct(Class, arguments, _getPrototypeOf(this).constructor);}Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } });return _setPrototypeOf(Wrapper, Class);};return _wrapNativeSuper(Class);}function _construct(Parent, args, Class) {if (_isNativeReflectConstruct()) {_construct = Reflect.construct;} else {_construct = function _construct(Parent, args, Class) {var a = [null];a.push.apply(a, args);var Constructor = Function.bind.apply(Parent, a);var instance = new Constructor();if (Class) _setPrototypeOf(instance, Class.prototype);return instance;};}return _construct.apply(null, arguments);}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 _isNativeFunction(fn) {return Function.toString.call(fn).indexOf("[native code]") !== -1;}function _setPrototypeOf(o, p) {_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {o.__proto__ = p;return o;};return _setPrototypeOf(o, p);}function _getPrototypeOf(o) {_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {return o.__proto__ || Object.getPrototypeOf(o);};return _getPrototypeOf(o);}var BROKER_ERRORS = {
NO_VALID_ID: -1,
ALREADY_CONNECTED: { code: 501, message: 'Already connected.' },
CONNECT_FAIL: {
code: 502,
message:
'Couldn\'t connect to TWS. Confirm that "Enable ActiveX and Socket Clients" ' +
'is enabled and connection port is the same as "Socket Port" on the TWS "Edit->Global Configuration...->API->Settings" menu. ' +
'Live Trading ports: TWS: 7496; IB Gasteway: 4001. Simulated Trading ports for new installations of version 954.1 or newer: ' +
'TWS: 7497; IB Gateway: 4002' },
UPDATE_TWS: { code: 503, message: 'The TWS is out of date and must be upgraded.' },
NOT_CONNECTED: { code: 504, message: 'Not connected' },
UNKNOWN_ID: { code: 505, message: 'Fatal Error: Unknown message id.' },
UNSUPPORTED_VERSION: { code: 506, message: 'Unsupported Version' },
BAD_LENGTH: { code: 507, message: 'Bad Message Length' },
BAD_MESSAGE: { code: 508, message: 'Bad Message' },
FAIL_SEND: { code: 509, message: 'Failed to send message - ' }, // generic message; all future messages should use this
FAIL_SEND_REQMKT: { code: 510, message: 'Request Market Data Sending Error - ' },
FAIL_SEND_CANMKT: { code: 511, message: 'Cancel Market Data Sending Error - ' },
FAIL_SEND_ORDER: { code: 512, message: 'Order Sending Error - ' },
FAIL_SEND_ACCT: { code: 513, message: 'Account Update Request Sending Error -' },
FAIL_SEND_EXEC: { code: 514, message: 'Request For Executions Sending Error -' },
FAIL_SEND_CORDER: { code: 515, message: 'Cancel Order Sending Error -' },
FAIL_SEND_OORDER: { code: 516, message: 'Request Open Order Sending Error -' },
UNKNOWN_CONTRACT: {
code: 517,
message: 'Unknown contract. Verify the contract details supplied.' },
FAIL_SEND_REQCONTRACT: { code: 518, message: 'Request Contract Data Sending Error - ' },
FAIL_SEND_REQMKTDEPTH: { code: 519, message: 'Request Market Depth Sending Error - ' },
FAIL_SEND_CANMKTDEPTH: { code: 520, message: 'Cancel Market Depth Sending Error - ' },
FAIL_SEND_SERVER_LOG_LEVEL: { code: 521, message: 'Set Server Log Level Sending Error - ' },
FAIL_SEND_FA_REQUEST: { code: 522, message: 'FA Information Request Sending Error - ' },
FAIL_SEND_FA_REPLACE: { code: 523, message: 'FA Information Replace Sending Error - ' },
FAIL_SEND_REQSCANNER: { code: 524, message: 'Request Scanner Subscription Sending Error - ' },
FAIL_SEND_CANSCANNER: { code: 525, message: 'Cancel Scanner Subscription Sending Error - ' },
FAIL_SEND_REQSCANNERPARAMETERS: {
code: 526,
message: 'Request Scanner Parameter Sending Error - ' },
FAIL_SEND_REQHISTDATA: { code: 527, message: 'Request Historical Data Sending Error - ' },
FAIL_SEND_CANHISTDATA: { code: 528, message: 'Request Historical Data Sending Error - ' },
FAIL_SEND_REQRTBARS: { code: 529, message: 'Request Real-time Bar Data Sending Error - ' },
FAIL_SEND_CANRTBARS: { code: 530, message: 'Cancel Real-time Bar Data Sending Error - ' },
FAIL_SEND_REQCURRTIME: { code: 531, message: 'Request Current Time Sending Error - ' },
FAIL_SEND_REQFUNDDATA: { code: 532, message: 'Request Fundamental Data Sending Error - ' },
FAIL_SEND_CANFUNDDATA: { code: 533, message: 'Cancel Fundamental Data Sending Error - ' },
FAIL_SEND_REQCALCIMPLIEDVOLAT: {
code: 534,
message: 'Request Calculate Implied Volatility Sending Error - ' },
FAIL_SEND_REQCALCOPTIONPRICE: {
code: 535,
message: 'Request Calculate Option Price Sending Error - ' },
FAIL_SEND_CANCALCIMPLIEDVOLAT: {
code: 536,
message: 'Cancel Calculate Implied Volatility Sending Error - ' },
FAIL_SEND_CANCALCOPTIONPRICE: {
code: 537,
message: 'Cancel Calculate Option Price Sending Error - ' },
FAIL_SEND_REQGLOBALCANCEL: { code: 538, message: 'Request Global Cancel Sending Error - ' },
FAIL_SEND_REQMARKETDATATYPE: { code: 539, message: 'Request Market Data Type Sending Error - ' },
FAIL_SEND_REQPOSITIONS: { code: 540, message: 'Request Positions Sending Error - ' },
FAIL_SEND_CANPOSITIONS: { code: 541, message: 'Cancel Positions Sending Error - ' },
FAIL_SEND_REQACCOUNTDATA: { code: 542, message: 'Request Account Data Sending Error - ' },
FAIL_SEND_CANACCOUNTDATA: { code: 543, message: 'Cancel Account Data Sending Error - ' },
FAIL_SEND_VERIFYREQUEST: { code: 544, message: 'Verify Request Sending Error - ' },
FAIL_SEND_VERIFYMESSAGE: { code: 545, message: 'Verify Message Sending Error - ' },
FAIL_SEND_QUERYDISPLAYGROUPS: { code: 546, message: 'Query Display Groups Sending Error - ' },
FAIL_SEND_SUBSCRIBETOGROUPEVENTS: {
code: 547,
message: 'Subscribe To Group Events Sending Error - ' },
FAIL_SEND_UPDATEDISPLAYGROUP: { code: 548, message: 'Update Display Group Sending Error - ' },
FAIL_SEND_UNSUBSCRIBEFROMGROUPEVENTS: {
code: 549,
message: 'Unsubscribe From Group Events Sending Error - ' },
FAIL_SEND_STARTAPI: { code: 550, message: 'Start API Sending Error - ' },
FAIL_SEND_VERIFYANDAUTHREQUEST: {
code: 551,
message: 'Verify And Auth Request Sending Error - ' },
FAIL_SEND_VERIFYANDAUTHMESSAGE: {
code: 552,
message: 'Verify And Auth Message Sending Error - ' },
FAIL_SEND_REQPOSITIONSMULTI: { code: 553, message: 'Request Positions Multi Sending Error - ' },
FAIL_SEND_CANPOSITIONSMULTI: { code: 554, message: 'Cancel Positions Multi Sending Error - ' },
FAIL_SEND_REQACCOUNTUPDATESMULTI: {
code: 555,
message: 'Request Account Updates Multi Sending Error - ' },
FAIL_SEND_CANACCOUNTUPDATESMULTI: {
code: 556,
message: 'Cancel Account Updates Multi Sending Error - ' },
FAIL_SEND_REQSECDEFOPTPARAMS: {
code: 557,
message: 'Request Security Definition Option Params Sending Error - ' },
FAIL_SEND_REQSOFTDOLLARTIERS: {
code: 558,
message: 'Request Soft Dollar Tiers Sending Error - ' },
FAIL_SEND_REQFAMILYCODES: { code: 559, message: 'Request Family Codes Sending Error - ' },
FAIL_SEND_REQMATCHINGSYMBOLS: { code: 560, message: 'Request Matching Symbols Sending Error - ' },
FAIL_SEND_REQMKTDEPTHEXCHANGES: {
code: 561,
message: 'Request Market Depth Exchanges Sending Error - ' },
FAIL_SEND_REQSMARTCOMPONENTS: { code: 562, message: 'Request Smart Components Sending Error - ' },
FAIL_SEND_REQNEWSPROVIDERS: { code: 563, message: 'Request News Providers Sending Error - ' },
FAIL_SEND_REQNEWSARTICLE: { code: 564, message: 'Request News Article Sending Error - ' },
FAIL_SEND_REQHISTORICALNEWS: { code: 565, message: 'Request Historical News Sending Error - ' },
FAIL_SEND_REQHEADTIMESTAMP: { code: 566, message: 'Request Head Time Stamp Sending Error - ' },
FAIL_SEND_CANHEADTIMESTAMP: { code: 567, message: 'Cancel Head Time Stamp Sending Error - ' },
FAIL_SEND_REQMARKETRULE: { code: 568, message: 'Request Market Rule Sending Error - ' },
FAIL_SEND_REQPNL: { code: 566, message: 'Request PnL Sending Error - ' },
FAIL_SEND_CANPNL: { code: 567, message: 'Cancel PnL Sending Error - ' },
FAIL_SEND_REQPNL_SINGLE: { code: 568, message: 'Request PnL Single Sending Error - ' },
FAIL_SEND_CANPNL_SINGLE: { code: 569, message: 'Cancel PnL Single Sending Error - ' },
FAIL_SEND_HISTORICAL_TICK: { code: 569, message: 'Request Historical Ticks Sending Error - ' },
FAIL_SEND_REQTICKBYTICK: { code: 570, message: 'Request Tick-By-Tick Sending Error - ' },
FAIL_SEND_CANTICKBYTICK: { code: 571, message: 'Cancel Tick-By-Tick Sending Error - ' } };exports.BROKER_ERRORS = BROKER_ERRORS;var
BrokerError = /*#__PURE__*/function (_Error) {_inherits(BrokerError, _Error);var _super = _createSuper(BrokerError);
function BrokerError(error) {var _this;_classCallCheck(this, BrokerError);
_this = _super.call(this, error.message);
_this.code = error.code || null;
_this.id = error.id || -1;return _this;
}return BrokerError;}( /*#__PURE__*/_wrapNativeSuper(Error));exports.BrokerError = BrokerError;var
UnderrunError = /*#__PURE__*/function (_Error2) {_inherits(UnderrunError, _Error2);var _super2 = _createSuper(UnderrunError);
function UnderrunError(message) {var _this2;_classCallCheck(this, UnderrunError);
_this2 = _super2.call(this);
_this2.name = 'UnderrunError';
_this2.message = message || 'An underrun error has occurred';
_this2.stack = new Error().stack;return _this2;
}return UnderrunError;}( /*#__PURE__*/_wrapNativeSuper(Error));exports.UnderrunError = UnderrunError;var
InputTypeError = /*#__PURE__*/function (_TypeError) {_inherits(InputTypeError, _TypeError);var _super3 = _createSuper(InputTypeError);
function InputTypeError(message) {var _this3;_classCallCheck(this, InputTypeError);
_this3 = _super3.call(this);
_this3.name = 'InputTypeError';
_this3.message = message || ' Invalid input type';return _this3;
}return InputTypeError;}( /*#__PURE__*/_wrapNativeSuper(TypeError));exports.InputTypeError = InputTypeError;