@pear-protocol/hyperliquid-sdk 0.0.12 → 0.0.15
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/client.d.ts +10 -1
- package/dist/hooks/index.d.ts +7 -6
- package/dist/hooks/useBasketCandles.d.ts +12 -0
- package/dist/hooks/useHistoricalPriceData.d.ts +9 -0
- package/dist/hooks/useTokenSelectionMetadata.d.ts +14 -0
- package/dist/hooks/useTrading.d.ts +6 -6
- package/dist/hooks/useUserSelection.d.ts +2 -0
- package/dist/hooks/useWebData.d.ts +12 -0
- package/dist/hyperliquid-websocket.d.ts +4 -4
- package/dist/index.d.ts +188 -67
- package/dist/index.js +3539 -8
- package/dist/provider.d.ts +0 -20
- package/dist/store/historicalPriceDataStore.d.ts +14 -0
- package/dist/store/hyperliquidDataStore.d.ts +1 -0
- package/dist/store/tokenSelectionMetadataStore.d.ts +21 -0
- package/dist/store/userDataStore.d.ts +1 -0
- package/dist/{hooks/useTokenSelection.d.ts → store/userSelection.d.ts} +11 -19
- package/dist/types.d.ts +77 -3
- package/dist/utils/basket-calculator.d.ts +24 -0
- package/dist/utils/token-metadata-extractor.d.ts +5 -3
- package/dist/websocket.d.ts +2 -12
- package/package.json +3 -3
- package/dist/hooks/useCalculatedAccountSummary.d.ts +0 -5
- package/dist/hooks/useCalculatedPositions.d.ts +0 -5
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PearHyperliquidConfig, ApiResponse, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncOpenOrderDto, SyncOpenOrderResponseDto } from './types';
|
|
1
|
+
import { PearHyperliquidConfig, ApiResponse, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, CandleData } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Main SDK client for Pear Protocol Hyperliquid API integration
|
|
4
4
|
*/
|
|
@@ -40,4 +40,13 @@ export declare class PearHyperliquidClient {
|
|
|
40
40
|
* @returns Promise with sync result
|
|
41
41
|
*/
|
|
42
42
|
syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto>>;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch historical candle data from HyperLiquid API
|
|
45
|
+
* @param coin - Token symbol (e.g., 'BTC', 'ETH')
|
|
46
|
+
* @param startTime - Start time in milliseconds
|
|
47
|
+
* @param endTime - End time in milliseconds
|
|
48
|
+
* @param interval - Candle interval
|
|
49
|
+
* @returns Promise with historical candle data
|
|
50
|
+
*/
|
|
51
|
+
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval: string): Promise<ApiResponse<CandleData[]>>;
|
|
43
52
|
}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
1
|
+
export * from './useAddress';
|
|
2
|
+
export * from './useTrading';
|
|
3
|
+
export * from './useUserSelection';
|
|
4
|
+
export * from './useWebData';
|
|
5
|
+
export * from './useTokenSelectionMetadata';
|
|
6
|
+
export * from './useHistoricalPriceData';
|
|
7
|
+
export * from './useBasketCandles';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WeightedCandleData } from '../types';
|
|
2
|
+
export interface UseBasketCandlesReturn {
|
|
3
|
+
fetchBasketCandles: (startTime: number, endTime: number) => Promise<WeightedCandleData[]>;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Composes historical price fetching with basket candle computation.
|
|
8
|
+
* - Listens to `longTokens` and `shortTokens` from user selection.
|
|
9
|
+
* - Uses `fetchHistoricalPriceData` to retrieve token candles for the range.
|
|
10
|
+
* - Computes and returns weighted basket candles via `computeBasketCandles`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useBasketCandles: () => UseBasketCandlesReturn;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CandleData } from '../types';
|
|
2
|
+
export interface UseHistoricalPriceDataReturn {
|
|
3
|
+
fetchHistoricalPriceData: (startTime: number, endTime: number, callback?: (data: Record<string, CandleData[]>) => void) => Promise<Record<string, CandleData[]>>;
|
|
4
|
+
hasHistoricalPriceData: (startTime: number, endTime: number) => boolean;
|
|
5
|
+
getHistoricalPriceData: (startTime: number, endTime: number) => Record<string, CandleData[]>;
|
|
6
|
+
isLoading: (symbol?: string) => boolean;
|
|
7
|
+
clearCache: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const useHistoricalPriceData: () => UseHistoricalPriceDataReturn;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TokenMetadata } from "../types";
|
|
2
|
+
export interface UseTokenSelectionMetadataReturn {
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
isPriceDataReady: boolean;
|
|
5
|
+
longTokensMetadata: Record<string, TokenMetadata | null>;
|
|
6
|
+
shortTokensMetadata: Record<string, TokenMetadata | null>;
|
|
7
|
+
weightedRatio: number;
|
|
8
|
+
weightedRatio24h: number;
|
|
9
|
+
sumNetFunding: number;
|
|
10
|
+
maxLeverage: number;
|
|
11
|
+
minMargin: number;
|
|
12
|
+
leverageMatched: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const useTokenSelectionMetadata: () => UseTokenSelectionMetadataReturn;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook to access trade histories with loading state
|
|
3
|
-
*/
|
|
4
1
|
export declare const useTradeHistories: () => {
|
|
5
|
-
data:
|
|
2
|
+
data: any;
|
|
6
3
|
isLoading: boolean;
|
|
7
4
|
};
|
|
8
5
|
/**
|
|
9
6
|
* Hook to access open positions with real-time calculations and loading state
|
|
10
7
|
*/
|
|
11
8
|
export declare const useOpenPositions: () => {
|
|
12
|
-
data:
|
|
9
|
+
data: null;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
data: import("..").OpenPositionDto[];
|
|
13
13
|
isLoading: boolean;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Hook to access open orders with loading state
|
|
17
17
|
*/
|
|
18
18
|
export declare const useOpenOrders: () => {
|
|
19
|
-
data:
|
|
19
|
+
data: any;
|
|
20
20
|
isLoading: boolean;
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssetMarketData } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to access webData and native WebSocket state
|
|
4
|
+
*/
|
|
5
|
+
export declare const useWebData: () => {
|
|
6
|
+
clearinghouseState: any;
|
|
7
|
+
perpsAtOpenInterestCap: any;
|
|
8
|
+
marketDataBySymbol: Record<string, AssetMarketData>;
|
|
9
|
+
isConnected: boolean;
|
|
10
|
+
connectionStatus: import("react-use-websocket").ReadyState;
|
|
11
|
+
error: string | null;
|
|
12
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ReadyState } from 'react-use-websocket';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CandleInterval } from './types';
|
|
3
3
|
export interface UseHyperliquidNativeWebSocketProps {
|
|
4
4
|
address: string | null;
|
|
5
|
+
tokens?: string[];
|
|
6
|
+
candleInterval?: CandleInterval;
|
|
5
7
|
}
|
|
6
8
|
export interface UseHyperliquidNativeWebSocketReturn {
|
|
7
|
-
webData2: WebData2Response | null;
|
|
8
|
-
allMids: WsAllMidsData | null;
|
|
9
9
|
connectionStatus: ReadyState;
|
|
10
10
|
isConnected: boolean;
|
|
11
11
|
lastError: string | null;
|
|
12
12
|
}
|
|
13
|
-
export declare const useHyperliquidNativeWebSocket: ({ address }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
|
13
|
+
export declare const useHyperliquidNativeWebSocket: ({ address, tokens, candleInterval }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
+
import * as react_use_websocket from 'react-use-websocket';
|
|
2
3
|
import { ReadyState } from 'react-use-websocket';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -215,7 +216,7 @@ type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'e
|
|
|
215
216
|
/**
|
|
216
217
|
* WebSocket channels
|
|
217
218
|
*/
|
|
218
|
-
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'webData2' | 'allMids';
|
|
219
|
+
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
219
220
|
/**
|
|
220
221
|
* WebSocket subscription message
|
|
221
222
|
*/
|
|
@@ -446,7 +447,8 @@ interface UniverseAsset {
|
|
|
446
447
|
name: string;
|
|
447
448
|
szDecimals: number;
|
|
448
449
|
maxLeverage: number;
|
|
449
|
-
onlyIsolated
|
|
450
|
+
onlyIsolated?: boolean;
|
|
451
|
+
isDelisted?: boolean;
|
|
450
452
|
}
|
|
451
453
|
/**
|
|
452
454
|
* WebData2 response structure
|
|
@@ -519,28 +521,22 @@ interface AssetInformationDetail {
|
|
|
519
521
|
assetIndex: number;
|
|
520
522
|
}
|
|
521
523
|
/**
|
|
522
|
-
*
|
|
524
|
+
* Leverage information from activeAssetData
|
|
523
525
|
*/
|
|
524
|
-
interface
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
size: number;
|
|
528
|
-
side: string;
|
|
526
|
+
interface LeverageInfo {
|
|
527
|
+
type: string;
|
|
528
|
+
value: number;
|
|
529
529
|
}
|
|
530
530
|
/**
|
|
531
|
-
*
|
|
531
|
+
* Active asset data from WebSocket
|
|
532
532
|
*/
|
|
533
|
-
interface
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
leverage:
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
createdAt: string;
|
|
541
|
-
updatedAt: string;
|
|
542
|
-
longAssets: RawAssetDto[];
|
|
543
|
-
shortAssets: RawAssetDto[];
|
|
533
|
+
interface ActiveAssetData {
|
|
534
|
+
user: string;
|
|
535
|
+
coin: string;
|
|
536
|
+
leverage: LeverageInfo;
|
|
537
|
+
maxTradeSzs: [string, string];
|
|
538
|
+
availableToTrade: [string, string];
|
|
539
|
+
markPx: string;
|
|
544
540
|
}
|
|
545
541
|
/**
|
|
546
542
|
* Token metadata from WebData2 and AllMids
|
|
@@ -556,6 +552,9 @@ interface TokenMetadata {
|
|
|
556
552
|
oraclePrice: number;
|
|
557
553
|
openInterest: string;
|
|
558
554
|
dayVolume: string;
|
|
555
|
+
leverage?: LeverageInfo;
|
|
556
|
+
maxTradeSzs?: [string, string];
|
|
557
|
+
availableToTrade?: [string, string];
|
|
559
558
|
}
|
|
560
559
|
/**
|
|
561
560
|
* Enhanced token selection with weight and metadata for basket trading
|
|
@@ -563,7 +562,6 @@ interface TokenMetadata {
|
|
|
563
562
|
interface TokenSelection {
|
|
564
563
|
symbol: string;
|
|
565
564
|
weight: number;
|
|
566
|
-
metadata?: TokenMetadata;
|
|
567
565
|
}
|
|
568
566
|
/**
|
|
569
567
|
* Token conflict information for position conflicts
|
|
@@ -573,6 +571,59 @@ interface TokenConflict {
|
|
|
573
571
|
conflictType: 'long' | 'short';
|
|
574
572
|
conflictMessage: string;
|
|
575
573
|
}
|
|
574
|
+
interface AssetMarketData {
|
|
575
|
+
asset: AssetCtx;
|
|
576
|
+
universe: UniverseAsset;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Candle interval options
|
|
580
|
+
*/
|
|
581
|
+
type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "8h" | "12h" | "1d" | "3d" | "1w" | "1M";
|
|
582
|
+
/**
|
|
583
|
+
* Candle data structure from WebSocket
|
|
584
|
+
*/
|
|
585
|
+
interface CandleData {
|
|
586
|
+
t: number;
|
|
587
|
+
T: number;
|
|
588
|
+
s: string;
|
|
589
|
+
i: string;
|
|
590
|
+
o: string;
|
|
591
|
+
c: string;
|
|
592
|
+
h: string;
|
|
593
|
+
l: string;
|
|
594
|
+
v: string;
|
|
595
|
+
n: number;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Candle chart data organized by symbol only
|
|
599
|
+
* Since new candles always have latest timestamp, no need to store per interval
|
|
600
|
+
*/
|
|
601
|
+
type CandleChartData = Record<string, CandleData>;
|
|
602
|
+
/**
|
|
603
|
+
* Historical candle data request
|
|
604
|
+
*/
|
|
605
|
+
interface CandleSnapshotRequest {
|
|
606
|
+
req: {
|
|
607
|
+
coin: string;
|
|
608
|
+
startTime: number;
|
|
609
|
+
endTime: number;
|
|
610
|
+
interval: CandleInterval;
|
|
611
|
+
};
|
|
612
|
+
type: "candleSnapshot";
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Weighted candle data for chart visualization
|
|
616
|
+
*/
|
|
617
|
+
interface WeightedCandleData {
|
|
618
|
+
t: number;
|
|
619
|
+
T: number;
|
|
620
|
+
o: number;
|
|
621
|
+
c: number;
|
|
622
|
+
h: number;
|
|
623
|
+
l: number;
|
|
624
|
+
v: number;
|
|
625
|
+
n: number;
|
|
626
|
+
}
|
|
576
627
|
|
|
577
628
|
/**
|
|
578
629
|
* Main SDK client for Pear Protocol Hyperliquid API integration
|
|
@@ -615,6 +666,15 @@ declare class PearHyperliquidClient {
|
|
|
615
666
|
* @returns Promise with sync result
|
|
616
667
|
*/
|
|
617
668
|
syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto>>;
|
|
669
|
+
/**
|
|
670
|
+
* Fetch historical candle data from HyperLiquid API
|
|
671
|
+
* @param coin - Token symbol (e.g., 'BTC', 'ETH')
|
|
672
|
+
* @param startTime - Start time in milliseconds
|
|
673
|
+
* @param endTime - End time in milliseconds
|
|
674
|
+
* @param interval - Candle interval
|
|
675
|
+
* @returns Promise with historical candle data
|
|
676
|
+
*/
|
|
677
|
+
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval: string): Promise<ApiResponse<CandleData[]>>;
|
|
618
678
|
}
|
|
619
679
|
|
|
620
680
|
/**
|
|
@@ -711,25 +771,25 @@ declare const useAddress: () => {
|
|
|
711
771
|
isLoggedIn: boolean;
|
|
712
772
|
};
|
|
713
773
|
|
|
714
|
-
/**
|
|
715
|
-
* Hook to access trade histories with loading state
|
|
716
|
-
*/
|
|
717
774
|
declare const useTradeHistories: () => {
|
|
718
|
-
data:
|
|
775
|
+
data: any;
|
|
719
776
|
isLoading: boolean;
|
|
720
777
|
};
|
|
721
778
|
/**
|
|
722
779
|
* Hook to access open positions with real-time calculations and loading state
|
|
723
780
|
*/
|
|
724
781
|
declare const useOpenPositions: () => {
|
|
725
|
-
data:
|
|
782
|
+
data: null;
|
|
783
|
+
isLoading: boolean;
|
|
784
|
+
} | {
|
|
785
|
+
data: OpenPositionDto[];
|
|
726
786
|
isLoading: boolean;
|
|
727
787
|
};
|
|
728
788
|
/**
|
|
729
789
|
* Hook to access open orders with loading state
|
|
730
790
|
*/
|
|
731
791
|
declare const useOpenOrders: () => {
|
|
732
|
-
data:
|
|
792
|
+
data: any;
|
|
733
793
|
isLoading: boolean;
|
|
734
794
|
};
|
|
735
795
|
/**
|
|
@@ -740,76 +800,98 @@ declare const useAccountSummary: () => {
|
|
|
740
800
|
isLoading: boolean;
|
|
741
801
|
};
|
|
742
802
|
|
|
743
|
-
|
|
744
|
-
* Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
|
|
745
|
-
*/
|
|
746
|
-
declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* Hook that calculates account summary by syncing platform data with HyperLiquid real-time data
|
|
750
|
-
*/
|
|
751
|
-
declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
|
|
752
|
-
|
|
753
|
-
interface UseTokenSelectionReturn {
|
|
803
|
+
interface UserSelectionState {
|
|
754
804
|
longTokens: TokenSelection[];
|
|
755
805
|
shortTokens: TokenSelection[];
|
|
756
806
|
openTokenSelector: boolean;
|
|
757
807
|
selectorConfig: TokenSelectorConfig | null;
|
|
758
808
|
openConflictModal: boolean;
|
|
759
809
|
conflicts: TokenConflict[];
|
|
760
|
-
|
|
761
|
-
isPriceDataReady: boolean;
|
|
762
|
-
weightedRatio: number;
|
|
763
|
-
weightedRatio24h: number;
|
|
764
|
-
sumNetFunding: number;
|
|
765
|
-
maxLeverage: number;
|
|
766
|
-
minMargin: number;
|
|
810
|
+
candleInterval: CandleInterval;
|
|
767
811
|
setLongTokens: (tokens: TokenSelection[]) => void;
|
|
768
812
|
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
813
|
setOpenTokenSelector: (open: boolean) => void;
|
|
774
814
|
setSelectorConfig: (config: TokenSelectorConfig | null) => void;
|
|
775
815
|
setOpenConflictModal: (open: boolean) => void;
|
|
776
816
|
setConflicts: (conflicts: TokenConflict[]) => void;
|
|
817
|
+
setCandleInterval: (interval: CandleInterval) => void;
|
|
818
|
+
updateTokenWeight: (isLong: boolean, index: number, newWeight: number) => void;
|
|
819
|
+
addToken: (isLong: boolean) => void;
|
|
820
|
+
removeToken: (isLong: boolean, index: number) => void;
|
|
821
|
+
handleTokenSelect: (selectedToken: string) => void;
|
|
777
822
|
resetToDefaults: () => void;
|
|
778
823
|
}
|
|
824
|
+
|
|
825
|
+
declare const useUserSelection: any;
|
|
826
|
+
|
|
779
827
|
/**
|
|
780
|
-
* Hook to access
|
|
828
|
+
* Hook to access webData and native WebSocket state
|
|
781
829
|
*/
|
|
782
|
-
declare const
|
|
830
|
+
declare const useWebData: () => {
|
|
831
|
+
clearinghouseState: any;
|
|
832
|
+
perpsAtOpenInterestCap: any;
|
|
833
|
+
marketDataBySymbol: Record<string, AssetMarketData>;
|
|
834
|
+
isConnected: boolean;
|
|
835
|
+
connectionStatus: react_use_websocket.ReadyState;
|
|
836
|
+
error: string | null;
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
interface UseTokenSelectionMetadataReturn {
|
|
840
|
+
isLoading: boolean;
|
|
841
|
+
isPriceDataReady: boolean;
|
|
842
|
+
longTokensMetadata: Record<string, TokenMetadata | null>;
|
|
843
|
+
shortTokensMetadata: Record<string, TokenMetadata | null>;
|
|
844
|
+
weightedRatio: number;
|
|
845
|
+
weightedRatio24h: number;
|
|
846
|
+
sumNetFunding: number;
|
|
847
|
+
maxLeverage: number;
|
|
848
|
+
minMargin: number;
|
|
849
|
+
leverageMatched: boolean;
|
|
850
|
+
}
|
|
851
|
+
declare const useTokenSelectionMetadata: () => UseTokenSelectionMetadataReturn;
|
|
783
852
|
|
|
784
|
-
interface
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
853
|
+
interface UseHistoricalPriceDataReturn {
|
|
854
|
+
fetchHistoricalPriceData: (startTime: number, endTime: number, callback?: (data: Record<string, CandleData[]>) => void) => Promise<Record<string, CandleData[]>>;
|
|
855
|
+
hasHistoricalPriceData: (startTime: number, endTime: number) => boolean;
|
|
856
|
+
getHistoricalPriceData: (startTime: number, endTime: number) => Record<string, CandleData[]>;
|
|
857
|
+
isLoading: (symbol?: string) => boolean;
|
|
858
|
+
clearCache: () => void;
|
|
859
|
+
}
|
|
860
|
+
declare const useHistoricalPriceData: () => UseHistoricalPriceDataReturn;
|
|
861
|
+
|
|
862
|
+
interface UseBasketCandlesReturn {
|
|
863
|
+
fetchBasketCandles: (startTime: number, endTime: number) => Promise<WeightedCandleData[]>;
|
|
864
|
+
isLoading: boolean;
|
|
789
865
|
}
|
|
866
|
+
/**
|
|
867
|
+
* Composes historical price fetching with basket candle computation.
|
|
868
|
+
* - Listens to `longTokens` and `shortTokens` from user selection.
|
|
869
|
+
* - Uses `fetchHistoricalPriceData` to retrieve token candles for the range.
|
|
870
|
+
* - Computes and returns weighted basket candles via `computeBasketCandles`.
|
|
871
|
+
*/
|
|
872
|
+
declare const useBasketCandles: () => UseBasketCandlesReturn;
|
|
873
|
+
|
|
790
874
|
interface UseHyperliquidWebSocketProps {
|
|
791
875
|
wsUrl: string;
|
|
792
876
|
address: string | null;
|
|
793
877
|
}
|
|
794
|
-
|
|
795
|
-
data: WebSocketData;
|
|
878
|
+
declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => {
|
|
796
879
|
connectionStatus: ReadyState;
|
|
797
880
|
isConnected: boolean;
|
|
798
881
|
lastError: string | null;
|
|
799
|
-
}
|
|
800
|
-
declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => UseHyperliquidWebSocketReturn;
|
|
882
|
+
};
|
|
801
883
|
|
|
802
884
|
interface UseHyperliquidNativeWebSocketProps {
|
|
803
885
|
address: string | null;
|
|
886
|
+
tokens?: string[];
|
|
887
|
+
candleInterval?: CandleInterval;
|
|
804
888
|
}
|
|
805
889
|
interface UseHyperliquidNativeWebSocketReturn {
|
|
806
|
-
webData2: WebData2Response | null;
|
|
807
|
-
allMids: WsAllMidsData | null;
|
|
808
890
|
connectionStatus: ReadyState;
|
|
809
891
|
isConnected: boolean;
|
|
810
892
|
lastError: string | null;
|
|
811
893
|
}
|
|
812
|
-
declare const useHyperliquidNativeWebSocket: ({ address }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
|
894
|
+
declare const useHyperliquidNativeWebSocket: ({ address, tokens, candleInterval }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
|
813
895
|
|
|
814
896
|
/**
|
|
815
897
|
* Account summary calculation utility class
|
|
@@ -875,17 +957,19 @@ declare class TokenMetadataExtractor {
|
|
|
875
957
|
* @param symbol - Token symbol
|
|
876
958
|
* @param webData2 - WebData2 response containing asset context and universe data
|
|
877
959
|
* @param allMids - AllMids data containing current prices
|
|
960
|
+
* @param activeAssetData - Optional active asset data containing leverage information
|
|
878
961
|
* @returns TokenMetadata or null if token not found
|
|
879
962
|
*/
|
|
880
|
-
static extractTokenMetadata(symbol: string, webData2: WebData2Response | null, allMids: WsAllMidsData | null): TokenMetadata | null;
|
|
963
|
+
static extractTokenMetadata(symbol: string, webData2: WebData2Response | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): TokenMetadata | null;
|
|
881
964
|
/**
|
|
882
965
|
* Extracts metadata for multiple tokens
|
|
883
966
|
* @param symbols - Array of token symbols
|
|
884
967
|
* @param webData2 - WebData2 response
|
|
885
968
|
* @param allMids - AllMids data
|
|
969
|
+
* @param activeAssetData - Optional active asset data containing leverage information
|
|
886
970
|
* @returns Record of symbol to TokenMetadata
|
|
887
971
|
*/
|
|
888
|
-
static extractMultipleTokensMetadata(symbols: string[], webData2: WebData2Response | null, allMids: WsAllMidsData | null): Record<string, TokenMetadata | null>;
|
|
972
|
+
static extractMultipleTokensMetadata(symbols: string[], webData2: WebData2Response | null, allMids: WsAllMidsData | null, activeAssetData?: Record<string, ActiveAssetData> | null): Record<string, TokenMetadata | null>;
|
|
889
973
|
/**
|
|
890
974
|
* Checks if token data is available in WebData2
|
|
891
975
|
* @param symbol - Token symbol
|
|
@@ -895,5 +979,42 @@ declare class TokenMetadataExtractor {
|
|
|
895
979
|
static isTokenAvailable(symbol: string, webData2: WebData2Response | null): boolean;
|
|
896
980
|
}
|
|
897
981
|
|
|
898
|
-
|
|
899
|
-
|
|
982
|
+
/**
|
|
983
|
+
* Create efficient timestamp-based lookup maps for candle data
|
|
984
|
+
*/
|
|
985
|
+
declare const createCandleLookups: (tokenCandles: Record<string, CandleData[]>) => Record<string, Map<number, CandleData>>;
|
|
986
|
+
/**
|
|
987
|
+
* Calculate weighted ratio for a specific price type (open, high, low, close)
|
|
988
|
+
* Uses the formula: LONG_PRODUCT * SHORT_PRODUCT
|
|
989
|
+
* Where LONG_PRODUCT = ∏(PRICE^(WEIGHT/100)) for long tokens
|
|
990
|
+
* And SHORT_PRODUCT = ∏(PRICE^-(WEIGHT/100)) for short tokens
|
|
991
|
+
*
|
|
992
|
+
* Optimized version that uses Map lookups instead of Array.find()
|
|
993
|
+
*/
|
|
994
|
+
declare const calculateWeightedRatio: (longTokens: TokenSelection[], shortTokens: TokenSelection[], candleLookups: Record<string, Map<number, CandleData>>, timestamp: number, priceType: "o" | "h" | "l" | "c") => number;
|
|
995
|
+
/**
|
|
996
|
+
* Get all unique timestamps where ALL required symbols have data
|
|
997
|
+
* Optimized version that uses Map lookups
|
|
998
|
+
*/
|
|
999
|
+
declare const getCompleteTimestamps: (candleLookups: Record<string, Map<number, CandleData>>, requiredSymbols: string[]) => number[];
|
|
1000
|
+
/**
|
|
1001
|
+
* Compute basket candles from individual token candles using weighted ratios
|
|
1002
|
+
* Optimized version that creates lookup maps once and reuses them
|
|
1003
|
+
*/
|
|
1004
|
+
declare const computeBasketCandles: (longTokens: TokenSelection[], shortTokens: TokenSelection[], tokenCandles: Record<string, CandleData[]>) => WeightedCandleData[];
|
|
1005
|
+
|
|
1006
|
+
interface HistoricalRange {
|
|
1007
|
+
start: number;
|
|
1008
|
+
end: number;
|
|
1009
|
+
}
|
|
1010
|
+
interface TokenHistoricalPriceData {
|
|
1011
|
+
symbol: string;
|
|
1012
|
+
interval: CandleInterval;
|
|
1013
|
+
candles: CandleData[];
|
|
1014
|
+
oldestTime: number | null;
|
|
1015
|
+
latestTime: number | null;
|
|
1016
|
+
}
|
|
1017
|
+
declare const useHistoricalPriceDataStore: any;
|
|
1018
|
+
|
|
1019
|
+
export { AccountSummaryCalculator, ConflictDetector, PearHyperliquidClient, PearHyperliquidProvider, PearMigrationSDK, TokenMetadataExtractor, calculateWeightedRatio, computeBasketCandles, createCandleLookups, PearHyperliquidClient as default, getCompleteTimestamps, useAccountSummary, useAddress, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMigrationSDK, useOpenOrders, useOpenPositions, usePearHyperliquidClient, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
|
|
1020
|
+
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetPosition, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, CrossMarginSummaryDto, CumFundingDto, HistoricalRange, MarginSummaryDto, MigrationHookState, MigrationHooks, OpenLimitOrderDto, OpenOrderV1Dto, OpenPositionDto, OpenPositionV1Dto, OrderAssetDto, OrderStatus, PearHyperliquidConfig, PnlDto, PositionAssetDetailDto, PositionSideDto, PositionSyncStatus, RawValueDto, SyncOpenOrderDto, SyncOpenOrderResponseDto, SyncOpenPositionDto, SyncOpenPositionResponseDto, SyncTradeHistoryDto, SyncTradeHistoryResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlDto, TradeHistoryAssetDataDto, TradeHistoryDataDto, TradeHistoryV1Dto, UniverseAsset, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseTokenSelectionMetadataReturn, UserSelectionState, WebData2Response, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketResponse, WebSocketSubscribeMessage, WeightedCandleData, WsAllMidsData };
|