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