@rabby-wallet/hyperliquid-sdk 1.0.0-beta.5 → 1.0.0-beta.7
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
CHANGED
|
@@ -32,8 +32,10 @@ const sdk = new HyperliquidSDK({
|
|
|
32
32
|
// 获取所有中间价
|
|
33
33
|
const prices = await sdk.info.getAllMids();
|
|
34
34
|
|
|
35
|
-
// 获取市场元数据与资产上下文
|
|
36
|
-
const
|
|
35
|
+
// 获取市场元数据与资产上下文
|
|
36
|
+
const canUseCache = true; //默认使用缓存,多次请求并发去重 ,需要刷新传false
|
|
37
|
+
const [meta, assetCtxs] = await sdk.info.metaAndAssetCtxs(canUseCache);
|
|
38
|
+
|
|
37
39
|
|
|
38
40
|
// 获取账户综合状态
|
|
39
41
|
const account = await sdk.info.getClearingHouseState();
|
|
@@ -11,6 +11,8 @@ export interface InfoClientConfig {
|
|
|
11
11
|
export declare class InfoClient {
|
|
12
12
|
private readonly httpClient;
|
|
13
13
|
private readonly masterAddress;
|
|
14
|
+
private metaAndAssetCtxsCache;
|
|
15
|
+
private metaAndAssetCtxsInFlight;
|
|
14
16
|
constructor(config: InfoClientConfig);
|
|
15
17
|
/**
|
|
16
18
|
* Get all mid prices for all assets
|
|
@@ -19,7 +21,7 @@ export declare class InfoClient {
|
|
|
19
21
|
/**
|
|
20
22
|
* Get metadata and asset contexts
|
|
21
23
|
*/
|
|
22
|
-
metaAndAssetCtxs(): Promise<[Meta, AssetCtx[]]>;
|
|
24
|
+
metaAndAssetCtxs(canUseCache?: boolean): Promise<[Meta, AssetCtx[]]>;
|
|
23
25
|
getClearingHouseState(address?: string): Promise<ClearinghouseState>;
|
|
24
26
|
getFrontendOpenOrders(address?: string): Promise<OpenOrder[]>;
|
|
25
27
|
getUserNonFundingLedgerUpdates(address?: string, startTime?: number, endTime?: number): Promise<UserNonFundingLedgerUpdates[]>;
|
|
@@ -18,6 +18,8 @@ const constants_1 = require("../types/constants");
|
|
|
18
18
|
*/
|
|
19
19
|
class InfoClient {
|
|
20
20
|
constructor(config) {
|
|
21
|
+
this.metaAndAssetCtxsCache = null;
|
|
22
|
+
this.metaAndAssetCtxsInFlight = null;
|
|
21
23
|
this.masterAddress = config.masterAddress;
|
|
22
24
|
this.httpClient = new http_client_1.HttpClient({
|
|
23
25
|
isTestnet: config.isTestnet,
|
|
@@ -38,10 +40,27 @@ class InfoClient {
|
|
|
38
40
|
* Get metadata and asset contexts
|
|
39
41
|
*/
|
|
40
42
|
metaAndAssetCtxs() {
|
|
41
|
-
return __awaiter(this,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
43
|
+
return __awaiter(this, arguments, void 0, function* (canUseCache = true) {
|
|
44
|
+
if (canUseCache && this.metaAndAssetCtxsCache) {
|
|
45
|
+
return this.metaAndAssetCtxsCache;
|
|
46
|
+
}
|
|
47
|
+
// De-duplicate concurrent requests
|
|
48
|
+
if (this.metaAndAssetCtxsInFlight) {
|
|
49
|
+
return this.metaAndAssetCtxsInFlight;
|
|
50
|
+
}
|
|
51
|
+
this.metaAndAssetCtxsInFlight = (() => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
const [meta, assetCtxs] = yield this.httpClient.info({
|
|
54
|
+
type: constants_1.InfoType.META_AND_ASSET_CTXS,
|
|
55
|
+
});
|
|
56
|
+
this.metaAndAssetCtxsCache = [meta, assetCtxs];
|
|
57
|
+
return [meta, assetCtxs];
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
this.metaAndAssetCtxsInFlight = null;
|
|
61
|
+
}
|
|
62
|
+
}))();
|
|
63
|
+
return this.metaAndAssetCtxsInFlight;
|
|
45
64
|
});
|
|
46
65
|
}
|
|
47
66
|
getClearingHouseState(address) {
|
|
@@ -191,7 +191,7 @@ class WebSocketClient {
|
|
|
191
191
|
*/
|
|
192
192
|
subscribeToUserOrders(callback) {
|
|
193
193
|
return this.subscribe({
|
|
194
|
-
subscription: { type: '
|
|
194
|
+
subscription: { type: 'orderUpdates', user: this.config.masterAddress },
|
|
195
195
|
}, callback);
|
|
196
196
|
}
|
|
197
197
|
/**
|
package/dist/hyperliquid-sdk.js
CHANGED
|
@@ -87,18 +87,5 @@ class HyperliquidSDK {
|
|
|
87
87
|
return this.info.getClearingHouseState();
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Quick helper: Get market overview
|
|
92
|
-
*/
|
|
93
|
-
getMarketOverview() {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
const [meta, assetCtxs] = yield this.info.metaAndAssetCtxs();
|
|
96
|
-
return {
|
|
97
|
-
assets: meta.universe,
|
|
98
|
-
assetContexts: assetCtxs,
|
|
99
|
-
marginTables: meta.marginTables,
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
90
|
}
|
|
104
91
|
exports.HyperliquidSDK = HyperliquidSDK;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ export type TriggerType = 'tp' | 'sl';
|
|
|
4
4
|
export type Side = 'A' | 'B';
|
|
5
5
|
export type AssetId = number;
|
|
6
6
|
export type OrderId = number;
|
|
7
|
+
export interface MarketOverview {
|
|
8
|
+
assets: AssetInfo[];
|
|
9
|
+
assetContexts: AssetCtx[];
|
|
10
|
+
marginTables: [number, MarginTable][];
|
|
11
|
+
}
|
|
7
12
|
export interface OpenOrder {
|
|
8
13
|
coin: string;
|
|
9
14
|
side: Side;
|
|
@@ -52,6 +57,7 @@ export type OrderType = LimitOrderType | MarketOrderType | StopOrderType;
|
|
|
52
57
|
export interface AssetInfo {
|
|
53
58
|
name: string;
|
|
54
59
|
szDecimals: number;
|
|
60
|
+
marginTableId: number;
|
|
55
61
|
maxLeverage: number;
|
|
56
62
|
onlyIsolated?: boolean;
|
|
57
63
|
isDelisted?: boolean;
|
|
@@ -151,6 +157,7 @@ export interface OrderResponse {
|
|
|
151
157
|
filled?: {
|
|
152
158
|
totalSz: string;
|
|
153
159
|
avgPx: string;
|
|
160
|
+
oid: number;
|
|
154
161
|
};
|
|
155
162
|
error?: string;
|
|
156
163
|
}>;
|
|
@@ -219,6 +226,7 @@ export interface WsFill {
|
|
|
219
226
|
tid: number;
|
|
220
227
|
}
|
|
221
228
|
export interface AssetCtx {
|
|
229
|
+
dayBaseVlm: string;
|
|
222
230
|
dayNtlVlm: string;
|
|
223
231
|
funding: string;
|
|
224
232
|
impactPxs: [string, string];
|
package/package.json
CHANGED