UNPKG

ib-client

Version:

Interactive Brokers API client library for Node.js

83 lines (79 loc) 4.27 kB
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _validators = require("./validators"); var _Combo = _interopRequireDefault(require("./contracts/Combo")); var _ComboLeg = _interopRequireDefault(require("./contracts/ComboLeg")); var _constants = require("./constants"); var _Stock = _interopRequireDefault(require("./contracts/Stock")); var _StockOption = _interopRequireDefault(require("./contracts/StockOption")); var _Futures = _interopRequireDefault(require("./contracts/Futures")); var _FuturesOption = _interopRequireDefault(require("./contracts/FuturesOption"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { "default": obj };}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;}var ContractBuilder = /*#__PURE__*/function () { function ContractBuilder() {var contract = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};_classCallCheck(this, ContractBuilder); this.conId = contract.conId || undefined; this.symbol = contract.symbol || undefined; this.secType = contract.secType || undefined; this.expiry = contract.expiry || undefined; this.strike = contract.strike || undefined; this.right = contract.right || undefined; this.multiplier = contract.multiplier || undefined; this.comboLegs = contract.comboLegs || []; this.exchange = contract.exchange || undefined; this.currency = contract.currency || undefined; }_createClass(ContractBuilder, [{ key: "setConId", value: function setConId( conId) { this.conId = conId; return this; } }, { key: "setSymbol", value: function setSymbol( symbol) { this.symbol = symbol; return this; } }, { key: "setSecType", value: function setSecType( secType) { this.secType = secType; return this; } }, { key: "setExpiry", value: function setExpiry( expiry) { this.expiry = expiry; return this; } }, { key: "setStrike", value: function setStrike( strike) { this.strike = strike; return this; } }, { key: "setRight", value: function setRight( right) { this.right = right; return this; } }, { key: "setMultiplier", value: function setMultiplier( multiplier) { this.multiplier = multiplier; return this; } }, { key: "addComboLeg", value: function addComboLeg( comboLeg) { (0, _validators.validateInput)(!comboLeg instanceof _ComboLeg["default"], 'comboLeg must be a ComboLeg instance.'); this.comboLegs = comboLeg; return this; } }, { key: "setExchange", value: function setExchange( exchange) { this.exchange = exchange; return this; } }, { key: "setCurrency", value: function setCurrency( currency) { this.currency = currency; return this; } }, { key: "build", value: function build() { switch (this.secType) { case _constants.SEC_TYPE.STOCK: return new _Stock["default"](this); case _constants.SEC_TYPE.STOCK_OPTION: return new _StockOption["default"](this); case _constants.SEC_TYPE.FUTURES: return new _Futures["default"](this); case _constants.SEC_TYPE.FUTURES_OPTION: return new _FuturesOption["default"](this); case _constants.SEC_TYPE.BAG: if (!Array.isArray(this.comboLegs) || this.comboLegs.length < 2) throw Error('Combo has no or just one leg.'); return new _Combo["default"](this); default: throw Error('Unknown security type.');} } }]);return ContractBuilder;}();exports["default"] = ContractBuilder;