nodejs-order-book 10.0.1 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/order.js CHANGED
@@ -1,292 +1,249 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.OrderFactory = exports.StopLimitOrder = exports.StopMarketOrder = exports.LimitOrder = void 0;
19
4
  /* node:coverage ignore next - Don't know why first and last line of each file count as uncovered */
20
- var node_crypto_1 = require("node:crypto");
21
- var errors_1 = require("./errors");
22
- var types_1 = require("./types");
23
- var utils_1 = require("./utils");
24
- var BaseOrder = /** @class */ (function () {
25
- function BaseOrder(options) {
26
- var _a, _b;
27
- this._id = (_a = options.id) !== null && _a !== void 0 ? _a : (0, node_crypto_1.randomUUID)();
5
+ const node_crypto_1 = require("node:crypto");
6
+ const errors_1 = require("./errors");
7
+ const types_1 = require("./types");
8
+ const utils_1 = require("./utils");
9
+ class BaseOrder {
10
+ _id;
11
+ _side;
12
+ _size;
13
+ _time;
14
+ _accountId;
15
+ _stpMode;
16
+ constructor(options) {
17
+ this._id = options.id ?? (0, node_crypto_1.randomUUID)();
28
18
  this._side = options.side;
29
19
  this._size = options.size;
30
- this._time = (_b = options.time) !== null && _b !== void 0 ? _b : Date.now();
20
+ this._time = options.time ?? Date.now();
21
+ this._accountId = options.accountId ?? "";
22
+ this._stpMode = options.stpMode ?? types_1.SelfTradePreventionMode.NONE;
31
23
  }
32
- Object.defineProperty(BaseOrder.prototype, "id", {
33
- // Getter for order ID
34
- get: function () {
35
- return this._id;
36
- },
37
- enumerable: false,
38
- configurable: true
39
- });
40
- Object.defineProperty(BaseOrder.prototype, "side", {
41
- // Getter for order side
42
- get: function () {
43
- return this._side;
44
- },
45
- enumerable: false,
46
- configurable: true
47
- });
48
- Object.defineProperty(BaseOrder.prototype, "size", {
49
- // Getter for order size
50
- get: function () {
51
- return this._size;
52
- },
53
- // Setter for order size
54
- set: function (size) {
55
- this._size = size;
56
- },
57
- enumerable: false,
58
- configurable: true
59
- });
60
- Object.defineProperty(BaseOrder.prototype, "time", {
61
- // Getter for order timestamp
62
- get: function () {
63
- return this._time;
64
- },
65
- // Setter for order timestamp
66
- set: function (time) {
67
- this._time = time;
68
- },
69
- enumerable: false,
70
- configurable: true
71
- });
72
- return BaseOrder;
73
- }());
74
- var LimitOrder = /** @class */ (function (_super) {
75
- __extends(LimitOrder, _super);
76
- function LimitOrder(options) {
77
- var _a;
78
- var _this = _super.call(this, options) || this;
79
- _this.toString = function () {
80
- return "".concat(_this._id, ":\n type: ").concat(_this.type, "\n side: ").concat(_this._side, "\n size: ").concat(_this._size, "\n origSize: ").concat(_this._origSize, "\n price: ").concat(_this._price, "\n time: ").concat(_this._time, "\n timeInForce: ").concat(_this._timeInForce, "\n makerQty: ").concat(_this._makerQty, "\n takerQty: ").concat(_this._takerQty);
81
- };
82
- _this.toJSON = function () { return (0, utils_1.safeStringify)(_this.toObject()); };
83
- _this.toObject = function () { return ({
84
- id: _this._id,
85
- type: _this.type,
86
- side: _this._side,
87
- size: _this._size,
88
- origSize: _this._origSize,
89
- price: _this._price,
90
- time: _this._time,
91
- timeInForce: _this._timeInForce,
92
- makerQty: _this._makerQty,
93
- takerQty: _this._takerQty,
94
- }); };
95
- _this._type = options.type;
96
- _this._origSize = options.origSize;
97
- _this._price = options.price;
98
- _this._timeInForce = options.timeInForce;
99
- _this._makerQty = options.makerQty;
100
- _this._takerQty = options.takerQty;
101
- _this._postOnly = (_a = options.postOnly) !== null && _a !== void 0 ? _a : false;
102
- _this._ocoStopPrice = options.ocoStopPrice;
103
- return _this;
24
+ // Getter for order ID
25
+ get id() {
26
+ return this._id;
104
27
  }
105
- Object.defineProperty(LimitOrder.prototype, "type", {
106
- // Getter for order type
107
- get: function () {
108
- return this._type;
109
- },
110
- enumerable: false,
111
- configurable: true
112
- });
113
- Object.defineProperty(LimitOrder.prototype, "price", {
114
- // Getter for order price
115
- get: function () {
116
- return this._price;
117
- },
118
- // Getter for order price
119
- set: function (price) {
120
- this._price = price;
121
- },
122
- enumerable: false,
123
- configurable: true
124
- });
125
- Object.defineProperty(LimitOrder.prototype, "timeInForce", {
126
- // Getter for timeInForce price
127
- get: function () {
128
- return this._timeInForce;
129
- },
130
- enumerable: false,
131
- configurable: true
132
- });
133
- Object.defineProperty(LimitOrder.prototype, "postOnly", {
134
- // Getter for order postOnly
135
- get: function () {
136
- return this._postOnly;
137
- },
138
- enumerable: false,
139
- configurable: true
140
- });
141
- Object.defineProperty(LimitOrder.prototype, "origSize", {
142
- // Getter for the original size of the order
143
- get: function () {
144
- return this._origSize;
145
- },
146
- enumerable: false,
147
- configurable: true
148
- });
149
- Object.defineProperty(LimitOrder.prototype, "makerQty", {
150
- // Getter for order makerQty
151
- get: function () {
152
- return this._makerQty;
153
- },
154
- enumerable: false,
155
- configurable: true
156
- });
157
- Object.defineProperty(LimitOrder.prototype, "takerQty", {
158
- // Getter for order takerQty
159
- get: function () {
160
- return this._takerQty;
161
- },
162
- enumerable: false,
163
- configurable: true
164
- });
165
- Object.defineProperty(LimitOrder.prototype, "ocoStopPrice", {
166
- get: function () {
167
- return this._ocoStopPrice;
168
- },
169
- enumerable: false,
170
- configurable: true
28
+ // Getter for order side
29
+ get side() {
30
+ return this._side;
31
+ }
32
+ // Getter for order size
33
+ get size() {
34
+ return this._size;
35
+ }
36
+ // Setter for order size
37
+ set size(size) {
38
+ this._size = size;
39
+ }
40
+ // Getter for order timestamp
41
+ get time() {
42
+ return this._time;
43
+ }
44
+ // Setter for order timestamp
45
+ set time(time) {
46
+ this._time = time;
47
+ }
48
+ // Getter for account ID (self-trade prevention)
49
+ get accountId() {
50
+ return this._accountId;
51
+ }
52
+ // Getter for self-trade prevention mode
53
+ get stpMode() {
54
+ return this._stpMode;
55
+ }
56
+ }
57
+ class LimitOrder extends BaseOrder {
58
+ _type;
59
+ _origSize;
60
+ _price;
61
+ _timeInForce;
62
+ _makerQty;
63
+ _takerQty;
64
+ _postOnly;
65
+ // Refers to the linked Stop Limit order stopPrice
66
+ _ocoStopPrice;
67
+ constructor(options) {
68
+ super(options);
69
+ this._type = options.type;
70
+ this._origSize = options.origSize;
71
+ this._price = options.price;
72
+ this._timeInForce = options.timeInForce;
73
+ this._makerQty = options.makerQty;
74
+ this._takerQty = options.takerQty;
75
+ this._postOnly = options.postOnly ?? false;
76
+ this._ocoStopPrice = options.ocoStopPrice;
77
+ }
78
+ // Getter for order type
79
+ get type() {
80
+ return this._type;
81
+ }
82
+ // Getter for order price
83
+ get price() {
84
+ return this._price;
85
+ }
86
+ // Getter for order price
87
+ set price(price) {
88
+ this._price = price;
89
+ }
90
+ // Getter for timeInForce price
91
+ get timeInForce() {
92
+ return this._timeInForce;
93
+ }
94
+ // Getter for order postOnly
95
+ get postOnly() {
96
+ return this._postOnly;
97
+ }
98
+ // Getter for the original size of the order
99
+ get origSize() {
100
+ return this._origSize;
101
+ }
102
+ // Getter for order makerQty
103
+ get makerQty() {
104
+ return this._makerQty;
105
+ }
106
+ // Getter for order takerQty
107
+ get takerQty() {
108
+ return this._takerQty;
109
+ }
110
+ get ocoStopPrice() {
111
+ return this._ocoStopPrice;
112
+ }
113
+ toString = () => `${this._id}:
114
+ type: ${this.type}
115
+ side: ${this._side}
116
+ size: ${this._size}
117
+ origSize: ${this._origSize}
118
+ price: ${this._price}
119
+ time: ${this._time}
120
+ timeInForce: ${this._timeInForce}
121
+ makerQty: ${this._makerQty}
122
+ takerQty: ${this._takerQty}`;
123
+ toJSON = () => (0, utils_1.safeStringify)(this.toObject());
124
+ toObject = () => ({
125
+ id: this._id,
126
+ type: this.type,
127
+ side: this._side,
128
+ size: this._size,
129
+ origSize: this._origSize,
130
+ price: this._price,
131
+ time: this._time,
132
+ timeInForce: this._timeInForce,
133
+ makerQty: this._makerQty,
134
+ takerQty: this._takerQty,
135
+ ...(this._accountId ? { accountId: this._accountId } : {}),
136
+ ...(this._stpMode !== types_1.SelfTradePreventionMode.NONE
137
+ ? { stpMode: this._stpMode }
138
+ : {}),
171
139
  });
172
- return LimitOrder;
173
- }(BaseOrder));
140
+ }
174
141
  exports.LimitOrder = LimitOrder;
175
- var StopMarketOrder = /** @class */ (function (_super) {
176
- __extends(StopMarketOrder, _super);
177
- function StopMarketOrder(options) {
178
- var _this = _super.call(this, options) || this;
179
- _this.toString = function () {
180
- return "".concat(_this._id, ":\n type: ").concat(_this.type, "\n side: ").concat(_this._side, "\n size: ").concat(_this._size, "\n stopPrice: ").concat(_this._stopPrice, "\n time: ").concat(_this._time);
181
- };
182
- _this.toJSON = function () { return (0, utils_1.safeStringify)(_this.toObject()); };
183
- _this.toObject = function () { return ({
184
- id: _this._id,
185
- type: _this.type,
186
- side: _this._side,
187
- size: _this._size,
188
- stopPrice: _this._stopPrice,
189
- time: _this._time,
190
- }); };
191
- _this._type = options.type;
192
- _this._stopPrice = options.stopPrice;
193
- return _this;
142
+ class StopMarketOrder extends BaseOrder {
143
+ _type;
144
+ _stopPrice;
145
+ constructor(options) {
146
+ super(options);
147
+ this._type = options.type;
148
+ this._stopPrice = options.stopPrice;
194
149
  }
195
- Object.defineProperty(StopMarketOrder.prototype, "type", {
196
- // Getter for order type
197
- get: function () {
198
- return this._type;
199
- },
200
- enumerable: false,
201
- configurable: true
202
- });
203
- Object.defineProperty(StopMarketOrder.prototype, "stopPrice", {
204
- // Getter for order stopPrice
205
- get: function () {
206
- return this._stopPrice;
207
- },
208
- enumerable: false,
209
- configurable: true
150
+ // Getter for order type
151
+ get type() {
152
+ return this._type;
153
+ }
154
+ // Getter for order stopPrice
155
+ get stopPrice() {
156
+ return this._stopPrice;
157
+ }
158
+ toString = () => `${this._id}:
159
+ type: ${this.type}
160
+ side: ${this._side}
161
+ size: ${this._size}
162
+ stopPrice: ${this._stopPrice}
163
+ time: ${this._time}`;
164
+ toJSON = () => (0, utils_1.safeStringify)(this.toObject());
165
+ toObject = () => ({
166
+ id: this._id,
167
+ type: this.type,
168
+ side: this._side,
169
+ size: this._size,
170
+ stopPrice: this._stopPrice,
171
+ time: this._time,
172
+ ...(this._accountId ? { accountId: this._accountId } : {}),
173
+ ...(this._stpMode !== types_1.SelfTradePreventionMode.NONE
174
+ ? { stpMode: this._stpMode }
175
+ : {}),
210
176
  });
211
- return StopMarketOrder;
212
- }(BaseOrder));
177
+ }
213
178
  exports.StopMarketOrder = StopMarketOrder;
214
- var StopLimitOrder = /** @class */ (function (_super) {
215
- __extends(StopLimitOrder, _super);
216
- function StopLimitOrder(options) {
217
- var _a;
218
- var _this = _super.call(this, options) || this;
219
- _this.toString = function () {
220
- return "".concat(_this._id, ":\n type: ").concat(_this.type, "\n side: ").concat(_this._side, "\n size: ").concat(_this._size, "\n price: ").concat(_this._price, "\n stopPrice: ").concat(_this._stopPrice, "\n\tisOCO: ").concat(_this.isOCO, "\n timeInForce: ").concat(_this._timeInForce, "\n time: ").concat(_this._time);
221
- };
222
- _this.toJSON = function () { return (0, utils_1.safeStringify)(_this.toObject()); };
223
- _this.toObject = function () { return ({
224
- id: _this._id,
225
- type: _this.type,
226
- side: _this._side,
227
- size: _this._size,
228
- price: _this._price,
229
- stopPrice: _this._stopPrice,
230
- isOCO: _this.isOCO,
231
- timeInForce: _this._timeInForce,
232
- time: _this._time,
233
- }); };
234
- _this._type = options.type;
235
- _this._price = options.price;
236
- _this._stopPrice = options.stopPrice;
237
- _this._timeInForce = options.timeInForce;
238
- _this._isOCO = (_a = options.isOCO) !== null && _a !== void 0 ? _a : false;
239
- return _this;
179
+ class StopLimitOrder extends BaseOrder {
180
+ _type;
181
+ _price;
182
+ _stopPrice;
183
+ _timeInForce;
184
+ // It's true when there is a linked Limit Order
185
+ _isOCO;
186
+ constructor(options) {
187
+ super(options);
188
+ this._type = options.type;
189
+ this._price = options.price;
190
+ this._stopPrice = options.stopPrice;
191
+ this._timeInForce = options.timeInForce;
192
+ this._isOCO = options.isOCO ?? false;
240
193
  }
241
- Object.defineProperty(StopLimitOrder.prototype, "type", {
242
- // Getter for order type
243
- get: function () {
244
- return this._type;
245
- },
246
- enumerable: false,
247
- configurable: true
248
- });
249
- Object.defineProperty(StopLimitOrder.prototype, "price", {
250
- // Getter for order price
251
- get: function () {
252
- return this._price;
253
- },
254
- // Getter for order price
255
- set: function (price) {
256
- this._price = price;
257
- },
258
- enumerable: false,
259
- configurable: true
260
- });
261
- Object.defineProperty(StopLimitOrder.prototype, "stopPrice", {
262
- // Getter for order stopPrice
263
- get: function () {
264
- return this._stopPrice;
265
- },
266
- enumerable: false,
267
- configurable: true
268
- });
269
- Object.defineProperty(StopLimitOrder.prototype, "timeInForce", {
270
- // Getter for timeInForce price
271
- get: function () {
272
- return this._timeInForce;
273
- },
274
- enumerable: false,
275
- configurable: true
276
- });
277
- Object.defineProperty(StopLimitOrder.prototype, "isOCO", {
278
- // Getter for order isOCO
279
- get: function () {
280
- return this._isOCO;
281
- },
282
- enumerable: false,
283
- configurable: true
194
+ // Getter for order type
195
+ get type() {
196
+ return this._type;
197
+ }
198
+ // Getter for order price
199
+ get price() {
200
+ return this._price;
201
+ }
202
+ // Getter for order price
203
+ set price(price) {
204
+ this._price = price;
205
+ }
206
+ // Getter for order stopPrice
207
+ get stopPrice() {
208
+ return this._stopPrice;
209
+ }
210
+ // Getter for timeInForce price
211
+ get timeInForce() {
212
+ return this._timeInForce;
213
+ }
214
+ // Getter for order isOCO
215
+ get isOCO() {
216
+ return this._isOCO;
217
+ }
218
+ toString = () => `${this._id}:
219
+ type: ${this.type}
220
+ side: ${this._side}
221
+ size: ${this._size}
222
+ price: ${this._price}
223
+ stopPrice: ${this._stopPrice}
224
+ isOCO: ${this.isOCO}
225
+ timeInForce: ${this._timeInForce}
226
+ time: ${this._time}`;
227
+ toJSON = () => (0, utils_1.safeStringify)(this.toObject());
228
+ toObject = () => ({
229
+ id: this._id,
230
+ type: this.type,
231
+ side: this._side,
232
+ size: this._size,
233
+ price: this._price,
234
+ stopPrice: this._stopPrice,
235
+ isOCO: this.isOCO,
236
+ timeInForce: this._timeInForce,
237
+ time: this._time,
238
+ ...(this._accountId ? { accountId: this._accountId } : {}),
239
+ ...(this._stpMode !== types_1.SelfTradePreventionMode.NONE
240
+ ? { stpMode: this._stpMode }
241
+ : {}),
284
242
  });
285
- return StopLimitOrder;
286
- }(BaseOrder));
243
+ }
287
244
  exports.StopLimitOrder = StopLimitOrder;
288
245
  exports.OrderFactory = {
289
- createOrder: function (options) {
246
+ createOrder(options) {
290
247
  switch (options.type) {
291
248
  case types_1.OrderType.LIMIT:
292
249
  // biome-ignore lint: don't know how to typing this return