@rabby-wallet/hyperliquid-sdk 1.0.0-beta.17 → 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 +8 -3
- package/dist/client/info-client.js +60 -8
- 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/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.js +1 -0
- package/dist/types/index.d.ts +27 -0
- 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
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Meta, AssetCtx, ClearinghouseState, UserFills, CandleSnapshot, AllMids, ExtraAgent, OpenOrder, FeeResponse, UserNonFundingLedgerUpdates } from '../types';
|
|
1
|
+
import type { Meta, AssetCtx, ClearinghouseState, UserFills, CandleSnapshot, AllMids, ExtraAgent, OpenOrder, FeeResponse, UserNonFundingLedgerUpdates, UserHistoricalOrders } from '../types';
|
|
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
|
*/
|
|
@@ -29,6 +30,10 @@ export declare class InfoClient {
|
|
|
29
30
|
* Get user's fill history
|
|
30
31
|
*/
|
|
31
32
|
getUserFills(address?: string, aggregateByTime?: boolean): Promise<UserFills>;
|
|
33
|
+
/**
|
|
34
|
+
* Get user's fill and cancel and other all orders history
|
|
35
|
+
*/
|
|
36
|
+
getUserHistoricalOrders(address?: string, startTime?: number, endTime?: number): Promise<UserHistoricalOrders[]>;
|
|
32
37
|
/**
|
|
33
38
|
* Get candlestick data snapshot
|
|
34
39
|
* Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
|
|
@@ -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,13 +117,34 @@ 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
|
});
|
|
111
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Get user's fill and cancel and other all orders history
|
|
133
|
+
*/
|
|
134
|
+
getUserHistoricalOrders(address, startTime, endTime) {
|
|
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
|
+
}
|
|
140
|
+
return this.httpClient.info({
|
|
141
|
+
type: constants_1.InfoType.USER_HISTORICAL_ORDERS,
|
|
142
|
+
user,
|
|
143
|
+
startTime: startTime || 0,
|
|
144
|
+
endTime,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
112
148
|
/**
|
|
113
149
|
* Get candlestick data snapshot
|
|
114
150
|
* Supported intervals: "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "8h", "12h", "1d", "3d", "1w", "1M"
|
|
@@ -134,9 +170,13 @@ class InfoClient {
|
|
|
134
170
|
*/
|
|
135
171
|
getMaxBuilderFee(builder, address) {
|
|
136
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
|
+
}
|
|
137
177
|
return this.httpClient.info({
|
|
138
178
|
type: constants_1.InfoType.MAX_BUILDER_FEE,
|
|
139
|
-
user
|
|
179
|
+
user,
|
|
140
180
|
builder,
|
|
141
181
|
});
|
|
142
182
|
});
|
|
@@ -146,9 +186,13 @@ class InfoClient {
|
|
|
146
186
|
*/
|
|
147
187
|
getUserRole(address) {
|
|
148
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
|
+
}
|
|
149
193
|
const res = yield this.httpClient.info({
|
|
150
194
|
type: constants_1.InfoType.USER_ROLE,
|
|
151
|
-
user
|
|
195
|
+
user,
|
|
152
196
|
});
|
|
153
197
|
return res;
|
|
154
198
|
});
|
|
@@ -158,9 +202,13 @@ class InfoClient {
|
|
|
158
202
|
*/
|
|
159
203
|
getUsersFees(address) {
|
|
160
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
|
+
}
|
|
161
209
|
const res = yield this.httpClient.info({
|
|
162
210
|
type: constants_1.InfoType.USER_FEES,
|
|
163
|
-
user
|
|
211
|
+
user,
|
|
164
212
|
});
|
|
165
213
|
// const perpFee = Number(res.userCrossRate) * (1 - Number(res.activeReferralDiscount));
|
|
166
214
|
return res;
|
|
@@ -171,9 +219,13 @@ class InfoClient {
|
|
|
171
219
|
*/
|
|
172
220
|
extraAgents(address) {
|
|
173
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
|
+
}
|
|
174
226
|
return this.httpClient.info({
|
|
175
227
|
type: constants_1.InfoType.EXTRA_AGENTS,
|
|
176
|
-
user
|
|
228
|
+
user,
|
|
177
229
|
});
|
|
178
230
|
});
|
|
179
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
|
|
@@ -28,6 +28,7 @@ export declare enum ExchangeType {
|
|
|
28
28
|
export declare enum InfoType {
|
|
29
29
|
ALL_MIDS = "allMids",
|
|
30
30
|
USER_NON_FUNDING_LEDGER_UPDATES = "userNonFundingLedgerUpdates",
|
|
31
|
+
USER_HISTORICAL_ORDERS = "historicalOrders",
|
|
31
32
|
USER_OPEN_ORDERS = "openOrders",
|
|
32
33
|
USER_FILLS = "userFills",
|
|
33
34
|
USER_FILLS_BY_TIME = "userFillsByTime",
|
package/dist/types/constants.js
CHANGED
|
@@ -36,6 +36,7 @@ var InfoType;
|
|
|
36
36
|
(function (InfoType) {
|
|
37
37
|
InfoType["ALL_MIDS"] = "allMids";
|
|
38
38
|
InfoType["USER_NON_FUNDING_LEDGER_UPDATES"] = "userNonFundingLedgerUpdates";
|
|
39
|
+
InfoType["USER_HISTORICAL_ORDERS"] = "historicalOrders";
|
|
39
40
|
InfoType["USER_OPEN_ORDERS"] = "openOrders";
|
|
40
41
|
InfoType["USER_FILLS"] = "userFills";
|
|
41
42
|
InfoType["USER_FILLS_BY_TIME"] = "userFillsByTime";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,6 +9,28 @@ export interface MarketOverview {
|
|
|
9
9
|
assetContexts: AssetCtx[];
|
|
10
10
|
marginTables: [number, MarginTable][];
|
|
11
11
|
}
|
|
12
|
+
export interface UserHistoricalOrders {
|
|
13
|
+
order: {
|
|
14
|
+
coin: string;
|
|
15
|
+
side: Side;
|
|
16
|
+
limitPx: string;
|
|
17
|
+
sz: string;
|
|
18
|
+
oid: number;
|
|
19
|
+
timestamp: number;
|
|
20
|
+
triggerCondition: string;
|
|
21
|
+
isTrigger: boolean;
|
|
22
|
+
triggerPx: string;
|
|
23
|
+
children: any;
|
|
24
|
+
isPositionTpsl: boolean;
|
|
25
|
+
reduceOnly: boolean;
|
|
26
|
+
orderType: string;
|
|
27
|
+
origSz: string;
|
|
28
|
+
tif: string;
|
|
29
|
+
cloid: string | null;
|
|
30
|
+
};
|
|
31
|
+
status: string;
|
|
32
|
+
statusTimestamp: number;
|
|
33
|
+
}
|
|
12
34
|
export interface OpenOrder {
|
|
13
35
|
coin: string;
|
|
14
36
|
side: Side;
|
|
@@ -229,6 +251,11 @@ export interface WsFill {
|
|
|
229
251
|
crossed: boolean;
|
|
230
252
|
fee: string;
|
|
231
253
|
tid: number;
|
|
254
|
+
liquidation?: {
|
|
255
|
+
liquidatedUser: string;
|
|
256
|
+
markPx: string;
|
|
257
|
+
method: string;
|
|
258
|
+
};
|
|
232
259
|
}
|
|
233
260
|
export interface AssetCtx {
|
|
234
261
|
dayBaseVlm: string;
|
package/package.json
CHANGED