nodejs-order-book 8.0.0

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