tardis-dev 17.3.0 → 18.0.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/boundedqueue.d.ts +19 -0
- package/dist/boundedqueue.d.ts.map +1 -0
- package/dist/boundedqueue.js +96 -0
- package/dist/boundedqueue.js.map +1 -0
- package/dist/combine.d.ts +6 -4
- package/dist/combine.d.ts.map +1 -1
- package/dist/combine.js +8 -30
- package/dist/combine.js.map +1 -1
- package/dist/computable/computable.d.ts.map +1 -1
- package/dist/computable/computable.js +6 -6
- package/dist/computable/computable.js.map +1 -1
- package/dist/realtimefeeds/binance.d.ts.map +1 -1
- package/dist/realtimefeeds/binance.js +9 -0
- package/dist/realtimefeeds/binance.js.map +1 -1
- package/dist/realtimefeeds/binancedex.d.ts.map +1 -1
- package/dist/realtimefeeds/binancedex.js +3 -0
- package/dist/realtimefeeds/binancedex.js.map +1 -1
- package/dist/realtimefeeds/bitstamp.d.ts.map +1 -1
- package/dist/realtimefeeds/bitstamp.js +3 -0
- package/dist/realtimefeeds/bitstamp.js.map +1 -1
- package/dist/realtimefeeds/huobi.d.ts.map +1 -1
- package/dist/realtimefeeds/huobi.js +3 -0
- package/dist/realtimefeeds/huobi.js.map +1 -1
- package/dist/realtimefeeds/index.d.ts +0 -1
- package/dist/realtimefeeds/index.d.ts.map +1 -1
- package/dist/realtimefeeds/index.js +0 -3
- package/dist/realtimefeeds/index.js.map +1 -1
- package/dist/realtimefeeds/kucoin.d.ts.map +1 -1
- package/dist/realtimefeeds/kucoin.js +3 -0
- package/dist/realtimefeeds/kucoin.js.map +1 -1
- package/dist/realtimefeeds/kucoinfutures.d.ts.map +1 -1
- package/dist/realtimefeeds/kucoinfutures.js +3 -0
- package/dist/realtimefeeds/kucoinfutures.js.map +1 -1
- package/dist/realtimefeeds/realtimefeed.d.ts +17 -8
- package/dist/realtimefeeds/realtimefeed.d.ts.map +1 -1
- package/dist/realtimefeeds/realtimefeed.js +186 -111
- package/dist/realtimefeeds/realtimefeed.js.map +1 -1
- package/dist/realtimefeeds/woox.d.ts.map +1 -1
- package/dist/realtimefeeds/woox.js +3 -0
- package/dist/realtimefeeds/woox.js.map +1 -1
- package/dist/realtimeiterator.d.ts +10 -0
- package/dist/realtimeiterator.d.ts.map +1 -0
- package/dist/realtimeiterator.js +106 -0
- package/dist/realtimeiterator.js.map +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +50 -21
- package/dist/stream.js.map +1 -1
- package/package.json +1 -1
- package/src/boundedqueue.ts +118 -0
- package/src/combine.ts +15 -39
- package/src/computable/computable.ts +6 -5
- package/src/realtimefeeds/binance.ts +10 -0
- package/src/realtimefeeds/binancedex.ts +3 -0
- package/src/realtimefeeds/bitstamp.ts +3 -0
- package/src/realtimefeeds/huobi.ts +4 -0
- package/src/realtimefeeds/index.ts +0 -4
- package/src/realtimefeeds/kucoin.ts +3 -0
- package/src/realtimefeeds/kucoinfutures.ts +3 -0
- package/src/realtimefeeds/realtimefeed.ts +230 -125
- package/src/realtimefeeds/woox.ts +3 -0
- package/src/realtimeiterator.ts +124 -0
- package/src/stream.ts +66 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kucoin.js","sourceRoot":"","sources":["../../src/realtimefeeds/kucoin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAQ,MAAM,aAAa,CAAA;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEpD,MAAM,OAAO,kBAAmB,SAAQ,gBAAgB;IAC5C,MAAM,GAAG,EAAE,CAAA;IACb,QAAQ,GAAG,4BAA4B,CAAA;IAErC,KAAK,CAAC,eAAe;QAC7B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAM,GAAG,IAAI,CAAC,QAAQ,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,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cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAI/C,SAAS,CAAC,cAAc,aAKvB;IAED,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,GAAG;CAGtC;AAED,cAAM,kCAAmC,SAAQ,iBAAiB;IAG9D,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADzB,QAAQ,EAAE,MAAM,EACC,QAAQ,EAAE,MAAM;cAKnB,gBAAgB,CAAC,YAAY,EAAE,QAAQ;CAiBxD"}
|
|
@@ -58,6 +58,9 @@ export class KucoinFuturesSingleConnectionRealTimeFeed extends RealTimeFeedBase
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const { data } = await getJSON(`${this._httpURL}/v1/level2/snapshot?symbol=${symbol}`, kucoinHttpOptions);
|
|
61
|
+
if (shouldCancel()) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
61
64
|
const snapshot = {
|
|
62
65
|
type: 'message',
|
|
63
66
|
generated: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kucoinfutures.js","sourceRoot":"","sources":["../../src/realtimefeeds/kucoinfutures.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEhE,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAExG,MAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,EAAE,GAAG,IAAI;IAClB,KAAK,EAAE;QACL,KAAK,EAAE,EAAE;QACT,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;QACjC,aAAa,EAAE,GAAG,GAAG,IAAI;KAC1B;CACF,CAAA;AAED,MAAM,OAAO,yBAA0B,SAAQ,+BAA+B;IACpE,QAAQ,GAAG,oCAAoC,CAAA;IAE7C,CAAC,iBAAiB,CAAC,QAAgB,EAAE,OAAyB,EAA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SAAQ,iBAAiB;IAG7C;IAFnB,YACE,QAAgB,EACC,QAAgB;QAEjC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;QAFD,aAAQ,GAAR,QAAQ,CAAQ;IAGnC,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,YAAsB;QACrD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,MAAM,OAAO,CAAM,GAAG,IAAI,CAAC,QAAQ,sBAAsB,EAAE,iBAAiB,CAAC,CAAA;QAEpG,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,mBAAmB,GAAG;gBAC1B,KAAK,EAAE,qBAAqB,UAAU,CAAC,MAAM,EAAE;gBAC/C,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,iBAAiB;gBAC1B,SAAS,EAAE,IAAI;gBACf,IAAI,EAAE,UAAU;aACjB,CAAA;YAED,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;gBAC1B,YAAY,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAA;YACzC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import dbg from 'debug';
|
|
2
2
|
import { Writable } from 'stream';
|
|
3
|
+
import { type ManagedRealTimeIterator } from '../realtimeiterator.ts';
|
|
3
4
|
import { Exchange, Filter } from '../types.ts';
|
|
4
5
|
export type RealTimeFeed = {
|
|
5
6
|
new (exchange: Exchange, filters: Filter<string>[], timeoutIntervalMS: number | undefined, onError?: (error: Error) => void): RealTimeFeedIterable;
|
|
@@ -9,20 +10,21 @@ export declare abstract class RealTimeFeedBase implements RealTimeFeedIterable {
|
|
|
9
10
|
protected readonly _exchange: string;
|
|
10
11
|
private readonly _timeoutIntervalMS;
|
|
11
12
|
private readonly _onError?;
|
|
12
|
-
[Symbol.asyncIterator]():
|
|
13
|
+
[Symbol.asyncIterator](): ManagedRealTimeIterator<any>;
|
|
13
14
|
protected readonly debug: dbg.Debugger;
|
|
14
15
|
protected abstract readonly wssURL: string;
|
|
15
16
|
protected readonly throttleSubscribeMS: number;
|
|
16
17
|
protected readonly manualSnapshotsBuffer: any[];
|
|
17
18
|
private readonly _filters;
|
|
18
|
-
private _receivedMessagesCount;
|
|
19
|
-
private _ws?;
|
|
20
|
-
private _connectionId;
|
|
21
19
|
private _wsClientOptions;
|
|
20
|
+
private _closed;
|
|
21
|
+
private readonly _closeController;
|
|
22
|
+
private _connection?;
|
|
22
23
|
protected readonly originHeader: string | undefined;
|
|
23
24
|
protected readonly extraHeaders: Record<string, string> | undefined;
|
|
24
25
|
constructor(_exchange: string, filters: Filter<string>[], _timeoutIntervalMS: number | undefined, _onError?: ((error: Error) => void) | undefined);
|
|
25
26
|
protected getWebSocketUrl(): Promise<string>;
|
|
27
|
+
private _close;
|
|
26
28
|
private _stream;
|
|
27
29
|
protected send(msg: any): void;
|
|
28
30
|
protected sendRaw(msg: string | Buffer): void;
|
|
@@ -38,8 +40,14 @@ export declare abstract class RealTimeFeedBase implements RealTimeFeedIterable {
|
|
|
38
40
|
protected decompress?: (msg: any) => Buffer;
|
|
39
41
|
private _monitorConnectionIfStale;
|
|
40
42
|
private _sendPeriodicPing;
|
|
41
|
-
private
|
|
43
|
+
private _onConnectionEstablished;
|
|
42
44
|
private _onConnectionClosed;
|
|
45
|
+
private _onConnectionOpen;
|
|
46
|
+
private _send;
|
|
47
|
+
private _isConnectionActive;
|
|
48
|
+
private _isConnectionOpen;
|
|
49
|
+
private _closeConnection;
|
|
50
|
+
private _wait;
|
|
43
51
|
}
|
|
44
52
|
export declare abstract class MultiConnectionRealTimeFeedBase implements RealTimeFeedIterable {
|
|
45
53
|
private readonly _exchange;
|
|
@@ -47,8 +55,7 @@ export declare abstract class MultiConnectionRealTimeFeedBase implements RealTim
|
|
|
47
55
|
private readonly _timeoutIntervalMS;
|
|
48
56
|
private readonly _onError?;
|
|
49
57
|
constructor(_exchange: string, _filters: Filter<string>[], _timeoutIntervalMS: number | undefined, _onError?: ((error: Error) => void) | undefined);
|
|
50
|
-
[Symbol.asyncIterator]():
|
|
51
|
-
private _stream;
|
|
58
|
+
[Symbol.asyncIterator](): ManagedRealTimeIterator<any>;
|
|
52
59
|
protected abstract _getRealTimeFeeds(exchange: string, filters: Filter<string>[], timeoutIntervalMS?: number, onError?: (error: Error) => void): IterableIterator<RealTimeFeedIterable>;
|
|
53
60
|
}
|
|
54
61
|
export declare abstract class PoolingClientBase implements RealTimeFeedIterable {
|
|
@@ -56,10 +63,12 @@ export declare abstract class PoolingClientBase implements RealTimeFeedIterable
|
|
|
56
63
|
protected readonly onError?: ((error: Error) => void) | undefined;
|
|
57
64
|
protected readonly debug: dbg.Debugger;
|
|
58
65
|
private _tid;
|
|
66
|
+
private _outputStream;
|
|
59
67
|
constructor(exchange: string, _poolingIntervalSeconds: number, onError?: ((error: Error) => void) | undefined);
|
|
60
|
-
[Symbol.asyncIterator]():
|
|
68
|
+
[Symbol.asyncIterator](): ManagedRealTimeIterator<any>;
|
|
61
69
|
protected abstract poolDataToStream(outputStream: Writable): Promise<void>;
|
|
62
70
|
protected getPoolingDelayMS(): number;
|
|
71
|
+
private _close;
|
|
63
72
|
private _startPooling;
|
|
64
73
|
private _stream;
|
|
65
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtimefeed.d.ts","sourceRoot":"","sources":["../../src/realtimefeeds/realtimefeed.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,OAAO,CAAA;AAGvB,OAAO,EAAe,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAG9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,MAAM,YAAY,GAAG;IACzB,KACE,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EACzB,iBAAiB,EAAE,MAAM,GAAG,SAAS,EACrC,OAAO,CAAC,EAA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,CAAC,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI;IAPrD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAA;IACtC,OAAO,CAAC,IAAI,CAAwC;IACpD,OAAO,CAAC,aAAa,CAAyB;gBAG5C,QAAQ,EAAE,MAAM,EACC,uBAAuB,EAAE,MAAM,EAC7B,OAAO,CAAC,GAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,aAAA;IAKrD,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,uBAAuB,CAAC,GAAG,CAAC;IAItD,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1E,SAAS,CAAC,iBAAiB;IAI3B,OAAO,CAAC,MAAM;YAQA,aAAa;YAyBZ,OAAO;CAwBvB"}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import dbg from 'debug';
|
|
2
2
|
import WebSocket, { createWebSocketStream } from 'ws';
|
|
3
3
|
import { PassThrough } from 'stream';
|
|
4
|
-
import {
|
|
5
|
-
import { getProxyAgent, ONE_SEC_IN_MS, optimizeFilters
|
|
4
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
5
|
+
import { getProxyAgent, ONE_SEC_IN_MS, optimizeFilters } from "../handy.js";
|
|
6
|
+
import { createManagedRealTimeIterator, mergeRealTime } from "../realtimeiterator.js";
|
|
6
7
|
let connectionCounter = 1;
|
|
8
|
+
const ABORTED = Symbol('aborted');
|
|
7
9
|
export class RealTimeFeedBase {
|
|
8
10
|
_exchange;
|
|
9
11
|
_timeoutIntervalMS;
|
|
10
12
|
_onError;
|
|
11
13
|
[Symbol.asyncIterator]() {
|
|
12
|
-
return this._stream();
|
|
14
|
+
return createManagedRealTimeIterator(this._stream(), () => this._close());
|
|
13
15
|
}
|
|
14
16
|
debug;
|
|
15
17
|
throttleSubscribeMS = 0;
|
|
16
18
|
manualSnapshotsBuffer = [];
|
|
17
19
|
_filters;
|
|
18
|
-
_receivedMessagesCount = 0;
|
|
19
|
-
_ws;
|
|
20
|
-
_connectionId = -1;
|
|
21
20
|
_wsClientOptions;
|
|
21
|
+
_closed = false;
|
|
22
|
+
_closeController = new AbortController();
|
|
23
|
+
_connection;
|
|
22
24
|
originHeader = undefined;
|
|
23
25
|
extraHeaders = undefined;
|
|
24
26
|
constructor(_exchange, filters, _timeoutIntervalMS, _onError) {
|
|
@@ -41,17 +43,31 @@ export class RealTimeFeedBase {
|
|
|
41
43
|
const finalWssUrl = wssUrlOverride !== undefined ? wssUrlOverride : this.wssURL;
|
|
42
44
|
return finalWssUrl;
|
|
43
45
|
}
|
|
46
|
+
_close() {
|
|
47
|
+
if (this._closed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this._closed = true;
|
|
51
|
+
this._closeController.abort();
|
|
52
|
+
this._closeConnection(this._connection);
|
|
53
|
+
}
|
|
44
54
|
async *_stream() {
|
|
45
|
-
let staleConnectionTimerId;
|
|
46
|
-
let pingTimerId;
|
|
47
55
|
let retries = 0;
|
|
48
|
-
while (
|
|
56
|
+
while (this._closed === false) {
|
|
57
|
+
const connectionId = connectionCounter++;
|
|
58
|
+
let connection;
|
|
59
|
+
let staleConnectionTimerId;
|
|
60
|
+
let pingTimerId;
|
|
61
|
+
let connectionError;
|
|
49
62
|
try {
|
|
50
|
-
this.
|
|
63
|
+
this.manualSnapshotsBuffer.length = 0;
|
|
51
64
|
const subscribeMessages = this.mapToSubscribeMessages(this._filters);
|
|
52
|
-
const finalWssUrl = await this.getWebSocketUrl();
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
const finalWssUrl = await resolveOrAbort(this.getWebSocketUrl(), this._closeController.signal);
|
|
66
|
+
if (finalWssUrl === ABORTED || this._closed) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.debug('(connection id: %d) estabilishing connection to %s', connectionId, finalWssUrl);
|
|
70
|
+
this.debug('(connection id: %d) provided filters: %o mapped to subscribe messages: %j', connectionId, this._filters, subscribeMessages);
|
|
55
71
|
if (this.originHeader !== undefined) {
|
|
56
72
|
;
|
|
57
73
|
this._wsClientOptions.headers['origin'] = this.originHeader;
|
|
@@ -60,16 +76,27 @@ export class RealTimeFeedBase {
|
|
|
60
76
|
Object.assign(this._wsClientOptions.headers, this.extraHeaders);
|
|
61
77
|
}
|
|
62
78
|
this._wsClientOptions.agent = getProxyAgent(finalWssUrl);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
const ws = new WebSocket(finalWssUrl, this._wsClientOptions);
|
|
80
|
+
const currentConnection = {
|
|
81
|
+
id: connectionId,
|
|
82
|
+
ws,
|
|
83
|
+
controller: new AbortController(),
|
|
84
|
+
receivedMessagesCount: 0
|
|
85
|
+
};
|
|
86
|
+
connection = currentConnection;
|
|
87
|
+
this._connection = currentConnection;
|
|
88
|
+
ws.onopen = () => this._onConnectionOpen(currentConnection, subscribeMessages);
|
|
89
|
+
ws.onclose = (event) => this._onConnectionClosed(currentConnection, event);
|
|
90
|
+
staleConnectionTimerId = this._monitorConnectionIfStale(currentConnection);
|
|
91
|
+
pingTimerId = this._sendPeriodicPing(currentConnection);
|
|
92
|
+
const realtimeMessagesStream = createWebSocketStream(ws, {
|
|
69
93
|
readableObjectMode: true, // othwerwise we may end up with multiple messages returned by stream in single iteration
|
|
70
94
|
readableHighWaterMark: 8096 // since we're in object mode, let's increase hwm a little from default of 16 messages buffered
|
|
71
95
|
});
|
|
72
96
|
for await (let message of realtimeMessagesStream) {
|
|
97
|
+
if (this._isConnectionActive(currentConnection) === false) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
73
100
|
if (this.decompress !== undefined) {
|
|
74
101
|
message = this.decompress(message);
|
|
75
102
|
}
|
|
@@ -91,7 +118,7 @@ export class RealTimeFeedBase {
|
|
|
91
118
|
// exclude heaartbeat messages from received messages counter
|
|
92
119
|
// connection could still be stale even if only heartbeats are provided without any data
|
|
93
120
|
if (this.messageIsHeartbeat(messageDeserialized) === false) {
|
|
94
|
-
|
|
121
|
+
currentConnection.receivedMessagesCount++;
|
|
95
122
|
}
|
|
96
123
|
this.onMessage(messageDeserialized);
|
|
97
124
|
yield messageDeserialized;
|
|
@@ -106,65 +133,56 @@ export class RealTimeFeedBase {
|
|
|
106
133
|
this.manualSnapshotsBuffer.length = 0;
|
|
107
134
|
}
|
|
108
135
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
clearInterval(staleConnectionTimerId);
|
|
136
|
+
if (this._closed) {
|
|
137
|
+
return;
|
|
112
138
|
}
|
|
113
|
-
yield { __disconnect__: true };
|
|
114
139
|
}
|
|
115
140
|
catch (error) {
|
|
116
|
-
if (this.
|
|
117
|
-
|
|
141
|
+
if (this._closed) {
|
|
142
|
+
return;
|
|
118
143
|
}
|
|
119
|
-
|
|
120
|
-
const MAX_DELAY = 32 * 1000;
|
|
121
|
-
const isRateLimited = error.message.includes('429');
|
|
122
|
-
let delay;
|
|
123
|
-
if (isRateLimited) {
|
|
124
|
-
delay = (MAX_DELAY / 2) * retries;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
delay = Math.pow(2, retries - 1) * 1000;
|
|
128
|
-
if (delay > MAX_DELAY) {
|
|
129
|
-
delay = MAX_DELAY;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
this.debug('(connection id: %d) %s real-time feed connection error, retries count: %d, next retry delay: %dms, rate limited: %s error message: %o', this._connectionId, this._exchange, retries, delay, isRateLimited, error);
|
|
133
|
-
// clear monitoring connection timer and notify about disconnect
|
|
134
|
-
if (staleConnectionTimerId !== undefined) {
|
|
135
|
-
clearInterval(staleConnectionTimerId);
|
|
136
|
-
}
|
|
137
|
-
yield { __disconnect__: true };
|
|
138
|
-
await wait(delay);
|
|
144
|
+
connectionError = error instanceof Error ? error : new Error(String(error));
|
|
139
145
|
}
|
|
140
146
|
finally {
|
|
141
|
-
// stop timers
|
|
142
147
|
if (staleConnectionTimerId !== undefined) {
|
|
143
148
|
clearInterval(staleConnectionTimerId);
|
|
144
149
|
}
|
|
145
150
|
if (pingTimerId !== undefined) {
|
|
146
151
|
clearInterval(pingTimerId);
|
|
147
152
|
}
|
|
153
|
+
this._closeConnection(connection);
|
|
154
|
+
}
|
|
155
|
+
if (this._closed) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
let retryDelay;
|
|
159
|
+
if (connectionError !== undefined) {
|
|
160
|
+
this._onError?.(connectionError);
|
|
161
|
+
retries++;
|
|
162
|
+
const MAX_DELAY = 32 * 1000;
|
|
163
|
+
const isRateLimited = connectionError.message.includes('429');
|
|
164
|
+
retryDelay = isRateLimited ? (MAX_DELAY / 2) * retries : Math.min(Math.pow(2, retries - 1) * 1000, MAX_DELAY);
|
|
165
|
+
this.debug('(connection id: %d) %s real-time feed connection error, retries count: %d, next retry delay: %dms, rate limited: %s error message: %o', connectionId, this._exchange, retries, retryDelay, isRateLimited, connectionError);
|
|
166
|
+
}
|
|
167
|
+
yield { __disconnect__: true };
|
|
168
|
+
if (retryDelay !== undefined) {
|
|
169
|
+
await this._wait(retryDelay, this._closeController.signal);
|
|
148
170
|
}
|
|
149
171
|
}
|
|
150
172
|
}
|
|
151
173
|
send(msg) {
|
|
152
|
-
|
|
174
|
+
const ws = this._connection?.ws;
|
|
175
|
+
if (ws === undefined || ws.readyState !== WebSocket.OPEN) {
|
|
153
176
|
return;
|
|
154
177
|
}
|
|
155
|
-
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
this._ws.send(JSON.stringify(msg));
|
|
178
|
+
ws.send(JSON.stringify(msg));
|
|
159
179
|
}
|
|
160
180
|
sendRaw(msg) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
if (this._ws.readyState !== WebSocket.OPEN) {
|
|
181
|
+
const ws = this._connection?.ws;
|
|
182
|
+
if (ws === undefined || ws.readyState !== WebSocket.OPEN) {
|
|
165
183
|
return;
|
|
166
184
|
}
|
|
167
|
-
|
|
185
|
+
ws.send(msg);
|
|
168
186
|
}
|
|
169
187
|
parseMessage(message) {
|
|
170
188
|
return JSON.parse(message);
|
|
@@ -180,39 +198,39 @@ export class RealTimeFeedBase {
|
|
|
180
198
|
onMessage(_msg) { }
|
|
181
199
|
async onConnected() { }
|
|
182
200
|
decompress;
|
|
183
|
-
_monitorConnectionIfStale() {
|
|
201
|
+
_monitorConnectionIfStale(connection) {
|
|
184
202
|
if (this._timeoutIntervalMS === undefined || this._timeoutIntervalMS === 0) {
|
|
185
203
|
return;
|
|
186
204
|
}
|
|
187
205
|
// set up timer that checks against open, but stale connections that do not return any data
|
|
188
206
|
return setInterval(() => {
|
|
189
|
-
if (this.
|
|
207
|
+
if (this._isConnectionActive(connection) === false) {
|
|
190
208
|
return;
|
|
191
209
|
}
|
|
192
|
-
if (
|
|
193
|
-
this.debug('(connection id: %d) did not received any messages within %d ms timeout, terminating connection...',
|
|
194
|
-
|
|
210
|
+
if (connection.receivedMessagesCount === 0) {
|
|
211
|
+
this.debug('(connection id: %d) did not received any messages within %d ms timeout, terminating connection...', connection.id, this._timeoutIntervalMS);
|
|
212
|
+
connection.ws.terminate();
|
|
195
213
|
}
|
|
196
|
-
|
|
214
|
+
connection.receivedMessagesCount = 0;
|
|
197
215
|
}, this._timeoutIntervalMS);
|
|
198
216
|
}
|
|
199
|
-
_sendPeriodicPing() {
|
|
217
|
+
_sendPeriodicPing(connection) {
|
|
200
218
|
return setInterval(() => {
|
|
201
|
-
if (this.
|
|
219
|
+
if (this._isConnectionOpen(connection) === false) {
|
|
202
220
|
return;
|
|
203
221
|
}
|
|
204
222
|
if (this.sendCustomPing !== undefined) {
|
|
205
223
|
this.sendCustomPing();
|
|
206
224
|
}
|
|
207
225
|
else {
|
|
208
|
-
|
|
226
|
+
connection.ws.ping();
|
|
209
227
|
}
|
|
210
228
|
}, 5 * ONE_SEC_IN_MS);
|
|
211
229
|
}
|
|
212
|
-
|
|
230
|
+
async _onConnectionEstablished(connection, subscribeMessages) {
|
|
231
|
+
const shouldCancel = () => this._isConnectionOpen(connection) === false;
|
|
213
232
|
try {
|
|
214
|
-
const
|
|
215
|
-
let symbolsCount = this._filters.reduce((prev, curr) => {
|
|
233
|
+
const symbolsCount = this._filters.reduce((prev, curr) => {
|
|
216
234
|
if (curr.symbols !== undefined) {
|
|
217
235
|
for (const symbol of curr.symbols) {
|
|
218
236
|
prev.add(symbol);
|
|
@@ -221,32 +239,102 @@ export class RealTimeFeedBase {
|
|
|
221
239
|
return prev;
|
|
222
240
|
}, new Set()).size;
|
|
223
241
|
await this.onConnected();
|
|
242
|
+
if (shouldCancel()) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
224
245
|
for (const message of subscribeMessages) {
|
|
225
|
-
|
|
246
|
+
if (shouldCancel()) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
this._send(connection, message);
|
|
226
250
|
if (this.throttleSubscribeMS > 0) {
|
|
227
|
-
await
|
|
251
|
+
await this._wait(this.throttleSubscribeMS, connection.controller.signal);
|
|
228
252
|
}
|
|
229
253
|
}
|
|
230
|
-
this.debug('(connection id: %d) established connection',
|
|
254
|
+
this.debug('(connection id: %d) established connection', connection.id);
|
|
231
255
|
//wait before fetching snapshots until we're sure we've got proper connection estabilished (received some messages)
|
|
232
|
-
while (
|
|
233
|
-
await
|
|
256
|
+
while (shouldCancel() === false && connection.receivedMessagesCount < symbolsCount * 2) {
|
|
257
|
+
await this._wait(100, connection.controller.signal);
|
|
258
|
+
}
|
|
259
|
+
if (shouldCancel()) {
|
|
260
|
+
return;
|
|
234
261
|
}
|
|
235
262
|
// wait a second just in case before starting fetching the snapshots
|
|
236
|
-
await
|
|
237
|
-
if (
|
|
263
|
+
await this._wait(1 * ONE_SEC_IN_MS, connection.controller.signal);
|
|
264
|
+
if (shouldCancel()) {
|
|
238
265
|
return;
|
|
239
266
|
}
|
|
240
|
-
await this.provideManualSnapshots(this._filters,
|
|
267
|
+
await this.provideManualSnapshots(this._filters, shouldCancel);
|
|
241
268
|
}
|
|
242
269
|
catch (e) {
|
|
243
|
-
this.debug('(connection id: %d) providing manual snapshots error: %o',
|
|
244
|
-
this.
|
|
270
|
+
this.debug('(connection id: %d) providing manual snapshots error: %o', connection.id, e);
|
|
271
|
+
if (this._isConnectionOpen(connection)) {
|
|
272
|
+
connection.ws.emit('error', e);
|
|
273
|
+
}
|
|
245
274
|
}
|
|
246
|
-
}
|
|
247
|
-
_onConnectionClosed
|
|
248
|
-
this.debug('(connection id: %d) connection closed %s',
|
|
249
|
-
}
|
|
275
|
+
}
|
|
276
|
+
_onConnectionClosed(connection, event) {
|
|
277
|
+
this.debug('(connection id: %d) connection closed %s', connection.id, event.reason);
|
|
278
|
+
}
|
|
279
|
+
_onConnectionOpen(connection, subscribeMessages) {
|
|
280
|
+
if (this._isConnectionActive(connection) === false) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
void this._onConnectionEstablished(connection, subscribeMessages);
|
|
284
|
+
}
|
|
285
|
+
_send(connection, message) {
|
|
286
|
+
if (this._isConnectionOpen(connection)) {
|
|
287
|
+
connection.ws.send(JSON.stringify(message));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
_isConnectionActive(connection) {
|
|
291
|
+
return this._closed === false && this._connection === connection && connection.controller.signal.aborted === false;
|
|
292
|
+
}
|
|
293
|
+
_isConnectionOpen(connection) {
|
|
294
|
+
return this._isConnectionActive(connection) && connection.ws.readyState === WebSocket.OPEN;
|
|
295
|
+
}
|
|
296
|
+
_closeConnection(connection) {
|
|
297
|
+
if (connection === undefined) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
connection.controller.abort();
|
|
301
|
+
if (connection.ws.readyState !== WebSocket.CLOSED) {
|
|
302
|
+
connection.ws.terminate();
|
|
303
|
+
}
|
|
304
|
+
if (this._connection === connection) {
|
|
305
|
+
this._connection = undefined;
|
|
306
|
+
this.manualSnapshotsBuffer.length = 0;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async _wait(delayMS, signal) {
|
|
310
|
+
try {
|
|
311
|
+
await sleep(delayMS, undefined, { signal });
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
if (signal.aborted === false) {
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function resolveOrAbort(promise, signal) {
|
|
321
|
+
if (signal.aborted) {
|
|
322
|
+
return Promise.resolve(ABORTED);
|
|
323
|
+
}
|
|
324
|
+
return new Promise((resolve, reject) => {
|
|
325
|
+
let settled = false;
|
|
326
|
+
const onAbort = () => settle(() => resolve(ABORTED));
|
|
327
|
+
const settle = (callback) => {
|
|
328
|
+
if (settled) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
settled = true;
|
|
332
|
+
signal.removeEventListener('abort', onAbort);
|
|
333
|
+
callback();
|
|
334
|
+
};
|
|
335
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
336
|
+
void promise.then((value) => settle(() => resolve(value)), (error) => settle(() => reject(error)));
|
|
337
|
+
});
|
|
250
338
|
}
|
|
251
339
|
export class MultiConnectionRealTimeFeedBase {
|
|
252
340
|
_exchange;
|
|
@@ -260,31 +348,8 @@ export class MultiConnectionRealTimeFeedBase {
|
|
|
260
348
|
this._onError = _onError;
|
|
261
349
|
}
|
|
262
350
|
[Symbol.asyncIterator]() {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
async *_stream() {
|
|
266
|
-
const combinedStream = new PassThrough({
|
|
267
|
-
objectMode: true,
|
|
268
|
-
highWaterMark: 8096
|
|
269
|
-
});
|
|
270
|
-
const realTimeFeeds = this._getRealTimeFeeds(this._exchange, this._filters, this._timeoutIntervalMS, this._onError);
|
|
271
|
-
for (const realTimeFeed of realTimeFeeds) {
|
|
272
|
-
// iterate over separate real-time feeds and write their messages into combined stream
|
|
273
|
-
;
|
|
274
|
-
(async function writeMessagesToCombinedStream() {
|
|
275
|
-
for await (const message of realTimeFeed) {
|
|
276
|
-
if (combinedStream.destroyed) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
if (!combinedStream.write(message))
|
|
280
|
-
// Handle backpressure on write
|
|
281
|
-
await once(combinedStream, 'drain');
|
|
282
|
-
}
|
|
283
|
-
})();
|
|
284
|
-
}
|
|
285
|
-
for await (const message of combinedStream) {
|
|
286
|
-
yield message;
|
|
287
|
-
}
|
|
351
|
+
const realTimeFeeds = Array.from(this._getRealTimeFeeds(this._exchange, this._filters, this._timeoutIntervalMS, this._onError));
|
|
352
|
+
return mergeRealTime(realTimeFeeds);
|
|
288
353
|
}
|
|
289
354
|
}
|
|
290
355
|
export class PoolingClientBase {
|
|
@@ -292,17 +357,25 @@ export class PoolingClientBase {
|
|
|
292
357
|
onError;
|
|
293
358
|
debug;
|
|
294
359
|
_tid = undefined;
|
|
360
|
+
_outputStream;
|
|
295
361
|
constructor(exchange, _poolingIntervalSeconds, onError) {
|
|
296
362
|
this._poolingIntervalSeconds = _poolingIntervalSeconds;
|
|
297
363
|
this.onError = onError;
|
|
298
364
|
this.debug = dbg(`tardis-dev:pooling-client:${exchange}`);
|
|
299
365
|
}
|
|
300
366
|
[Symbol.asyncIterator]() {
|
|
301
|
-
return this._stream();
|
|
367
|
+
return createManagedRealTimeIterator(this._stream(), () => this._close());
|
|
302
368
|
}
|
|
303
369
|
getPoolingDelayMS() {
|
|
304
370
|
return this._poolingIntervalSeconds * ONE_SEC_IN_MS;
|
|
305
371
|
}
|
|
372
|
+
_close() {
|
|
373
|
+
if (this._tid !== undefined) {
|
|
374
|
+
clearTimeout(this._tid);
|
|
375
|
+
this._tid = undefined;
|
|
376
|
+
}
|
|
377
|
+
this._outputStream?.destroy();
|
|
378
|
+
}
|
|
306
379
|
async _startPooling(outputStream) {
|
|
307
380
|
const pool = async () => {
|
|
308
381
|
try {
|
|
@@ -330,6 +403,7 @@ export class PoolingClientBase {
|
|
|
330
403
|
objectMode: true,
|
|
331
404
|
highWaterMark: 1024
|
|
332
405
|
});
|
|
406
|
+
this._outputStream = stream;
|
|
333
407
|
this._startPooling(stream);
|
|
334
408
|
this.debug('pooling started');
|
|
335
409
|
try {
|
|
@@ -338,8 +412,9 @@ export class PoolingClientBase {
|
|
|
338
412
|
}
|
|
339
413
|
}
|
|
340
414
|
finally {
|
|
341
|
-
|
|
342
|
-
|
|
415
|
+
this._close();
|
|
416
|
+
if (this._outputStream === stream) {
|
|
417
|
+
this._outputStream = undefined;
|
|
343
418
|
}
|
|
344
419
|
this.debug('pooling finished');
|
|
345
420
|
}
|