@pear-protocol/hyperliquid-sdk 0.0.4 → 0.0.7-2.1

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.
Files changed (59) hide show
  1. package/dist/clients/agentWallet.d.ts +3 -0
  2. package/dist/clients/auth.d.ts +14 -0
  3. package/dist/clients/hyperliquid.d.ts +25 -0
  4. package/dist/clients/notifications.d.ts +13 -0
  5. package/dist/clients/orders.d.ts +65 -0
  6. package/dist/clients/portfolio.d.ts +39 -0
  7. package/dist/clients/positions.d.ts +135 -0
  8. package/dist/clients/sync.d.ts +9 -0
  9. package/dist/clients/watchlist.d.ts +2 -0
  10. package/dist/hooks/index.d.ts +20 -2
  11. package/dist/hooks/useAccountSummary.d.ts +5 -0
  12. package/dist/hooks/useAgentWallet.d.ts +5 -0
  13. package/dist/hooks/useAllUserBalances.d.ts +9 -0
  14. package/dist/hooks/useAuth.d.ts +12 -0
  15. package/dist/hooks/useAutoSyncFills.d.ts +19 -0
  16. package/dist/hooks/useBasketCandles.d.ts +25 -0
  17. package/dist/hooks/useHistoricalPriceData.d.ts +11 -0
  18. package/dist/hooks/useMarketData.d.ts +12 -0
  19. package/dist/hooks/useNotifications.d.ts +16 -0
  20. package/dist/hooks/useOrders.d.ts +10 -0
  21. package/dist/hooks/usePerformanceOverlays.d.ts +14 -0
  22. package/dist/hooks/usePortfolio.d.ts +13 -0
  23. package/dist/hooks/usePosition.d.ts +13 -0
  24. package/dist/hooks/useSpotOrder.d.ts +13 -0
  25. package/dist/hooks/useTokenSelectionMetadata.d.ts +18 -0
  26. package/dist/hooks/useTrading.d.ts +10 -16
  27. package/dist/hooks/useTwap.d.ts +6 -0
  28. package/dist/hooks/useUserSelection.d.ts +3 -0
  29. package/dist/hooks/useWatchlist.d.ts +6 -0
  30. package/dist/hooks/useWebData.d.ts +30 -0
  31. package/dist/hyperliquid-websocket.d.ts +10 -0
  32. package/dist/index.d.ts +1289 -324
  33. package/dist/index.js +8432 -2727
  34. package/dist/provider.d.ts +11 -29
  35. package/dist/store/historicalPriceDataStore.d.ts +14 -0
  36. package/dist/store/hyperliquidDataStore.d.ts +1 -0
  37. package/dist/store/marketDataStore.d.ts +1 -0
  38. package/dist/store/tokenSelectionMetadataStore.d.ts +27 -0
  39. package/dist/store/userDataStore.d.ts +1 -0
  40. package/dist/store/userSelection.d.ts +27 -0
  41. package/dist/types.d.ts +617 -222
  42. package/dist/utils/account-summary-calculator.d.ts +17 -0
  43. package/dist/utils/basket-calculator.d.ts +24 -0
  44. package/dist/utils/chart-interval-mappers.d.ts +9 -0
  45. package/dist/utils/conflict-detector.d.ts +14 -0
  46. package/dist/utils/http.d.ts +26 -0
  47. package/dist/utils/position-processor.d.ts +2 -0
  48. package/dist/utils/position-validator.d.ts +61 -0
  49. package/dist/utils/symbol-translator.d.ts +40 -0
  50. package/dist/utils/token-metadata-extractor.d.ts +37 -0
  51. package/dist/websocket.d.ts +9 -0
  52. package/package.json +28 -8
  53. package/README.md +0 -230
  54. package/dist/client.d.ts +0 -43
  55. package/dist/hooks/useAddress.d.ts +0 -9
  56. package/dist/index.esm.js +0 -2830
  57. package/dist/index.esm.js.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/migration-sdk.d.ts +0 -59
package/dist/types.d.ts CHANGED
@@ -1,71 +1,8 @@
1
- /**
2
- * Raw value data for trade history positions
3
- */
4
- export interface RawValueDto {
5
- coin: string;
6
- size: string;
7
- leverage: number;
8
- openPx: string;
9
- closePx: string;
10
- marginUsed: string;
11
- positionValue: string;
12
- }
13
- /**
14
- * Trade history data structure from V1 API
15
- */
16
- export interface TradeHistoryV1Dto {
17
- pearId: string;
18
- openedDate: string;
19
- closedDate: string;
20
- time: string;
21
- pair: string;
22
- direction: Record<string, string>;
23
- closedPrice: number;
24
- openedPrice: number;
25
- size: string;
26
- longPositionValue: number;
27
- shortPositionValue: number;
28
- positionValue: number;
29
- fee: number;
30
- builderFee: number;
31
- closedPNL: number;
32
- closedPnlPercentage: number;
33
- leverage: number;
34
- rawLongValue: RawValueDto;
35
- rawShortValue: RawValueDto;
36
- }
37
- /**
38
- * Request payload for syncing trade history
39
- */
40
- export interface SyncTradeHistoryDto {
41
- address: string;
42
- data: TradeHistoryV1Dto[];
43
- }
44
- /**
45
- * Response from sync trade history endpoint
46
- */
47
- export interface SyncTradeHistoryResponseDto {
48
- success: boolean;
49
- positionId: string;
50
- tradeHistoryId: string;
51
- message: string;
52
- }
53
- /**
54
- * Base API error response
55
- */
56
1
  export interface ApiErrorResponse {
57
2
  statusCode: number;
58
3
  message: string;
59
4
  error?: string;
60
5
  }
61
- /**
62
- * Configuration options for the SDK
63
- */
64
- export interface PearHyperliquidConfig {
65
- baseUrl: string;
66
- timeout?: number;
67
- headers?: Record<string, string>;
68
- }
69
6
  /**
70
7
  * HTTP client response wrapper
71
8
  */
@@ -74,145 +11,58 @@ export interface ApiResponse<T> {
74
11
  status: number;
75
12
  headers: Record<string, string>;
76
13
  }
77
- /**
78
- * Hook state interface for migration operations
79
- */
80
- export interface MigrationHookState<T> {
81
- loading: boolean;
82
- error: ApiErrorResponse | null;
83
- data: T | null;
84
- }
85
- /**
86
- * PnL data structure for open positions
87
- */
88
- export interface PnlDto {
89
- value: number;
90
- percentage: number;
14
+ export interface ExternalLiquidationDto {
15
+ liquidatedUser: string;
16
+ markPx: string;
17
+ method: string;
91
18
  }
92
- /**
93
- * Take profit and stop loss data structure
94
- */
95
- export interface TpSlDto {
96
- takeProfit?: number;
97
- stopLoss?: number;
98
- }
99
- /**
100
- * Position side data structure for open positions
101
- */
102
- export interface PositionSideDto {
19
+ export interface ExternalFillDto {
103
20
  coin: string;
104
- size: string;
105
- leverage: number;
106
- entryPx: string;
107
- marginUsed: string;
108
- liquidationPx: string | undefined;
109
- unrealizedPnl: string;
110
- roe: string;
111
- positionValue: string;
112
- funding: string;
113
- }
114
- /**
115
- * Open position data structure from V1 API
116
- */
117
- export interface OpenPositionV1Dto {
118
- pair: string;
119
- leverage: number;
120
- size: number;
121
- longPositionValue?: number;
122
- shortPositionValue?: number;
123
- positionValue: number;
124
- entryPrice: number;
125
- markPrice: number;
126
- pnl: PnlDto;
127
- liqPrice: string | number;
128
- margin: number;
129
- funding: number;
130
- pearId: string;
131
- openedDate: string;
132
- tpsl: TpSlDto;
133
- long: PositionSideDto;
134
- short: PositionSideDto;
135
- }
136
- /**
137
- * Request payload for syncing open positions
138
- */
139
- export interface SyncOpenPositionDto {
140
- address: string;
141
- data: OpenPositionV1Dto[];
142
- }
143
- /**
144
- * Response from sync open positions endpoint
145
- */
146
- export interface SyncOpenPositionResponseDto {
147
- success: boolean;
148
- positionIds: string[];
149
- count: number;
150
- message: string;
151
- }
152
- /**
153
- * Open order data structure from V1 API
154
- */
155
- export interface OpenOrderV1Dto {
156
- id: string;
157
- time: string;
158
- pair: string;
159
- type: string;
160
- orderValue: number;
161
- price: number;
162
- triggerConditions: string;
163
- status: string;
164
- leverage?: string;
165
- }
166
- /**
167
- * Request payload for syncing open orders
168
- */
169
- export interface SyncOpenOrderDto {
170
- address: string;
171
- data: OpenOrderV1Dto[];
172
- }
173
- /**
174
- * Response from sync open orders endpoint
175
- */
176
- export interface SyncOpenOrderResponseDto {
177
- success: boolean;
178
- orderIds: string[];
179
- count: number;
180
- message: string;
181
- }
182
- /**
183
- * Migration hooks interface
184
- */
185
- export interface MigrationHooks {
186
- tradeHistory: {
187
- sync: (payload: SyncTradeHistoryDto) => Promise<ApiResponse<SyncTradeHistoryResponseDto>>;
188
- loading: boolean;
189
- error: ApiErrorResponse | null;
190
- data: SyncTradeHistoryResponseDto | null;
191
- reset: () => void;
192
- };
193
- openPositions: {
194
- sync: (payload: SyncOpenPositionDto) => Promise<ApiResponse<SyncOpenPositionResponseDto>>;
195
- loading: boolean;
196
- error: ApiErrorResponse | null;
197
- data: SyncOpenPositionResponseDto | null;
198
- reset: () => void;
199
- };
200
- openOrders: {
201
- sync: (payload: SyncOpenOrderDto) => Promise<ApiResponse<SyncOpenOrderResponseDto>>;
202
- loading: boolean;
203
- error: ApiErrorResponse | null;
204
- data: SyncOpenOrderResponseDto | null;
205
- reset: () => void;
206
- };
21
+ px: string;
22
+ sz: string;
23
+ side: 'B' | 'A';
24
+ time: number;
25
+ dir: string;
26
+ fee: string;
27
+ builderFee?: string;
28
+ oid?: string | number;
29
+ tid?: string | number;
30
+ cloid?: string | null;
31
+ hash?: string | null;
32
+ feeToken?: string | null;
33
+ liquidation?: ExternalLiquidationDto | null;
34
+ }
35
+ export interface SyncFillsRequestDto {
36
+ user: string;
37
+ fills: ExternalFillDto[];
38
+ assetPositions?: AssetPosition[];
39
+ }
40
+ export interface SyncFillsResponseDto {
41
+ insertedFills: number;
42
+ skippedDuplicates: number;
43
+ createdOrders: number;
44
+ updatedPositions: number;
45
+ createdPositions: number;
46
+ closedPositions: number;
47
+ }
48
+ export interface TwapSliceFillResponseItem {
49
+ fill: ExternalFillDto;
50
+ twapId: number;
207
51
  }
208
52
  /**
209
53
  * WebSocket connection states
210
54
  */
211
55
  export type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'error';
56
+ export declare enum ReadyState {
57
+ CONNECTING = 0,
58
+ OPEN = 1,
59
+ CLOSING = 2,
60
+ CLOSED = 3
61
+ }
212
62
  /**
213
63
  * WebSocket channels
214
64
  */
215
- export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary';
65
+ export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'market-data-all' | 'webData3' | 'allMids' | 'activeAssetData';
216
66
  /**
217
67
  * WebSocket subscription message
218
68
  */
@@ -223,7 +73,7 @@ export interface WebSocketSubscribeMessage {
223
73
  /**
224
74
  * WebSocket response message
225
75
  */
226
- export interface WebSocketResponse {
76
+ export interface WebSocketAckResponse {
227
77
  success?: boolean;
228
78
  message?: string;
229
79
  error?: string;
@@ -235,17 +85,85 @@ export interface WebSocketDataMessage<T = unknown> {
235
85
  channel: WebSocketChannel;
236
86
  data: T;
237
87
  }
88
+ export interface WatchlistAssetDto {
89
+ asset: string;
90
+ weight: number;
91
+ }
92
+ export interface WatchlistItemDto {
93
+ id: string;
94
+ longAssets: WatchlistAssetDto[];
95
+ shortAssets: WatchlistAssetDto[];
96
+ }
97
+ export interface ToggleWatchlistResponseDto {
98
+ items: WatchlistItemDto[];
99
+ }
100
+ export type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'TRADE_CLOSED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
101
+ export interface NotificationDto {
102
+ id: string;
103
+ address: string;
104
+ category: NotificationCategory;
105
+ parameters: Record<string, any>;
106
+ is_read: boolean;
107
+ created_at: string;
108
+ updated_at: string;
109
+ }
110
+ export interface ChunkFillDto {
111
+ fillId: string;
112
+ assetName: string;
113
+ price: number;
114
+ size: number;
115
+ executedAt: string;
116
+ }
117
+ export type TwapChunkStatus = 'PENDING' | 'SCHEDULED' | 'EXECUTING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
118
+ export interface TwapChunkStatusDto {
119
+ chunkId: string;
120
+ chunkIndex: number;
121
+ scheduledTime: string;
122
+ executedTime?: string;
123
+ status: TwapChunkStatus;
124
+ chunkSize: number;
125
+ fills: ChunkFillDto[];
126
+ errorMessage?: string;
127
+ }
128
+ export type TwapOrderOverallStatus = 'OPEN' | 'EXECUTING' | 'COMPLETED' | 'PARTIALLY_COMPLETED' | 'FAILED' | 'CANCELLED';
129
+ export interface TwapMonitoringDto {
130
+ orderId: string;
131
+ positionId?: string;
132
+ address: string;
133
+ orderType: string;
134
+ status: TwapOrderOverallStatus;
135
+ totalUsdValue: number;
136
+ filledUsdValue: number;
137
+ remainingUsdValue: number;
138
+ twapDuration: string;
139
+ twapIntervalSeconds?: number | null;
140
+ twapChunkUsdValue?: number | null;
141
+ randomizeExecution: boolean;
142
+ reduceOnly: boolean;
143
+ chunks: TwapChunkStatusDto[];
144
+ estimatedCompletionTime?: string;
145
+ actualCompletionTime?: string;
146
+ remainingChunks: number;
147
+ longAssets: OrderAssetDto[];
148
+ shortAssets: OrderAssetDto[];
149
+ createdAt: string;
150
+ updatedAt: string;
151
+ }
238
152
  /**
239
153
  * Trade history asset data
240
154
  */
241
155
  export interface TradeHistoryAssetDataDto {
242
156
  coin: string;
157
+ entryWeight: number;
243
158
  entryPrice: number;
244
159
  limitPrice: number;
160
+ leverage: number;
245
161
  size: number;
246
162
  externalFeePaid: number;
247
163
  builderFeePaid: number;
248
164
  realizedPnl: number;
165
+ marketPrefix?: string | null;
166
+ collateralToken?: CollateralToken;
249
167
  }
250
168
  /**
251
169
  * Trade history data structure
@@ -257,23 +175,19 @@ export interface TradeHistoryDataDto {
257
175
  externalFeePaid: number;
258
176
  builderFeePaid: number;
259
177
  realizedPnl: number;
178
+ realizedPnlPercentage: number;
179
+ totalEntryValue: number;
260
180
  totalValue: number;
261
181
  entryRatio: number;
262
182
  exitRatio: number;
263
- leverage: number;
264
- longAssets: TradeHistoryAssetDataDto[];
265
- shortAssets: TradeHistoryAssetDataDto[];
183
+ entryPriceRatio?: number;
184
+ exitpPriceRatio?: number;
185
+ closedLongAssets: TradeHistoryAssetDataDto[];
186
+ closedShortAssets: TradeHistoryAssetDataDto[];
187
+ positionLongAssets?: string[];
188
+ positionShortAssets?: string[];
266
189
  createdAt: string;
267
190
  }
268
- /**
269
- * Paginated trade history response
270
- */
271
- export interface PaginatedTradeHistoryResponseDto {
272
- data: TradeHistoryDataDto[];
273
- hasMore: boolean;
274
- nextCursor?: string;
275
- count: number;
276
- }
277
191
  /**
278
192
  * Cumulative funding information
279
193
  */
@@ -290,36 +204,40 @@ export interface PositionAssetDetailDto {
290
204
  entryPrice: number;
291
205
  platformSize: number;
292
206
  actualSize: number;
293
- cumFunding: CumFundingDto;
207
+ leverage: number;
294
208
  marginUsed: number;
209
+ entryPositionValue: number;
295
210
  positionValue: number;
296
211
  unrealizedPnl: number;
297
212
  liquidationPrice: number;
298
- isExternallyModified: boolean;
213
+ initialWeight: number;
214
+ fundingPaid?: number;
215
+ marketPrefix?: string | null;
216
+ collateralToken?: CollateralToken;
217
+ }
218
+ export interface TpSlThreshold {
219
+ type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
220
+ value: number;
299
221
  }
300
- /**
301
- * Position sync status
302
- */
303
- export type PositionSyncStatus = 'SYNCED' | 'EXTERNALLY_MODIFIED' | 'EXTERNALLY_CLOSED' | 'PAIR_BROKEN';
304
222
  /**
305
223
  * Open position data structure
306
224
  */
307
225
  export interface OpenPositionDto {
308
226
  positionId: string;
309
227
  address: string;
310
- leverage: number;
311
- stopLoss: number | null;
312
- takeProfit: number | null;
228
+ stopLoss: TpSlThreshold | null;
229
+ takeProfit: TpSlThreshold | null;
313
230
  entryRatio: number;
314
231
  markRatio: number;
315
- netFunding: number;
232
+ entryPriceRatio?: number;
233
+ markPriceRatio?: number;
234
+ entryPositionValue: number;
316
235
  positionValue: number;
317
236
  marginUsed: number;
318
237
  unrealizedPnl: number;
238
+ unrealizedPnlPercentage: number;
319
239
  longAssets: PositionAssetDetailDto[];
320
240
  shortAssets: PositionAssetDetailDto[];
321
- syncStatus: PositionSyncStatus;
322
- lastSyncAt: string;
323
241
  createdAt: string;
324
242
  updatedAt: string;
325
243
  }
@@ -329,23 +247,40 @@ export interface OpenPositionDto {
329
247
  export interface OrderAssetDto {
330
248
  asset: string;
331
249
  weight: number;
250
+ marketPrefix?: string | null;
251
+ collateralToken?: CollateralToken;
332
252
  }
333
253
  /**
334
254
  * Order status
335
255
  */
336
256
  export type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
257
+ /**
258
+ * Order type
259
+ */
260
+ export type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET' | 'LIMIT_BTCDOM' | 'TWAP';
261
+ /**
262
+ * TP/SL trigger type
263
+ */
264
+ export type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
265
+ export type OrderDirection = 'MORE_THAN' | 'LESS_THAN' | null;
337
266
  /**
338
267
  * Open limit order data structure
339
268
  */
340
269
  export interface OpenLimitOrderDto {
341
270
  orderId: string;
342
271
  address: string;
272
+ clientId: string | null;
273
+ positionId?: string | null;
343
274
  leverage: number;
344
275
  usdValue: number;
345
- limitRatio: number;
346
- stopLoss: number | null;
347
- takeProfit: number | null;
276
+ triggerValue?: number | null;
277
+ twapDuration?: string | null;
278
+ tpSlTriggerType?: TpSlTriggerType | null;
279
+ randomizeFlag: boolean;
280
+ reduceOnlyFlag: boolean;
348
281
  status: OrderStatus;
282
+ orderType: OrderType;
283
+ direction?: OrderDirection | null;
349
284
  longAssets: OrderAssetDto[];
350
285
  shortAssets: OrderAssetDto[];
351
286
  createdAt: string;
@@ -383,15 +318,23 @@ export interface BalanceSummaryDto {
383
318
  * Agent wallet information
384
319
  */
385
320
  export interface AgentWalletDto {
386
- address: string;
321
+ address?: string;
387
322
  status: string;
388
323
  }
324
+ export interface PlatformAccountSummaryResponseDto {
325
+ agentWalletAddress: string | null;
326
+ totalClosedTrades: number;
327
+ totalLimitOrderUsdValue?: number;
328
+ totalTwapChunkUsdValue?: number;
329
+ lastSyncedAt?: number;
330
+ }
389
331
  /**
390
332
  * Account balance response (renamed to AccountSummaryResponseDto for consistency)
391
333
  */
392
334
  export interface AccountSummaryResponseDto {
393
335
  balanceSummary: BalanceSummaryDto;
394
- agentWallet: AgentWalletDto;
336
+ platformAccountSummary: PlatformAccountSummaryResponseDto | null;
337
+ agentWallet?: AgentWalletDto;
395
338
  }
396
339
  /**
397
340
  * Address management state
@@ -402,3 +345,455 @@ export interface AddressState {
402
345
  autoConnect: boolean;
403
346
  previousAddresses: string[];
404
347
  }
348
+ export interface UseAuthOptions {
349
+ baseUrl: string;
350
+ clientId: string;
351
+ }
352
+ export interface UserProfile {
353
+ userId: string;
354
+ address: string;
355
+ appId: string;
356
+ }
357
+ export interface EIP712AuthDetails {
358
+ primaryType: string;
359
+ domain: {
360
+ name: string;
361
+ version: string;
362
+ chainId: number;
363
+ verifyingContract: `0x${string}`;
364
+ };
365
+ types: Record<string, Array<{
366
+ name: string;
367
+ type: string;
368
+ }>>;
369
+ message: Record<string, unknown>;
370
+ timestamp: number;
371
+ }
372
+ export interface GetEIP712MessageResponse extends EIP712AuthDetails {
373
+ }
374
+ export interface PrivyAuthDetails {
375
+ appId: string;
376
+ accessToken: string;
377
+ }
378
+ export interface AuthenticateRequest {
379
+ method: 'eip712' | 'api_key' | 'privy_access_token';
380
+ address: string;
381
+ clientId: string;
382
+ details: {
383
+ signature: string;
384
+ timestamp: number;
385
+ } | {
386
+ apiKey: string;
387
+ } | PrivyAuthDetails;
388
+ }
389
+ export interface AuthenticateResponse {
390
+ accessToken: string;
391
+ refreshToken: string;
392
+ tokenType: string;
393
+ expiresIn: number;
394
+ address: string;
395
+ clientId: string;
396
+ }
397
+ export interface RefreshTokenRequest {
398
+ refreshToken: string;
399
+ }
400
+ export interface RefreshTokenResponse {
401
+ accessToken: string;
402
+ refreshToken: string;
403
+ tokenType: string;
404
+ expiresIn: number;
405
+ }
406
+ export interface LogoutRequest {
407
+ refreshToken: string;
408
+ }
409
+ export interface LogoutResponse {
410
+ message: string;
411
+ }
412
+ export type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
413
+ export interface GetAgentWalletResponseDto {
414
+ agentWalletAddress?: string;
415
+ agentName: string;
416
+ status: AgentWalletStatus;
417
+ }
418
+ export interface CreateAgentWalletResponseDto {
419
+ agentWalletAddress: string;
420
+ message: string;
421
+ }
422
+ export interface ExtraAgent {
423
+ name: string;
424
+ address: string;
425
+ validUntil: number;
426
+ }
427
+ export interface AgentWalletState {
428
+ address: string | null;
429
+ name: string | null;
430
+ status: AgentWalletStatus | 'PENDING' | null;
431
+ isActive: boolean;
432
+ }
433
+ /**
434
+ * WebSocket message from HyperLiquid native API
435
+ */
436
+ export interface WebSocketMessage {
437
+ method: 'subscribe' | 'unsubscribe';
438
+ subscription: {
439
+ type: string;
440
+ dex?: string;
441
+ coin?: string;
442
+ interval?: string;
443
+ user?: string;
444
+ aggregateByTime?: boolean;
445
+ };
446
+ }
447
+ /**
448
+ * WebSocket response from HyperLiquid native API
449
+ */
450
+ export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle' | 'spotState' | 'allDexsClearinghouseState' | 'allDexsAssetCtxs';
451
+ export interface HLChannelDataMap {
452
+ webData3: WebData3Response;
453
+ allMids: WsAllMidsData;
454
+ activeAssetData: ActiveAssetData;
455
+ candle: CandleData;
456
+ spotState: {
457
+ user: string;
458
+ spotState: SpotState;
459
+ };
460
+ allDexsClearinghouseState: AllDexsClearinghouseStateData;
461
+ allDexsAssetCtxs: AllDexsAssetCtxsData;
462
+ }
463
+ export interface WebData3UserState {
464
+ agentAddress?: string;
465
+ agentValidUntil?: number;
466
+ cumLedger: string;
467
+ serverTime: number;
468
+ isVault: boolean;
469
+ user: string;
470
+ dexAbstractionEnabled?: boolean;
471
+ }
472
+ export interface WebData3AssetCtx {
473
+ funding: string;
474
+ openInterest: string;
475
+ prevDayPx: string;
476
+ dayNtlVlm: string;
477
+ premium: string | null;
478
+ oraclePx: string;
479
+ markPx: string;
480
+ midPx: string | null;
481
+ impactPxs: string[] | null;
482
+ dayBaseVlm: string;
483
+ }
484
+ export interface WebData3PerpDexState {
485
+ clearinghouseState: ClearinghouseState;
486
+ totalVaultEquity: string;
487
+ assetCtxs: WebData3AssetCtx[];
488
+ perpsAtOpenInterestCap: string[];
489
+ }
490
+ export interface WebData3Response {
491
+ userState: WebData3UserState;
492
+ perpDexStates: WebData3PerpDexState[];
493
+ }
494
+ export interface AllDexsClearinghouseStateData {
495
+ user: string;
496
+ clearinghouseStates: [string, ClearinghouseState][];
497
+ }
498
+ export interface AllDexsAssetCtxsData {
499
+ ctxs: [string, WebData3AssetCtx[]][];
500
+ }
501
+ export interface HLWebSocketResponse<T extends HLChannel = HLChannel> {
502
+ channel: T;
503
+ data: HLChannelDataMap[T];
504
+ }
505
+ /**
506
+ * All mids data structure
507
+ */
508
+ export interface WsAllMidsData {
509
+ mids: Record<string, string>;
510
+ }
511
+ /**
512
+ * Asset context data
513
+ */
514
+ export interface AssetCtx {
515
+ funding: string;
516
+ openInterest: string;
517
+ prevDayPx: string;
518
+ dayNtlVlm: string;
519
+ markPx: string;
520
+ midPx?: string;
521
+ impactPxs?: string[];
522
+ oraclePx: string;
523
+ }
524
+ /**
525
+ * Collateral token type
526
+ * 0 = USDC
527
+ * 360 = USDH
528
+ */
529
+ export type CollateralToken = 'USDC' | 'USDH';
530
+ /**
531
+ * Universe asset metadata
532
+ */
533
+ export interface UniverseAsset {
534
+ name: string;
535
+ szDecimals: number;
536
+ maxLeverage: number;
537
+ onlyIsolated?: boolean;
538
+ isDelisted?: boolean;
539
+ marketPrefix?: string;
540
+ collateralToken?: CollateralToken;
541
+ }
542
+ export interface PerpMetaAsset extends UniverseAsset {
543
+ marginTableId: number;
544
+ }
545
+ export interface MarginTier {
546
+ lowerBound: string;
547
+ maxLeverage: number;
548
+ }
549
+ export interface MarginTableDef {
550
+ description: string;
551
+ marginTiers: MarginTier[];
552
+ }
553
+ export type MarginTablesEntry = [number, MarginTableDef];
554
+ export interface AllPerpMetasItem {
555
+ universe: PerpMetaAsset[];
556
+ marginTables: MarginTablesEntry[];
557
+ collateralToken: number;
558
+ }
559
+ export type AllPerpMetasResponse = AllPerpMetasItem[];
560
+ export interface ClearinghouseState {
561
+ assetPositions: AssetPosition[];
562
+ crossMaintenanceMarginUsed: string;
563
+ crossMarginSummary: {
564
+ accountValue: string;
565
+ totalMarginUsed: string;
566
+ totalNtlPos: string;
567
+ totalRawUsd: string;
568
+ };
569
+ marginSummary: {
570
+ accountValue: string;
571
+ totalMarginUsed: string;
572
+ totalNtlPos: string;
573
+ totalRawUsd: string;
574
+ };
575
+ time: number;
576
+ withdrawable: string;
577
+ }
578
+ /**
579
+ * Asset position data
580
+ */
581
+ export interface AssetPosition {
582
+ position: {
583
+ coin: string;
584
+ entryPx?: string;
585
+ leverage: {
586
+ type: string;
587
+ value: number;
588
+ };
589
+ liquidationPx?: string;
590
+ marginUsed: string;
591
+ maxLeverage: number;
592
+ positionValue: string;
593
+ returnOnEquity: string;
594
+ szi: string;
595
+ unrealizedPnl: string;
596
+ cumFunding: {
597
+ allTime: string;
598
+ sinceChange: string;
599
+ sinceOpen: string;
600
+ };
601
+ };
602
+ type: string;
603
+ }
604
+ /**
605
+ * Asset information detail
606
+ */
607
+ export interface AssetInformationDetail {
608
+ name: string;
609
+ funding: string;
610
+ openInterest: string;
611
+ prevDayPx: string;
612
+ dayNtlVlm: string;
613
+ oraclePx: string;
614
+ markPx: string;
615
+ midPx?: string;
616
+ dayBaseVlm: string;
617
+ priceChange: number;
618
+ assetIndex: number;
619
+ }
620
+ /**
621
+ * Raw asset data from open-positions channel
622
+ */
623
+ export interface RawAssetDto {
624
+ coin: string;
625
+ entryPrice: number;
626
+ size: number;
627
+ side: string;
628
+ fundingPaid?: number;
629
+ marketPrefix?: string | null;
630
+ collateralToken?: CollateralToken;
631
+ leverage: number;
632
+ }
633
+ /**
634
+ * Raw position data from open-positions channel
635
+ */
636
+ export interface RawPositionDto {
637
+ positionId: string;
638
+ address: string;
639
+ stopLoss: number | null;
640
+ takeProfit: number | null;
641
+ status: string;
642
+ createdAt: string;
643
+ updatedAt: string;
644
+ longAssets: RawAssetDto[];
645
+ shortAssets: RawAssetDto[];
646
+ }
647
+ /**
648
+ * Leverage information from activeAssetData
649
+ */
650
+ export interface LeverageInfo {
651
+ type: string;
652
+ value: number;
653
+ }
654
+ /**
655
+ * Active asset data from WebSocket
656
+ */
657
+ export interface ActiveAssetData {
658
+ user: string;
659
+ coin: string;
660
+ leverage: LeverageInfo;
661
+ maxTradeSzs: [string, string];
662
+ availableToTrade: [string, string];
663
+ markPx: string;
664
+ }
665
+ export interface TokenMetadata {
666
+ currentPrice: number;
667
+ prevDayPrice: number;
668
+ priceChange24h: number;
669
+ priceChange24hPercent: number;
670
+ netFunding: number;
671
+ maxLeverage: number;
672
+ markPrice: number;
673
+ oraclePrice: number;
674
+ openInterest: string;
675
+ dayVolume: string;
676
+ leverage?: LeverageInfo;
677
+ maxTradeSzs?: [string, string];
678
+ availableToTrade?: [string, string];
679
+ collateralToken?: CollateralToken;
680
+ }
681
+ /**
682
+ * Enhanced token selection with weight and metadata for basket trading
683
+ */
684
+ export interface TokenSelection {
685
+ symbol: string;
686
+ weight: number;
687
+ }
688
+ /**
689
+ * Token conflict information for position conflicts
690
+ */
691
+ export interface TokenConflict {
692
+ symbol: string;
693
+ conflictType: 'long' | 'short';
694
+ conflictMessage: string;
695
+ }
696
+ export interface AssetMarketData {
697
+ asset: WebData3AssetCtx | AssetCtx;
698
+ universe: UniverseAsset;
699
+ }
700
+ /**
701
+ * Nested market data structure for multi-market assets.
702
+ * Each symbol maps to its market variants (keyed by prefix).
703
+ * For non-HIP3 assets, use "default" as the key.
704
+ *
705
+ * @example
706
+ * ```ts
707
+ * {
708
+ * "TSLA": {
709
+ * "xyz": { asset: {...}, universe: { collateralToken: "USDC", ... } },
710
+ * "flx": { asset: {...}, universe: { collateralToken: "USDH", ... } }
711
+ * },
712
+ * "BTC": {
713
+ * "default": { asset: {...}, universe: {...} }
714
+ * }
715
+ * }
716
+ * ```
717
+ */
718
+ export type MarketDataBySymbol = Record<string, Record<string, AssetMarketData>>;
719
+ export interface PairAssetDto {
720
+ asset: string;
721
+ weight: number;
722
+ collateralToken: CollateralToken;
723
+ marketPrefix: string | null;
724
+ }
725
+ export interface ActiveAssetGroupItem {
726
+ longAssets: PairAssetDto[];
727
+ shortAssets: PairAssetDto[];
728
+ openInterest: string;
729
+ volume: string;
730
+ netFunding?: string;
731
+ ratio?: string;
732
+ prevRatio?: string;
733
+ change24h?: string;
734
+ weightedRatio?: string;
735
+ weightedPrevRatio?: string;
736
+ weightedChange24h?: string;
737
+ collateralType: 'USDC' | 'USDH' | 'MIXED';
738
+ }
739
+ export interface ActiveAssetsResponse {
740
+ active: ActiveAssetGroupItem[];
741
+ topGainers: ActiveAssetGroupItem[];
742
+ topLosers: ActiveAssetGroupItem[];
743
+ highlighted: ActiveAssetGroupItem[];
744
+ watchlist: ActiveAssetGroupItem[];
745
+ }
746
+ export interface ActiveAssetsAllResponse {
747
+ active: ActiveAssetGroupItem[];
748
+ all: ActiveAssetGroupItem[];
749
+ highlighted: ActiveAssetGroupItem[];
750
+ watchlist: ActiveAssetGroupItem[];
751
+ }
752
+ /**
753
+ * Candle interval options
754
+ */
755
+ export type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
756
+ /**
757
+ * Candle data structure from WebSocket
758
+ */
759
+ export interface CandleData {
760
+ s?: string;
761
+ t: number;
762
+ T: number;
763
+ o: number;
764
+ c: number;
765
+ h: number;
766
+ l: number;
767
+ }
768
+ /**
769
+ * Candle chart data organized by symbol only
770
+ * Since new candles always have latest timestamp, no need to store per interval
771
+ */
772
+ export type CandleChartData = Map<string, CandleData>;
773
+ /**
774
+ * Historical candle data request
775
+ */
776
+ export interface CandleSnapshotRequest {
777
+ req: {
778
+ coin: string;
779
+ startTime: number;
780
+ endTime: number;
781
+ interval: CandleInterval;
782
+ };
783
+ type: 'candleSnapshot';
784
+ }
785
+ export interface TokenSelectorConfig {
786
+ isLong: boolean;
787
+ index: number;
788
+ }
789
+ export interface SpotBalance {
790
+ coin: string;
791
+ token: number;
792
+ total: string;
793
+ hold: string;
794
+ entryNtl: string;
795
+ }
796
+ export interface SpotState {
797
+ user: string;
798
+ balances: SpotBalance[];
799
+ }