@agg-build/sdk 4.25.0 → 4.27.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/dist/agg-websocket-BstVWtLA.d.mts +6004 -0
- package/dist/agg-websocket-BstVWtLA.d.mts.map +1 -0
- package/dist/agg-websocket-BstVWtLA.d.ts +6004 -0
- package/dist/agg-websocket-BstVWtLA.d.ts.map +1 -0
- package/dist/agg-websocket-CK2iXfti.mjs +1427 -0
- package/dist/agg-websocket-CK2iXfti.mjs.map +1 -0
- package/dist/agg-websocket-DJbIfxKb.js +1478 -0
- package/dist/browser.d.mts +67 -66
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.d.ts +67 -66
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +720 -2047
- package/dist/browser.mjs +423 -799
- package/dist/browser.mjs.map +1 -0
- package/dist/candle-builder-BNewIe9K.mjs +148 -0
- package/dist/candle-builder-BNewIe9K.mjs.map +1 -0
- package/dist/candle-builder-BULYdxB4.js +151 -0
- package/dist/index.d.mts +2 -1342
- package/dist/index.d.ts +2 -1342
- package/dist/index.js +2794 -4656
- package/dist/index.mjs +2788 -2486
- package/dist/index.mjs.map +1 -0
- package/dist/market-data.d.mts +6 -6
- package/dist/market-data.d.mts.map +1 -0
- package/dist/market-data.d.ts +6 -6
- package/dist/market-data.d.ts.map +1 -0
- package/dist/market-data.js +314 -1774
- package/dist/market-data.mjs +314 -350
- package/dist/market-data.mjs.map +1 -0
- package/dist/server.d.mts +235 -234
- package/dist/server.d.mts.map +1 -0
- package/dist/server.d.ts +235 -234
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +168 -296
- package/dist/server.mjs +163 -234
- package/dist/server.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/agg-websocket-Bxt9PzTz.d.mts +0 -4479
- package/dist/agg-websocket-Bxt9PzTz.d.ts +0 -4479
- package/dist/chunk-QXBVA5TW.mjs +0 -2073
- package/dist/chunk-VD5UTAVD.mjs +0 -158
- package/dist/chunk-WNQUEZJF.mjs +0 -58
package/dist/browser.mjs
CHANGED
|
@@ -1,804 +1,428 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
__async,
|
|
6
|
-
__objRest,
|
|
7
|
-
__spreadProps,
|
|
8
|
-
__spreadValues
|
|
9
|
-
} from "./chunk-WNQUEZJF.mjs";
|
|
10
|
-
|
|
11
|
-
// ../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.mjs
|
|
12
|
-
var proxyMarker = /* @__PURE__ */ Symbol("Comlink.proxy");
|
|
13
|
-
var createEndpoint = /* @__PURE__ */ Symbol("Comlink.endpoint");
|
|
14
|
-
var releaseProxy = /* @__PURE__ */ Symbol("Comlink.releaseProxy");
|
|
15
|
-
var finalizer = /* @__PURE__ */ Symbol("Comlink.finalizer");
|
|
16
|
-
var throwMarker = /* @__PURE__ */ Symbol("Comlink.thrown");
|
|
17
|
-
var isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";
|
|
18
|
-
var proxyTransferHandler = {
|
|
19
|
-
canHandle: (val) => isObject(val) && val[proxyMarker],
|
|
20
|
-
serialize(obj) {
|
|
21
|
-
const { port1, port2 } = new MessageChannel();
|
|
22
|
-
expose(obj, port1);
|
|
23
|
-
return [port2, [port2]];
|
|
24
|
-
},
|
|
25
|
-
deserialize(port) {
|
|
26
|
-
port.start();
|
|
27
|
-
return wrap(port);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var throwTransferHandler = {
|
|
31
|
-
canHandle: (value) => isObject(value) && throwMarker in value,
|
|
32
|
-
serialize({ value }) {
|
|
33
|
-
let serialized;
|
|
34
|
-
if (value instanceof Error) {
|
|
35
|
-
serialized = {
|
|
36
|
-
isError: true,
|
|
37
|
-
value: {
|
|
38
|
-
message: value.message,
|
|
39
|
-
name: value.name,
|
|
40
|
-
stack: value.stack
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
} else {
|
|
44
|
-
serialized = { isError: false, value };
|
|
45
|
-
}
|
|
46
|
-
return [serialized, []];
|
|
47
|
-
},
|
|
48
|
-
deserialize(serialized) {
|
|
49
|
-
if (serialized.isError) {
|
|
50
|
-
throw Object.assign(new Error(serialized.value.message), serialized.value);
|
|
51
|
-
}
|
|
52
|
-
throw serialized.value;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var transferHandlers = /* @__PURE__ */ new Map([
|
|
56
|
-
["proxy", proxyTransferHandler],
|
|
57
|
-
["throw", throwTransferHandler]
|
|
58
|
-
]);
|
|
59
|
-
function isAllowedOrigin(allowedOrigins, origin) {
|
|
60
|
-
for (const allowedOrigin of allowedOrigins) {
|
|
61
|
-
if (origin === allowedOrigin || allowedOrigin === "*") {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {
|
|
71
|
-
ep.addEventListener("message", function callback(ev) {
|
|
72
|
-
if (!ev || !ev.data) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (!isAllowedOrigin(allowedOrigins, ev.origin)) {
|
|
76
|
-
console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const { id, type, path } = Object.assign({ path: [] }, ev.data);
|
|
80
|
-
const argumentList = (ev.data.argumentList || []).map(fromWireValue);
|
|
81
|
-
let returnValue;
|
|
82
|
-
try {
|
|
83
|
-
const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);
|
|
84
|
-
const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);
|
|
85
|
-
switch (type) {
|
|
86
|
-
case "GET":
|
|
87
|
-
{
|
|
88
|
-
returnValue = rawValue;
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
case "SET":
|
|
92
|
-
{
|
|
93
|
-
parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);
|
|
94
|
-
returnValue = true;
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
case "APPLY":
|
|
98
|
-
{
|
|
99
|
-
returnValue = rawValue.apply(parent, argumentList);
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
case "CONSTRUCT":
|
|
103
|
-
{
|
|
104
|
-
const value = new rawValue(...argumentList);
|
|
105
|
-
returnValue = proxy(value);
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
case "ENDPOINT":
|
|
109
|
-
{
|
|
110
|
-
const { port1, port2 } = new MessageChannel();
|
|
111
|
-
expose(obj, port2);
|
|
112
|
-
returnValue = transfer(port1, [port1]);
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
case "RELEASE":
|
|
116
|
-
{
|
|
117
|
-
returnValue = void 0;
|
|
118
|
-
}
|
|
119
|
-
break;
|
|
120
|
-
default:
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
} catch (value) {
|
|
124
|
-
returnValue = { value, [throwMarker]: 0 };
|
|
125
|
-
}
|
|
126
|
-
Promise.resolve(returnValue).catch((value) => {
|
|
127
|
-
return { value, [throwMarker]: 0 };
|
|
128
|
-
}).then((returnValue2) => {
|
|
129
|
-
const [wireValue, transferables] = toWireValue(returnValue2);
|
|
130
|
-
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
131
|
-
if (type === "RELEASE") {
|
|
132
|
-
ep.removeEventListener("message", callback);
|
|
133
|
-
closeEndPoint(ep);
|
|
134
|
-
if (finalizer in obj && typeof obj[finalizer] === "function") {
|
|
135
|
-
obj[finalizer]();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}).catch((error) => {
|
|
139
|
-
const [wireValue, transferables] = toWireValue({
|
|
140
|
-
value: new TypeError("Unserializable return value"),
|
|
141
|
-
[throwMarker]: 0
|
|
142
|
-
});
|
|
143
|
-
ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
if (ep.start) {
|
|
147
|
-
ep.start();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function isMessagePort(endpoint) {
|
|
151
|
-
return endpoint.constructor.name === "MessagePort";
|
|
152
|
-
}
|
|
153
|
-
function closeEndPoint(endpoint) {
|
|
154
|
-
if (isMessagePort(endpoint))
|
|
155
|
-
endpoint.close();
|
|
156
|
-
}
|
|
157
|
-
function wrap(ep, target) {
|
|
158
|
-
const pendingListeners = /* @__PURE__ */ new Map();
|
|
159
|
-
ep.addEventListener("message", function handleMessage(ev) {
|
|
160
|
-
const { data } = ev;
|
|
161
|
-
if (!data || !data.id) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const resolver = pendingListeners.get(data.id);
|
|
165
|
-
if (!resolver) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
try {
|
|
169
|
-
resolver(data);
|
|
170
|
-
} finally {
|
|
171
|
-
pendingListeners.delete(data.id);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
return createProxy(ep, pendingListeners, [], target);
|
|
175
|
-
}
|
|
176
|
-
function throwIfProxyReleased(isReleased) {
|
|
177
|
-
if (isReleased) {
|
|
178
|
-
throw new Error("Proxy has been released and is not useable");
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function releaseEndpoint(ep) {
|
|
182
|
-
return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {
|
|
183
|
-
type: "RELEASE"
|
|
184
|
-
}).then(() => {
|
|
185
|
-
closeEndPoint(ep);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
var proxyCounter = /* @__PURE__ */ new WeakMap();
|
|
189
|
-
var proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {
|
|
190
|
-
const newCount = (proxyCounter.get(ep) || 0) - 1;
|
|
191
|
-
proxyCounter.set(ep, newCount);
|
|
192
|
-
if (newCount === 0) {
|
|
193
|
-
releaseEndpoint(ep);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
function registerProxy(proxy2, ep) {
|
|
197
|
-
const newCount = (proxyCounter.get(ep) || 0) + 1;
|
|
198
|
-
proxyCounter.set(ep, newCount);
|
|
199
|
-
if (proxyFinalizers) {
|
|
200
|
-
proxyFinalizers.register(proxy2, ep, proxy2);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function unregisterProxy(proxy2) {
|
|
204
|
-
if (proxyFinalizers) {
|
|
205
|
-
proxyFinalizers.unregister(proxy2);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function createProxy(ep, pendingListeners, path = [], target = function() {
|
|
209
|
-
}) {
|
|
210
|
-
let isProxyReleased = false;
|
|
211
|
-
const proxy2 = new Proxy(target, {
|
|
212
|
-
get(_target, prop) {
|
|
213
|
-
throwIfProxyReleased(isProxyReleased);
|
|
214
|
-
if (prop === releaseProxy) {
|
|
215
|
-
return () => {
|
|
216
|
-
unregisterProxy(proxy2);
|
|
217
|
-
releaseEndpoint(ep);
|
|
218
|
-
pendingListeners.clear();
|
|
219
|
-
isProxyReleased = true;
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
if (prop === "then") {
|
|
223
|
-
if (path.length === 0) {
|
|
224
|
-
return { then: () => proxy2 };
|
|
225
|
-
}
|
|
226
|
-
const r = requestResponseMessage(ep, pendingListeners, {
|
|
227
|
-
type: "GET",
|
|
228
|
-
path: path.map((p) => p.toString())
|
|
229
|
-
}).then(fromWireValue);
|
|
230
|
-
return r.then.bind(r);
|
|
231
|
-
}
|
|
232
|
-
return createProxy(ep, pendingListeners, [...path, prop]);
|
|
233
|
-
},
|
|
234
|
-
set(_target, prop, rawValue) {
|
|
235
|
-
throwIfProxyReleased(isProxyReleased);
|
|
236
|
-
const [value, transferables] = toWireValue(rawValue);
|
|
237
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
238
|
-
type: "SET",
|
|
239
|
-
path: [...path, prop].map((p) => p.toString()),
|
|
240
|
-
value
|
|
241
|
-
}, transferables).then(fromWireValue);
|
|
242
|
-
},
|
|
243
|
-
apply(_target, _thisArg, rawArgumentList) {
|
|
244
|
-
throwIfProxyReleased(isProxyReleased);
|
|
245
|
-
const last = path[path.length - 1];
|
|
246
|
-
if (last === createEndpoint) {
|
|
247
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
248
|
-
type: "ENDPOINT"
|
|
249
|
-
}).then(fromWireValue);
|
|
250
|
-
}
|
|
251
|
-
if (last === "bind") {
|
|
252
|
-
return createProxy(ep, pendingListeners, path.slice(0, -1));
|
|
253
|
-
}
|
|
254
|
-
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
255
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
256
|
-
type: "APPLY",
|
|
257
|
-
path: path.map((p) => p.toString()),
|
|
258
|
-
argumentList
|
|
259
|
-
}, transferables).then(fromWireValue);
|
|
260
|
-
},
|
|
261
|
-
construct(_target, rawArgumentList) {
|
|
262
|
-
throwIfProxyReleased(isProxyReleased);
|
|
263
|
-
const [argumentList, transferables] = processArguments(rawArgumentList);
|
|
264
|
-
return requestResponseMessage(ep, pendingListeners, {
|
|
265
|
-
type: "CONSTRUCT",
|
|
266
|
-
path: path.map((p) => p.toString()),
|
|
267
|
-
argumentList
|
|
268
|
-
}, transferables).then(fromWireValue);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
registerProxy(proxy2, ep);
|
|
272
|
-
return proxy2;
|
|
273
|
-
}
|
|
274
|
-
function myFlat(arr) {
|
|
275
|
-
return Array.prototype.concat.apply([], arr);
|
|
276
|
-
}
|
|
277
|
-
function processArguments(argumentList) {
|
|
278
|
-
const processed = argumentList.map(toWireValue);
|
|
279
|
-
return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];
|
|
280
|
-
}
|
|
281
|
-
var transferCache = /* @__PURE__ */ new WeakMap();
|
|
282
|
-
function transfer(obj, transfers) {
|
|
283
|
-
transferCache.set(obj, transfers);
|
|
284
|
-
return obj;
|
|
285
|
-
}
|
|
286
|
-
function proxy(obj) {
|
|
287
|
-
return Object.assign(obj, { [proxyMarker]: true });
|
|
288
|
-
}
|
|
289
|
-
function toWireValue(value) {
|
|
290
|
-
for (const [name, handler] of transferHandlers) {
|
|
291
|
-
if (handler.canHandle(value)) {
|
|
292
|
-
const [serializedValue, transferables] = handler.serialize(value);
|
|
293
|
-
return [
|
|
294
|
-
{
|
|
295
|
-
type: "HANDLER",
|
|
296
|
-
name,
|
|
297
|
-
value: serializedValue
|
|
298
|
-
},
|
|
299
|
-
transferables
|
|
300
|
-
];
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return [
|
|
304
|
-
{
|
|
305
|
-
type: "RAW",
|
|
306
|
-
value
|
|
307
|
-
},
|
|
308
|
-
transferCache.get(value) || []
|
|
309
|
-
];
|
|
310
|
-
}
|
|
311
|
-
function fromWireValue(value) {
|
|
312
|
-
switch (value.type) {
|
|
313
|
-
case "HANDLER":
|
|
314
|
-
return transferHandlers.get(value.name).deserialize(value.value);
|
|
315
|
-
case "RAW":
|
|
316
|
-
return value.value;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
function requestResponseMessage(ep, pendingListeners, msg, transfers) {
|
|
320
|
-
return new Promise((resolve) => {
|
|
321
|
-
const id = generateUUID();
|
|
322
|
-
pendingListeners.set(id, resolve);
|
|
323
|
-
if (ep.start) {
|
|
324
|
-
ep.start();
|
|
325
|
-
}
|
|
326
|
-
ep.postMessage(Object.assign({ id }, msg), transfers);
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
function generateUUID() {
|
|
330
|
-
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// src/market-data/worker-adapter.ts
|
|
1
|
+
import { t as AggWebSocket } from "./agg-websocket-CK2iXfti.mjs";
|
|
2
|
+
import { proxy, releaseProxy, wrap } from "comlink";
|
|
3
|
+
//#region src/market-data/worker-adapter.ts
|
|
334
4
|
var WorkerAggWebSocket = class extends AggWebSocket {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
if (this.stopped) return;
|
|
747
|
-
if (this.fallback) {
|
|
748
|
-
action(this.fallback);
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
void this.ready.then(() => {
|
|
752
|
-
var _a;
|
|
753
|
-
if (this.stopped) return;
|
|
754
|
-
const engine = (_a = this.fallback) != null ? _a : this.remote;
|
|
755
|
-
if (engine) return action(engine);
|
|
756
|
-
}).catch(this.fail);
|
|
757
|
-
}
|
|
758
|
-
fallbackCallbacks() {
|
|
759
|
-
return __spreadProps(__spreadValues({}, this.handlers), {
|
|
760
|
-
onArbMarket: (msg) => this.event("onArbMarket", [msg]),
|
|
761
|
-
onArbFeed: (msg) => this.event("onArbFeed", [msg])
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
syncFallback() {
|
|
765
|
-
for (const [key, unsubscribe] of this.fallbackUnsubs) {
|
|
766
|
-
if (!this.refs.has(key)) {
|
|
767
|
-
unsubscribe();
|
|
768
|
-
this.fallbackUnsubs.delete(key);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
for (const [key, { sub }] of this.refs) {
|
|
772
|
-
if (this.fallbackUnsubs.has(key)) continue;
|
|
773
|
-
this.fallbackUnsubs.set(
|
|
774
|
-
key,
|
|
775
|
-
sub.channel === "arb" ? this.fallback.subscribeArb(sub.id, () => {
|
|
776
|
-
}) : sub.channel === "arb-feed" ? this.fallback.subscribeArbFeed(() => {
|
|
777
|
-
}) : this.fallback.subscribe(sub.id, sub.channel)
|
|
778
|
-
);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
5
|
+
get processesCandles() {
|
|
6
|
+
return !this.fallback;
|
|
7
|
+
}
|
|
8
|
+
constructor(config, factory) {
|
|
9
|
+
super(config);
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.endpointListeners = /* @__PURE__ */ new Map();
|
|
12
|
+
this.historyOperations = 0;
|
|
13
|
+
this.currentBooks = /* @__PURE__ */ new Map();
|
|
14
|
+
this.recovering = /* @__PURE__ */ new Set();
|
|
15
|
+
this.diagnosticRevisions = /* @__PURE__ */ new Map();
|
|
16
|
+
this.deliveredRevisions = /* @__PURE__ */ new Map();
|
|
17
|
+
this.resolvedRevisions = /* @__PURE__ */ new Map();
|
|
18
|
+
this.refs = /* @__PURE__ */ new Map();
|
|
19
|
+
this.arbListeners = /* @__PURE__ */ new Map();
|
|
20
|
+
this.feedListeners = /* @__PURE__ */ new Set();
|
|
21
|
+
this.latest = /* @__PURE__ */ new Map();
|
|
22
|
+
this.generation = 0;
|
|
23
|
+
this.online = false;
|
|
24
|
+
this.stopped = false;
|
|
25
|
+
this.queued = false;
|
|
26
|
+
this.historyFailures = /* @__PURE__ */ new Set();
|
|
27
|
+
this.fallback = null;
|
|
28
|
+
this.fallbackUnsubs = /* @__PURE__ */ new Map();
|
|
29
|
+
this.historyGeneration = 0;
|
|
30
|
+
this.visibility = () => {
|
|
31
|
+
if (document.visibilityState === "visible") this.resnapshot([...this.refs.values()].filter((entry) => entry.sub.channel === "orderbook").map((entry) => entry.sub.id));
|
|
32
|
+
};
|
|
33
|
+
this.fail = () => {
|
|
34
|
+
if (this.stopped || this.fallback) return;
|
|
35
|
+
this.releaseWorker();
|
|
36
|
+
this.currentBooks.clear();
|
|
37
|
+
this.latest.clear();
|
|
38
|
+
this.recovering.clear();
|
|
39
|
+
this.diagnosticRevisions.clear();
|
|
40
|
+
this.deliveredRevisions.clear();
|
|
41
|
+
this.resolvedRevisions.clear();
|
|
42
|
+
this.online = false;
|
|
43
|
+
this.handlers.onConnectionStateChange?.(false);
|
|
44
|
+
this.fallback = new AggWebSocket({
|
|
45
|
+
...this.config,
|
|
46
|
+
callbacks: this.fallbackCallbacks()
|
|
47
|
+
});
|
|
48
|
+
for (const reject of this.historyFailures) reject(/* @__PURE__ */ new Error("Market-data worker failed"));
|
|
49
|
+
this.historyFailures.clear();
|
|
50
|
+
this.resolveFailure?.();
|
|
51
|
+
this.syncFallback();
|
|
52
|
+
};
|
|
53
|
+
if (config.callbacks?.onTrade && !config.callbacks.onMarketView) throw new Error("Raw trade callbacks require AggWebSocket; Worker views require onMarketView opt-in");
|
|
54
|
+
this.handlers = config.callbacks ?? {};
|
|
55
|
+
this.worker = factory();
|
|
56
|
+
const worker = this.worker;
|
|
57
|
+
const endpoint = {
|
|
58
|
+
postMessage: worker.postMessage.bind(worker),
|
|
59
|
+
addEventListener: (type, listener) => {
|
|
60
|
+
this.endpointListeners.set(listener, type);
|
|
61
|
+
worker.addEventListener(type, listener);
|
|
62
|
+
},
|
|
63
|
+
removeEventListener: (type, listener) => {
|
|
64
|
+
this.endpointListeners.delete(listener);
|
|
65
|
+
worker.removeEventListener(type, listener);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
this.remote = wrap(endpoint);
|
|
69
|
+
this.worker.addEventListener("error", this.fail);
|
|
70
|
+
this.worker.addEventListener("messageerror", this.fail);
|
|
71
|
+
const { callbacks: _callbacks, ...options } = config;
|
|
72
|
+
const startup = this.remote.start(options, proxy((event) => {
|
|
73
|
+
if (!this.fallback) this.event(event.name, event.args, event.revision);
|
|
74
|
+
})).then(() => {
|
|
75
|
+
if (this.stopped || this.fallback || !this.remote) return;
|
|
76
|
+
return this.remote.observeViews(proxy((batch) => {
|
|
77
|
+
if (batch.generation < this.generation || this.stopped || this.fallback) return;
|
|
78
|
+
for (const view of batch.views) {
|
|
79
|
+
if (!this.refs.has(`orderbook:${view.outcomeId}`) && !this.refs.has(`trades:${view.outcomeId}`)) continue;
|
|
80
|
+
if ((this.resolvedRevisions.get(view.outcomeId) ?? -1) >= view.revision) continue;
|
|
81
|
+
const integrity = (this.diagnosticRevisions.get(view.outcomeId) ?? -1) > view.revision ? "resyncing" : view.integrity;
|
|
82
|
+
this.deliveredRevisions.set(view.outcomeId, view.revision);
|
|
83
|
+
this.handlers.onMarketView?.({
|
|
84
|
+
...view,
|
|
85
|
+
integrity
|
|
86
|
+
});
|
|
87
|
+
if (view.book) {
|
|
88
|
+
this.currentBooks.set(view.outcomeId, view.book);
|
|
89
|
+
if (integrity === "ok") {
|
|
90
|
+
this.recovering.delete(view.outcomeId);
|
|
91
|
+
this.diagnosticRevisions.delete(view.outcomeId);
|
|
92
|
+
} else this.recovering.add(view.outcomeId);
|
|
93
|
+
if (view.snapshot) this.handlers.onSnapshot?.(view.outcomeId, view.book);
|
|
94
|
+
else this.handlers.onDelta?.(view.outcomeId, view.book);
|
|
95
|
+
}
|
|
96
|
+
for (const trade of [...view.trades].reverse()) this.handlers.onTrade?.(trade);
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
}).catch(this.fail);
|
|
100
|
+
const failed = new Promise((resolve) => {
|
|
101
|
+
this.resolveFailure = resolve;
|
|
102
|
+
});
|
|
103
|
+
this.ready = Promise.race([startup, failed]);
|
|
104
|
+
const startupTimeout = setTimeout(this.fail, 3e3);
|
|
105
|
+
this.ready.then(() => clearTimeout(startupTimeout));
|
|
106
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", this.visibility);
|
|
107
|
+
}
|
|
108
|
+
async decodeHistory(payload) {
|
|
109
|
+
this.historyOperations++;
|
|
110
|
+
try {
|
|
111
|
+
return await this.decodeHistoryRequest(payload);
|
|
112
|
+
} finally {
|
|
113
|
+
this.historyOperations--;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async decodeHistoryRequest(payload) {
|
|
117
|
+
if (this.stopped) throw new Error("Market-data worker disposed");
|
|
118
|
+
await this.ready;
|
|
119
|
+
if (this.stopped) throw new Error("Market-data worker disposed");
|
|
120
|
+
if (this.fallback) return this.fallback.decodeHistory(payload);
|
|
121
|
+
const remote = this.remote;
|
|
122
|
+
if (!remote) throw new Error("Market-data worker unavailable");
|
|
123
|
+
let rejectFailure;
|
|
124
|
+
const failed = new Promise((_resolve, reject) => {
|
|
125
|
+
rejectFailure = reject;
|
|
126
|
+
this.historyFailures.add(reject);
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
return await Promise.race([remote.decodeHistory(payload), failed]);
|
|
130
|
+
} finally {
|
|
131
|
+
this.historyFailures.delete(rejectFailure);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async loadHistory(manifest, options) {
|
|
135
|
+
this.historyOperations++;
|
|
136
|
+
try {
|
|
137
|
+
return await this.loadHistoryRequest(manifest, options);
|
|
138
|
+
} finally {
|
|
139
|
+
this.historyOperations--;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async loadHistoryRequest(manifest, options) {
|
|
143
|
+
if (this.stopped) throw new Error("Market-data worker disposed");
|
|
144
|
+
if (this.fallback) return this.fallback.loadHistory(manifest, options);
|
|
145
|
+
const generation = ++this.historyGeneration;
|
|
146
|
+
const key = `${manifest.venueMarketOutcomeId}:${manifest.resolution}:${manifest.from}:${manifest.to}`;
|
|
147
|
+
options?.signal?.throwIfAborted();
|
|
148
|
+
await this.ready;
|
|
149
|
+
if (this.stopped) throw new Error("Market-data worker disposed");
|
|
150
|
+
options?.signal?.throwIfAborted();
|
|
151
|
+
const fallbackAfterStartup = this.fallback;
|
|
152
|
+
if (fallbackAfterStartup) return fallbackAfterStartup.loadHistory(manifest, options);
|
|
153
|
+
const remote = this.remote;
|
|
154
|
+
if (!remote) throw new Error("Market-data worker unavailable");
|
|
155
|
+
let rejectFailure;
|
|
156
|
+
const failed = new Promise((_resolve, reject) => {
|
|
157
|
+
rejectFailure = reject;
|
|
158
|
+
this.historyFailures.add(reject);
|
|
159
|
+
});
|
|
160
|
+
const abort = () => {
|
|
161
|
+
this.remote?.cancelHistoryRange(key, generation);
|
|
162
|
+
};
|
|
163
|
+
options?.signal?.addEventListener("abort", abort, { once: true });
|
|
164
|
+
try {
|
|
165
|
+
const result = await Promise.race([remote.loadImmutableRange(key, generation, manifest), failed]);
|
|
166
|
+
options?.signal?.throwIfAborted();
|
|
167
|
+
return result;
|
|
168
|
+
} finally {
|
|
169
|
+
options?.signal?.removeEventListener("abort", abort);
|
|
170
|
+
this.historyFailures.delete(rejectFailure);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
setHostDiagnostics(provider) {
|
|
174
|
+
this.hostProvider = provider;
|
|
175
|
+
}
|
|
176
|
+
getDiagnostics() {
|
|
177
|
+
const subscriptions = [...this.refs.values()].map((entry) => entry.sub);
|
|
178
|
+
return this.fallback ? {
|
|
179
|
+
...this.fallback.getDiagnostics(),
|
|
180
|
+
host: this.hostProvider?.(),
|
|
181
|
+
pendingHistoryRequests: this.historyOperations,
|
|
182
|
+
workerAttached: false,
|
|
183
|
+
bridgeListeners: this.endpointListeners.size
|
|
184
|
+
} : {
|
|
185
|
+
connected: this.connected,
|
|
186
|
+
host: this.hostProvider?.(),
|
|
187
|
+
transport: this.stopped ? "disposed" : "worker",
|
|
188
|
+
orderbookOutcomeIds: subscriptions.filter((sub) => sub.channel === "orderbook").map((sub) => sub.id),
|
|
189
|
+
tradeOutcomeIds: subscriptions.filter((sub) => sub.channel === "trades").map((sub) => sub.id),
|
|
190
|
+
arbMarketIds: [...this.arbListeners.keys()],
|
|
191
|
+
arbFeedSubscribers: this.feedListeners.size,
|
|
192
|
+
cachedBooks: this.currentBooks.size,
|
|
193
|
+
cachedArb: this.latest.size,
|
|
194
|
+
resyncingBooks: this.recovering.size,
|
|
195
|
+
pendingResnapshots: 0,
|
|
196
|
+
pendingHistoryRequests: this.historyOperations,
|
|
197
|
+
workerAttached: this.worker !== null,
|
|
198
|
+
bridgeListeners: this.endpointListeners.size
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async getWorkerDiagnostics() {
|
|
202
|
+
await this.ready;
|
|
203
|
+
const remote = this.remote;
|
|
204
|
+
if (this.stopped || !remote || this.fallback) return null;
|
|
205
|
+
let rejectFailure;
|
|
206
|
+
const failed = new Promise((_resolve, reject) => {
|
|
207
|
+
rejectFailure = reject;
|
|
208
|
+
this.historyFailures.add(reject);
|
|
209
|
+
});
|
|
210
|
+
try {
|
|
211
|
+
return await Promise.race([remote.getMeasurements(), failed]);
|
|
212
|
+
} catch {
|
|
213
|
+
return null;
|
|
214
|
+
} finally {
|
|
215
|
+
this.historyFailures.delete(rejectFailure);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
get connected() {
|
|
219
|
+
return !this.stopped && (this.fallback?.connected ?? this.online);
|
|
220
|
+
}
|
|
221
|
+
getBook(id) {
|
|
222
|
+
return this.fallback?.getBook(id) ?? this.currentBooks.get(id) ?? null;
|
|
223
|
+
}
|
|
224
|
+
isResyncing(id) {
|
|
225
|
+
return this.fallback?.isResyncing(id) ?? this.recovering.has(id);
|
|
226
|
+
}
|
|
227
|
+
getArb(id) {
|
|
228
|
+
return this.fallback?.getArb(id) ?? this.latest.get(id) ?? null;
|
|
229
|
+
}
|
|
230
|
+
subscribe(id, channel = "orderbook") {
|
|
231
|
+
return this.ref({
|
|
232
|
+
id,
|
|
233
|
+
channel
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
subscribeTrades(id) {
|
|
237
|
+
return this.subscribe(id, "trades");
|
|
238
|
+
}
|
|
239
|
+
subscribeArb(id, cb) {
|
|
240
|
+
const listeners = this.arbListeners.get(id) ?? /* @__PURE__ */ new Set();
|
|
241
|
+
listeners.add(cb);
|
|
242
|
+
this.arbListeners.set(id, listeners);
|
|
243
|
+
const unsubscribe = this.ref({
|
|
244
|
+
id,
|
|
245
|
+
channel: "arb"
|
|
246
|
+
});
|
|
247
|
+
return () => {
|
|
248
|
+
unsubscribe();
|
|
249
|
+
listeners.delete(cb);
|
|
250
|
+
if (!listeners.size) this.arbListeners.delete(id);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
subscribeArbFeed(cb) {
|
|
254
|
+
this.feedListeners.add(cb);
|
|
255
|
+
const unsubscribe = this.ref({
|
|
256
|
+
id: "*",
|
|
257
|
+
channel: "arb-feed"
|
|
258
|
+
});
|
|
259
|
+
return () => {
|
|
260
|
+
unsubscribe();
|
|
261
|
+
this.feedListeners.delete(cb);
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
setCallbacks(callbacks) {
|
|
265
|
+
this.handlers = callbacks;
|
|
266
|
+
if (callbacks.onTrade && !callbacks.onMarketView && !this.fallback) this.fail();
|
|
267
|
+
this.fallback?.setCallbacks(this.fallbackCallbacks());
|
|
268
|
+
}
|
|
269
|
+
authenticate(token) {
|
|
270
|
+
this.config.initialToken = token;
|
|
271
|
+
this.run((engine) => engine.authenticate(token));
|
|
272
|
+
}
|
|
273
|
+
connect() {
|
|
274
|
+
this.run((engine) => engine.connect());
|
|
275
|
+
}
|
|
276
|
+
disconnect() {
|
|
277
|
+
this.run((engine) => engine.disconnect());
|
|
278
|
+
}
|
|
279
|
+
resnapshot(id) {
|
|
280
|
+
const ids = Array.isArray(id) ? id : [id];
|
|
281
|
+
this.run((engine) => engine.resnapshot(ids));
|
|
282
|
+
}
|
|
283
|
+
destroy() {
|
|
284
|
+
if (this.stopped) return;
|
|
285
|
+
this.stopped = true;
|
|
286
|
+
this.online = false;
|
|
287
|
+
this.resolveFailure?.();
|
|
288
|
+
for (const reject of this.historyFailures) reject(/* @__PURE__ */ new Error("Market-data worker disposed"));
|
|
289
|
+
this.historyFailures.clear();
|
|
290
|
+
this.refs.clear();
|
|
291
|
+
this.currentBooks.clear();
|
|
292
|
+
this.latest.clear();
|
|
293
|
+
this.arbListeners.clear();
|
|
294
|
+
this.feedListeners.clear();
|
|
295
|
+
this.recovering.clear();
|
|
296
|
+
this.diagnosticRevisions.clear();
|
|
297
|
+
this.deliveredRevisions.clear();
|
|
298
|
+
this.resolvedRevisions.clear();
|
|
299
|
+
this.fallback?.destroy();
|
|
300
|
+
this.fallbackUnsubs.clear();
|
|
301
|
+
this.hostProvider = void 0;
|
|
302
|
+
this.handlers = {};
|
|
303
|
+
if (typeof document !== "undefined") document.removeEventListener("visibilitychange", this.visibility);
|
|
304
|
+
this.releaseWorker();
|
|
305
|
+
}
|
|
306
|
+
releaseWorker() {
|
|
307
|
+
const worker = this.worker;
|
|
308
|
+
const remote = this.remote;
|
|
309
|
+
this.remote = null;
|
|
310
|
+
this.worker = null;
|
|
311
|
+
if (remote) remote[releaseProxy]();
|
|
312
|
+
if (!worker) return;
|
|
313
|
+
for (const [listener, type] of this.endpointListeners) worker.removeEventListener(type, listener);
|
|
314
|
+
this.endpointListeners.clear();
|
|
315
|
+
worker.removeEventListener("error", this.fail);
|
|
316
|
+
worker.removeEventListener("messageerror", this.fail);
|
|
317
|
+
worker.terminate();
|
|
318
|
+
}
|
|
319
|
+
event(name, args, revision = 0) {
|
|
320
|
+
if (this.stopped) return;
|
|
321
|
+
if (name === "onConnectionStateChange") this.online = args[0];
|
|
322
|
+
if (name === "onDiagnostics") {
|
|
323
|
+
const diagnostic = args[0];
|
|
324
|
+
if (diagnostic.outcomeId && revision < (this.deliveredRevisions.get(diagnostic.outcomeId) ?? -1)) return;
|
|
325
|
+
if (diagnostic.outcomeId && (this.refs.has(`orderbook:${diagnostic.outcomeId}`) || this.refs.has(`trades:${diagnostic.outcomeId}`)) && ["seq_gap", "checksum_mismatch"].includes(diagnostic.type)) {
|
|
326
|
+
this.recovering.add(diagnostic.outcomeId);
|
|
327
|
+
this.diagnosticRevisions.set(diagnostic.outcomeId, revision);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (name === "onMarketResolved") {
|
|
331
|
+
const id = args[0].outcomeId;
|
|
332
|
+
if (this.refs.has(`orderbook:${id}`) || this.refs.has(`trades:${id}`)) this.resolvedRevisions.set(id, revision);
|
|
333
|
+
this.currentBooks.delete(id);
|
|
334
|
+
}
|
|
335
|
+
if (name === "onArbMarket") {
|
|
336
|
+
const msg = args[0];
|
|
337
|
+
this.latest.set(msg.marketId, msg);
|
|
338
|
+
for (const cb of this.arbListeners.get(msg.marketId) ?? []) cb(msg);
|
|
339
|
+
}
|
|
340
|
+
if (name === "onArbFeed") for (const cb of this.feedListeners) cb(args[0]);
|
|
341
|
+
this.handlers[name]?.(...args);
|
|
342
|
+
}
|
|
343
|
+
ref(sub) {
|
|
344
|
+
const key = `${sub.channel}:${sub.id}`;
|
|
345
|
+
const entry = this.refs.get(key) ?? {
|
|
346
|
+
sub,
|
|
347
|
+
count: 0
|
|
348
|
+
};
|
|
349
|
+
entry.count++;
|
|
350
|
+
this.refs.set(key, entry);
|
|
351
|
+
this.sync();
|
|
352
|
+
let released = false;
|
|
353
|
+
return () => {
|
|
354
|
+
if (released) return;
|
|
355
|
+
released = true;
|
|
356
|
+
if (--entry.count === 0) {
|
|
357
|
+
this.refs.delete(key);
|
|
358
|
+
if (sub.channel === "orderbook") this.recovering.delete(sub.id);
|
|
359
|
+
if (!this.refs.has(`orderbook:${sub.id}`) && !this.refs.has(`trades:${sub.id}`)) {
|
|
360
|
+
this.currentBooks.delete(sub.id);
|
|
361
|
+
this.recovering.delete(sub.id);
|
|
362
|
+
this.diagnosticRevisions.delete(sub.id);
|
|
363
|
+
this.deliveredRevisions.delete(sub.id);
|
|
364
|
+
this.resolvedRevisions.delete(sub.id);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
this.sync();
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
sync() {
|
|
371
|
+
if (this.queued || this.stopped) return;
|
|
372
|
+
this.queued = true;
|
|
373
|
+
queueMicrotask(() => {
|
|
374
|
+
this.queued = false;
|
|
375
|
+
if (this.stopped) return;
|
|
376
|
+
if (this.fallback) {
|
|
377
|
+
this.syncFallback();
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const generation = ++this.generation;
|
|
381
|
+
const subscriptions = [...this.refs.values()].map((entry) => entry.sub);
|
|
382
|
+
this.ready.then(() => {
|
|
383
|
+
if (!this.stopped && !this.fallback) return this.remote?.setSubscriptions(subscriptions, generation);
|
|
384
|
+
}).catch(this.fail);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
run(action) {
|
|
388
|
+
if (this.stopped) return;
|
|
389
|
+
if (this.fallback) {
|
|
390
|
+
action(this.fallback);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
this.ready.then(() => {
|
|
394
|
+
if (this.stopped) return;
|
|
395
|
+
const engine = this.fallback ?? this.remote;
|
|
396
|
+
if (engine) return action(engine);
|
|
397
|
+
}).catch(this.fail);
|
|
398
|
+
}
|
|
399
|
+
fallbackCallbacks() {
|
|
400
|
+
return {
|
|
401
|
+
...this.handlers,
|
|
402
|
+
onArbMarket: (msg) => this.event("onArbMarket", [msg]),
|
|
403
|
+
onArbFeed: (msg) => this.event("onArbFeed", [msg])
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
syncFallback() {
|
|
407
|
+
for (const [key, unsubscribe] of this.fallbackUnsubs) if (!this.refs.has(key)) {
|
|
408
|
+
unsubscribe();
|
|
409
|
+
this.fallbackUnsubs.delete(key);
|
|
410
|
+
}
|
|
411
|
+
for (const [key, { sub }] of this.refs) {
|
|
412
|
+
if (this.fallbackUnsubs.has(key)) continue;
|
|
413
|
+
this.fallbackUnsubs.set(key, sub.channel === "arb" ? this.fallback.subscribeArb(sub.id, () => {}) : sub.channel === "arb-feed" ? this.fallback.subscribeArbFeed(() => {}) : this.fallback.subscribe(sub.id, sub.channel));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
781
416
|
};
|
|
782
417
|
function createWorkerWebSocket(options, factory) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
return new AggWebSocket(options);
|
|
790
|
-
}
|
|
418
|
+
if (options.callbacks?.onTrade && !options.callbacks.onMarketView) return new AggWebSocket(options);
|
|
419
|
+
try {
|
|
420
|
+
return new WorkerAggWebSocket(options, factory);
|
|
421
|
+
} catch {
|
|
422
|
+
return new AggWebSocket(options);
|
|
423
|
+
}
|
|
791
424
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
createWorkerWebSocket
|
|
795
|
-
};
|
|
796
|
-
/*! Bundled license information:
|
|
425
|
+
//#endregion
|
|
426
|
+
export { WorkerAggWebSocket, createWorkerWebSocket };
|
|
797
427
|
|
|
798
|
-
|
|
799
|
-
(**
|
|
800
|
-
* @license
|
|
801
|
-
* Copyright 2019 Google LLC
|
|
802
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
803
|
-
*)
|
|
804
|
-
*/
|
|
428
|
+
//# sourceMappingURL=browser.mjs.map
|