@pear-protocol/hyperliquid-sdk 0.0.9 → 0.0.10

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.
@@ -1,16 +1,28 @@
1
1
  /**
2
- * Hook to access trade histories
2
+ * Hook to access trade histories with loading state
3
3
  */
4
- export declare const useTradeHistories: () => import("..").PaginatedTradeHistoryResponseDto | null;
4
+ export declare const useTradeHistories: () => {
5
+ data: import("..").TradeHistoryDataDto[] | null;
6
+ isLoading: boolean;
7
+ };
5
8
  /**
6
- * Hook to access open positions with real-time calculations
9
+ * Hook to access open positions with real-time calculations and loading state
7
10
  */
8
- export declare const useOpenPositions: () => import("..").OpenPositionDto[] | null;
11
+ export declare const useOpenPositions: () => {
12
+ data: import("..").OpenPositionDto[] | null;
13
+ isLoading: boolean;
14
+ };
9
15
  /**
10
- * Hook to access open orders
16
+ * Hook to access open orders with loading state
11
17
  */
12
- export declare const useOpenOrders: () => import("..").OpenLimitOrderDto[] | null;
18
+ export declare const useOpenOrders: () => {
19
+ data: import("..").OpenLimitOrderDto[] | null;
20
+ isLoading: boolean;
21
+ };
13
22
  /**
14
- * Hook to access account summary with real-time calculations
23
+ * Hook to access account summary with real-time calculations and loading state
15
24
  */
16
- export declare const useAccountSummary: () => import("..").AccountSummaryResponseDto | null;
25
+ export declare const useAccountSummary: () => {
26
+ data: import("..").AccountSummaryResponseDto | null;
27
+ isLoading: boolean;
28
+ };
package/dist/index.d.ts CHANGED
@@ -260,15 +260,6 @@ interface TradeHistoryDataDto {
260
260
  shortAssets: TradeHistoryAssetDataDto[];
261
261
  createdAt: string;
262
262
  }
263
- /**
264
- * Paginated trade history response
265
- */
266
- interface PaginatedTradeHistoryResponseDto {
267
- data: TradeHistoryDataDto[];
268
- hasMore: boolean;
269
- nextCursor?: string;
270
- count: number;
271
- }
272
263
  /**
273
264
  * Cumulative funding information
274
265
  */
@@ -329,18 +320,31 @@ interface OrderAssetDto {
329
320
  * Order status
330
321
  */
331
322
  type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
323
+ /**
324
+ * Order type
325
+ */
326
+ type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET';
327
+ /**
328
+ * TP/SL trigger type
329
+ */
330
+ type TpSlTriggerType = 'RATIO' | 'PERCENTAGE' | 'PNL';
332
331
  /**
333
332
  * Open limit order data structure
334
333
  */
335
334
  interface OpenLimitOrderDto {
336
335
  orderId: string;
337
336
  address: string;
337
+ clientId: string | null;
338
+ positionId: string;
338
339
  leverage: number;
339
340
  usdValue: number;
340
- limitRatio: number;
341
- stopLoss: number | null;
342
- takeProfit: number | null;
341
+ triggerValue: number;
342
+ twapDuration: number | null;
343
+ tpSlTriggerType: TpSlTriggerType;
344
+ randomizeFlag: boolean;
345
+ reduceOnlyFlag: boolean;
343
346
  status: OrderStatus;
347
+ orderType: OrderType;
344
348
  longAssets: OrderAssetDto[];
345
349
  shortAssets: OrderAssetDto[];
346
350
  createdAt: string;
@@ -673,21 +677,33 @@ declare const useAddress: () => {
673
677
  };
674
678
 
675
679
  /**
676
- * Hook to access trade histories
680
+ * Hook to access trade histories with loading state
677
681
  */
678
- declare const useTradeHistories: () => PaginatedTradeHistoryResponseDto | null;
682
+ declare const useTradeHistories: () => {
683
+ data: TradeHistoryDataDto[] | null;
684
+ isLoading: boolean;
685
+ };
679
686
  /**
680
- * Hook to access open positions with real-time calculations
687
+ * Hook to access open positions with real-time calculations and loading state
681
688
  */
682
- declare const useOpenPositions: () => OpenPositionDto[] | null;
689
+ declare const useOpenPositions: () => {
690
+ data: OpenPositionDto[] | null;
691
+ isLoading: boolean;
692
+ };
683
693
  /**
684
- * Hook to access open orders
694
+ * Hook to access open orders with loading state
685
695
  */
686
- declare const useOpenOrders: () => OpenLimitOrderDto[] | null;
696
+ declare const useOpenOrders: () => {
697
+ data: OpenLimitOrderDto[] | null;
698
+ isLoading: boolean;
699
+ };
687
700
  /**
688
- * Hook to access account summary with real-time calculations
701
+ * Hook to access account summary with real-time calculations and loading state
689
702
  */
690
- declare const useAccountSummary: () => AccountSummaryResponseDto | null;
703
+ declare const useAccountSummary: () => {
704
+ data: AccountSummaryResponseDto | null;
705
+ isLoading: boolean;
706
+ };
691
707
 
692
708
  /**
693
709
  * Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
@@ -700,7 +716,7 @@ declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] |
700
716
  declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
701
717
 
702
718
  interface WebSocketData {
703
- tradeHistories: PaginatedTradeHistoryResponseDto | null;
719
+ tradeHistories: TradeHistoryDataDto[] | null;
704
720
  openPositions: RawPositionDto[] | null;
705
721
  openOrders: OpenLimitOrderDto[] | null;
706
722
  accountSummary: AccountSummaryResponseDto | null;
@@ -771,4 +787,4 @@ declare class AccountSummaryCalculator {
771
787
  }
772
788
 
773
789
  export { AccountSummaryCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
774
- export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetPosition, BalanceSummaryDto, CrossMarginSummaryDto, CumFundingDto, MarginSummaryDto, MigrationHookState, MigrationHooks, OpenLimitOrderDto, OpenOrderV1Dto, OpenPositionDto, OpenPositionV1Dto, OrderAssetDto, OrderStatus, PaginatedTradeHistoryResponseDto, PearHyperliquidConfig, PnlDto, PositionAssetDetailDto, PositionSideDto, PositionSyncStatus, RawValueDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, WebData2Response, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketResponse, WebSocketSubscribeMessage, WsAllMidsData };
790
+ export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetPosition, BalanceSummaryDto, CrossMarginSummaryDto, CumFundingDto, MarginSummaryDto, MigrationHookState, MigrationHooks, OpenLimitOrderDto, OpenOrderV1Dto, OpenPositionDto, OpenPositionV1Dto, OrderAssetDto, OrderStatus, PearHyperliquidConfig, PnlDto, PositionAssetDetailDto, PositionSideDto, PositionSyncStatus, RawValueDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, WebData2Response, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketResponse, WebSocketSubscribeMessage, WsAllMidsData };
package/dist/index.esm.js CHANGED
@@ -2638,21 +2638,17 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
2638
2638
  accountSummary: null,
2639
2639
  });
2640
2640
  const [lastError, setLastError] = useState(null);
2641
+ const [lastSubscribedAddress, setLastSubscribedAddress] = useState(null);
2641
2642
  // WebSocket connection
2642
- const { lastMessage, readyState, sendMessage } = useWebSocket(address ? wsUrl : null, // Only connect when address is set
2643
- {
2643
+ const { readyState, sendMessage } = useWebSocket(wsUrl, {
2644
2644
  shouldReconnect: () => true,
2645
2645
  reconnectAttempts: 5,
2646
2646
  reconnectInterval: 3000,
2647
- });
2648
- const isConnected = readyState === dist.ReadyState.OPEN;
2649
- // Handle incoming WebSocket messages
2650
- useEffect(() => {
2651
- if (lastMessage !== null) {
2647
+ onMessage: (event) => {
2652
2648
  try {
2653
- const message = JSON.parse(lastMessage.data);
2654
- // Handle subscription responses
2655
- if ('success' in message || 'error' in message) {
2649
+ const message = JSON.parse(event.data);
2650
+ // Handle subscription responses (only if they don't have channel data)
2651
+ if (('success' in message || 'error' in message) && !('channel' in message)) {
2656
2652
  if (message.error) {
2657
2653
  setLastError(message.error);
2658
2654
  }
@@ -2664,30 +2660,42 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
2664
2660
  // Handle channel data messages
2665
2661
  if ('channel' in message && 'data' in message) {
2666
2662
  const dataMessage = message;
2663
+ // Validate data exists and is not null/undefined
2664
+ if (dataMessage.data === null || dataMessage.data === undefined) {
2665
+ return;
2666
+ }
2667
2667
  switch (dataMessage.channel) {
2668
2668
  case 'trade-histories':
2669
- setData(prev => ({
2670
- ...prev,
2671
- tradeHistories: dataMessage.data
2672
- }));
2669
+ if (Array.isArray(dataMessage.data)) {
2670
+ setData(prev => ({
2671
+ ...prev,
2672
+ tradeHistories: dataMessage.data
2673
+ }));
2674
+ }
2673
2675
  break;
2674
2676
  case 'open-positions':
2675
- setData(prev => ({
2676
- ...prev,
2677
- openPositions: dataMessage.data
2678
- }));
2677
+ if (Array.isArray(dataMessage.data)) {
2678
+ setData(prev => ({
2679
+ ...prev,
2680
+ openPositions: dataMessage.data
2681
+ }));
2682
+ }
2679
2683
  break;
2680
2684
  case 'open-orders':
2681
- setData(prev => ({
2682
- ...prev,
2683
- openOrders: dataMessage.data
2684
- }));
2685
+ if (Array.isArray(dataMessage.data)) {
2686
+ setData(prev => ({
2687
+ ...prev,
2688
+ openOrders: dataMessage.data
2689
+ }));
2690
+ }
2685
2691
  break;
2686
2692
  case 'account-summary':
2687
- setData(prev => ({
2688
- ...prev,
2689
- accountSummary: dataMessage.data
2690
- }));
2693
+ if (typeof dataMessage.data === 'object' && dataMessage.data !== null) {
2694
+ setData(prev => ({
2695
+ ...prev,
2696
+ accountSummary: dataMessage.data
2697
+ }));
2698
+ }
2691
2699
  break;
2692
2700
  }
2693
2701
  }
@@ -2696,34 +2704,47 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
2696
2704
  setLastError(`Failed to parse message: ${error instanceof Error ? error.message : String(error)}`);
2697
2705
  }
2698
2706
  }
2699
- }, [lastMessage]);
2700
- // Handle address changes - subscribe/unsubscribe
2707
+ });
2708
+ const isConnected = readyState === dist.ReadyState.OPEN;
2709
+ // Handle subscription management
2701
2710
  useEffect(() => {
2702
- if (isConnected && address) {
2711
+ if (isConnected && address && address !== lastSubscribedAddress) {
2712
+ // Unsubscribe from previous address if exists
2713
+ if (lastSubscribedAddress) {
2714
+ sendMessage(JSON.stringify({
2715
+ action: 'unsubscribe',
2716
+ address: lastSubscribedAddress
2717
+ }));
2718
+ }
2703
2719
  // Subscribe to new address
2704
2720
  sendMessage(JSON.stringify({
2705
2721
  action: 'subscribe',
2706
2722
  address: address
2707
2723
  }));
2708
- // Clear previous data
2709
- setData({
2710
- tradeHistories: null,
2711
- openPositions: null,
2712
- openOrders: null,
2713
- accountSummary: null,
2714
- });
2724
+ setLastSubscribedAddress(address);
2715
2725
  setLastError(null);
2716
2726
  }
2717
- else if (isConnected && !address) {
2718
- // Clear data when address is removed
2727
+ else if (isConnected && !address && lastSubscribedAddress) {
2728
+ // Send unsubscribe action when address is removed
2729
+ sendMessage(JSON.stringify({
2730
+ action: 'unsubscribe',
2731
+ address: lastSubscribedAddress
2732
+ }));
2733
+ setLastSubscribedAddress(null);
2734
+ }
2735
+ }, [isConnected, address, lastSubscribedAddress, sendMessage]);
2736
+ // Clear data when address changes
2737
+ useEffect(() => {
2738
+ if (address !== lastSubscribedAddress) {
2719
2739
  setData({
2720
2740
  tradeHistories: null,
2721
2741
  openPositions: null,
2722
2742
  openOrders: null,
2723
2743
  accountSummary: null,
2724
2744
  });
2745
+ setLastError(null);
2725
2746
  }
2726
- }, [isConnected, address, sendMessage]);
2747
+ }, [address, lastSubscribedAddress]);
2727
2748
  return {
2728
2749
  data,
2729
2750
  connectionStatus: readyState,
@@ -2739,7 +2760,7 @@ const useHyperliquidNativeWebSocket = ({ address }) => {
2739
2760
  const [subscribedAddress, setSubscribedAddress] = useState(null);
2740
2761
  const pingIntervalRef = useRef(null);
2741
2762
  // WebSocket connection to HyperLiquid native API
2742
- const { lastMessage, readyState, sendJsonMessage } = useWebSocket('wss://api.hyperliquid.xyz/ws', {
2763
+ const { readyState, sendJsonMessage } = useWebSocket('wss://api.hyperliquid.xyz/ws', {
2743
2764
  shouldReconnect: () => true,
2744
2765
  reconnectAttempts: 5,
2745
2766
  reconnectInterval: 3000,
@@ -2747,6 +2768,41 @@ const useHyperliquidNativeWebSocket = ({ address }) => {
2747
2768
  onClose: () => { },
2748
2769
  onError: (event) => console.error('[HyperLiquid WS] Connection error:', event),
2749
2770
  onReconnectStop: () => console.error('[HyperLiquid WS] Reconnection stopped after 5 attempts'),
2771
+ onMessage: (event) => {
2772
+ try {
2773
+ const message = JSON.parse(event.data);
2774
+ // Handle subscription responses
2775
+ if ('success' in message || 'error' in message) {
2776
+ if (message.error) {
2777
+ console.error('[HyperLiquid WS] Subscription error:', message.error);
2778
+ setLastError(message.error);
2779
+ }
2780
+ else {
2781
+ setLastError(null);
2782
+ }
2783
+ return;
2784
+ }
2785
+ // Handle channel data messages
2786
+ if ('channel' in message && 'data' in message) {
2787
+ const response = message;
2788
+ switch (response.channel) {
2789
+ case 'webData2':
2790
+ setWebData2(response.data);
2791
+ break;
2792
+ case 'allMids':
2793
+ setAllMids(response.data);
2794
+ break;
2795
+ default:
2796
+ console.warn(`[HyperLiquid WS] Unknown channel: ${response.channel}`);
2797
+ }
2798
+ }
2799
+ }
2800
+ catch (error) {
2801
+ const errorMessage = `Failed to parse message: ${error instanceof Error ? error.message : String(error)}`;
2802
+ console.error('[HyperLiquid WS] Parse error:', errorMessage, 'Raw message:', event.data);
2803
+ setLastError(errorMessage);
2804
+ }
2805
+ }
2750
2806
  });
2751
2807
  const isConnected = readyState === dist.ReadyState.OPEN;
2752
2808
  // Setup ping mechanism
@@ -2812,44 +2868,6 @@ const useHyperliquidNativeWebSocket = ({ address }) => {
2812
2868
  setWebData2(null);
2813
2869
  }
2814
2870
  }, [isConnected, address, subscribedAddress, sendJsonMessage]);
2815
- // Handle incoming WebSocket messages
2816
- useEffect(() => {
2817
- if (!lastMessage)
2818
- return;
2819
- try {
2820
- const message = JSON.parse(lastMessage.data);
2821
- // Handle subscription responses
2822
- if ('success' in message || 'error' in message) {
2823
- if (message.error) {
2824
- console.error('[HyperLiquid WS] Subscription error:', message.error);
2825
- setLastError(message.error);
2826
- }
2827
- else {
2828
- setLastError(null);
2829
- }
2830
- return;
2831
- }
2832
- // Handle channel data messages
2833
- if ('channel' in message && 'data' in message) {
2834
- const response = message;
2835
- switch (response.channel) {
2836
- case 'webData2':
2837
- setWebData2(response.data);
2838
- break;
2839
- case 'allMids':
2840
- setAllMids(response.data);
2841
- break;
2842
- default:
2843
- console.warn(`[HyperLiquid WS] Unknown channel: ${response.channel}`);
2844
- }
2845
- }
2846
- }
2847
- catch (error) {
2848
- const errorMessage = `Failed to parse message: ${error instanceof Error ? error.message : String(error)}`;
2849
- console.error('[HyperLiquid WS] Parse error:', errorMessage, 'Raw message:', lastMessage.data);
2850
- setLastError(errorMessage);
2851
- }
2852
- }, [lastMessage]);
2853
2871
  return {
2854
2872
  webData2,
2855
2873
  allMids,
@@ -3180,32 +3198,24 @@ class PositionProcessor {
3180
3198
  };
3181
3199
  }
3182
3200
  calculateEntryRatio(syncResults) {
3201
+ var _a, _b;
3183
3202
  const longResults = syncResults.filter(result => result.asset.side === PositionSide.LONG);
3184
3203
  const shortResults = syncResults.filter(result => result.asset.side === PositionSide.SHORT);
3185
3204
  if (longResults.length === 0 || shortResults.length === 0)
3186
3205
  return 0;
3187
- const longValue = longResults.reduce((sum, result) => {
3188
- return sum + (Number(result.asset.size || 0) * Number(result.asset.entryPrice || 0));
3189
- }, 0);
3190
- const shortValue = shortResults.reduce((sum, result) => {
3191
- return sum + (Number(result.asset.size || 0) * Number(result.asset.entryPrice || 0));
3192
- }, 0);
3193
- return shortValue > 0 ? longValue / shortValue : 0;
3206
+ const longEntryPrice = ((_a = longResults[0]) === null || _a === void 0 ? void 0 : _a.asset.entryPrice) ? Number(longResults[0].asset.entryPrice) : 0;
3207
+ const shortEntryPrice = ((_b = shortResults[0]) === null || _b === void 0 ? void 0 : _b.asset.entryPrice) ? Number(shortResults[0].asset.entryPrice) : 0;
3208
+ return shortEntryPrice > 0 ? longEntryPrice / shortEntryPrice : 0;
3194
3209
  }
3195
3210
  calculateMarkRatio(syncResults) {
3211
+ var _a, _b;
3196
3212
  const longResults = syncResults.filter(result => result.asset.side === PositionSide.LONG);
3197
3213
  const shortResults = syncResults.filter(result => result.asset.side === PositionSide.SHORT);
3198
3214
  if (longResults.length === 0 || shortResults.length === 0)
3199
3215
  return 0;
3200
- const longValue = longResults.reduce((sum, result) => {
3201
- const currentPrice = this.getMarketPrice(result.asset.coin);
3202
- return sum + (result.actualSize * currentPrice);
3203
- }, 0);
3204
- const shortValue = shortResults.reduce((sum, result) => {
3205
- const currentPrice = this.getMarketPrice(result.asset.coin);
3206
- return sum + (result.actualSize * currentPrice);
3207
- }, 0);
3208
- return shortValue > 0 ? longValue / shortValue : 0;
3216
+ const longMarkPrice = ((_a = longResults[0]) === null || _a === void 0 ? void 0 : _a.asset.coin) ? this.getMarketPrice(longResults[0].asset.coin) : 0;
3217
+ const shortMarkPrice = ((_b = shortResults[0]) === null || _b === void 0 ? void 0 : _b.asset.coin) ? this.getMarketPrice(shortResults[0].asset.coin) : 0;
3218
+ return shortMarkPrice > 0 ? longMarkPrice / shortMarkPrice : 0;
3209
3219
  }
3210
3220
  calculateNetFundingFromSyncResults(syncResults) {
3211
3221
  const netFunding = syncResults.reduce((sum, result) => {
@@ -3348,17 +3358,24 @@ const useCalculatedAccountSummary = (platformAccountSummary, platformOpenOrders,
3348
3358
  };
3349
3359
 
3350
3360
  /**
3351
- * Hook to access trade histories
3361
+ * Hook to access trade histories with loading state
3352
3362
  */
3353
3363
  const useTradeHistories = () => {
3354
3364
  const context = useContext(PearHyperliquidContext);
3355
3365
  if (!context) {
3356
3366
  throw new Error('useTradeHistories must be used within a PearHyperliquidProvider');
3357
3367
  }
3358
- return context.data.tradeHistories;
3368
+ const isLoading = useMemo(() => {
3369
+ // Loading is true initially and becomes false once we get the first data
3370
+ return context.data.tradeHistories === null && context.isConnected;
3371
+ }, [context.data.tradeHistories, context.isConnected]);
3372
+ return {
3373
+ data: context.data.tradeHistories,
3374
+ isLoading
3375
+ };
3359
3376
  };
3360
3377
  /**
3361
- * Hook to access open positions with real-time calculations
3378
+ * Hook to access open positions with real-time calculations and loading state
3362
3379
  */
3363
3380
  const useOpenPositions = () => {
3364
3381
  const context = useContext(PearHyperliquidContext);
@@ -3367,20 +3384,38 @@ const useOpenPositions = () => {
3367
3384
  }
3368
3385
  // Use calculated positions that sync platform data with HyperLiquid real-time data
3369
3386
  const calculatedPositions = useCalculatedOpenPositions(context.data.openPositions, context.webData2, context.allMids);
3370
- return calculatedPositions;
3387
+ const isLoading = useMemo(() => {
3388
+ // Loading is true initially and becomes false only when:
3389
+ // 1. WebSocket has open-positions data
3390
+ // 2. webData2 and allMids are ready (required for calculations)
3391
+ // 3. Connection is established
3392
+ return (context.isConnected &&
3393
+ (context.data.openPositions === null || !context.webData2 || !context.allMids));
3394
+ }, [context.data.openPositions, context.webData2, context.allMids, context.isConnected]);
3395
+ return {
3396
+ data: calculatedPositions,
3397
+ isLoading
3398
+ };
3371
3399
  };
3372
3400
  /**
3373
- * Hook to access open orders
3401
+ * Hook to access open orders with loading state
3374
3402
  */
3375
3403
  const useOpenOrders = () => {
3376
3404
  const context = useContext(PearHyperliquidContext);
3377
3405
  if (!context) {
3378
3406
  throw new Error('useOpenOrders must be used within a PearHyperliquidProvider');
3379
3407
  }
3380
- return context.data.openOrders;
3408
+ const isLoading = useMemo(() => {
3409
+ // Loading is true initially and becomes false once we get the first data
3410
+ return context.data.openOrders === null && context.isConnected;
3411
+ }, [context.data.openOrders, context.isConnected]);
3412
+ return {
3413
+ data: context.data.openOrders,
3414
+ isLoading
3415
+ };
3381
3416
  };
3382
3417
  /**
3383
- * Hook to access account summary with real-time calculations
3418
+ * Hook to access account summary with real-time calculations and loading state
3384
3419
  */
3385
3420
  const useAccountSummary = () => {
3386
3421
  var _a, _b, _c, _d;
@@ -3390,7 +3425,14 @@ const useAccountSummary = () => {
3390
3425
  }
3391
3426
  // Use calculated account summary that syncs platform data with HyperLiquid real-time data
3392
3427
  const calculatedAccountSummary = useCalculatedAccountSummary(context.data.accountSummary, context.data.openOrders, context.webData2, (_b = (_a = context.data.accountSummary) === null || _a === void 0 ? void 0 : _a.agentWallet) === null || _b === void 0 ? void 0 : _b.address, (_d = (_c = context.data.accountSummary) === null || _c === void 0 ? void 0 : _c.agentWallet) === null || _d === void 0 ? void 0 : _d.status);
3393
- return calculatedAccountSummary;
3428
+ const isLoading = useMemo(() => {
3429
+ // Loading is true initially and becomes false once we get the first data
3430
+ return context.data.accountSummary === null && context.isConnected;
3431
+ }, [context.data.accountSummary, context.isConnected]);
3432
+ return {
3433
+ data: calculatedAccountSummary,
3434
+ isLoading
3435
+ };
3394
3436
  };
3395
3437
 
3396
3438
  export { AccountSummaryCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };