@rabby-wallet/hyperliquid-sdk 1.0.0-beta.18 → 1.0.0-beta.19
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/dist/client/exchange-client.d.ts +2 -1
- package/dist/client/exchange-client.js +6 -0
- package/dist/client/info-client.d.ts +3 -2
- package/dist/client/info-client.js +48 -9
- package/dist/client/websocket-client.d.ts +2 -1
- package/dist/client/websocket-client.js +22 -1
- package/dist/hyperliquid-sdk.d.ts +3 -3
- package/dist/hyperliquid-sdk.js +19 -6
- package/package.json +1 -1
|
@@ -9,10 +9,11 @@ export declare class ExchangeClient {
|
|
|
9
9
|
private agentPublicKey?;
|
|
10
10
|
private agentName?;
|
|
11
11
|
private readonly isTestnet;
|
|
12
|
-
private
|
|
12
|
+
private masterAddress;
|
|
13
13
|
private builder?;
|
|
14
14
|
private readonly symbolConversion;
|
|
15
15
|
constructor(config: ExchangeClientConfig);
|
|
16
|
+
initAccount(masterAddress: string, agentPrivateKey: string, agentPublicKey: string, agentName?: string): void;
|
|
16
17
|
/**
|
|
17
18
|
* Get the wallet address
|
|
18
19
|
*/
|
|
@@ -80,6 +80,12 @@ class ExchangeClient {
|
|
|
80
80
|
}
|
|
81
81
|
this.isTestnet = config.isTestnet || false;
|
|
82
82
|
}
|
|
83
|
+
initAccount(masterAddress, agentPrivateKey, agentPublicKey, agentName) {
|
|
84
|
+
this.masterAddress = masterAddress;
|
|
85
|
+
this.agentPrivateKey = agentPrivateKey.startsWith('0x') ? agentPrivateKey : ethUtil.addHexPrefix(agentPrivateKey);
|
|
86
|
+
this.agentPublicKey = agentPublicKey.startsWith('0x') ? agentPublicKey : ethUtil.addHexPrefix(agentPublicKey);
|
|
87
|
+
this.agentName = agentName || '';
|
|
88
|
+
}
|
|
83
89
|
/**
|
|
84
90
|
* Get the wallet address
|
|
85
91
|
*/
|
|
@@ -2,7 +2,7 @@ import type { Meta, AssetCtx, ClearinghouseState, UserFills, CandleSnapshot, All
|
|
|
2
2
|
export interface InfoClientConfig {
|
|
3
3
|
isTestnet?: boolean;
|
|
4
4
|
timeout?: number;
|
|
5
|
-
masterAddress
|
|
5
|
+
masterAddress?: string;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Client for querying Hyperliquid info endpoints (perpetuals only)
|
|
@@ -10,7 +10,7 @@ export interface InfoClientConfig {
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class InfoClient {
|
|
12
12
|
private readonly httpClient;
|
|
13
|
-
private
|
|
13
|
+
private masterAddress?;
|
|
14
14
|
private metaAndAssetCtxsCache;
|
|
15
15
|
private metaAndAssetCtxsInFlight;
|
|
16
16
|
constructor(config: InfoClientConfig);
|
|
@@ -18,6 +18,7 @@ export declare class InfoClient {
|
|
|
18
18
|
* Get all mid prices for all assets
|
|
19
19
|
*/
|
|
20
20
|
getAllMids(): Promise<AllMids>;
|
|
21
|
+
initMasterAddress(masterAddress: string): void;
|
|
21
22
|
/**
|
|
22
23
|
* Get metadata and asset contexts
|
|
23
24
|
*/
|
|
@@ -36,6 +36,9 @@ class InfoClient {
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
initMasterAddress(masterAddress) {
|
|
40
|
+
this.masterAddress = masterAddress;
|
|
41
|
+
}
|
|
39
42
|
/**
|
|
40
43
|
* Get metadata and asset contexts
|
|
41
44
|
*/
|
|
@@ -65,18 +68,26 @@ class InfoClient {
|
|
|
65
68
|
}
|
|
66
69
|
getClearingHouseState(address) {
|
|
67
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const user = address || this.masterAddress;
|
|
72
|
+
if (!user) {
|
|
73
|
+
throw new Error('user address is empty');
|
|
74
|
+
}
|
|
68
75
|
return this.httpClient.info({
|
|
69
76
|
type: constants_1.InfoType.CLEARINGHOUSE_STATE,
|
|
70
|
-
user
|
|
77
|
+
user,
|
|
71
78
|
});
|
|
72
79
|
});
|
|
73
80
|
}
|
|
74
81
|
// frontendOpenOrders
|
|
75
82
|
getFrontendOpenOrders(address) {
|
|
76
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const user = address || this.masterAddress;
|
|
85
|
+
if (!user) {
|
|
86
|
+
throw new Error('user address is empty');
|
|
87
|
+
}
|
|
77
88
|
return this.httpClient.info({
|
|
78
89
|
type: constants_1.InfoType.FRONTEND_OPEN_ORDERS,
|
|
79
|
-
user
|
|
90
|
+
user,
|
|
80
91
|
});
|
|
81
92
|
});
|
|
82
93
|
}
|
|
@@ -89,9 +100,13 @@ class InfoClient {
|
|
|
89
100
|
// }
|
|
90
101
|
getUserNonFundingLedgerUpdates(address, startTime, endTime) {
|
|
91
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const user = address || this.masterAddress;
|
|
104
|
+
if (!user) {
|
|
105
|
+
throw new Error('user address is empty');
|
|
106
|
+
}
|
|
92
107
|
return this.httpClient.info({
|
|
93
108
|
type: constants_1.InfoType.USER_NON_FUNDING_LEDGER_UPDATES,
|
|
94
|
-
user
|
|
109
|
+
user,
|
|
95
110
|
startTime: startTime || 0,
|
|
96
111
|
endTime,
|
|
97
112
|
});
|
|
@@ -102,9 +117,13 @@ class InfoClient {
|
|
|
102
117
|
*/
|
|
103
118
|
getUserFills(address, aggregateByTime) {
|
|
104
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const user = address || this.masterAddress;
|
|
121
|
+
if (!user) {
|
|
122
|
+
throw new Error('user address is empty');
|
|
123
|
+
}
|
|
105
124
|
return this.httpClient.info({
|
|
106
125
|
type: constants_1.InfoType.USER_FILLS,
|
|
107
|
-
user
|
|
126
|
+
user,
|
|
108
127
|
aggregateByTime: aggregateByTime || true,
|
|
109
128
|
});
|
|
110
129
|
});
|
|
@@ -114,9 +133,13 @@ class InfoClient {
|
|
|
114
133
|
*/
|
|
115
134
|
getUserHistoricalOrders(address, startTime, endTime) {
|
|
116
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const user = address || this.masterAddress;
|
|
137
|
+
if (!user) {
|
|
138
|
+
throw new Error('user address is empty');
|
|
139
|
+
}
|
|
117
140
|
return this.httpClient.info({
|
|
118
141
|
type: constants_1.InfoType.USER_HISTORICAL_ORDERS,
|
|
119
|
-
user
|
|
142
|
+
user,
|
|
120
143
|
startTime: startTime || 0,
|
|
121
144
|
endTime,
|
|
122
145
|
});
|
|
@@ -147,9 +170,13 @@ class InfoClient {
|
|
|
147
170
|
*/
|
|
148
171
|
getMaxBuilderFee(builder, address) {
|
|
149
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
const user = address || this.masterAddress;
|
|
174
|
+
if (!user) {
|
|
175
|
+
throw new Error('user address is empty');
|
|
176
|
+
}
|
|
150
177
|
return this.httpClient.info({
|
|
151
178
|
type: constants_1.InfoType.MAX_BUILDER_FEE,
|
|
152
|
-
user
|
|
179
|
+
user,
|
|
153
180
|
builder,
|
|
154
181
|
});
|
|
155
182
|
});
|
|
@@ -159,9 +186,13 @@ class InfoClient {
|
|
|
159
186
|
*/
|
|
160
187
|
getUserRole(address) {
|
|
161
188
|
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
const user = address || this.masterAddress;
|
|
190
|
+
if (!user) {
|
|
191
|
+
throw new Error('user address is empty');
|
|
192
|
+
}
|
|
162
193
|
const res = yield this.httpClient.info({
|
|
163
194
|
type: constants_1.InfoType.USER_ROLE,
|
|
164
|
-
user
|
|
195
|
+
user,
|
|
165
196
|
});
|
|
166
197
|
return res;
|
|
167
198
|
});
|
|
@@ -171,9 +202,13 @@ class InfoClient {
|
|
|
171
202
|
*/
|
|
172
203
|
getUsersFees(address) {
|
|
173
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const user = address || this.masterAddress;
|
|
206
|
+
if (!user) {
|
|
207
|
+
throw new Error('user address is empty');
|
|
208
|
+
}
|
|
174
209
|
const res = yield this.httpClient.info({
|
|
175
210
|
type: constants_1.InfoType.USER_FEES,
|
|
176
|
-
user
|
|
211
|
+
user,
|
|
177
212
|
});
|
|
178
213
|
// const perpFee = Number(res.userCrossRate) * (1 - Number(res.activeReferralDiscount));
|
|
179
214
|
return res;
|
|
@@ -184,9 +219,13 @@ class InfoClient {
|
|
|
184
219
|
*/
|
|
185
220
|
extraAgents(address) {
|
|
186
221
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
const user = address || this.masterAddress;
|
|
223
|
+
if (!user) {
|
|
224
|
+
throw new Error('user address is empty');
|
|
225
|
+
}
|
|
187
226
|
return this.httpClient.info({
|
|
188
227
|
type: constants_1.InfoType.EXTRA_AGENTS,
|
|
189
|
-
user
|
|
228
|
+
user,
|
|
190
229
|
});
|
|
191
230
|
});
|
|
192
231
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AllMids, L2Book, Candle, WsOrder, WebData2, WsActiveAssetCtx, WsUserFills } from '../types';
|
|
2
2
|
export interface WebSocketClientConfig {
|
|
3
|
-
masterAddress
|
|
3
|
+
masterAddress?: string;
|
|
4
4
|
isTestnet?: boolean;
|
|
5
5
|
autoReconnect?: boolean;
|
|
6
6
|
reconnectDelay?: number;
|
|
@@ -22,6 +22,7 @@ export declare class WebSocketClient {
|
|
|
22
22
|
private isConnecting;
|
|
23
23
|
private pendingSubscriptions;
|
|
24
24
|
constructor(config: WebSocketClientConfig);
|
|
25
|
+
initMasterAddress(masterAddress: string): void;
|
|
25
26
|
/**
|
|
26
27
|
* Connect to the WebSocket
|
|
27
28
|
*/
|
|
@@ -21,9 +21,18 @@ class WebSocketClient {
|
|
|
21
21
|
this.reconnectAttempts = 0;
|
|
22
22
|
this.isConnecting = false;
|
|
23
23
|
this.pendingSubscriptions = [];
|
|
24
|
-
this.config =
|
|
24
|
+
this.config = {
|
|
25
|
+
isTestnet: false,
|
|
26
|
+
autoReconnect: true,
|
|
27
|
+
reconnectDelay: 3000,
|
|
28
|
+
maxReconnectAttempts: 5,
|
|
29
|
+
masterAddress: config.masterAddress || '',
|
|
30
|
+
};
|
|
25
31
|
this.url = this.config.isTestnet ? constants_1.WSS_URLS.TESTNET : constants_1.WSS_URLS.PRODUCTION;
|
|
26
32
|
}
|
|
33
|
+
initMasterAddress(masterAddress) {
|
|
34
|
+
this.config.masterAddress = masterAddress;
|
|
35
|
+
}
|
|
27
36
|
/**
|
|
28
37
|
* Connect to the WebSocket
|
|
29
38
|
*/
|
|
@@ -183,6 +192,9 @@ class WebSocketClient {
|
|
|
183
192
|
* Subscribe to user fills
|
|
184
193
|
*/
|
|
185
194
|
subscribeToUserFills(callback) {
|
|
195
|
+
if (!this.config.masterAddress) {
|
|
196
|
+
throw new Error('masterAddress is empty');
|
|
197
|
+
}
|
|
186
198
|
return this.subscribe({
|
|
187
199
|
subscription: { type: 'userFills', user: this.config.masterAddress, aggregateByTime: true },
|
|
188
200
|
}, callback);
|
|
@@ -191,6 +203,9 @@ class WebSocketClient {
|
|
|
191
203
|
* Subscribe to user order updates
|
|
192
204
|
*/
|
|
193
205
|
subscribeToUserOrders(callback) {
|
|
206
|
+
if (!this.config.masterAddress) {
|
|
207
|
+
throw new Error('masterAddress is empty');
|
|
208
|
+
}
|
|
194
209
|
return this.subscribe({
|
|
195
210
|
subscription: { type: 'orderUpdates', user: this.config.masterAddress },
|
|
196
211
|
}, callback);
|
|
@@ -199,6 +214,9 @@ class WebSocketClient {
|
|
|
199
214
|
* Subscribe to user funding updates
|
|
200
215
|
*/
|
|
201
216
|
subscribeToUserFunding(callback) {
|
|
217
|
+
if (!this.config.masterAddress) {
|
|
218
|
+
throw new Error('masterAddress is empty');
|
|
219
|
+
}
|
|
202
220
|
return this.subscribe({
|
|
203
221
|
subscription: { type: 'userFundings', user: this.config.masterAddress },
|
|
204
222
|
}, callback);
|
|
@@ -208,6 +226,9 @@ class WebSocketClient {
|
|
|
208
226
|
* Includes positions, margin summary, open orders, and other user data
|
|
209
227
|
*/
|
|
210
228
|
subscribeToWebData2(callback) {
|
|
229
|
+
if (!this.config.masterAddress) {
|
|
230
|
+
throw new Error('masterAddress is empty');
|
|
231
|
+
}
|
|
211
232
|
return this.subscribe({
|
|
212
233
|
subscription: { type: 'webData2', user: this.config.masterAddress },
|
|
213
234
|
}, callback);
|
|
@@ -4,7 +4,7 @@ import type { ClearinghouseState } from './types';
|
|
|
4
4
|
import { WebSocketClient, WebSocketClientConfig } from './client/websocket-client';
|
|
5
5
|
import { SymbolConversion } from './client/symbolConversion';
|
|
6
6
|
export interface HyperliquidSDKConfig {
|
|
7
|
-
masterAddress
|
|
7
|
+
masterAddress?: string;
|
|
8
8
|
agentPrivateKey?: string;
|
|
9
9
|
agentPublicKey?: string;
|
|
10
10
|
agentName?: string;
|
|
@@ -22,14 +22,14 @@ export declare class HyperliquidSDK {
|
|
|
22
22
|
exchange?: ExchangeClient;
|
|
23
23
|
symbolConversion: SymbolConversion;
|
|
24
24
|
readonly ws: WebSocketClient;
|
|
25
|
-
private readonly masterAddress
|
|
25
|
+
private readonly masterAddress?;
|
|
26
26
|
private readonly configParams;
|
|
27
27
|
constructor(config: HyperliquidSDKConfig);
|
|
28
28
|
/**
|
|
29
29
|
* Get wallet address (only available if private key was provided)
|
|
30
30
|
*/
|
|
31
31
|
get address(): string;
|
|
32
|
-
|
|
32
|
+
initAccount(masterAddress: string, agentPrivateKey: string, agentPublicKey: string, agentName?: string): void;
|
|
33
33
|
/**
|
|
34
34
|
* Connect to WebSocket for real-time data
|
|
35
35
|
*/
|
package/dist/hyperliquid-sdk.js
CHANGED
|
@@ -33,7 +33,7 @@ class HyperliquidSDK {
|
|
|
33
33
|
this.masterAddress = config.masterAddress;
|
|
34
34
|
this.configParams = config;
|
|
35
35
|
// Initialize exchange client only if private key is provided
|
|
36
|
-
if (config.
|
|
36
|
+
if (config.masterAddress) {
|
|
37
37
|
this.exchange = new exchange_client_1.ExchangeClient({
|
|
38
38
|
masterAddress: config.masterAddress,
|
|
39
39
|
agentPrivateKey: config.agentPrivateKey,
|
|
@@ -51,12 +51,25 @@ class HyperliquidSDK {
|
|
|
51
51
|
* Get wallet address (only available if private key was provided)
|
|
52
52
|
*/
|
|
53
53
|
get address() {
|
|
54
|
-
return this.masterAddress;
|
|
54
|
+
return this.masterAddress || '';
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
initAccount(masterAddress, agentPrivateKey, agentPublicKey, agentName) {
|
|
57
|
+
this.info.initMasterAddress(masterAddress);
|
|
58
|
+
this.ws.initMasterAddress(masterAddress);
|
|
59
|
+
if (this.exchange) {
|
|
60
|
+
this.exchange.initAccount(masterAddress, agentPrivateKey, agentPublicKey, agentName);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.exchange = new exchange_client_1.ExchangeClient({
|
|
64
|
+
masterAddress,
|
|
65
|
+
symbolConversion: this.symbolConversion,
|
|
66
|
+
agentPrivateKey,
|
|
67
|
+
agentPublicKey,
|
|
68
|
+
agentName,
|
|
69
|
+
isTestnet: this.configParams.isTestnet,
|
|
70
|
+
timeout: this.configParams.timeout,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
60
73
|
}
|
|
61
74
|
/**
|
|
62
75
|
* Connect to WebSocket for real-time data
|
package/package.json
CHANGED