@flexemarkets/fm-sdk 0.1.3 → 0.2.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 +16 -19
- package/dist/client.d.ts +33 -12
- package/dist/client.js +56 -25
- package/dist/client.js.map +1 -1
- package/dist/{market-view.d.ts → desk.d.ts} +83 -34
- package/dist/{market-view.js → desk.js} +99 -47
- package/dist/desk.js.map +1 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/order-utils.d.ts +27 -2
- package/dist/order-utils.js +51 -2
- package/dist/order-utils.js.map +1 -1
- package/dist/orderbook.d.ts +17 -8
- package/dist/orderbook.js +37 -11
- package/dist/orderbook.js.map +1 -1
- package/dist/snapshot.d.ts +1 -1
- package/dist/stomp.d.ts +36 -4
- package/dist/stomp.js +90 -2
- package/dist/stomp.js.map +1 -1
- package/dist/ticker.js +20 -44
- package/dist/ticker.js.map +1 -1
- package/dist/trades.d.ts +77 -15
- package/dist/trades.js +83 -33
- package/dist/trades.js.map +1 -1
- package/dist/types.d.ts +25 -4
- package/dist/types.js +28 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/market-view.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Desk — always-current state for a single marketplace, hiding
|
|
3
3
|
* transport details (WebSocket subscribe, snapshot+delta
|
|
4
4
|
* reconciliation, sequence-gap recovery, reconnect) behind a small
|
|
5
5
|
* read-side surface. Mirrors the Java + Python SDKs; same staged
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
* snapshot seed, no sharing, no reconnect — those land in Phase 2.
|
|
11
11
|
*/
|
|
12
12
|
import type { Flexemarkets } from "./client.js";
|
|
13
|
-
import {
|
|
13
|
+
import { Book } from "./orderbook.js";
|
|
14
|
+
import { type Trade, type Tape } from "./trades.js";
|
|
14
15
|
import type { Holding, Market, Order, Session } from "./types.js";
|
|
15
16
|
/**
|
|
16
|
-
* Handle returned by `
|
|
17
|
+
* Handle returned by `Desk.on*` listener registrations. Call
|
|
17
18
|
* to unregister. Idempotent — multiple calls are no-ops.
|
|
18
19
|
*/
|
|
19
20
|
export type Subscription = () => void;
|
|
20
21
|
/**
|
|
21
|
-
* Fires when
|
|
22
|
+
* Fires when Desk detects a sequence-gap in the ORDERS-UPDATE
|
|
22
23
|
* WS stream — one or more frames were dropped between client and
|
|
23
|
-
* fm-server. After a gap,
|
|
24
|
+
* fm-server. After a gap, Desk re-runs the REST snapshot
|
|
24
25
|
* recovery flow before applying further deltas; the gap event is the
|
|
25
26
|
* signal callers can wire into their own observability stack instead
|
|
26
27
|
* of relying on the SDK's default console.warn.
|
|
@@ -31,26 +32,46 @@ export interface GapEvent {
|
|
|
31
32
|
readonly receivedSeq: number;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
* Fires when
|
|
35
|
+
* Fires when Desk reacts to a StreamDropped — either after
|
|
35
36
|
* the reconnect + resnapshot completes successfully, or after the
|
|
36
|
-
* attempt has failed and the
|
|
37
|
+
* attempt has failed and the desk is left stale.
|
|
37
38
|
*/
|
|
38
|
-
export interface
|
|
39
|
+
export interface DeskRecovery {
|
|
39
40
|
readonly marketplaceId: number;
|
|
40
41
|
readonly success: boolean;
|
|
41
42
|
readonly reason: string | null;
|
|
42
43
|
}
|
|
43
|
-
export interface
|
|
44
|
-
/** The marketplace this
|
|
44
|
+
export interface Desk {
|
|
45
|
+
/** The marketplace this desk tracks. */
|
|
45
46
|
readonly marketplaceId: number;
|
|
46
|
-
/** Markets in this marketplace, captured
|
|
47
|
+
/** Markets in this marketplace, captured when the desk was opened. */
|
|
47
48
|
readonly markets: Market[];
|
|
48
49
|
/**
|
|
49
50
|
* Always-current order book for `marketId`. Reads are atomic; a
|
|
50
51
|
* caller never sees a half-applied delta. Returns null if
|
|
51
52
|
* `marketId` isn't in this marketplace.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
book(marketId: number): Book | null;
|
|
55
|
+
/**
|
|
56
|
+
* Always-current trade tape for `marketId`, most recent last. Returns null
|
|
57
|
+
* if `marketId` isn't in this marketplace.
|
|
58
|
+
*
|
|
59
|
+
* Maintained alongside {@link book}: seeded from the server's recent
|
|
60
|
+
* trades when the desk opens, then kept current from the same delta stream.
|
|
61
|
+
* Each `Trade` on it carries both sides of its match — the resting
|
|
62
|
+
* order that was taken and the aggressor that took it.
|
|
63
|
+
*/
|
|
64
|
+
tape(marketId: number): Tape | null;
|
|
65
|
+
/**
|
|
66
|
+
* Every book this desk keeps, one per market.
|
|
67
|
+
*
|
|
68
|
+
* The whole-marketplace read that {@link book} answers one market at a time.
|
|
69
|
+
* A caller scanning for the best opportunity across markets wants this
|
|
70
|
+
* rather than {@link markets} zipped against {@link book}.
|
|
71
|
+
*/
|
|
72
|
+
books(): Book[];
|
|
73
|
+
/** Every tape this desk keeps, one per market. */
|
|
74
|
+
tapes(): Tape[];
|
|
54
75
|
/**
|
|
55
76
|
* Most-recent session update observed. Null until the first
|
|
56
77
|
* SESSION-UPDATE frame lands.
|
|
@@ -67,11 +88,30 @@ export interface MarketView {
|
|
|
67
88
|
* Register a handler that fires when the order book for
|
|
68
89
|
* `marketId` changes. The handler receives the post-update book.
|
|
69
90
|
*/
|
|
70
|
-
|
|
91
|
+
onBookChange(marketId: number, handler: (b: Book) => void): Subscription;
|
|
92
|
+
/**
|
|
93
|
+
* Register a handler that fires for each trade on `marketId`.
|
|
94
|
+
*
|
|
95
|
+
* The missing member of the family {@link onBookChange} and
|
|
96
|
+
* {@link onSessionChange} belong to. Without it, "tell me when a trade
|
|
97
|
+
* happens" is asked as "tell me when the book changed, then let me look" —
|
|
98
|
+
* which answers a different question, since a book changes on every resting
|
|
99
|
+
* order and most changes are not trades.
|
|
100
|
+
*
|
|
101
|
+
* Fires **once per trade**, oldest first, rather than coalescing a batch the
|
|
102
|
+
* way {@link onBookChange} does. A trade is a discrete event with its own
|
|
103
|
+
* price and counterparties; collapsing two into one callback would lose one.
|
|
104
|
+
*
|
|
105
|
+
* Live deltas only. A gap or a reconnect re-seeds the tape from the server's
|
|
106
|
+
* snapshot, and those trades do not fire here — they are not new, they are
|
|
107
|
+
* what was missed. {@link onGap} and {@link onRecovery} are how a caller
|
|
108
|
+
* learns that happened.
|
|
109
|
+
*/
|
|
110
|
+
onTrade(marketId: number, handler: (t: Trade) => void): Subscription;
|
|
71
111
|
/** Register a handler for the caller's holding changes. */
|
|
72
112
|
onHoldingChange(handler: (h: Holding) => void): Subscription;
|
|
73
113
|
/**
|
|
74
|
-
* Register a handler that fires when
|
|
114
|
+
* Register a handler that fires when Desk detects a gap in
|
|
75
115
|
* the ORDERS-UPDATE seq stream. Use this to wire your own
|
|
76
116
|
* telemetry — by default the SDK logs to console.warn but
|
|
77
117
|
* otherwise hides the recovery flow.
|
|
@@ -80,10 +120,10 @@ export interface MarketView {
|
|
|
80
120
|
/**
|
|
81
121
|
* Register a handler that fires after the SDK reacts to a
|
|
82
122
|
* transport error — either when reconnect + resnapshot have
|
|
83
|
-
* completed, or when the attempt has failed and the
|
|
123
|
+
* completed, or when the attempt has failed and the desk is left
|
|
84
124
|
* stale.
|
|
85
125
|
*/
|
|
86
|
-
|
|
126
|
+
onRecovery(handler: (event: DeskRecovery) => void): Subscription;
|
|
87
127
|
/** Submit a limit order on this marketplace. */
|
|
88
128
|
submitLimit(marketId: number, side: string, units: number, price: number): Promise<Order>;
|
|
89
129
|
/** Cancel a previously-submitted order. */
|
|
@@ -95,11 +135,11 @@ export interface MarketView {
|
|
|
95
135
|
*/
|
|
96
136
|
close(): void;
|
|
97
137
|
}
|
|
98
|
-
export declare class
|
|
138
|
+
export declare class DefaultDesk implements Desk {
|
|
99
139
|
readonly marketplaceId: number;
|
|
100
140
|
readonly markets: Market[];
|
|
101
141
|
private readonly _flexemarkets;
|
|
102
|
-
private readonly
|
|
142
|
+
private readonly _books;
|
|
103
143
|
private readonly _trades;
|
|
104
144
|
private _events;
|
|
105
145
|
private _session;
|
|
@@ -107,18 +147,19 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
107
147
|
private readonly _sessionHandlers;
|
|
108
148
|
private readonly _holdingHandlers;
|
|
109
149
|
private readonly _bookHandlers;
|
|
150
|
+
private readonly _tradeHandlers;
|
|
110
151
|
private readonly _gapHandlers;
|
|
111
152
|
private readonly _reconnectHandlers;
|
|
112
153
|
private _closed;
|
|
113
154
|
/**
|
|
114
|
-
* Highest ORDERS-UPDATE seq this
|
|
155
|
+
* Highest ORDERS-UPDATE seq this desk has applied so far. Deltas
|
|
115
156
|
* with `seq <= _lastAppliedSeq` are skipped — they've already been
|
|
116
157
|
* folded into the local state via the initial REST snapshot or a
|
|
117
158
|
* previously-applied delta. Initial value comes from the snapshot's
|
|
118
159
|
* `asOfSeq`; `NO_SEQ` disables filtering (older fm-server).
|
|
119
160
|
*/
|
|
120
161
|
private _lastAppliedSeq;
|
|
121
|
-
static open(flexemarkets: Flexemarkets, marketplaceId: number): Promise<
|
|
162
|
+
static open(flexemarkets: Flexemarkets, marketplaceId: number): Promise<DefaultDesk>;
|
|
122
163
|
private _seedComplete;
|
|
123
164
|
private _seedBuffer;
|
|
124
165
|
private constructor();
|
|
@@ -136,14 +177,18 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
136
177
|
* Phase 2b (gap recovery + ID-based dedup) closes the window.
|
|
137
178
|
*/
|
|
138
179
|
private _seedFromSnapshot;
|
|
139
|
-
|
|
180
|
+
book(marketId: number): Book | null;
|
|
181
|
+
tape(marketId: number): Tape | null;
|
|
182
|
+
books(): Book[];
|
|
183
|
+
tapes(): Tape[];
|
|
140
184
|
session(): Session | null;
|
|
141
185
|
holding(): Holding | null;
|
|
142
186
|
onSessionChange(handler: (s: Session) => void): Subscription;
|
|
143
|
-
|
|
187
|
+
onTrade(marketId: number, handler: (t: Trade) => void): Subscription;
|
|
188
|
+
onBookChange(marketId: number, handler: (b: Book) => void): Subscription;
|
|
144
189
|
onHoldingChange(handler: (h: Holding) => void): Subscription;
|
|
145
190
|
onGap(handler: (e: GapEvent) => void): Subscription;
|
|
146
|
-
|
|
191
|
+
onRecovery(handler: (e: DeskRecovery) => void): Subscription;
|
|
147
192
|
submitLimit(marketId: number, side: string, units: number, price: number): Promise<Order>;
|
|
148
193
|
submitCancel(marketId: number, originalId: number): Promise<Order>;
|
|
149
194
|
close(): void;
|
|
@@ -152,21 +197,21 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
152
197
|
/**
|
|
153
198
|
* Re-seed once the transport is back.
|
|
154
199
|
*
|
|
155
|
-
* Reconnecting is not this layer's job -- a `
|
|
200
|
+
* Reconnecting is not this layer's job -- a `StreamReconnected` only arrives
|
|
156
201
|
* because the listener already restored the subscription. Reseeding is: a
|
|
157
202
|
* reconnect is the largest possible sequence gap, so _seedFromSnapshot()
|
|
158
203
|
* (clear + REST snapshot + reapply + seq watermark) is what converges the
|
|
159
|
-
* state, exactly as it does for a small one. If it fails the
|
|
160
|
-
* stale until the caller close()s and
|
|
204
|
+
* state, exactly as it does for a small one. If it fails the desk is left
|
|
205
|
+
* stale until the caller close()s and desk()s again.
|
|
161
206
|
*/
|
|
162
207
|
private _reseedAfterReconnect;
|
|
163
208
|
private _applyOrdersUpdate;
|
|
164
209
|
private _ensureOpen;
|
|
165
210
|
}
|
|
166
211
|
/**
|
|
167
|
-
* Reader-side handle on a refcounted
|
|
168
|
-
* Flexemarkets.
|
|
169
|
-
* share one underlying
|
|
212
|
+
* Reader-side handle on a refcounted DefaultDesk. Returned by
|
|
213
|
+
* Flexemarkets.desk(); multiple handles for the same marketplaceId
|
|
214
|
+
* share one underlying desk + WS subscription + materialized state.
|
|
170
215
|
* Each handle's close() decrements the shared refcount and tears down
|
|
171
216
|
* the shared resources on the last close.
|
|
172
217
|
*
|
|
@@ -174,22 +219,26 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
174
219
|
* locally and closed when the handle closes — so a handler doesn't
|
|
175
220
|
* keep firing into stale state after the handle is gone.
|
|
176
221
|
*/
|
|
177
|
-
export declare class
|
|
222
|
+
export declare class DeskHandle implements Desk {
|
|
178
223
|
private readonly _shared;
|
|
179
224
|
private readonly _onClose;
|
|
180
225
|
private readonly _mySubscriptions;
|
|
181
226
|
private _closed;
|
|
182
|
-
constructor(shared:
|
|
227
|
+
constructor(shared: DefaultDesk, onClose: () => void);
|
|
183
228
|
get marketplaceId(): number;
|
|
184
229
|
get markets(): Market[];
|
|
185
|
-
|
|
230
|
+
book(marketId: number): Book | null;
|
|
231
|
+
tape(marketId: number): Tape | null;
|
|
232
|
+
books(): Book[];
|
|
233
|
+
tapes(): Tape[];
|
|
186
234
|
session(): Session | null;
|
|
187
235
|
holding(): Holding | null;
|
|
188
236
|
onSessionChange(handler: (s: Session) => void): Subscription;
|
|
189
|
-
|
|
237
|
+
onBookChange(marketId: number, handler: (b: Book) => void): Subscription;
|
|
238
|
+
onTrade(marketId: number, handler: (t: Trade) => void): Subscription;
|
|
190
239
|
onHoldingChange(handler: (h: Holding) => void): Subscription;
|
|
191
240
|
onGap(handler: (e: GapEvent) => void): Subscription;
|
|
192
|
-
|
|
241
|
+
onRecovery(handler: (e: DeskRecovery) => void): Subscription;
|
|
193
242
|
submitLimit(marketId: number, side: string, units: number, price: number): Promise<Order>;
|
|
194
243
|
submitCancel(marketId: number, originalId: number): Promise<Order>;
|
|
195
244
|
close(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Desk — always-current state for a single marketplace, hiding
|
|
3
3
|
* transport details (WebSocket subscribe, snapshot+delta
|
|
4
4
|
* reconciliation, sequence-gap recovery, reconnect) behind a small
|
|
5
5
|
* read-side surface. Mirrors the Java + Python SDKs; same staged
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* existing listen() / callback pipe. No reconciliation, no
|
|
10
10
|
* snapshot seed, no sharing, no reconnect — those land in Phase 2.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { BookIndex } from "./orderbook.js";
|
|
13
|
+
import { TapeIndex } from "./trades.js";
|
|
14
14
|
import { NO_SEQ } from "./stomp.js";
|
|
15
|
-
export class
|
|
15
|
+
export class DefaultDesk {
|
|
16
16
|
marketplaceId;
|
|
17
17
|
markets;
|
|
18
18
|
_flexemarkets;
|
|
19
|
-
|
|
19
|
+
_books;
|
|
20
20
|
_trades;
|
|
21
21
|
_events = null;
|
|
22
22
|
_session = null;
|
|
@@ -24,11 +24,12 @@ export class DefaultMarketView {
|
|
|
24
24
|
_sessionHandlers = [];
|
|
25
25
|
_holdingHandlers = [];
|
|
26
26
|
_bookHandlers = [];
|
|
27
|
+
_tradeHandlers = [];
|
|
27
28
|
_gapHandlers = [];
|
|
28
29
|
_reconnectHandlers = [];
|
|
29
30
|
_closed = false;
|
|
30
31
|
/**
|
|
31
|
-
* Highest ORDERS-UPDATE seq this
|
|
32
|
+
* Highest ORDERS-UPDATE seq this desk has applied so far. Deltas
|
|
32
33
|
* with `seq <= _lastAppliedSeq` are skipped — they've already been
|
|
33
34
|
* folded into the local state via the initial REST snapshot or a
|
|
34
35
|
* previously-applied delta. Initial value comes from the snapshot's
|
|
@@ -37,7 +38,7 @@ export class DefaultMarketView {
|
|
|
37
38
|
_lastAppliedSeq = NO_SEQ;
|
|
38
39
|
static async open(flexemarkets, marketplaceId) {
|
|
39
40
|
const markets = await flexemarkets.markets(marketplaceId);
|
|
40
|
-
const
|
|
41
|
+
const desk = new DefaultDesk(flexemarkets, marketplaceId, markets);
|
|
41
42
|
// Subscribe WS first (so deltas start buffering on the callback
|
|
42
43
|
// path), then fetch + apply the snapshot, only THEN allow live
|
|
43
44
|
// dispatch. _seedFromSnapshot flips _seedComplete=true atomically
|
|
@@ -45,22 +46,22 @@ export class DefaultMarketView {
|
|
|
45
46
|
//
|
|
46
47
|
// Phase 2d: own the EventListener directly rather than calling
|
|
47
48
|
// flexemarkets.listen() — that would clobber the singleton
|
|
48
|
-
// _eventListener and prevent multiple shared
|
|
49
|
+
// _eventListener and prevent multiple shared desks from
|
|
49
50
|
// coexisting in one Flexemarkets.
|
|
50
|
-
|
|
51
|
-
await
|
|
52
|
-
return
|
|
51
|
+
desk._events = await flexemarkets._connectEvents(marketplaceId, (event) => desk._dispatch(event));
|
|
52
|
+
await desk._seedFromSnapshot();
|
|
53
|
+
return desk;
|
|
53
54
|
}
|
|
54
55
|
_seedComplete = false;
|
|
55
56
|
_seedBuffer = [];
|
|
56
|
-
// 100 matches the default per-market
|
|
57
|
-
//
|
|
57
|
+
// 100 matches the default per-market Tape capacity. Plumb through to
|
|
58
|
+
// desk() later if a caller needs deeper trade scrollback.
|
|
58
59
|
constructor(flexemarkets, marketplaceId, markets) {
|
|
59
60
|
this._flexemarkets = flexemarkets;
|
|
60
61
|
this.marketplaceId = marketplaceId;
|
|
61
62
|
this.markets = markets;
|
|
62
|
-
this.
|
|
63
|
-
this._trades = new
|
|
63
|
+
this._books = new BookIndex(markets);
|
|
64
|
+
this._trades = new TapeIndex(markets, 100);
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
67
|
* Phase 2a snapshot seeding. Fetches the V1 active-orders and
|
|
@@ -81,10 +82,10 @@ export class DefaultMarketView {
|
|
|
81
82
|
// Clear before reseeding so a resync (Phase 2b) doesn't double-add
|
|
82
83
|
// against existing price levels. Initial seed hits empty books so
|
|
83
84
|
// clear() is a no-op there.
|
|
84
|
-
this.
|
|
85
|
+
this._books.clear();
|
|
85
86
|
this._trades.clear();
|
|
86
87
|
if (orders.body.length > 0)
|
|
87
|
-
this.
|
|
88
|
+
this._books.update(orders.body);
|
|
88
89
|
if (trades.body.length > 0)
|
|
89
90
|
this._trades.update(trades.body);
|
|
90
91
|
this._lastAppliedSeq = orders.asOfSeq;
|
|
@@ -99,9 +100,21 @@ export class DefaultMarketView {
|
|
|
99
100
|
for (const update of buffered)
|
|
100
101
|
this._applyOrdersUpdate(update);
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
+
book(marketId) {
|
|
103
104
|
this._ensureOpen();
|
|
104
|
-
return this.
|
|
105
|
+
return this._books.get(marketId) ?? null;
|
|
106
|
+
}
|
|
107
|
+
tape(marketId) {
|
|
108
|
+
this._ensureOpen();
|
|
109
|
+
return this._trades.get(marketId);
|
|
110
|
+
}
|
|
111
|
+
books() {
|
|
112
|
+
this._ensureOpen();
|
|
113
|
+
return [...this._books.collection()];
|
|
114
|
+
}
|
|
115
|
+
tapes() {
|
|
116
|
+
this._ensureOpen();
|
|
117
|
+
return [...this._trades.collection()];
|
|
105
118
|
}
|
|
106
119
|
session() {
|
|
107
120
|
this._ensureOpen();
|
|
@@ -120,7 +133,17 @@ export class DefaultMarketView {
|
|
|
120
133
|
this._sessionHandlers.splice(i, 1);
|
|
121
134
|
};
|
|
122
135
|
}
|
|
123
|
-
|
|
136
|
+
onTrade(marketId, handler) {
|
|
137
|
+
this._ensureOpen();
|
|
138
|
+
const entry = { marketId, handler };
|
|
139
|
+
this._tradeHandlers.push(entry);
|
|
140
|
+
return () => {
|
|
141
|
+
const i = this._tradeHandlers.indexOf(entry);
|
|
142
|
+
if (i >= 0)
|
|
143
|
+
this._tradeHandlers.splice(i, 1);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
onBookChange(marketId, handler) {
|
|
124
147
|
this._ensureOpen();
|
|
125
148
|
const entry = { marketId, handler };
|
|
126
149
|
this._bookHandlers.push(entry);
|
|
@@ -148,7 +171,7 @@ export class DefaultMarketView {
|
|
|
148
171
|
this._gapHandlers.splice(i, 1);
|
|
149
172
|
};
|
|
150
173
|
}
|
|
151
|
-
|
|
174
|
+
onRecovery(handler) {
|
|
152
175
|
this._ensureOpen();
|
|
153
176
|
this._reconnectHandlers.push(handler);
|
|
154
177
|
return () => {
|
|
@@ -177,7 +200,7 @@ export class DefaultMarketView {
|
|
|
177
200
|
this._events = null;
|
|
178
201
|
}
|
|
179
202
|
// Flexemarkets is owned by the caller; we don't close it. If
|
|
180
|
-
//
|
|
203
|
+
// desk() was the only consumer, the caller can close
|
|
181
204
|
// Flexemarkets themselves.
|
|
182
205
|
}
|
|
183
206
|
_resyncInFlight = false;
|
|
@@ -199,7 +222,7 @@ export class DefaultMarketView {
|
|
|
199
222
|
this._lastAppliedSeq !== NO_SEQ &&
|
|
200
223
|
event.seq > this._lastAppliedSeq + 1) {
|
|
201
224
|
const expectedSeq = this._lastAppliedSeq + 1;
|
|
202
|
-
console.warn(`[
|
|
225
|
+
console.warn(`[Desk] ORDERS-UPDATE seq gap on marketplace ${this.marketplaceId} ` +
|
|
203
226
|
`— expected ${expectedSeq}, got ${event.seq}; resyncing from snapshot`);
|
|
204
227
|
const gap = {
|
|
205
228
|
marketplaceId: this.marketplaceId,
|
|
@@ -237,7 +260,7 @@ export class DefaultMarketView {
|
|
|
237
260
|
}
|
|
238
261
|
if (_isStreamDropped(event)) {
|
|
239
262
|
// The subscription restores itself; nothing to do but say so.
|
|
240
|
-
console.warn(`[
|
|
263
|
+
console.warn(`[Desk] WS transport error on marketplace ${this.marketplaceId}: ${event.exception.message}`);
|
|
241
264
|
return;
|
|
242
265
|
}
|
|
243
266
|
if (_isReconnected(event)) {
|
|
@@ -247,8 +270,8 @@ export class DefaultMarketView {
|
|
|
247
270
|
if (_isFrameUnreadable(event)) {
|
|
248
271
|
// STOMP ERROR / parse failure. Logged for visibility;
|
|
249
272
|
// reconnecting won't help with a malformed frame, so we leave
|
|
250
|
-
// the
|
|
251
|
-
console.warn(`[
|
|
273
|
+
// the desk as-is.
|
|
274
|
+
console.warn(`[Desk] WS error on marketplace ${this.marketplaceId}: ${event.command} ${event.body}`);
|
|
252
275
|
return;
|
|
253
276
|
}
|
|
254
277
|
// VERSION, SESSION-LIST — not reflected in the public surface yet.
|
|
@@ -256,12 +279,12 @@ export class DefaultMarketView {
|
|
|
256
279
|
/**
|
|
257
280
|
* Re-seed once the transport is back.
|
|
258
281
|
*
|
|
259
|
-
* Reconnecting is not this layer's job -- a `
|
|
282
|
+
* Reconnecting is not this layer's job -- a `StreamReconnected` only arrives
|
|
260
283
|
* because the listener already restored the subscription. Reseeding is: a
|
|
261
284
|
* reconnect is the largest possible sequence gap, so _seedFromSnapshot()
|
|
262
285
|
* (clear + REST snapshot + reapply + seq watermark) is what converges the
|
|
263
|
-
* state, exactly as it does for a small one. If it fails the
|
|
264
|
-
* stale until the caller close()s and
|
|
286
|
+
* state, exactly as it does for a small one. If it fails the desk is left
|
|
287
|
+
* stale until the caller close()s and desk()s again.
|
|
265
288
|
*/
|
|
266
289
|
_reseedAfterReconnect() {
|
|
267
290
|
if (this._resyncInFlight)
|
|
@@ -276,11 +299,11 @@ export class DefaultMarketView {
|
|
|
276
299
|
}
|
|
277
300
|
catch (err) {
|
|
278
301
|
const reason = err instanceof Error ? err.message : String(err);
|
|
279
|
-
console.error(`[
|
|
302
|
+
console.error(`[Desk] Reconnect failed on marketplace ${this.marketplaceId}; desk is stale: ${reason}`);
|
|
280
303
|
outcome = { marketplaceId: this.marketplaceId, success: false, reason };
|
|
281
304
|
// Leave _resyncInFlight=true so subsequent dispatches keep
|
|
282
305
|
// buffering rather than corrupting state; caller can close()
|
|
283
|
-
// and
|
|
306
|
+
// and desk() to recover.
|
|
284
307
|
}
|
|
285
308
|
for (const h of this._reconnectHandlers) {
|
|
286
309
|
try {
|
|
@@ -301,10 +324,21 @@ export class DefaultMarketView {
|
|
|
301
324
|
}
|
|
302
325
|
const orders = update.orders;
|
|
303
326
|
const touched = _marketIdsTouched(orders);
|
|
304
|
-
this.
|
|
305
|
-
this._trades.update(orders);
|
|
327
|
+
this._books.update(orders);
|
|
328
|
+
const traded = this._trades.update(orders);
|
|
329
|
+
// Tape first: the more specific event, and a book handler that then reads
|
|
330
|
+
// the tape sees the same trade the trade handler was just given. Both
|
|
331
|
+
// aggregators are already current either way — what is ordered here is only
|
|
332
|
+
// which handler hears about it first.
|
|
333
|
+
for (const [marketId, fresh] of traded) {
|
|
334
|
+
for (const h of this._tradeHandlers) {
|
|
335
|
+
if (h.marketId === marketId)
|
|
336
|
+
for (const trade of fresh)
|
|
337
|
+
h.handler(trade);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
306
340
|
for (const marketId of touched) {
|
|
307
|
-
const book = this.
|
|
341
|
+
const book = this._books.get(marketId);
|
|
308
342
|
if (!book)
|
|
309
343
|
continue;
|
|
310
344
|
for (const h of this._bookHandlers) {
|
|
@@ -317,7 +351,7 @@ export class DefaultMarketView {
|
|
|
317
351
|
}
|
|
318
352
|
_ensureOpen() {
|
|
319
353
|
if (this._closed) {
|
|
320
|
-
throw new Error(`
|
|
354
|
+
throw new Error(`Desk for marketplace ${this.marketplaceId} is closed`);
|
|
321
355
|
}
|
|
322
356
|
}
|
|
323
357
|
}
|
|
@@ -346,9 +380,9 @@ function _isFrameUnreadable(event) {
|
|
|
346
380
|
return typeof event === "object" && event !== null && event.kind === "frame-unreadable";
|
|
347
381
|
}
|
|
348
382
|
/**
|
|
349
|
-
* Reader-side handle on a refcounted
|
|
350
|
-
* Flexemarkets.
|
|
351
|
-
* share one underlying
|
|
383
|
+
* Reader-side handle on a refcounted DefaultDesk. Returned by
|
|
384
|
+
* Flexemarkets.desk(); multiple handles for the same marketplaceId
|
|
385
|
+
* share one underlying desk + WS subscription + materialized state.
|
|
352
386
|
* Each handle's close() decrements the shared refcount and tears down
|
|
353
387
|
* the shared resources on the last close.
|
|
354
388
|
*
|
|
@@ -356,7 +390,7 @@ function _isFrameUnreadable(event) {
|
|
|
356
390
|
* locally and closed when the handle closes — so a handler doesn't
|
|
357
391
|
* keep firing into stale state after the handle is gone.
|
|
358
392
|
*/
|
|
359
|
-
export class
|
|
393
|
+
export class DeskHandle {
|
|
360
394
|
_shared;
|
|
361
395
|
_onClose;
|
|
362
396
|
_mySubscriptions = [];
|
|
@@ -372,9 +406,21 @@ export class MarketViewHandle {
|
|
|
372
406
|
this._check();
|
|
373
407
|
return this._shared.markets;
|
|
374
408
|
}
|
|
375
|
-
|
|
409
|
+
book(marketId) {
|
|
410
|
+
this._check();
|
|
411
|
+
return this._shared.book(marketId);
|
|
412
|
+
}
|
|
413
|
+
tape(marketId) {
|
|
414
|
+
this._check();
|
|
415
|
+
return this._shared.tape(marketId);
|
|
416
|
+
}
|
|
417
|
+
books() {
|
|
376
418
|
this._check();
|
|
377
|
-
return this._shared.
|
|
419
|
+
return this._shared.books();
|
|
420
|
+
}
|
|
421
|
+
tapes() {
|
|
422
|
+
this._check();
|
|
423
|
+
return this._shared.tapes();
|
|
378
424
|
}
|
|
379
425
|
session() {
|
|
380
426
|
this._check();
|
|
@@ -390,9 +436,15 @@ export class MarketViewHandle {
|
|
|
390
436
|
this._mySubscriptions.push(sub);
|
|
391
437
|
return sub;
|
|
392
438
|
}
|
|
393
|
-
|
|
439
|
+
onBookChange(marketId, handler) {
|
|
440
|
+
this._check();
|
|
441
|
+
const sub = this._shared.onBookChange(marketId, handler);
|
|
442
|
+
this._mySubscriptions.push(sub);
|
|
443
|
+
return sub;
|
|
444
|
+
}
|
|
445
|
+
onTrade(marketId, handler) {
|
|
394
446
|
this._check();
|
|
395
|
-
const sub = this._shared.
|
|
447
|
+
const sub = this._shared.onTrade(marketId, handler);
|
|
396
448
|
this._mySubscriptions.push(sub);
|
|
397
449
|
return sub;
|
|
398
450
|
}
|
|
@@ -408,9 +460,9 @@ export class MarketViewHandle {
|
|
|
408
460
|
this._mySubscriptions.push(sub);
|
|
409
461
|
return sub;
|
|
410
462
|
}
|
|
411
|
-
|
|
463
|
+
onRecovery(handler) {
|
|
412
464
|
this._check();
|
|
413
|
-
const sub = this._shared.
|
|
465
|
+
const sub = this._shared.onRecovery(handler);
|
|
414
466
|
this._mySubscriptions.push(sub);
|
|
415
467
|
return sub;
|
|
416
468
|
}
|
|
@@ -440,8 +492,8 @@ export class MarketViewHandle {
|
|
|
440
492
|
}
|
|
441
493
|
_check() {
|
|
442
494
|
if (this._closed) {
|
|
443
|
-
throw new Error(`
|
|
495
|
+
throw new Error(`Desk handle for marketplace ${this._shared.marketplaceId} is closed`);
|
|
444
496
|
}
|
|
445
497
|
}
|
|
446
498
|
}
|
|
447
|
-
//# sourceMappingURL=
|
|
499
|
+
//# sourceMappingURL=desk.js.map
|
package/dist/desk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"desk.js","sourceRoot":"","sources":["../src/desk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAQ,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAyH,MAAM,YAAY,CAAC;AAiJ3J,MAAM,OAAO,WAAW;IACb,aAAa,CAAS;IACtB,OAAO,CAAW;IAEV,aAAa,CAAe;IAC5B,MAAM,CAAY;IAClB,OAAO,CAAY;IAC5B,OAAO,GAAyB,IAAI,CAAC;IACrC,QAAQ,GAAmB,IAAI,CAAC;IAChC,QAAQ,GAAmB,IAAI,CAAC;IAEvB,gBAAgB,GAAgC,EAAE,CAAC;IACnD,gBAAgB,GAAgC,EAAE,CAAC;IACnD,aAAa,GAA4D,EAAE,CAAC;IAC5E,cAAc,GAA6D,EAAE,CAAC;IAC9E,YAAY,GAAiC,EAAE,CAAC;IAChD,kBAAkB,GAAqC,EAAE,CAAC;IAEnE,OAAO,GAAG,KAAK,CAAC;IAExB;;;;;;OAMG;IACK,eAAe,GAAW,MAAM,CAAC;IAEzC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,YAA0B,EAAE,aAAqB;QACjE,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QACnE,gEAAgE;QAChE,+DAA+D;QAC/D,kEAAkE;QAClE,iDAAiD;QACjD,EAAE;QACF,+DAA+D;QAC/D,2DAA2D;QAC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E,CAAC;YACxC,IAAI,CAAC;gBAAC,GAAG,EAAE,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;IAEO,MAAM;QACZ,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,OAAO,CAAC,aAAa,YAAY,CAAC,CAAC;QACzF,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/** Flexemarkets TypeScript SDK. */
|
|
2
|
-
export type { Person, Account, Token, Security, Holding, Market, Marketplace, Session, Order, ClientConnection, TickGrid, Version, ConflictFailure, } from "./types.js";
|
|
3
|
-
export {
|
|
2
|
+
export type { Person, Account, Allotment, Assets, ManagerOtpBundle, Token, Security, Holding, Market, Marketplace, Session, Order, ClientConnection, TickGrid, Version, ConflictFailure, } from "./types.js";
|
|
3
|
+
export { OrderSide, OrderType, toSide, toOrderType, SESSION_STATE_INIT, SESSION_STATE_OPEN, SESSION_STATE_PAUSED, SESSION_STATE_CLOSED, getSecurity, isApproved, orderedSecurities, holdingUnits, priceRound, unitRound, tickRound, gridRound, unitGrid, displayName, } from "./types.js";
|
|
4
4
|
export { Flexemarkets, FlexemarketsError, AuthenticationError, AuthorizationError, InvalidArgumentError, ConnectionFailedError, ConfigurationError, ConflictError, HttpError, ApiError, AccountNameConflictError, PersonHasMarketplaceDataError, } from "./client.js";
|
|
5
5
|
export { toInstant } from "./timestamps.js";
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export type {
|
|
10
|
-
export type {
|
|
6
|
+
export { contra, findOrder, isAvailable, isConsumed, isConsumedOrSplit, isResting, isSplit, isSubmit, isSupplier, isSymbol, limit, } from "./order-utils.js";
|
|
7
|
+
export { Book } from "./orderbook.js";
|
|
8
|
+
export { Tape, tradeOf } from "./trades.js";
|
|
9
|
+
export type { Trade } from "./trades.js";
|
|
10
|
+
export type { StompFrame, StreamDropped, StreamReconnected, FrameUnreadable, FmEvent, EventCallback, } from "./stomp.js";
|
|
11
|
+
export type { Desk, Subscription, GapEvent, DeskRecovery } from "./desk.js";
|
|
11
12
|
export type { Snapshot } from "./snapshot.js";
|
|
12
13
|
export { NO_SEQ } from "./stomp.js";
|
|
13
14
|
export type { OrdersUpdate } from "./stomp.js";
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
/** Flexemarkets TypeScript SDK. */
|
|
2
|
-
export {
|
|
2
|
+
export { OrderSide, OrderType, toSide, toOrderType, SESSION_STATE_INIT, SESSION_STATE_OPEN, SESSION_STATE_PAUSED, SESSION_STATE_CLOSED, getSecurity, isApproved, orderedSecurities, holdingUnits, priceRound, unitRound, tickRound, gridRound, unitGrid, displayName, } from "./types.js";
|
|
3
3
|
// Client
|
|
4
4
|
export { Flexemarkets, FlexemarketsError, AuthenticationError, AuthorizationError, InvalidArgumentError, ConnectionFailedError, ConfigurationError, ConflictError, HttpError, ApiError, AccountNameConflictError, PersonHasMarketplaceDataError, } from "./client.js";
|
|
5
5
|
export { toInstant } from "./timestamps.js";
|
|
6
|
-
// Order utils
|
|
7
|
-
|
|
6
|
+
// Order utils -- what can only be worked out from a set of orders together.
|
|
7
|
+
//
|
|
8
|
+
// isBuy, isSell, isCancel and isLimit are deliberately not here. They became
|
|
9
|
+
// one-line comparisons the moment side and type became enums: OrderSide.BUY ===
|
|
10
|
+
// order.side says the same thing as isBuy(order), reads the same way, and is
|
|
11
|
+
// one fewer name to know. Java deleted them outright; they survive here only
|
|
12
|
+
// because this SDK's own code uses them, where Java's did not.
|
|
13
|
+
//
|
|
14
|
+
// contra stays: OrderSide is a string union in TypeScript, so unlike Java and
|
|
15
|
+
// Python it cannot carry the method that replaced this.
|
|
16
|
+
export { contra, findOrder, isAvailable, isConsumed, isConsumedOrSplit, isResting, isSplit, isSubmit, isSupplier, isSymbol, limit, } from "./order-utils.js";
|
|
8
17
|
// Order book
|
|
9
|
-
export {
|
|
10
|
-
//
|
|
11
|
-
export {
|
|
18
|
+
export { Book } from "./orderbook.js";
|
|
19
|
+
// Tape
|
|
20
|
+
export { Tape, tradeOf } from "./trades.js";
|
|
12
21
|
export { NO_SEQ } from "./stomp.js";
|
|
13
22
|
//# sourceMappingURL=index.js.map
|