@pear-protocol/hyperliquid-sdk 0.0.72 → 0.0.73-beta-2
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/clients/hyperliquid.d.ts +1 -1
- package/dist/clients/kalshi.d.ts +87 -0
- package/dist/clients/orders.d.ts +41 -0
- package/dist/clients/positions.d.ts +14 -22
- package/dist/clients/watchlist.d.ts +1 -1
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useAllUserBalances.d.ts +9 -0
- package/dist/hooks/useAuth.d.ts +3 -3
- package/dist/hooks/useHyperliquidUserFills.d.ts +17 -0
- package/dist/hooks/useMarketData.d.ts +9 -7
- package/dist/hooks/useOrders.d.ts +2 -3
- package/dist/hooks/useSpotOrder.d.ts +13 -0
- package/dist/hooks/useTrading.d.ts +0 -3
- package/dist/hooks/useWebData.d.ts +21 -3
- package/dist/hyperliquid-websocket.d.ts +2 -1
- package/dist/index.d.ts +490 -95
- package/dist/index.js +1674 -354
- package/dist/provider.d.ts +1 -1
- package/dist/store/historicalPriceDataStore.d.ts +12 -1
- package/dist/store/hyperliquidDataStore.d.ts +31 -1
- package/dist/store/marketDataStore.d.ts +10 -1
- package/dist/store/tokenSelectionMetadataStore.d.ts +1 -1
- package/dist/store/userDataStore.d.ts +30 -1
- package/dist/store/userSelection.d.ts +1 -1
- package/dist/types.d.ts +147 -30
- package/dist/utils/order-helpers.d.ts +57 -0
- package/dist/utils/symbol-translator.d.ts +32 -3
- package/dist/utils/token-metadata-extractor.d.ts +9 -5
- package/package.json +3 -2
- package/dist/hooks/useAutoSyncFills.d.ts +0 -19
package/dist/provider.d.ts
CHANGED
|
@@ -10,5 +10,16 @@ interface TokenHistoricalPriceData {
|
|
|
10
10
|
oldestTime: number | null;
|
|
11
11
|
latestTime: number | null;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
interface HistoricalPriceDataState {
|
|
14
|
+
historicalPriceData: Record<string, TokenHistoricalPriceData>;
|
|
15
|
+
loadingTokens: Set<string>;
|
|
16
|
+
addHistoricalPriceData: (symbol: string, interval: CandleInterval, candles: CandleData[], range: HistoricalRange) => void;
|
|
17
|
+
hasHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => boolean;
|
|
18
|
+
getHistoricalPriceData: (symbol: string, interval: CandleInterval, startTime: number, endTime: number) => CandleData[];
|
|
19
|
+
setTokenLoading: (symbol: string, loading: boolean) => void;
|
|
20
|
+
isTokenLoading: (symbol: string) => boolean;
|
|
21
|
+
removeTokenPriceData: (symbol: string, interval: CandleInterval) => void;
|
|
22
|
+
clearData: () => void;
|
|
23
|
+
}
|
|
24
|
+
export declare const useHistoricalPriceDataStore: import("zustand").UseBoundStore<import("zustand").StoreApi<HistoricalPriceDataState>>;
|
|
14
25
|
export type { HistoricalRange, TokenHistoricalPriceData };
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { ActiveAssetData, CandleChartData, CandleData, ClearinghouseState, UniverseAsset, WebData3AssetCtx, WsAllMidsData } from '../types';
|
|
2
|
+
interface HyperliquidDataState {
|
|
3
|
+
allMids: WsAllMidsData | null;
|
|
4
|
+
activeAssetData: Record<string, ActiveAssetData> | null;
|
|
5
|
+
candleData: CandleChartData | null;
|
|
6
|
+
finalAssetContexts: WebData3AssetCtx[] | null;
|
|
7
|
+
finalAtOICaps: string[] | null;
|
|
8
|
+
aggregatedClearingHouseState: ClearinghouseState | null;
|
|
9
|
+
rawClearinghouseStates: [string, ClearinghouseState][] | null;
|
|
10
|
+
perpMetaAssets: UniverseAsset[] | null;
|
|
11
|
+
allPerpMetaAssets: UniverseAsset[] | null;
|
|
12
|
+
hip3Assets: Map<string, string[]>;
|
|
13
|
+
hip3MarketPrefixes: Map<string, string>;
|
|
14
|
+
setAllMids: (value: WsAllMidsData | null) => void;
|
|
15
|
+
setActiveAssetData: (value: Record<string, ActiveAssetData> | null | ((prev: Record<string, ActiveAssetData> | null) => Record<string, ActiveAssetData> | null)) => void;
|
|
16
|
+
deleteActiveAssetData: (key: string) => void;
|
|
17
|
+
addCandleData: (symbol: string, candle: CandleData) => void;
|
|
18
|
+
deleteCandleSymbol: (symbol: string) => void;
|
|
19
|
+
setCandleData: (value: CandleChartData | null) => void;
|
|
20
|
+
upsertActiveAssetData: (key: string, value: ActiveAssetData) => void;
|
|
21
|
+
setFinalAssetContexts: (value: WebData3AssetCtx[] | null) => void;
|
|
22
|
+
setFinalAtOICaps: (value: string[] | null) => void;
|
|
23
|
+
setAggregatedClearingHouseState: (value: ClearinghouseState | null) => void;
|
|
24
|
+
setRawClearinghouseStates: (value: [string, ClearinghouseState][] | null) => void;
|
|
25
|
+
setPerpMetaAssets: (value: UniverseAsset[] | null) => void;
|
|
26
|
+
setAllPerpMetaAssets: (value: UniverseAsset[] | null) => void;
|
|
27
|
+
setHip3Assets: (value: Map<string, string[]>) => void;
|
|
28
|
+
setHip3MarketPrefixes: (value: Map<string, string>) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare const useHyperliquidData: import("zustand").UseBoundStore<import("zustand").StoreApi<HyperliquidDataState>>;
|
|
31
|
+
export {};
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ActiveAssetsAllResponse, ActiveAssetsResponse } from '../types';
|
|
2
|
+
interface MarketDataState {
|
|
3
|
+
marketData: ActiveAssetsResponse | null;
|
|
4
|
+
marketDataAll: ActiveAssetsAllResponse | null;
|
|
5
|
+
setMarketData: (value: ActiveAssetsResponse | null) => void;
|
|
6
|
+
setMarketDataAll: (value: ActiveAssetsAllResponse | null) => void;
|
|
7
|
+
clean: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const useMarketData: import("zustand").UseBoundStore<import("zustand").StoreApi<MarketDataState>>;
|
|
10
|
+
export {};
|
|
@@ -24,4 +24,4 @@ export interface TokenSelectionMetadataState {
|
|
|
24
24
|
shortTokens: TokenSelection[];
|
|
25
25
|
}) => void;
|
|
26
26
|
}
|
|
27
|
-
export declare const useTokenSelectionMetadataStore:
|
|
27
|
+
export declare const useTokenSelectionMetadataStore: import("zustand").UseBoundStore<import("zustand").StoreApi<TokenSelectionMetadataState>>;
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { PlatformAccountSummaryResponseDto, OpenLimitOrderDto, RawPositionDto, TradeHistoryDataDto, TwapMonitoringDto, NotificationDto, ExtraAgent, SpotState } from "../types";
|
|
2
|
+
interface UserDataState {
|
|
3
|
+
accessToken: string | null;
|
|
4
|
+
refreshToken: string | null;
|
|
5
|
+
isAuthenticated: boolean;
|
|
6
|
+
address: string | null;
|
|
7
|
+
tradeHistories: TradeHistoryDataDto[] | null;
|
|
8
|
+
rawOpenPositions: RawPositionDto[] | null;
|
|
9
|
+
openOrders: OpenLimitOrderDto[] | null;
|
|
10
|
+
accountSummary: PlatformAccountSummaryResponseDto | null;
|
|
11
|
+
twapDetails: TwapMonitoringDto[] | null;
|
|
12
|
+
notifications: NotificationDto[] | null;
|
|
13
|
+
userExtraAgents: ExtraAgent[] | null;
|
|
14
|
+
spotState: SpotState | null;
|
|
15
|
+
setAccessToken: (token: string | null) => void;
|
|
16
|
+
setRefreshToken: (token: string | null) => void;
|
|
17
|
+
setIsAuthenticated: (value: boolean) => void;
|
|
18
|
+
setAddress: (address: string | null) => void;
|
|
19
|
+
setTradeHistories: (value: TradeHistoryDataDto[] | null) => void;
|
|
20
|
+
setRawOpenPositions: (value: RawPositionDto[] | null) => void;
|
|
21
|
+
setOpenOrders: (value: OpenLimitOrderDto[] | null) => void;
|
|
22
|
+
setAccountSummary: (value: PlatformAccountSummaryResponseDto | null) => void;
|
|
23
|
+
setUserExtraAgents: (value: ExtraAgent[] | null) => void;
|
|
24
|
+
setTwapDetails: (value: TwapMonitoringDto[] | null) => void;
|
|
25
|
+
setNotifications: (value: NotificationDto[] | null) => void;
|
|
26
|
+
setSpotState: (value: SpotState | null) => void;
|
|
27
|
+
clean: () => void;
|
|
28
|
+
}
|
|
29
|
+
export declare const useUserData: import("zustand").UseBoundStore<import("zustand").StoreApi<UserDataState>>;
|
|
30
|
+
export {};
|
|
@@ -23,5 +23,5 @@ interface UserSelectionState {
|
|
|
23
23
|
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
24
24
|
resetToDefaults: () => void;
|
|
25
25
|
}
|
|
26
|
-
export declare const useUserSelection:
|
|
26
|
+
export declare const useUserSelection: import("zustand").UseBoundStore<import("zustand").StoreApi<UserSelectionState>>;
|
|
27
27
|
export type { UserSelectionState };
|
package/dist/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ExternalFillDto {
|
|
|
20
20
|
coin: string;
|
|
21
21
|
px: string;
|
|
22
22
|
sz: string;
|
|
23
|
-
side:
|
|
23
|
+
side: 'B' | 'A';
|
|
24
24
|
time: number;
|
|
25
25
|
dir: string;
|
|
26
26
|
fee: string;
|
|
@@ -52,7 +52,7 @@ export interface TwapSliceFillResponseItem {
|
|
|
52
52
|
/**
|
|
53
53
|
* WebSocket connection states
|
|
54
54
|
*/
|
|
55
|
-
export type WebSocketConnectionState =
|
|
55
|
+
export type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
56
56
|
export declare enum ReadyState {
|
|
57
57
|
CONNECTING = 0,
|
|
58
58
|
OPEN = 1,
|
|
@@ -62,12 +62,12 @@ export declare enum ReadyState {
|
|
|
62
62
|
/**
|
|
63
63
|
* WebSocket channels
|
|
64
64
|
*/
|
|
65
|
-
export type WebSocketChannel =
|
|
65
|
+
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'market-data-all' | 'webData3' | 'allMids' | 'activeAssetData';
|
|
66
66
|
/**
|
|
67
67
|
* WebSocket subscription message
|
|
68
68
|
*/
|
|
69
69
|
export interface WebSocketSubscribeMessage {
|
|
70
|
-
action?:
|
|
70
|
+
action?: 'subscribe' | 'unsubscribe';
|
|
71
71
|
address: string;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -97,7 +97,7 @@ export interface WatchlistItemDto {
|
|
|
97
97
|
export interface ToggleWatchlistResponseDto {
|
|
98
98
|
items: WatchlistItemDto[];
|
|
99
99
|
}
|
|
100
|
-
export type NotificationCategory =
|
|
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
101
|
export interface NotificationDto {
|
|
102
102
|
id: string;
|
|
103
103
|
address: string;
|
|
@@ -114,7 +114,7 @@ export interface ChunkFillDto {
|
|
|
114
114
|
size: number;
|
|
115
115
|
executedAt: string;
|
|
116
116
|
}
|
|
117
|
-
export type TwapChunkStatus =
|
|
117
|
+
export type TwapChunkStatus = 'PENDING' | 'SCHEDULED' | 'EXECUTING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
118
118
|
export interface TwapChunkStatusDto {
|
|
119
119
|
chunkId: string;
|
|
120
120
|
chunkIndex: number;
|
|
@@ -125,7 +125,7 @@ export interface TwapChunkStatusDto {
|
|
|
125
125
|
fills: ChunkFillDto[];
|
|
126
126
|
errorMessage?: string;
|
|
127
127
|
}
|
|
128
|
-
export type TwapOrderOverallStatus =
|
|
128
|
+
export type TwapOrderOverallStatus = 'OPEN' | 'EXECUTING' | 'COMPLETED' | 'PARTIALLY_COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
129
129
|
export interface TwapMonitoringDto {
|
|
130
130
|
orderId: string;
|
|
131
131
|
positionId?: string;
|
|
@@ -162,6 +162,8 @@ export interface TradeHistoryAssetDataDto {
|
|
|
162
162
|
externalFeePaid: number;
|
|
163
163
|
builderFeePaid: number;
|
|
164
164
|
realizedPnl: number;
|
|
165
|
+
marketPrefix?: string | null;
|
|
166
|
+
collateralToken?: CollateralToken;
|
|
165
167
|
}
|
|
166
168
|
/**
|
|
167
169
|
* Trade history data structure
|
|
@@ -210,10 +212,15 @@ export interface PositionAssetDetailDto {
|
|
|
210
212
|
liquidationPrice: number;
|
|
211
213
|
initialWeight: number;
|
|
212
214
|
fundingPaid?: number;
|
|
215
|
+
marketPrefix?: string | null;
|
|
216
|
+
collateralToken?: CollateralToken;
|
|
213
217
|
}
|
|
214
218
|
export interface TpSlThreshold {
|
|
215
|
-
type:
|
|
219
|
+
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO';
|
|
216
220
|
value: number;
|
|
221
|
+
isTrailing?: boolean;
|
|
222
|
+
trailingDeltaValue?: number;
|
|
223
|
+
trailingActivationValue?: number;
|
|
217
224
|
}
|
|
218
225
|
/**
|
|
219
226
|
* Open position data structure
|
|
@@ -243,38 +250,96 @@ export interface OpenPositionDto {
|
|
|
243
250
|
export interface OrderAssetDto {
|
|
244
251
|
asset: string;
|
|
245
252
|
weight: number;
|
|
253
|
+
marketPrefix?: string | null;
|
|
254
|
+
collateralToken?: CollateralToken;
|
|
246
255
|
}
|
|
247
256
|
/**
|
|
248
257
|
* Order status
|
|
249
258
|
*/
|
|
250
|
-
export type OrderStatus =
|
|
259
|
+
export type OrderStatus = 'OPEN' | 'PROCESSING' | 'EXECUTED' | 'CANCELLED' | 'FAILED' | 'PARTIALLY_FILLED';
|
|
251
260
|
/**
|
|
252
261
|
* Order type
|
|
253
262
|
*/
|
|
254
|
-
export type OrderType =
|
|
263
|
+
export type OrderType = 'SYNC' | 'MARKET' | 'TRIGGER' | 'TWAP' | 'LADDER' | 'TP' | 'SL' | 'SPOT_MARKET' | 'SPOT_LIMIT' | 'SPOT_TWAP';
|
|
255
264
|
/**
|
|
256
265
|
* TP/SL trigger type
|
|
257
266
|
*/
|
|
258
|
-
export type TpSlTriggerType =
|
|
259
|
-
|
|
267
|
+
export type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO';
|
|
268
|
+
/**
|
|
269
|
+
* Trigger type for trigger orders
|
|
270
|
+
*/
|
|
271
|
+
export type TriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'BTC_DOM' | 'CROSS_ASSET_PRICE' | 'PREDICTION_MARKET_OUTCOME';
|
|
272
|
+
export type OrderDirection = 'MORE_THAN' | 'LESS_THAN';
|
|
273
|
+
/**
|
|
274
|
+
* Market order parameters
|
|
275
|
+
*/
|
|
276
|
+
export interface MarketOrderParameters {
|
|
277
|
+
leverage?: number;
|
|
278
|
+
usdValue: number;
|
|
279
|
+
reduceOnly?: boolean;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Trigger order parameters
|
|
283
|
+
*/
|
|
284
|
+
export interface TriggerOrderParameters {
|
|
285
|
+
leverage: number;
|
|
286
|
+
usdValue: number;
|
|
287
|
+
triggerType: TriggerType;
|
|
288
|
+
triggerValue: number;
|
|
289
|
+
direction: OrderDirection;
|
|
290
|
+
reduceOnly?: boolean;
|
|
291
|
+
assetName?: string;
|
|
292
|
+
marketCode?: string;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* TWAP order parameters
|
|
296
|
+
*/
|
|
297
|
+
export interface TwapOrderParameters {
|
|
298
|
+
leverage: number;
|
|
299
|
+
usdValue: number;
|
|
300
|
+
duration: string;
|
|
301
|
+
intervalSeconds?: number;
|
|
302
|
+
chunkUsdValue: number;
|
|
303
|
+
randomizeExecution?: boolean;
|
|
304
|
+
reduceOnly?: boolean;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* TP/SL order parameters
|
|
308
|
+
*/
|
|
309
|
+
export interface TpSlOrderParameters {
|
|
310
|
+
triggerType: TpSlTriggerType;
|
|
311
|
+
triggerValue: number;
|
|
312
|
+
isTrailing?: boolean;
|
|
313
|
+
trailingDeltaValue?: number;
|
|
314
|
+
trailingActivationValue?: number;
|
|
315
|
+
reduceOnly?: boolean;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Ladder order parameters
|
|
319
|
+
*/
|
|
320
|
+
export interface LadderOrderParameters {
|
|
321
|
+
leverage: number;
|
|
322
|
+
usdValue: number;
|
|
323
|
+
ratioStart: number;
|
|
324
|
+
ratioEnd: number;
|
|
325
|
+
numberOfLevels: number;
|
|
326
|
+
reduceOnly?: boolean;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Union type for all order parameters
|
|
330
|
+
*/
|
|
331
|
+
export type OrderParameters = MarketOrderParameters | TriggerOrderParameters | TwapOrderParameters | TpSlOrderParameters | LadderOrderParameters;
|
|
260
332
|
/**
|
|
261
333
|
* Open limit order data structure
|
|
262
334
|
*/
|
|
263
335
|
export interface OpenLimitOrderDto {
|
|
264
336
|
orderId: string;
|
|
265
337
|
address: string;
|
|
266
|
-
clientId
|
|
338
|
+
clientId?: string | null;
|
|
267
339
|
positionId?: string | null;
|
|
268
|
-
|
|
269
|
-
usdValue: number;
|
|
270
|
-
triggerValue?: number | null;
|
|
271
|
-
twapDuration?: string | null;
|
|
272
|
-
tpSlTriggerType?: TpSlTriggerType | null;
|
|
273
|
-
randomizeFlag: boolean;
|
|
274
|
-
reduceOnlyFlag: boolean;
|
|
275
|
-
status: OrderStatus;
|
|
340
|
+
parameters: OrderParameters;
|
|
276
341
|
orderType: OrderType;
|
|
277
|
-
|
|
342
|
+
status: OrderStatus;
|
|
278
343
|
longAssets: OrderAssetDto[];
|
|
279
344
|
shortAssets: OrderAssetDto[];
|
|
280
345
|
createdAt: string;
|
|
@@ -370,7 +435,7 @@ export interface PrivyAuthDetails {
|
|
|
370
435
|
accessToken: string;
|
|
371
436
|
}
|
|
372
437
|
export interface AuthenticateRequest {
|
|
373
|
-
method:
|
|
438
|
+
method: 'eip712' | 'api_key' | 'privy_access_token';
|
|
374
439
|
address: string;
|
|
375
440
|
clientId: string;
|
|
376
441
|
details: {
|
|
@@ -403,7 +468,7 @@ export interface LogoutRequest {
|
|
|
403
468
|
export interface LogoutResponse {
|
|
404
469
|
message: string;
|
|
405
470
|
}
|
|
406
|
-
export type AgentWalletStatus =
|
|
471
|
+
export type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
|
|
407
472
|
export interface GetAgentWalletResponseDto {
|
|
408
473
|
agentWalletAddress?: string;
|
|
409
474
|
agentName: string;
|
|
@@ -421,14 +486,14 @@ export interface ExtraAgent {
|
|
|
421
486
|
export interface AgentWalletState {
|
|
422
487
|
address: string | null;
|
|
423
488
|
name: string | null;
|
|
424
|
-
status: AgentWalletStatus |
|
|
489
|
+
status: AgentWalletStatus | 'PENDING' | null;
|
|
425
490
|
isActive: boolean;
|
|
426
491
|
}
|
|
427
492
|
/**
|
|
428
493
|
* WebSocket message from HyperLiquid native API
|
|
429
494
|
*/
|
|
430
495
|
export interface WebSocketMessage {
|
|
431
|
-
method:
|
|
496
|
+
method: 'subscribe' | 'unsubscribe';
|
|
432
497
|
subscription: {
|
|
433
498
|
type: string;
|
|
434
499
|
dex?: string;
|
|
@@ -441,14 +506,19 @@ export interface WebSocketMessage {
|
|
|
441
506
|
/**
|
|
442
507
|
* WebSocket response from HyperLiquid native API
|
|
443
508
|
*/
|
|
444
|
-
export type HLChannel =
|
|
509
|
+
export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle' | 'spotState' | 'allDexsClearinghouseState' | 'allDexsAssetCtxs' | 'userFills';
|
|
445
510
|
export interface HLChannelDataMap {
|
|
446
511
|
webData3: WebData3Response;
|
|
447
512
|
allMids: WsAllMidsData;
|
|
448
513
|
activeAssetData: ActiveAssetData;
|
|
449
514
|
candle: CandleData;
|
|
515
|
+
spotState: {
|
|
516
|
+
user: string;
|
|
517
|
+
spotState: SpotState;
|
|
518
|
+
};
|
|
450
519
|
allDexsClearinghouseState: AllDexsClearinghouseStateData;
|
|
451
520
|
allDexsAssetCtxs: AllDexsAssetCtxsData;
|
|
521
|
+
userFills: any;
|
|
452
522
|
}
|
|
453
523
|
export interface WebData3UserState {
|
|
454
524
|
agentAddress?: string;
|
|
@@ -511,6 +581,12 @@ export interface AssetCtx {
|
|
|
511
581
|
impactPxs?: string[];
|
|
512
582
|
oraclePx: string;
|
|
513
583
|
}
|
|
584
|
+
/**
|
|
585
|
+
* Collateral token type
|
|
586
|
+
* 0 = USDC
|
|
587
|
+
* 360 = USDH
|
|
588
|
+
*/
|
|
589
|
+
export type CollateralToken = 'USDC' | 'USDH';
|
|
514
590
|
/**
|
|
515
591
|
* Universe asset metadata
|
|
516
592
|
*/
|
|
@@ -520,6 +596,8 @@ export interface UniverseAsset {
|
|
|
520
596
|
maxLeverage: number;
|
|
521
597
|
onlyIsolated?: boolean;
|
|
522
598
|
isDelisted?: boolean;
|
|
599
|
+
marketPrefix?: string;
|
|
600
|
+
collateralToken?: CollateralToken;
|
|
523
601
|
}
|
|
524
602
|
export interface PerpMetaAsset extends UniverseAsset {
|
|
525
603
|
marginTableId: number;
|
|
@@ -608,6 +686,8 @@ export interface RawAssetDto {
|
|
|
608
686
|
size: number;
|
|
609
687
|
side: string;
|
|
610
688
|
fundingPaid?: number;
|
|
689
|
+
marketPrefix?: string | null;
|
|
690
|
+
collateralToken?: CollateralToken;
|
|
611
691
|
leverage: number;
|
|
612
692
|
}
|
|
613
693
|
/**
|
|
@@ -656,6 +736,7 @@ export interface TokenMetadata {
|
|
|
656
736
|
leverage?: LeverageInfo;
|
|
657
737
|
maxTradeSzs?: [string, string];
|
|
658
738
|
availableToTrade?: [string, string];
|
|
739
|
+
collateralToken?: CollateralToken;
|
|
659
740
|
}
|
|
660
741
|
/**
|
|
661
742
|
* Enhanced token selection with weight and metadata for basket trading
|
|
@@ -669,16 +750,37 @@ export interface TokenSelection {
|
|
|
669
750
|
*/
|
|
670
751
|
export interface TokenConflict {
|
|
671
752
|
symbol: string;
|
|
672
|
-
conflictType:
|
|
753
|
+
conflictType: 'long' | 'short';
|
|
673
754
|
conflictMessage: string;
|
|
674
755
|
}
|
|
675
756
|
export interface AssetMarketData {
|
|
676
757
|
asset: WebData3AssetCtx | AssetCtx;
|
|
677
758
|
universe: UniverseAsset;
|
|
678
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Nested market data structure for multi-market assets.
|
|
762
|
+
* Each symbol maps to its market variants (keyed by prefix).
|
|
763
|
+
* For non-HIP3 assets, use "default" as the key.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```ts
|
|
767
|
+
* {
|
|
768
|
+
* "TSLA": {
|
|
769
|
+
* "xyz": { asset: {...}, universe: { collateralToken: "USDC", ... } },
|
|
770
|
+
* "flx": { asset: {...}, universe: { collateralToken: "USDH", ... } }
|
|
771
|
+
* },
|
|
772
|
+
* "BTC": {
|
|
773
|
+
* "default": { asset: {...}, universe: {...} }
|
|
774
|
+
* }
|
|
775
|
+
* }
|
|
776
|
+
* ```
|
|
777
|
+
*/
|
|
778
|
+
export type MarketDataBySymbol = Record<string, Record<string, AssetMarketData>>;
|
|
679
779
|
export interface PairAssetDto {
|
|
680
780
|
asset: string;
|
|
681
781
|
weight: number;
|
|
782
|
+
collateralToken: CollateralToken;
|
|
783
|
+
marketPrefix: string | null;
|
|
682
784
|
}
|
|
683
785
|
export interface ActiveAssetGroupItem {
|
|
684
786
|
longAssets: PairAssetDto[];
|
|
@@ -692,6 +794,7 @@ export interface ActiveAssetGroupItem {
|
|
|
692
794
|
weightedRatio?: string;
|
|
693
795
|
weightedPrevRatio?: string;
|
|
694
796
|
weightedChange24h?: string;
|
|
797
|
+
collateralType: 'USDC' | 'USDH' | 'MIXED';
|
|
695
798
|
}
|
|
696
799
|
export interface ActiveAssetsResponse {
|
|
697
800
|
active: ActiveAssetGroupItem[];
|
|
@@ -709,7 +812,7 @@ export interface ActiveAssetsAllResponse {
|
|
|
709
812
|
/**
|
|
710
813
|
* Candle interval options
|
|
711
814
|
*/
|
|
712
|
-
export type CandleInterval =
|
|
815
|
+
export type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
713
816
|
/**
|
|
714
817
|
* Candle data structure from WebSocket
|
|
715
818
|
*/
|
|
@@ -737,9 +840,23 @@ export interface CandleSnapshotRequest {
|
|
|
737
840
|
endTime: number;
|
|
738
841
|
interval: CandleInterval;
|
|
739
842
|
};
|
|
740
|
-
type:
|
|
843
|
+
type: 'candleSnapshot';
|
|
741
844
|
}
|
|
742
845
|
export interface TokenSelectorConfig {
|
|
743
846
|
isLong: boolean;
|
|
744
847
|
index: number;
|
|
745
848
|
}
|
|
849
|
+
export interface SpotBalance {
|
|
850
|
+
coin: string;
|
|
851
|
+
token: number;
|
|
852
|
+
total: string;
|
|
853
|
+
hold: string;
|
|
854
|
+
entryNtl: string;
|
|
855
|
+
}
|
|
856
|
+
export interface SpotState {
|
|
857
|
+
user: string;
|
|
858
|
+
balances: SpotBalance[];
|
|
859
|
+
}
|
|
860
|
+
export interface EnrichedOpenLimitOrderDto extends OpenLimitOrderDto {
|
|
861
|
+
marketTitle?: string;
|
|
862
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { OpenLimitOrderDto, TpSlTriggerType, TriggerType, OrderDirection } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions to safely extract values from order parameters
|
|
4
|
+
* based on the order type and parameter structure.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Get leverage from order parameters (available for Market, Trigger, Twap, Ladder orders)
|
|
8
|
+
*/
|
|
9
|
+
export declare function getOrderLeverage(order: OpenLimitOrderDto): number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Get USD value from order parameters (available for Market, Trigger, Twap, Ladder orders)
|
|
12
|
+
*/
|
|
13
|
+
export declare function getOrderUsdValue(order: OpenLimitOrderDto): number | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Get trigger value from order parameters (available for TP/SL and Trigger orders)
|
|
16
|
+
*/
|
|
17
|
+
export declare function getOrderTriggerValue(order: OpenLimitOrderDto): number | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get TP/SL trigger type from order parameters (only for TP/SL orders)
|
|
20
|
+
*/
|
|
21
|
+
export declare function getOrderTpSlTriggerType(order: OpenLimitOrderDto): TpSlTriggerType | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Get trigger type from order parameters (for Trigger orders)
|
|
24
|
+
*/
|
|
25
|
+
export declare function getOrderTriggerType(order: OpenLimitOrderDto): TriggerType | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Get order direction from order parameters (for Trigger orders)
|
|
28
|
+
*/
|
|
29
|
+
export declare function getOrderDirection(order: OpenLimitOrderDto): OrderDirection | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Get reduce only flag from order parameters (available for all order types)
|
|
32
|
+
*/
|
|
33
|
+
export declare function getOrderReduceOnly(order: OpenLimitOrderDto): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Get TWAP duration from order parameters (only for TWAP orders)
|
|
36
|
+
*/
|
|
37
|
+
export declare function getOrderTwapDuration(order: OpenLimitOrderDto): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Get ladder config from order parameters (only for Ladder orders)
|
|
40
|
+
*/
|
|
41
|
+
export declare function getOrderLadderConfig(order: OpenLimitOrderDto): {
|
|
42
|
+
ratioStart: number;
|
|
43
|
+
ratioEnd: number;
|
|
44
|
+
numberOfLevels: number;
|
|
45
|
+
} | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Check if the order is a BTC Dominance trigger order
|
|
48
|
+
*/
|
|
49
|
+
export declare function isBtcDomOrder(order: OpenLimitOrderDto): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Get trailing info from TP/SL order parameters
|
|
52
|
+
*/
|
|
53
|
+
export declare function getOrderTrailingInfo(order: OpenLimitOrderDto): {
|
|
54
|
+
isTrailing: boolean;
|
|
55
|
+
trailingDeltaValue?: number;
|
|
56
|
+
trailingActivationValue?: number;
|
|
57
|
+
} | undefined;
|
|
@@ -5,7 +5,36 @@ export declare function toDisplaySymbol(symbol: string): string;
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert a display symbol back to backend form using a provided map.
|
|
7
7
|
* If mapping is missing, returns the original symbol.
|
|
8
|
-
*
|
|
9
|
-
* @param
|
|
8
|
+
* For multi-market assets, returns the first available market.
|
|
9
|
+
* @param displaySymbol e.g., "TSLA"
|
|
10
|
+
* @param hip3Assets map of display -> all full market names (e.g., "TSLA" -> ["xyz:TSLA", "flx:TSLA"])
|
|
10
11
|
*/
|
|
11
|
-
export declare function toBackendSymbol(displaySymbol: string,
|
|
12
|
+
export declare function toBackendSymbol(displaySymbol: string, hip3Assets: Map<string, string[]>): string;
|
|
13
|
+
/**
|
|
14
|
+
* Convert a display symbol to backend form for a specific market prefix.
|
|
15
|
+
* This is useful when an asset is available on multiple markets (e.g., xyz:TSLA and flx:TSLA).
|
|
16
|
+
* @param displaySymbol e.g., "TSLA"
|
|
17
|
+
* @param marketPrefix e.g., "xyz" or "flx"
|
|
18
|
+
* @param hip3Assets map of display -> all full market names
|
|
19
|
+
* @returns Full market name if found, null if prefix not specified for multi-market asset, otherwise displaySymbol with prefix
|
|
20
|
+
*/
|
|
21
|
+
export declare function toBackendSymbolWithMarket(displaySymbol: string, marketPrefix: string | undefined, hip3Assets: Map<string, string[]>): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Get all available markets for a display symbol.
|
|
24
|
+
* @param displaySymbol e.g., "TSLA"
|
|
25
|
+
* @param hip3Assets map of display -> all full market names
|
|
26
|
+
* @returns Array of full market names, e.g., ["xyz:TSLA", "flx:TSLA"]
|
|
27
|
+
*/
|
|
28
|
+
export declare function getAvailableMarkets(displaySymbol: string, hip3Assets: Map<string, string[]>): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Extract the market prefix from a full market name.
|
|
31
|
+
* @param fullSymbol e.g., "xyz:TSLA"
|
|
32
|
+
* @returns The prefix (e.g., "xyz") or undefined if no prefix
|
|
33
|
+
*/
|
|
34
|
+
export declare function getMarketPrefix(fullSymbol: string): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a symbol is a HIP-3 market (has a prefix).
|
|
37
|
+
* @param symbol e.g., "xyz:TSLA" or "TSLA"
|
|
38
|
+
* @returns true if the symbol has a market prefix
|
|
39
|
+
*/
|
|
40
|
+
export declare function isHip3Market(symbol: string): boolean;
|
|
@@ -5,24 +5,28 @@ import type { WsAllMidsData, TokenMetadata, ActiveAssetData, UniverseAsset, WebD
|
|
|
5
5
|
export declare class TokenMetadataExtractor {
|
|
6
6
|
/**
|
|
7
7
|
* Extracts comprehensive token metadata
|
|
8
|
-
* @param symbol - Token symbol
|
|
8
|
+
* @param symbol - Token symbol (base symbol without prefix, e.g., "TSLA")
|
|
9
9
|
* @param perpMetaAssets - Aggregated universe assets (flattened across dexes)
|
|
10
10
|
* @param finalAssetContexts - Aggregated asset contexts (flattened across dexes)
|
|
11
11
|
* @param allMids - AllMids data containing current prices
|
|
12
12
|
* @param activeAssetData - Optional active asset data containing leverage information
|
|
13
|
+
* @param marketPrefix - Optional market prefix (e.g., "xyz", "flx") for HIP3 multi-market assets
|
|
13
14
|
* @returns TokenMetadata or null if token not found
|
|
14
15
|
*/
|
|
15
|
-
static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): TokenMetadata | null;
|
|
16
|
+
static extractTokenMetadata(symbol: string, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null, marketPrefix?: string | null): TokenMetadata | null;
|
|
16
17
|
/**
|
|
17
18
|
* Extracts metadata for multiple tokens
|
|
18
|
-
* @param
|
|
19
|
+
* @param tokens - Array of token objects with symbol and optional marketPrefix
|
|
19
20
|
* @param perpMetaAssets - Aggregated universe assets
|
|
20
21
|
* @param finalAssetContexts - Aggregated asset contexts
|
|
21
22
|
* @param allMids - AllMids data
|
|
22
23
|
* @param activeAssetData - Optional active asset data containing leverage information
|
|
23
|
-
* @returns Record of
|
|
24
|
+
* @returns Record of unique key to TokenMetadata. Key is "{prefix}:{symbol}" for HIP3 assets, or just "{symbol}" otherwise
|
|
24
25
|
*/
|
|
25
|
-
static extractMultipleTokensMetadata(
|
|
26
|
+
static extractMultipleTokensMetadata(tokens: Array<{
|
|
27
|
+
symbol: string;
|
|
28
|
+
marketPrefix?: string | null;
|
|
29
|
+
}>, perpMetaAssets: UniverseAsset[] | null, finalAssetContexts: WebData3AssetCtx[] | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): Record<string, TokenMetadata | null>;
|
|
26
30
|
/**
|
|
27
31
|
* Checks if token data is available in aggregated universe assets
|
|
28
32
|
* @param symbol - Token symbol
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.73-beta-2",
|
|
4
4
|
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"clean": "rimraf dist"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "^1.6.0"
|
|
27
|
+
"axios": "^1.6.0",
|
|
28
|
+
"zustand": "^5.0.9"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"react": "^18.0.0",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { SyncFillsResponseDto } from '../types';
|
|
2
|
-
export interface AutoSyncFillsOptions {
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
address: string | null;
|
|
5
|
-
intervalMs?: number;
|
|
6
|
-
aggregateByTime?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface AutoSyncFillsState {
|
|
9
|
-
lastRunAt: number | null;
|
|
10
|
-
lastResult: SyncFillsResponseDto | null;
|
|
11
|
-
error: string | null;
|
|
12
|
-
isSyncing: boolean;
|
|
13
|
-
triggerSync: () => Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Listens to address changes and periodically syncs user fills
|
|
17
|
-
* Defaults: aggregate=true, interval=60s
|
|
18
|
-
*/
|
|
19
|
-
export declare function useAutoSyncFills(options: AutoSyncFillsOptions): AutoSyncFillsState;
|