nodejs-order-book 9.1.1 → 10.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.
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">
@@ -102,20 +102,49 @@ ob.modify(orderID: string, { side: 'buy' | 'sell', size: number, price: number }
102
102
 
103
103
  ob.cancel(orderID: string)
104
104
  ```
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`.
105
+ ### Conditional Orders
106
+ Currently `Stop Market`, `Stop Limit` and `OCO` orders are supported.
107
107
  ```js
108
108
  import { OrderBook } from 'nodejs-order-book'
109
109
 
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 })
110
+ const ob = new OrderBook()
117
111
 
118
- ob.oco({ id: string, side: 'buy' | 'sell', size: number, price: number, stopPrice: number, stopLimitPrice: number, timeInForce?: 'GTC' | 'FOK' | 'IOC', stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC' })
112
+ ob.createOrder({
113
+ type: 'stop_limit' | 'stop_market' | 'oco',
114
+ side: 'buy' | 'sell',
115
+ size: number,
116
+ price?: number,
117
+ id?: string,
118
+ stopPrice?: number,
119
+ timeInForce?: 'GTC' | 'FOK' | 'IOC',
120
+ stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC'
121
+ })
122
+
123
+ ob.stopLimit({
124
+ id: string,
125
+ side: 'buy' | 'sell',
126
+ size: number,
127
+ price: number,
128
+ stopPrice: number,
129
+ timeInForce?: 'GTC' | 'FOK' | 'IOC'
130
+ })
131
+
132
+ ob.stopMarket({
133
+ side: 'buy' | 'sell',
134
+ size: number,
135
+ stopPrice: number
136
+ })
137
+
138
+ ob.oco({
139
+ id: string,
140
+ side: 'buy' | 'sell',
141
+ size: number,
142
+ price: number,
143
+ stopPrice: number,
144
+ stopLimitPrice: number,
145
+ timeInForce?: 'GTC' | 'FOK' | 'IOC',
146
+ stopLimitTimeInForce?: 'GTC' | 'FOK' | 'IOC'
147
+ })
119
148
  ```
120
149
 
121
150
  ## About primary functions
@@ -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;
@@ -783,7 +770,6 @@ var OrderBook = /** @class */ (function () {
783
770
  this.asks = new orderside_1.OrderSide(types_1.Side.SELL);
784
771
  this.enableJournaling = enableJournaling;
785
772
  this.stopBook = new stopbook_1.StopBook();
786
- this.experimentalConditionalOrders = experimentalConditionalOrders;
787
773
  // First restore from orderbook snapshot
788
774
  if (snapshot != null) {
789
775
  this.restoreSnapshot(snapshot);
@@ -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;
@@ -780,7 +767,6 @@ var OrderBook = /** @class */ (function () {
780
767
  this.asks = new OrderSide(Side.SELL);
781
768
  this.enableJournaling = enableJournaling;
782
769
  this.stopBook = new StopBook();
783
- this.experimentalConditionalOrders = experimentalConditionalOrders;
784
770
  // First restore from orderbook snapshot
785
771
  if (snapshot != null) {
786
772
  this.restoreSnapshot(snapshot);
@@ -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.
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.0",
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",