@livo-build/runtime 0.2.4 → 0.2.6
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/eip712.d.ts +45 -0
- package/dist/eip712.js +160 -0
- package/dist/eip712.test.d.ts +1 -0
- package/dist/eip712.test.js +106 -0
- package/dist/gate.d.ts +10 -0
- package/dist/gate.js +18 -0
- package/dist/hyperliquid.d.ts +360 -0
- package/dist/hyperliquid.js +350 -0
- package/dist/hyperliquid.test.d.ts +1 -0
- package/dist/hyperliquid.test.js +31 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.js +14 -0
- package/dist/polymarket.d.ts +158 -0
- package/dist/polymarket.js +508 -0
- package/dist/polymarket.test.d.ts +1 -0
- package/dist/polymarket.test.js +121 -0
- package/dist/telegram.d.ts +31 -0
- package/dist/telegram.js +73 -0
- package/dist/telegramAuth.d.ts +16 -0
- package/dist/telegramAuth.js +108 -0
- package/dist/telegramAuth.test.d.ts +1 -0
- package/dist/telegramAuth.test.js +68 -0
- package/dist/telegramLinks.d.ts +27 -0
- package/dist/telegramLinks.js +78 -0
- package/dist/watcher.d.ts +83 -0
- package/dist/watcher.js +155 -0
- package/package.json +15 -4
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { ExchangeClient, InfoClient } from "@nktkas/hyperliquid";
|
|
2
|
+
import { type Hex } from "./hex.js";
|
|
3
|
+
export interface HyperliquidOptions {
|
|
4
|
+
/** Signing key. Default: env.HYPERLIQUID_PRIVATE_KEY, then env.RELAYER_PRIVATE_KEY. */
|
|
5
|
+
privateKey?: string;
|
|
6
|
+
/** Env var name to read the key from. Default: "HYPERLIQUID_PRIVATE_KEY". */
|
|
7
|
+
privateKeySecret?: string;
|
|
8
|
+
/** Use testnet endpoints. Default: truthy env.HYPERLIQUID_TESTNET. */
|
|
9
|
+
testnet?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Which HIP-3 builder dexes to resolve symbols for: an array of dex names, or
|
|
12
|
+
* true for all of them. Default true — so "xyz:TSLA" & friends just work.
|
|
13
|
+
*/
|
|
14
|
+
dexs?: string[] | boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Master secret for deriving per-user AGENT keys (see `forUser`/`agentAddress`).
|
|
17
|
+
* Default: env.HL_AGENT_SECRET, then env.RELAYER_PRIVATE_KEY. Keep it stable —
|
|
18
|
+
* changing it changes every user's agent address (they'd have to re-approve).
|
|
19
|
+
*/
|
|
20
|
+
agentSecret?: string;
|
|
21
|
+
}
|
|
22
|
+
export type Tif = "Gtc" | "Ioc" | "Alo";
|
|
23
|
+
export type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "8h" | "12h" | "1d" | "3d" | "1w" | "1M";
|
|
24
|
+
export interface CandlesOptions {
|
|
25
|
+
/** Window start (ms epoch). Default: endTime − lookbackMs. */
|
|
26
|
+
startTime?: number;
|
|
27
|
+
/** Window end (ms epoch). Default: now. */
|
|
28
|
+
endTime?: number;
|
|
29
|
+
/** How far back from endTime to start. Default: 24h. */
|
|
30
|
+
lookbackMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/** Live per-coin context: prices, funding, and open interest. */
|
|
33
|
+
export interface AssetContext {
|
|
34
|
+
coin: string;
|
|
35
|
+
markPx: number;
|
|
36
|
+
midPx: number | null;
|
|
37
|
+
oraclePx: number;
|
|
38
|
+
/** Current hourly funding rate (fraction, e.g. 0.0000125). */
|
|
39
|
+
funding: number;
|
|
40
|
+
openInterest: number;
|
|
41
|
+
prevDayPx: number;
|
|
42
|
+
/** 24h notional volume (USDC). */
|
|
43
|
+
dayNtlVlm: number;
|
|
44
|
+
}
|
|
45
|
+
/** Perp account summary. */
|
|
46
|
+
export interface AccountBalance {
|
|
47
|
+
accountValue: number;
|
|
48
|
+
withdrawable: number;
|
|
49
|
+
totalMarginUsed: number;
|
|
50
|
+
totalNtlPos: number;
|
|
51
|
+
}
|
|
52
|
+
export interface PlaceOrderOptions {
|
|
53
|
+
/** Reduce-only (close, never flip). Default false. */
|
|
54
|
+
reduceOnly?: boolean;
|
|
55
|
+
/** Time-in-force for limit orders. Default "Gtc". */
|
|
56
|
+
tif?: Tif;
|
|
57
|
+
}
|
|
58
|
+
export interface MarketOrderOptions {
|
|
59
|
+
/** Reduce-only (close, never flip). Default false. */
|
|
60
|
+
reduceOnly?: boolean;
|
|
61
|
+
/** Max slippage from mid for the protective limit price (0.05 = 5%). Default 0.05. */
|
|
62
|
+
slippage?: number;
|
|
63
|
+
}
|
|
64
|
+
interface MinimalEnv {
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
export declare class Hyperliquid {
|
|
68
|
+
/** True when pointed at testnet. */
|
|
69
|
+
readonly testnet: boolean;
|
|
70
|
+
/** The signer's address (null when no key is configured → read-only). */
|
|
71
|
+
readonly address: Hex | null;
|
|
72
|
+
private readonly env;
|
|
73
|
+
private readonly transport;
|
|
74
|
+
private readonly _info;
|
|
75
|
+
private readonly privateKey?;
|
|
76
|
+
private readonly dexOption;
|
|
77
|
+
private readonly agentSecret?;
|
|
78
|
+
private readAddressOverride?;
|
|
79
|
+
private _exchange?;
|
|
80
|
+
private _converter?;
|
|
81
|
+
private _meta?;
|
|
82
|
+
constructor(env: MinimalEnv | undefined, options?: HyperliquidOptions);
|
|
83
|
+
/** Raw @nktkas InfoClient (all read endpoints). */
|
|
84
|
+
get info(): InfoClient;
|
|
85
|
+
/** Raw @nktkas ExchangeClient (all signed endpoints). Throws if no key is set. */
|
|
86
|
+
get exchange(): ExchangeClient;
|
|
87
|
+
/**
|
|
88
|
+
* All mid prices for a dex, keyed by coin. With no arg → the main perp dex
|
|
89
|
+
* (e.g. { BTC: "95000.0" }). Pass a builder-dex name for equities/commodities
|
|
90
|
+
* (e.g. mids("xyz") → { "xyz:TSLA": "399.8", "xyz:GOLD": "4160.3", … }).
|
|
91
|
+
*/
|
|
92
|
+
mids(dex?: string): Promise<Record<string, string>>;
|
|
93
|
+
/**
|
|
94
|
+
* Mid price of one coin as a number. Accepts a main-dex perp ("BTC") or a
|
|
95
|
+
* builder-dex asset ("xyz:TSLA") — the right dex is queried automatically.
|
|
96
|
+
* Throws if the coin isn't listed (try `findAsset` to resolve a bare ticker).
|
|
97
|
+
*/
|
|
98
|
+
mid(coin: string): Promise<number>;
|
|
99
|
+
/** L2 order book for a coin (main-dex "BTC" or builder-dex "xyz:TSLA"). */
|
|
100
|
+
book(coin: string): Promise<import("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts").L2BookResponse>;
|
|
101
|
+
/** Perp account state (positions, margin, withdrawable) for an address (default: the signer). */
|
|
102
|
+
positions(user?: string): Promise<import("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts").ClearinghouseStateResponse>;
|
|
103
|
+
/** Resting open orders for an address (default: the signer). */
|
|
104
|
+
openOrders(user?: string): Promise<import("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts").OpenOrdersResponse>;
|
|
105
|
+
/** Main perp-dex metadata (universe of coins + szDecimals + maxLeverage). Cached. */
|
|
106
|
+
meta(): Promise<{
|
|
107
|
+
universe: Array<{
|
|
108
|
+
name: string;
|
|
109
|
+
szDecimals: number;
|
|
110
|
+
maxLeverage: number;
|
|
111
|
+
}>;
|
|
112
|
+
}>;
|
|
113
|
+
/** The HIP-3 builder-deployed perp dexes (name + fullName + deployer). */
|
|
114
|
+
dexs(): Promise<{
|
|
115
|
+
name: string;
|
|
116
|
+
fullName?: string;
|
|
117
|
+
}[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Resolve a bare ticker to its full Hyperliquid coin name. "BTC" → "BTC" (main
|
|
120
|
+
* dex); "TSLA" → "xyz:TSLA" (a builder dex). Returns null if nothing matches.
|
|
121
|
+
* Use the result with mid/book/limit/market/etc.
|
|
122
|
+
*/
|
|
123
|
+
findAsset(symbol: string): Promise<string | null>;
|
|
124
|
+
/** The integer asset id Hyperliquid uses in orders for a coin (main, spot, or builder dex). */
|
|
125
|
+
assetId(coin: string): Promise<number>;
|
|
126
|
+
/** Perp account summary (value, withdrawable, margin) for an address (default: the signer). */
|
|
127
|
+
balance(user?: string): Promise<AccountBalance>;
|
|
128
|
+
/** Spot token balances for an address (default: the signer). */
|
|
129
|
+
spotBalances(user?: string): Promise<import("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts").SpotClearinghouseStateResponse>;
|
|
130
|
+
/** Recent fills (trade history) for an address (default: the signer). */
|
|
131
|
+
fills(user?: string): Promise<import("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts").UserFillsResponse>;
|
|
132
|
+
/** Live context for a coin — mark/mid/oracle price, funding rate, open interest, 24h volume. */
|
|
133
|
+
assetCtx(coin: string): Promise<AssetContext>;
|
|
134
|
+
/** OHLCV candles for charting. `interval` default "1h"; window defaults to the last 24h. */
|
|
135
|
+
candles(coin: string, interval?: CandleInterval, opts?: CandlesOptions): Promise<import("file:///home/runner/work/hyperliquid/hyperliquid/src/mod.ts").CandleSnapshotResponse>;
|
|
136
|
+
/** Raw order passthrough (the @nktkas `order` shape) for full control. */
|
|
137
|
+
order(params: Parameters<ExchangeClient["order"]>[0]): Promise<{
|
|
138
|
+
status: "ok";
|
|
139
|
+
response: {
|
|
140
|
+
type: "order";
|
|
141
|
+
data: {
|
|
142
|
+
statuses: ({
|
|
143
|
+
resting: {
|
|
144
|
+
oid: number;
|
|
145
|
+
cloid?: `0x${string}`;
|
|
146
|
+
};
|
|
147
|
+
} | {
|
|
148
|
+
filled: {
|
|
149
|
+
totalSz: string;
|
|
150
|
+
avgPx: string;
|
|
151
|
+
oid: number;
|
|
152
|
+
cloid?: `0x${string}`;
|
|
153
|
+
};
|
|
154
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
}>;
|
|
158
|
+
/** Place a limit order. `price`/`size` are numbers; we format to HL's precision. */
|
|
159
|
+
limit(coin: string, isBuy: boolean, size: number, price: number, opts?: PlaceOrderOptions): Promise<{
|
|
160
|
+
status: "ok";
|
|
161
|
+
response: {
|
|
162
|
+
type: "order";
|
|
163
|
+
data: {
|
|
164
|
+
statuses: ({
|
|
165
|
+
resting: {
|
|
166
|
+
oid: number;
|
|
167
|
+
cloid?: `0x${string}`;
|
|
168
|
+
};
|
|
169
|
+
} | {
|
|
170
|
+
filled: {
|
|
171
|
+
totalSz: string;
|
|
172
|
+
avgPx: string;
|
|
173
|
+
oid: number;
|
|
174
|
+
cloid?: `0x${string}`;
|
|
175
|
+
};
|
|
176
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
}>;
|
|
180
|
+
limitBuy(coin: string, size: number, price: number, opts?: PlaceOrderOptions): Promise<{
|
|
181
|
+
status: "ok";
|
|
182
|
+
response: {
|
|
183
|
+
type: "order";
|
|
184
|
+
data: {
|
|
185
|
+
statuses: ({
|
|
186
|
+
resting: {
|
|
187
|
+
oid: number;
|
|
188
|
+
cloid?: `0x${string}`;
|
|
189
|
+
};
|
|
190
|
+
} | {
|
|
191
|
+
filled: {
|
|
192
|
+
totalSz: string;
|
|
193
|
+
avgPx: string;
|
|
194
|
+
oid: number;
|
|
195
|
+
cloid?: `0x${string}`;
|
|
196
|
+
};
|
|
197
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
}>;
|
|
201
|
+
limitSell(coin: string, size: number, price: number, opts?: PlaceOrderOptions): Promise<{
|
|
202
|
+
status: "ok";
|
|
203
|
+
response: {
|
|
204
|
+
type: "order";
|
|
205
|
+
data: {
|
|
206
|
+
statuses: ({
|
|
207
|
+
resting: {
|
|
208
|
+
oid: number;
|
|
209
|
+
cloid?: `0x${string}`;
|
|
210
|
+
};
|
|
211
|
+
} | {
|
|
212
|
+
filled: {
|
|
213
|
+
totalSz: string;
|
|
214
|
+
avgPx: string;
|
|
215
|
+
oid: number;
|
|
216
|
+
cloid?: `0x${string}`;
|
|
217
|
+
};
|
|
218
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
}>;
|
|
222
|
+
/**
|
|
223
|
+
* Market order — an IOC limit priced `slippage` past the current mid so it
|
|
224
|
+
* crosses immediately. Returns the @nktkas order response.
|
|
225
|
+
*/
|
|
226
|
+
market(coin: string, isBuy: boolean, size: number, opts?: MarketOrderOptions): Promise<{
|
|
227
|
+
status: "ok";
|
|
228
|
+
response: {
|
|
229
|
+
type: "order";
|
|
230
|
+
data: {
|
|
231
|
+
statuses: ({
|
|
232
|
+
resting: {
|
|
233
|
+
oid: number;
|
|
234
|
+
cloid?: `0x${string}`;
|
|
235
|
+
};
|
|
236
|
+
} | {
|
|
237
|
+
filled: {
|
|
238
|
+
totalSz: string;
|
|
239
|
+
avgPx: string;
|
|
240
|
+
oid: number;
|
|
241
|
+
cloid?: `0x${string}`;
|
|
242
|
+
};
|
|
243
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
}>;
|
|
247
|
+
marketBuy(coin: string, size: number, opts?: MarketOrderOptions): Promise<{
|
|
248
|
+
status: "ok";
|
|
249
|
+
response: {
|
|
250
|
+
type: "order";
|
|
251
|
+
data: {
|
|
252
|
+
statuses: ({
|
|
253
|
+
resting: {
|
|
254
|
+
oid: number;
|
|
255
|
+
cloid?: `0x${string}`;
|
|
256
|
+
};
|
|
257
|
+
} | {
|
|
258
|
+
filled: {
|
|
259
|
+
totalSz: string;
|
|
260
|
+
avgPx: string;
|
|
261
|
+
oid: number;
|
|
262
|
+
cloid?: `0x${string}`;
|
|
263
|
+
};
|
|
264
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
}>;
|
|
268
|
+
marketSell(coin: string, size: number, opts?: MarketOrderOptions): Promise<{
|
|
269
|
+
status: "ok";
|
|
270
|
+
response: {
|
|
271
|
+
type: "order";
|
|
272
|
+
data: {
|
|
273
|
+
statuses: ({
|
|
274
|
+
resting: {
|
|
275
|
+
oid: number;
|
|
276
|
+
cloid?: `0x${string}`;
|
|
277
|
+
};
|
|
278
|
+
} | {
|
|
279
|
+
filled: {
|
|
280
|
+
totalSz: string;
|
|
281
|
+
avgPx: string;
|
|
282
|
+
oid: number;
|
|
283
|
+
cloid?: `0x${string}`;
|
|
284
|
+
};
|
|
285
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
}>;
|
|
289
|
+
/**
|
|
290
|
+
* Market-close the entire open position in `coin` (reduce-only). Reads the
|
|
291
|
+
* current size and crosses the opposite side. No-op (returns closed:false) if flat.
|
|
292
|
+
*/
|
|
293
|
+
closePosition(coin: string, opts?: {
|
|
294
|
+
slippage?: number;
|
|
295
|
+
}): Promise<{
|
|
296
|
+
closed: false;
|
|
297
|
+
side?: undefined;
|
|
298
|
+
size?: undefined;
|
|
299
|
+
result?: undefined;
|
|
300
|
+
} | {
|
|
301
|
+
closed: true;
|
|
302
|
+
side: string;
|
|
303
|
+
size: number;
|
|
304
|
+
result: {
|
|
305
|
+
status: "ok";
|
|
306
|
+
response: {
|
|
307
|
+
type: "order";
|
|
308
|
+
data: {
|
|
309
|
+
statuses: ({
|
|
310
|
+
resting: {
|
|
311
|
+
oid: number;
|
|
312
|
+
cloid?: `0x${string}`;
|
|
313
|
+
};
|
|
314
|
+
} | {
|
|
315
|
+
filled: {
|
|
316
|
+
totalSz: string;
|
|
317
|
+
avgPx: string;
|
|
318
|
+
oid: number;
|
|
319
|
+
cloid?: `0x${string}`;
|
|
320
|
+
};
|
|
321
|
+
} | "waitingForFill" | "waitingForTrigger")[];
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
}>;
|
|
326
|
+
/** Cancel a resting order by its order id (oid). */
|
|
327
|
+
cancel(coin: string, oid: number): Promise<{
|
|
328
|
+
status: "ok";
|
|
329
|
+
response: {
|
|
330
|
+
type: "cancel";
|
|
331
|
+
data: {
|
|
332
|
+
statuses: "success"[];
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
}>;
|
|
336
|
+
/** Set leverage for a coin (cross by default). */
|
|
337
|
+
updateLeverage(coin: string, leverage: number, opts?: {
|
|
338
|
+
cross?: boolean;
|
|
339
|
+
}): Promise<{
|
|
340
|
+
status: "ok";
|
|
341
|
+
response: {
|
|
342
|
+
type: "default";
|
|
343
|
+
};
|
|
344
|
+
}>;
|
|
345
|
+
private symbols;
|
|
346
|
+
private lookup;
|
|
347
|
+
private requireUser;
|
|
348
|
+
/** The per-user agent PRIVATE key (deterministic from the agent secret + userId; never stored). */
|
|
349
|
+
agentKey(userId: string): Hex;
|
|
350
|
+
/** The agent ADDRESS the user must approve (show this in your connect/approve UI). */
|
|
351
|
+
agentAddress(userId: string): Hex;
|
|
352
|
+
/**
|
|
353
|
+
* A Hyperliquid bound to one end-user: it SIGNS orders with that user's agent key
|
|
354
|
+
* and READS/attributes to their `master` account. Use after the user has approved
|
|
355
|
+
* `agentAddress(userId)`. Trading methods (marketBuy/limit/closePosition/cancel/…)
|
|
356
|
+
* then act on the user's account; positions()/balance() default to `master`.
|
|
357
|
+
*/
|
|
358
|
+
forUser(userId: string, master: string): Hyperliquid;
|
|
359
|
+
}
|
|
360
|
+
export {};
|