openbroker 1.3.2 → 1.4.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/CHANGELOG.md +12 -0
- package/dist/auto/audit.d.ts +57 -0
- package/dist/auto/audit.d.ts.map +1 -0
- package/dist/auto/audit.js +407 -0
- package/dist/auto/cli.d.ts +2 -0
- package/dist/auto/cli.d.ts.map +1 -0
- package/dist/auto/cli.js +423 -0
- package/dist/auto/events.d.ts +11 -0
- package/dist/auto/events.d.ts.map +1 -0
- package/dist/auto/events.js +36 -0
- package/dist/auto/examples/dca.d.ts +4 -0
- package/dist/auto/examples/dca.d.ts.map +1 -0
- package/dist/auto/examples/dca.js +60 -0
- package/dist/auto/examples/funding-arb.d.ts +4 -0
- package/dist/auto/examples/funding-arb.d.ts.map +1 -0
- package/dist/auto/examples/funding-arb.js +81 -0
- package/dist/auto/examples/grid.d.ts +4 -0
- package/dist/auto/examples/grid.d.ts.map +1 -0
- package/dist/auto/examples/grid.js +114 -0
- package/dist/auto/examples/mm-maker.d.ts +4 -0
- package/dist/auto/examples/mm-maker.d.ts.map +1 -0
- package/dist/auto/examples/mm-maker.js +131 -0
- package/dist/auto/examples/mm-spread.d.ts +4 -0
- package/dist/auto/examples/mm-spread.d.ts.map +1 -0
- package/dist/auto/examples/mm-spread.js +119 -0
- package/dist/auto/examples/price-alert.d.ts +4 -0
- package/dist/auto/examples/price-alert.d.ts.map +1 -0
- package/dist/auto/examples/price-alert.js +85 -0
- package/dist/auto/keep-awake.d.ts +11 -0
- package/dist/auto/keep-awake.d.ts.map +1 -0
- package/dist/auto/keep-awake.js +70 -0
- package/dist/auto/loader.d.ts +22 -0
- package/dist/auto/loader.d.ts.map +1 -0
- package/dist/auto/loader.js +127 -0
- package/dist/auto/prune.d.ts +40 -0
- package/dist/auto/prune.d.ts.map +1 -0
- package/dist/auto/prune.js +204 -0
- package/dist/auto/registry.d.ts +24 -0
- package/dist/auto/registry.d.ts.map +1 -0
- package/dist/auto/registry.js +93 -0
- package/dist/auto/report.d.ts +3 -0
- package/dist/auto/report.d.ts.map +1 -0
- package/dist/auto/report.js +385 -0
- package/dist/auto/runtime.d.ts +33 -0
- package/dist/auto/runtime.d.ts.map +1 -0
- package/dist/auto/runtime.js +844 -0
- package/dist/auto/types.d.ts +236 -0
- package/dist/auto/types.d.ts.map +1 -0
- package/dist/auto/types.js +3 -0
- package/dist/core/client.d.ts +684 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +2040 -0
- package/dist/core/config.d.ts +22 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +143 -0
- package/dist/core/types.d.ts +221 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/utils.d.ts +61 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +142 -0
- package/dist/core/ws.d.ts +121 -0
- package/dist/core/ws.d.ts.map +1 -0
- package/dist/core/ws.js +222 -0
- package/dist/info/account.d.ts +3 -0
- package/dist/info/account.d.ts.map +1 -0
- package/dist/info/account.js +198 -0
- package/dist/info/all-markets.d.ts +3 -0
- package/dist/info/all-markets.d.ts.map +1 -0
- package/dist/info/all-markets.js +272 -0
- package/dist/info/candles.d.ts +3 -0
- package/dist/info/candles.d.ts.map +1 -0
- package/dist/info/candles.js +120 -0
- package/dist/info/fees.d.ts +3 -0
- package/dist/info/fees.d.ts.map +1 -0
- package/dist/info/fees.js +87 -0
- package/dist/info/fills.d.ts +3 -0
- package/dist/info/fills.d.ts.map +1 -0
- package/dist/info/fills.js +105 -0
- package/dist/info/funding-history.d.ts +3 -0
- package/dist/info/funding-history.d.ts.map +1 -0
- package/dist/info/funding-history.js +98 -0
- package/dist/info/funding-scan.d.ts +3 -0
- package/dist/info/funding-scan.d.ts.map +1 -0
- package/dist/info/funding-scan.js +178 -0
- package/dist/info/funding.d.ts +3 -0
- package/dist/info/funding.d.ts.map +1 -0
- package/dist/info/funding.js +158 -0
- package/dist/info/markets.d.ts +3 -0
- package/dist/info/markets.d.ts.map +1 -0
- package/dist/info/markets.js +178 -0
- package/dist/info/order-status.d.ts +3 -0
- package/dist/info/order-status.d.ts.map +1 -0
- package/dist/info/order-status.js +85 -0
- package/dist/info/orders.d.ts +3 -0
- package/dist/info/orders.d.ts.map +1 -0
- package/dist/info/orders.js +162 -0
- package/dist/info/outcomes.d.ts +3 -0
- package/dist/info/outcomes.d.ts.map +1 -0
- package/dist/info/outcomes.js +175 -0
- package/dist/info/positions.d.ts +3 -0
- package/dist/info/positions.d.ts.map +1 -0
- package/dist/info/positions.js +127 -0
- package/dist/info/rate-limit.d.ts +3 -0
- package/dist/info/rate-limit.d.ts.map +1 -0
- package/dist/info/rate-limit.js +58 -0
- package/dist/info/search-markets.d.ts +3 -0
- package/dist/info/search-markets.d.ts.map +1 -0
- package/dist/info/search-markets.js +296 -0
- package/dist/info/spot.d.ts +3 -0
- package/dist/info/spot.d.ts.map +1 -0
- package/dist/info/spot.js +192 -0
- package/dist/info/trades.d.ts +3 -0
- package/dist/info/trades.d.ts.map +1 -0
- package/dist/info/trades.js +97 -0
- package/dist/lib.d.ts +14 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +17 -0
- package/dist/operations/bracket.d.ts +28 -0
- package/dist/operations/bracket.d.ts.map +1 -0
- package/dist/operations/bracket.js +266 -0
- package/dist/operations/cancel.d.ts +3 -0
- package/dist/operations/cancel.d.ts.map +1 -0
- package/dist/operations/cancel.js +107 -0
- package/dist/operations/chase.d.ts +25 -0
- package/dist/operations/chase.d.ts.map +1 -0
- package/dist/operations/chase.js +215 -0
- package/dist/operations/limit-order.d.ts +3 -0
- package/dist/operations/limit-order.d.ts.map +1 -0
- package/dist/operations/limit-order.js +144 -0
- package/dist/operations/market-order.d.ts +3 -0
- package/dist/operations/market-order.d.ts.map +1 -0
- package/dist/operations/market-order.js +153 -0
- package/dist/operations/outcome-order.d.ts +3 -0
- package/dist/operations/outcome-order.d.ts.map +1 -0
- package/dist/operations/outcome-order.js +171 -0
- package/dist/operations/scale.d.ts +3 -0
- package/dist/operations/scale.d.ts.map +1 -0
- package/dist/operations/scale.js +212 -0
- package/dist/operations/set-tpsl.d.ts +3 -0
- package/dist/operations/set-tpsl.d.ts.map +1 -0
- package/dist/operations/set-tpsl.js +277 -0
- package/dist/operations/spot-order.d.ts +3 -0
- package/dist/operations/spot-order.d.ts.map +1 -0
- package/dist/operations/spot-order.js +173 -0
- package/dist/operations/trigger-order.d.ts +3 -0
- package/dist/operations/trigger-order.d.ts.map +1 -0
- package/dist/operations/trigger-order.js +177 -0
- package/dist/operations/twap-cancel.d.ts +3 -0
- package/dist/operations/twap-cancel.d.ts.map +1 -0
- package/dist/operations/twap-cancel.js +57 -0
- package/dist/operations/twap-status.d.ts +3 -0
- package/dist/operations/twap-status.d.ts.map +1 -0
- package/dist/operations/twap-status.js +81 -0
- package/dist/operations/twap.d.ts +3 -0
- package/dist/operations/twap.d.ts.map +1 -0
- package/dist/operations/twap.js +124 -0
- package/dist/setup/approve-builder.d.ts +3 -0
- package/dist/setup/approve-builder.d.ts.map +1 -0
- package/dist/setup/approve-builder.js +155 -0
- package/dist/setup/env.d.ts +4 -0
- package/dist/setup/env.d.ts.map +1 -0
- package/dist/setup/env.js +8 -0
- package/dist/setup/onboard.d.ts +10 -0
- package/dist/setup/onboard.d.ts.map +1 -0
- package/dist/setup/onboard.js +462 -0
- package/package.json +10 -4
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
import type { OpenBrokerConfig, BuilderInfo, OrderResponse, CancelResponse, MetaAndAssetCtxs, ClearinghouseState, OpenOrder, OutcomeMetaResponse, OutcomeMarket } from './types.js';
|
|
2
|
+
export declare class HyperliquidClient {
|
|
3
|
+
private config;
|
|
4
|
+
private account;
|
|
5
|
+
private transport;
|
|
6
|
+
private info;
|
|
7
|
+
private exchange;
|
|
8
|
+
private meta;
|
|
9
|
+
private assetMap;
|
|
10
|
+
private szDecimalsMap;
|
|
11
|
+
/** Maps coin name → dex info for HIP-3 assets. Main dex assets have dexName=null */
|
|
12
|
+
private coinDexMap;
|
|
13
|
+
/** Cache of perpDexs list */
|
|
14
|
+
private perpDexsCache;
|
|
15
|
+
/** Whether HIP-3 assets have been loaded into maps */
|
|
16
|
+
private hip3Loaded;
|
|
17
|
+
/** Whether API wallet setup has been validated */
|
|
18
|
+
private apiWalletValidated;
|
|
19
|
+
/** Set of HIP-3 dex names that have been loaded (for testnet on-demand loading) */
|
|
20
|
+
private loadedHip3Dexes;
|
|
21
|
+
/** HIP-3 assets that have had isolated margin set this session */
|
|
22
|
+
private hip3IsolatedSet;
|
|
23
|
+
/** Cached maxLeverage for HIP-3 assets */
|
|
24
|
+
private hip3MaxLeverageMap;
|
|
25
|
+
/** Cached account abstraction mode: 'standard' | 'unified' | 'portfolio' | 'dexAbstraction' */
|
|
26
|
+
private accountMode;
|
|
27
|
+
/** Spot asset index map: coin name → 10000 + spotMeta.universe[i].index */
|
|
28
|
+
private spotAssetMap;
|
|
29
|
+
/** Spot market key map: coin name → pair.name (e.g. "@230", "PURR/USDC") */
|
|
30
|
+
private spotPairNameMap;
|
|
31
|
+
/** Spot szDecimals map: coin name → base token szDecimals */
|
|
32
|
+
private spotSzDecimalsMap;
|
|
33
|
+
/** Whether spot metadata has been loaded */
|
|
34
|
+
private spotMetaLoaded;
|
|
35
|
+
/** HIP-4 outcome metadata cache */
|
|
36
|
+
private outcomeMeta;
|
|
37
|
+
verbose: boolean;
|
|
38
|
+
constructor(config?: OpenBrokerConfig);
|
|
39
|
+
private log;
|
|
40
|
+
private describeError;
|
|
41
|
+
/** Retry an async operation on transient failures (fetch failed, ECONNRESET, etc.) */
|
|
42
|
+
private withRetry;
|
|
43
|
+
private getTransportContext;
|
|
44
|
+
private postInfo;
|
|
45
|
+
/** The address we're trading on behalf of (may be different from wallet if using API wallet) */
|
|
46
|
+
get address(): string;
|
|
47
|
+
/** The address of the signing wallet (derived from private key) */
|
|
48
|
+
get walletAddress(): string;
|
|
49
|
+
/** Whether we're using an API wallet (signing wallet differs from trading account) */
|
|
50
|
+
get isApiWallet(): boolean;
|
|
51
|
+
get builderInfo(): BuilderInfo;
|
|
52
|
+
get builderAddress(): string;
|
|
53
|
+
get builderFeeBps(): number;
|
|
54
|
+
/** Whether client is in read-only mode (no trading capability) */
|
|
55
|
+
get isReadOnly(): boolean;
|
|
56
|
+
/** Whether connected to testnet (HIP-3 dexes not auto-loaded) */
|
|
57
|
+
get isTestnet(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Returns vaultAddress param for SDK exchange calls.
|
|
60
|
+
* Only used for vault trading (HYPERLIQUID_VAULT_ADDRESS set explicitly).
|
|
61
|
+
* Standard API wallets (agents) do NOT need this — the API maps agent → master automatically.
|
|
62
|
+
*/
|
|
63
|
+
private get vaultParam();
|
|
64
|
+
/** Throw error if trying to trade in read-only mode. Validates API wallet on first call. */
|
|
65
|
+
private requireTrading;
|
|
66
|
+
getMetaAndAssetCtxs(): Promise<MetaAndAssetCtxs>;
|
|
67
|
+
/**
|
|
68
|
+
* Load HIP-3 perp dex assets into the asset/szDecimals maps.
|
|
69
|
+
* Asset index formula: 100000 + dexIdx * 10000 + assetIdx
|
|
70
|
+
* Coins are keyed as "dexName:COIN" (e.g., "xyz:CL")
|
|
71
|
+
*/
|
|
72
|
+
/** Max concurrent HIP-3 API requests to avoid rate limiting */
|
|
73
|
+
private static readonly HIP3_CONCURRENCY;
|
|
74
|
+
/**
|
|
75
|
+
* Like Promise.allSettled but with a concurrency limit.
|
|
76
|
+
* Processes tasks in batches to avoid hitting API rate limits.
|
|
77
|
+
*/
|
|
78
|
+
private batchSettled;
|
|
79
|
+
/**
|
|
80
|
+
* Load HIP-3 perp dex assets into the asset/szDecimals maps.
|
|
81
|
+
* On testnet: skips auto-loading (too many junk dexes). Use loadSingleHip3Dex() on demand.
|
|
82
|
+
* On mainnet: loads all dexes with concurrency limit.
|
|
83
|
+
*/
|
|
84
|
+
private loadHip3Assets;
|
|
85
|
+
/**
|
|
86
|
+
* Load a single HIP-3 dex by name (on-demand, e.g. when user references "felix:BTC").
|
|
87
|
+
* No-op if already loaded.
|
|
88
|
+
*/
|
|
89
|
+
loadSingleHip3Dex(dexName: string): Promise<boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* Get HIP-3 dexes to iterate over for bulk queries.
|
|
92
|
+
* Mainnet: all dexes. Testnet: only explicitly loaded dexes.
|
|
93
|
+
*/
|
|
94
|
+
private getIterableHip3Dexs;
|
|
95
|
+
/** Register a fetched HIP-3 dex's assets into lookup maps */
|
|
96
|
+
private registerHip3Dex;
|
|
97
|
+
getAllMids(): Promise<Record<string, string>>;
|
|
98
|
+
/**
|
|
99
|
+
* Get all perpetual DEXs (including HIP-3 builder-deployed markets)
|
|
100
|
+
* Returns array where index 0 is null (main dex), others are HIP-3 dexs
|
|
101
|
+
*/
|
|
102
|
+
getPerpDexs(): Promise<Array<{
|
|
103
|
+
name: string;
|
|
104
|
+
fullName: string;
|
|
105
|
+
deployer: string;
|
|
106
|
+
} | null>>;
|
|
107
|
+
/**
|
|
108
|
+
* Get all perp markets including HIP-3 dexs
|
|
109
|
+
* Returns array of [meta, assetCtxs] for each dex
|
|
110
|
+
*/
|
|
111
|
+
getAllPerpMetas(): Promise<Array<{
|
|
112
|
+
dexName: string | null;
|
|
113
|
+
meta: {
|
|
114
|
+
universe: Array<{
|
|
115
|
+
name: string;
|
|
116
|
+
szDecimals: number;
|
|
117
|
+
maxLeverage: number;
|
|
118
|
+
onlyIsolated?: boolean;
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
assetCtxs: Array<{
|
|
122
|
+
funding: string;
|
|
123
|
+
openInterest: string;
|
|
124
|
+
markPx: string;
|
|
125
|
+
midPx: string | null;
|
|
126
|
+
oraclePx: string;
|
|
127
|
+
prevDayPx: string;
|
|
128
|
+
dayNtlVlm: string;
|
|
129
|
+
}>;
|
|
130
|
+
}>>;
|
|
131
|
+
/**
|
|
132
|
+
* Get spot market metadata
|
|
133
|
+
*/
|
|
134
|
+
getSpotMeta(): Promise<{
|
|
135
|
+
tokens: Array<{
|
|
136
|
+
name: string;
|
|
137
|
+
szDecimals: number;
|
|
138
|
+
weiDecimals: number;
|
|
139
|
+
index: number;
|
|
140
|
+
tokenId: string;
|
|
141
|
+
isCanonical: boolean;
|
|
142
|
+
fullName: string | null;
|
|
143
|
+
}>;
|
|
144
|
+
universe: Array<{
|
|
145
|
+
name: string;
|
|
146
|
+
tokens: [number, number];
|
|
147
|
+
index: number;
|
|
148
|
+
isCanonical: boolean;
|
|
149
|
+
}>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Get spot metadata with asset contexts (prices, volumes)
|
|
153
|
+
*/
|
|
154
|
+
getSpotMetaAndAssetCtxs(): Promise<{
|
|
155
|
+
meta: {
|
|
156
|
+
tokens: Array<{
|
|
157
|
+
name: string;
|
|
158
|
+
szDecimals: number;
|
|
159
|
+
weiDecimals: number;
|
|
160
|
+
index: number;
|
|
161
|
+
tokenId: string;
|
|
162
|
+
isCanonical: boolean;
|
|
163
|
+
}>;
|
|
164
|
+
universe: Array<{
|
|
165
|
+
name: string;
|
|
166
|
+
tokens: [number, number];
|
|
167
|
+
index: number;
|
|
168
|
+
isCanonical: boolean;
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
assetCtxs: Array<{
|
|
172
|
+
coin?: string;
|
|
173
|
+
dayNtlVlm: string;
|
|
174
|
+
markPx: string;
|
|
175
|
+
midPx: string;
|
|
176
|
+
prevDayPx: string;
|
|
177
|
+
}>;
|
|
178
|
+
}>;
|
|
179
|
+
private parseOutcomeDescription;
|
|
180
|
+
private normalizeOutcomeSide;
|
|
181
|
+
getOutcomeEncoding(outcome: number, side: 0 | 1): number;
|
|
182
|
+
getOutcomeCoin(outcome: number, side: 0 | 1): string;
|
|
183
|
+
getOutcomeAssetId(outcome: number, side: 0 | 1): number;
|
|
184
|
+
resolveOutcomeRef(ref: string | number, side?: string | number): {
|
|
185
|
+
outcome: number;
|
|
186
|
+
side: 0 | 1;
|
|
187
|
+
encoding: number;
|
|
188
|
+
coin: string;
|
|
189
|
+
tokenName: string;
|
|
190
|
+
assetId: number;
|
|
191
|
+
};
|
|
192
|
+
getOutcomeMeta(): Promise<OutcomeMetaResponse>;
|
|
193
|
+
private getOutcomeCtxMap;
|
|
194
|
+
getOutcomeMarkets(): Promise<OutcomeMarket[]>;
|
|
195
|
+
getOutcomeMarket(outcomeId: number): Promise<OutcomeMarket | null>;
|
|
196
|
+
getOutcomeSzDecimals(outcome: number, side: 0 | 1): Promise<number>;
|
|
197
|
+
getOutcomeMidPrice(outcome: number, side: 0 | 1): Promise<number>;
|
|
198
|
+
/**
|
|
199
|
+
* Load spot metadata into lookup maps.
|
|
200
|
+
* Spot asset index for orders = 10000 + universe[i].index
|
|
201
|
+
* Uses the base token's szDecimals for size rounding.
|
|
202
|
+
*/
|
|
203
|
+
private loadSpotMeta;
|
|
204
|
+
/** Get the spot asset index for a coin, or undefined if not a spot asset */
|
|
205
|
+
getSpotAssetIndex(coin: string): number | undefined;
|
|
206
|
+
/** Get the preferred spot market key for a coin (e.g. "@230", "PURR/USDC") */
|
|
207
|
+
getSpotMarketKey(coin: string): string | undefined;
|
|
208
|
+
/** Get spot szDecimals for a coin */
|
|
209
|
+
getSpotSzDecimals(coin: string): number | undefined;
|
|
210
|
+
/** Get all loaded spot asset names */
|
|
211
|
+
getSpotAssetNames(): string[];
|
|
212
|
+
/**
|
|
213
|
+
* Get user's spot token balances
|
|
214
|
+
*/
|
|
215
|
+
getSpotBalances(user?: string): Promise<{
|
|
216
|
+
balances: Array<{
|
|
217
|
+
coin: string;
|
|
218
|
+
token: number;
|
|
219
|
+
hold: string;
|
|
220
|
+
total: string;
|
|
221
|
+
entryNtl: string;
|
|
222
|
+
}>;
|
|
223
|
+
}>;
|
|
224
|
+
/**
|
|
225
|
+
* Get token details by token ID
|
|
226
|
+
*/
|
|
227
|
+
getTokenDetails(tokenId: string): Promise<{
|
|
228
|
+
name: string;
|
|
229
|
+
maxSupply: string;
|
|
230
|
+
totalSupply: string;
|
|
231
|
+
circulatingSupply: string;
|
|
232
|
+
szDecimals: number;
|
|
233
|
+
weiDecimals: number;
|
|
234
|
+
midPx: string;
|
|
235
|
+
markPx: string;
|
|
236
|
+
prevDayPx: string;
|
|
237
|
+
deployer: string;
|
|
238
|
+
deployTime: string;
|
|
239
|
+
} | null>;
|
|
240
|
+
/**
|
|
241
|
+
* Get predicted funding rates across venues
|
|
242
|
+
*/
|
|
243
|
+
getPredictedFundings(): Promise<Array<[
|
|
244
|
+
string,
|
|
245
|
+
Array<[string, {
|
|
246
|
+
fundingRate: string;
|
|
247
|
+
nextFundingTime: number;
|
|
248
|
+
}]>
|
|
249
|
+
]>>;
|
|
250
|
+
/**
|
|
251
|
+
* Get L2 order book for an asset
|
|
252
|
+
* Returns best bid/ask and depth
|
|
253
|
+
*/
|
|
254
|
+
getL2Book(coin: string): Promise<{
|
|
255
|
+
bids: Array<{
|
|
256
|
+
px: string;
|
|
257
|
+
sz: string;
|
|
258
|
+
n: number;
|
|
259
|
+
}>;
|
|
260
|
+
asks: Array<{
|
|
261
|
+
px: string;
|
|
262
|
+
sz: string;
|
|
263
|
+
n: number;
|
|
264
|
+
}>;
|
|
265
|
+
bestBid: number;
|
|
266
|
+
bestAsk: number;
|
|
267
|
+
midPrice: number;
|
|
268
|
+
spread: number;
|
|
269
|
+
spreadBps: number;
|
|
270
|
+
}>;
|
|
271
|
+
getAssetIndexAsync(coin: string): Promise<number>;
|
|
272
|
+
getAssetIndex(coin: string): number;
|
|
273
|
+
getSzDecimalsAsync(coin: string): Promise<number>;
|
|
274
|
+
getSzDecimals(coin: string): number;
|
|
275
|
+
/**
|
|
276
|
+
* Find HIP-3 assets matching a bare coin name (without dex prefix)
|
|
277
|
+
*/
|
|
278
|
+
private findHip3Matches;
|
|
279
|
+
/**
|
|
280
|
+
* Get the dex name for a coin (null for main dex assets)
|
|
281
|
+
*/
|
|
282
|
+
getCoinDex(coin: string): string | null;
|
|
283
|
+
/**
|
|
284
|
+
* Get the local (unprefixed) coin name for API calls that need it
|
|
285
|
+
* e.g., "xyz:CL" → "CL", "ETH" → "ETH"
|
|
286
|
+
*/
|
|
287
|
+
getCoinLocalName(coin: string): string;
|
|
288
|
+
/**
|
|
289
|
+
* Check if a coin is a HIP-3 asset
|
|
290
|
+
*/
|
|
291
|
+
isHip3(coin: string): boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Invalidate cached metadata so next call fetches fresh data.
|
|
294
|
+
* Useful for long-running strategies that need updated funding rates.
|
|
295
|
+
*/
|
|
296
|
+
invalidateMetaCache(): void;
|
|
297
|
+
/**
|
|
298
|
+
* Get all loaded asset names (main + HIP-3)
|
|
299
|
+
*/
|
|
300
|
+
getAllAssetNames(): string[];
|
|
301
|
+
/**
|
|
302
|
+
* Get all HIP-3 asset names
|
|
303
|
+
*/
|
|
304
|
+
getHip3AssetNames(): string[];
|
|
305
|
+
/**
|
|
306
|
+
* Get the account's abstraction mode.
|
|
307
|
+
* Returns: 'standard' | 'unified' | 'portfolio' | 'dexAbstraction'
|
|
308
|
+
* Unified accounts have a single USDC balance shared across all dexes.
|
|
309
|
+
* Standard accounts have separate balances per dex (need sendAsset transfers).
|
|
310
|
+
*/
|
|
311
|
+
getAccountMode(user?: string): Promise<string>;
|
|
312
|
+
/** Whether the account uses unified balances (unified or portfolio margin) */
|
|
313
|
+
isUnifiedAccount(user?: string): Promise<boolean>;
|
|
314
|
+
/**
|
|
315
|
+
* Query the role of an address on HyperCore L1.
|
|
316
|
+
* Returns: "user" | "agent" | "vault" | "subAccount" | "missing"
|
|
317
|
+
* Useful for verifying API wallet (agent) registration.
|
|
318
|
+
*/
|
|
319
|
+
getUserRole(address?: string): Promise<{
|
|
320
|
+
role: string;
|
|
321
|
+
data?: Record<string, string>;
|
|
322
|
+
}>;
|
|
323
|
+
/**
|
|
324
|
+
* Validate API wallet setup: check that the signing wallet is recognized
|
|
325
|
+
* as an "agent" on HyperCore and the account address exists.
|
|
326
|
+
* Logs warnings if misconfigured.
|
|
327
|
+
*/
|
|
328
|
+
validateApiWalletSetup(): Promise<{
|
|
329
|
+
valid: boolean;
|
|
330
|
+
walletRole: string;
|
|
331
|
+
accountRole: string;
|
|
332
|
+
}>;
|
|
333
|
+
/**
|
|
334
|
+
* Check if an address has sub-accounts (is a master account)
|
|
335
|
+
* Sub-accounts cannot approve builder fees - only master accounts can
|
|
336
|
+
*/
|
|
337
|
+
getSubAccounts(user?: string): Promise<Array<{
|
|
338
|
+
subAccountUser: string;
|
|
339
|
+
name: string;
|
|
340
|
+
}>>;
|
|
341
|
+
/**
|
|
342
|
+
* Check the maximum builder fee approved for a user/builder pair
|
|
343
|
+
* Returns the max fee rate as a string (e.g., "0.1%") or null if not approved
|
|
344
|
+
*/
|
|
345
|
+
getMaxBuilderFee(user?: string, builder?: string): Promise<string | null>;
|
|
346
|
+
/**
|
|
347
|
+
* Approve a builder fee for the open-broker builder
|
|
348
|
+
* IMPORTANT: This must be signed by a MAIN wallet, not an API wallet or sub-account
|
|
349
|
+
*
|
|
350
|
+
* @param maxFeeRate - Max fee rate to approve (e.g., "0.01%" for 1 bps)
|
|
351
|
+
* @param builder - Builder address (defaults to open-broker builder)
|
|
352
|
+
*/
|
|
353
|
+
approveBuilderFee(maxFeeRate?: string, builder?: string): Promise<{
|
|
354
|
+
status: 'ok' | 'err';
|
|
355
|
+
response?: unknown;
|
|
356
|
+
}>;
|
|
357
|
+
/**
|
|
358
|
+
* Get user funding ledger updates
|
|
359
|
+
* Returns array of funding payments received/paid per position
|
|
360
|
+
*/
|
|
361
|
+
getUserFunding(user?: string, startTime?: number, endTime?: number): Promise<Array<{
|
|
362
|
+
time: number;
|
|
363
|
+
hash: string;
|
|
364
|
+
delta: {
|
|
365
|
+
type: 'funding';
|
|
366
|
+
coin: string;
|
|
367
|
+
usdc: string;
|
|
368
|
+
szi: string;
|
|
369
|
+
fundingRate: string;
|
|
370
|
+
nSamples: number | null;
|
|
371
|
+
};
|
|
372
|
+
}>>;
|
|
373
|
+
/**
|
|
374
|
+
* Get user trade fills
|
|
375
|
+
*/
|
|
376
|
+
getUserFills(user?: string, aggregateByTime?: boolean): Promise<Array<{
|
|
377
|
+
coin: string;
|
|
378
|
+
px: string;
|
|
379
|
+
sz: string;
|
|
380
|
+
side: 'B' | 'A';
|
|
381
|
+
time: number;
|
|
382
|
+
startPosition: string;
|
|
383
|
+
dir: string;
|
|
384
|
+
closedPnl: string;
|
|
385
|
+
fee: string;
|
|
386
|
+
hash: string;
|
|
387
|
+
oid: number;
|
|
388
|
+
tid: number;
|
|
389
|
+
crossed: boolean;
|
|
390
|
+
feeToken: string;
|
|
391
|
+
twapId: number | null;
|
|
392
|
+
cloid: string | null;
|
|
393
|
+
builderFee: string | null;
|
|
394
|
+
}>>;
|
|
395
|
+
/**
|
|
396
|
+
* Get historical orders (all statuses)
|
|
397
|
+
*/
|
|
398
|
+
getHistoricalOrders(user?: string): Promise<Array<{
|
|
399
|
+
order: {
|
|
400
|
+
coin: string;
|
|
401
|
+
side: string;
|
|
402
|
+
limitPx: string;
|
|
403
|
+
sz: string;
|
|
404
|
+
origSz: string;
|
|
405
|
+
oid: number;
|
|
406
|
+
timestamp: number;
|
|
407
|
+
orderType: string;
|
|
408
|
+
tif: string | null;
|
|
409
|
+
cloid: string | null;
|
|
410
|
+
triggerCondition: string;
|
|
411
|
+
triggerPx: string;
|
|
412
|
+
isTrigger: boolean;
|
|
413
|
+
isPositionTpsl: boolean;
|
|
414
|
+
reduceOnly: boolean;
|
|
415
|
+
children: unknown[];
|
|
416
|
+
};
|
|
417
|
+
status: string;
|
|
418
|
+
statusTimestamp: number;
|
|
419
|
+
}>>;
|
|
420
|
+
/**
|
|
421
|
+
* Get status of a specific order by OID or CLOID
|
|
422
|
+
*/
|
|
423
|
+
getOrderStatus(oid: number | string, user?: string): Promise<{
|
|
424
|
+
status: string;
|
|
425
|
+
order?: {
|
|
426
|
+
order: {
|
|
427
|
+
coin: string;
|
|
428
|
+
side: string;
|
|
429
|
+
limitPx: string;
|
|
430
|
+
sz: string;
|
|
431
|
+
origSz: string;
|
|
432
|
+
oid: number;
|
|
433
|
+
timestamp: number;
|
|
434
|
+
orderType: string;
|
|
435
|
+
tif: string | null;
|
|
436
|
+
cloid: string | null;
|
|
437
|
+
triggerCondition: string;
|
|
438
|
+
triggerPx: string;
|
|
439
|
+
isTrigger: boolean;
|
|
440
|
+
isPositionTpsl: boolean;
|
|
441
|
+
reduceOnly: boolean;
|
|
442
|
+
};
|
|
443
|
+
status: string;
|
|
444
|
+
statusTimestamp: number;
|
|
445
|
+
};
|
|
446
|
+
}>;
|
|
447
|
+
/**
|
|
448
|
+
* Get user fee schedule and volume info
|
|
449
|
+
*/
|
|
450
|
+
getUserFees(user?: string): Promise<{
|
|
451
|
+
dailyUserVlm: Array<{
|
|
452
|
+
date: string;
|
|
453
|
+
exchange: string;
|
|
454
|
+
userCross: string;
|
|
455
|
+
userAdd: string;
|
|
456
|
+
}>;
|
|
457
|
+
feeSchedule: Record<string, unknown>;
|
|
458
|
+
userCrossRate: string;
|
|
459
|
+
userAddRate: string;
|
|
460
|
+
userSpotCrossRate: string;
|
|
461
|
+
userSpotAddRate: string;
|
|
462
|
+
activeReferralDiscount: string;
|
|
463
|
+
trial: unknown;
|
|
464
|
+
feeTrialEscrow: string;
|
|
465
|
+
nextTrialAvailableTimestamp: unknown;
|
|
466
|
+
stakingLink: {
|
|
467
|
+
stakingUser: string;
|
|
468
|
+
status: string;
|
|
469
|
+
} | null;
|
|
470
|
+
activeStakingDiscount: {
|
|
471
|
+
basisPoints: number;
|
|
472
|
+
discountRate: string;
|
|
473
|
+
} | null;
|
|
474
|
+
}>;
|
|
475
|
+
/**
|
|
476
|
+
* Get OHLCV candle data for an asset
|
|
477
|
+
*/
|
|
478
|
+
getCandleSnapshot(coin: string, interval: string, startTime: number, endTime?: number): Promise<Array<{
|
|
479
|
+
t: number;
|
|
480
|
+
T: number;
|
|
481
|
+
s: string;
|
|
482
|
+
i: string;
|
|
483
|
+
o: string;
|
|
484
|
+
c: string;
|
|
485
|
+
h: string;
|
|
486
|
+
l: string;
|
|
487
|
+
v: string;
|
|
488
|
+
n: number;
|
|
489
|
+
}>>;
|
|
490
|
+
/**
|
|
491
|
+
* Get historical funding rates for an asset
|
|
492
|
+
*/
|
|
493
|
+
getFundingHistory(coin: string, startTime: number, endTime?: number): Promise<Array<{
|
|
494
|
+
coin: string;
|
|
495
|
+
fundingRate: string;
|
|
496
|
+
premium: string;
|
|
497
|
+
time: number;
|
|
498
|
+
}>>;
|
|
499
|
+
/**
|
|
500
|
+
* Get recent trades for an asset
|
|
501
|
+
*/
|
|
502
|
+
getRecentTrades(coin: string): Promise<Array<{
|
|
503
|
+
coin: string;
|
|
504
|
+
side: 'B' | 'A';
|
|
505
|
+
px: string;
|
|
506
|
+
sz: string;
|
|
507
|
+
time: number;
|
|
508
|
+
hash: string;
|
|
509
|
+
tid: number;
|
|
510
|
+
}>>;
|
|
511
|
+
/**
|
|
512
|
+
* Get user API rate limit status
|
|
513
|
+
*/
|
|
514
|
+
getUserRateLimit(user?: string): Promise<{
|
|
515
|
+
cumVlm: string;
|
|
516
|
+
nRequestsUsed: number;
|
|
517
|
+
nRequestsCap: number;
|
|
518
|
+
nRequestsSurplus: number;
|
|
519
|
+
}>;
|
|
520
|
+
getUserState(user?: string, dex?: string): Promise<ClearinghouseState>;
|
|
521
|
+
/**
|
|
522
|
+
* Get user state across all dexes (main + HIP-3).
|
|
523
|
+
* For unified accounts: equity comes from spotClearinghouseState (single USDC balance).
|
|
524
|
+
* For standard accounts: aggregates margin summaries from each dex.
|
|
525
|
+
*/
|
|
526
|
+
getUserStateAll(user?: string): Promise<ClearinghouseState>;
|
|
527
|
+
getOpenOrders(user?: string): Promise<OpenOrder[]>;
|
|
528
|
+
/**
|
|
529
|
+
* HIP-3 perps: prepare for trading.
|
|
530
|
+
* 1. Set isolated margin mode (required for HIP-3)
|
|
531
|
+
* 2. For standard accounts only: transfer USDC from main perp to HIP-3 dex
|
|
532
|
+
* (unified accounts share USDC across all dexes automatically)
|
|
533
|
+
*/
|
|
534
|
+
private ensureHip3Ready;
|
|
535
|
+
order(coin: string, isBuy: boolean, size: number, price: number, orderType: {
|
|
536
|
+
limit: {
|
|
537
|
+
tif: 'Gtc' | 'Ioc' | 'Alo';
|
|
538
|
+
};
|
|
539
|
+
}, reduceOnly?: boolean, includeBuilder?: boolean, leverage?: number): Promise<OrderResponse>;
|
|
540
|
+
marketOrder(coin: string, isBuy: boolean, size: number, slippageBps?: number, leverage?: number): Promise<OrderResponse>;
|
|
541
|
+
limitOrder(coin: string, isBuy: boolean, size: number, price: number, tif?: 'Gtc' | 'Ioc' | 'Alo', reduceOnly?: boolean, leverage?: number): Promise<OrderResponse>;
|
|
542
|
+
/**
|
|
543
|
+
* Place a trigger order (stop loss or take profit)
|
|
544
|
+
* @param coin - Asset to trade
|
|
545
|
+
* @param isBuy - True for buy, false for sell
|
|
546
|
+
* @param size - Order size
|
|
547
|
+
* @param triggerPrice - Price at which the order triggers
|
|
548
|
+
* @param limitPrice - Limit price for the order (use triggerPrice for market-like execution)
|
|
549
|
+
* @param tpsl - 'tp' for take profit, 'sl' for stop loss
|
|
550
|
+
* @param reduceOnly - Whether order is reduce-only (should be true for TP/SL)
|
|
551
|
+
*/
|
|
552
|
+
triggerOrder(coin: string, isBuy: boolean, size: number, triggerPrice: number, limitPrice: number, tpsl: 'tp' | 'sl', reduceOnly?: boolean, leverage?: number): Promise<OrderResponse>;
|
|
553
|
+
/**
|
|
554
|
+
* Place a stop loss order
|
|
555
|
+
*/
|
|
556
|
+
stopLoss(coin: string, isBuy: boolean, size: number, triggerPrice: number, slippageBps?: number): Promise<OrderResponse>;
|
|
557
|
+
/**
|
|
558
|
+
* Place a take profit order
|
|
559
|
+
*/
|
|
560
|
+
takeProfit(coin: string, isBuy: boolean, size: number, triggerPrice: number): Promise<OrderResponse>;
|
|
561
|
+
cancel(coin: string, oid: number): Promise<CancelResponse>;
|
|
562
|
+
cancelAll(coin?: string): Promise<CancelResponse[]>;
|
|
563
|
+
/**
|
|
564
|
+
* Place a spot order.
|
|
565
|
+
* Uses the same exchange.order() endpoint but with spot asset indices (10000 + spotIndex).
|
|
566
|
+
* Spot orders have no leverage, no reduce-only, and builder fee max is 1000 (vs 100 for perps).
|
|
567
|
+
*
|
|
568
|
+
* @param coin - Base token symbol (e.g. "PURR", "HYPE")
|
|
569
|
+
* @param isBuy - True to buy base token, false to sell
|
|
570
|
+
* @param size - Size in base token units
|
|
571
|
+
* @param price - Limit price in quote token (usually USDC)
|
|
572
|
+
* @param orderType - Order type with time-in-force
|
|
573
|
+
* @param includeBuilder - Whether to include builder fee (default: true)
|
|
574
|
+
*/
|
|
575
|
+
spotOrder(coin: string, isBuy: boolean, size: number, price: number, orderType: {
|
|
576
|
+
limit: {
|
|
577
|
+
tif: 'Gtc' | 'Ioc' | 'Alo';
|
|
578
|
+
};
|
|
579
|
+
}, includeBuilder?: boolean): Promise<OrderResponse>;
|
|
580
|
+
/**
|
|
581
|
+
* Place a spot market order (IOC at slippage price).
|
|
582
|
+
* @param coin - Base token symbol (e.g. "PURR", "HYPE")
|
|
583
|
+
* @param isBuy - True to buy, false to sell
|
|
584
|
+
* @param size - Size in base token units
|
|
585
|
+
* @param slippageBps - Slippage tolerance in basis points (default: config value)
|
|
586
|
+
*/
|
|
587
|
+
spotMarketOrder(coin: string, isBuy: boolean, size: number, slippageBps?: number): Promise<OrderResponse>;
|
|
588
|
+
/**
|
|
589
|
+
* Place a spot limit order.
|
|
590
|
+
* @param coin - Base token symbol (e.g. "PURR", "HYPE")
|
|
591
|
+
* @param isBuy - True to buy, false to sell
|
|
592
|
+
* @param size - Size in base token units
|
|
593
|
+
* @param price - Limit price in quote token (usually USDC)
|
|
594
|
+
* @param tif - Time-in-force (default: Gtc)
|
|
595
|
+
*/
|
|
596
|
+
spotLimitOrder(coin: string, isBuy: boolean, size: number, price: number, tif?: 'Gtc' | 'Ioc' | 'Alo'): Promise<OrderResponse>;
|
|
597
|
+
/**
|
|
598
|
+
* Place a HIP-4 outcome order.
|
|
599
|
+
* Outcome assets are spot-like, but encoded as:
|
|
600
|
+
* encoding = 10 * outcome + side
|
|
601
|
+
* assetId = 100_000_000 + encoding
|
|
602
|
+
* coin = #<encoding>
|
|
603
|
+
*
|
|
604
|
+
* Side 0 is usually YES and side 1 is usually NO, per outcomeMeta.sideSpecs.
|
|
605
|
+
*/
|
|
606
|
+
outcomeOrder(outcomeRef: string | number, outcomeSide: string | number | undefined, isBuy: boolean, size: number, price: number, orderType: {
|
|
607
|
+
limit: {
|
|
608
|
+
tif: 'Gtc' | 'Ioc' | 'Alo';
|
|
609
|
+
};
|
|
610
|
+
}, includeBuilder?: boolean, szDecimalsOverride?: number): Promise<OrderResponse>;
|
|
611
|
+
outcomeMarketOrder(outcomeRef: string | number, outcomeSide: string | number | undefined, isBuy: boolean, size: number, slippageBps?: number, szDecimalsOverride?: number): Promise<OrderResponse>;
|
|
612
|
+
outcomeLimitOrder(outcomeRef: string | number, outcomeSide: string | number | undefined, isBuy: boolean, size: number, price: number, tif?: 'Gtc' | 'Ioc' | 'Alo', szDecimalsOverride?: number): Promise<OrderResponse>;
|
|
613
|
+
/**
|
|
614
|
+
* Cancel a spot order by coin and order ID.
|
|
615
|
+
*/
|
|
616
|
+
spotCancel(coin: string, oid: number): Promise<CancelResponse>;
|
|
617
|
+
updateLeverage(coin: string, leverage: number, isCross?: boolean): Promise<unknown>;
|
|
618
|
+
/**
|
|
619
|
+
* Place a native Hyperliquid TWAP order.
|
|
620
|
+
* The exchange handles slicing and timing server-side.
|
|
621
|
+
* @param coin Asset symbol (e.g. "ETH")
|
|
622
|
+
* @param isBuy true for long, false for short
|
|
623
|
+
* @param size Total size in base currency
|
|
624
|
+
* @param durationMinutes Duration in minutes (5–1440)
|
|
625
|
+
* @param randomize Enable random order timing
|
|
626
|
+
* @param reduceOnly Reduce-only flag
|
|
627
|
+
* @param leverage Optional leverage to set before placing the TWAP
|
|
628
|
+
*/
|
|
629
|
+
twapOrder(coin: string, isBuy: boolean, size: number, durationMinutes: number, randomize?: boolean, reduceOnly?: boolean, leverage?: number): Promise<{
|
|
630
|
+
status: "ok";
|
|
631
|
+
response: {
|
|
632
|
+
type: "twapOrder";
|
|
633
|
+
data: {
|
|
634
|
+
status: {
|
|
635
|
+
running: {
|
|
636
|
+
twapId: number;
|
|
637
|
+
};
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
}>;
|
|
642
|
+
/**
|
|
643
|
+
* Cancel a running TWAP order.
|
|
644
|
+
* @param coin Asset symbol (e.g. "ETH")
|
|
645
|
+
* @param twapId The TWAP order ID to cancel
|
|
646
|
+
*/
|
|
647
|
+
twapCancel(coin: string, twapId: number): Promise<{
|
|
648
|
+
status: "ok";
|
|
649
|
+
response: {
|
|
650
|
+
type: "twapCancel";
|
|
651
|
+
data: {
|
|
652
|
+
status: string;
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
}>;
|
|
656
|
+
/**
|
|
657
|
+
* Get TWAP order history for the current user.
|
|
658
|
+
*/
|
|
659
|
+
twapHistory(): Promise<{
|
|
660
|
+
time: number;
|
|
661
|
+
state: {
|
|
662
|
+
coin: string;
|
|
663
|
+
executedNtl: string;
|
|
664
|
+
executedSz: string;
|
|
665
|
+
minutes: number;
|
|
666
|
+
randomize: boolean;
|
|
667
|
+
reduceOnly: boolean;
|
|
668
|
+
side: "B" | "A";
|
|
669
|
+
sz: string;
|
|
670
|
+
timestamp: number;
|
|
671
|
+
user: `0x${string}`;
|
|
672
|
+
};
|
|
673
|
+
status: {
|
|
674
|
+
status: "finished" | "activated" | "terminated";
|
|
675
|
+
} | {
|
|
676
|
+
status: "error";
|
|
677
|
+
description: string;
|
|
678
|
+
};
|
|
679
|
+
twapId?: number | undefined;
|
|
680
|
+
}[]>;
|
|
681
|
+
}
|
|
682
|
+
export declare function getClient(config?: OpenBrokerConfig): HyperliquidClient;
|
|
683
|
+
export declare function resetClient(): void;
|
|
684
|
+
//# sourceMappingURL=client.d.ts.map
|