ib-client
Version:
Interactive Brokers API client library for Node.js
37 lines (31 loc) • 2.05 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _validators = require("../validators");
var _constants = require("../constants");function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}var _default =
function _default(_ref) {var account = _ref.account,action = _ref.action,quantity = _ref.quantity,stopPrice = _ref.stopPrice,parentId = _ref.parentId,transmitOrder = _ref.transmitOrder,tif = _ref.tif,outsideRth = _ref.outsideRth;_classCallCheck(this, _default);
(0, _validators.validateInput)(typeof account === 'string' && account.length > 0, 'Account must be a string.');
(0, _validators.validateInput)([_constants.ACTION.BUY, _constants.ACTION.SELL].includes(action), 'Action must either be BUY or SELL.');
(0, _validators.validateInput)(typeof quantity === 'number', 'Quantity must be a number.');
(0, _validators.validateInput)(typeof stopPrice === 'number', 'Stop Price must be a number.');
if (parentId)
(0, _validators.validateInput)(
Number.isInteger(parentId) && parentId >= 0,
'ParentId must be a positive integer.');
if (transmitOrder)
(0, _validators.validateInput)(typeof transmitOrder === 'boolean', 'TransmitOrder must be a string.');
if (tif)
(0, _validators.validateInput)(
[_constants.TIME_IN_FORCE.DAY, _constants.TIME_IN_FORCE.GTC].includes(tif),
'Time in force must either be GTC or DAY.');
if (outsideRth)
(0, _validators.validateInput)(
typeof outsideRth === 'boolean',
'Outside Regular Trading Hours must be a string.');
this.account = account || undefined;
this.action = action || undefined;
this.totalQuantity = quantity || undefined;
this.orderType = _constants.ORDER_TYPE.STOP;
this.auxPrice = stopPrice || undefined;
this.parentId = parentId || 0;
this.transmit = transmitOrder || true;
this.tif = tif || _constants.TIME_IN_FORCE.GTC;
this.outsideRth = outsideRth || undefined;
};exports["default"] = _default;