@pear-protocol/hyperliquid-sdk 0.0.13 → 0.0.16
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 -7
- 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 +3 -5
- package/dist/index.d.ts +161 -78
- package/dist/index.js +9886 -8
- package/dist/provider.d.ts +0 -22
- 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 -20
- package/dist/types.d.ts +55 -2
- package/dist/utils/basket-calculator.d.ts +24 -0
- package/dist/websocket.d.ts +2 -12
- package/package.json +2 -4
- package/dist/hooks/use-webdata2.d.ts +0 -10
- package/dist/hooks/useCalculatedAccountSummary.d.ts +0 -5
- package/dist/hooks/useCalculatedPositions.d.ts +0 -5
package/dist/provider.d.ts
CHANGED
|
@@ -3,26 +3,10 @@ import { ReadyState } from 'react-use-websocket';
|
|
|
3
3
|
import { PearHyperliquidClient } from './client';
|
|
4
4
|
import { PearHyperliquidConfig } from './types';
|
|
5
5
|
import { PearMigrationSDK } from './migration-sdk';
|
|
6
|
-
import type { RawPositionDto, OpenLimitOrderDto, AccountSummaryResponseDto, WebData2Response, WsAllMidsData, TradeHistoryDataDto, TokenSelection, TokenConflict, ActiveAssetData } from './types';
|
|
7
|
-
interface WebSocketData {
|
|
8
|
-
tradeHistories: TradeHistoryDataDto[] | null;
|
|
9
|
-
openPositions: RawPositionDto[] | null;
|
|
10
|
-
openOrders: OpenLimitOrderDto[] | null;
|
|
11
|
-
accountSummary: AccountSummaryResponseDto | null;
|
|
12
|
-
}
|
|
13
6
|
export interface TokenSelectorConfig {
|
|
14
7
|
isLong: boolean;
|
|
15
8
|
index: number;
|
|
16
9
|
}
|
|
17
|
-
interface TokenSelectionState {
|
|
18
|
-
longTokens: TokenSelection[];
|
|
19
|
-
shortTokens: TokenSelection[];
|
|
20
|
-
openTokenSelector: boolean;
|
|
21
|
-
selectorConfig: TokenSelectorConfig | null;
|
|
22
|
-
openConflictModal: boolean;
|
|
23
|
-
conflicts: TokenConflict[];
|
|
24
|
-
leverageMatched: boolean;
|
|
25
|
-
}
|
|
26
10
|
export interface PearHyperliquidContextType {
|
|
27
11
|
client: PearHyperliquidClient;
|
|
28
12
|
migrationSDK: PearMigrationSDK;
|
|
@@ -30,16 +14,10 @@ export interface PearHyperliquidContextType {
|
|
|
30
14
|
setAddress: (address: string | null) => void;
|
|
31
15
|
connectionStatus: ReadyState;
|
|
32
16
|
isConnected: boolean;
|
|
33
|
-
data: WebSocketData;
|
|
34
17
|
lastError: string | null;
|
|
35
18
|
nativeConnectionStatus: ReadyState;
|
|
36
19
|
nativeIsConnected: boolean;
|
|
37
20
|
nativeLastError: string | null;
|
|
38
|
-
webData2: WebData2Response | null;
|
|
39
|
-
allMids: WsAllMidsData | null;
|
|
40
|
-
activeAssetData: Record<string, ActiveAssetData> | null;
|
|
41
|
-
tokenSelection: TokenSelectionState;
|
|
42
|
-
setTokenSelection: React.Dispatch<React.SetStateAction<TokenSelectionState>>;
|
|
43
21
|
}
|
|
44
22
|
export declare const PearHyperliquidContext: React.Context<PearHyperliquidContextType | undefined>;
|
|
45
23
|
interface PearHyperliquidProviderProps {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CandleData, CandleInterval } from "../types";
|
|
2
|
+
interface HistoricalRange {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
}
|
|
6
|
+
interface TokenHistoricalPriceData {
|
|
7
|
+
symbol: string;
|
|
8
|
+
interval: CandleInterval;
|
|
9
|
+
candles: CandleData[];
|
|
10
|
+
oldestTime: number | null;
|
|
11
|
+
latestTime: number | null;
|
|
12
|
+
}
|
|
13
|
+
export declare const useHistoricalPriceDataStore: any;
|
|
14
|
+
export type { HistoricalRange, TokenHistoricalPriceData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useHyperliquidData: any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActiveAssetData, TokenSelection, TokenMetadata, WebData2Response, WsAllMidsData } from "../types";
|
|
2
|
+
export interface TokenSelectionMetadataState {
|
|
3
|
+
isPriceDataReady: boolean;
|
|
4
|
+
isLoading: 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
|
+
recompute: (args: {
|
|
14
|
+
webData2: WebData2Response | null;
|
|
15
|
+
allMids: WsAllMidsData | null;
|
|
16
|
+
activeAssetData: Record<string, ActiveAssetData> | null;
|
|
17
|
+
longTokens: TokenSelection[];
|
|
18
|
+
shortTokens: TokenSelection[];
|
|
19
|
+
}) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare const useTokenSelectionMetadataStore: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useUserData: any;
|
|
@@ -1,34 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { TokenSelectorConfig } from
|
|
3
|
-
|
|
4
|
-
export interface UseTokenSelectionReturn {
|
|
1
|
+
import type { CandleInterval, TokenConflict, TokenSelection } from "../types";
|
|
2
|
+
import type { TokenSelectorConfig } from "../provider";
|
|
3
|
+
interface UserSelectionState {
|
|
5
4
|
longTokens: TokenSelection[];
|
|
6
5
|
shortTokens: TokenSelection[];
|
|
7
6
|
openTokenSelector: boolean;
|
|
8
7
|
selectorConfig: TokenSelectorConfig | null;
|
|
9
8
|
openConflictModal: boolean;
|
|
10
9
|
conflicts: TokenConflict[];
|
|
11
|
-
|
|
12
|
-
isPriceDataReady: boolean;
|
|
13
|
-
weightedRatio: number;
|
|
14
|
-
weightedRatio24h: number;
|
|
15
|
-
sumNetFunding: number;
|
|
16
|
-
maxLeverage: number;
|
|
17
|
-
minMargin: number;
|
|
18
|
-
leverageMatched: boolean;
|
|
10
|
+
candleInterval: CandleInterval;
|
|
19
11
|
setLongTokens: (tokens: TokenSelection[]) => void;
|
|
20
12
|
setShortTokens: (tokens: TokenSelection[]) => void;
|
|
21
|
-
updateTokenWeight: (isLong: boolean, index: number, newWeight: number) => void;
|
|
22
|
-
addToken: (isLong: boolean) => void;
|
|
23
|
-
removeToken: (isLong: boolean, index: number) => void;
|
|
24
|
-
handleTokenSelect: (selectedToken: string) => void;
|
|
25
13
|
setOpenTokenSelector: (open: boolean) => void;
|
|
26
14
|
setSelectorConfig: (config: TokenSelectorConfig | null) => void;
|
|
27
15
|
setOpenConflictModal: (open: boolean) => void;
|
|
28
16
|
setConflicts: (conflicts: TokenConflict[]) => void;
|
|
17
|
+
setCandleInterval: (interval: CandleInterval) => void;
|
|
18
|
+
updateTokenWeight: (isLong: boolean, index: number, newWeight: number) => void;
|
|
19
|
+
addToken: (isLong: boolean) => void;
|
|
20
|
+
removeToken: (isLong: boolean, index: number) => void;
|
|
21
|
+
handleTokenSelect: (selectedToken: string) => void;
|
|
29
22
|
resetToDefaults: () => void;
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
export declare const useTokenSelection: () => UseTokenSelectionReturn;
|
|
24
|
+
export declare const useUserSelection: any;
|
|
25
|
+
export type { UserSelectionState };
|
package/dist/types.d.ts
CHANGED
|
@@ -452,7 +452,8 @@ export interface UniverseAsset {
|
|
|
452
452
|
name: string;
|
|
453
453
|
szDecimals: number;
|
|
454
454
|
maxLeverage: number;
|
|
455
|
-
onlyIsolated
|
|
455
|
+
onlyIsolated?: boolean;
|
|
456
|
+
isDelisted?: boolean;
|
|
456
457
|
}
|
|
457
458
|
/**
|
|
458
459
|
* WebData2 response structure
|
|
@@ -590,7 +591,6 @@ export interface TokenMetadata {
|
|
|
590
591
|
export interface TokenSelection {
|
|
591
592
|
symbol: string;
|
|
592
593
|
weight: number;
|
|
593
|
-
metadata?: TokenMetadata;
|
|
594
594
|
}
|
|
595
595
|
/**
|
|
596
596
|
* Token conflict information for position conflicts
|
|
@@ -600,3 +600,56 @@ export interface TokenConflict {
|
|
|
600
600
|
conflictType: 'long' | 'short';
|
|
601
601
|
conflictMessage: string;
|
|
602
602
|
}
|
|
603
|
+
export interface AssetMarketData {
|
|
604
|
+
asset: AssetCtx;
|
|
605
|
+
universe: UniverseAsset;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Candle interval options
|
|
609
|
+
*/
|
|
610
|
+
export type CandleInterval = "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "8h" | "12h" | "1d" | "3d" | "1w" | "1M";
|
|
611
|
+
/**
|
|
612
|
+
* Candle data structure from WebSocket
|
|
613
|
+
*/
|
|
614
|
+
export interface CandleData {
|
|
615
|
+
t: number;
|
|
616
|
+
T: number;
|
|
617
|
+
s: string;
|
|
618
|
+
i: string;
|
|
619
|
+
o: string;
|
|
620
|
+
c: string;
|
|
621
|
+
h: string;
|
|
622
|
+
l: string;
|
|
623
|
+
v: string;
|
|
624
|
+
n: number;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Candle chart data organized by symbol only
|
|
628
|
+
* Since new candles always have latest timestamp, no need to store per interval
|
|
629
|
+
*/
|
|
630
|
+
export type CandleChartData = Record<string, CandleData>;
|
|
631
|
+
/**
|
|
632
|
+
* Historical candle data request
|
|
633
|
+
*/
|
|
634
|
+
export interface CandleSnapshotRequest {
|
|
635
|
+
req: {
|
|
636
|
+
coin: string;
|
|
637
|
+
startTime: number;
|
|
638
|
+
endTime: number;
|
|
639
|
+
interval: CandleInterval;
|
|
640
|
+
};
|
|
641
|
+
type: "candleSnapshot";
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Weighted candle data for chart visualization
|
|
645
|
+
*/
|
|
646
|
+
export interface WeightedCandleData {
|
|
647
|
+
t: number;
|
|
648
|
+
T: number;
|
|
649
|
+
o: number;
|
|
650
|
+
c: number;
|
|
651
|
+
h: number;
|
|
652
|
+
l: number;
|
|
653
|
+
v: number;
|
|
654
|
+
n: number;
|
|
655
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CandleData, TokenSelection, WeightedCandleData } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create efficient timestamp-based lookup maps for candle data
|
|
4
|
+
*/
|
|
5
|
+
export declare const createCandleLookups: (tokenCandles: Record<string, CandleData[]>) => Record<string, Map<number, CandleData>>;
|
|
6
|
+
/**
|
|
7
|
+
* Calculate weighted ratio for a specific price type (open, high, low, close)
|
|
8
|
+
* Uses the formula: LONG_PRODUCT * SHORT_PRODUCT
|
|
9
|
+
* Where LONG_PRODUCT = ∏(PRICE^(WEIGHT/100)) for long tokens
|
|
10
|
+
* And SHORT_PRODUCT = ∏(PRICE^-(WEIGHT/100)) for short tokens
|
|
11
|
+
*
|
|
12
|
+
* Optimized version that uses Map lookups instead of Array.find()
|
|
13
|
+
*/
|
|
14
|
+
export declare const calculateWeightedRatio: (longTokens: TokenSelection[], shortTokens: TokenSelection[], candleLookups: Record<string, Map<number, CandleData>>, timestamp: number, priceType: "o" | "h" | "l" | "c") => number;
|
|
15
|
+
/**
|
|
16
|
+
* Get all unique timestamps where ALL required symbols have data
|
|
17
|
+
* Optimized version that uses Map lookups
|
|
18
|
+
*/
|
|
19
|
+
export declare const getCompleteTimestamps: (candleLookups: Record<string, Map<number, CandleData>>, requiredSymbols: string[]) => number[];
|
|
20
|
+
/**
|
|
21
|
+
* Compute basket candles from individual token candles using weighted ratios
|
|
22
|
+
* Optimized version that creates lookup maps once and reuses them
|
|
23
|
+
*/
|
|
24
|
+
export declare const computeBasketCandles: (longTokens: TokenSelection[], shortTokens: TokenSelection[], tokenCandles: Record<string, CandleData[]>) => WeightedCandleData[];
|
package/dist/websocket.d.ts
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { ReadyState } from 'react-use-websocket';
|
|
2
|
-
import type { OpenLimitOrderDto, AccountSummaryResponseDto, RawPositionDto, TradeHistoryDataDto } from './types';
|
|
3
|
-
interface WebSocketData {
|
|
4
|
-
tradeHistories: TradeHistoryDataDto[] | null;
|
|
5
|
-
openPositions: RawPositionDto[] | null;
|
|
6
|
-
openOrders: OpenLimitOrderDto[] | null;
|
|
7
|
-
accountSummary: AccountSummaryResponseDto | null;
|
|
8
|
-
}
|
|
9
2
|
export interface UseHyperliquidWebSocketProps {
|
|
10
3
|
wsUrl: string;
|
|
11
4
|
address: string | null;
|
|
12
5
|
}
|
|
13
|
-
export
|
|
14
|
-
data: WebSocketData;
|
|
6
|
+
export declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => {
|
|
15
7
|
connectionStatus: ReadyState;
|
|
16
8
|
isConnected: boolean;
|
|
17
9
|
lastError: string | null;
|
|
18
|
-
}
|
|
19
|
-
export declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => UseHyperliquidWebSocketReturn;
|
|
20
|
-
export {};
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -15,9 +15,7 @@
|
|
|
15
15
|
"clean": "rimraf dist"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"react-use-websocket": "^4.8.1"
|
|
19
|
-
},
|
|
20
|
-
"peerDependencies": {
|
|
18
|
+
"react-use-websocket": "^4.8.1",
|
|
21
19
|
"react": ">=16.8.0",
|
|
22
20
|
"react-dom": ">=16.8.0",
|
|
23
21
|
"axios": "^1.6.0"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook to access webData2 and native WebSocket state
|
|
3
|
-
*/
|
|
4
|
-
export declare const useWebData2: () => {
|
|
5
|
-
webData2: import("..").WebData2Response | null;
|
|
6
|
-
allMids: import("..").WsAllMidsData | null;
|
|
7
|
-
isConnected: boolean;
|
|
8
|
-
connectionStatus: import("react-use-websocket").ReadyState;
|
|
9
|
-
error: string | null;
|
|
10
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AccountSummaryResponseDto, WebData2Response, OpenLimitOrderDto } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that calculates account summary by syncing platform data with HyperLiquid real-time data
|
|
4
|
-
*/
|
|
5
|
-
export declare const useCalculatedAccountSummary: (platformAccountSummary: AccountSummaryResponseDto | null, platformOpenOrders: OpenLimitOrderDto[] | null, webData2: WebData2Response | null, agentWalletAddress?: string, agentWalletStatus?: string) => AccountSummaryResponseDto | null;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { OpenPositionDto, RawPositionDto, WebData2Response, WsAllMidsData } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* Hook that calculates open positions by syncing platform positions with HyperLiquid real-time data
|
|
4
|
-
*/
|
|
5
|
-
export declare const useCalculatedOpenPositions: (platformPositions: RawPositionDto[] | null, webData2: WebData2Response | null, allMids: WsAllMidsData | null) => OpenPositionDto[] | null;
|