@nktkas/hyperliquid 0.22.2 → 0.23.1
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/README.md +79 -67
- package/esm/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/base.d.ts +4 -1
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/base.js +2 -2
- package/esm/src/clients/exchange.d.ts +289 -207
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +605 -410
- package/esm/src/clients/info.d.ts +264 -48
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +273 -31
- package/esm/src/clients/multiSign.d.ts +285 -204
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +521 -493
- package/esm/src/clients/subscription.d.ts +38 -3
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +36 -3
- package/esm/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/mod.d.ts +35 -0
- package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/mod.js +59 -0
- package/esm/src/signing/_signTypedData/private_key.d.ts +26 -0
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/private_key.js +144 -0
- package/esm/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
- package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -0
- package/{script/src/signing/_window.d.ts → esm/src/signing/_signTypedData/window.d.ts} +18 -12
- package/esm/src/signing/_signTypedData/window.d.ts.map +1 -0
- package/esm/src/signing/{_window.js → _signTypedData/window.js} +3 -2
- package/esm/src/signing/_sorter.d.ts +56 -82
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +36 -49
- package/esm/src/signing/mod.d.ts +151 -130
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +182 -228
- package/esm/src/transports/base.d.ts +1 -1
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/base.js +2 -2
- package/esm/src/transports/http/http_transport.d.ts +9 -15
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +64 -59
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +17 -4
- package/esm/src/transports/websocket/_websocket_async_request.d.ts +0 -9
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +14 -20
- package/esm/src/transports/websocket/websocket_transport.d.ts +8 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +83 -54
- package/esm/src/types/exchange/requests.d.ts +27 -51
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +5 -8
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +5 -5
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +6 -0
- package/esm/src/types/info/markets.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +1 -1
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +129 -124
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/{script/src/types/info/delegations.d.ts → esm/src/types/info/validators.d.ts} +2 -2
- package/esm/src/types/info/validators.d.ts.map +1 -0
- package/esm/src/types/info/vaults.d.ts +7 -0
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +1 -1
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +72 -18
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/responses.d.ts +2 -0
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
- package/package.json +8 -5
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +13 -23
- package/script/src/base.d.ts +4 -1
- package/script/src/base.d.ts.map +1 -1
- package/script/src/base.js +10 -20
- package/script/src/clients/exchange.d.ts +289 -207
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +2000 -1815
- package/script/src/clients/info.d.ts +264 -48
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +1442 -1210
- package/script/src/clients/multiSign.d.ts +285 -204
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +2043 -2025
- package/script/src/clients/subscription.d.ts +38 -3
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +568 -545
- package/script/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
- package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/ethers.js +16 -0
- package/script/src/signing/_signTypedData/mod.d.ts +35 -0
- package/script/src/signing/_signTypedData/mod.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/mod.js +67 -0
- package/script/src/signing/_signTypedData/private_key.d.ts +26 -0
- package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/private_key.js +148 -0
- package/script/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
- package/script/src/signing/_signTypedData/viem.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/viem.js +9 -0
- package/{esm/src/signing/_window.d.ts → script/src/signing/_signTypedData/window.d.ts} +18 -12
- package/script/src/signing/_signTypedData/window.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/window.js +34 -0
- package/script/src/signing/_sorter.d.ts +56 -82
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +655 -678
- package/script/src/signing/mod.d.ts +151 -130
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +286 -342
- package/script/src/transports/base.d.ts +1 -1
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/base.js +11 -21
- package/script/src/transports/http/http_transport.d.ts +9 -15
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +97 -102
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +51 -61
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +271 -268
- package/script/src/transports/websocket/_websocket_async_request.d.ts +0 -9
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +157 -174
- package/script/src/transports/websocket/websocket_transport.d.ts +8 -4
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +209 -189
- package/script/src/types/exchange/requests.d.ts +27 -51
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +2 -12
- package/script/src/types/exchange/responses.js +2 -12
- package/script/src/types/explorer/requests.d.ts +5 -8
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +2 -12
- package/script/src/types/explorer/responses.js +2 -12
- package/script/src/types/info/accounts.d.ts +5 -5
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +2 -12
- package/script/src/types/info/assets.js +2 -12
- package/script/src/types/info/markets.d.ts +6 -0
- package/script/src/types/info/markets.d.ts.map +1 -1
- package/script/src/types/info/markets.js +2 -12
- package/script/src/types/info/orders.d.ts +1 -1
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/orders.js +2 -12
- package/script/src/types/info/requests.d.ts +129 -124
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +2 -12
- package/{esm/src/types/info/delegations.d.ts → script/src/types/info/validators.d.ts} +2 -2
- package/script/src/types/info/validators.d.ts.map +1 -0
- package/script/src/types/info/validators.js +2 -0
- package/script/src/types/info/vaults.d.ts +7 -0
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/info/vaults.js +2 -12
- package/script/src/types/mod.d.ts +1 -1
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +2 -12
- package/script/src/types/subscriptions/requests.d.ts +72 -18
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +2 -12
- package/script/src/types/subscriptions/responses.d.ts +2 -0
- package/script/src/types/subscriptions/responses.d.ts.map +1 -1
- package/script/src/types/subscriptions/responses.js +2 -12
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -10
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.js +0 -63
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -2
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -32
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -2
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -237
- package/esm/src/signing/_ethers.d.ts.map +0 -1
- package/esm/src/signing/_private_key.d.ts +0 -22
- package/esm/src/signing/_private_key.d.ts.map +0 -1
- package/esm/src/signing/_private_key.js +0 -124
- package/esm/src/signing/_viem.d.ts.map +0 -1
- package/esm/src/signing/_window.d.ts.map +0 -1
- package/esm/src/types/info/delegations.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -27
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -24
- package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
- package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +0 -76
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -13
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -45
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -67
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -26
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -13
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -101
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -13
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -250
- package/script/src/signing/_ethers.d.ts.map +0 -1
- package/script/src/signing/_ethers.js +0 -26
- package/script/src/signing/_private_key.d.ts +0 -22
- package/script/src/signing/_private_key.d.ts.map +0 -1
- package/script/src/signing/_private_key.js +0 -138
- package/script/src/signing/_viem.d.ts.map +0 -1
- package/script/src/signing/_viem.js +0 -19
- package/script/src/signing/_window.d.ts.map +0 -1
- package/script/src/signing/_window.js +0 -43
- package/script/src/types/info/delegations.d.ts.map +0 -1
- package/script/src/types/info/delegations.js +0 -12
- /package/esm/src/signing/{_ethers.js → _signTypedData/ethers.js} +0 -0
- /package/esm/src/signing/{_viem.js → _signTypedData/viem.js} +0 -0
- /package/esm/src/types/info/{delegations.js → validators.js} +0 -0
package/README.md
CHANGED
|
@@ -1,9 +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://bundlephobia.com/package/@nktkas/hyperliquid)
|
|
7
7
|
|
|
8
8
|
Unofficial [Hyperliquid API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api) SDK for all major JS
|
|
9
9
|
runtimes, written in TypeScript and provided with tests.
|
|
@@ -44,17 +44,19 @@ deno add jsr:@nktkas/hyperliquid
|
|
|
44
44
|
```html
|
|
45
45
|
<script type="module">
|
|
46
46
|
import * as hl from "https://esm.sh/jsr/@nktkas/hyperliquid";
|
|
47
|
-
// Use hl.InfoClient, hl.ExchangeClient, etc.
|
|
48
47
|
</script>
|
|
49
48
|
```
|
|
50
49
|
|
|
51
50
|
### React Native
|
|
52
51
|
|
|
53
52
|
<details>
|
|
54
|
-
<summary>For React Native, you need to import
|
|
53
|
+
<summary>For React Native, you need to import polyfills before importing the SDK:</summary>
|
|
55
54
|
|
|
56
55
|
```js
|
|
57
|
-
// React Native 0.76.3
|
|
56
|
+
// React Native 0.76.3 / Expo v52
|
|
57
|
+
// Issues:
|
|
58
|
+
// - signing: does not support private keys directly, use viem or ethers
|
|
59
|
+
|
|
58
60
|
import { Event, EventTarget } from "event-target-shim";
|
|
59
61
|
|
|
60
62
|
if (!globalThis.EventTarget || !globalThis.Event) {
|
|
@@ -89,21 +91,6 @@ if (!Promise.withResolvers) {
|
|
|
89
91
|
return { promise, resolve, reject };
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
if (!ArrayBuffer.prototype.transfer) {
|
|
94
|
-
ArrayBuffer.prototype.transfer = function (newByteLength) {
|
|
95
|
-
const length = newByteLength ?? this.byteLength;
|
|
96
|
-
const newBuffer = new ArrayBuffer(length);
|
|
97
|
-
const oldView = new Uint8Array(this);
|
|
98
|
-
const newView = new Uint8Array(newBuffer);
|
|
99
|
-
|
|
100
|
-
newView.set(oldView.subarray(0, Math.min(oldView.length, length)));
|
|
101
|
-
|
|
102
|
-
Object.defineProperty(this, "byteLength", { value: 0 });
|
|
103
|
-
|
|
104
|
-
return newBuffer;
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
94
|
```
|
|
108
95
|
|
|
109
96
|
</details>
|
|
@@ -174,16 +161,15 @@ const signers = [
|
|
|
174
161
|
] as const;
|
|
175
162
|
|
|
176
163
|
const transport = new hl.HttpTransport();
|
|
177
|
-
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends ExchangeClient
|
|
164
|
+
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
|
|
178
165
|
|
|
179
|
-
const data = await multiSignClient.approveAgent({ // same API as ExchangeClient
|
|
166
|
+
const data = await multiSignClient.approveAgent({ // same API as `ExchangeClient`
|
|
180
167
|
agentAddress: "0x...",
|
|
181
168
|
agentName: "agentName",
|
|
182
169
|
});
|
|
183
170
|
```
|
|
184
171
|
|
|
185
|
-
|
|
186
|
-
<summary><h2>Usage</h2></summary>
|
|
172
|
+
## Usage
|
|
187
173
|
|
|
188
174
|
### 1) Initialize Transport
|
|
189
175
|
|
|
@@ -192,11 +178,11 @@ First, choose and configure your transport layer (more details in the [API Refer
|
|
|
192
178
|
```ts
|
|
193
179
|
import * as hl from "@nktkas/hyperliquid";
|
|
194
180
|
|
|
195
|
-
// HTTP Transport
|
|
196
|
-
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters
|
|
181
|
+
// 1. HTTP Transport: suitable for one-time requests or serverless environments
|
|
182
|
+
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
|
|
197
183
|
|
|
198
|
-
// WebSocket Transport
|
|
199
|
-
const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters
|
|
184
|
+
// 2. WebSocket Transport: has better network latency than HTTP transport
|
|
185
|
+
const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters (e.g. url, timeout, reconnect, etc.)
|
|
200
186
|
```
|
|
201
187
|
|
|
202
188
|
### 2) Initialize Client
|
|
@@ -208,7 +194,7 @@ Next, initialize a client with the transport layer (more details in the [API Ref
|
|
|
208
194
|
```ts
|
|
209
195
|
import * as hl from "@nktkas/hyperliquid";
|
|
210
196
|
|
|
211
|
-
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
197
|
+
const transport = new hl.HttpTransport(); // or `WebSocketTransport`
|
|
212
198
|
const infoClient = new hl.InfoClient({ transport });
|
|
213
199
|
```
|
|
214
200
|
|
|
@@ -220,17 +206,17 @@ import { createWalletClient, custom } from "viem";
|
|
|
220
206
|
import { privateKeyToAccount } from "viem/accounts";
|
|
221
207
|
import { ethers } from "ethers";
|
|
222
208
|
|
|
223
|
-
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
209
|
+
const transport = new hl.HttpTransport(); // or `WebSocketTransport`
|
|
224
210
|
|
|
225
|
-
// 1. Using private key
|
|
211
|
+
// 1. Using private key directly
|
|
226
212
|
const privateKey = "0x...";
|
|
227
213
|
const exchClient_privateKey = new hl.ExchangeClient({ wallet: privateKey, transport });
|
|
228
214
|
|
|
229
|
-
// 2. Using Viem
|
|
215
|
+
// 2. Using Viem
|
|
230
216
|
const viemAccount = privateKeyToAccount("0x...");
|
|
231
217
|
const exchClient_viem = new hl.ExchangeClient({ wallet: viemAccount, transport });
|
|
232
218
|
|
|
233
|
-
// 3. Using Ethers (or Ethers V5)
|
|
219
|
+
// 3. Using Ethers (or Ethers V5)
|
|
234
220
|
const ethersWallet = new ethers.Wallet("0x...");
|
|
235
221
|
const exchClient_ethers = new hl.ExchangeClient({ wallet: ethersWallet, transport });
|
|
236
222
|
|
|
@@ -239,7 +225,7 @@ const [account] = await window.ethereum.request({ method: "eth_requestAccounts"
|
|
|
239
225
|
const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
240
226
|
const exchClient_viemMetamask = new hl.ExchangeClient({ wallet: externalWallet, transport });
|
|
241
227
|
|
|
242
|
-
// 5. Using external wallet (e.g. MetaMask) via `window.ethereum`
|
|
228
|
+
// 5. Using external wallet (e.g. MetaMask) via `window.ethereum`
|
|
243
229
|
const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereum, transport });
|
|
244
230
|
```
|
|
245
231
|
|
|
@@ -248,7 +234,7 @@ const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereu
|
|
|
248
234
|
```ts
|
|
249
235
|
import * as hl from "@nktkas/hyperliquid";
|
|
250
236
|
|
|
251
|
-
const transport = new hl.WebSocketTransport(); // only WebSocketTransport
|
|
237
|
+
const transport = new hl.WebSocketTransport(); // only `WebSocketTransport`
|
|
252
238
|
const subsClient = new hl.SubscriptionClient({ transport });
|
|
253
239
|
```
|
|
254
240
|
|
|
@@ -264,7 +250,7 @@ const signers = [
|
|
|
264
250
|
privateKeyToAccount("0x..."), // first is leader for multi-sign transaction, must contain own address
|
|
265
251
|
new ethers.Wallet("0x..."),
|
|
266
252
|
{ // can be a custom async wallet
|
|
267
|
-
signTypedData(params: {
|
|
253
|
+
async signTypedData(params: {
|
|
268
254
|
domain: {
|
|
269
255
|
name: string;
|
|
270
256
|
version: string;
|
|
@@ -281,14 +267,14 @@ const signers = [
|
|
|
281
267
|
message: Record<string, unknown>;
|
|
282
268
|
}): Promise<Hex> {
|
|
283
269
|
// Custom signer logic
|
|
284
|
-
return "0x..."; // return signature
|
|
270
|
+
return "0x..."; // return hex signature
|
|
285
271
|
},
|
|
286
272
|
},
|
|
287
273
|
"0x...", // private key directly
|
|
288
274
|
];
|
|
289
275
|
|
|
290
276
|
const transport = new hl.HttpTransport();
|
|
291
|
-
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends ExchangeClient
|
|
277
|
+
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
|
|
292
278
|
```
|
|
293
279
|
|
|
294
280
|
### 3) Use Client
|
|
@@ -390,7 +376,7 @@ const signers = [
|
|
|
390
376
|
const transport = new hl.HttpTransport();
|
|
391
377
|
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
|
|
392
378
|
|
|
393
|
-
// Interaction is the same as with ExchangeClient
|
|
379
|
+
// Interaction is the same as with `ExchangeClient`
|
|
394
380
|
|
|
395
381
|
// Place an orders
|
|
396
382
|
const result = await multiSignClient.order({
|
|
@@ -422,10 +408,7 @@ const result = await multiSignClient.withdraw3({
|
|
|
422
408
|
});
|
|
423
409
|
```
|
|
424
410
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
<details>
|
|
428
|
-
<summary><h2>API Reference</h2></summary>
|
|
411
|
+
## API Reference
|
|
429
412
|
|
|
430
413
|
### Clients
|
|
431
414
|
|
|
@@ -447,6 +430,9 @@ class InfoClient {
|
|
|
447
430
|
candleSnapshot(args: CandleSnapshotParameters): Promise<Candle[]>;
|
|
448
431
|
fundingHistory(args: FundingHistoryParameters): Promise<FundingHistory[]>;
|
|
449
432
|
l2Book(args: L2BookParameters): Promise<Book>;
|
|
433
|
+
liquidatable(): Promise<unknown[]>;
|
|
434
|
+
marginTable(args: MarginTableParameters): Promise<MarginTable>;
|
|
435
|
+
maxMarketOrderNtls(): Promise<[number, string][]>;
|
|
450
436
|
meta(): Promise<PerpsMeta>;
|
|
451
437
|
metaAndAssetCtxs(): Promise<PerpsMetaAndAssetCtxs>;
|
|
452
438
|
perpDeployAuctionStatus(): Promise<DeployAuctionStatus>;
|
|
@@ -487,18 +473,23 @@ class InfoClient {
|
|
|
487
473
|
userTwapSliceFills(args: UserTwapSliceFillsParameters): Promise<TwapSliceFill[]>;
|
|
488
474
|
userTwapSliceFillsByTime(args: UserTwapSliceFillsByTimeParameters): Promise<TwapSliceFill[]>;
|
|
489
475
|
|
|
490
|
-
//
|
|
476
|
+
// Validator
|
|
491
477
|
delegations(args: DelegationsParameters): Promise<Delegation[]>;
|
|
492
478
|
delegatorHistory(args: DelegatorHistoryParameters): Promise<DelegatorUpdate[]>;
|
|
493
479
|
delegatorRewards(args: DelegatorRewardsParameters): Promise<DelegatorReward[]>;
|
|
494
480
|
delegatorSummary(args: DelegatorSummaryParameters): Promise<DelegatorSummary>;
|
|
481
|
+
validatorL1Votes(): Promise<unknown[]>;
|
|
495
482
|
validatorSummaries(): Promise<ValidatorSummary[]>;
|
|
496
483
|
|
|
497
484
|
// Vault
|
|
485
|
+
leadingVaults(args: LeadingVaultsParameters): Promise<VaultLeading[]>;
|
|
498
486
|
userVaultEquities(args: UserVaultEquitiesParameters): Promise<VaultEquity[]>;
|
|
499
487
|
vaultDetails(args: VaultDetailsParameters): Promise<VaultDetails | null>;
|
|
500
488
|
vaultSummaries(): Promise<VaultSummary[]>;
|
|
501
489
|
|
|
490
|
+
// Server
|
|
491
|
+
exchangeStatus(): Promise<ExchangeStatus>;
|
|
492
|
+
|
|
502
493
|
// Explorer (RPC endpoint)
|
|
503
494
|
blockDetails(args: BlockDetailsParameters): Promise<BlockDetails>;
|
|
504
495
|
txDetails(args: TxDetailsParameters): Promise<TxDetails>;
|
|
@@ -513,14 +504,15 @@ class ExchangeClient {
|
|
|
513
504
|
constructor(args: {
|
|
514
505
|
transport: HttpTransport | WebSocketTransport;
|
|
515
506
|
wallet:
|
|
507
|
+
| Hex // Private key directly
|
|
516
508
|
| AbstractViemWalletClient // viem
|
|
517
509
|
| AbstractEthersSigner // ethers
|
|
518
510
|
| AbstractEthersV5Signer // ethers v5
|
|
519
511
|
| AbstractWindowEthereum; // window.ethereum (EIP-1193)
|
|
520
512
|
isTestnet?: boolean; // Whether to use testnet (default: false)
|
|
521
513
|
defaultVaultAddress?: Hex; // Vault address used by default if not provided in method call
|
|
522
|
-
signatureChainId?: Hex | (() => MaybePromise<Hex>); // Chain ID used for signing (default: trying to guess based on wallet and isTestnet)
|
|
523
|
-
nonceManager?: () => MaybePromise<number>; // Function to get the next nonce (default: auto-incrementing Date.now())
|
|
514
|
+
signatureChainId?: Hex | (() => MaybePromise<Hex>); // Chain ID used for signing (default: trying to guess based on wallet and `isTestnet`)
|
|
515
|
+
nonceManager?: () => MaybePromise<number>; // Function to get the next nonce (default: auto-incrementing `Date.now()`)
|
|
524
516
|
});
|
|
525
517
|
|
|
526
518
|
// Order
|
|
@@ -539,7 +531,6 @@ class ExchangeClient {
|
|
|
539
531
|
approveAgent(args: ApproveAgentParameters): Promise<SuccessResponse>;
|
|
540
532
|
approveBuilderFee(args: ApproveBuilderFeeParameters): Promise<SuccessResponse>;
|
|
541
533
|
claimRewards(): Promise<SuccessResponse>;
|
|
542
|
-
convertToMultiSigUser(args: ConvertToMultiSigUserParameters): Promise<SuccessResponse>;
|
|
543
534
|
createSubAccount(args: CreateSubAccountParameters): Promise<CreateSubAccountResponse>;
|
|
544
535
|
evmUserModify(args: EvmUserModifyParameters): Promise<SuccessResponse>;
|
|
545
536
|
registerReferrer(args: RegisterReferrerParameters): Promise<SuccessResponse>;
|
|
@@ -550,6 +541,7 @@ class ExchangeClient {
|
|
|
550
541
|
|
|
551
542
|
// Transfer
|
|
552
543
|
perpDexClassTransfer(args: PerpDexClassTransferParameters): Promise<SuccessResponse>;
|
|
544
|
+
perpDexTransfer(args: PerpDexTransferParameters): Promise<SuccessResponse>;
|
|
553
545
|
spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
|
|
554
546
|
subAccountSpotTransfer(args: SubAccountSpotTransferParameters): Promise<SuccessResponse>;
|
|
555
547
|
subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
|
|
@@ -573,6 +565,7 @@ class ExchangeClient {
|
|
|
573
565
|
vaultTransfer(args: VaultTransferParameters): Promise<SuccessResponse>;
|
|
574
566
|
|
|
575
567
|
// Multi-Sign
|
|
568
|
+
convertToMultiSigUser(args: ConvertToMultiSigUserParameters): Promise<SuccessResponse>;
|
|
576
569
|
multiSig(args: MultiSigParameters): Promise<BaseExchangeResponse>;
|
|
577
570
|
|
|
578
571
|
// Validator
|
|
@@ -635,16 +628,18 @@ class MultiSignClient extends ExchangeClient {
|
|
|
635
628
|
},
|
|
636
629
|
);
|
|
637
630
|
|
|
638
|
-
// Same methods as ExchangeClient
|
|
631
|
+
// Same methods as `ExchangeClient`
|
|
639
632
|
}
|
|
640
633
|
```
|
|
641
634
|
|
|
642
635
|
### Transports
|
|
643
636
|
|
|
644
|
-
Transport acts as a layer between
|
|
637
|
+
Transport acts as a layer between class requests and Hyperliquid servers.
|
|
645
638
|
|
|
646
639
|
#### HTTP Transport
|
|
647
640
|
|
|
641
|
+
HTTP transport is suitable for one-off requests or serverless environments.
|
|
642
|
+
|
|
648
643
|
```ts
|
|
649
644
|
class HttpTransport {
|
|
650
645
|
constructor(options?: {
|
|
@@ -663,6 +658,8 @@ class HttpTransport {
|
|
|
663
658
|
|
|
664
659
|
#### WebSocket Transport
|
|
665
660
|
|
|
661
|
+
WebSocket transport has better network latency than HTTP transport.
|
|
662
|
+
|
|
666
663
|
```ts
|
|
667
664
|
class WebSocketTransport {
|
|
668
665
|
constructor(options?: {
|
|
@@ -686,10 +683,7 @@ class WebSocketTransport {
|
|
|
686
683
|
}
|
|
687
684
|
```
|
|
688
685
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
<details>
|
|
692
|
-
<summary><h2>Additional Import Points</h2></summary>
|
|
686
|
+
## Additional Import Points
|
|
693
687
|
|
|
694
688
|
### `/types`
|
|
695
689
|
|
|
@@ -709,22 +703,22 @@ import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
|
709
703
|
|
|
710
704
|
const privateKey = "0x..."; // or `viem`, `ethers`
|
|
711
705
|
|
|
706
|
+
const nonce = Date.now();
|
|
712
707
|
const action = {
|
|
713
708
|
type: "cancel",
|
|
714
709
|
cancels: [
|
|
715
710
|
{ a: 0, o: 12345 },
|
|
716
711
|
],
|
|
717
|
-
};
|
|
718
|
-
const nonce = Date.now();
|
|
712
|
+
} as const;
|
|
719
713
|
|
|
720
714
|
const signature = await signL1Action({
|
|
721
715
|
wallet: privateKey,
|
|
722
|
-
action: actionSorter[action.type](action),
|
|
716
|
+
action: actionSorter[action.type](action),
|
|
723
717
|
nonce,
|
|
724
|
-
isTestnet: true, // change to `false` for mainnet
|
|
725
718
|
});
|
|
726
719
|
|
|
727
|
-
|
|
720
|
+
// Send the signed action to the Hyperliquid API
|
|
721
|
+
const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
728
722
|
method: "POST",
|
|
729
723
|
headers: { "Content-Type": "application/json" },
|
|
730
724
|
body: JSON.stringify({ action, signature, nonce }),
|
|
@@ -741,21 +735,21 @@ const privateKey = "0x..."; // or `viem`, `ethers`
|
|
|
741
735
|
|
|
742
736
|
const action = {
|
|
743
737
|
type: "approveAgent",
|
|
744
|
-
signatureChainId: "0x66eee",
|
|
745
|
-
hyperliquidChain: "
|
|
738
|
+
signatureChainId: "0x66eee",
|
|
739
|
+
hyperliquidChain: "Mainnet",
|
|
746
740
|
agentAddress: "0x...",
|
|
747
741
|
agentName: "Agent",
|
|
748
742
|
nonce: Date.now(),
|
|
749
|
-
};
|
|
743
|
+
} as const;
|
|
750
744
|
|
|
751
745
|
const signature = await signUserSignedAction({
|
|
752
746
|
wallet: privateKey,
|
|
753
747
|
action,
|
|
754
|
-
types: userSignedActionEip712Types[action.type],
|
|
755
|
-
chainId: parseInt(action.signatureChainId, 16),
|
|
748
|
+
types: userSignedActionEip712Types[action.type],
|
|
756
749
|
});
|
|
757
750
|
|
|
758
|
-
|
|
751
|
+
// Send the signed action to the Hyperliquid API
|
|
752
|
+
const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
759
753
|
method: "POST",
|
|
760
754
|
headers: { "Content-Type": "application/json" },
|
|
761
755
|
body: JSON.stringify({ action, signature, nonce: action.nonce }),
|
|
@@ -763,7 +757,25 @@ const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
|
763
757
|
const body = await response.json();
|
|
764
758
|
```
|
|
765
759
|
|
|
766
|
-
|
|
760
|
+
## FAQ
|
|
761
|
+
|
|
762
|
+
### How to execute an L1 action via an external wallet (e.g. MetaMask)?
|
|
763
|
+
|
|
764
|
+
Hyperliquid requires chain `1337` for L1 actions (open order, change leverage, etc.). There are two ways to execute an
|
|
765
|
+
L1 action through an external wallet:
|
|
766
|
+
|
|
767
|
+
- (recommended) Create an
|
|
768
|
+
[Agent Wallet](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets#api-wallets)
|
|
769
|
+
and execute all L1 actions through it
|
|
770
|
+
- Change the user's chain to `1337`, however, the user will sign unreadable data
|
|
771
|
+
|
|
772
|
+
### How to create a market order?
|
|
773
|
+
|
|
774
|
+
Hyperliquid doesn't have traditional market orders, but you can achieve market-like execution by placing limit orders
|
|
775
|
+
with `tif: "Ioc"` and prices that guarantee immediate execution:
|
|
776
|
+
|
|
777
|
+
- For buys: set limit price >= current best ask
|
|
778
|
+
- For sells: set limit price <= current best bid
|
|
767
779
|
|
|
768
780
|
## Contributing
|
|
769
781
|
|
package/esm/mod.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type * from "./src/types/exchange/responses.js";
|
|
|
11
11
|
export type * from "./src/types/explorer/responses.js";
|
|
12
12
|
export type * from "./src/types/info/accounts.js";
|
|
13
13
|
export type * from "./src/types/info/assets.js";
|
|
14
|
-
export type * from "./src/types/info/
|
|
14
|
+
export type * from "./src/types/info/validators.js";
|
|
15
15
|
export type * from "./src/types/info/markets.js";
|
|
16
16
|
export type * from "./src/types/info/orders.js";
|
|
17
17
|
export type * from "./src/types/info/vaults.js";
|
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AAGzC,YAAY,EACR,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GACzB,MAAM,sBAAsB,CAAC;AAG9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,mDAAmD,CAAC;AAGlE,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,8BAA8B,CAAC;AAClD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AAGzC,YAAY,EACR,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,GACzB,MAAM,sBAAsB,CAAC;AAG9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,mDAAmD,CAAC;AAGlE,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,8BAA8B,CAAC;AAClD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,gCAAgC,CAAC;AACpD,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,wCAAwC,CAAC"}
|
package/esm/src/base.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type Hex = `0x${string}`;
|
|
2
2
|
export type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
export type DeepImmutable<T> = {
|
|
4
|
+
readonly [K in keyof T]: DeepImmutable<T[K]>;
|
|
5
|
+
};
|
|
3
6
|
/** Base error class for all SDK errors. */
|
|
4
7
|
export declare class HyperliquidError extends Error {
|
|
5
|
-
constructor(message?: string);
|
|
8
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=base.d.ts.map
|
package/esm/src/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAG7C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC3B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,2CAA2C;AAC3C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIvD"}
|
package/esm/src/base.js
CHANGED