@pear-protocol/hyperliquid-sdk 0.0.9 → 0.0.11

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.
@@ -2,3 +2,5 @@ export { useAddress } from './useAddress';
2
2
  export { useTradeHistories, useOpenPositions, useOpenOrders, useAccountSummary } from './useTrading';
3
3
  export { useCalculatedOpenPositions } from './useCalculatedPositions';
4
4
  export { useCalculatedAccountSummary } from './useCalculatedAccountSummary';
5
+ export { useTokenSelection } from './useTokenSelection';
6
+ export type { TokenSelectorConfig, UseTokenSelectionReturn } from './useTokenSelection';
@@ -0,0 +1,33 @@
1
+ import type { TokenSelection, TokenConflict } from '../types';
2
+ import { TokenSelectorConfig } from '../provider';
3
+ export type { TokenSelectorConfig };
4
+ export interface UseTokenSelectionReturn {
5
+ longTokens: TokenSelection[];
6
+ shortTokens: TokenSelection[];
7
+ openTokenSelector: boolean;
8
+ selectorConfig: TokenSelectorConfig | null;
9
+ openConflictModal: boolean;
10
+ conflicts: TokenConflict[];
11
+ isLoading: boolean;
12
+ isPriceDataReady: boolean;
13
+ weightedRatio: number;
14
+ weightedRatio24h: number;
15
+ sumNetFunding: number;
16
+ maxLeverage: number;
17
+ minMargin: number;
18
+ setLongTokens: (tokens: TokenSelection[]) => void;
19
+ setShortTokens: (tokens: TokenSelection[]) => void;
20
+ updateTokenWeight: (isLong: boolean, index: number, newWeight: number) => void;
21
+ addToken: (isLong: boolean) => void;
22
+ removeToken: (isLong: boolean, index: number) => void;
23
+ handleTokenSelect: (selectedToken: string) => void;
24
+ setOpenTokenSelector: (open: boolean) => void;
25
+ setSelectorConfig: (config: TokenSelectorConfig | null) => void;
26
+ setOpenConflictModal: (open: boolean) => void;
27
+ setConflicts: (conflicts: TokenConflict[]) => void;
28
+ resetToDefaults: () => void;
29
+ }
30
+ /**
31
+ * Hook to access token selection state using provider's WebSocket data
32
+ */
33
+ export declare const useTokenSelection: () => UseTokenSelectionReturn;
@@ -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;
@@ -538,6 +542,37 @@ interface RawPositionDto {
538
542
  longAssets: RawAssetDto[];
539
543
  shortAssets: RawAssetDto[];
540
544
  }
545
+ /**
546
+ * Token metadata from WebData2 and AllMids
547
+ */
548
+ interface TokenMetadata {
549
+ currentPrice: number;
550
+ prevDayPrice: number;
551
+ priceChange24h: number;
552
+ priceChange24hPercent: number;
553
+ netFunding: number;
554
+ maxLeverage: number;
555
+ markPrice: number;
556
+ oraclePrice: number;
557
+ openInterest: string;
558
+ dayVolume: string;
559
+ }
560
+ /**
561
+ * Enhanced token selection with weight and metadata for basket trading
562
+ */
563
+ interface TokenSelection {
564
+ symbol: string;
565
+ weight: number;
566
+ metadata?: TokenMetadata;
567
+ }
568
+ /**
569
+ * Token conflict information for position conflicts
570
+ */
571
+ interface TokenConflict {
572
+ symbol: string;
573
+ conflictType: 'long' | 'short';
574
+ conflictMessage: string;
575
+ }
541
576
 
542
577
  /**
543
578
  * Main SDK client for Pear Protocol Hyperliquid API integration
@@ -640,6 +675,10 @@ declare class PearMigrationSDK {
640
675
  getBaseUrl(): string;
641
676
  }
642
677
 
678
+ interface TokenSelectorConfig {
679
+ isLong: boolean;
680
+ index: number;
681
+ }
643
682
  interface PearHyperliquidProviderProps {
644
683
  config: PearHyperliquidConfig;
645
684
  /**
@@ -673,21 +712,33 @@ declare const useAddress: () => {
673
712
  };
674
713
 
675
714
  /**
676
- * Hook to access trade histories
715
+ * Hook to access trade histories with loading state
677
716
  */
678
- declare const useTradeHistories: () => PaginatedTradeHistoryResponseDto | null;
717
+ declare const useTradeHistories: () => {
718
+ data: TradeHistoryDataDto[] | null;
719
+ isLoading: boolean;
720
+ };
679
721
  /**
680
- * Hook to access open positions with real-time calculations
722
+ * Hook to access open positions with real-time calculations and loading state
681
723
  */
682
- declare const useOpenPositions: () => OpenPositionDto[] | null;
724
+ declare const useOpenPositions: () => {
725
+ data: OpenPositionDto[] | null;
726
+ isLoading: boolean;
727
+ };
683
728
  /**
684
- * Hook to access open orders
729
+ * Hook to access open orders with loading state
685
730
  */
686
- declare const useOpenOrders: () => OpenLimitOrderDto[] | null;
731
+ declare const useOpenOrders: () => {
732
+ data: OpenLimitOrderDto[] | null;
733
+ isLoading: boolean;
734
+ };
687
735
  /**
688
- * Hook to access account summary with real-time calculations
736
+ * Hook to access account summary with real-time calculations and loading state
689
737
  */
690
- declare const useAccountSummary: () => AccountSummaryResponseDto | null;
738
+ declare const useAccountSummary: () => {
739
+ data: AccountSummaryResponseDto | null;
740
+ isLoading: boolean;
741
+ };
691
742
 
692
743
  /**
693
744
  * Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
@@ -699,8 +750,39 @@ declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] |
699
750
  */
700
751
  declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
701
752
 
753
+ interface UseTokenSelectionReturn {
754
+ longTokens: TokenSelection[];
755
+ shortTokens: TokenSelection[];
756
+ openTokenSelector: boolean;
757
+ selectorConfig: TokenSelectorConfig | null;
758
+ openConflictModal: boolean;
759
+ conflicts: TokenConflict[];
760
+ isLoading: boolean;
761
+ isPriceDataReady: boolean;
762
+ weightedRatio: number;
763
+ weightedRatio24h: number;
764
+ sumNetFunding: number;
765
+ maxLeverage: number;
766
+ minMargin: number;
767
+ setLongTokens: (tokens: TokenSelection[]) => void;
768
+ setShortTokens: (tokens: TokenSelection[]) => void;
769
+ updateTokenWeight: (isLong: boolean, index: number, newWeight: number) => void;
770
+ addToken: (isLong: boolean) => void;
771
+ removeToken: (isLong: boolean, index: number) => void;
772
+ handleTokenSelect: (selectedToken: string) => void;
773
+ setOpenTokenSelector: (open: boolean) => void;
774
+ setSelectorConfig: (config: TokenSelectorConfig | null) => void;
775
+ setOpenConflictModal: (open: boolean) => void;
776
+ setConflicts: (conflicts: TokenConflict[]) => void;
777
+ resetToDefaults: () => void;
778
+ }
779
+ /**
780
+ * Hook to access token selection state using provider's WebSocket data
781
+ */
782
+ declare const useTokenSelection: () => UseTokenSelectionReturn;
783
+
702
784
  interface WebSocketData {
703
- tradeHistories: PaginatedTradeHistoryResponseDto | null;
785
+ tradeHistories: TradeHistoryDataDto[] | null;
704
786
  openPositions: RawPositionDto[] | null;
705
787
  openOrders: OpenLimitOrderDto[] | null;
706
788
  accountSummary: AccountSummaryResponseDto | null;
@@ -770,5 +852,48 @@ declare class AccountSummaryCalculator {
770
852
  hasRealTimeData(): boolean;
771
853
  }
772
854
 
773
- 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 };
855
+ /**
856
+ * Detects conflicts between selected tokens and existing positions
857
+ */
858
+ declare class ConflictDetector {
859
+ /**
860
+ * Detects conflicts between token selections and open positions
861
+ * @param longTokens - Selected long tokens
862
+ * @param shortTokens - Selected short tokens
863
+ * @param openPositions - Current open positions from API
864
+ * @returns Array of detected conflicts
865
+ */
866
+ static detectConflicts(longTokens: TokenSelection[], shortTokens: TokenSelection[], openPositions: any[] | null): TokenConflict[];
867
+ }
868
+
869
+ /**
870
+ * Extracts token metadata from WebData2 and AllMids data
871
+ */
872
+ declare class TokenMetadataExtractor {
873
+ /**
874
+ * Extracts comprehensive token metadata
875
+ * @param symbol - Token symbol
876
+ * @param webData2 - WebData2 response containing asset context and universe data
877
+ * @param allMids - AllMids data containing current prices
878
+ * @returns TokenMetadata or null if token not found
879
+ */
880
+ static extractTokenMetadata(symbol: string, webData2: WebData2Response | null, allMids: WsAllMidsData | null): TokenMetadata | null;
881
+ /**
882
+ * Extracts metadata for multiple tokens
883
+ * @param symbols - Array of token symbols
884
+ * @param webData2 - WebData2 response
885
+ * @param allMids - AllMids data
886
+ * @returns Record of symbol to TokenMetadata
887
+ */
888
+ static extractMultipleTokensMetadata(symbols: string[], webData2: WebData2Response | null, allMids: WsAllMidsData | null): Record<string, TokenMetadata | null>;
889
+ /**
890
+ * Checks if token data is available in WebData2
891
+ * @param symbol - Token symbol
892
+ * @param webData2 - WebData2 response
893
+ * @returns boolean indicating if token exists in universe
894
+ */
895
+ static isTokenAvailable(symbol: string, webData2: WebData2Response | null): boolean;
896
+ }
897
+
898
+ export { AccountSummaryCalculator, ConflictDetector, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, TokenMetadataExtractor, PearHyperliquidClient as default, useAccountSummary, useAddress, useCalculatedAccountSummary, useCalculatedOpenPositions, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTokenSelection, useTradeHistories };
899
+ 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, TokenConflict, TokenMetadata, TokenSelection, TokenSelectorConfig, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, UseTokenSelectionReturn, WebData2Response, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketResponse, WebSocketSubscribeMessage, WsAllMidsData };