@nktkas/hyperliquid 0.23.0 → 0.24.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 +3 -2
- package/README.md +184 -186
- package/esm/mod.d.ts +2 -2
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/base.d.ts +0 -5
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/clients/exchange.d.ts +430 -393
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +467 -927
- package/esm/src/clients/info.d.ts +330 -185
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +348 -334
- package/esm/src/clients/multiSign.d.ts +14 -1184
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +37 -2004
- package/esm/src/clients/subscription.d.ts +95 -93
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +101 -146
- package/esm/src/signing/_signTypedData/ethers.d.ts +16 -4
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/ethers.js +1 -1
- package/esm/src/signing/_signTypedData/mod.d.ts +12 -12
- package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/mod.js +52 -24
- package/esm/src/signing/_signTypedData/private_key.d.ts +6 -5
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/private_key.js +40 -19
- package/esm/src/signing/_signTypedData/viem.d.ts +27 -6
- package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/viem.js +1 -1
- package/esm/src/signing/_sorter.d.ts +12 -21
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +30 -63
- package/esm/src/signing/mod.d.ts +177 -127
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +182 -130
- package/esm/src/transports/base.d.ts +2 -1
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.d.ts +3 -2
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +4 -4
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -2
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +17 -21
- package/esm/src/transports/websocket/websocket_transport.d.ts +4 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +6 -6
- package/esm/src/types/exchange/requests.d.ts +492 -306
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +105 -25
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +3 -3
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +1 -1
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +403 -98
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +131 -35
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +35 -8
- package/esm/src/types/info/markets.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +62 -17
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +194 -76
- 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} +45 -15
- package/esm/src/types/info/validators.d.ts.map +1 -0
- package/esm/src/types/info/vaults.d.ts +32 -10
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +2 -2
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +21 -66
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/responses.d.ts +46 -55
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
- package/package.json +2 -3
- package/script/mod.d.ts +2 -2
- package/script/mod.d.ts.map +1 -1
- package/script/src/base.d.ts +0 -5
- package/script/src/base.d.ts.map +1 -1
- package/script/src/clients/exchange.d.ts +430 -393
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +466 -926
- package/script/src/clients/info.d.ts +330 -185
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +348 -334
- package/script/src/clients/multiSign.d.ts +14 -1184
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +38 -2005
- package/script/src/clients/subscription.d.ts +95 -93
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +101 -146
- package/script/src/signing/_signTypedData/ethers.d.ts +16 -4
- package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/ethers.js +2 -2
- package/script/src/signing/_signTypedData/mod.d.ts +12 -12
- package/script/src/signing/_signTypedData/mod.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/mod.js +51 -26
- package/script/src/signing/_signTypedData/private_key.d.ts +6 -5
- package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/private_key.js +40 -18
- package/script/src/signing/_signTypedData/viem.d.ts +27 -6
- package/script/src/signing/_signTypedData/viem.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/viem.js +2 -2
- package/script/src/signing/_sorter.d.ts +12 -21
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +30 -63
- package/script/src/signing/mod.d.ts +177 -127
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +185 -148
- package/script/src/transports/base.d.ts +2 -1
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.d.ts +3 -2
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +4 -4
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -2
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +17 -21
- package/script/src/transports/websocket/websocket_transport.d.ts +4 -4
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +6 -6
- package/script/src/types/exchange/requests.d.ts +492 -306
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/responses.d.ts +105 -25
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/explorer/requests.d.ts +3 -3
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/responses.d.ts +1 -1
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +403 -98
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +131 -35
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/markets.d.ts +35 -8
- package/script/src/types/info/markets.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +62 -17
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +194 -76
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/{esm/src/types/info/delegations.d.ts → script/src/types/info/validators.d.ts} +45 -15
- package/script/src/types/info/validators.d.ts.map +1 -0
- package/script/src/types/info/vaults.d.ts +32 -10
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +2 -2
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.d.ts +21 -66
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/responses.d.ts +46 -55
- package/script/src/types/subscriptions/responses.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/window.d.ts +0 -29
- package/esm/src/signing/_signTypedData/window.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/window.js +0 -30
- package/esm/src/types/info/delegations.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/window.d.ts +0 -29
- package/script/src/signing/_signTypedData/window.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/window.js +0 -34
- package/script/src/types/info/delegations.d.ts.map +0 -1
- /package/esm/src/types/info/{delegations.js → validators.js} +0 -0
- /package/script/src/types/info/{delegations.js → validators.js} +0 -0
package/README.md
CHANGED
|
@@ -6,16 +6,16 @@
|
|
|
6
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
|
-
runtimes, written in TypeScript
|
|
9
|
+
runtimes, written in TypeScript.
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
13
|
- 🖋️ **Typed**: Source code is 100% TypeScript.
|
|
14
|
-
- 🧪 **Tested**: Good code coverage and type
|
|
14
|
+
- 🧪 **Tested**: Good code coverage and type relevance.
|
|
15
15
|
- 📦 **Minimal dependencies**: A few small trusted dependencies.
|
|
16
16
|
- 🌐 **Cross-Environment Support**: Compatible with all major JS runtimes.
|
|
17
|
-
- 🔧 **Integratable**: Easy to use with [viem](https://github.com/wevm/viem),
|
|
18
|
-
[ethers](https://github.com/ethers-io/ethers.js)
|
|
17
|
+
- 🔧 **Integratable**: Easy to use with wallet providers ([viem](https://github.com/wevm/viem),
|
|
18
|
+
[ethers](https://github.com/ethers-io/ethers.js), private key directly).
|
|
19
19
|
- 📚 **Documented**: JSDoc annotations with usage examples in source code.
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
@@ -53,9 +53,10 @@ deno add jsr:@nktkas/hyperliquid
|
|
|
53
53
|
<summary>For React Native, you need to import polyfills before importing the SDK:</summary>
|
|
54
54
|
|
|
55
55
|
```js
|
|
56
|
-
// React Native
|
|
56
|
+
// React Native 0.76.3 / Expo v52
|
|
57
57
|
// Issues:
|
|
58
|
-
// - signing: does not support private keys directly, use viem or ethers
|
|
58
|
+
// - signing: does not support private keys directly, use `viem` or `ethers`
|
|
59
|
+
|
|
59
60
|
import { Event, EventTarget } from "event-target-shim";
|
|
60
61
|
|
|
61
62
|
if (!globalThis.EventTarget || !globalThis.Event) {
|
|
@@ -90,48 +91,40 @@ if (!Promise.withResolvers) {
|
|
|
90
91
|
return { promise, resolve, reject };
|
|
91
92
|
};
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
-
if (!ArrayBuffer.prototype.transfer) {
|
|
95
|
-
ArrayBuffer.prototype.transfer = function (newByteLength) {
|
|
96
|
-
const length = newByteLength ?? this.byteLength;
|
|
97
|
-
const newBuffer = new ArrayBuffer(length);
|
|
98
|
-
const oldView = new Uint8Array(this);
|
|
99
|
-
const newView = new Uint8Array(newBuffer);
|
|
100
|
-
|
|
101
|
-
newView.set(oldView.subarray(0, Math.min(oldView.length, length)));
|
|
102
|
-
|
|
103
|
-
Object.defineProperty(this, "byteLength", { value: 0 });
|
|
104
|
-
|
|
105
|
-
return newBuffer;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
94
|
```
|
|
109
95
|
|
|
110
96
|
</details>
|
|
111
97
|
|
|
112
98
|
## Quick Start
|
|
113
99
|
|
|
114
|
-
|
|
100
|
+
### [Info endpoint](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint)
|
|
115
101
|
|
|
116
102
|
```ts
|
|
103
|
+
// 1. Import module
|
|
117
104
|
import * as hl from "@nktkas/hyperliquid";
|
|
118
105
|
|
|
119
|
-
|
|
120
|
-
const infoClient = new hl.InfoClient({
|
|
106
|
+
// 1. Set up client with transport
|
|
107
|
+
const infoClient = new hl.InfoClient({
|
|
108
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
109
|
+
});
|
|
121
110
|
|
|
111
|
+
// 3. Query data
|
|
122
112
|
const openOrders = await infoClient.openOrders({ user: "0x..." });
|
|
123
113
|
```
|
|
124
114
|
|
|
125
|
-
|
|
115
|
+
### [Exchange endpoint](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint)
|
|
126
116
|
|
|
127
117
|
```ts
|
|
118
|
+
// 1. Import module
|
|
128
119
|
import * as hl from "@nktkas/hyperliquid";
|
|
129
120
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
// 2. Set up client with wallet and transport
|
|
122
|
+
const exchClient = new hl.ExchangeClient({
|
|
123
|
+
wallet: "0x...", // `viem`, `ethers`, or private key directly
|
|
124
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
125
|
+
});
|
|
134
126
|
|
|
127
|
+
// 3. Execute an action
|
|
135
128
|
const result = await exchClient.order({
|
|
136
129
|
orders: [{
|
|
137
130
|
a: 0,
|
|
@@ -149,38 +142,41 @@ const result = await exchClient.order({
|
|
|
149
142
|
});
|
|
150
143
|
```
|
|
151
144
|
|
|
152
|
-
|
|
145
|
+
### [Subscription](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions)
|
|
153
146
|
|
|
154
147
|
```ts
|
|
148
|
+
// 1. Import module
|
|
155
149
|
import * as hl from "@nktkas/hyperliquid";
|
|
156
150
|
|
|
157
|
-
|
|
158
|
-
const subsClient = new hl.SubscriptionClient({
|
|
151
|
+
// 2. Set up client with transport
|
|
152
|
+
const subsClient = new hl.SubscriptionClient({
|
|
153
|
+
transport: new hl.WebSocketTransport(),
|
|
154
|
+
});
|
|
159
155
|
|
|
156
|
+
// 3. Subscribe to events
|
|
160
157
|
const sub = await subsClient.allMids((event) => {
|
|
161
158
|
console.log(event);
|
|
162
159
|
});
|
|
163
|
-
|
|
164
|
-
await sub.unsubscribe(); // unsubscribe from the event
|
|
160
|
+
await sub.unsubscribe();
|
|
165
161
|
```
|
|
166
162
|
|
|
167
|
-
|
|
163
|
+
### [Multi-Sign](https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig)
|
|
168
164
|
|
|
169
165
|
```ts
|
|
166
|
+
// 1. Import module
|
|
170
167
|
import * as hl from "@nktkas/hyperliquid";
|
|
171
168
|
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const data = await multiSignClient.approveAgent({ // same API as `ExchangeClient`
|
|
181
|
-
agentAddress: "0x...",
|
|
182
|
-
agentName: "agentName",
|
|
169
|
+
// 2. Set up client with
|
|
170
|
+
const multiSignClient = new hl.MultiSignClient({
|
|
171
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
172
|
+
multiSignAddress: "0x...",
|
|
173
|
+
signers: [
|
|
174
|
+
"0x...", // `viem`, `ethers`, or private key directly
|
|
175
|
+
],
|
|
183
176
|
});
|
|
177
|
+
|
|
178
|
+
// 3. Execute an action
|
|
179
|
+
const data = await multiSignClient.approveAgent({ agentAddress: "0x..." });
|
|
184
180
|
```
|
|
185
181
|
|
|
186
182
|
## Usage
|
|
@@ -193,26 +189,27 @@ First, choose and configure your transport layer (more details in the [API Refer
|
|
|
193
189
|
import * as hl from "@nktkas/hyperliquid";
|
|
194
190
|
|
|
195
191
|
// 1. HTTP Transport: suitable for one-time requests or serverless environments
|
|
196
|
-
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
|
|
192
|
+
const httpTransport = new hl.HttpTransport({...}); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
|
|
197
193
|
|
|
198
194
|
// 2. WebSocket Transport: has better network latency than HTTP transport
|
|
199
|
-
const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters (e.g. url, timeout, reconnect, etc.)
|
|
195
|
+
const wsTransport = new hl.WebSocketTransport({...}); // Accepts optional parameters (e.g. url, timeout, reconnect, etc.)
|
|
200
196
|
```
|
|
201
197
|
|
|
202
198
|
### 2) Initialize Client
|
|
203
199
|
|
|
204
200
|
Next, initialize a client with the transport layer (more details in the [API Reference](#clients)):
|
|
205
201
|
|
|
206
|
-
#### Create InfoClient
|
|
202
|
+
#### Create [InfoClient](#infoclient)
|
|
207
203
|
|
|
208
204
|
```ts
|
|
209
205
|
import * as hl from "@nktkas/hyperliquid";
|
|
210
206
|
|
|
211
|
-
const
|
|
212
|
-
|
|
207
|
+
const infoClient = new hl.InfoClient({
|
|
208
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
209
|
+
});
|
|
213
210
|
```
|
|
214
211
|
|
|
215
|
-
#### Create ExchangeClient
|
|
212
|
+
#### Create [ExchangeClient](#exchangeclient)
|
|
216
213
|
|
|
217
214
|
```ts
|
|
218
215
|
import * as hl from "@nktkas/hyperliquid";
|
|
@@ -230,7 +227,7 @@ const exchClient_privateKey = new hl.ExchangeClient({ wallet: privateKey, transp
|
|
|
230
227
|
const viemAccount = privateKeyToAccount("0x...");
|
|
231
228
|
const exchClient_viem = new hl.ExchangeClient({ wallet: viemAccount, transport });
|
|
232
229
|
|
|
233
|
-
// 3. Using Ethers (or
|
|
230
|
+
// 3. Using Ethers (V5 or V6)
|
|
234
231
|
const ethersWallet = new ethers.Wallet("0x...");
|
|
235
232
|
const exchClient_ethers = new hl.ExchangeClient({ wallet: ethersWallet, transport });
|
|
236
233
|
|
|
@@ -238,70 +235,69 @@ const exchClient_ethers = new hl.ExchangeClient({ wallet: ethersWallet, transpor
|
|
|
238
235
|
const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
239
236
|
const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
240
237
|
const exchClient_viemMetamask = new hl.ExchangeClient({ wallet: externalWallet, transport });
|
|
241
|
-
|
|
242
|
-
// 5. Using external wallet (e.g. MetaMask) via `window.ethereum`
|
|
243
|
-
const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereum, transport });
|
|
244
238
|
```
|
|
245
239
|
|
|
246
|
-
#### Create SubscriptionClient
|
|
240
|
+
#### Create [SubscriptionClient](#subscriptionclient)
|
|
247
241
|
|
|
248
242
|
```ts
|
|
249
243
|
import * as hl from "@nktkas/hyperliquid";
|
|
250
244
|
|
|
251
|
-
const
|
|
252
|
-
|
|
245
|
+
const subsClient = new hl.SubscriptionClient({
|
|
246
|
+
transport: new hl.WebSocketTransport(),
|
|
247
|
+
});
|
|
253
248
|
```
|
|
254
249
|
|
|
255
|
-
#### Create MultiSignClient
|
|
250
|
+
#### Create [MultiSignClient](#multisignclient)
|
|
256
251
|
|
|
257
252
|
```ts
|
|
258
253
|
import * as hl from "@nktkas/hyperliquid";
|
|
259
254
|
import { privateKeyToAccount } from "viem/accounts";
|
|
260
255
|
import { ethers } from "ethers";
|
|
261
256
|
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
chainId: number;
|
|
272
|
-
verifyingContract: Hex;
|
|
273
|
-
};
|
|
274
|
-
types: {
|
|
275
|
-
[key: string]: {
|
|
257
|
+
const multiSignClient = new hl.MultiSignClient({
|
|
258
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
259
|
+
multiSignAddress: "0x...",
|
|
260
|
+
signers: [
|
|
261
|
+
privateKeyToAccount("0x..."), // first is leader for multi-sign transaction (signs transaction 2 times)
|
|
262
|
+
new ethers.Wallet("0x..."),
|
|
263
|
+
{ // can be a custom async wallet
|
|
264
|
+
async signTypedData(params: {
|
|
265
|
+
domain: {
|
|
276
266
|
name: string;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
267
|
+
version: string;
|
|
268
|
+
chainId: number;
|
|
269
|
+
verifyingContract: `0x${string}`;
|
|
270
|
+
};
|
|
271
|
+
types: {
|
|
272
|
+
[key: string]: {
|
|
273
|
+
name: string;
|
|
274
|
+
type: string;
|
|
275
|
+
}[];
|
|
276
|
+
};
|
|
277
|
+
primaryType: string;
|
|
278
|
+
message: Record<string, unknown>;
|
|
279
|
+
}): Promise<`0x${string}`> {
|
|
280
|
+
// Custom signer logic
|
|
281
|
+
return "0x..."; // return hex signature
|
|
282
|
+
},
|
|
285
283
|
},
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const transport = new hl.HttpTransport();
|
|
291
|
-
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
|
|
284
|
+
"0x...", // private key directly
|
|
285
|
+
],
|
|
286
|
+
});
|
|
292
287
|
```
|
|
293
288
|
|
|
294
289
|
### 3) Use Client
|
|
295
290
|
|
|
296
291
|
Finally, use client methods to interact with the Hyperliquid API (more details in the [API Reference](#clients)):
|
|
297
292
|
|
|
298
|
-
#### Example of using an InfoClient
|
|
293
|
+
#### Example of using an [InfoClient](#infoclient)
|
|
299
294
|
|
|
300
295
|
```ts
|
|
301
296
|
import * as hl from "@nktkas/hyperliquid";
|
|
302
297
|
|
|
303
|
-
const
|
|
304
|
-
|
|
298
|
+
const infoClient = new hl.InfoClient({
|
|
299
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
300
|
+
});
|
|
305
301
|
|
|
306
302
|
// L2 Book
|
|
307
303
|
const l2Book = await infoClient.l2Book({ coin: "BTC" });
|
|
@@ -313,15 +309,15 @@ const clearinghouseState = await infoClient.clearinghouseState({ user: "0x..." }
|
|
|
313
309
|
const openOrders = await infoClient.openOrders({ user: "0x..." });
|
|
314
310
|
```
|
|
315
311
|
|
|
316
|
-
#### Example of using an ExchangeClient
|
|
312
|
+
#### Example of using an [ExchangeClient](#exchangeclient)
|
|
317
313
|
|
|
318
314
|
```ts
|
|
319
315
|
import * as hl from "@nktkas/hyperliquid";
|
|
320
316
|
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
317
|
+
const exchClient = new hl.ExchangeClient({
|
|
318
|
+
wallet: "0x...", // `viem`, `ethers`, or private key directly
|
|
319
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
320
|
+
});
|
|
325
321
|
|
|
326
322
|
// Place an orders
|
|
327
323
|
const result = await exchClient.order({
|
|
@@ -341,25 +337,20 @@ const result = await exchClient.order({
|
|
|
341
337
|
});
|
|
342
338
|
|
|
343
339
|
// Approve an agent
|
|
344
|
-
const result = await exchClient.approveAgent({
|
|
345
|
-
agentAddress: "0x...",
|
|
346
|
-
agentName: "agentName",
|
|
347
|
-
});
|
|
340
|
+
const result = await exchClient.approveAgent({ agentAddress: "0x..." });
|
|
348
341
|
|
|
349
342
|
// Withdraw funds
|
|
350
|
-
const result = await exchClient.withdraw3({
|
|
351
|
-
destination: account.address,
|
|
352
|
-
amount: "100",
|
|
353
|
-
});
|
|
343
|
+
const result = await exchClient.withdraw3({ destination: "0x...", amount: "100" });
|
|
354
344
|
```
|
|
355
345
|
|
|
356
|
-
#### Example of using a SubscriptionClient
|
|
346
|
+
#### Example of using a [SubscriptionClient](#subscriptionclient)
|
|
357
347
|
|
|
358
348
|
```ts
|
|
359
349
|
import * as hl from "@nktkas/hyperliquid";
|
|
360
350
|
|
|
361
|
-
const
|
|
362
|
-
|
|
351
|
+
const subsClient = new hl.SubscriptionClient({
|
|
352
|
+
transport: new hl.WebSocketTransport(),
|
|
353
|
+
});
|
|
363
354
|
|
|
364
355
|
// L2 Book updates
|
|
365
356
|
await subsClient.l2Book({ coin: "BTC" }, (data) => {
|
|
@@ -372,54 +363,25 @@ await subsClient.userFills({ user: "0x..." }, (data) => {
|
|
|
372
363
|
});
|
|
373
364
|
|
|
374
365
|
// Candle updates
|
|
375
|
-
|
|
366
|
+
await subsClient.candle({ coin: "BTC", interval: "1h" }, (data) => {
|
|
376
367
|
console.log(data);
|
|
377
368
|
});
|
|
378
369
|
```
|
|
379
370
|
|
|
380
|
-
#### Example of using a MultiSignClient
|
|
371
|
+
#### Example of using a [MultiSignClient](#multisignclient)
|
|
381
372
|
|
|
382
373
|
```ts
|
|
383
374
|
import * as hl from "@nktkas/hyperliquid";
|
|
384
375
|
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
"0x...",
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
|
|
392
|
-
|
|
393
|
-
// Interaction is the same as with `ExchangeClient`
|
|
394
|
-
|
|
395
|
-
// Place an orders
|
|
396
|
-
const result = await multiSignClient.order({
|
|
397
|
-
orders: [{
|
|
398
|
-
a: 0,
|
|
399
|
-
b: true,
|
|
400
|
-
p: "30000",
|
|
401
|
-
s: "0.1",
|
|
402
|
-
r: false,
|
|
403
|
-
t: {
|
|
404
|
-
limit: {
|
|
405
|
-
tif: "Gtc",
|
|
406
|
-
},
|
|
407
|
-
},
|
|
408
|
-
}],
|
|
409
|
-
grouping: "na",
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
// Approve an agent
|
|
413
|
-
const result = await multiSignClient.approveAgent({
|
|
414
|
-
agentAddress: "0x...",
|
|
415
|
-
agentName: "agentName",
|
|
376
|
+
const multiSignClient = new hl.MultiSignClient({
|
|
377
|
+
transport: new hl.HttpTransport(), // or `WebSocketTransport`
|
|
378
|
+
multiSignAddress: "0x...",
|
|
379
|
+
signers: [
|
|
380
|
+
"0x...", // `viem`, `ethers`, or private key directly
|
|
381
|
+
],
|
|
416
382
|
});
|
|
417
383
|
|
|
418
|
-
//
|
|
419
|
-
const result = await multiSignClient.withdraw3({
|
|
420
|
-
destination: account.address,
|
|
421
|
-
amount: "100",
|
|
422
|
-
});
|
|
384
|
+
// Interaction is the same as with `ExchangeClient`
|
|
423
385
|
```
|
|
424
386
|
|
|
425
387
|
## API Reference
|
|
@@ -428,9 +390,6 @@ const result = await multiSignClient.withdraw3({
|
|
|
428
390
|
|
|
429
391
|
A client is an interface through which you can interact with the Hyperliquid API.
|
|
430
392
|
|
|
431
|
-
The client is responsible for formatting an action, creating a signature correctly, sending a request, and validating a
|
|
432
|
-
response.
|
|
433
|
-
|
|
434
393
|
#### InfoClient
|
|
435
394
|
|
|
436
395
|
```ts
|
|
@@ -444,6 +403,9 @@ class InfoClient {
|
|
|
444
403
|
candleSnapshot(args: CandleSnapshotParameters): Promise<Candle[]>;
|
|
445
404
|
fundingHistory(args: FundingHistoryParameters): Promise<FundingHistory[]>;
|
|
446
405
|
l2Book(args: L2BookParameters): Promise<Book>;
|
|
406
|
+
liquidatable(): Promise<unknown[]>;
|
|
407
|
+
marginTable(args: MarginTableParameters): Promise<MarginTable>;
|
|
408
|
+
maxMarketOrderNtls(): Promise<[number, string][]>;
|
|
447
409
|
meta(): Promise<PerpsMeta>;
|
|
448
410
|
metaAndAssetCtxs(): Promise<PerpsMetaAndAssetCtxs>;
|
|
449
411
|
perpDeployAuctionStatus(): Promise<DeployAuctionStatus>;
|
|
@@ -484,18 +446,23 @@ class InfoClient {
|
|
|
484
446
|
userTwapSliceFills(args: UserTwapSliceFillsParameters): Promise<TwapSliceFill[]>;
|
|
485
447
|
userTwapSliceFillsByTime(args: UserTwapSliceFillsByTimeParameters): Promise<TwapSliceFill[]>;
|
|
486
448
|
|
|
487
|
-
//
|
|
449
|
+
// Validator
|
|
488
450
|
delegations(args: DelegationsParameters): Promise<Delegation[]>;
|
|
489
451
|
delegatorHistory(args: DelegatorHistoryParameters): Promise<DelegatorUpdate[]>;
|
|
490
452
|
delegatorRewards(args: DelegatorRewardsParameters): Promise<DelegatorReward[]>;
|
|
491
453
|
delegatorSummary(args: DelegatorSummaryParameters): Promise<DelegatorSummary>;
|
|
454
|
+
validatorL1Votes(): Promise<unknown[]>;
|
|
492
455
|
validatorSummaries(): Promise<ValidatorSummary[]>;
|
|
493
456
|
|
|
494
457
|
// Vault
|
|
458
|
+
leadingVaults(args: LeadingVaultsParameters): Promise<VaultLeading[]>;
|
|
495
459
|
userVaultEquities(args: UserVaultEquitiesParameters): Promise<VaultEquity[]>;
|
|
496
460
|
vaultDetails(args: VaultDetailsParameters): Promise<VaultDetails | null>;
|
|
497
461
|
vaultSummaries(): Promise<VaultSummary[]>;
|
|
498
462
|
|
|
463
|
+
// Server
|
|
464
|
+
exchangeStatus(): Promise<ExchangeStatus>;
|
|
465
|
+
|
|
499
466
|
// Explorer (RPC endpoint)
|
|
500
467
|
blockDetails(args: BlockDetailsParameters): Promise<BlockDetails>;
|
|
501
468
|
txDetails(args: TxDetailsParameters): Promise<TxDetails>;
|
|
@@ -509,16 +476,11 @@ class InfoClient {
|
|
|
509
476
|
class ExchangeClient {
|
|
510
477
|
constructor(args: {
|
|
511
478
|
transport: HttpTransport | WebSocketTransport;
|
|
512
|
-
wallet:
|
|
513
|
-
| Hex // Private key directly
|
|
514
|
-
| AbstractViemWalletClient // viem
|
|
515
|
-
| AbstractEthersSigner // ethers
|
|
516
|
-
| AbstractEthersV5Signer // ethers v5
|
|
517
|
-
| AbstractWindowEthereum; // window.ethereum (EIP-1193)
|
|
479
|
+
wallet: AbstractWallet; // `viem`, `ethers` (v5 or v6), or private key directly
|
|
518
480
|
isTestnet?: boolean; // Whether to use testnet (default: false)
|
|
519
|
-
defaultVaultAddress?:
|
|
520
|
-
signatureChainId?:
|
|
521
|
-
nonceManager?: () => MaybePromise<number>; // Function to get the next nonce (default:
|
|
481
|
+
defaultVaultAddress?: `0x${string}`; // Vault address used by default if not provided in method call
|
|
482
|
+
signatureChainId?: `0x${string}` | (() => MaybePromise<`0x${string}`>); // Chain ID used for signing (default: get chain id from wallet otherwise `0x1`)
|
|
483
|
+
nonceManager?: () => MaybePromise<number>; // Function to get the next nonce (default: monotonically incrementing `Date.now()`)
|
|
522
484
|
});
|
|
523
485
|
|
|
524
486
|
// Order
|
|
@@ -537,18 +499,16 @@ class ExchangeClient {
|
|
|
537
499
|
approveAgent(args: ApproveAgentParameters): Promise<SuccessResponse>;
|
|
538
500
|
approveBuilderFee(args: ApproveBuilderFeeParameters): Promise<SuccessResponse>;
|
|
539
501
|
claimRewards(): Promise<SuccessResponse>;
|
|
540
|
-
convertToMultiSigUser(args: ConvertToMultiSigUserParameters): Promise<SuccessResponse>;
|
|
541
502
|
createSubAccount(args: CreateSubAccountParameters): Promise<CreateSubAccountResponse>;
|
|
542
503
|
evmUserModify(args: EvmUserModifyParameters): Promise<SuccessResponse>;
|
|
543
504
|
registerReferrer(args: RegisterReferrerParameters): Promise<SuccessResponse>;
|
|
544
505
|
reserveRequestWeight(args: ReserveRequestWeightParameters): Promise<SuccessResponse>;
|
|
545
506
|
setDisplayName(args: SetDisplayNameParameters): Promise<SuccessResponse>;
|
|
546
507
|
setReferrer(args: SetReferrerParameters): Promise<SuccessResponse>;
|
|
508
|
+
subAccountModify(args: SubAccountModifyParameters): Promise<SuccessResponse>;
|
|
547
509
|
spotUser(args: SpotUserParameters): Promise<SuccessResponse>;
|
|
548
510
|
|
|
549
511
|
// Transfer
|
|
550
|
-
perpDexClassTransfer(args: PerpDexClassTransferParameters): Promise<SuccessResponse>;
|
|
551
|
-
perpDexTransfer(args: PerpDexTransferParameters): Promise<SuccessResponse>;
|
|
552
512
|
spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
|
|
553
513
|
subAccountSpotTransfer(args: SubAccountSpotTransferParameters): Promise<SuccessResponse>;
|
|
554
514
|
subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
|
|
@@ -572,6 +532,7 @@ class ExchangeClient {
|
|
|
572
532
|
vaultTransfer(args: VaultTransferParameters): Promise<SuccessResponse>;
|
|
573
533
|
|
|
574
534
|
// Multi-Sign
|
|
535
|
+
convertToMultiSigUser(args: ConvertToMultiSigUserParameters): Promise<SuccessResponse>;
|
|
575
536
|
multiSig(args: MultiSigParameters): Promise<BaseExchangeResponse>;
|
|
576
537
|
|
|
577
538
|
// Validator
|
|
@@ -591,7 +552,7 @@ class SubscriptionClient {
|
|
|
591
552
|
|
|
592
553
|
// Market
|
|
593
554
|
activeAssetCtx(args: EventActiveAssetCtxParameters, listener: (data: WsActiveAssetCtx | WsActiveSpotAssetCtx) => void): Promise<Subscription>;
|
|
594
|
-
activeAssetData(args: EventActiveAssetDataParameters, listener: (data:
|
|
555
|
+
activeAssetData(args: EventActiveAssetDataParameters, listener: (data: ActiveAssetData) => void): Promise<Subscription>;
|
|
595
556
|
allMids(listener: (data: WsAllMids) => void): Promise<Subscription>;
|
|
596
557
|
bbo(args: EventBboParameters, listener: (data: WsBbo) => void): Promise<Subscription>;
|
|
597
558
|
candle(args: EventCandleParameters, listener: (data: Candle) => void): Promise<Subscription>;
|
|
@@ -611,7 +572,7 @@ class SubscriptionClient {
|
|
|
611
572
|
userTwapHistory(args: EventUserTwapHistory, listener: (data: WsUserTwapHistory) => void): Promise<Subscription>;
|
|
612
573
|
userTwapSliceFills(args: EventUserTwapSliceFills, listener: (data: WsUserTwapSliceFills) => void): Promise<Subscription>;
|
|
613
574
|
|
|
614
|
-
// Explorer
|
|
575
|
+
// Explorer (RPC endpoint)
|
|
615
576
|
explorerBlock(listener: (data: WsBlockDetails[]) => void): Promise<Subscription>;
|
|
616
577
|
explorerTxs(listener: (data: TxDetails[]) => void): Promise<Subscription>;
|
|
617
578
|
}
|
|
@@ -624,13 +585,10 @@ class SubscriptionClient {
|
|
|
624
585
|
class MultiSignClient extends ExchangeClient {
|
|
625
586
|
constructor(
|
|
626
587
|
args:
|
|
627
|
-
& Omit<ExchangeClientParameters, "wallet"> //
|
|
588
|
+
& Omit<ExchangeClientParameters, "wallet"> // instead of `wallet`, you should specify the following parameters:
|
|
628
589
|
& {
|
|
629
|
-
multiSignAddress:
|
|
630
|
-
signers: [
|
|
631
|
-
AbstractWalletWithAddress, // First signer is the leader of a multi-sign transaction
|
|
632
|
-
...AbstractWallet[], // Any number of additional signers
|
|
633
|
-
];
|
|
590
|
+
multiSignAddress: `0x${string}`;
|
|
591
|
+
signers: [AbstractWallet, ...AbstractWallet[]];
|
|
634
592
|
},
|
|
635
593
|
);
|
|
636
594
|
|
|
@@ -644,7 +602,11 @@ Transport acts as a layer between class requests and Hyperliquid servers.
|
|
|
644
602
|
|
|
645
603
|
#### HTTP Transport
|
|
646
604
|
|
|
647
|
-
|
|
605
|
+
**Features:**
|
|
606
|
+
|
|
607
|
+
- Uses [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) for requests. Can be configured using
|
|
608
|
+
[`fetchOptions`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit).
|
|
609
|
+
- Automatically determines the target URL based on the request + `isTestnet` flag.
|
|
648
610
|
|
|
649
611
|
```ts
|
|
650
612
|
class HttpTransport {
|
|
@@ -664,7 +626,20 @@ class HttpTransport {
|
|
|
664
626
|
|
|
665
627
|
#### WebSocket Transport
|
|
666
628
|
|
|
667
|
-
|
|
629
|
+
**Features:**
|
|
630
|
+
|
|
631
|
+
- Uses [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) for requests.
|
|
632
|
+
- Supports [subscriptions](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions)
|
|
633
|
+
and [post requests](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests).
|
|
634
|
+
- Automatically restores connection after loss and resubscribes to previous subscriptions.
|
|
635
|
+
- Smart keep alive (pings only when idle).
|
|
636
|
+
- Lazy initialization with message buffering during connection establishment.
|
|
637
|
+
|
|
638
|
+
**Limitations:**
|
|
639
|
+
|
|
640
|
+
- Cannot mix api/explorer endpoints or mainnet/testnet in single connection. Need to create separate instances for
|
|
641
|
+
different endpoints.
|
|
642
|
+
- Cannot send explorer post-requests via WebSocket. Use [HTTP transport](#http-transport).
|
|
668
643
|
|
|
669
644
|
```ts
|
|
670
645
|
class WebSocketTransport {
|
|
@@ -707,27 +682,23 @@ The import point gives access to functions that generate signatures for Hyperliq
|
|
|
707
682
|
```ts
|
|
708
683
|
import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
709
684
|
|
|
710
|
-
const privateKey = "0x..."; //
|
|
685
|
+
const privateKey = "0x..."; // `viem`, `ethers`, or private key directly
|
|
711
686
|
|
|
712
|
-
const
|
|
713
|
-
const action = {
|
|
687
|
+
const action = actionSorter.cancel({
|
|
714
688
|
type: "cancel",
|
|
715
689
|
cancels: [
|
|
716
690
|
{ a: 0, o: 12345 },
|
|
717
691
|
],
|
|
718
|
-
} as const;
|
|
719
|
-
|
|
720
|
-
const signature = await signL1Action({
|
|
721
|
-
wallet: privateKey,
|
|
722
|
-
action: actionSorter[action.type](action),
|
|
723
|
-
nonce,
|
|
724
692
|
});
|
|
693
|
+
const nonce = Date.now();
|
|
694
|
+
|
|
695
|
+
const signature = await signL1Action({ wallet: privateKey, action, nonce });
|
|
725
696
|
|
|
726
697
|
// Send the signed action to the Hyperliquid API
|
|
727
698
|
const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
728
699
|
method: "POST",
|
|
729
700
|
headers: { "Content-Type": "application/json" },
|
|
730
|
-
body: JSON.stringify({ action, signature, nonce }),
|
|
701
|
+
body: JSON.stringify({ action, signature, nonce }), // recommended to send the same formatted action
|
|
731
702
|
});
|
|
732
703
|
const body = await response.json();
|
|
733
704
|
```
|
|
@@ -735,18 +706,18 @@ const body = await response.json();
|
|
|
735
706
|
#### Approve agent yourself
|
|
736
707
|
|
|
737
708
|
```ts
|
|
738
|
-
import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
709
|
+
import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
739
710
|
|
|
740
|
-
const privateKey = "0x..."; //
|
|
711
|
+
const privateKey = "0x..."; // `viem`, `ethers`, or private key directly
|
|
741
712
|
|
|
742
|
-
const action = {
|
|
713
|
+
const action = actionSorter.approveAgent({
|
|
743
714
|
type: "approveAgent",
|
|
744
715
|
signatureChainId: "0x66eee",
|
|
745
716
|
hyperliquidChain: "Mainnet",
|
|
746
717
|
agentAddress: "0x...",
|
|
747
718
|
agentName: "Agent",
|
|
748
719
|
nonce: Date.now(),
|
|
749
|
-
}
|
|
720
|
+
});
|
|
750
721
|
|
|
751
722
|
const signature = await signUserSignedAction({
|
|
752
723
|
wallet: privateKey,
|
|
@@ -758,11 +729,38 @@ const signature = await signUserSignedAction({
|
|
|
758
729
|
const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
759
730
|
method: "POST",
|
|
760
731
|
headers: { "Content-Type": "application/json" },
|
|
761
|
-
body: JSON.stringify({ action, signature, nonce: action.nonce }),
|
|
732
|
+
body: JSON.stringify({ action, signature, nonce: action.nonce }), // recommended to send the same formatted action
|
|
762
733
|
});
|
|
763
734
|
const body = await response.json();
|
|
764
735
|
```
|
|
765
736
|
|
|
737
|
+
## FAQ
|
|
738
|
+
|
|
739
|
+
### How to execute an L1 action via an external wallet (e.g. MetaMask)?
|
|
740
|
+
|
|
741
|
+
Hyperliquid requires chain `1337` for L1 actions (open order, change leverage, etc.). There are two ways to execute an
|
|
742
|
+
L1 action through an external wallet:
|
|
743
|
+
|
|
744
|
+
- (recommended) Create an
|
|
745
|
+
[Agent Wallet](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets#api-wallets)
|
|
746
|
+
and execute all L1 actions through it
|
|
747
|
+
- Change the user's chain to `1337`, however, the user will sign unreadable data
|
|
748
|
+
|
|
749
|
+
### How to create a market order?
|
|
750
|
+
|
|
751
|
+
Hyperliquid doesn't have traditional market orders, but you can achieve market-like execution by placing limit order
|
|
752
|
+
with `tif: "Ioc"` and price that guarantee immediate execution:
|
|
753
|
+
|
|
754
|
+
- For buys: set limit price >= current best ask
|
|
755
|
+
- For sells: set limit price <= current best bid
|
|
756
|
+
|
|
757
|
+
### How to use the [Agent Wallet](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets#api-wallets) / [Vault](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#subaccounts-and-vaults) / [Sub-Account](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#subaccounts-and-vaults) in `ExchangeClient`?
|
|
758
|
+
|
|
759
|
+
**Agent Wallet**: Use agent's private key in constructor instead of master account's private key.
|
|
760
|
+
|
|
761
|
+
**Vault and Sub-Account**: Pass vault or sub-account address via `vaultAddress` options to methods or set
|
|
762
|
+
`defaultVaultAddress` in constructor.
|
|
763
|
+
|
|
766
764
|
## Contributing
|
|
767
765
|
|
|
768
766
|
We appreciate your help! To contribute, please read the [contributing instructions](CONTRIBUTING.md).
|