@nktkas/hyperliquid 0.20.0 → 0.21.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 +40 -50
- package/esm/mod.d.ts +3 -4
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +3 -4
- package/{script/src/clients/wallet.d.ts → esm/src/clients/exchange.d.ts} +100 -100
- package/esm/src/clients/exchange.d.ts.map +1 -0
- package/esm/src/clients/{wallet.js → exchange.js} +41 -41
- package/esm/src/clients/{public.d.ts → info.d.ts} +100 -100
- package/esm/src/clients/info.d.ts.map +1 -0
- package/esm/src/clients/{public.js → info.js} +51 -51
- package/{script/src/clients/event.d.ts → esm/src/clients/subscription.d.ts} +60 -78
- package/esm/src/clients/subscription.d.ts.map +1 -0
- package/esm/src/clients/{event.js → subscription.js} +57 -79
- package/esm/src/signing.d.ts +0 -1
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +0 -1
- package/esm/src/transports/base.d.ts +5 -7
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +3 -2
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +11 -5
- package/esm/src/transports/websocket/_websocket_async_request.d.ts +6 -4
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +47 -28
- package/esm/src/transports/websocket/websocket_transport.d.ts +24 -21
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +60 -57
- package/esm/src/types/info/accounts.d.ts +12 -0
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +0 -1
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/mod.js +1 -1
- package/package.json +1 -1
- package/script/mod.d.ts +3 -4
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +4 -5
- package/{esm/src/clients/wallet.d.ts → script/src/clients/exchange.d.ts} +100 -100
- package/script/src/clients/exchange.d.ts.map +1 -0
- package/script/src/clients/{wallet.js → exchange.js} +43 -43
- package/script/src/clients/{public.d.ts → info.d.ts} +100 -100
- package/script/src/clients/info.d.ts.map +1 -0
- package/script/src/clients/{public.js → info.js} +53 -53
- package/{esm/src/clients/event.d.ts → script/src/clients/subscription.d.ts} +60 -78
- package/script/src/clients/subscription.d.ts.map +1 -0
- package/script/src/clients/{event.js → subscription.js} +59 -81
- package/script/src/signing.d.ts +0 -1
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +52 -53
- package/script/src/transports/base.d.ts +5 -7
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +3 -2
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +11 -5
- package/script/src/transports/websocket/_websocket_async_request.d.ts +6 -4
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +47 -28
- package/script/src/transports/websocket/websocket_transport.d.ts +24 -21
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +60 -57
- package/script/src/types/info/accounts.d.ts +12 -0
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +0 -1
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +24 -25
- package/esm/_dnt.polyfills.d.ts +0 -20
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -12
- package/esm/src/clients/event.d.ts.map +0 -1
- package/esm/src/clients/public.d.ts.map +0 -1
- package/esm/src/clients/wallet.d.ts.map +0 -1
- package/script/_dnt.polyfills.d.ts +0 -20
- package/script/_dnt.polyfills.d.ts.map +0 -1
- package/script/_dnt.polyfills.js +0 -23
- package/script/src/clients/event.d.ts.map +0 -1
- package/script/src/clients/public.d.ts.map +0 -1
- package/script/src/clients/wallet.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -45,9 +45,9 @@ deno add jsr:@nktkas/hyperliquid
|
|
|
45
45
|
import * as hl from "@nktkas/hyperliquid";
|
|
46
46
|
|
|
47
47
|
const transport = new hl.HttpTransport();
|
|
48
|
-
const
|
|
48
|
+
const infoClient = new hl.InfoClient({ transport });
|
|
49
49
|
|
|
50
|
-
const openOrders = await
|
|
50
|
+
const openOrders = await infoClient.openOrders({ user: "0x..." }); // Change to your address
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
```ts
|
|
@@ -57,9 +57,9 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
57
57
|
const wallet = privateKeyToAccount("0x..."); // Your private key
|
|
58
58
|
|
|
59
59
|
const transport = new hl.HttpTransport();
|
|
60
|
-
const
|
|
60
|
+
const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
61
61
|
|
|
62
|
-
const result = await
|
|
62
|
+
const result = await exchClient.order({
|
|
63
63
|
orders: [{
|
|
64
64
|
a: 0, // Asset index
|
|
65
65
|
b: true, // Buy order
|
|
@@ -80,9 +80,9 @@ const result = await client.order({
|
|
|
80
80
|
import * as hl from "@nktkas/hyperliquid";
|
|
81
81
|
|
|
82
82
|
const transport = new hl.WebSocketTransport();
|
|
83
|
-
const
|
|
83
|
+
const subsClient = new hl.SubscriptionClient({ transport });
|
|
84
84
|
|
|
85
|
-
const sub = await
|
|
85
|
+
const sub = await subsClient.allMids((event) => {
|
|
86
86
|
console.log(event);
|
|
87
87
|
});
|
|
88
88
|
|
|
@@ -109,16 +109,16 @@ const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters
|
|
|
109
109
|
|
|
110
110
|
Next, initialize a client with the transport layer (more details in the [API Reference](#clients)):
|
|
111
111
|
|
|
112
|
-
#### Create
|
|
112
|
+
#### Create InfoClient
|
|
113
113
|
|
|
114
114
|
```ts
|
|
115
115
|
import * as hl from "@nktkas/hyperliquid";
|
|
116
116
|
|
|
117
117
|
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
118
|
-
const
|
|
118
|
+
const infoClient = new hl.InfoClient({ transport });
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
#### Create
|
|
121
|
+
#### Create ExchangeClient
|
|
122
122
|
|
|
123
123
|
```ts
|
|
124
124
|
import * as hl from "@nktkas/hyperliquid";
|
|
@@ -130,53 +130,53 @@ const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
|
130
130
|
|
|
131
131
|
// 1. Using Viem with private key
|
|
132
132
|
const viemAccount = privateKeyToAccount("0x...");
|
|
133
|
-
const
|
|
133
|
+
const ExchangeClient_Viem = new hl.ExchangeClient({ wallet: viemAccount, transport });
|
|
134
134
|
|
|
135
135
|
// 2. Using Ethers (or Ethers V5) with private key
|
|
136
136
|
const ethersWallet = new ethers.Wallet("0x...");
|
|
137
|
-
const
|
|
137
|
+
const ExchangeClient_Ethers = new hl.ExchangeClient({ wallet: ethersWallet, transport });
|
|
138
138
|
|
|
139
139
|
// 3. Using external wallet (e.g. MetaMask) via Viem
|
|
140
140
|
const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
141
141
|
const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
142
|
-
const
|
|
142
|
+
const ExchangeClient_ViemMetamask = new hl.ExchangeClient({ wallet: externalWallet, transport });
|
|
143
143
|
|
|
144
144
|
// 4. Using external wallet (e.g. MetaMask) via `window.ethereum` directly
|
|
145
|
-
const
|
|
145
|
+
const ExchangeClient_WindowMetamask = new hl.ExchangeClient({ wallet: window.ethereum, transport });
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
#### Create
|
|
148
|
+
#### Create SubscriptionClient
|
|
149
149
|
|
|
150
150
|
```ts
|
|
151
151
|
import * as hl from "@nktkas/hyperliquid";
|
|
152
152
|
|
|
153
153
|
const transport = new hl.WebSocketTransport(); // only WebSocketTransport
|
|
154
|
-
const
|
|
154
|
+
const subsClient = new hl.SubscriptionClient({ transport });
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
### 3) Use Client
|
|
158
158
|
|
|
159
159
|
Finally, use client methods to interact with the Hyperliquid API (more details in the [API Reference](#clients)):
|
|
160
160
|
|
|
161
|
-
#### Example of using
|
|
161
|
+
#### Example of using an InfoClient
|
|
162
162
|
|
|
163
163
|
```ts
|
|
164
164
|
import * as hl from "@nktkas/hyperliquid";
|
|
165
165
|
|
|
166
166
|
const transport = new hl.HttpTransport();
|
|
167
|
-
const
|
|
167
|
+
const infoClient = new hl.InfoClient({ transport });
|
|
168
168
|
|
|
169
169
|
// L2 Book
|
|
170
|
-
const l2Book = await
|
|
170
|
+
const l2Book = await infoClient.l2Book({ coin: "BTC" });
|
|
171
171
|
|
|
172
172
|
// Account clearinghouse state
|
|
173
|
-
const clearinghouseState = await
|
|
173
|
+
const clearinghouseState = await infoClient.clearinghouseState({ user: "0x..." });
|
|
174
174
|
|
|
175
175
|
// Open orders
|
|
176
|
-
const openOrders = await
|
|
176
|
+
const openOrders = await infoClient.openOrders({ user: "0x..." });
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
#### Example of using
|
|
179
|
+
#### Example of using an ExchangeClient
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
182
|
import * as hl from "@nktkas/hyperliquid";
|
|
@@ -184,10 +184,10 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
184
184
|
|
|
185
185
|
const account = privateKeyToAccount("0x...");
|
|
186
186
|
const transport = new hl.HttpTransport();
|
|
187
|
-
const
|
|
187
|
+
const exchClient = new hl.ExchangeClient({ wallet: account, transport });
|
|
188
188
|
|
|
189
189
|
// Place an orders
|
|
190
|
-
const result = await
|
|
190
|
+
const result = await exchClient.order({
|
|
191
191
|
orders: [{
|
|
192
192
|
a: 0,
|
|
193
193
|
b: true,
|
|
@@ -204,25 +204,25 @@ const result = await client.order({
|
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
// Approve an agent
|
|
207
|
-
const result = await
|
|
207
|
+
const result = await exchClient.approveAgent({
|
|
208
208
|
agentAddress: "0x...",
|
|
209
209
|
agentName: "agentName",
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
// Withdraw funds
|
|
213
|
-
const result = await
|
|
213
|
+
const result = await exchClient.withdraw3({
|
|
214
214
|
destination: account.address,
|
|
215
215
|
amount: "100",
|
|
216
216
|
});
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
#### Example of using
|
|
219
|
+
#### Example of using a SubscriptionClient
|
|
220
220
|
|
|
221
221
|
```ts
|
|
222
222
|
import * as hl from "@nktkas/hyperliquid";
|
|
223
223
|
|
|
224
224
|
const transport = new hl.WebSocketTransport();
|
|
225
|
-
const
|
|
225
|
+
const subsClient = new hl.SubscriptionClient({ transport });
|
|
226
226
|
|
|
227
227
|
// L2 Book updates
|
|
228
228
|
await client.l2Book({ coin: "BTC" }, (data) => {
|
|
@@ -246,16 +246,16 @@ await client.explorerBlock((data) => {
|
|
|
246
246
|
|
|
247
247
|
A Client provides access to the Hyperliquid API endpoints.
|
|
248
248
|
|
|
249
|
-
####
|
|
249
|
+
#### Info Client
|
|
250
250
|
|
|
251
|
-
|
|
251
|
+
An Info Client which provides access to
|
|
252
252
|
[Info API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint) and Explorer API, such as
|
|
253
253
|
`l2Book` and `clearinghouseState`.
|
|
254
254
|
|
|
255
|
-
The
|
|
255
|
+
The Info Client class sets up with a given [Transport](#transports).
|
|
256
256
|
|
|
257
257
|
```ts
|
|
258
|
-
class
|
|
258
|
+
class InfoClient {
|
|
259
259
|
constructor(args: {
|
|
260
260
|
transport: HttpTransport | WebSocketTransport;
|
|
261
261
|
});
|
|
@@ -324,18 +324,18 @@ class PublicClient {
|
|
|
324
324
|
}
|
|
325
325
|
```
|
|
326
326
|
|
|
327
|
-
####
|
|
327
|
+
#### Exchange Client
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
An Exchange Client which provides access to
|
|
330
330
|
[Exchange API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint), such as `order`
|
|
331
331
|
and `withdraw3`.
|
|
332
332
|
|
|
333
|
-
The
|
|
333
|
+
The Exchange Client class sets up with a given [Transport](#transports) and a wallet instance, which can be a
|
|
334
334
|
[viem](https://viem.sh/docs/clients/wallet), [ethers.js](https://docs.ethers.org/v6/api/providers/#Signer) or other
|
|
335
335
|
wallet libraries.
|
|
336
336
|
|
|
337
337
|
```ts
|
|
338
|
-
class
|
|
338
|
+
class ExchangeClient {
|
|
339
339
|
constructor(args: {
|
|
340
340
|
transport: HttpTransport | WebSocketTransport;
|
|
341
341
|
wallet:
|
|
@@ -408,17 +408,17 @@ class WalletClient {
|
|
|
408
408
|
}
|
|
409
409
|
```
|
|
410
410
|
|
|
411
|
-
####
|
|
411
|
+
#### Subscription Client
|
|
412
412
|
|
|
413
|
-
A
|
|
413
|
+
A Subscription Client which provides access to
|
|
414
414
|
[Subscriptions API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions), such as
|
|
415
415
|
real-time updates for `l2Book` and `userFills`.
|
|
416
416
|
|
|
417
|
-
The
|
|
417
|
+
The Subscription Client class sets up with a given [WebSocket Transport](#websocket-transport).
|
|
418
418
|
|
|
419
419
|
<!-- deno-fmt-ignore-start -->
|
|
420
420
|
```ts
|
|
421
|
-
class
|
|
421
|
+
class SubscriptionClient {
|
|
422
422
|
constructor(args: {
|
|
423
423
|
transport: WebSocketTransport;
|
|
424
424
|
});
|
|
@@ -473,8 +473,6 @@ class HttpTransport {
|
|
|
473
473
|
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>; // A callback before request is sent
|
|
474
474
|
onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>; // A callback after response is received
|
|
475
475
|
});
|
|
476
|
-
|
|
477
|
-
request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
478
476
|
}
|
|
479
477
|
```
|
|
480
478
|
|
|
@@ -499,16 +497,8 @@ class WebSocketTransport {
|
|
|
499
497
|
shouldReconnect?: (event: CloseEvent) => boolean | Promise<boolean>; // Custom reconnection logic (default: Always reconnect)
|
|
500
498
|
messageBuffer?: MessageBufferStrategy; // Message buffering strategy between reconnection (default: FIFO buffer)
|
|
501
499
|
};
|
|
500
|
+
autoResubscribe?: boolean; // Whether to automatically resubscribe to events after reconnection (default: true)
|
|
502
501
|
});
|
|
503
|
-
|
|
504
|
-
request(endpoint: "info" | "exchange", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
505
|
-
subscribe(
|
|
506
|
-
channel: string,
|
|
507
|
-
payload: unknown,
|
|
508
|
-
listener: (data: CustomEvent) => void,
|
|
509
|
-
signal?: AbortSignal,
|
|
510
|
-
): Promise<Subscription>;
|
|
511
|
-
|
|
512
502
|
ready(signal?: AbortSignal): Promise<void>;
|
|
513
503
|
close(signal?: AbortSignal): Promise<void>;
|
|
514
504
|
}
|
package/esm/mod.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import "./_dnt.polyfills.js";
|
|
2
1
|
export * from "./src/base.js";
|
|
3
2
|
export * from "./src/transports/base.js";
|
|
4
3
|
export type { AbstractEthersSigner, AbstractEthersV5Signer, AbstractExtendedViemWalletClient, AbstractViemWalletClient, AbstractWindowEthereum, } from "./src/signing.js";
|
|
5
|
-
export * from "./src/clients/
|
|
6
|
-
export * from "./src/clients/
|
|
7
|
-
export * from "./src/clients/
|
|
4
|
+
export * from "./src/clients/subscription.js";
|
|
5
|
+
export * from "./src/clients/info.js";
|
|
6
|
+
export * from "./src/clients/exchange.js";
|
|
8
7
|
export * from "./src/transports/http/http_transport.js";
|
|
9
8
|
export * from "./src/transports/websocket/websocket_transport.js";
|
|
10
9
|
export type * from "./src/types/exchange/responses.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,
|
|
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,gCAAgC,EAChC,wBAAwB,EACxB,sBAAsB,GACzB,MAAM,kBAAkB,CAAC;AAG1B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAG1C,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,iCAAiC,CAAC;AACrD,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,wCAAwC,CAAC"}
|
package/esm/mod.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Base interfaces
|
|
2
|
-
import "./_dnt.polyfills.js";
|
|
3
2
|
export * from "./src/base.js";
|
|
4
3
|
export * from "./src/transports/base.js";
|
|
5
4
|
// Clients
|
|
6
|
-
export * from "./src/clients/
|
|
7
|
-
export * from "./src/clients/
|
|
8
|
-
export * from "./src/clients/
|
|
5
|
+
export * from "./src/clients/subscription.js";
|
|
6
|
+
export * from "./src/clients/info.js";
|
|
7
|
+
export * from "./src/clients/exchange.js";
|
|
9
8
|
// Transports
|
|
10
9
|
export * from "./src/transports/http/http_transport.js";
|
|
11
10
|
export * from "./src/transports/websocket/websocket_transport.js";
|