@nktkas/hyperliquid 0.13.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/CONTRIBUTING.md +59 -0
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/SECURITY.md +7 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +10 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +43 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +65 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +283 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +211 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.js +32 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +26 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.js +109 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.js +237 -0
- package/esm/mod.d.ts +24 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +9 -0
- package/esm/package.json +3 -0
- package/esm/src/clients/event.d.ts +374 -0
- package/esm/src/clients/event.d.ts.map +1 -0
- package/esm/src/clients/event.js +490 -0
- package/esm/src/clients/public.d.ts +695 -0
- package/esm/src/clients/public.d.ts.map +1 -0
- package/esm/src/clients/public.js +704 -0
- package/esm/src/clients/wallet.d.ts +682 -0
- package/esm/src/clients/wallet.d.ts.map +1 -0
- package/esm/src/clients/wallet.js +984 -0
- package/esm/src/transports/base.d.ts +55 -0
- package/esm/src/transports/base.d.ts.map +1 -0
- package/esm/src/transports/base.js +14 -0
- package/esm/src/transports/http/http_transport.d.ts +78 -0
- package/esm/src/transports/http/http_transport.d.ts.map +1 -0
- package/esm/src/transports/http/http_transport.js +170 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
- package/esm/src/transports/websocket/hyperliquid_event_target.js +33 -0
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
- package/esm/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
- package/esm/src/transports/websocket/reconnecting_websocket.js +370 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.js +201 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts +117 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -0
- package/esm/src/transports/websocket/websocket_transport.js +233 -0
- package/esm/src/utils/key_sort.d.ts +21 -0
- package/esm/src/utils/key_sort.d.ts.map +1 -0
- package/esm/src/utils/key_sort.js +124 -0
- package/esm/src/utils/signing.d.ts +109 -0
- package/esm/src/utils/signing.d.ts.map +1 -0
- package/esm/src/utils/signing.js +164 -0
- package/package.json +34 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +2 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +17 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +95 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +1 -0
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +14 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts +23 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +49 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts +55 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +88 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts +2 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +4 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts +52 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts +120 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +235 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts +19 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +35 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts +2 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +29 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts +37 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +113 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts +37 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +240 -0
- package/script/mod.d.ts +24 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +27 -0
- package/script/package.json +3 -0
- package/script/src/clients/event.d.ts +374 -0
- package/script/src/clients/event.d.ts.map +1 -0
- package/script/src/clients/event.js +494 -0
- package/script/src/clients/public.d.ts +695 -0
- package/script/src/clients/public.d.ts.map +1 -0
- package/script/src/clients/public.js +708 -0
- package/script/src/clients/wallet.d.ts +682 -0
- package/script/src/clients/wallet.d.ts.map +1 -0
- package/script/src/clients/wallet.js +989 -0
- package/script/src/transports/base.d.ts +55 -0
- package/script/src/transports/base.d.ts.map +1 -0
- package/script/src/transports/base.js +18 -0
- package/script/src/transports/http/http_transport.d.ts +78 -0
- package/script/src/transports/http/http_transport.d.ts.map +1 -0
- package/script/src/transports/http/http_transport.js +175 -0
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +66 -0
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -0
- package/script/src/transports/websocket/hyperliquid_event_target.js +37 -0
- package/script/src/transports/websocket/reconnecting_websocket.d.ts +160 -0
- package/script/src/transports/websocket/reconnecting_websocket.d.ts.map +1 -0
- package/script/src/transports/websocket/reconnecting_websocket.js +374 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts +63 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -0
- package/script/src/transports/websocket/websocket_request_dispatcher.js +206 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +117 -0
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -0
- package/script/src/transports/websocket/websocket_transport.js +237 -0
- package/script/src/utils/key_sort.d.ts +21 -0
- package/script/src/utils/key_sort.d.ts.map +1 -0
- package/script/src/utils/key_sort.js +127 -0
- package/script/src/utils/signing.d.ts +109 -0
- package/script/src/utils/signing.d.ts.map +1 -0
- package/script/src/utils/signing.js +172 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { concat } from "../../bytes/1.0.4/concat.js";
|
|
4
|
+
const FOUR_BITS = 16;
|
|
5
|
+
const FIVE_BITS = 32;
|
|
6
|
+
const SEVEN_BITS = 128;
|
|
7
|
+
const EIGHT_BITS = 256;
|
|
8
|
+
const FIFTEEN_BITS = 32768;
|
|
9
|
+
const SIXTEEN_BITS = 65536;
|
|
10
|
+
const THIRTY_ONE_BITS = 2147483648;
|
|
11
|
+
const THIRTY_TWO_BITS = 4294967296;
|
|
12
|
+
const SIXTY_THREE_BITS = 9223372036854775808n;
|
|
13
|
+
const SIXTY_FOUR_BITS = 18446744073709551616n;
|
|
14
|
+
const encoder = new TextEncoder();
|
|
15
|
+
/**
|
|
16
|
+
* Encode a value to {@link https://msgpack.org/ | MessagePack} binary format.
|
|
17
|
+
*
|
|
18
|
+
* @example Usage
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { encode } from "@std/msgpack/encode";
|
|
21
|
+
* import { assertEquals } from "@std/assert";
|
|
22
|
+
*
|
|
23
|
+
* const obj = {
|
|
24
|
+
* str: "deno",
|
|
25
|
+
* arr: [1, 2, 3],
|
|
26
|
+
* map: {
|
|
27
|
+
* foo: "bar"
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* const encoded = encode(obj);
|
|
32
|
+
*
|
|
33
|
+
* assertEquals(encoded.length, 31);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param object Value to encode to MessagePack binary format.
|
|
37
|
+
* @returns Encoded MessagePack binary data.
|
|
38
|
+
*/
|
|
39
|
+
export function encode(object) {
|
|
40
|
+
const byteParts = [];
|
|
41
|
+
encodeSlice(object, byteParts);
|
|
42
|
+
return concat(byteParts);
|
|
43
|
+
}
|
|
44
|
+
function encodeFloat64(num) {
|
|
45
|
+
const dataView = new DataView(new ArrayBuffer(9));
|
|
46
|
+
dataView.setFloat64(1, num);
|
|
47
|
+
dataView.setUint8(0, 0xcb);
|
|
48
|
+
return new Uint8Array(dataView.buffer);
|
|
49
|
+
}
|
|
50
|
+
function encodeNumber(num) {
|
|
51
|
+
if (!Number.isInteger(num)) { // float 64
|
|
52
|
+
return encodeFloat64(num);
|
|
53
|
+
}
|
|
54
|
+
if (num < 0) {
|
|
55
|
+
if (num >= -FIVE_BITS) { // negative fixint
|
|
56
|
+
return new Uint8Array([num]);
|
|
57
|
+
}
|
|
58
|
+
if (num >= -SEVEN_BITS) { // int 8
|
|
59
|
+
return new Uint8Array([0xd0, num]);
|
|
60
|
+
}
|
|
61
|
+
if (num >= -FIFTEEN_BITS) { // int 16
|
|
62
|
+
const dataView = new DataView(new ArrayBuffer(3));
|
|
63
|
+
dataView.setInt16(1, num);
|
|
64
|
+
dataView.setUint8(0, 0xd1);
|
|
65
|
+
return new Uint8Array(dataView.buffer);
|
|
66
|
+
}
|
|
67
|
+
if (num >= -THIRTY_ONE_BITS) { // int 32
|
|
68
|
+
const dataView = new DataView(new ArrayBuffer(5));
|
|
69
|
+
dataView.setInt32(1, num);
|
|
70
|
+
dataView.setUint8(0, 0xd2);
|
|
71
|
+
return new Uint8Array(dataView.buffer);
|
|
72
|
+
}
|
|
73
|
+
// float 64
|
|
74
|
+
return encodeFloat64(num);
|
|
75
|
+
}
|
|
76
|
+
// if the number fits within a positive fixint, use it
|
|
77
|
+
if (num <= 0x7f) {
|
|
78
|
+
return new Uint8Array([num]);
|
|
79
|
+
}
|
|
80
|
+
if (num < EIGHT_BITS) { // uint8
|
|
81
|
+
return new Uint8Array([0xcc, num]);
|
|
82
|
+
}
|
|
83
|
+
if (num < SIXTEEN_BITS) { // uint16
|
|
84
|
+
const dataView = new DataView(new ArrayBuffer(3));
|
|
85
|
+
dataView.setUint16(1, num);
|
|
86
|
+
dataView.setUint8(0, 0xcd);
|
|
87
|
+
return new Uint8Array(dataView.buffer);
|
|
88
|
+
}
|
|
89
|
+
if (num < THIRTY_TWO_BITS) { // uint32
|
|
90
|
+
const dataView = new DataView(new ArrayBuffer(5));
|
|
91
|
+
dataView.setUint32(1, num);
|
|
92
|
+
dataView.setUint8(0, 0xce);
|
|
93
|
+
return new Uint8Array(dataView.buffer);
|
|
94
|
+
}
|
|
95
|
+
// float 64
|
|
96
|
+
return encodeFloat64(num);
|
|
97
|
+
}
|
|
98
|
+
function encodeSlice(object, byteParts) {
|
|
99
|
+
if (object === null) {
|
|
100
|
+
byteParts.push(new Uint8Array([0xc0]));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (object === false) {
|
|
104
|
+
byteParts.push(new Uint8Array([0xc2]));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (object === true) {
|
|
108
|
+
byteParts.push(new Uint8Array([0xc3]));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (typeof object === "number") {
|
|
112
|
+
byteParts.push(encodeNumber(object));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (typeof object === "bigint") {
|
|
116
|
+
if (object < 0) {
|
|
117
|
+
if (object < -SIXTY_THREE_BITS) {
|
|
118
|
+
throw new Error("Cannot safely encode bigint larger than 64 bits");
|
|
119
|
+
}
|
|
120
|
+
const dataView = new DataView(new ArrayBuffer(9));
|
|
121
|
+
dataView.setBigInt64(1, object);
|
|
122
|
+
dataView.setUint8(0, 0xd3);
|
|
123
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (object >= SIXTY_FOUR_BITS) {
|
|
127
|
+
throw new Error("Cannot safely encode bigint larger than 64 bits");
|
|
128
|
+
}
|
|
129
|
+
const dataView = new DataView(new ArrayBuffer(9));
|
|
130
|
+
dataView.setBigUint64(1, object);
|
|
131
|
+
dataView.setUint8(0, 0xcf);
|
|
132
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (typeof object === "string") {
|
|
136
|
+
const encoded = encoder.encode(object);
|
|
137
|
+
const len = encoded.length;
|
|
138
|
+
if (len < FIVE_BITS) { // fixstr
|
|
139
|
+
byteParts.push(new Uint8Array([0xa0 | len]));
|
|
140
|
+
}
|
|
141
|
+
else if (len < EIGHT_BITS) { // str 8
|
|
142
|
+
byteParts.push(new Uint8Array([0xd9, len]));
|
|
143
|
+
}
|
|
144
|
+
else if (len < SIXTEEN_BITS) { // str 16
|
|
145
|
+
const dataView = new DataView(new ArrayBuffer(3));
|
|
146
|
+
dataView.setUint16(1, len);
|
|
147
|
+
dataView.setUint8(0, 0xda);
|
|
148
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
149
|
+
}
|
|
150
|
+
else if (len < THIRTY_TWO_BITS) { // str 32
|
|
151
|
+
const dataView = new DataView(new ArrayBuffer(5));
|
|
152
|
+
dataView.setUint32(1, len);
|
|
153
|
+
dataView.setUint8(0, 0xdb);
|
|
154
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
throw new Error("Cannot safely encode string with size larger than 32 bits");
|
|
158
|
+
}
|
|
159
|
+
byteParts.push(encoded);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (object instanceof Uint8Array) {
|
|
163
|
+
if (object.length < EIGHT_BITS) { // bin 8
|
|
164
|
+
byteParts.push(new Uint8Array([0xc4, object.length]));
|
|
165
|
+
}
|
|
166
|
+
else if (object.length < SIXTEEN_BITS) { // bin 16
|
|
167
|
+
const dataView = new DataView(new ArrayBuffer(3));
|
|
168
|
+
dataView.setUint16(1, object.length);
|
|
169
|
+
dataView.setUint8(0, 0xc5);
|
|
170
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
171
|
+
}
|
|
172
|
+
else if (object.length < THIRTY_TWO_BITS) { // bin 32
|
|
173
|
+
const dataView = new DataView(new ArrayBuffer(5));
|
|
174
|
+
dataView.setUint32(1, object.length);
|
|
175
|
+
dataView.setUint8(0, 0xc6);
|
|
176
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new Error("Cannot safely encode Uint8Array with size larger than 32 bits");
|
|
180
|
+
}
|
|
181
|
+
byteParts.push(object);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(object)) {
|
|
185
|
+
if (object.length < FOUR_BITS) { // fixarray
|
|
186
|
+
byteParts.push(new Uint8Array([0x90 | object.length]));
|
|
187
|
+
}
|
|
188
|
+
else if (object.length < SIXTEEN_BITS) { // array 16
|
|
189
|
+
const dataView = new DataView(new ArrayBuffer(3));
|
|
190
|
+
dataView.setUint16(1, object.length);
|
|
191
|
+
dataView.setUint8(0, 0xdc);
|
|
192
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
193
|
+
}
|
|
194
|
+
else if (object.length < THIRTY_TWO_BITS) { // array 32
|
|
195
|
+
const dataView = new DataView(new ArrayBuffer(5));
|
|
196
|
+
dataView.setUint32(1, object.length);
|
|
197
|
+
dataView.setUint8(0, 0xdd);
|
|
198
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
throw new Error("Cannot safely encode array with size larger than 32 bits");
|
|
202
|
+
}
|
|
203
|
+
for (const obj of object) {
|
|
204
|
+
encodeSlice(obj, byteParts);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// If object is a plain object
|
|
209
|
+
const prototype = Object.getPrototypeOf(object);
|
|
210
|
+
if (prototype === null || prototype === Object.prototype) {
|
|
211
|
+
const numKeys = Object.keys(object).length;
|
|
212
|
+
if (numKeys < FOUR_BITS) { // fixarray
|
|
213
|
+
byteParts.push(new Uint8Array([0x80 | numKeys]));
|
|
214
|
+
}
|
|
215
|
+
else if (numKeys < SIXTEEN_BITS) { // map 16
|
|
216
|
+
const dataView = new DataView(new ArrayBuffer(3));
|
|
217
|
+
dataView.setUint16(1, numKeys);
|
|
218
|
+
dataView.setUint8(0, 0xde);
|
|
219
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
220
|
+
}
|
|
221
|
+
else if (numKeys < THIRTY_TWO_BITS) { // map 32
|
|
222
|
+
const dataView = new DataView(new ArrayBuffer(5));
|
|
223
|
+
dataView.setUint32(1, numKeys);
|
|
224
|
+
dataView.setUint8(0, 0xdf);
|
|
225
|
+
byteParts.push(new Uint8Array(dataView.buffer));
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
throw new Error("Cannot safely encode map with size larger than 32 bits");
|
|
229
|
+
}
|
|
230
|
+
for (const [key, value] of Object.entries(object)) {
|
|
231
|
+
encodeSlice(key, byteParts);
|
|
232
|
+
encodeSlice(value, byteParts);
|
|
233
|
+
}
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
throw new Error("Cannot safely encode value into messagepack");
|
|
237
|
+
}
|
package/esm/mod.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from "./src/clients/event.js";
|
|
2
|
+
export * from "./src/clients/public.js";
|
|
3
|
+
export * from "./src/clients/wallet.js";
|
|
4
|
+
export * from "./src/transports/base.js";
|
|
5
|
+
export * from "./src/transports/http/http_transport.js";
|
|
6
|
+
export * from "./src/transports/websocket/websocket_transport.js";
|
|
7
|
+
export type { MessageBufferStrategy, ReconnectingWebSocketOptions, } from "./src/transports/websocket/reconnecting_websocket.js";
|
|
8
|
+
export { WebSocketRequestError } from "./src/transports/websocket/websocket_request_dispatcher.js";
|
|
9
|
+
export type * from "./src/types/common";
|
|
10
|
+
export type * from "./src/types/exchange/common";
|
|
11
|
+
export type * from "./src/types/exchange/requests";
|
|
12
|
+
export type * from "./src/types/exchange/responses";
|
|
13
|
+
export type * from "./src/types/explorer/common";
|
|
14
|
+
export type * from "./src/types/explorer/requests";
|
|
15
|
+
export type * from "./src/types/explorer/responses";
|
|
16
|
+
export type * from "./src/types/info/accounts";
|
|
17
|
+
export type * from "./src/types/info/assets";
|
|
18
|
+
export type * from "./src/types/info/orders";
|
|
19
|
+
export type * from "./src/types/info/requests";
|
|
20
|
+
export type * from "./src/types/info/vaults";
|
|
21
|
+
export type * from "./src/types/subscriptions/common";
|
|
22
|
+
export type * from "./src/types/subscriptions/requests";
|
|
23
|
+
export type { AbstractEthersSigner, AbstractEthersV5Signer, AbstractViemWalletClient } from "./src/utils/signing.js";
|
|
24
|
+
//# sourceMappingURL=mod.d.ts.map
|
package/esm/mod.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,yCAAyC,CAAC;AAExD,cAAc,mDAAmD,CAAC;AAClE,YAAY,EACR,qBAAqB,EACrB,4BAA4B,GAC/B,MAAM,sDAAsD,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AAGnG,mBAAmB,oBAAoB,CAAC;AAExC,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,+BAA+B,CAAC;AACnD,mBAAmB,gCAAgC,CAAC;AAEpD,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,+BAA+B,CAAC;AACnD,mBAAmB,gCAAgC,CAAC;AAEpD,mBAAmB,2BAA2B,CAAC;AAC/C,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,2BAA2B,CAAC;AAC/C,mBAAmB,yBAAyB,CAAC;AAE7C,mBAAmB,kCAAkC,CAAC;AACtD,mBAAmB,oCAAoC,CAAC;AAGxD,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/esm/mod.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Clients
|
|
2
|
+
export * from "./src/clients/event.js";
|
|
3
|
+
export * from "./src/clients/public.js";
|
|
4
|
+
export * from "./src/clients/wallet.js";
|
|
5
|
+
// Transports
|
|
6
|
+
export * from "./src/transports/base.js";
|
|
7
|
+
export * from "./src/transports/http/http_transport.js";
|
|
8
|
+
export * from "./src/transports/websocket/websocket_transport.js";
|
|
9
|
+
export { WebSocketRequestError } from "./src/transports/websocket/websocket_request_dispatcher.js";
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import type { ISubscriptionTransport, Subscription } from "../transports/base.js";
|
|
2
|
+
import type { WsActiveAssetCtxRequest, WsActiveAssetDataRequest, WsCandleRequest, WsL2BookRequest, WsNotificationRequest, WsOrderUpdatesRequest, WsTradesRequest, WsUserEventsRequest, WsUserFillsRequest, WsUserFundingsRequest, WsUserNonFundingLedgerUpdatesRequest, WsUserTwapHistoryRequest, WsUserTwapSliceFillsRequest, WsWebData2Request } from "../types/subscriptions/requests";
|
|
3
|
+
import type { WsActiveAssetCtx, WsActiveAssetData, WsActiveSpotAssetCtx, WsAllMids, WsNotification, WsTrade, WsUserEvent, WsUserFills, WsUserFundings, WsUserNonFundingLedgerUpdates, WsUserTwapHistory, WsUserTwapSliceFills, WsWebData2 } from "../types/subscriptions/common";
|
|
4
|
+
import type { Candle } from "../types/info/assets";
|
|
5
|
+
import type { Book, Order, OrderStatus } from "../types/info/orders";
|
|
6
|
+
/** Parameters for the {@linkcode EventClient} constructor. */
|
|
7
|
+
export interface EventClientParameters<T extends ISubscriptionTransport = ISubscriptionTransport> {
|
|
8
|
+
/** The transport used to connect to the Hyperliquid API. */
|
|
9
|
+
transport: T;
|
|
10
|
+
}
|
|
11
|
+
/** Parameters for the {@linkcode EventClient.activeAssetCtx} method. */
|
|
12
|
+
export type EventActiveAssetCtxParameters = Omit<WsActiveAssetCtxRequest, "type">;
|
|
13
|
+
/** Parameters for the {@linkcode EventClient.activeAssetData} method. */
|
|
14
|
+
export type EventActiveAssetDataParameters = Omit<WsActiveAssetDataRequest, "type">;
|
|
15
|
+
/** Parameters for the {@linkcode EventClient.candle} method. */
|
|
16
|
+
export type EventCandleParameters = Omit<WsCandleRequest, "type">;
|
|
17
|
+
/** Parameters for the {@linkcode EventClient.l2Book} method. */
|
|
18
|
+
export type EventL2BookParameters = Omit<WsL2BookRequest, "type">;
|
|
19
|
+
/** Parameters for the {@linkcode EventClient.notification} method. */
|
|
20
|
+
export type EventNotificationParameters = Omit<WsNotificationRequest, "type">;
|
|
21
|
+
/** Parameters for the {@linkcode EventClient.orderUpdates} method. */
|
|
22
|
+
export type EventOrderUpdatesParameters = Omit<WsOrderUpdatesRequest, "type">;
|
|
23
|
+
/** Parameters for the {@linkcode EventClient.trades} method. */
|
|
24
|
+
export type EventTradesParameters = Omit<WsTradesRequest, "type">;
|
|
25
|
+
/** Parameters for the {@linkcode EventClient.userEvents} method. */
|
|
26
|
+
export type EventUserEventsParameters = Omit<WsUserEventsRequest, "type">;
|
|
27
|
+
/** Parameters for the {@linkcode EventClient.userFills} method. */
|
|
28
|
+
export type EventUserFillsParameters = Omit<WsUserFillsRequest, "type">;
|
|
29
|
+
/** Parameters for the {@linkcode EventClient.userFundings} method. */
|
|
30
|
+
export type EventUserFundingsParameters = Omit<WsUserFundingsRequest, "type">;
|
|
31
|
+
/** Parameters for the {@linkcode EventClient.userNonFundingLedgerUpdates} method. */
|
|
32
|
+
export type EventUserNonFundingLedgerUpdatesParameters = Omit<WsUserNonFundingLedgerUpdatesRequest, "type">;
|
|
33
|
+
/** Parameters for the {@linkcode EventClient.userTwapHistory} method. */
|
|
34
|
+
export type EventUserTwapHistory = Omit<WsUserTwapHistoryRequest, "type">;
|
|
35
|
+
/** Parameters for the {@linkcode EventClient.userTwapSliceFills} method. */
|
|
36
|
+
export type EventUserTwapSliceFills = Omit<WsUserTwapSliceFillsRequest, "type">;
|
|
37
|
+
/** Parameters for the {@linkcode EventClient.webData2} method. */
|
|
38
|
+
export type EventWebData2Parameters = Omit<WsWebData2Request, "type">;
|
|
39
|
+
/**
|
|
40
|
+
* Event client for subscribing to various Hyperliquid events.
|
|
41
|
+
* @typeParam T - The type of transport used to connect to the Hyperliquid Websocket API.
|
|
42
|
+
*/
|
|
43
|
+
export declare class EventClient<T extends ISubscriptionTransport = ISubscriptionTransport> {
|
|
44
|
+
/** The transport used to connect to the Hyperliquid API. */
|
|
45
|
+
transport: T;
|
|
46
|
+
/**
|
|
47
|
+
* Initialises a new instance.
|
|
48
|
+
* @param args - The arguments for initialisation.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
53
|
+
*
|
|
54
|
+
* const transport = new hl.WebSocketTransport();
|
|
55
|
+
* const client = new hl.EventClient({ transport });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
constructor(args: EventClientParameters<T>);
|
|
59
|
+
/**
|
|
60
|
+
* Subscribe to context updates for a specific perpetual asset.
|
|
61
|
+
* @param args - The parameters for the subscription.
|
|
62
|
+
* @param listener - The callback function to be called when the event is received.
|
|
63
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
64
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
70
|
+
*
|
|
71
|
+
* const transport = new hl.WebSocketTransport();
|
|
72
|
+
* const client = new hl.EventClient({ transport });
|
|
73
|
+
*
|
|
74
|
+
* const sub = await client.activeAssetCtx({ coin: "BTC" }, (data) => {
|
|
75
|
+
* console.log(data);
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
activeAssetCtx(args: EventActiveAssetCtxParameters, listener: (data: WsActiveAssetCtx | WsActiveSpotAssetCtx) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
80
|
+
/**
|
|
81
|
+
* Subscribe to trading data updates for a specific asset and user.
|
|
82
|
+
* @param args - The parameters for the subscription.
|
|
83
|
+
* @param listener - The callback function to be called when the event is received.
|
|
84
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
85
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
91
|
+
*
|
|
92
|
+
* const transport = new hl.WebSocketTransport();
|
|
93
|
+
* const client = new hl.EventClient({ transport });
|
|
94
|
+
*
|
|
95
|
+
* const sub = await client.activeAssetData({ coin: "BTC", user: "0x..." }, (data) => {
|
|
96
|
+
* console.log(data);
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
activeAssetData(args: EventActiveAssetDataParameters, listener: (data: WsActiveAssetData) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
101
|
+
/**
|
|
102
|
+
* Subscribe to mid prices for all actively traded assets.
|
|
103
|
+
* @param listener - The callback function to be called when the event is received.
|
|
104
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
105
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
111
|
+
*
|
|
112
|
+
* const transport = new hl.WebSocketTransport();
|
|
113
|
+
* const client = new hl.EventClient({ transport });
|
|
114
|
+
*
|
|
115
|
+
* const sub = await client.allMids((data) => {
|
|
116
|
+
* console.log(data);
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
allMids(listener: (data: WsAllMids) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
121
|
+
/**
|
|
122
|
+
* Subscribe to candlestick data updates for a specific asset.
|
|
123
|
+
* @param args - The parameters for the subscription.
|
|
124
|
+
* @param listener - The callback function to be called when the event is received.
|
|
125
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
126
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
127
|
+
*
|
|
128
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
132
|
+
*
|
|
133
|
+
* const transport = new hl.WebSocketTransport();
|
|
134
|
+
* const client = new hl.EventClient({ transport });
|
|
135
|
+
*
|
|
136
|
+
* const sub = await client.candle({ coin: "BTC", interval: "1h" }, (data) => {
|
|
137
|
+
* console.log(data);
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
candle(args: EventCandleParameters, listener: (data: Candle) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
142
|
+
/**
|
|
143
|
+
* Subscribe to L2 order book updates for a specific asset.
|
|
144
|
+
* @param args - The parameters for the subscription.
|
|
145
|
+
* @param listener - The callback function to be called when the event is received.
|
|
146
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
147
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
148
|
+
*
|
|
149
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
153
|
+
*
|
|
154
|
+
* const transport = new hl.WebSocketTransport();
|
|
155
|
+
* const client = new hl.EventClient({ transport });
|
|
156
|
+
*
|
|
157
|
+
* const sub = await client.l2Book({ coin: "BTC" }, (data) => {
|
|
158
|
+
* console.log(data);
|
|
159
|
+
* });
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
l2Book(args: EventL2BookParameters, listener: (data: Book) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
163
|
+
/**
|
|
164
|
+
* Subscribe to user notification.
|
|
165
|
+
* @param args - The parameters for the subscription.
|
|
166
|
+
* @param listener - The callback function to be called when the event is received.
|
|
167
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
168
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
169
|
+
*
|
|
170
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
174
|
+
*
|
|
175
|
+
* const transport = new hl.WebSocketTransport();
|
|
176
|
+
* const client = new hl.EventClient({ transport });
|
|
177
|
+
*
|
|
178
|
+
* const sub = await client.notification({ user: "0x..." }, (data) => {
|
|
179
|
+
* console.log(data);
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
notification(args: EventNotificationParameters, listener: (data: WsNotification) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
184
|
+
/**
|
|
185
|
+
* Subscribe to order status updates for a specific user.
|
|
186
|
+
* @param args - The parameters for the subscription.
|
|
187
|
+
* @param listener - The callback function to be called when the event is received.
|
|
188
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
189
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
190
|
+
*
|
|
191
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
195
|
+
*
|
|
196
|
+
* const transport = new hl.WebSocketTransport();
|
|
197
|
+
* const client = new hl.EventClient({ transport });
|
|
198
|
+
*
|
|
199
|
+
* const sub = await client.orderUpdates({ user: "0x..." }, (data) => {
|
|
200
|
+
* console.log(data);
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
orderUpdates(args: EventOrderUpdatesParameters, listener: (data: OrderStatus<Order>[]) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
205
|
+
/**
|
|
206
|
+
* Subscribe to real-time trade updates for a specific asset.
|
|
207
|
+
* @param args - The parameters for the subscription.
|
|
208
|
+
* @param listener - The callback function to be called when the event is received.
|
|
209
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
210
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
211
|
+
*
|
|
212
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
216
|
+
*
|
|
217
|
+
* const transport = new hl.WebSocketTransport();
|
|
218
|
+
* const client = new hl.EventClient({ transport });
|
|
219
|
+
*
|
|
220
|
+
* const sub = await client.trades({ coin: "BTC" }, (data) => {
|
|
221
|
+
* console.log(data);
|
|
222
|
+
* });
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
trades(args: EventTradesParameters, listener: (data: WsTrade[]) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
226
|
+
/**
|
|
227
|
+
* Subscribe to all events for a specific user.
|
|
228
|
+
* @param args - The parameters for the subscription.
|
|
229
|
+
* @param listener - The callback function to be called when the event is received.
|
|
230
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
231
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
232
|
+
*
|
|
233
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
237
|
+
*
|
|
238
|
+
* const transport = new hl.WebSocketTransport();
|
|
239
|
+
* const client = new hl.EventClient({ transport });
|
|
240
|
+
*
|
|
241
|
+
* const sub = await client.userEvents({ user: "0x..." }, (data) => {
|
|
242
|
+
* console.log(data);
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
userEvents(args: EventUserEventsParameters, listener: (data: WsUserEvent) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
247
|
+
/**
|
|
248
|
+
* Subscribe to trade fill updates for a specific user.
|
|
249
|
+
* @param args - The parameters for the subscription.
|
|
250
|
+
* @param listener - The callback function to be called when the event is received.
|
|
251
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
252
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
253
|
+
*
|
|
254
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
258
|
+
*
|
|
259
|
+
* const transport = new hl.WebSocketTransport();
|
|
260
|
+
* const client = new hl.EventClient({ transport });
|
|
261
|
+
*
|
|
262
|
+
* const sub = await client.userFills({ user: "0x..." }, (data) => {
|
|
263
|
+
* console.log(data);
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
userFills(args: EventUserFillsParameters, listener: (data: WsUserFills) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
268
|
+
/**
|
|
269
|
+
* Subscribe to funding payment updates for a specific user.
|
|
270
|
+
* @param args - The parameters for the subscription.
|
|
271
|
+
* @param listener - The callback function to be called when the event is received.
|
|
272
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
273
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
274
|
+
*
|
|
275
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
279
|
+
*
|
|
280
|
+
* const transport = new hl.WebSocketTransport();
|
|
281
|
+
* const client = new hl.EventClient({ transport });
|
|
282
|
+
*
|
|
283
|
+
* const sub = await client.userFundings({ user: "0x..." }, (data) => {
|
|
284
|
+
* console.log(data);
|
|
285
|
+
* });
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
userFundings(args: EventUserFundingsParameters, listener: (data: WsUserFundings) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
289
|
+
/**
|
|
290
|
+
* Subscribe to non-funding ledger updates for a specific user.
|
|
291
|
+
* @param args - The parameters for the subscription.
|
|
292
|
+
* @param listener - The callback function to be called when the event is received.
|
|
293
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
294
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
295
|
+
*
|
|
296
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
300
|
+
*
|
|
301
|
+
* const transport = new hl.WebSocketTransport();
|
|
302
|
+
* const client = new hl.EventClient({ transport });
|
|
303
|
+
*
|
|
304
|
+
* const sub = await client.userNonFundingLedgerUpdates({ user: "0x..." }, (data) => {
|
|
305
|
+
* console.log(data);
|
|
306
|
+
* });
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
userNonFundingLedgerUpdates(args: EventUserNonFundingLedgerUpdatesParameters, listener: (data: WsUserNonFundingLedgerUpdates) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
310
|
+
/**
|
|
311
|
+
* Subscribe to TWAP order history updates for a specific user.
|
|
312
|
+
* @param args - The parameters for the subscription.
|
|
313
|
+
* @param listener - The callback function to be called when the event is received.
|
|
314
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
315
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
316
|
+
*
|
|
317
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
321
|
+
*
|
|
322
|
+
* const transport = new hl.WebSocketTransport();
|
|
323
|
+
* const client = new hl.EventClient({ transport });
|
|
324
|
+
*
|
|
325
|
+
* const sub = await client.userTwapHistory({ user: "0x..." }, (data) => {
|
|
326
|
+
* console.log(data);
|
|
327
|
+
* });
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
userTwapHistory(args: EventUserTwapHistory, listener: (data: WsUserTwapHistory) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
331
|
+
/**
|
|
332
|
+
* Subscribe to TWAP execution updates for a specific user.
|
|
333
|
+
* @param args - The parameters for the subscription.
|
|
334
|
+
* @param listener - The callback function to be called when the event is received.
|
|
335
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
336
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
337
|
+
*
|
|
338
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
342
|
+
*
|
|
343
|
+
* const transport = new hl.WebSocketTransport();
|
|
344
|
+
* const client = new hl.EventClient({ transport });
|
|
345
|
+
*
|
|
346
|
+
* const sub = await client.userTwapSliceFills({ user: "0x..." }, (data) => {
|
|
347
|
+
* console.log(data);
|
|
348
|
+
* });
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
userTwapSliceFills(args: EventUserTwapSliceFills, listener: (data: WsUserTwapSliceFills) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
352
|
+
/**
|
|
353
|
+
* Subscribe to comprehensive user and market data updates.
|
|
354
|
+
* @param args - The parameters for the subscription.
|
|
355
|
+
* @param listener - The callback function to be called when the event is received.
|
|
356
|
+
* @param signal - An optional abort signal for canceling the subscription request.
|
|
357
|
+
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
358
|
+
*
|
|
359
|
+
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Hyperliquid GitBook}
|
|
360
|
+
* @example
|
|
361
|
+
* ```ts
|
|
362
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
363
|
+
*
|
|
364
|
+
* const transport = new hl.WebSocketTransport();
|
|
365
|
+
* const client = new hl.EventClient({ transport });
|
|
366
|
+
*
|
|
367
|
+
* const sub = await client.webData2({ user: "0x..." }, (data) => {
|
|
368
|
+
* console.log(data);
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
webData2(args: EventWebData2Parameters, listener: (data: WsWebData2) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/src/clients/event.ts"],"names":[],"mappings":"AAAA,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