API Reference / OrderTracker
Class: OrderTracker
Defined in: src/execution/OrderTracker.ts:46
Resolves a placed order to its final state using order-update events.
Order placement returns an id, not a fill. Polling GET /orders/{id} to find out what happened is slower and burns rate limit, so this listens on the order-update socket instead and settles a promise when the order reaches a terminal status.
Correlation ids are the join key: an order is tracked from the moment it is submitted, which closes the race where the fill event arrives before the REST response does.
Extends
EventEmitter
Constructors
Constructor
new OrderTracker(
options?):OrderTracker
Defined in: node_modules/@types/node/events.d.ts:90
Parameters
options?
EventEmitterOptions
Returns
OrderTracker
Inherited from
EventEmitter.constructor
Methods
onOrderUpdate()
onOrderUpdate(
state):void
Defined in: src/execution/OrderTracker.ts:57
Feeds one order update in. Wire to client.ws.orders.on("order", …).
Parameters
state
Returns
void
waitFor()
waitFor(
key,options?):Promise<OrderOutcome>
Defined in: src/execution/OrderTracker.ts:98
Resolves when the order reaches a terminal status.
Rejection and cancellation resolve rather than throw — they are outcomes, not errors. Only the timeout rejects.
Parameters
key
string
options?
WaitOptions = {}
Returns
Promise<OrderOutcome>
clear()
clear():
void
Defined in: src/execution/OrderTracker.ts:122
Drops every pending waiter — call on disconnect or shutdown.
Returns
void
on()
on<
K>(event,listener):this
Defined in: src/execution/OrderTracker.ts:131
Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// aType Parameters
K
K extends keyof OrderTrackerEvents
Parameters
event
K
listener
The callback function
Returns
this
Since
v0.1.101
Overrides
EventEmitter.on
emit()
emit<
K>(event, ...args):boolean
Defined in: src/execution/OrderTracker.ts:138
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.
Returns true if the event had listeners, false otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listenerType Parameters
K
K extends keyof OrderTrackerEvents
Parameters
event
K
args
...Parameters<OrderTrackerEvents[K]>
Returns
boolean
Since
v0.1.26
Overrides
EventEmitter.emit