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