@pear-protocol/hyperliquid-sdk 0.0.60-beta-usdh-3 → 0.0.60-beta-usdh-4
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/hooks/index.d.ts +1 -0
- package/dist/hooks/useSpotBalances.d.ts +7 -0
- package/dist/index.d.ts +41 -19
- package/dist/index.js +75 -1
- package/dist/types.d.ts +33 -18
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ interface ExternalFillDto {
|
|
|
47
47
|
coin: string;
|
|
48
48
|
px: string;
|
|
49
49
|
sz: string;
|
|
50
|
-
side:
|
|
50
|
+
side: 'B' | 'A';
|
|
51
51
|
time: number;
|
|
52
52
|
dir: string;
|
|
53
53
|
fee: string;
|
|
@@ -74,16 +74,16 @@ interface TwapSliceFillResponseItem {
|
|
|
74
74
|
/**
|
|
75
75
|
* WebSocket connection states
|
|
76
76
|
*/
|
|
77
|
-
type WebSocketConnectionState =
|
|
77
|
+
type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
78
78
|
/**
|
|
79
79
|
* WebSocket channels
|
|
80
80
|
*/
|
|
81
|
-
type WebSocketChannel =
|
|
81
|
+
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'market-data-all' | 'webData3' | 'allMids' | 'activeAssetData';
|
|
82
82
|
/**
|
|
83
83
|
* WebSocket subscription message
|
|
84
84
|
*/
|
|
85
85
|
interface WebSocketSubscribeMessage {
|
|
86
|
-
action?:
|
|
86
|
+
action?: 'subscribe' | 'unsubscribe';
|
|
87
87
|
address: string;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
@@ -113,7 +113,7 @@ interface WatchlistItemDto {
|
|
|
113
113
|
interface ToggleWatchlistResponseDto {
|
|
114
114
|
items: WatchlistItemDto[];
|
|
115
115
|
}
|
|
116
|
-
type NotificationCategory =
|
|
116
|
+
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';
|
|
117
117
|
interface NotificationDto {
|
|
118
118
|
id: string;
|
|
119
119
|
address: string;
|
|
@@ -130,7 +130,7 @@ interface ChunkFillDto {
|
|
|
130
130
|
size: number;
|
|
131
131
|
executedAt: string;
|
|
132
132
|
}
|
|
133
|
-
type TwapChunkStatus =
|
|
133
|
+
type TwapChunkStatus = 'PENDING' | 'SCHEDULED' | 'EXECUTING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
134
134
|
interface TwapChunkStatusDto {
|
|
135
135
|
chunkId: string;
|
|
136
136
|
chunkIndex: number;
|
|
@@ -141,7 +141,7 @@ interface TwapChunkStatusDto {
|
|
|
141
141
|
fills: ChunkFillDto[];
|
|
142
142
|
errorMessage?: string;
|
|
143
143
|
}
|
|
144
|
-
type TwapOrderOverallStatus =
|
|
144
|
+
type TwapOrderOverallStatus = 'OPEN' | 'EXECUTING' | 'COMPLETED' | 'PARTIALLY_COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
145
145
|
interface TwapMonitoringDto {
|
|
146
146
|
orderId: string;
|
|
147
147
|
positionId?: string;
|
|
@@ -232,7 +232,7 @@ interface PositionAssetDetailDto {
|
|
|
232
232
|
collateralToken?: CollateralToken;
|
|
233
233
|
}
|
|
234
234
|
interface TpSlThreshold {
|
|
235
|
-
type:
|
|
235
|
+
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
236
236
|
value: number;
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
@@ -267,16 +267,16 @@ interface OrderAssetDto {
|
|
|
267
267
|
/**
|
|
268
268
|
* Order status
|
|
269
269
|
*/
|
|
270
|
-
type OrderStatus =
|
|
270
|
+
type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
|
|
271
271
|
/**
|
|
272
272
|
* Order type
|
|
273
273
|
*/
|
|
274
|
-
type OrderType =
|
|
274
|
+
type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET' | 'LIMIT_BTCDOM' | 'TWAP';
|
|
275
275
|
/**
|
|
276
276
|
* TP/SL trigger type
|
|
277
277
|
*/
|
|
278
|
-
type TpSlTriggerType =
|
|
279
|
-
type OrderDirection =
|
|
278
|
+
type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
279
|
+
type OrderDirection = 'MORE_THAN' | 'LESS_THAN' | null;
|
|
280
280
|
/**
|
|
281
281
|
* Open limit order data structure
|
|
282
282
|
*/
|
|
@@ -382,7 +382,7 @@ interface RefreshTokenResponse {
|
|
|
382
382
|
tokenType: string;
|
|
383
383
|
expiresIn: number;
|
|
384
384
|
}
|
|
385
|
-
type AgentWalletStatus =
|
|
385
|
+
type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
|
|
386
386
|
interface CreateAgentWalletResponseDto {
|
|
387
387
|
agentWalletAddress: string;
|
|
388
388
|
message: string;
|
|
@@ -395,7 +395,7 @@ interface ExtraAgent {
|
|
|
395
395
|
interface AgentWalletState {
|
|
396
396
|
address: string | null;
|
|
397
397
|
name: string | null;
|
|
398
|
-
status: AgentWalletStatus |
|
|
398
|
+
status: AgentWalletStatus | 'PENDING' | null;
|
|
399
399
|
isActive: boolean;
|
|
400
400
|
}
|
|
401
401
|
/**
|
|
@@ -415,12 +415,16 @@ interface WebSocketMessage {
|
|
|
415
415
|
/**
|
|
416
416
|
* WebSocket response from HyperLiquid native API
|
|
417
417
|
*/
|
|
418
|
-
type HLChannel =
|
|
418
|
+
type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle' | 'spotState';
|
|
419
419
|
interface HLChannelDataMap {
|
|
420
420
|
webData3: WebData3Response;
|
|
421
421
|
allMids: WsAllMidsData;
|
|
422
422
|
activeAssetData: ActiveAssetData;
|
|
423
423
|
candle: CandleData;
|
|
424
|
+
spotState: {
|
|
425
|
+
user: string;
|
|
426
|
+
spotState: SpotState;
|
|
427
|
+
};
|
|
424
428
|
}
|
|
425
429
|
interface WebData3UserState {
|
|
426
430
|
agentAddress?: string;
|
|
@@ -624,7 +628,7 @@ interface TokenSelection {
|
|
|
624
628
|
*/
|
|
625
629
|
interface TokenConflict {
|
|
626
630
|
symbol: string;
|
|
627
|
-
conflictType:
|
|
631
|
+
conflictType: 'long' | 'short';
|
|
628
632
|
conflictMessage: string;
|
|
629
633
|
}
|
|
630
634
|
interface AssetMarketData {
|
|
@@ -686,7 +690,7 @@ interface ActiveAssetsAllResponse {
|
|
|
686
690
|
/**
|
|
687
691
|
* Candle interval options
|
|
688
692
|
*/
|
|
689
|
-
type CandleInterval =
|
|
693
|
+
type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
690
694
|
/**
|
|
691
695
|
* Candle data structure from WebSocket
|
|
692
696
|
*/
|
|
@@ -720,6 +724,17 @@ interface TokenSelectorConfig {
|
|
|
720
724
|
isLong: boolean;
|
|
721
725
|
index: number;
|
|
722
726
|
}
|
|
727
|
+
interface SpotBalance {
|
|
728
|
+
coin: string;
|
|
729
|
+
token: number;
|
|
730
|
+
total: string;
|
|
731
|
+
hold: string;
|
|
732
|
+
entryNtl: string;
|
|
733
|
+
}
|
|
734
|
+
interface SpotState {
|
|
735
|
+
user: string;
|
|
736
|
+
balances: SpotBalance[];
|
|
737
|
+
}
|
|
723
738
|
|
|
724
739
|
declare const useAccountSummary: () => {
|
|
725
740
|
data: AccountSummaryResponseDto | null;
|
|
@@ -1225,6 +1240,13 @@ declare function useAuth(): {
|
|
|
1225
1240
|
readonly logout: () => Promise<void>;
|
|
1226
1241
|
};
|
|
1227
1242
|
|
|
1243
|
+
interface SpotBalances {
|
|
1244
|
+
usdhBalance: number | undefined;
|
|
1245
|
+
spotUsdcBalance: number | undefined;
|
|
1246
|
+
isLoading: boolean;
|
|
1247
|
+
}
|
|
1248
|
+
declare const useSpotBalances: () => SpotBalances;
|
|
1249
|
+
|
|
1228
1250
|
interface UseHyperliquidWebSocketProps {
|
|
1229
1251
|
wsUrl: string;
|
|
1230
1252
|
address: string | null;
|
|
@@ -1446,5 +1468,5 @@ declare function isHip3Market(symbol: string): boolean;
|
|
|
1446
1468
|
|
|
1447
1469
|
declare const useMarketData: any;
|
|
1448
1470
|
|
|
1449
|
-
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1450
|
-
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1471
|
+
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotBalances, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1472
|
+
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotBalance, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const useUserData = create((set) => ({
|
|
|
23
23
|
twapDetails: null,
|
|
24
24
|
notifications: null,
|
|
25
25
|
userExtraAgents: null,
|
|
26
|
+
spotState: null,
|
|
26
27
|
setAccessToken: (token) => set({ accessToken: token }),
|
|
27
28
|
setRefreshToken: (token) => set({ refreshToken: token }),
|
|
28
29
|
setIsAuthenticated: (value) => set({ isAuthenticated: value }),
|
|
@@ -43,6 +44,7 @@ const useUserData = create((set) => ({
|
|
|
43
44
|
setAccountSummary: (value) => set({ accountSummary: value }),
|
|
44
45
|
setTwapDetails: (value) => set({ twapDetails: value }),
|
|
45
46
|
setNotifications: (value) => set({ notifications: value }),
|
|
47
|
+
setSpotState: (value) => set({ spotState: value }),
|
|
46
48
|
clean: () => set({
|
|
47
49
|
accessToken: null,
|
|
48
50
|
refreshToken: null,
|
|
@@ -54,6 +56,7 @@ const useUserData = create((set) => ({
|
|
|
54
56
|
accountSummary: null,
|
|
55
57
|
twapDetails: null,
|
|
56
58
|
notifications: null,
|
|
59
|
+
spotState: null,
|
|
57
60
|
}),
|
|
58
61
|
setUserExtraAgents: (value) => set({ userExtraAgents: value }),
|
|
59
62
|
}));
|
|
@@ -559,6 +562,7 @@ const useUserSelection$1 = create((set, get) => ({
|
|
|
559
562
|
|
|
560
563
|
const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
561
564
|
const { setAllMids, setActiveAssetData, upsertActiveAssetData, setCandleData, deleteCandleSymbol, deleteActiveAssetData, addCandleData, setFinalAssetContexts, setFinalAtOICaps, setAggregatedClearingHouseState, } = useHyperliquidData();
|
|
565
|
+
const { setSpotState } = useUserData();
|
|
562
566
|
const { candleInterval } = useUserSelection$1();
|
|
563
567
|
const longTokens = useUserSelection$1((s) => s.longTokens);
|
|
564
568
|
const shortTokens = useUserSelection$1((s) => s.shortTokens);
|
|
@@ -680,6 +684,14 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
680
684
|
addCandleData(symbol, normalized);
|
|
681
685
|
}
|
|
682
686
|
break;
|
|
687
|
+
case 'spotState':
|
|
688
|
+
{
|
|
689
|
+
const spotStateData = response.data;
|
|
690
|
+
if (spotStateData === null || spotStateData === void 0 ? void 0 : spotStateData.spotState) {
|
|
691
|
+
setSpotState(spotStateData.spotState);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
break;
|
|
683
695
|
default:
|
|
684
696
|
console.warn(`[HyperLiquid WS] Unknown channel: ${response.channel}`);
|
|
685
697
|
}
|
|
@@ -697,6 +709,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
697
709
|
setFinalAssetContexts,
|
|
698
710
|
setFinalAtOICaps,
|
|
699
711
|
setAggregatedClearingHouseState,
|
|
712
|
+
setSpotState,
|
|
700
713
|
]);
|
|
701
714
|
const connect = useCallback(() => {
|
|
702
715
|
if (!enabled)
|
|
@@ -795,6 +808,17 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
795
808
|
},
|
|
796
809
|
};
|
|
797
810
|
sendJsonMessage(unsubscribeMessage);
|
|
811
|
+
// Unsubscribe from spotState for previous address
|
|
812
|
+
if (subscribedAddress !== DEFAULT_ADDRESS) {
|
|
813
|
+
const unsubscribeSpotState = {
|
|
814
|
+
method: 'unsubscribe',
|
|
815
|
+
subscription: {
|
|
816
|
+
type: 'spotState',
|
|
817
|
+
user: subscribedAddress,
|
|
818
|
+
},
|
|
819
|
+
};
|
|
820
|
+
sendJsonMessage(unsubscribeSpotState);
|
|
821
|
+
}
|
|
798
822
|
}
|
|
799
823
|
// Subscribe to webData3 with new address
|
|
800
824
|
const subscribeWebData3 = {
|
|
@@ -814,11 +838,25 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
814
838
|
};
|
|
815
839
|
sendJsonMessage(subscribeWebData3);
|
|
816
840
|
sendJsonMessage(subscribeAllMids);
|
|
841
|
+
// Subscribe to spotState for real-time spot balances (USDH, USDC, etc.)
|
|
842
|
+
// Only subscribe if we have a real user address (not the default)
|
|
843
|
+
if (userAddress !== DEFAULT_ADDRESS) {
|
|
844
|
+
const subscribeSpotState = {
|
|
845
|
+
method: 'subscribe',
|
|
846
|
+
subscription: {
|
|
847
|
+
type: 'spotState',
|
|
848
|
+
user: userAddress,
|
|
849
|
+
},
|
|
850
|
+
};
|
|
851
|
+
sendJsonMessage(subscribeSpotState);
|
|
852
|
+
}
|
|
817
853
|
setSubscribedAddress(userAddress);
|
|
818
854
|
// Clear previous data when address changes
|
|
819
855
|
if (subscribedAddress && subscribedAddress !== userAddress) {
|
|
820
856
|
// clear aggregatedClearingHouseState
|
|
821
857
|
setAggregatedClearingHouseState(null);
|
|
858
|
+
// clear spotState
|
|
859
|
+
setSpotState(null);
|
|
822
860
|
}
|
|
823
861
|
}, [
|
|
824
862
|
isConnected,
|
|
@@ -826,6 +864,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
826
864
|
subscribedAddress,
|
|
827
865
|
sendJsonMessage,
|
|
828
866
|
setAggregatedClearingHouseState,
|
|
867
|
+
setSpotState,
|
|
829
868
|
]);
|
|
830
869
|
// Handle token subscriptions for activeAssetData
|
|
831
870
|
useEffect(() => {
|
|
@@ -7701,6 +7740,35 @@ function useAuth() {
|
|
|
7701
7740
|
};
|
|
7702
7741
|
}
|
|
7703
7742
|
|
|
7743
|
+
const useSpotBalances = () => {
|
|
7744
|
+
const spotState = useUserData((state) => state.spotState);
|
|
7745
|
+
return useMemo(() => {
|
|
7746
|
+
if (!spotState) {
|
|
7747
|
+
return {
|
|
7748
|
+
usdhBalance: undefined,
|
|
7749
|
+
spotUsdcBalance: undefined,
|
|
7750
|
+
isLoading: true,
|
|
7751
|
+
};
|
|
7752
|
+
}
|
|
7753
|
+
const balances = spotState.balances || [];
|
|
7754
|
+
let usdhBal = 0;
|
|
7755
|
+
let spotUsdcBal = 0;
|
|
7756
|
+
for (const balance of balances) {
|
|
7757
|
+
if (balance.coin === 'USDH') {
|
|
7758
|
+
usdhBal = parseFloat(balance.hold || '0') + parseFloat(balance.total || '0');
|
|
7759
|
+
}
|
|
7760
|
+
if (balance.coin === 'USDC') {
|
|
7761
|
+
spotUsdcBal = parseFloat(balance.hold || '0') + parseFloat(balance.total || '0');
|
|
7762
|
+
}
|
|
7763
|
+
}
|
|
7764
|
+
return {
|
|
7765
|
+
usdhBalance: usdhBal,
|
|
7766
|
+
spotUsdcBalance: spotUsdcBal,
|
|
7767
|
+
isLoading: false,
|
|
7768
|
+
};
|
|
7769
|
+
}, [spotState]);
|
|
7770
|
+
};
|
|
7771
|
+
|
|
7704
7772
|
const PearHyperliquidContext = createContext(undefined);
|
|
7705
7773
|
/**
|
|
7706
7774
|
* React Provider for PearHyperliquidClient
|
|
@@ -7731,6 +7799,8 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-v2.pearpro
|
|
|
7731
7799
|
const marketPrefixes = new Map(); // "xyz:TSLA" -> "xyz"
|
|
7732
7800
|
const cleanedPerpMetas = [];
|
|
7733
7801
|
// Process each market group (different collateral tokens)
|
|
7802
|
+
// Filter out vntl HIP-3 assets from being sent to frontend
|
|
7803
|
+
const FILTERED_PREFIXES = ['vntl'];
|
|
7734
7804
|
res.data.forEach((item) => {
|
|
7735
7805
|
// Convert numeric collateral token to human-readable name
|
|
7736
7806
|
const collateralToken = item.collateralToken === 360 ? "USDH" : "USDC";
|
|
@@ -7740,6 +7810,10 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = "https://hl-v2.pearpro
|
|
|
7740
7810
|
if (maybeMarket) {
|
|
7741
7811
|
// HIP-3 market with prefix (e.g., "xyz:TSLA")
|
|
7742
7812
|
const prefix = maybePrefix.toLowerCase();
|
|
7813
|
+
// Skip filtered prefixes (e.g., vntl)
|
|
7814
|
+
if (FILTERED_PREFIXES.includes(prefix)) {
|
|
7815
|
+
return;
|
|
7816
|
+
}
|
|
7743
7817
|
const displayName = maybeMarket;
|
|
7744
7818
|
const fullName = `${prefix}:${displayName}`;
|
|
7745
7819
|
// Store full market name with prefix
|
|
@@ -7911,4 +7985,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
7911
7985
|
}
|
|
7912
7986
|
}
|
|
7913
7987
|
|
|
7914
|
-
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
7988
|
+
export { AccountSummaryCalculator, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotBalances, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
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;
|
|
@@ -216,7 +216,7 @@ export interface PositionAssetDetailDto {
|
|
|
216
216
|
collateralToken?: CollateralToken;
|
|
217
217
|
}
|
|
218
218
|
export interface TpSlThreshold {
|
|
219
|
-
type:
|
|
219
|
+
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
220
220
|
value: number;
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
@@ -251,16 +251,16 @@ export interface OrderAssetDto {
|
|
|
251
251
|
/**
|
|
252
252
|
* Order status
|
|
253
253
|
*/
|
|
254
|
-
export type OrderStatus =
|
|
254
|
+
export type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
|
|
255
255
|
/**
|
|
256
256
|
* Order type
|
|
257
257
|
*/
|
|
258
|
-
export type OrderType =
|
|
258
|
+
export type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET' | 'LIMIT_BTCDOM' | 'TWAP';
|
|
259
259
|
/**
|
|
260
260
|
* TP/SL trigger type
|
|
261
261
|
*/
|
|
262
|
-
export type TpSlTriggerType =
|
|
263
|
-
export type OrderDirection =
|
|
262
|
+
export type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
263
|
+
export type OrderDirection = 'MORE_THAN' | 'LESS_THAN' | null;
|
|
264
264
|
/**
|
|
265
265
|
* Open limit order data structure
|
|
266
266
|
*/
|
|
@@ -374,7 +374,7 @@ export interface PrivyAuthDetails {
|
|
|
374
374
|
accessToken: string;
|
|
375
375
|
}
|
|
376
376
|
export interface AuthenticateRequest {
|
|
377
|
-
method:
|
|
377
|
+
method: 'eip712' | 'api_key' | 'privy_access_token';
|
|
378
378
|
address: string;
|
|
379
379
|
clientId: string;
|
|
380
380
|
details: {
|
|
@@ -407,7 +407,7 @@ export interface LogoutRequest {
|
|
|
407
407
|
export interface LogoutResponse {
|
|
408
408
|
message: string;
|
|
409
409
|
}
|
|
410
|
-
export type AgentWalletStatus =
|
|
410
|
+
export type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
|
|
411
411
|
export interface GetAgentWalletResponseDto {
|
|
412
412
|
agentWalletAddress?: string;
|
|
413
413
|
agentName: string;
|
|
@@ -425,7 +425,7 @@ export interface ExtraAgent {
|
|
|
425
425
|
export interface AgentWalletState {
|
|
426
426
|
address: string | null;
|
|
427
427
|
name: string | null;
|
|
428
|
-
status: AgentWalletStatus |
|
|
428
|
+
status: AgentWalletStatus | 'PENDING' | null;
|
|
429
429
|
isActive: boolean;
|
|
430
430
|
}
|
|
431
431
|
/**
|
|
@@ -445,12 +445,16 @@ export interface WebSocketMessage {
|
|
|
445
445
|
/**
|
|
446
446
|
* WebSocket response from HyperLiquid native API
|
|
447
447
|
*/
|
|
448
|
-
export type HLChannel =
|
|
448
|
+
export type HLChannel = 'webData3' | 'allMids' | 'activeAssetData' | 'candle' | 'spotState';
|
|
449
449
|
export interface HLChannelDataMap {
|
|
450
450
|
webData3: WebData3Response;
|
|
451
451
|
allMids: WsAllMidsData;
|
|
452
452
|
activeAssetData: ActiveAssetData;
|
|
453
453
|
candle: CandleData;
|
|
454
|
+
spotState: {
|
|
455
|
+
user: string;
|
|
456
|
+
spotState: SpotState;
|
|
457
|
+
};
|
|
454
458
|
}
|
|
455
459
|
export interface WebData3UserState {
|
|
456
460
|
agentAddress?: string;
|
|
@@ -672,7 +676,7 @@ export interface TokenSelection {
|
|
|
672
676
|
*/
|
|
673
677
|
export interface TokenConflict {
|
|
674
678
|
symbol: string;
|
|
675
|
-
conflictType:
|
|
679
|
+
conflictType: 'long' | 'short';
|
|
676
680
|
conflictMessage: string;
|
|
677
681
|
}
|
|
678
682
|
export interface AssetMarketData {
|
|
@@ -734,7 +738,7 @@ export interface ActiveAssetsAllResponse {
|
|
|
734
738
|
/**
|
|
735
739
|
* Candle interval options
|
|
736
740
|
*/
|
|
737
|
-
export type CandleInterval =
|
|
741
|
+
export type CandleInterval = '1m' | '3m' | '5m' | '15m' | '30m' | '1h' | '2h' | '4h' | '8h' | '12h' | '1d' | '3d' | '1w' | '1M';
|
|
738
742
|
/**
|
|
739
743
|
* Candle data structure from WebSocket
|
|
740
744
|
*/
|
|
@@ -768,3 +772,14 @@ export interface TokenSelectorConfig {
|
|
|
768
772
|
isLong: boolean;
|
|
769
773
|
index: number;
|
|
770
774
|
}
|
|
775
|
+
export interface SpotBalance {
|
|
776
|
+
coin: string;
|
|
777
|
+
token: number;
|
|
778
|
+
total: string;
|
|
779
|
+
hold: string;
|
|
780
|
+
entryNtl: string;
|
|
781
|
+
}
|
|
782
|
+
export interface SpotState {
|
|
783
|
+
user: string;
|
|
784
|
+
balances: SpotBalance[];
|
|
785
|
+
}
|