@openfeed/sdk-js 1.6.9 → 1.6.11
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.11";
|
package/dist/index.js
CHANGED
|
@@ -39,19 +39,19 @@ function varint64read() {
|
|
|
39
39
|
}
|
|
40
40
|
throw new Error("invalid varint");
|
|
41
41
|
}
|
|
42
|
-
function varint64write(lo, hi,
|
|
42
|
+
function varint64write(lo, hi, bytes2) {
|
|
43
43
|
for (let i = 0; i < 28; i = i + 7) {
|
|
44
44
|
const shift = lo >>> i;
|
|
45
45
|
const hasNext = !(shift >>> 7 == 0 && hi == 0);
|
|
46
46
|
const byte = (hasNext ? shift | 128 : shift) & 255;
|
|
47
|
-
|
|
47
|
+
bytes2.push(byte);
|
|
48
48
|
if (!hasNext) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
const splitBits = lo >>> 28 & 15 | (hi & 7) << 4;
|
|
53
53
|
const hasMoreBits = !(hi >> 3 == 0);
|
|
54
|
-
|
|
54
|
+
bytes2.push((hasMoreBits ? splitBits | 128 : splitBits) & 255);
|
|
55
55
|
if (!hasMoreBits) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
@@ -59,12 +59,12 @@ function varint64write(lo, hi, bytes) {
|
|
|
59
59
|
const shift = hi >>> i;
|
|
60
60
|
const hasNext = !(shift >>> 7 == 0);
|
|
61
61
|
const byte = (hasNext ? shift | 128 : shift) & 255;
|
|
62
|
-
|
|
62
|
+
bytes2.push(byte);
|
|
63
63
|
if (!hasNext) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
bytes2.push(hi >>> 31 & 1);
|
|
68
68
|
}
|
|
69
69
|
const TWO_PWR_32_DBL$1 = 4294967296;
|
|
70
70
|
function int64FromString(dec) {
|
|
@@ -140,19 +140,19 @@ const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
|
|
|
140
140
|
const partial = String(digit1e7);
|
|
141
141
|
return "0000000".slice(partial.length) + partial;
|
|
142
142
|
};
|
|
143
|
-
function varint32write(value,
|
|
143
|
+
function varint32write(value, bytes2) {
|
|
144
144
|
if (value >= 0) {
|
|
145
145
|
while (value > 127) {
|
|
146
|
-
|
|
146
|
+
bytes2.push(value & 127 | 128);
|
|
147
147
|
value = value >>> 7;
|
|
148
148
|
}
|
|
149
|
-
|
|
149
|
+
bytes2.push(value);
|
|
150
150
|
} else {
|
|
151
151
|
for (let i = 0; i < 9; i++) {
|
|
152
|
-
|
|
152
|
+
bytes2.push(value & 127 | 128);
|
|
153
153
|
value = value >> 7;
|
|
154
154
|
}
|
|
155
|
-
|
|
155
|
+
bytes2.push(1);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
function varint32read() {
|
|
@@ -299,8 +299,8 @@ function getTextEncoding() {
|
|
|
299
299
|
encodeUtf8(text) {
|
|
300
300
|
return te.encode(text);
|
|
301
301
|
},
|
|
302
|
-
decodeUtf8(
|
|
303
|
-
return td.decode(
|
|
302
|
+
decodeUtf8(bytes2) {
|
|
303
|
+
return td.decode(bytes2);
|
|
304
304
|
},
|
|
305
305
|
checkUtf8(text) {
|
|
306
306
|
try {
|
|
@@ -346,14 +346,14 @@ class BinaryWriter {
|
|
|
346
346
|
let len = 0;
|
|
347
347
|
for (let i = 0; i < this.chunks.length; i++)
|
|
348
348
|
len += this.chunks[i].length;
|
|
349
|
-
let
|
|
349
|
+
let bytes2 = new Uint8Array(len);
|
|
350
350
|
let offset = 0;
|
|
351
351
|
for (let i = 0; i < this.chunks.length; i++) {
|
|
352
|
-
|
|
352
|
+
bytes2.set(this.chunks[i], offset);
|
|
353
353
|
offset += this.chunks[i].length;
|
|
354
354
|
}
|
|
355
355
|
this.chunks = [];
|
|
356
|
-
return
|
|
356
|
+
return bytes2;
|
|
357
357
|
}
|
|
358
358
|
/**
|
|
359
359
|
* Start a new fork for length-delimited data like a message
|
|
@@ -1608,20 +1608,20 @@ LongPrototype.toBytesBE = function toBytesBE() {
|
|
|
1608
1608
|
lo & 255
|
|
1609
1609
|
];
|
|
1610
1610
|
};
|
|
1611
|
-
Long.fromBytes = function fromBytes(
|
|
1612
|
-
return le ? Long.fromBytesLE(
|
|
1611
|
+
Long.fromBytes = function fromBytes(bytes2, unsigned, le) {
|
|
1612
|
+
return le ? Long.fromBytesLE(bytes2, unsigned) : Long.fromBytesBE(bytes2, unsigned);
|
|
1613
1613
|
};
|
|
1614
|
-
Long.fromBytesLE = function fromBytesLE(
|
|
1614
|
+
Long.fromBytesLE = function fromBytesLE(bytes2, unsigned) {
|
|
1615
1615
|
return new Long(
|
|
1616
|
-
|
|
1617
|
-
|
|
1616
|
+
bytes2[0] | bytes2[1] << 8 | bytes2[2] << 16 | bytes2[3] << 24,
|
|
1617
|
+
bytes2[4] | bytes2[5] << 8 | bytes2[6] << 16 | bytes2[7] << 24,
|
|
1618
1618
|
unsigned
|
|
1619
1619
|
);
|
|
1620
1620
|
};
|
|
1621
|
-
Long.fromBytesBE = function fromBytesBE(
|
|
1621
|
+
Long.fromBytesBE = function fromBytesBE(bytes2, unsigned) {
|
|
1622
1622
|
return new Long(
|
|
1623
|
-
|
|
1624
|
-
|
|
1623
|
+
bytes2[4] << 24 | bytes2[5] << 16 | bytes2[6] << 8 | bytes2[7],
|
|
1624
|
+
bytes2[0] << 24 | bytes2[1] << 16 | bytes2[2] << 8 | bytes2[3],
|
|
1625
1625
|
unsigned
|
|
1626
1626
|
);
|
|
1627
1627
|
};
|
|
@@ -11496,33 +11496,33 @@ const toT = (obj) => obj;
|
|
|
11496
11496
|
function encodeMessage(message) {
|
|
11497
11497
|
return OpenfeedGatewayRequestEncode.encode(message).finish();
|
|
11498
11498
|
}
|
|
11499
|
-
function decodeRequestMessage(
|
|
11500
|
-
return OpenfeedGatewayRequestDecode.decode(
|
|
11499
|
+
function decodeRequestMessage(bytes2) {
|
|
11500
|
+
return OpenfeedGatewayRequestDecode.decode(bytes2);
|
|
11501
11501
|
}
|
|
11502
|
-
const
|
|
11503
|
-
|
|
11504
|
-
|
|
11502
|
+
const bytes = new Uint8Array(2);
|
|
11503
|
+
bytes[0] = 0;
|
|
11504
|
+
bytes[1] = 0;
|
|
11505
11505
|
function encodeResponseMessage(message) {
|
|
11506
11506
|
const bw = new BinaryWriter();
|
|
11507
|
-
bw.raw(
|
|
11507
|
+
bw.raw(bytes);
|
|
11508
11508
|
OpenfeedGatewayMessageEncode.encode(message, bw);
|
|
11509
|
-
const
|
|
11510
|
-
const len =
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
return
|
|
11509
|
+
const ret = bw.finish();
|
|
11510
|
+
const len = ret.length - 2;
|
|
11511
|
+
ret[0] = len >> 8;
|
|
11512
|
+
ret[1] = len & 255;
|
|
11513
|
+
return ret;
|
|
11514
11514
|
}
|
|
11515
11515
|
function send(socket, message) {
|
|
11516
11516
|
socket.send(encodeMessage(toT(message)));
|
|
11517
11517
|
}
|
|
11518
11518
|
const getShort = (a, b) => a << 8 | b << 0;
|
|
11519
|
-
function* decodeMessages(
|
|
11519
|
+
function* decodeMessages(bytes2) {
|
|
11520
11520
|
let currentIndex = 0;
|
|
11521
|
-
while (currentIndex <
|
|
11522
|
-
const len = getShort(
|
|
11521
|
+
while (currentIndex < bytes2.length) {
|
|
11522
|
+
const len = getShort(bytes2[currentIndex], bytes2[currentIndex + 1]);
|
|
11523
11523
|
if (len === 0) break;
|
|
11524
11524
|
const total = len + 2;
|
|
11525
|
-
const currentArray =
|
|
11525
|
+
const currentArray = bytes2.subarray(currentIndex + 2, currentIndex + total);
|
|
11526
11526
|
currentIndex += total;
|
|
11527
11527
|
yield OpenfeedGatewayMessageDecode.decode(currentArray);
|
|
11528
11528
|
}
|
|
@@ -11551,6 +11551,9 @@ class ConnectionDisposedError extends Error {
|
|
|
11551
11551
|
return this.constructor.name;
|
|
11552
11552
|
}
|
|
11553
11553
|
}
|
|
11554
|
+
function toStringOrNumber(id) {
|
|
11555
|
+
return id.isSafeInteger() ? id.toInt() : id.toString();
|
|
11556
|
+
}
|
|
11554
11557
|
class OpenFeedConnection {
|
|
11555
11558
|
constructor(connectionToken, socket, listeners, logger) {
|
|
11556
11559
|
this.connectionToken = connectionToken;
|
|
@@ -11562,11 +11565,11 @@ class OpenFeedConnection {
|
|
|
11562
11565
|
this.socket.onclose = this.onClose;
|
|
11563
11566
|
this.runConnectionWatchLoop();
|
|
11564
11567
|
}
|
|
11565
|
-
subscriptionRequests = /* @__PURE__ */ new Map();
|
|
11566
|
-
exchangeRequests = /* @__PURE__ */ new Map();
|
|
11567
|
-
instrumentRequests = /* @__PURE__ */ new Map();
|
|
11568
|
-
definitionsInFlight = /* @__PURE__ */ new Map();
|
|
11569
|
-
instrumentReferenceRequests = /* @__PURE__ */ new Map();
|
|
11568
|
+
#subscriptionRequests = /* @__PURE__ */ new Map();
|
|
11569
|
+
#exchangeRequests = /* @__PURE__ */ new Map();
|
|
11570
|
+
#instrumentRequests = /* @__PURE__ */ new Map();
|
|
11571
|
+
#definitionsInFlight = /* @__PURE__ */ new Map();
|
|
11572
|
+
#instrumentReferenceRequests = /* @__PURE__ */ new Map();
|
|
11570
11573
|
whenDisconnectedSource = new ResolutionSource();
|
|
11571
11574
|
messageTriggered = false;
|
|
11572
11575
|
runConnectionWatchLoop = async () => {
|
|
@@ -11609,45 +11612,38 @@ class OpenFeedConnection {
|
|
|
11609
11612
|
}
|
|
11610
11613
|
if (message.instrumentResponse) {
|
|
11611
11614
|
const { correlationId, instrumentDefinition, numberOfDefinitions } = message.instrumentResponse;
|
|
11612
|
-
const
|
|
11613
|
-
const request = this
|
|
11614
|
-
if (!request) throw new Error(`Instrument request ID ${
|
|
11615
|
-
if (!instrumentDefinition) throw new Error(`Instrument definition not found in response ID ${
|
|
11616
|
-
let definitions = this
|
|
11615
|
+
const id = toStringOrNumber(correlationId);
|
|
11616
|
+
const request = this.#instrumentRequests.get(id);
|
|
11617
|
+
if (!request) throw new Error(`Instrument request ID ${id} not found`);
|
|
11618
|
+
if (!instrumentDefinition) throw new Error(`Instrument definition not found in response ID ${id}`);
|
|
11619
|
+
let definitions = this.#definitionsInFlight.get(id);
|
|
11617
11620
|
if (!definitions) {
|
|
11618
11621
|
definitions = [instrumentDefinition];
|
|
11619
11622
|
} else {
|
|
11620
11623
|
definitions.push(instrumentDefinition);
|
|
11621
11624
|
}
|
|
11622
11625
|
if (definitions.length === numberOfDefinitions) {
|
|
11623
|
-
this
|
|
11626
|
+
this.#definitionsInFlight.delete(id);
|
|
11624
11627
|
request.resolve(definitions);
|
|
11625
11628
|
} else {
|
|
11626
|
-
this
|
|
11629
|
+
this.#definitionsInFlight.set(id, definitions);
|
|
11627
11630
|
}
|
|
11628
|
-
continue;
|
|
11629
11631
|
}
|
|
11630
11632
|
if (message.instrumentReferenceResponse) {
|
|
11631
11633
|
const { correlationId } = message.instrumentReferenceResponse;
|
|
11632
|
-
const request = this
|
|
11633
|
-
|
|
11634
|
-
request.resolve(message.instrumentReferenceResponse);
|
|
11635
|
-
continue;
|
|
11634
|
+
const request = this.#instrumentReferenceRequests.get(toStringOrNumber(correlationId));
|
|
11635
|
+
request?.resolve(message.instrumentReferenceResponse);
|
|
11636
11636
|
}
|
|
11637
11637
|
if (message.exchangeResponse) {
|
|
11638
11638
|
const { correlationId } = message.exchangeResponse;
|
|
11639
|
-
const request = this
|
|
11640
|
-
|
|
11641
|
-
request.resolve(message.exchangeResponse);
|
|
11642
|
-
continue;
|
|
11639
|
+
const request = this.#exchangeRequests.get(toStringOrNumber(correlationId));
|
|
11640
|
+
request?.resolve(message.exchangeResponse);
|
|
11643
11641
|
}
|
|
11644
11642
|
if (message.subscriptionResponse) {
|
|
11645
11643
|
const { correlationId, unsubscribe } = message.subscriptionResponse;
|
|
11646
11644
|
if (!unsubscribe) {
|
|
11647
|
-
const request = this
|
|
11648
|
-
|
|
11649
|
-
const [, sub] = request;
|
|
11650
|
-
sub.resolve();
|
|
11645
|
+
const request = this.#subscriptionRequests.get(toStringOrNumber(correlationId));
|
|
11646
|
+
request?.[1].resolve();
|
|
11651
11647
|
}
|
|
11652
11648
|
}
|
|
11653
11649
|
this.listeners.onMessage(message);
|
|
@@ -11668,9 +11664,9 @@ class OpenFeedConnection {
|
|
|
11668
11664
|
request.reject(error);
|
|
11669
11665
|
}
|
|
11670
11666
|
};
|
|
11671
|
-
cleanRequests(this
|
|
11672
|
-
cleanRequests(this
|
|
11673
|
-
cleanRequests(this
|
|
11667
|
+
cleanRequests(this.#exchangeRequests);
|
|
11668
|
+
cleanRequests(this.#instrumentRequests);
|
|
11669
|
+
cleanRequests(this.#instrumentReferenceRequests);
|
|
11674
11670
|
this.socket.close(1e3, error.message);
|
|
11675
11671
|
this.whenDisconnectedSource.reject(error);
|
|
11676
11672
|
}
|
|
@@ -11741,7 +11737,7 @@ class OpenFeedConnection {
|
|
|
11741
11737
|
unsubscribe: false
|
|
11742
11738
|
};
|
|
11743
11739
|
const source = new ResolutionSource();
|
|
11744
|
-
this
|
|
11740
|
+
this.#subscriptionRequests.set(toStringOrNumber(correlationId), [subscriptionRequest, source]);
|
|
11745
11741
|
send(this.socket, { subscriptionRequest });
|
|
11746
11742
|
return correlationId;
|
|
11747
11743
|
};
|
|
@@ -11749,7 +11745,7 @@ class OpenFeedConnection {
|
|
|
11749
11745
|
if (this.whenDisconnectedSource.completed) {
|
|
11750
11746
|
throw new ConnectionDisposedError("This connection was closed");
|
|
11751
11747
|
}
|
|
11752
|
-
const subscription = this
|
|
11748
|
+
const subscription = this.#subscriptionRequests.get(toStringOrNumber(subscriptionId));
|
|
11753
11749
|
if (!subscription) {
|
|
11754
11750
|
throw new Error(`Subscription ID ${subscriptionId} does not exist.`);
|
|
11755
11751
|
}
|
|
@@ -11765,7 +11761,7 @@ class OpenFeedConnection {
|
|
|
11765
11761
|
send(this.socket, { subscriptionRequest });
|
|
11766
11762
|
} catch (e) {
|
|
11767
11763
|
} finally {
|
|
11768
|
-
this
|
|
11764
|
+
this.#subscriptionRequests.delete(toStringOrNumber(originalRequest.correlationId));
|
|
11769
11765
|
}
|
|
11770
11766
|
}
|
|
11771
11767
|
send = (msg, correlationId) => {
|
|
@@ -11786,7 +11782,7 @@ class OpenFeedConnection {
|
|
|
11786
11782
|
}
|
|
11787
11783
|
const correlationId = CorrelationId.create();
|
|
11788
11784
|
const source = new ResolutionSource();
|
|
11789
|
-
this
|
|
11785
|
+
this.#exchangeRequests.set(toStringOrNumber(correlationId), source);
|
|
11790
11786
|
try {
|
|
11791
11787
|
const exchangeRequest = {
|
|
11792
11788
|
correlationId,
|
|
@@ -11799,7 +11795,7 @@ class OpenFeedConnection {
|
|
|
11799
11795
|
this.logger?.error(error);
|
|
11800
11796
|
throw error;
|
|
11801
11797
|
} finally {
|
|
11802
|
-
this
|
|
11798
|
+
this.#exchangeRequests.delete(toStringOrNumber(correlationId));
|
|
11803
11799
|
}
|
|
11804
11800
|
};
|
|
11805
11801
|
getInstrument = async (request) => {
|
|
@@ -11808,7 +11804,7 @@ class OpenFeedConnection {
|
|
|
11808
11804
|
}
|
|
11809
11805
|
const correlationId = CorrelationId.create();
|
|
11810
11806
|
const source = new ResolutionSource();
|
|
11811
|
-
this
|
|
11807
|
+
this.#instrumentRequests.set(toStringOrNumber(correlationId), source);
|
|
11812
11808
|
try {
|
|
11813
11809
|
const instrumentRequest = toT({
|
|
11814
11810
|
...request,
|
|
@@ -11823,7 +11819,7 @@ class OpenFeedConnection {
|
|
|
11823
11819
|
this.logger?.error(error);
|
|
11824
11820
|
throw error;
|
|
11825
11821
|
} finally {
|
|
11826
|
-
this
|
|
11822
|
+
this.#instrumentRequests.delete(toStringOrNumber(correlationId));
|
|
11827
11823
|
}
|
|
11828
11824
|
};
|
|
11829
11825
|
getInstrumentReference = async (request) => {
|
|
@@ -11832,7 +11828,7 @@ class OpenFeedConnection {
|
|
|
11832
11828
|
}
|
|
11833
11829
|
const correlationId = CorrelationId.create();
|
|
11834
11830
|
const source = new ResolutionSource();
|
|
11835
|
-
this
|
|
11831
|
+
this.#instrumentReferenceRequests.set(toStringOrNumber(correlationId), source);
|
|
11836
11832
|
try {
|
|
11837
11833
|
const instrumentReferenceRequest = toT({ ...request, correlationId, token: this.connectionToken });
|
|
11838
11834
|
send(this.socket, { instrumentReferenceRequest });
|
|
@@ -11842,13 +11838,13 @@ class OpenFeedConnection {
|
|
|
11842
11838
|
this.logger?.error(error);
|
|
11843
11839
|
throw error;
|
|
11844
11840
|
} finally {
|
|
11845
|
-
this
|
|
11841
|
+
this.#instrumentRequests.delete(toStringOrNumber(correlationId));
|
|
11846
11842
|
}
|
|
11847
11843
|
};
|
|
11848
11844
|
whenDisconnected = () => this.whenDisconnectedSource.whenCompleted;
|
|
11849
11845
|
dispose = () => this.disconnect(new ConnectionDisposedError("Disposed"));
|
|
11850
11846
|
}
|
|
11851
|
-
const version = "1.6.
|
|
11847
|
+
const version = "1.6.11";
|
|
11852
11848
|
const getClientVersion = async (clientId) => {
|
|
11853
11849
|
let platformDescription;
|
|
11854
11850
|
if (typeof window !== "undefined") {
|
|
@@ -12078,19 +12074,14 @@ const IDGetters = [
|
|
|
12078
12074
|
class OpenFeedListeners {
|
|
12079
12075
|
instrumentByMarketId = /* @__PURE__ */ new Map();
|
|
12080
12076
|
constructor() {
|
|
12081
|
-
this.onMessage = this
|
|
12082
|
-
this.onCleanup = this
|
|
12077
|
+
this.onMessage = this.#addDetails;
|
|
12078
|
+
this.onCleanup = this.#cleanUp;
|
|
12083
12079
|
}
|
|
12084
|
-
cleanUp = () =>
|
|
12085
|
-
|
|
12086
|
-
};
|
|
12087
|
-
addDetails = (message) => {
|
|
12080
|
+
#cleanUp = () => this.instrumentByMarketId.clear();
|
|
12081
|
+
#addDetails = (message) => {
|
|
12088
12082
|
let def;
|
|
12089
12083
|
let symbols;
|
|
12090
|
-
const getInstrumentDefinition = (marketId) =>
|
|
12091
|
-
const res = this.instrumentByMarketId.get(marketId.toString());
|
|
12092
|
-
return res ?? [void 0, void 0];
|
|
12093
|
-
};
|
|
12084
|
+
const getInstrumentDefinition = (marketId) => this.instrumentByMarketId.get(marketId.toString()) ?? [void 0, void 0];
|
|
12094
12085
|
const includesSymbolSubscription = (arr, item) => {
|
|
12095
12086
|
return arr.some(([symbol2, correlationId]) => symbol2 === item[0] && correlationId === item[1]);
|
|
12096
12087
|
};
|
package/dist/node.js
CHANGED
|
@@ -3702,19 +3702,19 @@ function varint64read() {
|
|
|
3702
3702
|
}
|
|
3703
3703
|
throw new Error("invalid varint");
|
|
3704
3704
|
}
|
|
3705
|
-
function varint64write(lo, hi,
|
|
3705
|
+
function varint64write(lo, hi, bytes2) {
|
|
3706
3706
|
for (let i = 0; i < 28; i = i + 7) {
|
|
3707
3707
|
const shift = lo >>> i;
|
|
3708
3708
|
const hasNext = !(shift >>> 7 == 0 && hi == 0);
|
|
3709
3709
|
const byte = (hasNext ? shift | 128 : shift) & 255;
|
|
3710
|
-
|
|
3710
|
+
bytes2.push(byte);
|
|
3711
3711
|
if (!hasNext) {
|
|
3712
3712
|
return;
|
|
3713
3713
|
}
|
|
3714
3714
|
}
|
|
3715
3715
|
const splitBits = lo >>> 28 & 15 | (hi & 7) << 4;
|
|
3716
3716
|
const hasMoreBits = !(hi >> 3 == 0);
|
|
3717
|
-
|
|
3717
|
+
bytes2.push((hasMoreBits ? splitBits | 128 : splitBits) & 255);
|
|
3718
3718
|
if (!hasMoreBits) {
|
|
3719
3719
|
return;
|
|
3720
3720
|
}
|
|
@@ -3722,12 +3722,12 @@ function varint64write(lo, hi, bytes) {
|
|
|
3722
3722
|
const shift = hi >>> i;
|
|
3723
3723
|
const hasNext = !(shift >>> 7 == 0);
|
|
3724
3724
|
const byte = (hasNext ? shift | 128 : shift) & 255;
|
|
3725
|
-
|
|
3725
|
+
bytes2.push(byte);
|
|
3726
3726
|
if (!hasNext) {
|
|
3727
3727
|
return;
|
|
3728
3728
|
}
|
|
3729
3729
|
}
|
|
3730
|
-
|
|
3730
|
+
bytes2.push(hi >>> 31 & 1);
|
|
3731
3731
|
}
|
|
3732
3732
|
var TWO_PWR_32_DBL = 4294967296;
|
|
3733
3733
|
function int64FromString(dec) {
|
|
@@ -3803,19 +3803,19 @@ var decimalFrom1e7WithLeadingZeros = (digit1e7) => {
|
|
|
3803
3803
|
const partial = String(digit1e7);
|
|
3804
3804
|
return "0000000".slice(partial.length) + partial;
|
|
3805
3805
|
};
|
|
3806
|
-
function varint32write(value,
|
|
3806
|
+
function varint32write(value, bytes2) {
|
|
3807
3807
|
if (value >= 0) {
|
|
3808
3808
|
while (value > 127) {
|
|
3809
|
-
|
|
3809
|
+
bytes2.push(value & 127 | 128);
|
|
3810
3810
|
value = value >>> 7;
|
|
3811
3811
|
}
|
|
3812
|
-
|
|
3812
|
+
bytes2.push(value);
|
|
3813
3813
|
} else {
|
|
3814
3814
|
for (let i = 0; i < 9; i++) {
|
|
3815
|
-
|
|
3815
|
+
bytes2.push(value & 127 | 128);
|
|
3816
3816
|
value = value >> 7;
|
|
3817
3817
|
}
|
|
3818
|
-
|
|
3818
|
+
bytes2.push(1);
|
|
3819
3819
|
}
|
|
3820
3820
|
}
|
|
3821
3821
|
function varint32read() {
|
|
@@ -3966,8 +3966,8 @@ function getTextEncoding() {
|
|
|
3966
3966
|
encodeUtf8(text) {
|
|
3967
3967
|
return te.encode(text);
|
|
3968
3968
|
},
|
|
3969
|
-
decodeUtf8(
|
|
3970
|
-
return td.decode(
|
|
3969
|
+
decodeUtf8(bytes2) {
|
|
3970
|
+
return td.decode(bytes2);
|
|
3971
3971
|
},
|
|
3972
3972
|
checkUtf8(text) {
|
|
3973
3973
|
try {
|
|
@@ -4015,14 +4015,14 @@ var BinaryWriter = class {
|
|
|
4015
4015
|
let len = 0;
|
|
4016
4016
|
for (let i = 0; i < this.chunks.length; i++)
|
|
4017
4017
|
len += this.chunks[i].length;
|
|
4018
|
-
let
|
|
4018
|
+
let bytes2 = new Uint8Array(len);
|
|
4019
4019
|
let offset = 0;
|
|
4020
4020
|
for (let i = 0; i < this.chunks.length; i++) {
|
|
4021
|
-
|
|
4021
|
+
bytes2.set(this.chunks[i], offset);
|
|
4022
4022
|
offset += this.chunks[i].length;
|
|
4023
4023
|
}
|
|
4024
4024
|
this.chunks = [];
|
|
4025
|
-
return
|
|
4025
|
+
return bytes2;
|
|
4026
4026
|
}
|
|
4027
4027
|
/**
|
|
4028
4028
|
* Start a new fork for length-delimited data like a message
|
|
@@ -5279,20 +5279,20 @@ LongPrototype.toBytesBE = function toBytesBE() {
|
|
|
5279
5279
|
lo & 255
|
|
5280
5280
|
];
|
|
5281
5281
|
};
|
|
5282
|
-
Long.fromBytes = function fromBytes(
|
|
5283
|
-
return le ? Long.fromBytesLE(
|
|
5282
|
+
Long.fromBytes = function fromBytes(bytes2, unsigned, le) {
|
|
5283
|
+
return le ? Long.fromBytesLE(bytes2, unsigned) : Long.fromBytesBE(bytes2, unsigned);
|
|
5284
5284
|
};
|
|
5285
|
-
Long.fromBytesLE = function fromBytesLE(
|
|
5285
|
+
Long.fromBytesLE = function fromBytesLE(bytes2, unsigned) {
|
|
5286
5286
|
return new Long(
|
|
5287
|
-
|
|
5288
|
-
|
|
5287
|
+
bytes2[0] | bytes2[1] << 8 | bytes2[2] << 16 | bytes2[3] << 24,
|
|
5288
|
+
bytes2[4] | bytes2[5] << 8 | bytes2[6] << 16 | bytes2[7] << 24,
|
|
5289
5289
|
unsigned
|
|
5290
5290
|
);
|
|
5291
5291
|
};
|
|
5292
|
-
Long.fromBytesBE = function fromBytesBE(
|
|
5292
|
+
Long.fromBytesBE = function fromBytesBE(bytes2, unsigned) {
|
|
5293
5293
|
return new Long(
|
|
5294
|
-
|
|
5295
|
-
|
|
5294
|
+
bytes2[4] << 24 | bytes2[5] << 16 | bytes2[6] << 8 | bytes2[7],
|
|
5295
|
+
bytes2[0] << 24 | bytes2[1] << 16 | bytes2[2] << 8 | bytes2[3],
|
|
5296
5296
|
unsigned
|
|
5297
5297
|
);
|
|
5298
5298
|
};
|
|
@@ -15276,33 +15276,33 @@ var toT = (obj) => obj;
|
|
|
15276
15276
|
function encodeMessage(message) {
|
|
15277
15277
|
return OpenfeedGatewayRequestEncode.encode(message).finish();
|
|
15278
15278
|
}
|
|
15279
|
-
function decodeRequestMessage(
|
|
15280
|
-
return OpenfeedGatewayRequestDecode.decode(
|
|
15279
|
+
function decodeRequestMessage(bytes2) {
|
|
15280
|
+
return OpenfeedGatewayRequestDecode.decode(bytes2);
|
|
15281
15281
|
}
|
|
15282
|
-
var
|
|
15283
|
-
|
|
15284
|
-
|
|
15282
|
+
var bytes = new Uint8Array(2);
|
|
15283
|
+
bytes[0] = 0;
|
|
15284
|
+
bytes[1] = 0;
|
|
15285
15285
|
function encodeResponseMessage(message) {
|
|
15286
15286
|
const bw = new BinaryWriter();
|
|
15287
|
-
bw.raw(
|
|
15287
|
+
bw.raw(bytes);
|
|
15288
15288
|
OpenfeedGatewayMessageEncode.encode(message, bw);
|
|
15289
|
-
const
|
|
15290
|
-
const len =
|
|
15291
|
-
|
|
15292
|
-
|
|
15293
|
-
return
|
|
15289
|
+
const ret = bw.finish();
|
|
15290
|
+
const len = ret.length - 2;
|
|
15291
|
+
ret[0] = len >> 8;
|
|
15292
|
+
ret[1] = len & 255;
|
|
15293
|
+
return ret;
|
|
15294
15294
|
}
|
|
15295
15295
|
function send(socket, message) {
|
|
15296
15296
|
socket.send(encodeMessage(toT(message)));
|
|
15297
15297
|
}
|
|
15298
15298
|
var getShort = (a, b) => a << 8 | b << 0;
|
|
15299
|
-
function* decodeMessages(
|
|
15299
|
+
function* decodeMessages(bytes2) {
|
|
15300
15300
|
let currentIndex = 0;
|
|
15301
|
-
while (currentIndex <
|
|
15302
|
-
const len = getShort(
|
|
15301
|
+
while (currentIndex < bytes2.length) {
|
|
15302
|
+
const len = getShort(bytes2[currentIndex], bytes2[currentIndex + 1]);
|
|
15303
15303
|
if (len === 0) break;
|
|
15304
15304
|
const total = len + 2;
|
|
15305
|
-
const currentArray =
|
|
15305
|
+
const currentArray = bytes2.subarray(currentIndex + 2, currentIndex + total);
|
|
15306
15306
|
currentIndex += total;
|
|
15307
15307
|
yield OpenfeedGatewayMessageDecode.decode(currentArray);
|
|
15308
15308
|
}
|
|
@@ -15337,6 +15337,9 @@ var ConnectionDisposedError = class extends Error {
|
|
|
15337
15337
|
};
|
|
15338
15338
|
|
|
15339
15339
|
// src/connection/connection.ts
|
|
15340
|
+
function toStringOrNumber(id) {
|
|
15341
|
+
return id.isSafeInteger() ? id.toInt() : id.toString();
|
|
15342
|
+
}
|
|
15340
15343
|
var OpenFeedConnection = class {
|
|
15341
15344
|
constructor(connectionToken, socket, listeners, logger) {
|
|
15342
15345
|
this.connectionToken = connectionToken;
|
|
@@ -15348,11 +15351,11 @@ var OpenFeedConnection = class {
|
|
|
15348
15351
|
this.socket.onclose = this.onClose;
|
|
15349
15352
|
this.runConnectionWatchLoop();
|
|
15350
15353
|
}
|
|
15351
|
-
subscriptionRequests = /* @__PURE__ */ new Map();
|
|
15352
|
-
exchangeRequests = /* @__PURE__ */ new Map();
|
|
15353
|
-
instrumentRequests = /* @__PURE__ */ new Map();
|
|
15354
|
-
definitionsInFlight = /* @__PURE__ */ new Map();
|
|
15355
|
-
instrumentReferenceRequests = /* @__PURE__ */ new Map();
|
|
15354
|
+
#subscriptionRequests = /* @__PURE__ */ new Map();
|
|
15355
|
+
#exchangeRequests = /* @__PURE__ */ new Map();
|
|
15356
|
+
#instrumentRequests = /* @__PURE__ */ new Map();
|
|
15357
|
+
#definitionsInFlight = /* @__PURE__ */ new Map();
|
|
15358
|
+
#instrumentReferenceRequests = /* @__PURE__ */ new Map();
|
|
15356
15359
|
whenDisconnectedSource = new ResolutionSource();
|
|
15357
15360
|
messageTriggered = false;
|
|
15358
15361
|
runConnectionWatchLoop = async () => {
|
|
@@ -15397,45 +15400,38 @@ var OpenFeedConnection = class {
|
|
|
15397
15400
|
}
|
|
15398
15401
|
if (message.instrumentResponse) {
|
|
15399
15402
|
const { correlationId, instrumentDefinition, numberOfDefinitions } = message.instrumentResponse;
|
|
15400
|
-
const
|
|
15401
|
-
const request = this
|
|
15402
|
-
if (!request) throw new Error(`Instrument request ID ${
|
|
15403
|
-
if (!instrumentDefinition) throw new Error(`Instrument definition not found in response ID ${
|
|
15404
|
-
let definitions = this
|
|
15403
|
+
const id = toStringOrNumber(correlationId);
|
|
15404
|
+
const request = this.#instrumentRequests.get(id);
|
|
15405
|
+
if (!request) throw new Error(`Instrument request ID ${id} not found`);
|
|
15406
|
+
if (!instrumentDefinition) throw new Error(`Instrument definition not found in response ID ${id}`);
|
|
15407
|
+
let definitions = this.#definitionsInFlight.get(id);
|
|
15405
15408
|
if (!definitions) {
|
|
15406
15409
|
definitions = [instrumentDefinition];
|
|
15407
15410
|
} else {
|
|
15408
15411
|
definitions.push(instrumentDefinition);
|
|
15409
15412
|
}
|
|
15410
15413
|
if (definitions.length === numberOfDefinitions) {
|
|
15411
|
-
this
|
|
15414
|
+
this.#definitionsInFlight.delete(id);
|
|
15412
15415
|
request.resolve(definitions);
|
|
15413
15416
|
} else {
|
|
15414
|
-
this
|
|
15417
|
+
this.#definitionsInFlight.set(id, definitions);
|
|
15415
15418
|
}
|
|
15416
|
-
continue;
|
|
15417
15419
|
}
|
|
15418
15420
|
if (message.instrumentReferenceResponse) {
|
|
15419
15421
|
const { correlationId } = message.instrumentReferenceResponse;
|
|
15420
|
-
const request = this
|
|
15421
|
-
|
|
15422
|
-
request.resolve(message.instrumentReferenceResponse);
|
|
15423
|
-
continue;
|
|
15422
|
+
const request = this.#instrumentReferenceRequests.get(toStringOrNumber(correlationId));
|
|
15423
|
+
request == null ? void 0 : request.resolve(message.instrumentReferenceResponse);
|
|
15424
15424
|
}
|
|
15425
15425
|
if (message.exchangeResponse) {
|
|
15426
15426
|
const { correlationId } = message.exchangeResponse;
|
|
15427
|
-
const request = this
|
|
15428
|
-
|
|
15429
|
-
request.resolve(message.exchangeResponse);
|
|
15430
|
-
continue;
|
|
15427
|
+
const request = this.#exchangeRequests.get(toStringOrNumber(correlationId));
|
|
15428
|
+
request == null ? void 0 : request.resolve(message.exchangeResponse);
|
|
15431
15429
|
}
|
|
15432
15430
|
if (message.subscriptionResponse) {
|
|
15433
15431
|
const { correlationId, unsubscribe } = message.subscriptionResponse;
|
|
15434
15432
|
if (!unsubscribe) {
|
|
15435
|
-
const request = this
|
|
15436
|
-
|
|
15437
|
-
const [, sub] = request;
|
|
15438
|
-
sub.resolve();
|
|
15433
|
+
const request = this.#subscriptionRequests.get(toStringOrNumber(correlationId));
|
|
15434
|
+
request == null ? void 0 : request[1].resolve();
|
|
15439
15435
|
}
|
|
15440
15436
|
}
|
|
15441
15437
|
this.listeners.onMessage(message);
|
|
@@ -15456,9 +15452,9 @@ var OpenFeedConnection = class {
|
|
|
15456
15452
|
request.reject(error);
|
|
15457
15453
|
}
|
|
15458
15454
|
};
|
|
15459
|
-
cleanRequests(this
|
|
15460
|
-
cleanRequests(this
|
|
15461
|
-
cleanRequests(this
|
|
15455
|
+
cleanRequests(this.#exchangeRequests);
|
|
15456
|
+
cleanRequests(this.#instrumentRequests);
|
|
15457
|
+
cleanRequests(this.#instrumentReferenceRequests);
|
|
15462
15458
|
this.socket.close(1e3, error.message);
|
|
15463
15459
|
this.whenDisconnectedSource.reject(error);
|
|
15464
15460
|
}
|
|
@@ -15531,7 +15527,7 @@ var OpenFeedConnection = class {
|
|
|
15531
15527
|
unsubscribe: false
|
|
15532
15528
|
};
|
|
15533
15529
|
const source = new ResolutionSource();
|
|
15534
|
-
this
|
|
15530
|
+
this.#subscriptionRequests.set(toStringOrNumber(correlationId), [subscriptionRequest, source]);
|
|
15535
15531
|
send(this.socket, { subscriptionRequest });
|
|
15536
15532
|
return correlationId;
|
|
15537
15533
|
};
|
|
@@ -15539,7 +15535,7 @@ var OpenFeedConnection = class {
|
|
|
15539
15535
|
if (this.whenDisconnectedSource.completed) {
|
|
15540
15536
|
throw new ConnectionDisposedError("This connection was closed");
|
|
15541
15537
|
}
|
|
15542
|
-
const subscription = this
|
|
15538
|
+
const subscription = this.#subscriptionRequests.get(toStringOrNumber(subscriptionId));
|
|
15543
15539
|
if (!subscription) {
|
|
15544
15540
|
throw new Error(`Subscription ID ${subscriptionId} does not exist.`);
|
|
15545
15541
|
}
|
|
@@ -15555,7 +15551,7 @@ var OpenFeedConnection = class {
|
|
|
15555
15551
|
send(this.socket, { subscriptionRequest });
|
|
15556
15552
|
} catch (e) {
|
|
15557
15553
|
} finally {
|
|
15558
|
-
this
|
|
15554
|
+
this.#subscriptionRequests.delete(toStringOrNumber(originalRequest.correlationId));
|
|
15559
15555
|
}
|
|
15560
15556
|
}
|
|
15561
15557
|
send = (msg, correlationId) => {
|
|
@@ -15577,7 +15573,7 @@ var OpenFeedConnection = class {
|
|
|
15577
15573
|
}
|
|
15578
15574
|
const correlationId = CorrelationId.create();
|
|
15579
15575
|
const source = new ResolutionSource();
|
|
15580
|
-
this
|
|
15576
|
+
this.#exchangeRequests.set(toStringOrNumber(correlationId), source);
|
|
15581
15577
|
try {
|
|
15582
15578
|
const exchangeRequest = {
|
|
15583
15579
|
correlationId,
|
|
@@ -15590,7 +15586,7 @@ var OpenFeedConnection = class {
|
|
|
15590
15586
|
(_a = this.logger) == null ? void 0 : _a.error(error);
|
|
15591
15587
|
throw error;
|
|
15592
15588
|
} finally {
|
|
15593
|
-
this
|
|
15589
|
+
this.#exchangeRequests.delete(toStringOrNumber(correlationId));
|
|
15594
15590
|
}
|
|
15595
15591
|
};
|
|
15596
15592
|
getInstrument = async (request) => {
|
|
@@ -15600,7 +15596,7 @@ var OpenFeedConnection = class {
|
|
|
15600
15596
|
}
|
|
15601
15597
|
const correlationId = CorrelationId.create();
|
|
15602
15598
|
const source = new ResolutionSource();
|
|
15603
|
-
this
|
|
15599
|
+
this.#instrumentRequests.set(toStringOrNumber(correlationId), source);
|
|
15604
15600
|
try {
|
|
15605
15601
|
const instrumentRequest = toT({
|
|
15606
15602
|
...request,
|
|
@@ -15615,7 +15611,7 @@ var OpenFeedConnection = class {
|
|
|
15615
15611
|
(_a = this.logger) == null ? void 0 : _a.error(error);
|
|
15616
15612
|
throw error;
|
|
15617
15613
|
} finally {
|
|
15618
|
-
this
|
|
15614
|
+
this.#instrumentRequests.delete(toStringOrNumber(correlationId));
|
|
15619
15615
|
}
|
|
15620
15616
|
};
|
|
15621
15617
|
getInstrumentReference = async (request) => {
|
|
@@ -15625,7 +15621,7 @@ var OpenFeedConnection = class {
|
|
|
15625
15621
|
}
|
|
15626
15622
|
const correlationId = CorrelationId.create();
|
|
15627
15623
|
const source = new ResolutionSource();
|
|
15628
|
-
this
|
|
15624
|
+
this.#instrumentReferenceRequests.set(toStringOrNumber(correlationId), source);
|
|
15629
15625
|
try {
|
|
15630
15626
|
const instrumentReferenceRequest = toT({ ...request, correlationId, token: this.connectionToken });
|
|
15631
15627
|
send(this.socket, { instrumentReferenceRequest });
|
|
@@ -15635,7 +15631,7 @@ var OpenFeedConnection = class {
|
|
|
15635
15631
|
(_a = this.logger) == null ? void 0 : _a.error(error);
|
|
15636
15632
|
throw error;
|
|
15637
15633
|
} finally {
|
|
15638
|
-
this
|
|
15634
|
+
this.#instrumentRequests.delete(toStringOrNumber(correlationId));
|
|
15639
15635
|
}
|
|
15640
15636
|
};
|
|
15641
15637
|
whenDisconnected = () => this.whenDisconnectedSource.whenCompleted;
|
|
@@ -15643,7 +15639,7 @@ var OpenFeedConnection = class {
|
|
|
15643
15639
|
};
|
|
15644
15640
|
|
|
15645
15641
|
// generated/version.ts
|
|
15646
|
-
var version = "1.6.
|
|
15642
|
+
var version = "1.6.11";
|
|
15647
15643
|
|
|
15648
15644
|
// src/utilities/client_version.ts
|
|
15649
15645
|
var getClientVersion = async (clientId) => {
|
|
@@ -15897,20 +15893,15 @@ var IDGetters = [
|
|
|
15897
15893
|
var OpenFeedListeners = class {
|
|
15898
15894
|
instrumentByMarketId = /* @__PURE__ */ new Map();
|
|
15899
15895
|
constructor() {
|
|
15900
|
-
this.onMessage = this
|
|
15901
|
-
this.onCleanup = this
|
|
15896
|
+
this.onMessage = this.#addDetails;
|
|
15897
|
+
this.onCleanup = this.#cleanUp;
|
|
15902
15898
|
}
|
|
15903
|
-
cleanUp = () =>
|
|
15904
|
-
|
|
15905
|
-
};
|
|
15906
|
-
addDetails = (message) => {
|
|
15899
|
+
#cleanUp = () => this.instrumentByMarketId.clear();
|
|
15900
|
+
#addDetails = (message) => {
|
|
15907
15901
|
var _a, _b, _c;
|
|
15908
15902
|
let def;
|
|
15909
15903
|
let symbols;
|
|
15910
|
-
const getInstrumentDefinition = (marketId) =>
|
|
15911
|
-
const res = this.instrumentByMarketId.get(marketId.toString());
|
|
15912
|
-
return res ?? [void 0, void 0];
|
|
15913
|
-
};
|
|
15904
|
+
const getInstrumentDefinition = (marketId) => this.instrumentByMarketId.get(marketId.toString()) ?? [void 0, void 0];
|
|
15914
15905
|
const includesSymbolSubscription = (arr, item) => {
|
|
15915
15906
|
return arr.some(([symbol2, correlationId]) => symbol2 === item[0] && correlationId === item[1]);
|
|
15916
15907
|
};
|
|
@@ -6,15 +6,11 @@ import type { Service } from "@gen/openfeed";
|
|
|
6
6
|
import { IOpenFeedConnection, IOpenFeedLogger, OpenFeedInstrumentReferenceRequest, OpenFeedInstrumentRequest, OpenfeedRequest } from "./interfaces";
|
|
7
7
|
import { OpenFeedListeners } from "./listeners";
|
|
8
8
|
export declare class OpenFeedConnection implements IOpenFeedConnection {
|
|
9
|
+
#private;
|
|
9
10
|
private readonly connectionToken;
|
|
10
11
|
private readonly socket;
|
|
11
12
|
private readonly listeners;
|
|
12
13
|
private readonly logger?;
|
|
13
|
-
private readonly subscriptionRequests;
|
|
14
|
-
private readonly exchangeRequests;
|
|
15
|
-
private readonly instrumentRequests;
|
|
16
|
-
private readonly definitionsInFlight;
|
|
17
|
-
private readonly instrumentReferenceRequests;
|
|
18
14
|
private readonly whenDisconnectedSource;
|
|
19
15
|
constructor(connectionToken: string, socket: WebSocket, listeners: OpenFeedListeners, logger?: IOpenFeedLogger | undefined);
|
|
20
16
|
private messageTriggered;
|
|
@@ -4,10 +4,9 @@ import Long from "long";
|
|
|
4
4
|
import { HeartBeat } from "@gen/openfeed";
|
|
5
5
|
import { IOpenFeedConnection } from "./interfaces";
|
|
6
6
|
export declare class OpenFeedListeners {
|
|
7
|
+
#private;
|
|
7
8
|
private readonly instrumentByMarketId;
|
|
8
9
|
constructor();
|
|
9
|
-
private cleanUp;
|
|
10
|
-
private addDetails;
|
|
11
10
|
getInstrumentByMarketId: (marketId: Long) => InstrumentDefinition | undefined;
|
|
12
11
|
getSymbolsByMarketId: (marketId: Long) => string[];
|
|
13
12
|
onCleanup: () => void | Promise<void>;
|