nodejs-order-book 8.0.1 → 9.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 +40 -8
- package/dist/cjs/order.js +6 -4
- package/dist/cjs/orderbook.js +153 -126
- package/dist/cjs/utils.js +24 -0
- package/dist/esm/order.js +6 -4
- package/dist/esm/orderbook.js +153 -126
- package/dist/esm/utils.js +19 -0
- package/dist/types/order.d.ts +3 -3
- package/dist/types/orderbook.d.ts +2 -47
- package/dist/types/types.d.ts +61 -20
- package/dist/types/utils.d.ts +2 -0
- package/dist/umd/index.js +1 -1
- package/package.json +10 -6
package/dist/types/types.d.ts
CHANGED
|
@@ -88,7 +88,6 @@ export interface InternalStopLimitOrderOptions extends ILimitOrderOptions {
|
|
|
88
88
|
* Specific options for oco order.
|
|
89
89
|
*/
|
|
90
90
|
export interface OCOOrderOptions extends StopLimitOrderOptions {
|
|
91
|
-
stopPrice: number;
|
|
92
91
|
stopLimitPrice: number;
|
|
93
92
|
stopLimitTimeInForce?: TimeInForce;
|
|
94
93
|
}
|
|
@@ -141,22 +140,25 @@ export interface IStopLimitOrder {
|
|
|
141
140
|
stopPrice: number;
|
|
142
141
|
timeInForce: TimeInForce;
|
|
143
142
|
time: number;
|
|
143
|
+
isOCO: boolean;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
146
|
* Represents an order in the order book.
|
|
147
147
|
*/
|
|
148
148
|
export type OrderOptions = InternalMarketOrderOptions | InternalLimitOrderOptions | InternalStopLimitOrderOptions | InternalStopMarketOrderOptions;
|
|
149
149
|
export type StopOrderOptions = StopMarketOrderOptions | StopLimitOrderOptions | OCOOrderOptions;
|
|
150
|
+
export type IStopOrder = IStopLimitOrder | IStopMarketOrder;
|
|
151
|
+
export type IOrder = ILimitOrder | IStopOrder;
|
|
150
152
|
/**
|
|
151
153
|
* Represents the result of processing an order.
|
|
152
154
|
*/
|
|
153
155
|
export interface IProcessOrder {
|
|
154
156
|
/** Array of fully processed orders. */
|
|
155
|
-
done:
|
|
157
|
+
done: IOrder[];
|
|
156
158
|
/** Array of activated (stop limit or stop market) orders */
|
|
157
|
-
activated:
|
|
159
|
+
activated: IStopOrder[];
|
|
158
160
|
/** The partially processed order, if any. */
|
|
159
|
-
partial:
|
|
161
|
+
partial: ILimitOrder | null;
|
|
160
162
|
/** The quantity that has been processed in the partial order. */
|
|
161
163
|
partialQuantityProcessed: number;
|
|
162
164
|
/** The remaining quantity that needs to be processed. */
|
|
@@ -185,19 +187,10 @@ export interface CancelOrderOptions {
|
|
|
185
187
|
/** Unique identifier of the order. */
|
|
186
188
|
orderID: string;
|
|
187
189
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Represents a cancel order operation.
|
|
190
|
-
*/
|
|
191
|
-
export interface ICancelOrder {
|
|
192
|
-
order: LimitOrder;
|
|
193
|
-
stopOrder?: StopOrder;
|
|
194
|
-
/** Optional log related to the order cancellation. */
|
|
195
|
-
log?: CancelOrderJournalLog;
|
|
196
|
-
}
|
|
197
190
|
/**
|
|
198
191
|
* Represents a log entry for a market order operation.
|
|
199
192
|
*/
|
|
200
|
-
|
|
193
|
+
interface MarketOrderJournalLog {
|
|
201
194
|
/** Incremental ID of the operation */
|
|
202
195
|
opId: number;
|
|
203
196
|
/** Timestamp of the operation. */
|
|
@@ -210,7 +203,7 @@ export interface MarketOrderJournalLog {
|
|
|
210
203
|
/**
|
|
211
204
|
* Represents a log entry for a limit order operation.
|
|
212
205
|
*/
|
|
213
|
-
|
|
206
|
+
interface LimitOrderJournalLog {
|
|
214
207
|
/** Incremental ID of the operation */
|
|
215
208
|
opId: number;
|
|
216
209
|
/** Timestamp of the operation. */
|
|
@@ -220,10 +213,49 @@ export interface LimitOrderJournalLog {
|
|
|
220
213
|
/** Specific options for the limit order. */
|
|
221
214
|
o: LimitOrderOptions;
|
|
222
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Represents a log entry for a stop_market order operation.
|
|
218
|
+
*/
|
|
219
|
+
interface StopMarketOrderJournalLog {
|
|
220
|
+
/** Incremental ID of the operation */
|
|
221
|
+
opId: number;
|
|
222
|
+
/** Timestamp of the operation. */
|
|
223
|
+
ts: number;
|
|
224
|
+
/** Operation type: 'sm' for stop_market order. */
|
|
225
|
+
op: "sm";
|
|
226
|
+
/** Specific options for the stop_market order. */
|
|
227
|
+
o: StopMarketOrderOptions;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Represents a log entry for a stop_limit order operation.
|
|
231
|
+
*/
|
|
232
|
+
interface StopLimitOrderJournalLog {
|
|
233
|
+
/** Incremental ID of the operation */
|
|
234
|
+
opId: number;
|
|
235
|
+
/** Timestamp of the operation. */
|
|
236
|
+
ts: number;
|
|
237
|
+
/** Operation type: 'l' for stop_limit order. */
|
|
238
|
+
op: "sl";
|
|
239
|
+
/** Specific options for the stop_limit order. */
|
|
240
|
+
o: StopLimitOrderOptions;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Represents a log entry for a oco order operation.
|
|
244
|
+
*/
|
|
245
|
+
interface OCOOrderJournalLog {
|
|
246
|
+
/** Incremental ID of the operation */
|
|
247
|
+
opId: number;
|
|
248
|
+
/** Timestamp of the operation. */
|
|
249
|
+
ts: number;
|
|
250
|
+
/** Operation type: 'l' for oco order. */
|
|
251
|
+
op: "oco";
|
|
252
|
+
/** Specific options for the oco order. */
|
|
253
|
+
o: OCOOrderOptions;
|
|
254
|
+
}
|
|
223
255
|
/**
|
|
224
256
|
* Represents a log entry for an order modification operation.
|
|
225
257
|
*/
|
|
226
|
-
|
|
258
|
+
interface ModifyOrderJournalLog {
|
|
227
259
|
/** Incremental ID of the operation */
|
|
228
260
|
opId: number;
|
|
229
261
|
/** Timestamp of the operation. */
|
|
@@ -236,7 +268,7 @@ export interface ModifyOrderJournalLog {
|
|
|
236
268
|
/**
|
|
237
269
|
* Represents a log entry for an order cancellation operation.
|
|
238
270
|
*/
|
|
239
|
-
|
|
271
|
+
interface CancelOrderJournalLog {
|
|
240
272
|
/** Incremental ID of the operation */
|
|
241
273
|
opId: number;
|
|
242
274
|
/** Timestamp of the operation. */
|
|
@@ -249,7 +281,7 @@ export interface CancelOrderJournalLog {
|
|
|
249
281
|
/**
|
|
250
282
|
* Discriminated union of all journaling log types.
|
|
251
283
|
*/
|
|
252
|
-
export type JournalLog = MarketOrderJournalLog | LimitOrderJournalLog | ModifyOrderJournalLog | CancelOrderJournalLog;
|
|
284
|
+
export type JournalLog = MarketOrderJournalLog | LimitOrderJournalLog | StopMarketOrderJournalLog | StopLimitOrderJournalLog | OCOOrderJournalLog | ModifyOrderJournalLog | CancelOrderJournalLog;
|
|
253
285
|
export type CreateOrderOptions = ({
|
|
254
286
|
type: OrderType.MARKET;
|
|
255
287
|
} & MarketOrderOptions) | ({
|
|
@@ -261,6 +293,15 @@ export type CreateOrderOptions = ({
|
|
|
261
293
|
} & StopLimitOrderOptions) | ({
|
|
262
294
|
type: OrderType.OCO;
|
|
263
295
|
} & OCOOrderOptions);
|
|
296
|
+
/**
|
|
297
|
+
* Represents a cancel order operation.
|
|
298
|
+
*/
|
|
299
|
+
export interface ICancelOrder {
|
|
300
|
+
order: ILimitOrder;
|
|
301
|
+
stopOrder?: IStopOrder;
|
|
302
|
+
/** Optional log related to the order cancellation. */
|
|
303
|
+
log?: CancelOrderJournalLog;
|
|
304
|
+
}
|
|
264
305
|
/**
|
|
265
306
|
* Options for configuring the order book.
|
|
266
307
|
*/
|
|
@@ -307,14 +348,14 @@ export interface Snapshot {
|
|
|
307
348
|
/** Price of the ask order */
|
|
308
349
|
price: number;
|
|
309
350
|
/** List of orders associated with this price */
|
|
310
|
-
orders:
|
|
351
|
+
orders: ILimitOrder[];
|
|
311
352
|
}>;
|
|
312
353
|
/** List of bid orders, each with a price and a list of associated orders */
|
|
313
354
|
bids: Array<{
|
|
314
355
|
/** Price of the bid order */
|
|
315
356
|
price: number;
|
|
316
357
|
/** List of orders associated with this price */
|
|
317
|
-
orders:
|
|
358
|
+
orders: ILimitOrder[];
|
|
318
359
|
}>;
|
|
319
360
|
/** Unix timestamp representing when the snapshot was taken */
|
|
320
361
|
ts: number;
|