@pear-protocol/hyperliquid-sdk 0.0.41 → 0.0.43
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/README.md +562 -267
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useMarketData.d.ts +7 -0
- package/dist/hooks/useTokenSelectionMetadata.d.ts +4 -0
- package/dist/index.d.ts +42 -3
- package/dist/index.js +161 -12
- package/dist/store/marketDataStore.d.ts +1 -0
- package/dist/store/tokenSelectionMetadataStore.d.ts +6 -1
- package/dist/types.d.ts +27 -1
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ActiveAssetGroupItem, ActiveAssetsResponse } from '../types';
|
|
2
|
+
export declare const useMarketDataPayload: () => ActiveAssetsResponse | null;
|
|
3
|
+
export declare const useActiveBaskets: () => ActiveAssetGroupItem[];
|
|
4
|
+
export declare const useTopGainers: (limit?: number) => ActiveAssetGroupItem[];
|
|
5
|
+
export declare const useTopLosers: (limit?: number) => ActiveAssetGroupItem[];
|
|
6
|
+
export declare const useHighlightedBaskets: () => ActiveAssetGroupItem[];
|
|
7
|
+
export declare const useFindBasket: (longs: string[], shorts: string[]) => ActiveAssetGroupItem | undefined;
|
|
@@ -6,6 +6,10 @@ export interface UseTokenSelectionMetadataReturn {
|
|
|
6
6
|
shortTokensMetadata: Record<string, TokenMetadata | null>;
|
|
7
7
|
weightedRatio: number;
|
|
8
8
|
weightedRatio24h: number;
|
|
9
|
+
priceRatio: number;
|
|
10
|
+
priceRatio24h: number;
|
|
11
|
+
openInterest: string;
|
|
12
|
+
volume: string;
|
|
9
13
|
sumNetFunding: number;
|
|
10
14
|
maxLeverage: number;
|
|
11
15
|
minMargin: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'e
|
|
|
30
30
|
/**
|
|
31
31
|
* WebSocket channels
|
|
32
32
|
*/
|
|
33
|
-
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
33
|
+
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
34
34
|
/**
|
|
35
35
|
* WebSocket subscription message
|
|
36
36
|
*/
|
|
@@ -132,6 +132,8 @@ interface TradeHistoryDataDto {
|
|
|
132
132
|
totalValue: number;
|
|
133
133
|
entryRatio: number;
|
|
134
134
|
exitRatio: number;
|
|
135
|
+
entryPriceRatio?: number;
|
|
136
|
+
exitpPriceRatio?: number;
|
|
135
137
|
longAssets: TradeHistoryAssetDataDto[];
|
|
136
138
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
137
139
|
createdAt: string;
|
|
@@ -174,6 +176,8 @@ interface OpenPositionDto {
|
|
|
174
176
|
takeProfit: TpSlThreshold | null;
|
|
175
177
|
entryRatio: number;
|
|
176
178
|
markRatio: number;
|
|
179
|
+
entryPriceRatio?: number;
|
|
180
|
+
markPriceRatio?: number;
|
|
177
181
|
entryPositionValue: number;
|
|
178
182
|
positionValue: number;
|
|
179
183
|
marginUsed: number;
|
|
@@ -507,6 +511,28 @@ interface AssetMarketData {
|
|
|
507
511
|
asset: AssetCtx;
|
|
508
512
|
universe: UniverseAsset;
|
|
509
513
|
}
|
|
514
|
+
interface PairAssetDto {
|
|
515
|
+
asset: string;
|
|
516
|
+
weight: number;
|
|
517
|
+
}
|
|
518
|
+
interface ActiveAssetGroupItem {
|
|
519
|
+
longAssets: PairAssetDto[];
|
|
520
|
+
shortAssets: PairAssetDto[];
|
|
521
|
+
openInterest: string;
|
|
522
|
+
volume: string;
|
|
523
|
+
ratio?: string;
|
|
524
|
+
prevRatio?: string;
|
|
525
|
+
change24h?: string;
|
|
526
|
+
weightedRatio?: string;
|
|
527
|
+
weightedPrevRatio?: string;
|
|
528
|
+
weightedChange24h?: string;
|
|
529
|
+
}
|
|
530
|
+
interface ActiveAssetsResponse {
|
|
531
|
+
active: ActiveAssetGroupItem[];
|
|
532
|
+
topGainers: ActiveAssetGroupItem[];
|
|
533
|
+
topLosers: ActiveAssetGroupItem[];
|
|
534
|
+
highlighted: ActiveAssetGroupItem[];
|
|
535
|
+
}
|
|
510
536
|
/**
|
|
511
537
|
* Candle interval options
|
|
512
538
|
*/
|
|
@@ -691,6 +717,10 @@ interface UseTokenSelectionMetadataReturn {
|
|
|
691
717
|
shortTokensMetadata: Record<string, TokenMetadata | null>;
|
|
692
718
|
weightedRatio: number;
|
|
693
719
|
weightedRatio24h: number;
|
|
720
|
+
priceRatio: number;
|
|
721
|
+
priceRatio24h: number;
|
|
722
|
+
openInterest: string;
|
|
723
|
+
volume: string;
|
|
694
724
|
sumNetFunding: number;
|
|
695
725
|
maxLeverage: number;
|
|
696
726
|
minMargin: number;
|
|
@@ -976,6 +1006,13 @@ interface UseNotificationsResult {
|
|
|
976
1006
|
*/
|
|
977
1007
|
declare function useNotifications(): UseNotificationsResult;
|
|
978
1008
|
|
|
1009
|
+
declare const useMarketDataPayload: () => ActiveAssetsResponse | null;
|
|
1010
|
+
declare const useActiveBaskets: () => ActiveAssetGroupItem[];
|
|
1011
|
+
declare const useTopGainers: (limit?: number) => ActiveAssetGroupItem[];
|
|
1012
|
+
declare const useTopLosers: (limit?: number) => ActiveAssetGroupItem[];
|
|
1013
|
+
declare const useHighlightedBaskets: () => ActiveAssetGroupItem[];
|
|
1014
|
+
declare const useFindBasket: (longs: string[], shorts: string[]) => ActiveAssetGroupItem | undefined;
|
|
1015
|
+
|
|
979
1016
|
interface UseHyperliquidWebSocketProps {
|
|
980
1017
|
wsUrl: string;
|
|
981
1018
|
address: string | null;
|
|
@@ -1112,5 +1149,7 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1112
1149
|
*/
|
|
1113
1150
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1114
1151
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1152
|
+
declare const useMarketData: any;
|
|
1153
|
+
|
|
1154
|
+
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWebData };
|
|
1155
|
+
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -2451,8 +2451,15 @@ const useUserData = create((set) => ({
|
|
|
2451
2451
|
}),
|
|
2452
2452
|
}));
|
|
2453
2453
|
|
|
2454
|
+
const useMarketData = create((set) => ({
|
|
2455
|
+
marketData: null,
|
|
2456
|
+
setMarketData: (value) => set({ marketData: value }),
|
|
2457
|
+
clean: () => set({ marketData: null }),
|
|
2458
|
+
}));
|
|
2459
|
+
|
|
2454
2460
|
const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
2455
2461
|
const { setTradeHistories, setRawOpenPositions, setOpenOrders, setAccountSummary, setTwapDetails, setNotifications, clean, } = useUserData();
|
|
2462
|
+
const { setMarketData, clean: cleanMarketData } = useMarketData();
|
|
2456
2463
|
const [lastError, setLastError] = useState(null);
|
|
2457
2464
|
const [lastSubscribedAddress, setLastSubscribedAddress] = useState(null);
|
|
2458
2465
|
// WebSocket connection
|
|
@@ -2499,6 +2506,9 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
|
2499
2506
|
case 'notifications':
|
|
2500
2507
|
setNotifications(dataMessage.data);
|
|
2501
2508
|
break;
|
|
2509
|
+
case 'market-data':
|
|
2510
|
+
setMarketData(dataMessage.data);
|
|
2511
|
+
break;
|
|
2502
2512
|
// 'fills-checkpoint' is intentionally ignored here
|
|
2503
2513
|
}
|
|
2504
2514
|
}
|
|
@@ -2511,38 +2521,61 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
|
2511
2521
|
const isConnected = readyState === dist.ReadyState.OPEN;
|
|
2512
2522
|
// Handle subscription management
|
|
2513
2523
|
useEffect(() => {
|
|
2514
|
-
if (isConnected
|
|
2515
|
-
|
|
2524
|
+
if (!isConnected)
|
|
2525
|
+
return;
|
|
2526
|
+
// Define all available channels
|
|
2527
|
+
const addressSpecificChannels = [
|
|
2528
|
+
'trade-histories',
|
|
2529
|
+
'open-positions',
|
|
2530
|
+
'account-summary',
|
|
2531
|
+
'open-orders',
|
|
2532
|
+
'twap-details',
|
|
2533
|
+
'fills-checkpoint',
|
|
2534
|
+
'notifications'
|
|
2535
|
+
];
|
|
2536
|
+
const globalChannels = ['market-data'];
|
|
2537
|
+
if (address && address !== lastSubscribedAddress) {
|
|
2538
|
+
// Unsubscribe from previous address-specific channels if exists
|
|
2516
2539
|
if (lastSubscribedAddress) {
|
|
2517
2540
|
sendMessage(JSON.stringify({
|
|
2518
2541
|
action: 'unsubscribe',
|
|
2519
|
-
address: lastSubscribedAddress
|
|
2542
|
+
address: lastSubscribedAddress,
|
|
2543
|
+
channels: addressSpecificChannels
|
|
2520
2544
|
}));
|
|
2521
2545
|
}
|
|
2522
|
-
// Subscribe to
|
|
2546
|
+
// Subscribe to all channels (global + address-specific)
|
|
2523
2547
|
sendMessage(JSON.stringify({
|
|
2524
2548
|
action: 'subscribe',
|
|
2525
|
-
address: address
|
|
2549
|
+
address: address,
|
|
2550
|
+
channels: [...globalChannels, ...addressSpecificChannels]
|
|
2526
2551
|
}));
|
|
2527
2552
|
setLastSubscribedAddress(address);
|
|
2528
2553
|
setLastError(null);
|
|
2529
2554
|
}
|
|
2530
2555
|
else if (isConnected && !address && lastSubscribedAddress) {
|
|
2531
|
-
//
|
|
2556
|
+
// Unsubscribe from address-specific channels when address is removed
|
|
2532
2557
|
sendMessage(JSON.stringify({
|
|
2533
2558
|
action: 'unsubscribe',
|
|
2534
|
-
address: lastSubscribedAddress
|
|
2559
|
+
address: lastSubscribedAddress,
|
|
2560
|
+
channels: addressSpecificChannels
|
|
2535
2561
|
}));
|
|
2536
2562
|
setLastSubscribedAddress(null);
|
|
2537
2563
|
}
|
|
2564
|
+
else if (isConnected && !address && !lastSubscribedAddress) {
|
|
2565
|
+
// If no address but connected, subscribe to global channels only
|
|
2566
|
+
sendMessage(JSON.stringify({
|
|
2567
|
+
action: 'subscribe',
|
|
2568
|
+
channels: globalChannels
|
|
2569
|
+
}));
|
|
2570
|
+
}
|
|
2538
2571
|
}, [isConnected, address, lastSubscribedAddress, sendMessage]);
|
|
2539
|
-
// Clear data when address changes
|
|
2572
|
+
// Clear user data when address changes (but keep market data)
|
|
2540
2573
|
useEffect(() => {
|
|
2541
2574
|
if (address !== lastSubscribedAddress) {
|
|
2542
2575
|
clean();
|
|
2543
2576
|
setLastError(null);
|
|
2544
2577
|
}
|
|
2545
|
-
}, [address, lastSubscribedAddress]);
|
|
2578
|
+
}, [address, lastSubscribedAddress, clean]);
|
|
2546
2579
|
return {
|
|
2547
2580
|
connectionStatus: readyState,
|
|
2548
2581
|
isConnected,
|
|
@@ -7251,11 +7284,15 @@ const useTokenSelectionMetadataStore = create((set) => ({
|
|
|
7251
7284
|
shortTokensMetadata: {},
|
|
7252
7285
|
weightedRatio: 1,
|
|
7253
7286
|
weightedRatio24h: 1,
|
|
7287
|
+
priceRatio: 1,
|
|
7288
|
+
priceRatio24h: 1,
|
|
7289
|
+
openInterest: "0",
|
|
7290
|
+
volume: "0",
|
|
7254
7291
|
sumNetFunding: 0,
|
|
7255
7292
|
maxLeverage: 0,
|
|
7256
7293
|
minMargin: 0,
|
|
7257
7294
|
leverageMatched: true,
|
|
7258
|
-
recompute: ({ webData2, allMids, activeAssetData, longTokens, shortTokens }) => {
|
|
7295
|
+
recompute: ({ webData2, allMids, activeAssetData, marketData, longTokens, shortTokens }) => {
|
|
7259
7296
|
const isPriceDataReady = !!(webData2 && allMids);
|
|
7260
7297
|
// Compute metadata when ready
|
|
7261
7298
|
const longSymbols = longTokens.map((t) => t.symbol);
|
|
@@ -7276,6 +7313,42 @@ const useTokenSelectionMetadataStore = create((set) => ({
|
|
|
7276
7313
|
const allMetadata = { ...longTokensMetadata, ...shortTokensMetadata };
|
|
7277
7314
|
return allTokens.some((token) => !allMetadata[token.symbol]);
|
|
7278
7315
|
})();
|
|
7316
|
+
// Open interest and volume (from market data for matching asset basket)
|
|
7317
|
+
const { openInterest, volume } = (() => {
|
|
7318
|
+
const empty = { openInterest: "0", volume: "0" };
|
|
7319
|
+
if (!(marketData === null || marketData === void 0 ? void 0 : marketData.active) || (!longTokens.length && !shortTokens.length))
|
|
7320
|
+
return empty;
|
|
7321
|
+
const selectedLong = longTokens.map((t) => t.symbol).sort();
|
|
7322
|
+
const selectedShort = shortTokens.map((t) => t.symbol).sort();
|
|
7323
|
+
const match = marketData.active.find((item) => {
|
|
7324
|
+
const longs = [...item.longAssets].sort();
|
|
7325
|
+
const shorts = [...item.shortAssets].sort();
|
|
7326
|
+
if (longs.length !== selectedLong.length || shorts.length !== selectedShort.length)
|
|
7327
|
+
return false;
|
|
7328
|
+
const longsEqual = longs.every((s, i) => s.asset === selectedLong[i]);
|
|
7329
|
+
const shortsEqual = shorts.every((s, i) => s.asset === selectedShort[i]);
|
|
7330
|
+
return longsEqual && shortsEqual;
|
|
7331
|
+
});
|
|
7332
|
+
return match ? { openInterest: match.openInterest, volume: match.volume } : empty;
|
|
7333
|
+
})();
|
|
7334
|
+
// Price ratio (only when exactly one long and one short)
|
|
7335
|
+
const { priceRatio, priceRatio24h } = (() => {
|
|
7336
|
+
var _a, _b, _c, _d;
|
|
7337
|
+
if (longTokens.length !== 1 || shortTokens.length !== 1) {
|
|
7338
|
+
return { priceRatio: 1, priceRatio24h: 1 };
|
|
7339
|
+
}
|
|
7340
|
+
const longSymbol = longTokens[0].symbol;
|
|
7341
|
+
const shortSymbol = shortTokens[0].symbol;
|
|
7342
|
+
const longMeta = longTokensMetadata[longSymbol];
|
|
7343
|
+
const shortMeta = shortTokensMetadata[shortSymbol];
|
|
7344
|
+
const currentLong = (_a = longMeta === null || longMeta === void 0 ? void 0 : longMeta.currentPrice) !== null && _a !== void 0 ? _a : 0;
|
|
7345
|
+
const currentShort = (_b = shortMeta === null || shortMeta === void 0 ? void 0 : shortMeta.currentPrice) !== null && _b !== void 0 ? _b : 0;
|
|
7346
|
+
const prevLong = (_c = longMeta === null || longMeta === void 0 ? void 0 : longMeta.prevDayPrice) !== null && _c !== void 0 ? _c : 0;
|
|
7347
|
+
const prevShort = (_d = shortMeta === null || shortMeta === void 0 ? void 0 : shortMeta.prevDayPrice) !== null && _d !== void 0 ? _d : 0;
|
|
7348
|
+
const ratio = currentShort !== 0 ? currentLong / currentShort : 1;
|
|
7349
|
+
const ratio24h = prevShort !== 0 ? prevLong / prevShort : 1;
|
|
7350
|
+
return { priceRatio: ratio, priceRatio24h: ratio24h };
|
|
7351
|
+
})();
|
|
7279
7352
|
// Weighted ratio (current)
|
|
7280
7353
|
const weightedRatio = (() => {
|
|
7281
7354
|
let longProduct = 1;
|
|
@@ -7380,6 +7453,10 @@ const useTokenSelectionMetadataStore = create((set) => ({
|
|
|
7380
7453
|
shortTokensMetadata,
|
|
7381
7454
|
weightedRatio,
|
|
7382
7455
|
weightedRatio24h,
|
|
7456
|
+
priceRatio,
|
|
7457
|
+
priceRatio24h,
|
|
7458
|
+
openInterest,
|
|
7459
|
+
volume,
|
|
7383
7460
|
sumNetFunding,
|
|
7384
7461
|
maxLeverage,
|
|
7385
7462
|
minMargin,
|
|
@@ -7396,14 +7473,16 @@ const useTokenSelectionMetadata = () => {
|
|
|
7396
7473
|
const webData2 = useHyperliquidData((state) => state.webData2);
|
|
7397
7474
|
const allMids = useHyperliquidData((state) => state.allMids);
|
|
7398
7475
|
const activeAssetData = useHyperliquidData((state) => state.activeAssetData);
|
|
7476
|
+
const marketData = useMarketData((state) => state.marketData);
|
|
7399
7477
|
const { longTokens, shortTokens } = useUserSelection$1();
|
|
7400
|
-
const { isLoading, isPriceDataReady, longTokensMetadata, shortTokensMetadata, weightedRatio, weightedRatio24h, sumNetFunding, maxLeverage, minMargin, leverageMatched, recompute, } = useTokenSelectionMetadataStore();
|
|
7478
|
+
const { isLoading, isPriceDataReady, longTokensMetadata, shortTokensMetadata, weightedRatio, weightedRatio24h, priceRatio, priceRatio24h, openInterest, volume, sumNetFunding, maxLeverage, minMargin, leverageMatched, recompute, } = useTokenSelectionMetadataStore();
|
|
7401
7479
|
// Recompute derived metadata when inputs change
|
|
7402
7480
|
useEffect(() => {
|
|
7403
7481
|
recompute({
|
|
7404
7482
|
webData2,
|
|
7405
7483
|
allMids,
|
|
7406
7484
|
activeAssetData: activeAssetData || null,
|
|
7485
|
+
marketData: marketData || null,
|
|
7407
7486
|
longTokens,
|
|
7408
7487
|
shortTokens,
|
|
7409
7488
|
});
|
|
@@ -7419,6 +7498,10 @@ const useTokenSelectionMetadata = () => {
|
|
|
7419
7498
|
// Calculated values
|
|
7420
7499
|
weightedRatio,
|
|
7421
7500
|
weightedRatio24h,
|
|
7501
|
+
priceRatio,
|
|
7502
|
+
priceRatio24h,
|
|
7503
|
+
openInterest,
|
|
7504
|
+
volume,
|
|
7422
7505
|
sumNetFunding,
|
|
7423
7506
|
maxLeverage,
|
|
7424
7507
|
minMargin,
|
|
@@ -8412,6 +8495,17 @@ const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
|
8412
8495
|
return mappedPositionAssets;
|
|
8413
8496
|
});
|
|
8414
8497
|
mappedPosition.positionValue = mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
|
|
8498
|
+
// If exactly one long and one short asset, include simple price ratios
|
|
8499
|
+
if (position.longAssets.length === 1 && position.shortAssets.length === 1) {
|
|
8500
|
+
const long = position.longAssets[0];
|
|
8501
|
+
const short = position.shortAssets[0];
|
|
8502
|
+
const longMark = parseFloat(allMids.mids[long.coin]);
|
|
8503
|
+
const shortMark = parseFloat(allMids.mids[short.coin]);
|
|
8504
|
+
// entryPriceRatio = long entry price / short entry price
|
|
8505
|
+
mappedPosition.entryPriceRatio = long.entryPrice / short.entryPrice;
|
|
8506
|
+
// markPriceRatio = long current price / short current price
|
|
8507
|
+
mappedPosition.markPriceRatio = longMark / shortMark;
|
|
8508
|
+
}
|
|
8415
8509
|
return mappedPosition;
|
|
8416
8510
|
});
|
|
8417
8511
|
};
|
|
@@ -8643,6 +8737,61 @@ function useNotifications() {
|
|
|
8643
8737
|
};
|
|
8644
8738
|
}
|
|
8645
8739
|
|
|
8740
|
+
// Base selector for the full market-data payload
|
|
8741
|
+
const useMarketDataPayload = () => {
|
|
8742
|
+
return useMarketData((s) => s.marketData);
|
|
8743
|
+
};
|
|
8744
|
+
// Active baskets
|
|
8745
|
+
const useActiveBaskets = () => {
|
|
8746
|
+
var _a;
|
|
8747
|
+
const data = useMarketDataPayload();
|
|
8748
|
+
return (_a = data === null || data === void 0 ? void 0 : data.active) !== null && _a !== void 0 ? _a : [];
|
|
8749
|
+
};
|
|
8750
|
+
// Top gainers (optional limit override)
|
|
8751
|
+
const useTopGainers = (limit) => {
|
|
8752
|
+
const data = useMarketDataPayload();
|
|
8753
|
+
return useMemo(() => {
|
|
8754
|
+
var _a;
|
|
8755
|
+
const list = (_a = data === null || data === void 0 ? void 0 : data.topGainers) !== null && _a !== void 0 ? _a : [];
|
|
8756
|
+
return typeof limit === 'number' ? list.slice(0, Math.max(0, limit)) : list;
|
|
8757
|
+
}, [data, limit]);
|
|
8758
|
+
};
|
|
8759
|
+
// Top losers (optional limit override)
|
|
8760
|
+
const useTopLosers = (limit) => {
|
|
8761
|
+
const data = useMarketDataPayload();
|
|
8762
|
+
return useMemo(() => {
|
|
8763
|
+
var _a;
|
|
8764
|
+
const list = (_a = data === null || data === void 0 ? void 0 : data.topLosers) !== null && _a !== void 0 ? _a : [];
|
|
8765
|
+
return typeof limit === 'number' ? list.slice(0, Math.max(0, limit)) : list;
|
|
8766
|
+
}, [data, limit]);
|
|
8767
|
+
};
|
|
8768
|
+
// Highlighted baskets
|
|
8769
|
+
const useHighlightedBaskets = () => {
|
|
8770
|
+
var _a;
|
|
8771
|
+
const data = useMarketDataPayload();
|
|
8772
|
+
return (_a = data === null || data === void 0 ? void 0 : data.highlighted) !== null && _a !== void 0 ? _a : [];
|
|
8773
|
+
};
|
|
8774
|
+
// Find a basket by its exact asset composition (order-insensitive)
|
|
8775
|
+
const useFindBasket = (longs, shorts) => {
|
|
8776
|
+
const data = useMarketDataPayload();
|
|
8777
|
+
return useMemo(() => {
|
|
8778
|
+
if (!data)
|
|
8779
|
+
return undefined;
|
|
8780
|
+
const normalize = (arr) => Array.isArray(arr)
|
|
8781
|
+
? arr
|
|
8782
|
+
.map((v) => (typeof v === 'string' ? v : v === null || v === void 0 ? void 0 : v.asset))
|
|
8783
|
+
.filter(Boolean)
|
|
8784
|
+
.map((s) => s.toUpperCase())
|
|
8785
|
+
.sort()
|
|
8786
|
+
.join(',')
|
|
8787
|
+
: '';
|
|
8788
|
+
const lKey = normalize(longs);
|
|
8789
|
+
const sKey = normalize(shorts);
|
|
8790
|
+
const match = (item) => normalize(item.longAssets) === lKey && normalize(item.shortAssets) === sKey;
|
|
8791
|
+
return data.active.find(match) || data.highlighted.find(match);
|
|
8792
|
+
}, [data, longs, shorts]);
|
|
8793
|
+
};
|
|
8794
|
+
|
|
8646
8795
|
const PearHyperliquidContext = createContext(undefined);
|
|
8647
8796
|
/**
|
|
8648
8797
|
* React Provider for PearHyperliquidClient
|
|
@@ -8941,4 +9090,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8941
9090
|
}
|
|
8942
9091
|
}
|
|
8943
9092
|
|
|
8944
|
-
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
|
|
9093
|
+
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWebData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useMarketData: any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActiveAssetData, TokenSelection, TokenMetadata, WebData2Response, WsAllMidsData } from "../types";
|
|
1
|
+
import type { ActiveAssetData, TokenSelection, TokenMetadata, WebData2Response, WsAllMidsData, ActiveAssetsResponse } from "../types";
|
|
2
2
|
export interface TokenSelectionMetadataState {
|
|
3
3
|
isPriceDataReady: boolean;
|
|
4
4
|
isLoading: boolean;
|
|
@@ -6,6 +6,10 @@ export interface TokenSelectionMetadataState {
|
|
|
6
6
|
shortTokensMetadata: Record<string, TokenMetadata | null>;
|
|
7
7
|
weightedRatio: number;
|
|
8
8
|
weightedRatio24h: number;
|
|
9
|
+
priceRatio: number;
|
|
10
|
+
priceRatio24h: number;
|
|
11
|
+
openInterest: string;
|
|
12
|
+
volume: string;
|
|
9
13
|
sumNetFunding: number;
|
|
10
14
|
maxLeverage: number;
|
|
11
15
|
minMargin: number;
|
|
@@ -14,6 +18,7 @@ export interface TokenSelectionMetadataState {
|
|
|
14
18
|
webData2: WebData2Response | null;
|
|
15
19
|
allMids: WsAllMidsData | null;
|
|
16
20
|
activeAssetData: Record<string, ActiveAssetData> | null;
|
|
21
|
+
marketData: ActiveAssetsResponse | null;
|
|
17
22
|
longTokens: TokenSelection[];
|
|
18
23
|
shortTokens: TokenSelection[];
|
|
19
24
|
}) => void;
|
package/dist/types.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnecte
|
|
|
51
51
|
/**
|
|
52
52
|
* WebSocket channels
|
|
53
53
|
*/
|
|
54
|
-
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
54
|
+
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'market-data' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
55
55
|
/**
|
|
56
56
|
* WebSocket subscription message
|
|
57
57
|
*/
|
|
@@ -153,6 +153,8 @@ export interface TradeHistoryDataDto {
|
|
|
153
153
|
totalValue: number;
|
|
154
154
|
entryRatio: number;
|
|
155
155
|
exitRatio: number;
|
|
156
|
+
entryPriceRatio?: number;
|
|
157
|
+
exitpPriceRatio?: number;
|
|
156
158
|
longAssets: TradeHistoryAssetDataDto[];
|
|
157
159
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
158
160
|
createdAt: string;
|
|
@@ -195,6 +197,8 @@ export interface OpenPositionDto {
|
|
|
195
197
|
takeProfit: TpSlThreshold | null;
|
|
196
198
|
entryRatio: number;
|
|
197
199
|
markRatio: number;
|
|
200
|
+
entryPriceRatio?: number;
|
|
201
|
+
markPriceRatio?: number;
|
|
198
202
|
entryPositionValue: number;
|
|
199
203
|
positionValue: number;
|
|
200
204
|
marginUsed: number;
|
|
@@ -592,6 +596,28 @@ export interface AssetMarketData {
|
|
|
592
596
|
asset: AssetCtx;
|
|
593
597
|
universe: UniverseAsset;
|
|
594
598
|
}
|
|
599
|
+
export interface PairAssetDto {
|
|
600
|
+
asset: string;
|
|
601
|
+
weight: number;
|
|
602
|
+
}
|
|
603
|
+
export interface ActiveAssetGroupItem {
|
|
604
|
+
longAssets: PairAssetDto[];
|
|
605
|
+
shortAssets: PairAssetDto[];
|
|
606
|
+
openInterest: string;
|
|
607
|
+
volume: string;
|
|
608
|
+
ratio?: string;
|
|
609
|
+
prevRatio?: string;
|
|
610
|
+
change24h?: string;
|
|
611
|
+
weightedRatio?: string;
|
|
612
|
+
weightedPrevRatio?: string;
|
|
613
|
+
weightedChange24h?: string;
|
|
614
|
+
}
|
|
615
|
+
export interface ActiveAssetsResponse {
|
|
616
|
+
active: ActiveAssetGroupItem[];
|
|
617
|
+
topGainers: ActiveAssetGroupItem[];
|
|
618
|
+
topLosers: ActiveAssetGroupItem[];
|
|
619
|
+
highlighted: ActiveAssetGroupItem[];
|
|
620
|
+
}
|
|
595
621
|
/**
|
|
596
622
|
* Candle interval options
|
|
597
623
|
*/
|