@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
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-2025 nktkas
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 nktkas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Hyperliquid API TypeScript SDK
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@nktkas/hyperliquid)
|
|
4
|
+
[](https://jsr.io/@nktkas/hyperliquid)
|
|
5
|
+
[](https://coveralls.io/github/nktkas/hyperliquid)
|
|
6
|
+
[](https://bundlejs.com/?q=@nktkas/hyperliquid)
|
|
5
7
|
|
|
6
8
|
Unofficial [Hyperliquid API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api) SDK for all major JS
|
|
7
9
|
runtimes, written in TypeScript and provided with tests.
|
|
@@ -9,12 +11,12 @@ runtimes, written in TypeScript and provided with tests.
|
|
|
9
11
|
## Features
|
|
10
12
|
|
|
11
13
|
- 🖋️ **Typed**: Source code is 100% TypeScript.
|
|
12
|
-
- 🧪 **Tested**: Good code coverage and type
|
|
14
|
+
- 🧪 **Tested**: Good code coverage and type testing.
|
|
13
15
|
- 📦 **Minimal dependencies**: Few small dependencies, standard JS is favored.
|
|
14
16
|
- 🌐 **Cross-Environment Support**: Compatible with all major JS runtimes, including Node.js, Deno, Bun, and browser
|
|
15
17
|
environments.
|
|
16
|
-
- 🔧 **
|
|
17
|
-
[ethers](https://github.com/ethers-io/ethers.js).
|
|
18
|
+
- 🔧 **Integratable**: Easy to use with [viem](https://github.com/wevm/viem),
|
|
19
|
+
[ethers](https://github.com/ethers-io/ethers.js) and web3 wallets.
|
|
18
20
|
- 📚 **Documented**: Comprehensive documentation and usage examples, provided directly in JSDoc annotations within the
|
|
19
21
|
source code.
|
|
20
22
|
|
|
@@ -22,16 +24,16 @@ runtimes, written in TypeScript and provided with tests.
|
|
|
22
24
|
|
|
23
25
|
```bash
|
|
24
26
|
# npm
|
|
25
|
-
|
|
27
|
+
npm i @nktkas/hyperliquid
|
|
26
28
|
|
|
27
29
|
# yarn
|
|
28
|
-
yarn
|
|
30
|
+
yarn add @nktkas/hyperliquid
|
|
29
31
|
|
|
30
32
|
# pnpm
|
|
31
|
-
pnpm
|
|
33
|
+
pnpm add @nktkas/hyperliquid
|
|
32
34
|
|
|
33
35
|
# bun
|
|
34
|
-
|
|
36
|
+
bun i @nktkas/hyperliquid
|
|
35
37
|
|
|
36
38
|
# deno
|
|
37
39
|
deno add jsr:@nktkas/hyperliquid
|
|
@@ -50,21 +52,15 @@ First, choose and configure your transport layer (more details in the [API Refer
|
|
|
50
52
|
import * as hl from "@nktkas/hyperliquid";
|
|
51
53
|
|
|
52
54
|
// HTTP Transport
|
|
53
|
-
const httpTransport = new hl.HttpTransport(
|
|
54
|
-
url: "https://api.hyperliquid.xyz", // API base URL for /info, /exchange, /explorer
|
|
55
|
-
timeout: 10_000, // Request timeout in ms
|
|
56
|
-
});
|
|
55
|
+
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters (e.g. url, timeout, fetchOptions)
|
|
57
56
|
|
|
58
|
-
//
|
|
59
|
-
const wsTransport = new hl.WebSocketTransport(
|
|
60
|
-
url: "wss://api.hyperliquid.xyz/ws", // WebSocket URL
|
|
61
|
-
timeout: 10_000, // Request timeout in ms
|
|
62
|
-
});
|
|
57
|
+
// or WebSocket Transport
|
|
58
|
+
const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters (e.g. url, timeout, keepAlive, reconnect)
|
|
63
59
|
```
|
|
64
60
|
|
|
65
61
|
### Initialize Client
|
|
66
62
|
|
|
67
|
-
Next, initialize
|
|
63
|
+
Next, initialize a client with the transport layer (more details in the [API Reference](#clients)):
|
|
68
64
|
|
|
69
65
|
#### Create PublicClient
|
|
70
66
|
|
|
@@ -80,7 +76,6 @@ const client = new hl.PublicClient({ transport });
|
|
|
80
76
|
```typescript
|
|
81
77
|
import * as hl from "@nktkas/hyperliquid";
|
|
82
78
|
import { createWalletClient, custom } from "viem";
|
|
83
|
-
import { arbitrum } from "viem/chains";
|
|
84
79
|
import { privateKeyToAccount } from "viem/accounts";
|
|
85
80
|
import { ethers } from "ethers";
|
|
86
81
|
|
|
@@ -96,12 +91,11 @@ const ethersClient = new hl.WalletClient({ wallet: ethersWallet, transport });
|
|
|
96
91
|
|
|
97
92
|
// 3. Using external wallet (e.g. MetaMask) via Viem
|
|
98
93
|
const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
99
|
-
const externalWallet = createWalletClient({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
const metamaskClient = new hl.WalletClient({ wallet: externalWallet, transport });
|
|
94
|
+
const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
95
|
+
const viemMetamaskClient = new hl.WalletClient({ wallet: externalWallet, transport });
|
|
96
|
+
|
|
97
|
+
// 4. Using external wallet (e.g. MetaMask) via `window.ethereum` directly
|
|
98
|
+
const windowMetamaskClient = new hl.WalletClient({ wallet: window.ethereum, transport });
|
|
105
99
|
```
|
|
106
100
|
|
|
107
101
|
#### Create EventClient
|
|
@@ -109,8 +103,99 @@ const metamaskClient = new hl.WalletClient({ wallet: externalWallet, transport }
|
|
|
109
103
|
```typescript
|
|
110
104
|
import * as hl from "@nktkas/hyperliquid";
|
|
111
105
|
|
|
106
|
+
const transport = new hl.WebSocketTransport(); // Only WebSocketTransport is supported
|
|
107
|
+
const client = new hl.EventClient({ transport });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Use Client
|
|
111
|
+
|
|
112
|
+
Finally, use client methods to interact with the Hyperliquid API (more details in the [API Reference](#clients)):
|
|
113
|
+
|
|
114
|
+
#### Example of using a public client
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
118
|
+
|
|
119
|
+
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
120
|
+
const client = new hl.PublicClient({ transport });
|
|
121
|
+
|
|
122
|
+
// L2 Book
|
|
123
|
+
const l2Book = await client.l2Book({ coin: "BTC" });
|
|
124
|
+
|
|
125
|
+
// Account clearinghouse state
|
|
126
|
+
const clearinghouseState = await client.clearinghouseState({ user: "0x..." });
|
|
127
|
+
|
|
128
|
+
// Open orders
|
|
129
|
+
const openOrders = await client.openOrders({ user: "0x..." });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### Example of using a wallet client
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
136
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
137
|
+
|
|
138
|
+
const account = privateKeyToAccount("0x...");
|
|
139
|
+
const transport = new hl.HttpTransport();
|
|
140
|
+
const client = new hl.WalletClient({ wallet: account, transport });
|
|
141
|
+
|
|
142
|
+
// Place an orders
|
|
143
|
+
const result = await client.order({
|
|
144
|
+
orders: [{
|
|
145
|
+
a: 0, // Asset index
|
|
146
|
+
b: true, // Buy order
|
|
147
|
+
p: "30000", // Price
|
|
148
|
+
s: "0.1", // Size
|
|
149
|
+
r: false, // Not reduce-only
|
|
150
|
+
t: {
|
|
151
|
+
limit: {
|
|
152
|
+
tif: "Gtc", // Good-til-cancelled
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
}],
|
|
156
|
+
grouping: "na", // No grouping
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Approve an agent
|
|
160
|
+
const result = await client.approveAgent({
|
|
161
|
+
agentAddress: "0x...",
|
|
162
|
+
agentName: "agentName",
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Withdraw funds
|
|
166
|
+
const result = await client.withdraw3({
|
|
167
|
+
destination: account.address, // Withdraw funds to your address
|
|
168
|
+
amount: "100", // 100 USD
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Example of using an event client
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
176
|
+
|
|
112
177
|
const transport = new hl.WebSocketTransport();
|
|
113
178
|
const client = new hl.EventClient({ transport });
|
|
179
|
+
|
|
180
|
+
// L2 Book updates
|
|
181
|
+
// Promise is resolved when the subscription is set up
|
|
182
|
+
const sub = await client.l2Book({ coin: "BTC" }, (data) => {
|
|
183
|
+
console.log(data);
|
|
184
|
+
});
|
|
185
|
+
// Later, you can unsubscribe from receiving events
|
|
186
|
+
await sub.unsubscribe();
|
|
187
|
+
|
|
188
|
+
// User fills
|
|
189
|
+
const sub = await client.userFills({ user: "0x..." }, (data) => {
|
|
190
|
+
console.log(data);
|
|
191
|
+
});
|
|
192
|
+
await sub.unsubscribe();
|
|
193
|
+
|
|
194
|
+
// Explorer block updates
|
|
195
|
+
const sub = await client.explorerBlock((data) => {
|
|
196
|
+
console.log(data);
|
|
197
|
+
});
|
|
198
|
+
await sub.unsubscribe();
|
|
114
199
|
```
|
|
115
200
|
|
|
116
201
|
## API Reference
|
|
@@ -130,20 +215,19 @@ A Public Client which provides access to
|
|
|
130
215
|
The Public Client class sets up with a given [Transport](#transports).
|
|
131
216
|
|
|
132
217
|
```typescript
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
class PublicClient<T extends IRESTTransport> {
|
|
138
|
-
constructor(args: PublicClientParameters<T>);
|
|
218
|
+
class PublicClient {
|
|
219
|
+
constructor(args: {
|
|
220
|
+
transport: HttpTransport | WebSocketTransport;
|
|
221
|
+
});
|
|
139
222
|
|
|
140
223
|
// Market
|
|
141
224
|
allMids(): Promise<AllMids>;
|
|
142
|
-
candleSnapshot(args: CandleSnapshotParameters): Promise<
|
|
225
|
+
candleSnapshot(args: CandleSnapshotParameters): Promise<Candle[]>;
|
|
143
226
|
fundingHistory(args: FundingHistoryParameters): Promise<FundingHistory[]>;
|
|
144
|
-
l2Book(args: L2BookParameters): Promise<
|
|
145
|
-
meta(): Promise<
|
|
146
|
-
metaAndAssetCtxs(): Promise<
|
|
227
|
+
l2Book(args: L2BookParameters): Promise<Book>;
|
|
228
|
+
meta(): Promise<PerpsMeta>;
|
|
229
|
+
metaAndAssetCtxs(): Promise<PerpsMetaAndAssetCtxs>;
|
|
230
|
+
perpsAtOpenInterestCap(): Promise<string[]>;
|
|
147
231
|
predictedFundings(): Promise<PredictedFunding[]>;
|
|
148
232
|
spotDeployState(args: SpotDeployStateParameters): Promise<SpotDeployState>;
|
|
149
233
|
spotMeta(): Promise<SpotMeta>;
|
|
@@ -151,35 +235,47 @@ class PublicClient<T extends IRESTTransport> {
|
|
|
151
235
|
tokenDetails(args: TokenDetailsParameters): Promise<TokenDetails>;
|
|
152
236
|
|
|
153
237
|
// Account
|
|
154
|
-
clearinghouseState(args: ClearinghouseStateParameters): Promise<
|
|
238
|
+
clearinghouseState(args: ClearinghouseStateParameters): Promise<PerpsClearinghouseState>;
|
|
155
239
|
extraAgents(args: ExtraAgentsParameters): Promise<ExtraAgent[]>;
|
|
240
|
+
isVip(args: IsVipParameters): Promise<boolean>;
|
|
241
|
+
legalCheck(args: LegalCheckParameters): Promise<LegalCheck>;
|
|
156
242
|
maxBuilderFee(args: MaxBuilderFeeParameters): Promise<number>;
|
|
243
|
+
portfolio(args: PortfolioParameters): Promise<PortfolioPeriods>;
|
|
157
244
|
referral(args: ReferralParameters): Promise<Referral>;
|
|
158
245
|
spotClearinghouseState(args: SpotClearinghouseStateParameters): Promise<SpotClearinghouseState>;
|
|
159
|
-
subAccounts(args: SubAccountsParameters): Promise<SubAccount[]>;
|
|
246
|
+
subAccounts(args: SubAccountsParameters): Promise<SubAccount[] | null>;
|
|
160
247
|
userFees(args: UserFeesParameters): Promise<UserFees>;
|
|
161
|
-
userFunding(args: UserFundingParameters): Promise<
|
|
162
|
-
userNonFundingLedgerUpdates(args: UserNonFundingLedgerUpdatesParameters): Promise<
|
|
248
|
+
userFunding(args: UserFundingParameters): Promise<UserFundingUpdate[]>;
|
|
249
|
+
userNonFundingLedgerUpdates(args: UserNonFundingLedgerUpdatesParameters): Promise<UserNonFundingLedgerUpdate[]>;
|
|
163
250
|
userRateLimit(args: UserRateLimitParameters): Promise<UserRateLimit>;
|
|
251
|
+
userRole(args: UserRoleParameters): Promise<UserRole>;
|
|
164
252
|
|
|
165
253
|
// Order
|
|
166
|
-
frontendOpenOrders(args: FrontendOpenOrdersParameters): Promise<
|
|
167
|
-
historicalOrders(args: HistoricalOrdersParameters): Promise<OrderStatus[]>;
|
|
168
|
-
openOrders(args: OpenOrdersParameters): Promise<
|
|
169
|
-
orderStatus(args: OrderStatusParameters): Promise<
|
|
170
|
-
twapHistory(args: TwapHistoryParameters): Promise<TwapHistory>;
|
|
171
|
-
userFills(args: UserFillsParameters): Promise<
|
|
172
|
-
userFillsByTime(args: UserFillsByTimeParameters): Promise<
|
|
173
|
-
userTwapSliceFills(args: UserTwapSliceFillsParameters): Promise<
|
|
254
|
+
frontendOpenOrders(args: FrontendOpenOrdersParameters): Promise<FrontendOrder[]>;
|
|
255
|
+
historicalOrders(args: HistoricalOrdersParameters): Promise<OrderStatus<FrontendOrder>[]>;
|
|
256
|
+
openOrders(args: OpenOrdersParameters): Promise<Order[]>;
|
|
257
|
+
orderStatus(args: OrderStatusParameters): Promise<OrderLookup>;
|
|
258
|
+
twapHistory(args: TwapHistoryParameters): Promise<TwapHistory[]>;
|
|
259
|
+
userFills(args: UserFillsParameters): Promise<Fill[]>;
|
|
260
|
+
userFillsByTime(args: UserFillsByTimeParameters): Promise<Fill[]>;
|
|
261
|
+
userTwapSliceFills(args: UserTwapSliceFillsParameters): Promise<TwapSliceFill[]>;
|
|
262
|
+
|
|
263
|
+
// Staking
|
|
264
|
+
delegations(args: DelegationsParameters): Promise<Delegation[]>;
|
|
265
|
+
delegatorHistory(args: DelegatorHistoryParameters): Promise<DelegatorUpdate[]>;
|
|
266
|
+
delegatorRewards(args: DelegatorRewardsParameters): Promise<DelegatorReward[]>;
|
|
267
|
+
delegatorSummary(args: DelegatorSummaryParameters): Promise<DelegatorSummary>;
|
|
268
|
+
validatorSummaries(): Promise<ValidatorSummary[]>;
|
|
174
269
|
|
|
175
270
|
// Vault
|
|
176
|
-
userVaultEquities(args: UserVaultEquitiesParameters): Promise<
|
|
271
|
+
userVaultEquities(args: UserVaultEquitiesParameters): Promise<VaultEquity[]>;
|
|
177
272
|
vaultDetails(args: VaultDetailsParameters): Promise<VaultDetails | null>;
|
|
178
273
|
vaultSummaries(): Promise<VaultSummary[]>;
|
|
179
274
|
|
|
180
|
-
//
|
|
275
|
+
// Explorer
|
|
181
276
|
blockDetails(args: BlockDetailsParameters): Promise<BlockDetailsResponse>;
|
|
182
277
|
txDetails(args: TxDetailsParameters): Promise<TxDetailsResponse>;
|
|
278
|
+
userDetails(args: UserDetailsParameters): Promise<UserDetailsResponse>;
|
|
183
279
|
}
|
|
184
280
|
```
|
|
185
281
|
|
|
@@ -194,23 +290,20 @@ The Wallet Client class sets up with a given [Transport](#transports) and a wall
|
|
|
194
290
|
[Ethers Wallet](https://docs.ethers.org/v6/api/providers/#Signer).
|
|
195
291
|
|
|
196
292
|
```typescript
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
W extends AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer,
|
|
210
|
-
> {
|
|
211
|
-
constructor(args: WalletClientParameters<T, W>);
|
|
293
|
+
class WalletClient {
|
|
294
|
+
constructor(args: {
|
|
295
|
+
transport: HttpTransport | WebSocketTransport;
|
|
296
|
+
wallet:
|
|
297
|
+
| AbstractViemWalletClient // viem
|
|
298
|
+
| AbstractExtendedViemWalletClient // extended viem (e.g. privy)
|
|
299
|
+
| AbstractEthersSigner // ethers
|
|
300
|
+
| AbstractEthersV5Signer // ethers v5
|
|
301
|
+
| AbstractWindowEthereum; // window.ethereum (EIP-1193) directly
|
|
302
|
+
isTestnet?: boolean; // Whether to use testnet API (default: false)
|
|
303
|
+
defaultVaultAddress?: Hex; // Vault address used by default if not provided in method call
|
|
304
|
+
});
|
|
212
305
|
|
|
213
|
-
// Order
|
|
306
|
+
// Order
|
|
214
307
|
batchModify(args: BatchModifyParameters): Promise<OrderResponseSuccess>;
|
|
215
308
|
cancel(args: CancelParameters): Promise<CancelResponseSuccess>;
|
|
216
309
|
cancelByCloid(args: CancelByCloidParameters): Promise<CancelResponseSuccess>;
|
|
@@ -222,19 +315,33 @@ class WalletClient<
|
|
|
222
315
|
updateIsolatedMargin(args: UpdateIsolatedMarginParameters): Promise<SuccessResponse>;
|
|
223
316
|
updateLeverage(args: UpdateLeverageParameters): Promise<SuccessResponse>;
|
|
224
317
|
|
|
225
|
-
// Account
|
|
318
|
+
// Account
|
|
226
319
|
approveAgent(args: ApproveAgentParameters): Promise<SuccessResponse>;
|
|
227
320
|
approveBuilderFee(args: ApproveBuilderFeeParameters): Promise<SuccessResponse>;
|
|
321
|
+
claimRewards(args: ClaimRewardsParameters): Promise<SuccessResponse>;
|
|
228
322
|
createSubAccount(args: CreateSubAccountParameters): Promise<CreateSubAccountResponse>;
|
|
323
|
+
evmUserModify(args: EvmUserModifyParameters): Promise<SuccessResponse>;
|
|
324
|
+
setDisplayName(args: SetDisplayNameParameters): Promise<SuccessResponse>;
|
|
229
325
|
setReferrer(args: SetReferrerParameters): Promise<SuccessResponse>;
|
|
326
|
+
spotUser(args: SpotUserParameters): Promise<SuccessResponse>;
|
|
230
327
|
|
|
231
328
|
// Transfers & Withdrawals
|
|
232
329
|
spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
|
|
330
|
+
subAccountSpotTransfer(args: SubAccountSpotTransferParameters): Promise<SuccessResponse>;
|
|
233
331
|
subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
|
|
234
332
|
usdClassTransfer(args: UsdClassTransferParameters): Promise<SuccessResponse>;
|
|
235
333
|
usdSend(args: UsdSendParameters): Promise<SuccessResponse>;
|
|
236
|
-
vaultTransfer(args: VaultTransferParameters): Promise<SuccessResponse>;
|
|
237
334
|
withdraw3(args: Withdraw3Parameters): Promise<SuccessResponse>;
|
|
335
|
+
|
|
336
|
+
// Staking
|
|
337
|
+
cDeposit(args: CDepositParameters): Promise<SuccessResponse>;
|
|
338
|
+
cWithdraw(args: CWithdrawParameters): Promise<SuccessResponse>;
|
|
339
|
+
tokenDelegate(args: TokenDelegateParameters): Promise<SuccessResponse>;
|
|
340
|
+
|
|
341
|
+
// Vault
|
|
342
|
+
vaultDistribute(args: VaultDistributeParameters): Promise<SuccessResponse>;
|
|
343
|
+
vaultModify(args: VaultModifyParameters): Promise<SuccessResponse>;
|
|
344
|
+
vaultTransfer(args: VaultTransferParameters): Promise<SuccessResponse>;
|
|
238
345
|
}
|
|
239
346
|
```
|
|
240
347
|
|
|
@@ -248,14 +355,12 @@ The Event Client class sets up with a given [WebSocket Transport](#websocket-tra
|
|
|
248
355
|
|
|
249
356
|
<!-- deno-fmt-ignore-start -->
|
|
250
357
|
```typescript
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
358
|
+
class EventClient {
|
|
359
|
+
constructor(args: {
|
|
360
|
+
transport: WebSocketTransport;
|
|
361
|
+
});
|
|
254
362
|
|
|
255
|
-
|
|
256
|
-
constructor(args: EventClientParameters<T>);
|
|
257
|
-
|
|
258
|
-
// Market Data
|
|
363
|
+
// Market
|
|
259
364
|
activeAssetCtx(args: EventActiveAssetCtxParameters, listener: (data: WsActiveAssetCtx | WsActiveSpotAssetCtx) => void): Promise<Subscription>;
|
|
260
365
|
activeAssetData(args: EventActiveAssetDataParameters, listener: (data: WsActiveAssetData) => void): Promise<Subscription>;
|
|
261
366
|
allMids(listener: (data: WsAllMids) => void): Promise<Subscription>;
|
|
@@ -263,18 +368,22 @@ class EventClient<T extends ISubscriptionTransport> {
|
|
|
263
368
|
l2Book(args: EventL2BookParameters, listener: (data: Book) => void): Promise<Subscription>;
|
|
264
369
|
trades(args: EventTradesParameters, listener: (data: WsTrade[]) => void): Promise<Subscription>;
|
|
265
370
|
|
|
266
|
-
// Account
|
|
371
|
+
// Account
|
|
267
372
|
notification(args: EventNotificationParameters, listener: (data: WsNotification) => void): Promise<Subscription>;
|
|
268
373
|
userEvents(args: EventUserEventsParameters, listener: (data: WsUserEvent) => void): Promise<Subscription>;
|
|
269
374
|
userFundings(args: EventUserFundingsParameters, listener: (data: WsUserFundings) => void): Promise<Subscription>;
|
|
270
375
|
userNonFundingLedgerUpdates(args: EventUserNonFundingLedgerUpdatesParameters, listener: (data: WsUserNonFundingLedgerUpdates) => void): Promise<Subscription>;
|
|
271
376
|
webData2(args: EventWebData2Parameters, listener: (data: WsWebData2) => void): Promise<Subscription>;
|
|
272
377
|
|
|
273
|
-
// Order
|
|
274
|
-
orderUpdates(args: EventOrderUpdatesParameters, listener: (data: OrderStatus) => void): Promise<Subscription>;
|
|
378
|
+
// Order
|
|
379
|
+
orderUpdates(args: EventOrderUpdatesParameters, listener: (data: OrderStatus<Order>[]) => void): Promise<Subscription>;
|
|
275
380
|
userFills(args: EventUserFillsParameters, listener: (data: WsUserFills) => void): Promise<Subscription>;
|
|
276
381
|
userTwapHistory(args: EventUserTwapHistory, listener: (data: WsUserTwapHistory) => void): Promise<Subscription>;
|
|
277
382
|
userTwapSliceFills(args: EventUserTwapSliceFills, listener: (data: WsUserTwapSliceFills) => void): Promise<Subscription>;
|
|
383
|
+
|
|
384
|
+
// Explorer
|
|
385
|
+
explorerBlock(listener: (data: WsBlockDetails[]) => void): Promise<Subscription>;
|
|
386
|
+
explorerTx(listener: (data: TxDetails[]) => void): Promise<Subscription>;
|
|
278
387
|
}
|
|
279
388
|
```
|
|
280
389
|
<!-- deno-fmt-ignore-end -->
|
|
@@ -292,19 +401,17 @@ A HTTP Transport that executes requests via a [fetch](https://developer.mozilla.
|
|
|
292
401
|
API.
|
|
293
402
|
|
|
294
403
|
```typescript
|
|
295
|
-
class HttpTransport
|
|
296
|
-
constructor(options?:
|
|
404
|
+
class HttpTransport {
|
|
405
|
+
constructor(options?: {
|
|
406
|
+
url?: string | URL; // Base URL for API endpoints (default: "https://api.hyperliquid.xyz")
|
|
407
|
+
timeout?: number; // Request timeout in ms (default: 10_000)
|
|
408
|
+
fetchOptions?: RequestInit; // A custom fetch options
|
|
409
|
+
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>; // A callback before request is sent
|
|
410
|
+
onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>; // A callback after response is received
|
|
411
|
+
});
|
|
297
412
|
|
|
298
413
|
request(endpoint: "info" | "action" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
299
414
|
}
|
|
300
|
-
|
|
301
|
-
interface HttpTransportOptions {
|
|
302
|
-
url?: string | URL; // Base URL for API endpoints (default: "https://api.hyperliquid.xyz")
|
|
303
|
-
timeout?: number; // Request timeout in ms (default: 10_000)
|
|
304
|
-
fetchOptions?: RequestInit; // A custom fetch options
|
|
305
|
-
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>; // A callback before request is sent
|
|
306
|
-
onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>; // A callback after response is received
|
|
307
|
-
}
|
|
308
415
|
```
|
|
309
416
|
|
|
310
417
|
#### WebSocket Transport
|
|
@@ -313,8 +420,21 @@ A WebSocket Transport that executes requests and subscribes to events via a
|
|
|
313
420
|
[WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) connection.
|
|
314
421
|
|
|
315
422
|
```typescript
|
|
316
|
-
class WebSocketTransport
|
|
317
|
-
constructor(options?:
|
|
423
|
+
class WebSocketTransport {
|
|
424
|
+
constructor(options?: {
|
|
425
|
+
url?: string | URL; // WebSocket URL (default: "wss://api.hyperliquid.xyz/ws")
|
|
426
|
+
timeout?: number; // Request timeout in ms (default: 10_000)
|
|
427
|
+
keepAlive?: { // Keep-alive configuration
|
|
428
|
+
interval?: number; // Ping interval in ms (default: 20_000)
|
|
429
|
+
};
|
|
430
|
+
reconnect?: { // Reconnection policy configuration for closed connections
|
|
431
|
+
maxRetries?: number; // Maximum number of reconnection attempts (default: 3)
|
|
432
|
+
connectionTimeout?: number; // Connection timeout in ms (default: 10_000)
|
|
433
|
+
connectionDelay?: number | ((attempt: number) => number | Promise<number>); // Delay between reconnection (default: Exponential backoff (max 10s))
|
|
434
|
+
shouldReconnect?: (event: CloseEvent) => boolean | Promise<boolean>; // Custom reconnection logic (default: Always reconnect)
|
|
435
|
+
messageBuffer?: MessageBufferStrategy; // Message buffering strategy between reconnection (default: FIFO buffer)
|
|
436
|
+
};
|
|
437
|
+
});
|
|
318
438
|
|
|
319
439
|
request(endpoint: "info" | "action" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
320
440
|
subscribe(
|
|
@@ -327,28 +447,135 @@ class WebSocketTransport implements IRESTTransport, ISubscriptionTransport {
|
|
|
327
447
|
ready(signal?: AbortSignal): Promise<void>;
|
|
328
448
|
close(signal?: AbortSignal): Promise<void>;
|
|
329
449
|
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## Additional Import Points
|
|
453
|
+
|
|
454
|
+
The SDK exports additional import points to access internal functions.
|
|
455
|
+
|
|
456
|
+
### `/types`
|
|
457
|
+
|
|
458
|
+
The import point gives access to all Hyperliquid-related types, including the base types on which class methods are
|
|
459
|
+
based.
|
|
460
|
+
|
|
461
|
+
Useful if you want to get all Hyperliquid types.
|
|
462
|
+
|
|
463
|
+
### `/signing`
|
|
464
|
+
|
|
465
|
+
The import point gives access to functions that generate signatures for Hyperliquid transactions.
|
|
466
|
+
|
|
467
|
+
Useful if you want to sign a Hyperliquid transaction yourself.
|
|
468
|
+
|
|
469
|
+
### Examples
|
|
470
|
+
|
|
471
|
+
#### Cancel an order without a client
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
475
|
+
import type { CancelRequest, CancelResponse } from "@nktkas/hyperliquid/types";
|
|
476
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
477
|
+
|
|
478
|
+
// —————————— Prepare ——————————
|
|
479
|
+
|
|
480
|
+
const wallet = privateKeyToAccount("0x..."); // Change to your private key
|
|
481
|
+
|
|
482
|
+
// The CancelRequest["action"] type ensures that we collect the correct cancel request action
|
|
483
|
+
const action: CancelRequest["action"] = { type: "cancel", cancels: [{ a: 0, o: 12345 }] };
|
|
484
|
+
const nonce = Date.now();
|
|
485
|
+
|
|
486
|
+
// —————————— Signing ——————————
|
|
487
|
+
|
|
488
|
+
const signature = await signL1Action({
|
|
489
|
+
wallet,
|
|
490
|
+
action: sortedAction,
|
|
491
|
+
nonce,
|
|
492
|
+
isTestnet: true,
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// —————————— Request ——————————
|
|
496
|
+
|
|
497
|
+
// The CancelRequest type guarantees us that the object we want to send is valid in terms of types
|
|
498
|
+
const request: CancelRequest = { action, signature, nonce };
|
|
499
|
+
|
|
500
|
+
const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
501
|
+
method: "POST",
|
|
502
|
+
headers: { "Content-Type": "application/json" },
|
|
503
|
+
body: JSON.stringify(request),
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
if (!response.ok) {
|
|
507
|
+
const body = await response.text();
|
|
508
|
+
throw new Error(`Failed to cancel order: ${response.statusText} ${body}`);
|
|
509
|
+
}
|
|
330
510
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
511
|
+
// If we sent a cancel request and received a successful response, then we got exactly the CancelResponse type
|
|
512
|
+
const body = await response.json() as CancelResponse;
|
|
513
|
+
console.log("Order cancel response:", body);
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
#### Approve an agent without a client
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
520
|
+
import type { ApproveAgentRequest, ErrorResponse, SuccessResponse } from "@nktkas/hyperliquid/types";
|
|
521
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
522
|
+
|
|
523
|
+
// —————————— Prepare ——————————
|
|
524
|
+
|
|
525
|
+
const wallet = privateKeyToAccount("0x..."); // Change to your private key
|
|
526
|
+
|
|
527
|
+
// The ApproveAgentRequest["action"] type ensures that we collect the correct approve agent request action
|
|
528
|
+
const action: ApproveAgentRequest["action"] = {
|
|
529
|
+
type: "approveAgent",
|
|
530
|
+
hyperliquidChain: "Testnet",
|
|
531
|
+
signatureChainId: "0x66eee",
|
|
532
|
+
nonce: Date.now(),
|
|
533
|
+
agentAddress: "0x...", // Change to the agent address you want to approve
|
|
534
|
+
agentName: "TempAgent",
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
// —————————— Signing ——————————
|
|
538
|
+
|
|
539
|
+
const signature = await signUserSignedAction({
|
|
540
|
+
wallet,
|
|
541
|
+
action,
|
|
542
|
+
types: {
|
|
543
|
+
"HyperliquidTransaction:ApproveAgent": [
|
|
544
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
545
|
+
{ name: "agentAddress", type: "address" },
|
|
546
|
+
{ name: "agentName", type: "string" },
|
|
547
|
+
{ name: "nonce", type: "uint64" },
|
|
548
|
+
],
|
|
549
|
+
},
|
|
550
|
+
chainId: parseInt(action.signatureChainId, 16),
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
// —————————— Request ——————————
|
|
554
|
+
|
|
555
|
+
// The ApproveAgentRequest type guarantees us that the object we want to send is valid in terms of types
|
|
556
|
+
const request: ApproveAgentRequest = { action, signature, nonce: action.nonce };
|
|
557
|
+
|
|
558
|
+
const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
559
|
+
method: "POST",
|
|
560
|
+
headers: { "Content-Type": "application/json" },
|
|
561
|
+
body: JSON.stringify(request),
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
if (!response.ok) {
|
|
565
|
+
const body = await response.text();
|
|
566
|
+
throw new Error(`Failed to approve agent: ${response.statusText} ${body}`);
|
|
345
567
|
}
|
|
568
|
+
|
|
569
|
+
// If we sent a request for agent approval and received a successful response,
|
|
570
|
+
// we will get either a SuccessResponse type or an ErrorResponse type
|
|
571
|
+
const body = await response.json() as SuccessResponse | ErrorResponse;
|
|
572
|
+
console.log("Agent approval response:", body);
|
|
346
573
|
```
|
|
347
574
|
|
|
348
|
-
##
|
|
575
|
+
## Versioning Policy
|
|
349
576
|
|
|
350
|
-
This library follows [
|
|
351
|
-
[
|
|
577
|
+
This library follows a [stricter version](https://github.com/semver/semver/pull/923) of
|
|
578
|
+
[Semantic Versioning](https://semver.org/) for its releases.
|
|
352
579
|
|
|
353
580
|
> [!IMPORTANT]
|
|
354
581
|
> To avoid rapid increase in the main version of the SDK due to changes in Hyperliquid API types, such changes are
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy type of {@code Uint8Array<ArrayBuffer} or {@code Uint8Array} in TypeScript 5.7 or below respectively.
|
|
3
|
+
*
|
|
4
|
+
* This type is internal utility type and should not be used directly.
|
|
5
|
+
*
|
|
6
|
+
* @internal @private
|
|
7
|
+
*/
|
|
8
|
+
export type Uint8Array_ = ReturnType<Uint8Array["slice"]>;
|
|
9
|
+
//# sourceMappingURL=_types.d.ts.map
|