@nktkas/hyperliquid 0.13.1 → 0.14.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/LICENSE +20 -20
- package/README.md +334 -107
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.js +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.js +2 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.js +1 -1
- package/{script/deps/jsr.io/@std/encoding/1.0.6 → esm/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/hex.js +1 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +2 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.js +2 -2
- package/esm/mod.d.ts +4 -12
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -2
- package/{script/src/transports → esm/src}/base.d.ts +10 -13
- package/esm/src/base.d.ts.map +1 -0
- package/esm/src/base.js +14 -0
- package/esm/src/clients/event.d.ts +59 -18
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +74 -18
- package/esm/src/clients/public.d.ts +348 -53
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +349 -50
- package/esm/src/clients/wallet.d.ts +345 -73
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +979 -229
- package/esm/src/signing.d.ts +135 -0
- package/esm/src/signing.d.ts.map +1 -0
- package/esm/src/signing.js +188 -0
- package/esm/src/transports/http/http_transport.d.ts +1 -1
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +64 -0
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +52 -0
- package/esm/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/{reconnecting_websocket.js → _reconnecting_websocket.js} +91 -76
- package/{script/src/transports/websocket/websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_request_dispatcher.d.ts} +3 -7
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/{websocket_request_dispatcher.js → _websocket_request_dispatcher.js} +6 -10
- package/esm/src/transports/websocket/websocket_transport.d.ts +15 -21
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +55 -52
- package/esm/src/types/exchange/requests.d.ts +298 -79
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +38 -38
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +23 -10
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +45 -3
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +279 -189
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +191 -185
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/delegations.d.ts +117 -0
- package/esm/src/types/info/delegations.d.ts.map +1 -0
- package/esm/src/types/info/orders.d.ts +94 -94
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +192 -64
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +42 -85
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +14 -0
- package/esm/src/types/mod.d.ts.map +1 -0
- package/esm/src/types/subscriptions/requests.d.ts +11 -1
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/{script/src/types/subscriptions/common.d.ts → esm/src/types/subscriptions/responses.d.ts} +18 -3
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -0
- package/package.json +20 -4
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
- package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
- package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
- package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
- package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
- package/script/mod.d.ts +4 -12
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +21 -13
- package/{esm/src/transports → script/src}/base.d.ts +10 -13
- package/script/src/base.d.ts.map +1 -0
- package/script/src/base.js +29 -0
- package/script/src/clients/event.d.ts +59 -18
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +551 -485
- package/script/src/clients/public.d.ts +348 -53
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +1017 -708
- package/script/src/clients/wallet.d.ts +345 -73
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +1737 -977
- package/script/src/signing.d.ts +135 -0
- package/script/src/signing.d.ts.map +1 -0
- package/script/src/signing.js +203 -0
- package/script/src/transports/http/http_transport.d.ts +1 -1
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +174 -164
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +64 -0
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/_hyperliquid_event_target.js +66 -0
- package/script/src/transports/websocket/{reconnecting_websocket.d.ts → _reconnecting_websocket.d.ts} +26 -26
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/_reconnecting_websocket.js +400 -0
- package/{esm/src/transports/websocket/websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_request_dispatcher.d.ts} +3 -7
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/_websocket_request_dispatcher.js +212 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +15 -21
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +235 -222
- package/script/src/types/exchange/requests.d.ts +298 -79
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +12 -2
- package/script/src/types/exchange/responses.d.ts +38 -38
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/exchange/responses.js +12 -2
- package/script/src/types/explorer/requests.d.ts +23 -10
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +12 -2
- package/script/src/types/explorer/responses.d.ts +45 -3
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/explorer/responses.js +12 -2
- package/script/src/types/info/accounts.d.ts +279 -189
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +12 -2
- package/script/src/types/info/assets.d.ts +191 -185
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/assets.js +12 -2
- package/script/src/types/info/delegations.d.ts +117 -0
- package/script/src/types/info/delegations.d.ts.map +1 -0
- package/script/src/types/info/delegations.js +12 -0
- package/script/src/types/info/orders.d.ts +94 -94
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/orders.js +12 -2
- package/script/src/types/info/requests.d.ts +192 -64
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +12 -2
- package/script/src/types/info/vaults.d.ts +42 -85
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/info/vaults.js +12 -2
- package/script/src/types/mod.d.ts +14 -0
- package/script/src/types/mod.d.ts.map +1 -0
- package/script/src/types/mod.js +12 -0
- package/script/src/types/subscriptions/requests.d.ts +11 -1
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +12 -2
- package/{esm/src/types/subscriptions/common.d.ts → script/src/types/subscriptions/responses.d.ts} +18 -3
- package/script/src/types/subscriptions/responses.d.ts.map +1 -0
- package/script/src/types/subscriptions/responses.js +12 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/esm/src/transports/base.d.ts.map +0 -1
- package/esm/src/transports/base.js +0 -14
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +0 -66
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/esm/src/transports/websocket/hyperliquid_event_target.js +0 -33
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/esm/src/types/common.d.ts +0 -3
- package/esm/src/types/common.d.ts.map +0 -1
- package/esm/src/types/exchange/common.d.ts +0 -36
- package/esm/src/types/exchange/common.d.ts.map +0 -1
- package/esm/src/types/explorer/common.d.ts +0 -37
- package/esm/src/types/explorer/common.d.ts.map +0 -1
- package/esm/src/types/subscriptions/common.d.ts.map +0 -1
- package/esm/src/types/subscriptions/common.js +0 -1
- package/esm/src/utils/key_sort.d.ts +0 -21
- package/esm/src/utils/key_sort.d.ts.map +0 -1
- package/esm/src/utils/key_sort.js +0 -124
- package/esm/src/utils/signing.d.ts +0 -109
- package/esm/src/utils/signing.d.ts.map +0 -1
- package/esm/src/utils/signing.js +0 -164
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
- package/script/src/transports/base.d.ts.map +0 -1
- package/script/src/transports/base.js +0 -18
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +0 -66
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +0 -1
- package/script/src/transports/websocket/hyperliquid_event_target.js +0 -37
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +0 -1
- package/script/src/transports/websocket/reconnecting_websocket.js +0 -374
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +0 -1
- package/script/src/transports/websocket/websocket_request_dispatcher.js +0 -206
- package/script/src/types/common.d.ts +0 -3
- package/script/src/types/common.d.ts.map +0 -1
- package/script/src/types/common.js +0 -2
- package/script/src/types/exchange/common.d.ts +0 -36
- package/script/src/types/exchange/common.d.ts.map +0 -1
- package/script/src/types/exchange/common.js +0 -2
- package/script/src/types/explorer/common.d.ts +0 -37
- package/script/src/types/explorer/common.d.ts.map +0 -1
- package/script/src/types/explorer/common.js +0 -2
- package/script/src/types/subscriptions/common.d.ts.map +0 -1
- package/script/src/types/subscriptions/common.js +0 -2
- package/script/src/utils/key_sort.d.ts +0 -21
- package/script/src/utils/key_sort.d.ts.map +0 -1
- package/script/src/utils/key_sort.js +0 -127
- package/script/src/utils/signing.d.ts +0 -109
- package/script/src/utils/signing.d.ts.map +0 -1
- package/script/src/utils/signing.js +0 -172
- /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
- /package/esm/src/types/{common.js → info/delegations.js} +0 -0
- /package/esm/src/types/{exchange/common.js → mod.js} +0 -0
- /package/esm/src/types/{explorer/common.js → subscriptions/responses.js} +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// deno-lint-ignore-file no-explicit-any
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ReconnectingWebSocket = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Simple FIFO (First In, First Out) buffer implementation.
|
|
7
|
-
*/
|
|
8
|
-
class FIFOMessageBuffer {
|
|
9
|
-
constructor() {
|
|
10
|
-
Object.defineProperty(this, "messages", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: []
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
push(data) {
|
|
18
|
-
this.messages.push(data);
|
|
19
|
-
}
|
|
20
|
-
shift() {
|
|
21
|
-
return this.messages.shift();
|
|
22
|
-
}
|
|
23
|
-
clear() {
|
|
24
|
-
this.messages = [];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* A WebSocket that automatically reconnects when disconnected.
|
|
29
|
-
* Fully compatible with standard WebSocket API.
|
|
30
|
-
*/
|
|
31
|
-
class ReconnectingWebSocket {
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new reconnecting WebSocket.
|
|
34
|
-
* @param url - The WebSocket URL to connect to.
|
|
35
|
-
* @param protocols - The WebSocket protocols to use.
|
|
36
|
-
* @param options - The configuration options.
|
|
37
|
-
*/
|
|
38
|
-
constructor(url, protocols, options) {
|
|
39
|
-
/** Controller for handling connection termination */
|
|
40
|
-
Object.defineProperty(this, "terminationController", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true,
|
|
44
|
-
value: new AbortController()
|
|
45
|
-
});
|
|
46
|
-
/** WebSocket protocols */
|
|
47
|
-
Object.defineProperty(this, "protocols", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true,
|
|
51
|
-
value: void 0
|
|
52
|
-
});
|
|
53
|
-
/** The underlying WebSocket instance */
|
|
54
|
-
Object.defineProperty(this, "socket", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: void 0
|
|
59
|
-
});
|
|
60
|
-
/** Current number of reconnection attempts */
|
|
61
|
-
Object.defineProperty(this, "reconnectCount", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
configurable: true,
|
|
64
|
-
writable: true,
|
|
65
|
-
value: 0
|
|
66
|
-
});
|
|
67
|
-
/** Array of registered event listeners */
|
|
68
|
-
Object.defineProperty(this, "eventListeners", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: []
|
|
73
|
-
});
|
|
74
|
-
/** Configuration options */
|
|
75
|
-
Object.defineProperty(this, "reconnectOptions", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: void 0
|
|
80
|
-
});
|
|
81
|
-
/** An AbortSignal that is triggered when the connection is permanently closed */
|
|
82
|
-
Object.defineProperty(this, "terminationSignal", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
configurable: true,
|
|
85
|
-
writable: true,
|
|
86
|
-
value: this.terminationController.signal
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(this, "CLOSED", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: WebSocket.CLOSED
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(this, "CLOSING", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
configurable: true,
|
|
97
|
-
writable: true,
|
|
98
|
-
value: WebSocket.CLOSING
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(this, "CONNECTING", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true,
|
|
104
|
-
value: WebSocket.CONNECTING
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(this, "OPEN", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
configurable: true,
|
|
109
|
-
writable: true,
|
|
110
|
-
value: WebSocket.OPEN
|
|
111
|
-
});
|
|
112
|
-
this.reconnectOptions = {
|
|
113
|
-
maxRetries: options?.maxRetries ?? 3,
|
|
114
|
-
connectionTimeout: options?.connectionTimeout === undefined ? 10_000 : options.connectionTimeout,
|
|
115
|
-
connectionDelay: options?.connectionDelay ?? ((attempt) => Math.min(~~(1 << attempt) * 150, 10_000)),
|
|
116
|
-
shouldReconnect: options?.shouldReconnect ?? (() => true),
|
|
117
|
-
messageBuffer: options?.messageBuffer ?? new FIFOMessageBuffer(),
|
|
118
|
-
WebSocketConstructor: options?.WebSocketConstructor ?? WebSocket,
|
|
119
|
-
};
|
|
120
|
-
this.protocols = protocols;
|
|
121
|
-
this.socket = this.reconnectOptions.connectionTimeout
|
|
122
|
-
? this.connectWithTimeout(url, this.protocols, this.reconnectOptions.connectionTimeout)
|
|
123
|
-
: new this.reconnectOptions.WebSocketConstructor(url, this.protocols);
|
|
124
|
-
this.initEventListeners();
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Creates a WebSocket connection with timeout.
|
|
128
|
-
* @param url - The WebSocket URL to connect to.
|
|
129
|
-
* @param protocols - The WebSocket protocols to use.
|
|
130
|
-
* @param timeout - The connection timeout in ms.
|
|
131
|
-
* @returns A new WebSocket instance.
|
|
132
|
-
*/
|
|
133
|
-
connectWithTimeout(url, protocols, timeout) {
|
|
134
|
-
const socket = new this.reconnectOptions.WebSocketConstructor(url, protocols);
|
|
135
|
-
const timeoutId = setTimeout(() => {
|
|
136
|
-
socket.removeEventListener("open", openHandler);
|
|
137
|
-
socket.removeEventListener("close", closeHandler);
|
|
138
|
-
socket.close(3008, "Timeout"); // https://www.iana.org/assignments/websocket/websocket.xml#close-code-number
|
|
139
|
-
}, timeout);
|
|
140
|
-
const openHandler = () => {
|
|
141
|
-
socket.removeEventListener("close", closeHandler);
|
|
142
|
-
clearTimeout(timeoutId);
|
|
143
|
-
};
|
|
144
|
-
const closeHandler = () => {
|
|
145
|
-
socket.removeEventListener("open", openHandler);
|
|
146
|
-
clearTimeout(timeoutId);
|
|
147
|
-
};
|
|
148
|
-
socket.addEventListener("open", openHandler, { once: true });
|
|
149
|
-
socket.addEventListener("close", closeHandler, { once: true });
|
|
150
|
-
return socket;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Initializes the internal event listeners for the WebSocket.
|
|
154
|
-
*/
|
|
155
|
-
initEventListeners() {
|
|
156
|
-
this.socket.addEventListener("open", () => {
|
|
157
|
-
// Reset reconnection count
|
|
158
|
-
this.reconnectCount = 0;
|
|
159
|
-
// Send all buffered messages
|
|
160
|
-
let message;
|
|
161
|
-
while ((message = this.reconnectOptions.messageBuffer.shift()) !== undefined) {
|
|
162
|
-
this.socket.send(message);
|
|
163
|
-
}
|
|
164
|
-
}, { once: true });
|
|
165
|
-
this.socket.addEventListener("close", async (event) => {
|
|
166
|
-
try {
|
|
167
|
-
// If the termination signal is already aborted, do not attempt to reconnect
|
|
168
|
-
if (this.terminationSignal.aborted)
|
|
169
|
-
return;
|
|
170
|
-
// Check if reconnection should be attempted
|
|
171
|
-
if (++this.reconnectCount > this.reconnectOptions.maxRetries) {
|
|
172
|
-
this.cleanup(new Error("RECONNECTION_LIMIT_REACHED", { cause: event }));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
const userDecision = await this.reconnectOptions.shouldReconnect(event);
|
|
176
|
-
if (this.terminationSignal.aborted)
|
|
177
|
-
return; // Check again after the await
|
|
178
|
-
if (!userDecision) {
|
|
179
|
-
this.cleanup(new Error("RECONNECTION_STOPPED_BY_USER", { cause: event }));
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
// Delay before reconnecting
|
|
183
|
-
const delay = typeof this.reconnectOptions.connectionDelay === "number"
|
|
184
|
-
? this.reconnectOptions.connectionDelay
|
|
185
|
-
: await this.reconnectOptions.connectionDelay(this.reconnectCount);
|
|
186
|
-
if (this.terminationSignal.aborted)
|
|
187
|
-
return; // Check again after the await
|
|
188
|
-
await sleep(delay, this.terminationSignal);
|
|
189
|
-
// Reconnect the socket
|
|
190
|
-
this.socket = this.reconnectOptions.connectionTimeout
|
|
191
|
-
? this.connectWithTimeout(this.url, this.protocols, this.reconnectOptions.connectionTimeout)
|
|
192
|
-
: new this.reconnectOptions.WebSocketConstructor(this.url, this.protocols);
|
|
193
|
-
// Reconnect all listeners
|
|
194
|
-
this.initEventListeners();
|
|
195
|
-
this.eventListeners.forEach(({ type, listenerProxy, options }) => {
|
|
196
|
-
this.socket.addEventListener(type, listenerProxy, options);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
this.cleanup(new Error("RECONNECTION_ERROR", { cause: { error, event } }));
|
|
201
|
-
}
|
|
202
|
-
}, { once: true });
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Clean up internal resources.
|
|
206
|
-
* @param reason - The reason for cleanup.
|
|
207
|
-
*/
|
|
208
|
-
cleanup(reason) {
|
|
209
|
-
this.terminationController.abort(reason);
|
|
210
|
-
this.reconnectOptions.messageBuffer.clear();
|
|
211
|
-
this.eventListeners = [];
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Check if two event listeners are the same (just like EventTarget).
|
|
215
|
-
* @param a - First event listener configuration.
|
|
216
|
-
* @param b - Second event listener configuration.
|
|
217
|
-
* @returns True if the listeners match.
|
|
218
|
-
*/
|
|
219
|
-
isListenerMatch(a, b) {
|
|
220
|
-
const aCapture = Boolean(typeof a.options === "object" ? a.options.capture : a.options);
|
|
221
|
-
const bCapture = Boolean(typeof b.options === "object" ? b.options.capture : b.options);
|
|
222
|
-
return a.type === b.type && a.listener === b.listener && aCapture === bCapture;
|
|
223
|
-
}
|
|
224
|
-
// WebSocket property implementations
|
|
225
|
-
get url() {
|
|
226
|
-
return this.socket.url;
|
|
227
|
-
}
|
|
228
|
-
get readyState() {
|
|
229
|
-
return this.socket.readyState;
|
|
230
|
-
}
|
|
231
|
-
get bufferedAmount() {
|
|
232
|
-
return this.socket.bufferedAmount;
|
|
233
|
-
}
|
|
234
|
-
get extensions() {
|
|
235
|
-
return this.socket.extensions;
|
|
236
|
-
}
|
|
237
|
-
get protocol() {
|
|
238
|
-
return this.socket.protocol;
|
|
239
|
-
}
|
|
240
|
-
get binaryType() {
|
|
241
|
-
return this.socket.binaryType;
|
|
242
|
-
}
|
|
243
|
-
set binaryType(value) {
|
|
244
|
-
this.socket.binaryType = value;
|
|
245
|
-
}
|
|
246
|
-
get onclose() {
|
|
247
|
-
return this.socket.onclose;
|
|
248
|
-
}
|
|
249
|
-
set onclose(value) {
|
|
250
|
-
this.socket.onclose = value;
|
|
251
|
-
}
|
|
252
|
-
get onerror() {
|
|
253
|
-
return this.socket.onerror;
|
|
254
|
-
}
|
|
255
|
-
set onerror(value) {
|
|
256
|
-
this.socket.onerror = value;
|
|
257
|
-
}
|
|
258
|
-
get onmessage() {
|
|
259
|
-
return this.socket.onmessage;
|
|
260
|
-
}
|
|
261
|
-
set onmessage(value) {
|
|
262
|
-
this.socket.onmessage = value;
|
|
263
|
-
}
|
|
264
|
-
get onopen() {
|
|
265
|
-
return this.socket.onopen;
|
|
266
|
-
}
|
|
267
|
-
set onopen(value) {
|
|
268
|
-
this.socket.onopen = value;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* @param permanently - If true, the connection will be permanently closed. Default is true.
|
|
272
|
-
*/
|
|
273
|
-
close(code, reason, permanently = true) {
|
|
274
|
-
if (permanently)
|
|
275
|
-
this.cleanup(new Error("USER_INITIATED_CLOSE"));
|
|
276
|
-
this.socket.close(code, reason);
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* @note If the connection is not open, the data will be buffered and sent when the connection is established.
|
|
280
|
-
*/
|
|
281
|
-
send(data) {
|
|
282
|
-
if (this.socket.readyState !== WebSocket.OPEN && !this.terminationSignal.aborted) {
|
|
283
|
-
this.reconnectOptions.messageBuffer.push(data);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
this.socket.send(data);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
addEventListener(type, listener, options) {
|
|
290
|
-
// Check if the listener is already added
|
|
291
|
-
const exists = this.eventListeners.some((e) => this.isListenerMatch(e, { type, listener, options }));
|
|
292
|
-
if (exists)
|
|
293
|
-
return;
|
|
294
|
-
// Wrap the original listener to follow the once option when reconnecting
|
|
295
|
-
const listenerProxy = (event) => {
|
|
296
|
-
try {
|
|
297
|
-
if (typeof listener === "function") {
|
|
298
|
-
listener.call(this, event);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
listener.handleEvent(event);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
finally {
|
|
305
|
-
if (typeof options === "object" && options.once === true) {
|
|
306
|
-
const index = this.eventListeners.findIndex((e) => this.isListenerMatch(e, { type, listener, options }));
|
|
307
|
-
if (index !== -1)
|
|
308
|
-
this.eventListeners.splice(index, 1);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
this.eventListeners.push({ type, listener, options, listenerProxy });
|
|
313
|
-
this.socket.addEventListener(type, listenerProxy, options);
|
|
314
|
-
}
|
|
315
|
-
removeEventListener(type, listener, options) {
|
|
316
|
-
const index = this.eventListeners.findIndex((e) => this.isListenerMatch(e, { type, listener, options }));
|
|
317
|
-
if (index !== -1) {
|
|
318
|
-
const { listenerProxy } = this.eventListeners[index];
|
|
319
|
-
this.socket.removeEventListener(type, listenerProxy, options);
|
|
320
|
-
this.eventListeners.splice(index, 1);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
dispatchEvent(event) {
|
|
324
|
-
return this.socket.dispatchEvent(event);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
exports.ReconnectingWebSocket = ReconnectingWebSocket;
|
|
328
|
-
Object.defineProperty(ReconnectingWebSocket, "CLOSED", {
|
|
329
|
-
enumerable: true,
|
|
330
|
-
configurable: true,
|
|
331
|
-
writable: true,
|
|
332
|
-
value: WebSocket.CLOSED
|
|
333
|
-
});
|
|
334
|
-
Object.defineProperty(ReconnectingWebSocket, "CLOSING", {
|
|
335
|
-
enumerable: true,
|
|
336
|
-
configurable: true,
|
|
337
|
-
writable: true,
|
|
338
|
-
value: WebSocket.CLOSING
|
|
339
|
-
});
|
|
340
|
-
Object.defineProperty(ReconnectingWebSocket, "CONNECTING", {
|
|
341
|
-
enumerable: true,
|
|
342
|
-
configurable: true,
|
|
343
|
-
writable: true,
|
|
344
|
-
value: WebSocket.CONNECTING
|
|
345
|
-
});
|
|
346
|
-
Object.defineProperty(ReconnectingWebSocket, "OPEN", {
|
|
347
|
-
enumerable: true,
|
|
348
|
-
configurable: true,
|
|
349
|
-
writable: true,
|
|
350
|
-
value: WebSocket.OPEN
|
|
351
|
-
});
|
|
352
|
-
/**
|
|
353
|
-
* Returns a promise that resolves after the specified number of ms,
|
|
354
|
-
* or rejects as soon as the given signal is aborted.
|
|
355
|
-
* @param ms - The number of ms to sleep.
|
|
356
|
-
* @param signal - An optional abort signal.
|
|
357
|
-
* @returns A promise that resolves after the specified delay.
|
|
358
|
-
*/
|
|
359
|
-
function sleep(ms, signal) {
|
|
360
|
-
return new Promise((resolve, reject) => {
|
|
361
|
-
if (signal?.aborted) {
|
|
362
|
-
return reject(signal.reason);
|
|
363
|
-
}
|
|
364
|
-
const onAbort = function () {
|
|
365
|
-
clearTimeout(timer);
|
|
366
|
-
reject(this.reason);
|
|
367
|
-
};
|
|
368
|
-
const timer = setTimeout(() => {
|
|
369
|
-
signal?.removeEventListener("abort", onAbort);
|
|
370
|
-
resolve();
|
|
371
|
-
}, ms);
|
|
372
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
373
|
-
});
|
|
374
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket_request_dispatcher.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_request_dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,cAAc;IACrD;;;OAGG;gBACS,OAAO,EAAE,MAAM;CAI9B;AAED;;;GAGG;AACH,qBAAa,0BAA0B;IAevB,SAAS,CAAC,MAAM,EAAE,SAAS;IAdvC,2BAA2B;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAK;IAE7B,oDAAoD;IACpD,SAAS,CAAC,OAAO,EAAE,GAAG,CAClB,MAAM,GAAG,MAAM,EACf;QAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;KAAE,CAC3E,CAAa;IAEd;;;;OAIG;gBACmB,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,sBAAsB;IA2DzE,+BAA+B;IAC/B,SAAS,KAAK,MAAM,IAAI,MAAM,CAE7B;IAED;;;;;;OAMG;IACH,OAAO,CACH,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,aAAa,EAC5C,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,OAAO,CAAC;IAkCnB;;;;OAIG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAK5D;;;;OAIG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI;IAK5D;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAK7C"}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebSocketRequestDispatcher = exports.WebSocketRequestError = void 0;
|
|
4
|
-
const base_js_1 = require("../base.js");
|
|
5
|
-
/**
|
|
6
|
-
* Error thrown when a WebSocket request fails:
|
|
7
|
-
* - When the WebSocket connection is closed
|
|
8
|
-
* - When the server responds with an error message
|
|
9
|
-
*/
|
|
10
|
-
class WebSocketRequestError extends base_js_1.TransportError {
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new WebSocket request error.
|
|
13
|
-
* @param message - The error message.
|
|
14
|
-
*/
|
|
15
|
-
constructor(message) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = "WebSocketRequestError";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.WebSocketRequestError = WebSocketRequestError;
|
|
21
|
-
/**
|
|
22
|
-
* Manages WebSocket requests to the Hyperliquid API.
|
|
23
|
-
* Handles request creation, sending, and mapping responses to their corresponding requests.
|
|
24
|
-
*/
|
|
25
|
-
class WebSocketRequestDispatcher {
|
|
26
|
-
/**
|
|
27
|
-
* Creates a new WebSocket request dispatcher.
|
|
28
|
-
* @param socket - WebSocket connection instance for sending requests to the Hyperliquid WebSocket API
|
|
29
|
-
* @param hlEvents - Used to recognize Hyperliquid responses and match them with sent requests
|
|
30
|
-
*/
|
|
31
|
-
constructor(socket, hlEvents) {
|
|
32
|
-
Object.defineProperty(this, "socket", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: socket
|
|
37
|
-
});
|
|
38
|
-
/** Last used request ID */
|
|
39
|
-
Object.defineProperty(this, "lastId", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: 0
|
|
44
|
-
});
|
|
45
|
-
/** Map of pending requests waiting for responses */
|
|
46
|
-
Object.defineProperty(this, "pending", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: new Map()
|
|
51
|
-
});
|
|
52
|
-
// Monitor responses and match the pending request
|
|
53
|
-
hlEvents.addEventListener("subscriptionResponse", (event) => {
|
|
54
|
-
// Use a stringified request as an id
|
|
55
|
-
const id = WebSocketRequestDispatcher.requestToId(event.detail.subscription);
|
|
56
|
-
this.resolve(id, event.detail);
|
|
57
|
-
});
|
|
58
|
-
hlEvents.addEventListener("post", (event) => {
|
|
59
|
-
const data = event.detail.response.type === "info"
|
|
60
|
-
? event.detail.response.payload.data
|
|
61
|
-
: event.detail.response.payload;
|
|
62
|
-
this.resolve(event.detail.id, data);
|
|
63
|
-
});
|
|
64
|
-
hlEvents.addEventListener("error", (event) => {
|
|
65
|
-
try {
|
|
66
|
-
// Error event doesn't have an id, use original request to match
|
|
67
|
-
const request = event.detail.match(/{.*}/)?.[0];
|
|
68
|
-
if (request) {
|
|
69
|
-
const parsedRequest = JSON.parse(request);
|
|
70
|
-
if ("id" in parsedRequest && typeof parsedRequest.id === "number") {
|
|
71
|
-
// If a post request was sent, it is possible to get the id from the request
|
|
72
|
-
this.reject(parsedRequest.id, new WebSocketRequestError(`Cannot process WebSocket request: ${event.detail}`));
|
|
73
|
-
}
|
|
74
|
-
else if ("subscription" in parsedRequest &&
|
|
75
|
-
typeof parsedRequest.subscription === "object" &&
|
|
76
|
-
parsedRequest.subscription !== null) {
|
|
77
|
-
// If a subscription/unsubscribe request was sent, use the request as an id
|
|
78
|
-
const id = WebSocketRequestDispatcher.requestToId(parsedRequest.subscription);
|
|
79
|
-
this.reject(id, new WebSocketRequestError(`Cannot process subscription request: ${event.detail}`));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
// If the request is not recognized, use the parsed request as an id
|
|
83
|
-
const id = WebSocketRequestDispatcher.requestToId(parsedRequest);
|
|
84
|
-
this.reject(id, new WebSocketRequestError(`Cannot process unrecognized request: ${event.detail}`));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// Ignore JSON parsing errors
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
// Throws all pending requests if the connection is dropped
|
|
93
|
-
socket.addEventListener("close", () => {
|
|
94
|
-
this.pending.forEach(({ reject }) => {
|
|
95
|
-
reject(new WebSocketRequestError("Cannot complete WebSocket request: connection is closed"));
|
|
96
|
-
});
|
|
97
|
-
this.pending.clear();
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/** Gets the next request ID */
|
|
101
|
-
get nextId() {
|
|
102
|
-
return ++this.lastId;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Sends a request to the Hyperliquid API.
|
|
106
|
-
* @param method - The method of websocket request.
|
|
107
|
-
* @param payload - The payload to send with the request.
|
|
108
|
-
* @param signal - An optional abort signal.
|
|
109
|
-
* @returns A promise that resolves with the parsed JSON response body.
|
|
110
|
-
*/
|
|
111
|
-
request(method, payload, signal) {
|
|
112
|
-
signal?.throwIfAborted();
|
|
113
|
-
// Create a request object
|
|
114
|
-
let id;
|
|
115
|
-
let request;
|
|
116
|
-
if (method === "post") {
|
|
117
|
-
id = this.nextId;
|
|
118
|
-
request = { method, id, request: payload };
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
id = WebSocketRequestDispatcher.requestToId(payload);
|
|
122
|
-
request = { method, subscription: payload };
|
|
123
|
-
}
|
|
124
|
-
// Send the request
|
|
125
|
-
this.socket.send(JSON.stringify(request));
|
|
126
|
-
// Wait for a response
|
|
127
|
-
let onAbort;
|
|
128
|
-
return new Promise((resolve, reject) => {
|
|
129
|
-
// Add an abort listener
|
|
130
|
-
onAbort = () => reject(signal?.reason);
|
|
131
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
132
|
-
// Add the promise to the pending list
|
|
133
|
-
this.pending.set(id, { resolve, reject });
|
|
134
|
-
}).finally(() => {
|
|
135
|
-
// Remove the abort listener when the promise is settled
|
|
136
|
-
signal?.removeEventListener("abort", onAbort);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Resolves a pending request.
|
|
141
|
-
* @param id - A request ID or a stringified request.
|
|
142
|
-
* @param value - A resolution value.
|
|
143
|
-
*/
|
|
144
|
-
resolve(id, value) {
|
|
145
|
-
this.pending.get(id)?.resolve(value);
|
|
146
|
-
this.pending.delete(id);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Rejects a pending request.
|
|
150
|
-
* @param id - A request ID or a stringified request.
|
|
151
|
-
* @param reason - A rejection reason.
|
|
152
|
-
*/
|
|
153
|
-
reject(id, reason) {
|
|
154
|
-
this.pending.get(id)?.reject(reason);
|
|
155
|
-
this.pending.delete(id);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Normalizes a request object to an ID.
|
|
159
|
-
* @param value - A request object.
|
|
160
|
-
* @returns A stringified request.
|
|
161
|
-
*/
|
|
162
|
-
static requestToId(value) {
|
|
163
|
-
const lowerHex = deepLowerHex(value);
|
|
164
|
-
const sorted = deepSortKeys(lowerHex);
|
|
165
|
-
return JSON.stringify(sorted);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.WebSocketRequestDispatcher = WebSocketRequestDispatcher;
|
|
169
|
-
/**
|
|
170
|
-
* Convert all hexadecimal strings to lowercase in an object/array.
|
|
171
|
-
* @param obj - The object/array to convert hexadecimal strings to lowercase.
|
|
172
|
-
* @returns A new object/array with hexadecimal strings converted to lowercase.
|
|
173
|
-
*/
|
|
174
|
-
function deepLowerHex(obj) {
|
|
175
|
-
if (Array.isArray(obj)) {
|
|
176
|
-
return obj.map(deepLowerHex);
|
|
177
|
-
}
|
|
178
|
-
else if (obj && typeof obj === "object") {
|
|
179
|
-
return Object.entries(obj).reduce((acc, [key, val]) => ({
|
|
180
|
-
...acc,
|
|
181
|
-
[key]: deepLowerHex(val),
|
|
182
|
-
}), {});
|
|
183
|
-
}
|
|
184
|
-
else if (typeof obj === "string" && /^0x[0-9A-Fa-f]+$/.test(obj)) {
|
|
185
|
-
return obj.toLowerCase();
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
return obj;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Deeply sort the keys of an object.
|
|
193
|
-
* @param obj - An object to sort the keys of.
|
|
194
|
-
* @returns A new object with sorted keys.
|
|
195
|
-
*/
|
|
196
|
-
function deepSortKeys(obj) {
|
|
197
|
-
if (obj === null || typeof obj !== "object") {
|
|
198
|
-
return obj;
|
|
199
|
-
}
|
|
200
|
-
if (Array.isArray(obj)) {
|
|
201
|
-
return obj.map(deepSortKeys);
|
|
202
|
-
}
|
|
203
|
-
return Object.fromEntries(Object.entries(obj)
|
|
204
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
205
|
-
.map(([k, v]) => [k, deepSortKeys(v)]));
|
|
206
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/src/types/common.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Hex } from "../common.js";
|
|
2
|
-
import type { TIF } from "../info/orders.js";
|
|
3
|
-
/** Order parameters. */
|
|
4
|
-
export type OrderParms = {
|
|
5
|
-
/** An integer representing the asset being traded. */
|
|
6
|
-
a: number;
|
|
7
|
-
/** Position side (true for long, false for short). */
|
|
8
|
-
b: boolean;
|
|
9
|
-
/** Price. */
|
|
10
|
-
p: string;
|
|
11
|
-
/** Size (in base currency units). */
|
|
12
|
-
s: string;
|
|
13
|
-
/** Is reduce-only? */
|
|
14
|
-
r: boolean;
|
|
15
|
-
/** Order type and parameters. */
|
|
16
|
-
t: {
|
|
17
|
-
/** Limit order parameters. */
|
|
18
|
-
limit: {
|
|
19
|
-
/** Time-in-force. */
|
|
20
|
-
tif: TIF;
|
|
21
|
-
};
|
|
22
|
-
} | {
|
|
23
|
-
/** Trigger order parameters. */
|
|
24
|
-
trigger: {
|
|
25
|
-
/** Is the market order. */
|
|
26
|
-
isMarket: boolean;
|
|
27
|
-
/** Trigger price. */
|
|
28
|
-
triggerPx: string;
|
|
29
|
-
/** Indicates if it's take-profit or stop-loss. */
|
|
30
|
-
tpsl: "tp" | "sl";
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
/** Client Order ID. */
|
|
34
|
-
c?: Hex;
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/src/types/exchange/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,wBAAwB;AACxB,MAAM,MAAM,UAAU,GAAG;IACrB,sDAAsD;IACtD,CAAC,EAAE,MAAM,CAAC;IAEV,sDAAsD;IACtD,CAAC,EAAE,OAAO,CAAC;IAEX,aAAa;IACb,CAAC,EAAE,MAAM,CAAC;IAEV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IAEV,sBAAsB;IACtB,CAAC,EAAE,OAAO,CAAC;IAEX,iCAAiC;IACjC,CAAC,EACK;QACE,8BAA8B;QAC9B,KAAK,EAAE;YACH,qBAAqB;YACrB,GAAG,EAAE,GAAG,CAAC;SACZ,CAAC;KACL,GACC;QACE,gCAAgC;QAChC,OAAO,EAAE;YACL,2BAA2B;YAC3B,QAAQ,EAAE,OAAO,CAAC;YAElB,qBAAqB;YACrB,SAAS,EAAE,MAAM,CAAC;YAElB,kDAAkD;YAClD,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;SACrB,CAAC;KACL,CAAC;IAEN,uBAAuB;IACvB,CAAC,CAAC,EAAE,GAAG,CAAC;CACX,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Hex } from "../common.js";
|
|
2
|
-
/** The transaction details. */
|
|
3
|
-
export interface TxDetails {
|
|
4
|
-
/** The action of the transaction. */
|
|
5
|
-
action: {
|
|
6
|
-
/** Type of action. */
|
|
7
|
-
type: string;
|
|
8
|
-
/** Additional action parameters. */
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
};
|
|
11
|
-
/** The block number in which the transaction was included. */
|
|
12
|
-
block: number;
|
|
13
|
-
/** The error message if the transaction failed. */
|
|
14
|
-
error: string | null;
|
|
15
|
-
/** The hash of the transaction. */
|
|
16
|
-
hash: Hex;
|
|
17
|
-
/** The time at which the transaction was created. */
|
|
18
|
-
time: number;
|
|
19
|
-
/** The user that created the transaction. */
|
|
20
|
-
user: Hex;
|
|
21
|
-
}
|
|
22
|
-
/** The block details. */
|
|
23
|
-
export interface BlockDetails {
|
|
24
|
-
/** The time at which the block was created. */
|
|
25
|
-
blockTime: number;
|
|
26
|
-
/** The hash of the block. */
|
|
27
|
-
hash: Hex;
|
|
28
|
-
/** The height of the block. */
|
|
29
|
-
height: number;
|
|
30
|
-
/** The number of transactions in the block. */
|
|
31
|
-
numTxs: number;
|
|
32
|
-
/** The proposer of the block. */
|
|
33
|
-
proposer: Hex;
|
|
34
|
-
/** The transactions in the block. */
|
|
35
|
-
txs: TxDetails[];
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/src/types/explorer/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAExC,+BAA+B;AAC/B,MAAM,WAAW,SAAS;IACtB,qCAAqC;IACrC,MAAM,EAAE;QACJ,sBAAsB;QACtB,IAAI,EAAE,MAAM,CAAC;QAEb,oCAAoC;QACpC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KAC1B,CAAC;IAEF,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IAEd,mDAAmD;IACnD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB,mCAAmC;IACnC,IAAI,EAAE,GAAG,CAAC;IAEV,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IAEb,6CAA6C;IAC7C,IAAI,EAAE,GAAG,CAAC;CACb;AAED,yBAAyB;AACzB,MAAM,WAAW,YAAY;IACzB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAElB,6BAA6B;IAC7B,IAAI,EAAE,GAAG,CAAC;IAEV,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IAEf,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;IAEf,iCAAiC;IACjC,QAAQ,EAAE,GAAG,CAAC;IAEd,qCAAqC;IACrC,GAAG,EAAE,SAAS,EAAE,CAAC;CACpB"}
|