ib-client
Version:
Interactive Brokers API client library for Node.js
74 lines (68 loc) • 3.6 kB
JavaScript
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _constants = require("./constants");
var _Market = _interopRequireDefault(require("./orders/Market"));
var _Limit = _interopRequireDefault(require("./orders/Limit"));
var _Stop = _interopRequireDefault(require("./orders/Stop"));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
OrderBuilder = /*#__PURE__*/function () {
function OrderBuilder() {var order = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};_classCallCheck(this, OrderBuilder);
this.account = order.account || undefined;
this.action = order.action || undefined;
this.quantity = order.quantity || undefined;
this.orderType = order.orderType || undefined;
this.limitPrice = order.limitPrice || undefined;
this.stopPrice = order.stopPrice || undefined;
this.parentId = order.parentId || undefined;
this.transmitOrder = order.transmitOrder || undefined;
this.tif = order.tif || undefined;
this.outsideRth = order.outsideRth || undefined;
}_createClass(OrderBuilder, [{ key: "setAccount", value: function setAccount(
account) {
this.account = account;
return this;
} }, { key: "setAction", value: function setAction(
action) {
this.action = action;
return this;
} }, { key: "setQuantity", value: function setQuantity(
quantity) {
this.quantity = quantity;
return this;
} }, { key: "setOrderType", value: function setOrderType(
orderType) {
this.orderType = orderType;
return this;
} }, { key: "setLimitPrice", value: function setLimitPrice(
limitPrice) {
this.limitPrice = limitPrice;
return this;
} }, { key: "setStopPrice", value: function setStopPrice(
stopPrice) {
this.stopPrice = stopPrice;
return this;
} }, { key: "setParentId", value: function setParentId(
parentId) {
this.parentId = parentId;
return this;
} }, { key: "setTransmitOrder", value: function setTransmitOrder(
transmitOrder) {
this.transmitOrder = transmitOrder;
return this;
} }, { key: "setTimeInForce", value: function setTimeInForce(
tif) {
this.tif = tif;
return this;
} }, { key: "setOutsideRth", value: function setOutsideRth(
outsideRth) {
this.outsideRth = outsideRth;
return this;
} }, { key: "build", value: function build()
{
switch (this.orderType) {
case _constants.ORDER_TYPE.MARKET:
return new _Market["default"](this);
case _constants.ORDER_TYPE.LIMIT:
return new _Limit["default"](this);
case _constants.ORDER_TYPE.STOP:
return new _Stop["default"](this);
default:
throw Error('Unknown order type.');}
} }]);return OrderBuilder;}();exports["default"] = OrderBuilder;