nodejs-order-book 9.1.1 → 10.0.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/README.md CHANGED
@@ -19,7 +19,7 @@ Ultra-fast Node.js Order Book written in TypeScript </br> for high-frequency tra
19
19
  - [Features](#features)
20
20
  - [Installation](#installation)
21
21
  - [Usage](#usage)
22
- - [Experimental Conditional Orders](#conditional-orders-)
22
+ - [Conditional Orders](#conditional-orders)
23
23
  - [About Primary Functions](#about-primary-functions)
24
24
  - [Create order `createOrder()`](#create-order)
25
25
  - [Create Limit order `limit()`](#create-limit-order)
@@ -48,7 +48,7 @@ Ultra-fast Node.js Order Book written in TypeScript </br> for high-frequency tra
48
48
  - Standard price-time priority
49
49
  - Supports both market and limit orders
50
50
  - Supports `post-only` limit order <img src="https://img.shields.io/badge/New-green" alt="New">
51
- - Supports conditional orders [**Stop Limit, Stop Market and OCO**](#conditional-orders-) <img src="https://img.shields.io/badge/New-green" alt="New"> <img src="https://img.shields.io/badge/Experimental-blue" alt="Experimental">
51
+ - Supports conditional orders [**Stop Limit, Stop Market and OCO**](#conditional-orders) <img src="https://img.shields.io/badge/New-green" alt="New">
52
52
  - Supports time in force GTC, FOK and IOC <img src="https://img.shields.io/badge/New-green" alt="New">
53
53
  - Supports order cancelling
54
54
  - Supports order price and/or size updating <img src="https://img.shields.io/badge/New-green" alt="New">
@@ -63,19 +63,19 @@ Ultra-fast Node.js Order Book written in TypeScript </br> for high-frequency tra
63
63
 
64
64
  Install with npm:
65
65
 
66
- ```sh
66
+ ```
67
67
  npm install nodejs-order-book
68
68
  ```
69
69
 
70
70
  Install with yarn:
71
71
 
72
- ```sh
72
+ ```
73
73
  yarn add nodejs-order-book
74
74
  ```
75
75
 
76
76
  Install with pnpm:
77
77
 
78
- ```sh
78
+ ```
79
79
  pnpm add nodejs-order-book
80
80
  ```
81
81
 
@@ -83,7 +83,7 @@ pnpm add nodejs-order-book
83
83
 
84
84
  To start using order book you need to import `OrderBook` and create new instance:
85
85
 
86
- ```js
86
+ ```ts
87
87
  import { OrderBook } from 'nodejs-order-book'
88
88
 
89
89
  const ob = new OrderBook()
@@ -91,31 +91,79 @@ const ob = new OrderBook()
91
91
 
92
92
  Then you'll be able to use next primary functions:
93
93
 
94
- ```js
95
- ob.createOrder({ type: 'limit' | 'market', side: 'buy' | 'sell', size: number, price?: number, id?: string, postOnly?: boolean, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
96
-
97
- ob.limit({ id: string, side: 'buy' | 'sell', size: number, price: number, postOnly?: boolean, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
94
+ ```ts
95
+ ob.createOrder({
96
+ type: 'limit' | 'market',
97
+ side: 'buy' | 'sell',
98
+ size: number,
99
+ price?: number,
100
+ id?: string,
101
+ postOnly?: boolean,
102
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
103
+ })
104
+
105
+ ob.limit({
106
+ id: string,
107
+ side: 'buy' | 'sell',
108
+ size: number,
109
+ price: number,
110
+ postOnly?: boolean,
111
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
112
+ })
98
113
 
99
114
  ob.market({ side: 'buy' | 'sell', size: number })
100
115
 
101
- ob.modify(orderID: string, { side: 'buy' | 'sell', size: number, price: number })
116
+ ob.modify(orderID: string, {
117
+ side: 'buy' | 'sell',
118
+ size: number,
119
+ price: number
120
+ })
102
121
 
103
122
  ob.cancel(orderID: string)
104
123
  ```
105
- ### Conditional Orders ![Experimental](https://img.shields.io/badge/Experimental-blue)
106
- The version `v6.1.0` introduced support for Conditional Orders `Stop Market`, `Stop Limit` and `OCO`. Even though the test coverage for these new features is at 100%, they are not yet considered stable because they have not been tested with real-world scenarios. For this reason, if you want to use conditional orders, you need to instantiate the order book with the `experimentalConditionalOrders` option set to `true`.
107
- ```js
124
+ ### Conditional Orders
125
+ Currently `Stop Market`, `Stop Limit` and `OCO` orders are supported.
126
+ ```ts
108
127
  import { OrderBook } from 'nodejs-order-book'
109
128
 
110
- const ob = new OrderBook({ experimentalConditionalOrders: true })
111
-
112
- ob.createOrder({ type: 'stop_limit' | 'stop_market' | 'oco', side: 'buy' | 'sell', size: number, price?: number, id?: string, stopPrice?: number, timeInForce?: 'GTC' | 'FOK' | 'IOC', stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC' })
113
-
114
- ob.stopLimit({ id: string, side: 'buy' | 'sell', size: number, price: number, stopPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
115
-
116
- ob.stopMarket({ side: 'buy' | 'sell', size: number, stopPrice: number })
129
+ const ob = new OrderBook()
117
130
 
118
- ob.oco({ id: string, side: 'buy' | 'sell', size: number, price: number, stopPrice: number, stopLimitPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC', stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC' })
131
+ ob.createOrder({
132
+ type: 'stop_limit' | 'stop_market' | 'oco',
133
+ side: 'buy' | 'sell',
134
+ size: number,
135
+ price?: number,
136
+ id?: string,
137
+ stopPrice?: number,
138
+ timeInForce?: 'GTC' | 'FOK' | 'IOC',
139
+ stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC'
140
+ })
141
+
142
+ ob.stopLimit({
143
+ id: string,
144
+ side: 'buy' | 'sell',
145
+ size: number,
146
+ price: number,
147
+ stopPrice: number,
148
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
149
+ })
150
+
151
+ ob.stopMarket({
152
+ side: 'buy' | 'sell',
153
+ size: number,
154
+ stopPrice: number
155
+ })
156
+
157
+ ob.oco({
158
+ id: string,
159
+ side: 'buy' | 'sell',
160
+ size: number,
161
+ price: number,
162
+ stopPrice: number,
163
+ stopLimitPrice: number,
164
+ timeInForce?: 'GTC' | 'FOK' | 'IOC',
165
+ stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC'
166
+ })
119
167
  ```
120
168
 
121
169
  ## About primary functions
@@ -124,26 +172,59 @@ To add an order to the order book you can call the general `createOrder()` funct
124
172
 
125
173
  ### Create Order
126
174
 
127
- ```js
175
+ ```ts
128
176
  // Create limit order
129
- ob.createOrder({ type: 'limit', side: 'buy' | 'sell', size: number, price: number, id: string, postOnly?: boolean, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
177
+ ob.createOrder({
178
+ type: 'limit',
179
+ side: 'buy' | 'sell',
180
+ size: number,
181
+ price: number,
182
+ id: string,
183
+ postOnly?: boolean,
184
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
185
+ })
130
186
 
131
187
  // Create market order
132
- ob.createOrder({ type: 'market', side: 'buy' | 'sell', size: number })
188
+ ob.createOrder({
189
+ type: 'market',
190
+ side: 'buy' | 'sell',
191
+ size: number
192
+ })
133
193
 
134
194
  // Create stop limit order
135
- ob.createOrder({ type: 'stop_limit', side: 'buy' | 'sell', size: number, price: number, id: string, stopPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
195
+ ob.createOrder({
196
+ type: 'stop_limit',
197
+ side: 'buy' | 'sell',
198
+ size: number,
199
+ price: number,
200
+ id: string,
201
+ stopPrice: number,
202
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
203
+ })
136
204
 
137
205
  // Create stop market order
138
- ob.createOrder({ type: 'stop_market', side: 'buy' | 'sell', size: number, stopPrice: number })
206
+ ob.createOrder({
207
+ type: 'stop_market',
208
+ side: 'buy' | 'sell',
209
+ size: number,
210
+ stopPrice: number
211
+ })
139
212
 
140
213
  // Create OCO order
141
- ob.createOrder({ type: 'oco', side: 'buy' | 'sell', size: number, stopPrice: number, stopLimitPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC', stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC' })
214
+ ob.createOrder({
215
+ type: 'oco',
216
+ side: 'buy' | 'sell',
217
+ size: number,
218
+ stopPrice: number,
219
+ stopLimitPrice: number,
220
+ timeInForce?: 'GTC' | 'FOK' | 'IOC',
221
+ stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC'
222
+ })
142
223
  ```
143
224
 
144
225
  ### Create Limit Order
145
226
 
146
- ```js
227
+ ```ts
147
228
  /**
148
229
  * Create a limit order. See {@link LimitOrderOptions} for details.
149
230
  *
@@ -156,12 +237,19 @@ ob.createOrder({ type: 'oco', side: 'buy' | 'sell', size: number, stopPrice: num
156
237
  * @param options.timeInForce - Time-in-force type supported are: GTC, FOK, IOC. Default is GTC
157
238
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
158
239
  */
159
- ob.limit({ side: 'buy' | 'sell', id: string, size: number, price: number, postOnly?: boolean, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
240
+ ob.limit({
241
+ side: 'buy' | 'sell',
242
+ id: string,
243
+ size: number,
244
+ price: number,
245
+ postOnly?: boolean,
246
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
247
+ })
160
248
  ```
161
249
 
162
250
  For example:
163
251
 
164
- ```
252
+ ```ts
165
253
  ob.limit({ side: "sell", id: "uniqueID", size: 55, price: 100 })
166
254
 
167
255
  asks: 110 -> 5 110 -> 5
@@ -174,7 +262,7 @@ done - null
174
262
  partial - null
175
263
  ```
176
264
 
177
- ```
265
+ ```ts
178
266
  ob.limit({ side: "buy", id: "uniqueID", size: 7, price: 120 })
179
267
 
180
268
  asks: 110 -> 5
@@ -188,7 +276,7 @@ done - 2 (or more orders)
188
276
  partial - uniqueID order
189
277
  ```
190
278
 
191
- ```
279
+ ```ts
192
280
  ob.limit({ side: "buy", id: "uniqueID", size: 3, price: 120 })
193
281
 
194
282
  asks: 110 -> 5
@@ -203,7 +291,7 @@ partial - 1 order with price 110
203
291
 
204
292
  ### Create Market Order
205
293
 
206
- ```js
294
+ ```ts
207
295
  /**
208
296
  * Create a market order. See {@link MarketOrderOptions} for details.
209
297
  *
@@ -217,7 +305,7 @@ ob.market({ side: 'buy' | 'sell', size: number })
217
305
 
218
306
  For example:
219
307
 
220
- ```
308
+ ```ts
221
309
  ob.market({ side: 'sell', size: 6 })
222
310
 
223
311
  asks: 110 -> 5 110 -> 5
@@ -231,7 +319,7 @@ partial - 1 order with price 80
231
319
  quantityLeft - 0
232
320
  ```
233
321
 
234
- ```
322
+ ```ts
235
323
  ob.market({ side: 'buy', size: 10 })
236
324
 
237
325
  asks: 110 -> 5
@@ -247,7 +335,7 @@ quantityLeft - 4
247
335
 
248
336
  ### Create Stop Limit Order
249
337
 
250
- ```js
338
+ ```ts
251
339
  /**
252
340
  * Create a stop limit order. See {@link StopLimitOrderOptions} for details.
253
341
  *
@@ -260,12 +348,19 @@ quantityLeft - 4
260
348
  * @param options.timeInForce - Time-in-force type supported are: GTC, FOK, IOC. Default is GTC
261
349
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
262
350
  */
263
- ob.stopLimit({ side: 'buy' | 'sell', id: string, size: number, price: number, stopPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC' })
351
+ ob.stopLimit({
352
+ side: 'buy' | 'sell',
353
+ id: string,
354
+ size: number,
355
+ price: number,
356
+ stopPrice: number,
357
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
358
+ })
264
359
  ```
265
360
 
266
361
  ### Create Stop Market Order
267
362
 
268
- ```js
363
+ ```ts
269
364
  /**
270
365
  * Create a stop market order. See {@link StopMarketOrderOptions} for details.
271
366
  *
@@ -275,12 +370,16 @@ ob.stopLimit({ side: 'buy' | 'sell', id: string, size: number, price: number, st
275
370
  * @param options.stopPrice - The price at which the order will be triggered.
276
371
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
277
372
  */
278
- ob.stopMarket({ side: 'buy' | 'sell', size: number, stopPrice: number })
373
+ ob.stopMarket({
374
+ side: 'buy' | 'sell',
375
+ size: number,
376
+ stopPrice: number
377
+ })
279
378
  ```
280
379
 
281
380
  ### Create OCO (One-Cancels-the-Other) Order
282
381
 
283
- ```js
382
+ ```ts
284
383
  /**
285
384
  * Create an OCO (One-Cancels-the-Other) order.
286
385
  * OCO order combines a `stop_limit` order and a `limit` order, where if stop price
@@ -304,12 +403,21 @@ ob.stopMarket({ side: 'buy' | 'sell', size: number, stopPrice: number })
304
403
  * @param options.stopLimitTimeInForce - Time-in-force of the `stop_limit` order. Type supported are: GTC, FOK, IOC. Default is GTC
305
404
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
306
405
  */
307
- ob.oco({ side: 'buy' | 'sell', id: string, size: number, price: number, stopPrice: number, stopLimitPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC', stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC' })
406
+ ob.oco({
407
+ side: 'buy' | 'sell',
408
+ id: string,
409
+ size: number,
410
+ price: number,
411
+ stopPrice: number,
412
+ stopLimitPrice: number,
413
+ timeInForce?: 'GTC' | 'FOK' | 'IOC',
414
+ stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC'
415
+ })
308
416
  ```
309
417
 
310
418
  ### Modify an existing order
311
419
 
312
- ```js
420
+ ```ts
313
421
  /**
314
422
  * Modify an existing order with given ID. When an order is modified by price or quantity,
315
423
  * it will be deemed as a new entry. Under the price-time-priority algorithm, orders are
@@ -325,7 +433,7 @@ ob.modify(orderID: string, { size: number, price: number })
325
433
 
326
434
  For example:
327
435
 
328
- ```
436
+ ```ts
329
437
  ob.limit({ side: "sell", id: "uniqueID", size: 55, price: 100 })
330
438
 
331
439
  asks: 110 -> 5 110 -> 5
@@ -356,7 +464,7 @@ bids: 90 -> 5 90 -> 5
356
464
 
357
465
  ### Cancel Order
358
466
 
359
- ```js
467
+ ```ts
360
468
  /**
361
469
  * Remove an existing order with given ID from the order book
362
470
  *
@@ -368,7 +476,7 @@ ob.cancel(orderID: string)
368
476
 
369
477
  For example:
370
478
 
371
- ```
479
+ ```ts
372
480
  ob.cancel("myUniqueID-Sell-1-with-100")
373
481
 
374
482
  asks: 110 -> 5
@@ -396,7 +504,7 @@ After taking the snapshot, you can safely remove all logs preceding the `lastOp`
396
504
 
397
505
  **Note**: The snapshot of the order book returns an object containing an `array` of `bids` and `asks`, which in turn are arrays of order objects. If the snapshot is saved to the database as a `string`, make sure to pass the snapshot in its original format when initializing the order book. For example, you can achieve this by using `JSON.parse` to convert the string back into its original object form.
398
506
 
399
- ```js
507
+ ```ts
400
508
  const ob = new OrderBook({ enableJournaling: true})
401
509
 
402
510
  // after every order save the log to the database
@@ -420,7 +528,7 @@ const ob = new OrderBook({ snapshot: JSON.parse(snapshot), journal: log, enableJ
420
528
 
421
529
  ### Journal Logs
422
530
  The `journal` option expects an array of journal logs that you can get by setting `enableJournaling` to true. When the journal is provided, the order book will replay all the operations, bringing the order book to the same state as the last log.
423
- ```js
531
+ ```ts
424
532
  // Assuming 'logs' is an array of log entries retrieved from the database
425
533
 
426
534
  const logs = await getLogs()
@@ -430,7 +538,7 @@ By combining snapshots with journaling, you can effectively restore and audit th
430
538
 
431
539
  ### Enable Journaling
432
540
  `enabledJournaling` is a configuration setting that determines whether journaling is enabled or disabled. When enabled, the property `log` will be added to the body of the response for each operation. The logs must be saved to the database and can then be used when a new instance of the order book is instantiated.
433
- ```js
541
+ ```ts
434
542
  const ob = new OrderBook({ enableJournaling: true }) // false by default
435
543
 
436
544
  // after every order save the log to the database
@@ -444,7 +552,7 @@ await saveLog(order.log)
444
552
 
445
553
  Build production (distribution) files in your dist folder:
446
554
 
447
- ```sh
555
+ ```
448
556
  npm run build
449
557
  ```
450
558
 
@@ -452,7 +560,7 @@ npm run build
452
560
 
453
561
  To run all the unit-test
454
562
 
455
- ```sh
563
+ ```
456
564
  npm run test
457
565
  ```
458
566
 
@@ -460,7 +568,7 @@ npm run test
460
568
 
461
569
  Run testing coverage
462
570
 
463
- ```sh
571
+ ```
464
572
  npm run test:cov
465
573
  ```
466
574
 
@@ -468,7 +576,7 @@ npm run test:cov
468
576
 
469
577
  Before running benchmark, make sure to have built the source code with `npm run build` first
470
578
 
471
- ```sh
579
+ ```
472
580
  npm run bench
473
581
  ```
474
582
 
@@ -26,10 +26,9 @@ var OrderBook = /** @class */ (function () {
26
26
  * @param {JournalLog} [options.snapshot] - The orderbook snapshot will be restored before processing any journal logs, if any.
27
27
  * @param {JournalLog} [options.journal] - Array of journal logs (optional).
28
28
  * @param {boolean} [options.enableJournaling=false] - Flag to enable journaling. Default to false
29
- * @param {boolean} [options.experimentalConditionalOrders=false] - Flag to enable experimental Conditional Order (Stop Market, Stop Limit and OCO orders). Default to false
30
29
  */
31
30
  function OrderBook(_a) {
32
- var _b = _a === void 0 ? {} : _a, snapshot = _b.snapshot, journal = _b.journal, _c = _b.enableJournaling, enableJournaling = _c === void 0 ? false : _c, _d = _b.experimentalConditionalOrders, experimentalConditionalOrders = _d === void 0 ? false : _d;
31
+ var _b = _a === void 0 ? {} : _a, snapshot = _b.snapshot, journal = _b.journal, _c = _b.enableJournaling, enableJournaling = _c === void 0 ? false : _c;
33
32
  var _this = this;
34
33
  this.orders = {};
35
34
  this._lastOp = 0;
@@ -44,9 +43,6 @@ var OrderBook = /** @class */ (function () {
44
43
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
45
44
  */
46
45
  this.stopMarket = function (options) {
47
- /* node:coverage ignore next 4 - We don't need test for this */
48
- if (!_this.experimentalConditionalOrders)
49
- throw new Error("In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true");
50
46
  var response = _this._stopMarket(options);
51
47
  if (_this.enableJournaling && response.err === null) {
52
48
  response.log = {
@@ -71,9 +67,6 @@ var OrderBook = /** @class */ (function () {
71
67
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
72
68
  */
73
69
  this.stopLimit = function (options) {
74
- /* node:coverage ignore next 4 - We don't need test for this */
75
- if (!_this.experimentalConditionalOrders)
76
- throw new Error("In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true");
77
70
  var response = _this._stopLimit(options);
78
71
  if (_this.enableJournaling && response.err === null) {
79
72
  response.log = {
@@ -109,9 +102,6 @@ var OrderBook = /** @class */ (function () {
109
102
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
110
103
  */
111
104
  this.oco = function (options) {
112
- /* node:coverage ignore next 4 - We don't need test for this */
113
- if (!_this.experimentalConditionalOrders)
114
- throw new Error("In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true");
115
105
  var response = _this._oco(options);
116
106
  if (_this.enableJournaling && response.err === null) {
117
107
  response.log = {
@@ -532,8 +522,6 @@ var OrderBook = /** @class */ (function () {
532
522
  return order;
533
523
  };
534
524
  this.executeConditionalOrder = function (side, priceBefore, response) {
535
- if (!_this.experimentalConditionalOrders)
536
- return;
537
525
  var pendingOrders = _this.stopBook.getConditionalOrders(side, priceBefore, _this._marketPrice);
538
526
  if (pendingOrders.length > 0) {
539
527
  var toBeExecuted_1 = [];
@@ -697,8 +685,7 @@ var OrderBook = /** @class */ (function () {
697
685
  }
698
686
  }
699
687
  // Remove linked OCO Stop Order if any
700
- if (_this.experimentalConditionalOrders &&
701
- headOrder.ocoStopPrice !== undefined) {
688
+ if (headOrder.ocoStopPrice !== undefined) {
702
689
  _this.stopBook.remove(headOrder.side, headOrder.id, headOrder.ocoStopPrice);
703
690
  }
704
691
  _this._marketPrice = headOrder.price;
@@ -717,6 +704,7 @@ var OrderBook = /** @class */ (function () {
717
704
  return false;
718
705
  }
719
706
  var cumulativeSize = 0;
707
+ // biome-ignore lint/suspicious/useIterableCallbackReturn: the forEach of the priceTree must return true to break the loop
720
708
  orderSide.priceTree().forEach(function (_, level) {
721
709
  if (price >= level.price() && cumulativeSize < size) {
722
710
  cumulativeSize += level.volume();
@@ -732,6 +720,7 @@ var OrderBook = /** @class */ (function () {
732
720
  return false;
733
721
  }
734
722
  var cumulativeSize = 0;
723
+ // biome-ignore lint/suspicious/useIterableCallbackReturn: the forEach of the priceTree must return true to break the loop
735
724
  orderSide.priceTree().forEach(function (_, level) {
736
725
  if (price <= level.price() && cumulativeSize < size) {
737
726
  cumulativeSize += level.volume();
@@ -783,7 +772,6 @@ var OrderBook = /** @class */ (function () {
783
772
  this.asks = new orderside_1.OrderSide(types_1.Side.SELL);
784
773
  this.enableJournaling = enableJournaling;
785
774
  this.stopBook = new stopbook_1.StopBook();
786
- this.experimentalConditionalOrders = experimentalConditionalOrders;
787
775
  // First restore from orderbook snapshot
788
776
  if (snapshot != null) {
789
777
  this.restoreSnapshot(snapshot);
package/dist/cjs/utils.js CHANGED
@@ -2,12 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.safeParse = exports.safeStringify = void 0;
4
4
  /* node:coverage ignore next - Don't know why this line is uncovered */
5
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
6
5
  var safeStringify = function (value) {
7
6
  try {
8
7
  return JSON.stringify(value);
9
8
  }
10
- catch (error) {
9
+ catch (_error) {
11
10
  return null;
12
11
  }
13
12
  };
@@ -17,7 +16,7 @@ var safeParse = function (value) {
17
16
  try {
18
17
  return JSON.parse(value);
19
18
  }
20
- catch (error) {
19
+ catch (_error) {
21
20
  return null;
22
21
  }
23
22
  };
@@ -23,10 +23,9 @@ var OrderBook = /** @class */ (function () {
23
23
  * @param {JournalLog} [options.snapshot] - The orderbook snapshot will be restored before processing any journal logs, if any.
24
24
  * @param {JournalLog} [options.journal] - Array of journal logs (optional).
25
25
  * @param {boolean} [options.enableJournaling=false] - Flag to enable journaling. Default to false
26
- * @param {boolean} [options.experimentalConditionalOrders=false] - Flag to enable experimental Conditional Order (Stop Market, Stop Limit and OCO orders). Default to false
27
26
  */
28
27
  function OrderBook(_a) {
29
- var _b = _a === void 0 ? {} : _a, snapshot = _b.snapshot, journal = _b.journal, _c = _b.enableJournaling, enableJournaling = _c === void 0 ? false : _c, _d = _b.experimentalConditionalOrders, experimentalConditionalOrders = _d === void 0 ? false : _d;
28
+ var _b = _a === void 0 ? {} : _a, snapshot = _b.snapshot, journal = _b.journal, _c = _b.enableJournaling, enableJournaling = _c === void 0 ? false : _c;
30
29
  var _this = this;
31
30
  this.orders = {};
32
31
  this._lastOp = 0;
@@ -41,9 +40,6 @@ var OrderBook = /** @class */ (function () {
41
40
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
42
41
  */
43
42
  this.stopMarket = function (options) {
44
- /* node:coverage ignore next 4 - We don't need test for this */
45
- if (!_this.experimentalConditionalOrders)
46
- throw new Error("In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true");
47
43
  var response = _this._stopMarket(options);
48
44
  if (_this.enableJournaling && response.err === null) {
49
45
  response.log = {
@@ -68,9 +64,6 @@ var OrderBook = /** @class */ (function () {
68
64
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
69
65
  */
70
66
  this.stopLimit = function (options) {
71
- /* node:coverage ignore next 4 - We don't need test for this */
72
- if (!_this.experimentalConditionalOrders)
73
- throw new Error("In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true");
74
67
  var response = _this._stopLimit(options);
75
68
  if (_this.enableJournaling && response.err === null) {
76
69
  response.log = {
@@ -106,9 +99,6 @@ var OrderBook = /** @class */ (function () {
106
99
  * @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
107
100
  */
108
101
  this.oco = function (options) {
109
- /* node:coverage ignore next 4 - We don't need test for this */
110
- if (!_this.experimentalConditionalOrders)
111
- throw new Error("In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true");
112
102
  var response = _this._oco(options);
113
103
  if (_this.enableJournaling && response.err === null) {
114
104
  response.log = {
@@ -529,8 +519,6 @@ var OrderBook = /** @class */ (function () {
529
519
  return order;
530
520
  };
531
521
  this.executeConditionalOrder = function (side, priceBefore, response) {
532
- if (!_this.experimentalConditionalOrders)
533
- return;
534
522
  var pendingOrders = _this.stopBook.getConditionalOrders(side, priceBefore, _this._marketPrice);
535
523
  if (pendingOrders.length > 0) {
536
524
  var toBeExecuted_1 = [];
@@ -694,8 +682,7 @@ var OrderBook = /** @class */ (function () {
694
682
  }
695
683
  }
696
684
  // Remove linked OCO Stop Order if any
697
- if (_this.experimentalConditionalOrders &&
698
- headOrder.ocoStopPrice !== undefined) {
685
+ if (headOrder.ocoStopPrice !== undefined) {
699
686
  _this.stopBook.remove(headOrder.side, headOrder.id, headOrder.ocoStopPrice);
700
687
  }
701
688
  _this._marketPrice = headOrder.price;
@@ -714,6 +701,7 @@ var OrderBook = /** @class */ (function () {
714
701
  return false;
715
702
  }
716
703
  var cumulativeSize = 0;
704
+ // biome-ignore lint/suspicious/useIterableCallbackReturn: the forEach of the priceTree must return true to break the loop
717
705
  orderSide.priceTree().forEach(function (_, level) {
718
706
  if (price >= level.price() && cumulativeSize < size) {
719
707
  cumulativeSize += level.volume();
@@ -729,6 +717,7 @@ var OrderBook = /** @class */ (function () {
729
717
  return false;
730
718
  }
731
719
  var cumulativeSize = 0;
720
+ // biome-ignore lint/suspicious/useIterableCallbackReturn: the forEach of the priceTree must return true to break the loop
732
721
  orderSide.priceTree().forEach(function (_, level) {
733
722
  if (price <= level.price() && cumulativeSize < size) {
734
723
  cumulativeSize += level.volume();
@@ -780,7 +769,6 @@ var OrderBook = /** @class */ (function () {
780
769
  this.asks = new OrderSide(Side.SELL);
781
770
  this.enableJournaling = enableJournaling;
782
771
  this.stopBook = new StopBook();
783
- this.experimentalConditionalOrders = experimentalConditionalOrders;
784
772
  // First restore from orderbook snapshot
785
773
  if (snapshot != null) {
786
774
  this.restoreSnapshot(snapshot);
package/dist/esm/utils.js CHANGED
@@ -1,10 +1,9 @@
1
1
  /* node:coverage ignore next - Don't know why this line is uncovered */
2
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
3
2
  export var safeStringify = function (value) {
4
3
  try {
5
4
  return JSON.stringify(value);
6
5
  }
7
- catch (error) {
6
+ catch (_error) {
8
7
  return null;
9
8
  }
10
9
  };
@@ -13,7 +12,7 @@ export var safeParse = function (value) {
13
12
  try {
14
13
  return JSON.parse(value);
15
14
  }
16
- catch (error) {
15
+ catch (_error) {
17
16
  return null;
18
17
  }
19
18
  };
@@ -1,4 +1,4 @@
1
1
  import { OrderBook } from "./orderbook";
2
+ import type { CreateOrderOptions, ICancelOrder, IOrder, IProcessOrder, LimitOrderOptions, MarketOrderOptions, OCOOrderOptions, OrderBookOptions, OrderUpdatePrice, OrderUpdateSize, StopLimitOrderOptions, StopMarketOrderOptions } from "./types";
2
3
  import { OrderType, Side } from "./types";
3
- import type { CreateOrderOptions, ICancelOrder, IProcessOrder, LimitOrderOptions, MarketOrderOptions, OCOOrderOptions, OrderBookOptions, OrderUpdatePrice, OrderUpdateSize, StopLimitOrderOptions, StopMarketOrderOptions } from "./types";
4
- export { type CreateOrderOptions, type ICancelOrder, type IProcessOrder, type LimitOrderOptions, type MarketOrderOptions, type OCOOrderOptions, OrderBook, type OrderBookOptions, OrderType, type OrderUpdatePrice, type OrderUpdateSize, Side, type StopLimitOrderOptions, type StopMarketOrderOptions, };
4
+ export { type CreateOrderOptions, type ICancelOrder, type IOrder, type IProcessOrder, type LimitOrderOptions, type MarketOrderOptions, type OCOOrderOptions, OrderBook, type OrderBookOptions, OrderType, type OrderUpdatePrice, type OrderUpdateSize, Side, type StopLimitOrderOptions, type StopMarketOrderOptions, };
@@ -1,4 +1,4 @@
1
- import { type ILimitOrder, type IStopLimitOrder, type IStopMarketOrder, type InternalLimitOrderOptions, type InternalStopLimitOrderOptions, type InternalStopMarketOrderOptions, type OrderOptions, OrderType, type Side, type TimeInForce } from "./types";
1
+ import { type ILimitOrder, type InternalLimitOrderOptions, type InternalStopLimitOrderOptions, type InternalStopMarketOrderOptions, type IStopLimitOrder, type IStopMarketOrder, type OrderOptions, OrderType, type Side, type TimeInForce } from "./types";
2
2
  declare abstract class BaseOrder {
3
3
  readonly _id: string;
4
4
  readonly _side: Side;
@@ -8,16 +8,14 @@ export declare class OrderBook {
8
8
  private readonly asks;
9
9
  private readonly enableJournaling;
10
10
  private readonly stopBook;
11
- private readonly experimentalConditionalOrders;
12
11
  /**
13
12
  * Creates an instance of OrderBook.
14
13
  * @param {OrderBookOptions} [options={}] - Options for configuring the order book.
15
14
  * @param {JournalLog} [options.snapshot] - The orderbook snapshot will be restored before processing any journal logs, if any.
16
15
  * @param {JournalLog} [options.journal] - Array of journal logs (optional).
17
16
  * @param {boolean} [options.enableJournaling=false] - Flag to enable journaling. Default to false
18
- * @param {boolean} [options.experimentalConditionalOrders=false] - Flag to enable experimental Conditional Order (Stop Market, Stop Limit and OCO orders). Default to false
19
17
  */
20
- constructor({ snapshot, journal, enableJournaling, experimentalConditionalOrders, }?: OrderBookOptions);
18
+ constructor({ snapshot, journal, enableJournaling, }?: OrderBookOptions);
21
19
  get marketPrice(): number;
22
20
  get lastOp(): number;
23
21
  /**
@@ -315,11 +315,6 @@ export interface OrderBookOptions {
315
315
  enableJournaling?: boolean;
316
316
  /** Array of journal logs. */
317
317
  journal?: JournalLog[];
318
- /**
319
- * Flag to enable experimental Conditional Order (Stop Market, Stop Limit and OCO orders).
320
- * Default to false
321
- */
322
- experimentalConditionalOrders?: boolean;
323
318
  }
324
319
  /**
325
320
  * Represents an update to the price of an order.
@@ -1,2 +1,2 @@
1
- export declare const safeStringify: (value: any) => string | null;
1
+ export declare const safeStringify: (value: unknown) => string | null;
2
2
  export declare const safeParse: <T>(value: string) => T | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-order-book",
3
- "version": "9.1.1",
3
+ "version": "10.0.1",
4
4
  "description": "Node.js Lmit Order Book for high-frequency trading (HFT).",
5
5
  "author": "Andrea Fassina <fasenderos@gmail.com>",
6
6
  "license": "MIT",