@pear-protocol/hyperliquid-sdk 0.0.8 → 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,5 +1,5 @@
1
- import type { OpenPositionDto, WebData2Response, WsAllMidsData } from '../types';
1
+ import type { OpenPositionDto, RawPositionDto, WebData2Response, WsAllMidsData } from '../types';
2
2
  /**
3
3
  * Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
4
4
  */
5
- export declare const useCalculatedOpenPositions: (platformPositions: OpenPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
5
+ export declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
@@ -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;
@@ -490,13 +494,13 @@ interface AssetPosition {
490
494
  returnOnEquity: string;
491
495
  szi: string;
492
496
  unrealizedPnl: string;
497
+ cumFunding: {
498
+ allTime: string;
499
+ sinceChange: string;
500
+ sinceOpen: string;
501
+ };
493
502
  };
494
503
  type: string;
495
- cumFunding: {
496
- allTime: string;
497
- sinceChange: string;
498
- sinceOpen: string;
499
- };
500
504
  }
501
505
  /**
502
506
  * Asset information detail
@@ -514,6 +518,30 @@ interface AssetInformationDetail {
514
518
  priceChange: number;
515
519
  assetIndex: number;
516
520
  }
521
+ /**
522
+ * Raw asset data from open-positions channel
523
+ */
524
+ interface RawAssetDto {
525
+ coin: string;
526
+ entryPrice: number;
527
+ size: number;
528
+ side: string;
529
+ }
530
+ /**
531
+ * Raw position data from open-positions channel
532
+ */
533
+ interface RawPositionDto {
534
+ positionId: string;
535
+ address: string;
536
+ leverage: number;
537
+ stopLoss: number | null;
538
+ takeProfit: number | null;
539
+ status: string;
540
+ createdAt: string;
541
+ updatedAt: string;
542
+ longAssets: RawAssetDto[];
543
+ shortAssets: RawAssetDto[];
544
+ }
517
545
 
518
546
  /**
519
547
  * Main SDK client for Pear Protocol Hyperliquid API integration
@@ -649,26 +677,38 @@ declare const useAddress: () => {
649
677
  };
650
678
 
651
679
  /**
652
- * Hook to access trade histories
680
+ * Hook to access trade histories with loading state
653
681
  */
654
- declare const useTradeHistories: () => PaginatedTradeHistoryResponseDto | null;
682
+ declare const useTradeHistories: () => {
683
+ data: TradeHistoryDataDto[] | null;
684
+ isLoading: boolean;
685
+ };
655
686
  /**
656
- * Hook to access open positions with real-time calculations
687
+ * Hook to access open positions with real-time calculations and loading state
657
688
  */
658
- declare const useOpenPositions: () => OpenPositionDto[] | null;
689
+ declare const useOpenPositions: () => {
690
+ data: OpenPositionDto[] | null;
691
+ isLoading: boolean;
692
+ };
659
693
  /**
660
- * Hook to access open orders
694
+ * Hook to access open orders with loading state
661
695
  */
662
- declare const useOpenOrders: () => OpenLimitOrderDto[] | null;
696
+ declare const useOpenOrders: () => {
697
+ data: OpenLimitOrderDto[] | null;
698
+ isLoading: boolean;
699
+ };
663
700
  /**
664
- * Hook to access account summary with real-time calculations
701
+ * Hook to access account summary with real-time calculations and loading state
665
702
  */
666
- declare const useAccountSummary: () => AccountSummaryResponseDto | null;
703
+ declare const useAccountSummary: () => {
704
+ data: AccountSummaryResponseDto | null;
705
+ isLoading: boolean;
706
+ };
667
707
 
668
708
  /**
669
709
  * Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
670
710
  */
671
- declare const useCalculatedOpenPositions: (platformPositions: OpenPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
711
+ declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
672
712
 
673
713
  /**
674
714
  * Hook that calculates account summary by syncing platform data with HyperLiquid real-time data
@@ -676,8 +716,8 @@ declare const useCalculatedOpenPositions: (platformPositions: OpenPositionDto[]
676
716
  declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
677
717
 
678
718
  interface WebSocketData {
679
- tradeHistories: PaginatedTradeHistoryResponseDto | null;
680
- openPositions: OpenPositionDto[] | null;
719
+ tradeHistories: TradeHistoryDataDto[] | null;
720
+ openPositions: RawPositionDto[] | null;
681
721
  openOrders: OpenLimitOrderDto[] | null;
682
722
  accountSummary: AccountSummaryResponseDto | null;
683
723
  }
@@ -705,87 +745,6 @@ interface UseHyperliquidNativeWebSocketReturn {
705
745
  }
706
746
  declare const useHyperliquidNativeWebSocket: ({ address }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
707
747
 
708
- /**
709
- * Position side enum for calculations
710
- */
711
- declare enum PositionSide {
712
- LONG = "LONG",
713
- SHORT = "SHORT"
714
- }
715
- /**
716
- * Aggregate position calculation utility class that handles cross-position asset syncing
717
- */
718
- declare class AggregatePositionCalculator {
719
- private webData2;
720
- private allMids;
721
- constructor(webData2: WebData2Response | null, allMids: WsAllMidsData | null);
722
- /**
723
- * Get market price for a coin from allMids data
724
- */
725
- getMarketPrice(coin: string): number;
726
- /**
727
- * Get user positions from webData2
728
- */
729
- getUserPositions(): AssetPosition[];
730
- /**
731
- * Calculate updated open positions by syncing platform positions with HyperLiquid data
732
- * Uses aggregate totals across all positions for accurate cross-position sync
733
- */
734
- calculateOpenPositions(platformPositions: OpenPositionDto[]): OpenPositionDto[];
735
- /**
736
- * Calculate total platform sizes per asset across all positions
737
- */
738
- private calculatePlatformTotalsByAsset;
739
- /**
740
- * Extract base currency from asset name (handles "LINK/USD" -> "LINK")
741
- */
742
- private extractBaseCurrency;
743
- /**
744
- * Sync a single position with HyperLiquid data using aggregate totals
745
- */
746
- private syncPositionWithAggregateData;
747
- /**
748
- * Sync individual asset with aggregate data awareness
749
- */
750
- private syncAssetWithAggregateData;
751
- /**
752
- * Determine sync status with sophisticated side-aware logic
753
- */
754
- private determineSyncStatus;
755
- /**
756
- * Build updated position with synced data
757
- */
758
- private buildUpdatedPosition;
759
- /**
760
- * Map sync result to PositionAssetDetailDto
761
- */
762
- private mapSyncResultToAssetDto;
763
- /**
764
- * Calculate entry ratio using actual sizes from sync results
765
- */
766
- private calculateEntryRatio;
767
- /**
768
- * Calculate mark ratio using actual sizes and current prices
769
- */
770
- private calculateMarkRatio;
771
- /**
772
- * Calculate net funding from sync results
773
- */
774
- private calculateNetFundingFromSyncResults;
775
- /**
776
- * Calculate total unrealized PnL from sync results
777
- */
778
- private calculateTotalUnrealizedPnlFromSyncResults;
779
- /**
780
- * Calculate current total position value using market prices
781
- */
782
- private calculateCurrentTotalPositionValue;
783
- /**
784
- * Calculate entry total position value using entry prices
785
- */
786
- private calculateEntryTotalPositionValue;
787
- }
788
-
789
748
  /**
790
749
  * Account summary calculation utility class
791
750
  */
@@ -827,5 +786,5 @@ declare class AccountSummaryCalculator {
827
786
  hasRealTimeData(): boolean;
828
787
  }
829
788
 
830
- export { AccountSummaryCalculator, AggregatePositionCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PositionSide, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
831
- 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 };
789
+ export { AccountSummaryCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
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 };