@pear-protocol/hyperliquid-sdk 0.0.8 → 0.0.9

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;
package/dist/index.d.ts CHANGED
@@ -490,13 +490,13 @@ interface AssetPosition {
490
490
  returnOnEquity: string;
491
491
  szi: string;
492
492
  unrealizedPnl: string;
493
+ cumFunding: {
494
+ allTime: string;
495
+ sinceChange: string;
496
+ sinceOpen: string;
497
+ };
493
498
  };
494
499
  type: string;
495
- cumFunding: {
496
- allTime: string;
497
- sinceChange: string;
498
- sinceOpen: string;
499
- };
500
500
  }
501
501
  /**
502
502
  * Asset information detail
@@ -514,6 +514,30 @@ interface AssetInformationDetail {
514
514
  priceChange: number;
515
515
  assetIndex: number;
516
516
  }
517
+ /**
518
+ * Raw asset data from open-positions channel
519
+ */
520
+ interface RawAssetDto {
521
+ coin: string;
522
+ entryPrice: number;
523
+ size: number;
524
+ side: string;
525
+ }
526
+ /**
527
+ * Raw position data from open-positions channel
528
+ */
529
+ interface RawPositionDto {
530
+ positionId: string;
531
+ address: string;
532
+ leverage: number;
533
+ stopLoss: number | null;
534
+ takeProfit: number | null;
535
+ status: string;
536
+ createdAt: string;
537
+ updatedAt: string;
538
+ longAssets: RawAssetDto[];
539
+ shortAssets: RawAssetDto[];
540
+ }
517
541
 
518
542
  /**
519
543
  * Main SDK client for Pear Protocol Hyperliquid API integration
@@ -668,7 +692,7 @@ declare const useAccountSummary: () => AccountSummaryResponseDto | null;
668
692
  /**
669
693
  * Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
670
694
  */
671
- declare const useCalculatedOpenPositions: (platformPositions: OpenPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
695
+ declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
672
696
 
673
697
  /**
674
698
  * Hook that calculates account summary by syncing platform data with HyperLiquid real-time data
@@ -677,7 +701,7 @@ declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSumma
677
701
 
678
702
  interface WebSocketData {
679
703
  tradeHistories: PaginatedTradeHistoryResponseDto | null;
680
- openPositions: OpenPositionDto[] | null;
704
+ openPositions: RawPositionDto[] | null;
681
705
  openOrders: OpenLimitOrderDto[] | null;
682
706
  accountSummary: AccountSummaryResponseDto | null;
683
707
  }
@@ -705,87 +729,6 @@ interface UseHyperliquidNativeWebSocketReturn {
705
729
  }
706
730
  declare const useHyperliquidNativeWebSocket: ({ address }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
707
731
 
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
732
  /**
790
733
  * Account summary calculation utility class
791
734
  */
@@ -827,5 +770,5 @@ declare class AccountSummaryCalculator {
827
770
  hasRealTimeData(): boolean;
828
771
  }
829
772
 
830
- export { AccountSummaryCalculator, AggregatePositionCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PositionSide, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
773
+ export { AccountSummaryCalculator, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTradeHistories };
831
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 };