@pear-protocol/hyperliquid-sdk 0.0.10 → 0.0.12
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 +2 -0
- package/dist/hooks/useTokenSelection.d.ts +33 -0
- package/dist/index.d.ts +111 -2
- package/dist/index.js +11 -3447
- package/dist/provider.d.ts +15 -1
- package/dist/types.d.ts +31 -0
- package/dist/utils/conflict-detector.d.ts +14 -0
- package/dist/utils/token-metadata-extractor.d.ts +29 -0
- package/package.json +18 -8
- package/dist/index.esm.js +0 -3439
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -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;
|
package/dist/index.d.ts
CHANGED
|
@@ -542,6 +542,37 @@ interface RawPositionDto {
|
|
|
542
542
|
longAssets: RawAssetDto[];
|
|
543
543
|
shortAssets: RawAssetDto[];
|
|
544
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
|
+
}
|
|
545
576
|
|
|
546
577
|
/**
|
|
547
578
|
* Main SDK client for Pear Protocol Hyperliquid API integration
|
|
@@ -644,6 +675,10 @@ declare class PearMigrationSDK {
|
|
|
644
675
|
getBaseUrl(): string;
|
|
645
676
|
}
|
|
646
677
|
|
|
678
|
+
interface TokenSelectorConfig {
|
|
679
|
+
isLong: boolean;
|
|
680
|
+
index: number;
|
|
681
|
+
}
|
|
647
682
|
interface PearHyperliquidProviderProps {
|
|
648
683
|
config: PearHyperliquidConfig;
|
|
649
684
|
/**
|
|
@@ -715,6 +750,37 @@ declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] |
|
|
|
715
750
|
*/
|
|
716
751
|
declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
|
|
717
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
|
+
|
|
718
784
|
interface WebSocketData {
|
|
719
785
|
tradeHistories: TradeHistoryDataDto[] | null;
|
|
720
786
|
openPositions: RawPositionDto[] | null;
|
|
@@ -786,5 +852,48 @@ declare class AccountSummaryCalculator {
|
|
|
786
852
|
hasRealTimeData(): boolean;
|
|
787
853
|
}
|
|
788
854
|
|
|
789
|
-
|
|
790
|
-
|
|
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 };
|