nodejs-order-book 8.1.0 → 9.1.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.
@@ -1,6 +1,5 @@
1
1
  import { type OrderBookError } from "./errors";
2
- import { type LimitOrder } from "./order";
3
- import { type CreateOrderOptions, type ICancelOrder, type IProcessOrder, type LimitOrderOptions, type MarketOrderOptions, type OCOOrderOptions, type OrderBookOptions, type OrderUpdatePrice, type OrderUpdateSize, Side, type Snapshot, type StopLimitOrderOptions, type StopMarketOrderOptions } from "./types";
2
+ import { type CreateOrderOptions, type ICancelOrder, type ILimitOrder, type IProcessOrder, type LimitOrderOptions, type MarketOrderOptions, type OCOOrderOptions, type OrderBookOptions, type OrderUpdatePrice, type OrderUpdateSize, Side, type Snapshot, type StopLimitOrderOptions, type StopMarketOrderOptions } from "./types";
4
3
  export declare class OrderBook {
5
4
  private orders;
6
5
  private _lastOp;
@@ -131,7 +130,7 @@ export declare class OrderBook {
131
130
  * @param orderID - The ID of the order to be returned
132
131
  * @returns The order if exists or `undefined`
133
132
  */
134
- order: (orderID: string) => LimitOrder | undefined;
133
+ order: (orderID: string) => ILimitOrder | undefined;
135
134
  depth: () => [Array<[number, number]>, Array<[number, number]>];
136
135
  toString: () => string;
137
136
  calculateMarketPrice: (side: Side, size: number) => {
@@ -1,5 +1,5 @@
1
1
  import type { StopQueue } from "./stopqueue";
2
- import { Side, type StopOrder } from "./types";
2
+ import { type IStopOrder, Side, type StopOrder } from "./types";
3
3
  export declare class StopBook {
4
4
  private readonly bids;
5
5
  private readonly asks;
@@ -17,4 +17,14 @@ export declare class StopBook {
17
17
  * Sell: marketPrice > stopPrice
18
18
  */
19
19
  validConditionalOrder: (marketPrice: number, order: StopOrder) => boolean;
20
+ snapshot: () => {
21
+ bids: {
22
+ price: number;
23
+ orders: IStopOrder[];
24
+ }[];
25
+ asks: {
26
+ price: number;
27
+ orders: IStopOrder[];
28
+ }[];
29
+ };
20
30
  }
@@ -9,4 +9,5 @@ export declare class StopQueue {
9
9
  removeFromHead: () => StopOrder | undefined;
10
10
  append: (order: StopOrder) => StopOrder;
11
11
  remove: (id: string) => StopOrder | undefined;
12
+ toArray: () => StopOrder[];
12
13
  }
@@ -1,3 +1,4 @@
1
+ import createRBTree from "functional-red-black-tree";
1
2
  import { StopQueue } from "./stopqueue";
2
3
  import { Side, type StopOrder } from "./types";
3
4
  export declare class StopSide {
@@ -9,4 +10,5 @@ export declare class StopSide {
9
10
  remove: (id: string, stopPrice: number) => StopOrder | undefined;
10
11
  removePriceLevel: (priceLevel: number) => void;
11
12
  between: (priceBefore: number, marketPrice: number) => StopQueue[];
13
+ priceTree: () => createRBTree.Tree<number, StopQueue>;
12
14
  }
@@ -140,22 +140,25 @@ export interface IStopLimitOrder {
140
140
  stopPrice: number;
141
141
  timeInForce: TimeInForce;
142
142
  time: number;
143
+ isOCO: boolean;
143
144
  }
144
145
  /**
145
146
  * Represents an order in the order book.
146
147
  */
147
148
  export type OrderOptions = InternalMarketOrderOptions | InternalLimitOrderOptions | InternalStopLimitOrderOptions | InternalStopMarketOrderOptions;
148
149
  export type StopOrderOptions = StopMarketOrderOptions | StopLimitOrderOptions | OCOOrderOptions;
150
+ export type IStopOrder = IStopLimitOrder | IStopMarketOrder;
151
+ export type IOrder = ILimitOrder | IStopOrder;
149
152
  /**
150
153
  * Represents the result of processing an order.
151
154
  */
152
155
  export interface IProcessOrder {
153
156
  /** Array of fully processed orders. */
154
- done: Order[];
157
+ done: IOrder[];
155
158
  /** Array of activated (stop limit or stop market) orders */
156
- activated: StopOrder[];
159
+ activated: IStopOrder[];
157
160
  /** The partially processed order, if any. */
158
- partial: LimitOrder | null;
161
+ partial: ILimitOrder | null;
159
162
  /** The quantity that has been processed in the partial order. */
160
163
  partialQuantityProcessed: number;
161
164
  /** The remaining quantity that needs to be processed. */
@@ -294,8 +297,8 @@ export type CreateOrderOptions = ({
294
297
  * Represents a cancel order operation.
295
298
  */
296
299
  export interface ICancelOrder {
297
- order: LimitOrder;
298
- stopOrder?: StopOrder;
300
+ order: ILimitOrder;
301
+ stopOrder?: IStopOrder;
299
302
  /** Optional log related to the order cancellation. */
300
303
  log?: CancelOrderJournalLog;
301
304
  }
@@ -345,15 +348,25 @@ export interface Snapshot {
345
348
  /** Price of the ask order */
346
349
  price: number;
347
350
  /** List of orders associated with this price */
348
- orders: LimitOrder[];
351
+ orders: ILimitOrder[];
349
352
  }>;
350
353
  /** List of bid orders, each with a price and a list of associated orders */
351
354
  bids: Array<{
352
355
  /** Price of the bid order */
353
356
  price: number;
354
357
  /** List of orders associated with this price */
355
- orders: LimitOrder[];
358
+ orders: ILimitOrder[];
356
359
  }>;
360
+ stopBook: {
361
+ asks: Array<{
362
+ price: number;
363
+ orders: IStopOrder[];
364
+ }>;
365
+ bids: Array<{
366
+ price: number;
367
+ orders: IStopOrder[];
368
+ }>;
369
+ };
357
370
  /** Unix timestamp representing when the snapshot was taken */
358
371
  ts: number;
359
372
  /** The id of the last operation inserted in the orderbook */
@@ -0,0 +1,2 @@
1
+ export declare const safeStringify: (value: any) => string | null;
2
+ export declare const safeParse: <T>(value: string) => T | null;