Skip to content

Commit 96d864f

Browse files
committed
feat: remove experimental conditional orders flag
1 parent b3e84c7 commit 96d864f

File tree

4 files changed

+49
-54
lines changed

4 files changed

+49
-54
lines changed

README.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Ultra-fast Node.js Order Book written in TypeScript </br> for high-frequency tra
1919
- [Features](#features)
2020
- [Installation](#installation)
2121
- [Usage](#usage)
22-
- [Experimental Conditional Orders](#conditional-orders-)
22+
- [Conditional Orders](#conditional-orders)
2323
- [About Primary Functions](#about-primary-functions)
2424
- [Create order `createOrder()`](#create-order)
2525
- [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
4848
- Standard price-time priority
4949
- Supports both market and limit orders
5050
- 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">
5252
- Supports time in force GTC, FOK and IOC <img src="https://img.shields.io/badge/New-green" alt="New">
5353
- Supports order cancelling
5454
- 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 }
102102

103103
ob.cancel(orderID: string)
104104
```
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.
107107
```js
108108
import { OrderBook } from 'nodejs-order-book'
109109

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()
117111

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+
})
119148
```
120149

121150
## About primary functions

src/orderbook.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,22 @@ export class OrderBook {
4141
private readonly asks: OrderSide;
4242
private readonly enableJournaling: boolean;
4343
private readonly stopBook: StopBook;
44-
private readonly experimentalConditionalOrders: boolean;
4544
/**
4645
* Creates an instance of OrderBook.
4746
* @param {OrderBookOptions} [options={}] - Options for configuring the order book.
4847
* @param {JournalLog} [options.snapshot] - The orderbook snapshot will be restored before processing any journal logs, if any.
4948
* @param {JournalLog} [options.journal] - Array of journal logs (optional).
5049
* @param {boolean} [options.enableJournaling=false] - Flag to enable journaling. Default to false
51-
* @param {boolean} [options.experimentalConditionalOrders=false] - Flag to enable experimental Conditional Order (Stop Market, Stop Limit and OCO orders). Default to false
5250
*/
5351
constructor({
5452
snapshot,
5553
journal,
5654
enableJournaling = false,
57-
experimentalConditionalOrders = false,
5855
}: OrderBookOptions = {}) {
5956
this.bids = new OrderSide(Side.BUY);
6057
this.asks = new OrderSide(Side.SELL);
6158
this.enableJournaling = enableJournaling;
6259
this.stopBook = new StopBook();
63-
this.experimentalConditionalOrders = experimentalConditionalOrders;
6460
// First restore from orderbook snapshot
6561
if (snapshot != null) {
6662
this.restoreSnapshot(snapshot);
@@ -156,11 +152,6 @@ export class OrderBook {
156152
* @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
157153
*/
158154
public stopMarket = (options: StopMarketOrderOptions): IProcessOrder => {
159-
/* node:coverage ignore next 4 - We don't need test for this */
160-
if (!this.experimentalConditionalOrders)
161-
throw new Error(
162-
"In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true",
163-
);
164155
const response = this._stopMarket(options);
165156
if (this.enableJournaling && response.err === null) {
166157
response.log = {
@@ -211,11 +202,6 @@ export class OrderBook {
211202
* @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
212203
*/
213204
public stopLimit = (options: StopLimitOrderOptions): IProcessOrder => {
214-
/* node:coverage ignore next 4 - We don't need test for this */
215-
if (!this.experimentalConditionalOrders)
216-
throw new Error(
217-
"In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true",
218-
);
219205
const response = this._stopLimit(options);
220206
if (this.enableJournaling && response.err === null) {
221207
response.log = {
@@ -252,11 +238,6 @@ export class OrderBook {
252238
* @returns An object with the result of the processed order or an error. See {@link IProcessOrder} for the returned data structure
253239
*/
254240
public oco = (options: OCOOrderOptions): IProcessOrder => {
255-
/* node:coverage ignore next 4 - We don't need test for this */
256-
if (!this.experimentalConditionalOrders)
257-
throw new Error(
258-
"In order to use conditional orders you need to instantiate the order book with the `experimentalConditionalOrders` option set to true",
259-
);
260241
const response = this._oco(options);
261242
if (this.enableJournaling && response.err === null) {
262243
response.log = {
@@ -767,7 +748,6 @@ export class OrderBook {
767748
priceBefore: number,
768749
response: IProcessOrder,
769750
): void => {
770-
if (!this.experimentalConditionalOrders) return;
771751
const pendingOrders = this.stopBook.getConditionalOrders(
772752
side,
773753
priceBefore,
@@ -956,10 +936,7 @@ export class OrderBook {
956936
}
957937
}
958938
// Remove linked OCO Stop Order if any
959-
if (
960-
this.experimentalConditionalOrders &&
961-
headOrder.ocoStopPrice !== undefined
962-
) {
939+
if (headOrder.ocoStopPrice !== undefined) {
963940
this.stopBook.remove(
964941
headOrder.side,
965942
headOrder.id,

src/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,6 @@ export interface OrderBookOptions {
354354
enableJournaling?: boolean;
355355
/** Array of journal logs. */
356356
journal?: JournalLog[];
357-
/**
358-
* Flag to enable experimental Conditional Order (Stop Market, Stop Limit and OCO orders).
359-
* Default to false
360-
*/
361-
experimentalConditionalOrders?: boolean;
362357
}
363358

364359
/**

test/orderbook.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ void test("createOrder error", () => {
444444
* Sell: marketPrice > stopPrice
445445
*/
446446
void test("test stop_market order", () => {
447-
const ob = new OrderBook({ experimentalConditionalOrders: true });
447+
const ob = new OrderBook();
448448

449449
addDepth(ob, "", 2);
450450
// We need to create at least on maket order in order to set
@@ -601,7 +601,7 @@ void test("test stop_market order", () => {
601601
* Sell: marketPrice > stopPrice >= price
602602
*/
603603
void test("test stop_limit order", () => {
604-
const ob = new OrderBook({ experimentalConditionalOrders: true });
604+
const ob = new OrderBook();
605605

606606
addDepth(ob, "", 2);
607607
// We need to create at least on maket order in order to set
@@ -808,7 +808,7 @@ void test("test stop_limit order", () => {
808808
* Sell: price > marketPrice > stopPrice
809809
*/
810810
void test("test oco order", () => {
811-
const ob = new OrderBook({ experimentalConditionalOrders: true });
811+
const ob = new OrderBook();
812812

813813
addDepth(ob, "", 2);
814814
// We need to create at least on maket order in order to set
@@ -1284,10 +1284,7 @@ void test("orderbook enableJournaling option", () => {
12841284
});
12851285

12861286
void test("orderbook replayJournal", () => {
1287-
const ob = new OrderBook({
1288-
enableJournaling: true,
1289-
experimentalConditionalOrders: true,
1290-
});
1287+
const ob = new OrderBook({ enableJournaling: true });
12911288

12921289
const journal: JournalLog[] = [];
12931290

@@ -1388,7 +1385,7 @@ void test("orderbook replayJournal", () => {
13881385
if (deleteOrder?.log != null) journal.push(deleteOrder.log);
13891386
}
13901387

1391-
const ob2 = new OrderBook({ journal, experimentalConditionalOrders: true });
1388+
const ob2 = new OrderBook({ journal });
13921389

13931390
assert.equal(ob.toString(), ob2.toString());
13941391
assert.equal(
@@ -1563,7 +1560,7 @@ void test("orderbook replayJournal test wrong journal", () => {
15631560
});
15641561

15651562
void test("orderbook test snapshot", () => {
1566-
const ob = new OrderBook({ experimentalConditionalOrders: true });
1563+
const ob = new OrderBook();
15671564
const addStopOrder = (
15681565
side: Side,
15691566
orderId: string,
@@ -1662,10 +1659,7 @@ void test("orderbook test snapshot", () => {
16621659
void test("orderbook restore from snapshot", () => {
16631660
// Create a new orderbook with 3 orders for price levels and make a snapshot
16641661
const journal: JournalLog[] = [];
1665-
const ob = new OrderBook({
1666-
enableJournaling: true,
1667-
experimentalConditionalOrders: true,
1668-
});
1662+
const ob = new OrderBook({ enableJournaling: true });
16691663

16701664
const addStopOrder = (
16711665
side: Side,

0 commit comments

Comments
 (0)