@flexemarkets/fm-sdk 0.1.4 → 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 +15 -15
- package/dist/client.js +38 -28
- package/dist/client.js.map +1 -1
- package/dist/{market-view.d.ts → desk.d.ts} +57 -43
- package/dist/{market-view.js → desk.js} +66 -50
- package/dist/desk.js.map +1 -0
- package/dist/index.d.ts +7 -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 +22 -9
- 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 +12 -12
- package/dist/trades.js +11 -11
- package/dist/trades.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -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,18 +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 {
|
|
14
|
-
import { type Trade, type
|
|
13
|
+
import { Book } from "./orderbook.js";
|
|
14
|
+
import { type Trade, type Tape } from "./trades.js";
|
|
15
15
|
import type { Holding, Market, Order, Session } from "./types.js";
|
|
16
16
|
/**
|
|
17
|
-
* Handle returned by `
|
|
17
|
+
* Handle returned by `Desk.on*` listener registrations. Call
|
|
18
18
|
* to unregister. Idempotent — multiple calls are no-ops.
|
|
19
19
|
*/
|
|
20
20
|
export type Subscription = () => void;
|
|
21
21
|
/**
|
|
22
|
-
* Fires when
|
|
22
|
+
* Fires when Desk detects a sequence-gap in the ORDERS-UPDATE
|
|
23
23
|
* WS stream — one or more frames were dropped between client and
|
|
24
|
-
* fm-server. After a gap,
|
|
24
|
+
* fm-server. After a gap, Desk re-runs the REST snapshot
|
|
25
25
|
* recovery flow before applying further deltas; the gap event is the
|
|
26
26
|
* signal callers can wire into their own observability stack instead
|
|
27
27
|
* of relying on the SDK's default console.warn.
|
|
@@ -32,36 +32,46 @@ export interface GapEvent {
|
|
|
32
32
|
readonly receivedSeq: number;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* Fires when
|
|
35
|
+
* Fires when Desk reacts to a StreamDropped — either after
|
|
36
36
|
* the reconnect + resnapshot completes successfully, or after the
|
|
37
|
-
* attempt has failed and the
|
|
37
|
+
* attempt has failed and the desk is left stale.
|
|
38
38
|
*/
|
|
39
|
-
export interface
|
|
39
|
+
export interface DeskRecovery {
|
|
40
40
|
readonly marketplaceId: number;
|
|
41
41
|
readonly success: boolean;
|
|
42
42
|
readonly reason: string | null;
|
|
43
43
|
}
|
|
44
|
-
export interface
|
|
45
|
-
/** The marketplace this
|
|
44
|
+
export interface Desk {
|
|
45
|
+
/** The marketplace this desk tracks. */
|
|
46
46
|
readonly marketplaceId: number;
|
|
47
|
-
/** Markets in this marketplace, captured
|
|
47
|
+
/** Markets in this marketplace, captured when the desk was opened. */
|
|
48
48
|
readonly markets: Market[];
|
|
49
49
|
/**
|
|
50
50
|
* Always-current order book for `marketId`. Reads are atomic; a
|
|
51
51
|
* caller never sees a half-applied delta. Returns null if
|
|
52
52
|
* `marketId` isn't in this marketplace.
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
book(marketId: number): Book | null;
|
|
55
55
|
/**
|
|
56
56
|
* Always-current trade tape for `marketId`, most recent last. Returns null
|
|
57
57
|
* if `marketId` isn't in this marketplace.
|
|
58
58
|
*
|
|
59
|
-
* Maintained alongside {@link
|
|
60
|
-
* trades when the
|
|
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
61
|
* Each `Trade` on it carries both sides of its match — the resting
|
|
62
62
|
* order that was taken and the aggressor that took it.
|
|
63
63
|
*/
|
|
64
|
-
|
|
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[];
|
|
65
75
|
/**
|
|
66
76
|
* Most-recent session update observed. Null until the first
|
|
67
77
|
* SESSION-UPDATE frame lands.
|
|
@@ -78,30 +88,30 @@ export interface MarketView {
|
|
|
78
88
|
* Register a handler that fires when the order book for
|
|
79
89
|
* `marketId` changes. The handler receives the post-update book.
|
|
80
90
|
*/
|
|
81
|
-
|
|
91
|
+
onBookChange(marketId: number, handler: (b: Book) => void): Subscription;
|
|
82
92
|
/**
|
|
83
93
|
* Register a handler that fires for each trade on `marketId`.
|
|
84
94
|
*
|
|
85
|
-
* The missing member of the family {@link
|
|
95
|
+
* The missing member of the family {@link onBookChange} and
|
|
86
96
|
* {@link onSessionChange} belong to. Without it, "tell me when a trade
|
|
87
97
|
* happens" is asked as "tell me when the book changed, then let me look" —
|
|
88
98
|
* which answers a different question, since a book changes on every resting
|
|
89
99
|
* order and most changes are not trades.
|
|
90
100
|
*
|
|
91
101
|
* Fires **once per trade**, oldest first, rather than coalescing a batch the
|
|
92
|
-
* way {@link
|
|
102
|
+
* way {@link onBookChange} does. A trade is a discrete event with its own
|
|
93
103
|
* price and counterparties; collapsing two into one callback would lose one.
|
|
94
104
|
*
|
|
95
105
|
* Live deltas only. A gap or a reconnect re-seeds the tape from the server's
|
|
96
106
|
* snapshot, and those trades do not fire here — they are not new, they are
|
|
97
|
-
* what was missed. {@link onGap} and {@link
|
|
107
|
+
* what was missed. {@link onGap} and {@link onRecovery} are how a caller
|
|
98
108
|
* learns that happened.
|
|
99
109
|
*/
|
|
100
110
|
onTrade(marketId: number, handler: (t: Trade) => void): Subscription;
|
|
101
111
|
/** Register a handler for the caller's holding changes. */
|
|
102
112
|
onHoldingChange(handler: (h: Holding) => void): Subscription;
|
|
103
113
|
/**
|
|
104
|
-
* Register a handler that fires when
|
|
114
|
+
* Register a handler that fires when Desk detects a gap in
|
|
105
115
|
* the ORDERS-UPDATE seq stream. Use this to wire your own
|
|
106
116
|
* telemetry — by default the SDK logs to console.warn but
|
|
107
117
|
* otherwise hides the recovery flow.
|
|
@@ -110,10 +120,10 @@ export interface MarketView {
|
|
|
110
120
|
/**
|
|
111
121
|
* Register a handler that fires after the SDK reacts to a
|
|
112
122
|
* transport error — either when reconnect + resnapshot have
|
|
113
|
-
* completed, or when the attempt has failed and the
|
|
123
|
+
* completed, or when the attempt has failed and the desk is left
|
|
114
124
|
* stale.
|
|
115
125
|
*/
|
|
116
|
-
|
|
126
|
+
onRecovery(handler: (event: DeskRecovery) => void): Subscription;
|
|
117
127
|
/** Submit a limit order on this marketplace. */
|
|
118
128
|
submitLimit(marketId: number, side: string, units: number, price: number): Promise<Order>;
|
|
119
129
|
/** Cancel a previously-submitted order. */
|
|
@@ -125,11 +135,11 @@ export interface MarketView {
|
|
|
125
135
|
*/
|
|
126
136
|
close(): void;
|
|
127
137
|
}
|
|
128
|
-
export declare class
|
|
138
|
+
export declare class DefaultDesk implements Desk {
|
|
129
139
|
readonly marketplaceId: number;
|
|
130
140
|
readonly markets: Market[];
|
|
131
141
|
private readonly _flexemarkets;
|
|
132
|
-
private readonly
|
|
142
|
+
private readonly _books;
|
|
133
143
|
private readonly _trades;
|
|
134
144
|
private _events;
|
|
135
145
|
private _session;
|
|
@@ -142,14 +152,14 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
142
152
|
private readonly _reconnectHandlers;
|
|
143
153
|
private _closed;
|
|
144
154
|
/**
|
|
145
|
-
* Highest ORDERS-UPDATE seq this
|
|
155
|
+
* Highest ORDERS-UPDATE seq this desk has applied so far. Deltas
|
|
146
156
|
* with `seq <= _lastAppliedSeq` are skipped — they've already been
|
|
147
157
|
* folded into the local state via the initial REST snapshot or a
|
|
148
158
|
* previously-applied delta. Initial value comes from the snapshot's
|
|
149
159
|
* `asOfSeq`; `NO_SEQ` disables filtering (older fm-server).
|
|
150
160
|
*/
|
|
151
161
|
private _lastAppliedSeq;
|
|
152
|
-
static open(flexemarkets: Flexemarkets, marketplaceId: number): Promise<
|
|
162
|
+
static open(flexemarkets: Flexemarkets, marketplaceId: number): Promise<DefaultDesk>;
|
|
153
163
|
private _seedComplete;
|
|
154
164
|
private _seedBuffer;
|
|
155
165
|
private constructor();
|
|
@@ -167,16 +177,18 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
167
177
|
* Phase 2b (gap recovery + ID-based dedup) closes the window.
|
|
168
178
|
*/
|
|
169
179
|
private _seedFromSnapshot;
|
|
170
|
-
|
|
171
|
-
|
|
180
|
+
book(marketId: number): Book | null;
|
|
181
|
+
tape(marketId: number): Tape | null;
|
|
182
|
+
books(): Book[];
|
|
183
|
+
tapes(): Tape[];
|
|
172
184
|
session(): Session | null;
|
|
173
185
|
holding(): Holding | null;
|
|
174
186
|
onSessionChange(handler: (s: Session) => void): Subscription;
|
|
175
187
|
onTrade(marketId: number, handler: (t: Trade) => void): Subscription;
|
|
176
|
-
|
|
188
|
+
onBookChange(marketId: number, handler: (b: Book) => void): Subscription;
|
|
177
189
|
onHoldingChange(handler: (h: Holding) => void): Subscription;
|
|
178
190
|
onGap(handler: (e: GapEvent) => void): Subscription;
|
|
179
|
-
|
|
191
|
+
onRecovery(handler: (e: DeskRecovery) => void): Subscription;
|
|
180
192
|
submitLimit(marketId: number, side: string, units: number, price: number): Promise<Order>;
|
|
181
193
|
submitCancel(marketId: number, originalId: number): Promise<Order>;
|
|
182
194
|
close(): void;
|
|
@@ -185,21 +197,21 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
185
197
|
/**
|
|
186
198
|
* Re-seed once the transport is back.
|
|
187
199
|
*
|
|
188
|
-
* Reconnecting is not this layer's job -- a `
|
|
200
|
+
* Reconnecting is not this layer's job -- a `StreamReconnected` only arrives
|
|
189
201
|
* because the listener already restored the subscription. Reseeding is: a
|
|
190
202
|
* reconnect is the largest possible sequence gap, so _seedFromSnapshot()
|
|
191
203
|
* (clear + REST snapshot + reapply + seq watermark) is what converges the
|
|
192
|
-
* state, exactly as it does for a small one. If it fails the
|
|
193
|
-
* 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.
|
|
194
206
|
*/
|
|
195
207
|
private _reseedAfterReconnect;
|
|
196
208
|
private _applyOrdersUpdate;
|
|
197
209
|
private _ensureOpen;
|
|
198
210
|
}
|
|
199
211
|
/**
|
|
200
|
-
* Reader-side handle on a refcounted
|
|
201
|
-
* Flexemarkets.
|
|
202
|
-
* 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.
|
|
203
215
|
* Each handle's close() decrements the shared refcount and tears down
|
|
204
216
|
* the shared resources on the last close.
|
|
205
217
|
*
|
|
@@ -207,24 +219,26 @@ export declare class DefaultMarketView implements MarketView {
|
|
|
207
219
|
* locally and closed when the handle closes — so a handler doesn't
|
|
208
220
|
* keep firing into stale state after the handle is gone.
|
|
209
221
|
*/
|
|
210
|
-
export declare class
|
|
222
|
+
export declare class DeskHandle implements Desk {
|
|
211
223
|
private readonly _shared;
|
|
212
224
|
private readonly _onClose;
|
|
213
225
|
private readonly _mySubscriptions;
|
|
214
226
|
private _closed;
|
|
215
|
-
constructor(shared:
|
|
227
|
+
constructor(shared: DefaultDesk, onClose: () => void);
|
|
216
228
|
get marketplaceId(): number;
|
|
217
229
|
get markets(): Market[];
|
|
218
|
-
|
|
219
|
-
|
|
230
|
+
book(marketId: number): Book | null;
|
|
231
|
+
tape(marketId: number): Tape | null;
|
|
232
|
+
books(): Book[];
|
|
233
|
+
tapes(): Tape[];
|
|
220
234
|
session(): Session | null;
|
|
221
235
|
holding(): Holding | null;
|
|
222
236
|
onSessionChange(handler: (s: Session) => void): Subscription;
|
|
223
|
-
|
|
237
|
+
onBookChange(marketId: number, handler: (b: Book) => void): Subscription;
|
|
224
238
|
onTrade(marketId: number, handler: (t: Trade) => void): Subscription;
|
|
225
239
|
onHoldingChange(handler: (h: Holding) => void): Subscription;
|
|
226
240
|
onGap(handler: (e: GapEvent) => void): Subscription;
|
|
227
|
-
|
|
241
|
+
onRecovery(handler: (e: DeskRecovery) => void): Subscription;
|
|
228
242
|
submitLimit(marketId: number, side: string, units: number, price: number): Promise<Order>;
|
|
229
243
|
submitCancel(marketId: number, originalId: number): Promise<Order>;
|
|
230
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;
|
|
@@ -29,7 +29,7 @@ export class DefaultMarketView {
|
|
|
29
29
|
_reconnectHandlers = [];
|
|
30
30
|
_closed = false;
|
|
31
31
|
/**
|
|
32
|
-
* Highest ORDERS-UPDATE seq this
|
|
32
|
+
* Highest ORDERS-UPDATE seq this desk has applied so far. Deltas
|
|
33
33
|
* with `seq <= _lastAppliedSeq` are skipped — they've already been
|
|
34
34
|
* folded into the local state via the initial REST snapshot or a
|
|
35
35
|
* previously-applied delta. Initial value comes from the snapshot's
|
|
@@ -38,7 +38,7 @@ export class DefaultMarketView {
|
|
|
38
38
|
_lastAppliedSeq = NO_SEQ;
|
|
39
39
|
static async open(flexemarkets, marketplaceId) {
|
|
40
40
|
const markets = await flexemarkets.markets(marketplaceId);
|
|
41
|
-
const
|
|
41
|
+
const desk = new DefaultDesk(flexemarkets, marketplaceId, markets);
|
|
42
42
|
// Subscribe WS first (so deltas start buffering on the callback
|
|
43
43
|
// path), then fetch + apply the snapshot, only THEN allow live
|
|
44
44
|
// dispatch. _seedFromSnapshot flips _seedComplete=true atomically
|
|
@@ -46,22 +46,22 @@ export class DefaultMarketView {
|
|
|
46
46
|
//
|
|
47
47
|
// Phase 2d: own the EventListener directly rather than calling
|
|
48
48
|
// flexemarkets.listen() — that would clobber the singleton
|
|
49
|
-
// _eventListener and prevent multiple shared
|
|
49
|
+
// _eventListener and prevent multiple shared desks from
|
|
50
50
|
// coexisting in one Flexemarkets.
|
|
51
|
-
|
|
52
|
-
await
|
|
53
|
-
return
|
|
51
|
+
desk._events = await flexemarkets._connectEvents(marketplaceId, (event) => desk._dispatch(event));
|
|
52
|
+
await desk._seedFromSnapshot();
|
|
53
|
+
return desk;
|
|
54
54
|
}
|
|
55
55
|
_seedComplete = false;
|
|
56
56
|
_seedBuffer = [];
|
|
57
|
-
// 100 matches the default per-market
|
|
58
|
-
//
|
|
57
|
+
// 100 matches the default per-market Tape capacity. Plumb through to
|
|
58
|
+
// desk() later if a caller needs deeper trade scrollback.
|
|
59
59
|
constructor(flexemarkets, marketplaceId, markets) {
|
|
60
60
|
this._flexemarkets = flexemarkets;
|
|
61
61
|
this.marketplaceId = marketplaceId;
|
|
62
62
|
this.markets = markets;
|
|
63
|
-
this.
|
|
64
|
-
this._trades = new
|
|
63
|
+
this._books = new BookIndex(markets);
|
|
64
|
+
this._trades = new TapeIndex(markets, 100);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Phase 2a snapshot seeding. Fetches the V1 active-orders and
|
|
@@ -82,10 +82,10 @@ export class DefaultMarketView {
|
|
|
82
82
|
// Clear before reseeding so a resync (Phase 2b) doesn't double-add
|
|
83
83
|
// against existing price levels. Initial seed hits empty books so
|
|
84
84
|
// clear() is a no-op there.
|
|
85
|
-
this.
|
|
85
|
+
this._books.clear();
|
|
86
86
|
this._trades.clear();
|
|
87
87
|
if (orders.body.length > 0)
|
|
88
|
-
this.
|
|
88
|
+
this._books.update(orders.body);
|
|
89
89
|
if (trades.body.length > 0)
|
|
90
90
|
this._trades.update(trades.body);
|
|
91
91
|
this._lastAppliedSeq = orders.asOfSeq;
|
|
@@ -100,14 +100,22 @@ export class DefaultMarketView {
|
|
|
100
100
|
for (const update of buffered)
|
|
101
101
|
this._applyOrdersUpdate(update);
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
book(marketId) {
|
|
104
104
|
this._ensureOpen();
|
|
105
|
-
return this.
|
|
105
|
+
return this._books.get(marketId) ?? null;
|
|
106
106
|
}
|
|
107
|
-
|
|
107
|
+
tape(marketId) {
|
|
108
108
|
this._ensureOpen();
|
|
109
109
|
return this._trades.get(marketId);
|
|
110
110
|
}
|
|
111
|
+
books() {
|
|
112
|
+
this._ensureOpen();
|
|
113
|
+
return [...this._books.collection()];
|
|
114
|
+
}
|
|
115
|
+
tapes() {
|
|
116
|
+
this._ensureOpen();
|
|
117
|
+
return [...this._trades.collection()];
|
|
118
|
+
}
|
|
111
119
|
session() {
|
|
112
120
|
this._ensureOpen();
|
|
113
121
|
return this._session;
|
|
@@ -135,7 +143,7 @@ export class DefaultMarketView {
|
|
|
135
143
|
this._tradeHandlers.splice(i, 1);
|
|
136
144
|
};
|
|
137
145
|
}
|
|
138
|
-
|
|
146
|
+
onBookChange(marketId, handler) {
|
|
139
147
|
this._ensureOpen();
|
|
140
148
|
const entry = { marketId, handler };
|
|
141
149
|
this._bookHandlers.push(entry);
|
|
@@ -163,7 +171,7 @@ export class DefaultMarketView {
|
|
|
163
171
|
this._gapHandlers.splice(i, 1);
|
|
164
172
|
};
|
|
165
173
|
}
|
|
166
|
-
|
|
174
|
+
onRecovery(handler) {
|
|
167
175
|
this._ensureOpen();
|
|
168
176
|
this._reconnectHandlers.push(handler);
|
|
169
177
|
return () => {
|
|
@@ -192,7 +200,7 @@ export class DefaultMarketView {
|
|
|
192
200
|
this._events = null;
|
|
193
201
|
}
|
|
194
202
|
// Flexemarkets is owned by the caller; we don't close it. If
|
|
195
|
-
//
|
|
203
|
+
// desk() was the only consumer, the caller can close
|
|
196
204
|
// Flexemarkets themselves.
|
|
197
205
|
}
|
|
198
206
|
_resyncInFlight = false;
|
|
@@ -214,7 +222,7 @@ export class DefaultMarketView {
|
|
|
214
222
|
this._lastAppliedSeq !== NO_SEQ &&
|
|
215
223
|
event.seq > this._lastAppliedSeq + 1) {
|
|
216
224
|
const expectedSeq = this._lastAppliedSeq + 1;
|
|
217
|
-
console.warn(`[
|
|
225
|
+
console.warn(`[Desk] ORDERS-UPDATE seq gap on marketplace ${this.marketplaceId} ` +
|
|
218
226
|
`— expected ${expectedSeq}, got ${event.seq}; resyncing from snapshot`);
|
|
219
227
|
const gap = {
|
|
220
228
|
marketplaceId: this.marketplaceId,
|
|
@@ -252,7 +260,7 @@ export class DefaultMarketView {
|
|
|
252
260
|
}
|
|
253
261
|
if (_isStreamDropped(event)) {
|
|
254
262
|
// The subscription restores itself; nothing to do but say so.
|
|
255
|
-
console.warn(`[
|
|
263
|
+
console.warn(`[Desk] WS transport error on marketplace ${this.marketplaceId}: ${event.exception.message}`);
|
|
256
264
|
return;
|
|
257
265
|
}
|
|
258
266
|
if (_isReconnected(event)) {
|
|
@@ -262,8 +270,8 @@ export class DefaultMarketView {
|
|
|
262
270
|
if (_isFrameUnreadable(event)) {
|
|
263
271
|
// STOMP ERROR / parse failure. Logged for visibility;
|
|
264
272
|
// reconnecting won't help with a malformed frame, so we leave
|
|
265
|
-
// the
|
|
266
|
-
console.warn(`[
|
|
273
|
+
// the desk as-is.
|
|
274
|
+
console.warn(`[Desk] WS error on marketplace ${this.marketplaceId}: ${event.command} ${event.body}`);
|
|
267
275
|
return;
|
|
268
276
|
}
|
|
269
277
|
// VERSION, SESSION-LIST — not reflected in the public surface yet.
|
|
@@ -271,12 +279,12 @@ export class DefaultMarketView {
|
|
|
271
279
|
/**
|
|
272
280
|
* Re-seed once the transport is back.
|
|
273
281
|
*
|
|
274
|
-
* Reconnecting is not this layer's job -- a `
|
|
282
|
+
* Reconnecting is not this layer's job -- a `StreamReconnected` only arrives
|
|
275
283
|
* because the listener already restored the subscription. Reseeding is: a
|
|
276
284
|
* reconnect is the largest possible sequence gap, so _seedFromSnapshot()
|
|
277
285
|
* (clear + REST snapshot + reapply + seq watermark) is what converges the
|
|
278
|
-
* state, exactly as it does for a small one. If it fails the
|
|
279
|
-
* 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.
|
|
280
288
|
*/
|
|
281
289
|
_reseedAfterReconnect() {
|
|
282
290
|
if (this._resyncInFlight)
|
|
@@ -291,11 +299,11 @@ export class DefaultMarketView {
|
|
|
291
299
|
}
|
|
292
300
|
catch (err) {
|
|
293
301
|
const reason = err instanceof Error ? err.message : String(err);
|
|
294
|
-
console.error(`[
|
|
302
|
+
console.error(`[Desk] Reconnect failed on marketplace ${this.marketplaceId}; desk is stale: ${reason}`);
|
|
295
303
|
outcome = { marketplaceId: this.marketplaceId, success: false, reason };
|
|
296
304
|
// Leave _resyncInFlight=true so subsequent dispatches keep
|
|
297
305
|
// buffering rather than corrupting state; caller can close()
|
|
298
|
-
// and
|
|
306
|
+
// and desk() to recover.
|
|
299
307
|
}
|
|
300
308
|
for (const h of this._reconnectHandlers) {
|
|
301
309
|
try {
|
|
@@ -316,9 +324,9 @@ export class DefaultMarketView {
|
|
|
316
324
|
}
|
|
317
325
|
const orders = update.orders;
|
|
318
326
|
const touched = _marketIdsTouched(orders);
|
|
319
|
-
this.
|
|
327
|
+
this._books.update(orders);
|
|
320
328
|
const traded = this._trades.update(orders);
|
|
321
|
-
//
|
|
329
|
+
// Tape first: the more specific event, and a book handler that then reads
|
|
322
330
|
// the tape sees the same trade the trade handler was just given. Both
|
|
323
331
|
// aggregators are already current either way — what is ordered here is only
|
|
324
332
|
// which handler hears about it first.
|
|
@@ -330,7 +338,7 @@ export class DefaultMarketView {
|
|
|
330
338
|
}
|
|
331
339
|
}
|
|
332
340
|
for (const marketId of touched) {
|
|
333
|
-
const book = this.
|
|
341
|
+
const book = this._books.get(marketId);
|
|
334
342
|
if (!book)
|
|
335
343
|
continue;
|
|
336
344
|
for (const h of this._bookHandlers) {
|
|
@@ -343,7 +351,7 @@ export class DefaultMarketView {
|
|
|
343
351
|
}
|
|
344
352
|
_ensureOpen() {
|
|
345
353
|
if (this._closed) {
|
|
346
|
-
throw new Error(`
|
|
354
|
+
throw new Error(`Desk for marketplace ${this.marketplaceId} is closed`);
|
|
347
355
|
}
|
|
348
356
|
}
|
|
349
357
|
}
|
|
@@ -372,9 +380,9 @@ function _isFrameUnreadable(event) {
|
|
|
372
380
|
return typeof event === "object" && event !== null && event.kind === "frame-unreadable";
|
|
373
381
|
}
|
|
374
382
|
/**
|
|
375
|
-
* Reader-side handle on a refcounted
|
|
376
|
-
* Flexemarkets.
|
|
377
|
-
* 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.
|
|
378
386
|
* Each handle's close() decrements the shared refcount and tears down
|
|
379
387
|
* the shared resources on the last close.
|
|
380
388
|
*
|
|
@@ -382,7 +390,7 @@ function _isFrameUnreadable(event) {
|
|
|
382
390
|
* locally and closed when the handle closes — so a handler doesn't
|
|
383
391
|
* keep firing into stale state after the handle is gone.
|
|
384
392
|
*/
|
|
385
|
-
export class
|
|
393
|
+
export class DeskHandle {
|
|
386
394
|
_shared;
|
|
387
395
|
_onClose;
|
|
388
396
|
_mySubscriptions = [];
|
|
@@ -398,13 +406,21 @@ export class MarketViewHandle {
|
|
|
398
406
|
this._check();
|
|
399
407
|
return this._shared.markets;
|
|
400
408
|
}
|
|
401
|
-
|
|
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() {
|
|
402
418
|
this._check();
|
|
403
|
-
return this._shared.
|
|
419
|
+
return this._shared.books();
|
|
404
420
|
}
|
|
405
|
-
|
|
421
|
+
tapes() {
|
|
406
422
|
this._check();
|
|
407
|
-
return this._shared.
|
|
423
|
+
return this._shared.tapes();
|
|
408
424
|
}
|
|
409
425
|
session() {
|
|
410
426
|
this._check();
|
|
@@ -420,9 +436,9 @@ export class MarketViewHandle {
|
|
|
420
436
|
this._mySubscriptions.push(sub);
|
|
421
437
|
return sub;
|
|
422
438
|
}
|
|
423
|
-
|
|
439
|
+
onBookChange(marketId, handler) {
|
|
424
440
|
this._check();
|
|
425
|
-
const sub = this._shared.
|
|
441
|
+
const sub = this._shared.onBookChange(marketId, handler);
|
|
426
442
|
this._mySubscriptions.push(sub);
|
|
427
443
|
return sub;
|
|
428
444
|
}
|
|
@@ -444,9 +460,9 @@ export class MarketViewHandle {
|
|
|
444
460
|
this._mySubscriptions.push(sub);
|
|
445
461
|
return sub;
|
|
446
462
|
}
|
|
447
|
-
|
|
463
|
+
onRecovery(handler) {
|
|
448
464
|
this._check();
|
|
449
|
-
const sub = this._shared.
|
|
465
|
+
const sub = this._shared.onRecovery(handler);
|
|
450
466
|
this._mySubscriptions.push(sub);
|
|
451
467
|
return sub;
|
|
452
468
|
}
|
|
@@ -476,8 +492,8 @@ export class MarketViewHandle {
|
|
|
476
492
|
}
|
|
477
493
|
_check() {
|
|
478
494
|
if (this._closed) {
|
|
479
|
-
throw new Error(`
|
|
495
|
+
throw new Error(`Desk handle for marketplace ${this._shared.marketplaceId} is closed`);
|
|
480
496
|
}
|
|
481
497
|
}
|
|
482
498
|
}
|
|
483
|
-
//# 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,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,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,WAAW,CAAC,QAAgB,EAAE,IAAY,EAAE,KAAa,EAAE,KAAa;QACtE,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;IAED,YAAY,CAAC,QAAgB,EAAE,UAAkB;QAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,+DAA+D;QAC/D,mEAAmE;QACnE,iEAAiE;QACjE,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,gBAAgB,EAAE,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,14 +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 {
|
|
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
9
|
export type { Trade } from "./trades.js";
|
|
10
|
-
export type { StompFrame, StreamDropped,
|
|
11
|
-
export type {
|
|
10
|
+
export type { StompFrame, StreamDropped, StreamReconnected, FrameUnreadable, FmEvent, EventCallback, } from "./stomp.js";
|
|
11
|
+
export type { Desk, Subscription, GapEvent, DeskRecovery } from "./desk.js";
|
|
12
12
|
export type { Snapshot } from "./snapshot.js";
|
|
13
13
|
export { NO_SEQ } from "./stomp.js";
|
|
14
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
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAsBnC,OAAO,EACL,SAAS,EACT,SAAS,EACT,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,SAAS;AACT,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,QAAQ,EACR,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,+DAA+D;AAC/D,EAAE;AACF,8EAA8E;AAC9E,wDAAwD;AACxD,OAAO,EACL,MAAM,EACN,SAAS,EACT,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,KAAK,GACN,MAAM,kBAAkB,CAAC;AAE1B,aAAa;AACb,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO;AACP,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAgB5C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|