@pear-protocol/hyperliquid-sdk 0.1.23 → 0.1.25
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/clients/tradeHistory.d.ts +7 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/usePnlCalendar.d.ts +61 -0
- package/dist/hooks/usePnlHeatmap.d.ts +13 -0
- package/dist/index.d.ts +90 -6
- package/dist/index.js +462 -3
- package/dist/types.d.ts +13 -4
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ApiResponse, TradeHistoryDataDto } from '../types';
|
|
2
|
+
export interface GetTradeHistoryParams {
|
|
3
|
+
startDate?: string;
|
|
4
|
+
endDate?: string;
|
|
5
|
+
limit?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function getTradeHistory(baseUrl: string, params?: GetTradeHistoryParams): Promise<ApiResponse<TradeHistoryDataDto[]>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type PnlCalendarTimeframe = '2W' | '3W' | '2M' | '3M';
|
|
2
|
+
export interface PnlCalendarOptions {
|
|
3
|
+
timeframe?: PnlCalendarTimeframe;
|
|
4
|
+
startDate?: Date | string;
|
|
5
|
+
endDate?: Date | string;
|
|
6
|
+
}
|
|
7
|
+
export interface PnlCalendarAsset {
|
|
8
|
+
coin: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
assetName: string;
|
|
11
|
+
marketPrefix: string;
|
|
12
|
+
percentage: number;
|
|
13
|
+
collateralToken: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PnlCalendarTrade {
|
|
16
|
+
tradeHistoryId: string;
|
|
17
|
+
realizedPnl: number;
|
|
18
|
+
result: 'profit' | 'loss' | 'breakeven';
|
|
19
|
+
collateralTypes: string[];
|
|
20
|
+
closedLongAssets: PnlCalendarAsset[];
|
|
21
|
+
closedShortAssets: PnlCalendarAsset[];
|
|
22
|
+
}
|
|
23
|
+
export interface PnlCalendarDay {
|
|
24
|
+
date: string;
|
|
25
|
+
totalPnl: number;
|
|
26
|
+
volume: number;
|
|
27
|
+
positionsClosed: number;
|
|
28
|
+
result: 'profit' | 'loss' | 'breakeven';
|
|
29
|
+
trades: PnlCalendarTrade[];
|
|
30
|
+
}
|
|
31
|
+
export interface PeriodSummary {
|
|
32
|
+
pnl: number;
|
|
33
|
+
volume: number;
|
|
34
|
+
winRate: number;
|
|
35
|
+
wins: number;
|
|
36
|
+
losses: number;
|
|
37
|
+
totalProfit: number;
|
|
38
|
+
totalLoss: number;
|
|
39
|
+
}
|
|
40
|
+
export interface PnlCalendarWeek {
|
|
41
|
+
weekStart: string;
|
|
42
|
+
weekEnd: string;
|
|
43
|
+
days: PnlCalendarDay[];
|
|
44
|
+
summary: PeriodSummary;
|
|
45
|
+
}
|
|
46
|
+
export interface PnlCalendarMonth {
|
|
47
|
+
month: string;
|
|
48
|
+
label: string;
|
|
49
|
+
days: PnlCalendarDay[];
|
|
50
|
+
summary: PeriodSummary;
|
|
51
|
+
}
|
|
52
|
+
export interface UsePnlCalendarResult {
|
|
53
|
+
timeframe: PnlCalendarTimeframe;
|
|
54
|
+
weeks: PnlCalendarWeek[];
|
|
55
|
+
months: PnlCalendarMonth[];
|
|
56
|
+
overall: PeriodSummary;
|
|
57
|
+
isLoading: boolean;
|
|
58
|
+
error: string | null;
|
|
59
|
+
refetch: () => void;
|
|
60
|
+
}
|
|
61
|
+
export declare function usePnlCalendar(options?: PnlCalendarTimeframe | PnlCalendarOptions): UsePnlCalendarResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PnlCalendarTrade } from './usePnlCalendar';
|
|
2
|
+
export type PnlHeatmapTimeframe = 'allTime' | '100D' | '30D' | '7D';
|
|
3
|
+
export interface PnlHeatmapTrade extends PnlCalendarTrade {
|
|
4
|
+
percentage: number;
|
|
5
|
+
}
|
|
6
|
+
export interface UsePnlHeatmapResult {
|
|
7
|
+
timeframe: PnlHeatmapTimeframe;
|
|
8
|
+
trades: PnlHeatmapTrade[];
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
error: string | null;
|
|
11
|
+
refetch: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function usePnlHeatmap(timeframe?: PnlHeatmapTimeframe): UsePnlHeatmapResult;
|
package/dist/index.d.ts
CHANGED
|
@@ -504,20 +504,29 @@ interface EIP712AuthDetails {
|
|
|
504
504
|
message: Record<string, unknown>;
|
|
505
505
|
timestamp: number;
|
|
506
506
|
}
|
|
507
|
+
interface GetEIP712MessageRequest {
|
|
508
|
+
address: string;
|
|
509
|
+
clientId: string;
|
|
510
|
+
/** EIP-155 chain ID for EIP712 domain. Optional; server falls back to default EIP712_CHAIN_ID. */
|
|
511
|
+
chainId?: number;
|
|
512
|
+
}
|
|
507
513
|
interface GetEIP712MessageResponse extends EIP712AuthDetails {
|
|
508
514
|
}
|
|
509
515
|
interface PrivyAuthDetails {
|
|
510
516
|
appId: string;
|
|
511
517
|
accessToken: string;
|
|
512
518
|
}
|
|
519
|
+
interface EIP712AuthDetailsRequest {
|
|
520
|
+
signature: string;
|
|
521
|
+
timestamp: number;
|
|
522
|
+
/** EIP-155 chain ID used in signed EIP712 domain. Optional; server falls back to default EIP712_CHAIN_ID. */
|
|
523
|
+
chainId?: number;
|
|
524
|
+
}
|
|
513
525
|
interface AuthenticateRequest {
|
|
514
526
|
method: 'eip712' | 'api_key' | 'privy_access_token';
|
|
515
527
|
address: string;
|
|
516
528
|
clientId: string;
|
|
517
|
-
details: {
|
|
518
|
-
signature: string;
|
|
519
|
-
timestamp: number;
|
|
520
|
-
} | {
|
|
529
|
+
details: EIP712AuthDetailsRequest | {
|
|
521
530
|
apiKey: string;
|
|
522
531
|
} | PrivyAuthDetails;
|
|
523
532
|
}
|
|
@@ -1512,6 +1521,81 @@ interface UseHyperliquidUserFillsState {
|
|
|
1512
1521
|
*/
|
|
1513
1522
|
declare function useHyperliquidUserFills(options: UseHyperliquidUserFillsOptions): UseHyperliquidUserFillsState;
|
|
1514
1523
|
|
|
1524
|
+
type PnlCalendarTimeframe = '2W' | '3W' | '2M' | '3M';
|
|
1525
|
+
interface PnlCalendarOptions {
|
|
1526
|
+
timeframe?: PnlCalendarTimeframe;
|
|
1527
|
+
startDate?: Date | string;
|
|
1528
|
+
endDate?: Date | string;
|
|
1529
|
+
}
|
|
1530
|
+
interface PnlCalendarAsset {
|
|
1531
|
+
coin: string;
|
|
1532
|
+
symbol: string;
|
|
1533
|
+
assetName: string;
|
|
1534
|
+
marketPrefix: string;
|
|
1535
|
+
percentage: number;
|
|
1536
|
+
collateralToken: string;
|
|
1537
|
+
}
|
|
1538
|
+
interface PnlCalendarTrade {
|
|
1539
|
+
tradeHistoryId: string;
|
|
1540
|
+
realizedPnl: number;
|
|
1541
|
+
result: 'profit' | 'loss' | 'breakeven';
|
|
1542
|
+
collateralTypes: string[];
|
|
1543
|
+
closedLongAssets: PnlCalendarAsset[];
|
|
1544
|
+
closedShortAssets: PnlCalendarAsset[];
|
|
1545
|
+
}
|
|
1546
|
+
interface PnlCalendarDay {
|
|
1547
|
+
date: string;
|
|
1548
|
+
totalPnl: number;
|
|
1549
|
+
volume: number;
|
|
1550
|
+
positionsClosed: number;
|
|
1551
|
+
result: 'profit' | 'loss' | 'breakeven';
|
|
1552
|
+
trades: PnlCalendarTrade[];
|
|
1553
|
+
}
|
|
1554
|
+
interface PeriodSummary {
|
|
1555
|
+
pnl: number;
|
|
1556
|
+
volume: number;
|
|
1557
|
+
winRate: number;
|
|
1558
|
+
wins: number;
|
|
1559
|
+
losses: number;
|
|
1560
|
+
totalProfit: number;
|
|
1561
|
+
totalLoss: number;
|
|
1562
|
+
}
|
|
1563
|
+
interface PnlCalendarWeek {
|
|
1564
|
+
weekStart: string;
|
|
1565
|
+
weekEnd: string;
|
|
1566
|
+
days: PnlCalendarDay[];
|
|
1567
|
+
summary: PeriodSummary;
|
|
1568
|
+
}
|
|
1569
|
+
interface PnlCalendarMonth {
|
|
1570
|
+
month: string;
|
|
1571
|
+
label: string;
|
|
1572
|
+
days: PnlCalendarDay[];
|
|
1573
|
+
summary: PeriodSummary;
|
|
1574
|
+
}
|
|
1575
|
+
interface UsePnlCalendarResult {
|
|
1576
|
+
timeframe: PnlCalendarTimeframe;
|
|
1577
|
+
weeks: PnlCalendarWeek[];
|
|
1578
|
+
months: PnlCalendarMonth[];
|
|
1579
|
+
overall: PeriodSummary;
|
|
1580
|
+
isLoading: boolean;
|
|
1581
|
+
error: string | null;
|
|
1582
|
+
refetch: () => void;
|
|
1583
|
+
}
|
|
1584
|
+
declare function usePnlCalendar(options?: PnlCalendarTimeframe | PnlCalendarOptions): UsePnlCalendarResult;
|
|
1585
|
+
|
|
1586
|
+
type PnlHeatmapTimeframe = 'allTime' | '100D' | '30D' | '7D';
|
|
1587
|
+
interface PnlHeatmapTrade extends PnlCalendarTrade {
|
|
1588
|
+
percentage: number;
|
|
1589
|
+
}
|
|
1590
|
+
interface UsePnlHeatmapResult {
|
|
1591
|
+
timeframe: PnlHeatmapTimeframe;
|
|
1592
|
+
trades: PnlHeatmapTrade[];
|
|
1593
|
+
isLoading: boolean;
|
|
1594
|
+
error: string | null;
|
|
1595
|
+
refetch: () => void;
|
|
1596
|
+
}
|
|
1597
|
+
declare function usePnlHeatmap(timeframe?: PnlHeatmapTimeframe): UsePnlHeatmapResult;
|
|
1598
|
+
|
|
1515
1599
|
/**
|
|
1516
1600
|
* Mark notifications as read up to a given timestamp (ms)
|
|
1517
1601
|
*/
|
|
@@ -1799,5 +1883,5 @@ interface MarketDataState {
|
|
|
1799
1883
|
}
|
|
1800
1884
|
declare const useMarketData: zustand.UseBoundStore<zustand.StoreApi<MarketDataState>>;
|
|
1801
1885
|
|
|
1802
|
-
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, ReadyState, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1803
|
-
export type { AccountSummaryResponseDto, ActiveAssetData, ActiveAssetGroupItem, ActiveAssetsAllResponse, ActiveAssetsResponse, AddressState, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, AgentWalletStatus, AllDexsAssetCtxsData, AllDexsClearinghouseStateData, AllPerpMetasItem, AllPerpMetasResponse, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AuthenticateRequest, AuthenticateResponse, AvailableToTrades, BalanceSummaryDto, BaseTriggerOrderNotificationParams, BtcDomTriggerParams, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ChunkFillDto, ClearinghouseState, CloseAllExecutionType, CloseAllPositionsRequestInput, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CloseTriggerType, CollateralToken, CreateAgentWalletResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossAssetPriceTriggerParams, CrossMarginSummaryDto, CumFundingDto, EIP712AuthDetails, ExecutionType, ExternalFillDto, ExternalLiquidationDto, ExtraAgent, GetAgentWalletResponseDto, GetEIP712MessageResponse, GetKalshiMarketsParams, HLChannel, HLChannelDataMap, HLWebSocketResponse, HistoricalRange, KalshiMarket, KalshiMarketsResponse, KalshiMveLeg, KalshiPriceRange, LadderConfigInput, LadderOrderParameters, LeverageInfo, LogoutRequest, LogoutResponse, MarginRequiredPerCollateral, MarginRequiredResult, MarginSummaryDto, MarginTableDef, MarginTablesEntry, MarginTier, MarketOrderParameters, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderDirection, OrderParameters, OrderStatus, OrderType, PairAssetDto, PairAssetInput, PerformanceOverlay, PerpDex, PerpDexsResponse, PerpMetaAsset, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PredictionMarketOutcomeTriggerParams, PriceRatioTriggerParams, PriceTriggerParams, PrivyAuthDetails, RawAssetDto, RawPositionDto, RealtimeBar, RealtimeBarsCallback, RebalanceAssetPlan, RebalancePlan, RefreshTokenRequest, RefreshTokenResponse, SpotBalance, SpotBalances, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, SyncFillsRequestDto, SyncFillsResponseDto, ToggleWatchlistResponseDto, TokenConflict, TokenEntry, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TokenSelectorConfig, TpSlOrderParameters, TpSlThreshold, TpSlThresholdInput, TpSlThresholdType, TpSlTriggerType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TriggerOrderNotificationAsset, TriggerOrderNotificationParams, TriggerOrderNotificationType, TriggerOrderParameters, TriggerType, TwapChunkStatus, TwapChunkStatusDto, TwapMonitoringDto, TwapOrderOverallStatus, TwapOrderParameters, TwapSliceFillResponseItem, UniverseAsset, UpdateLeverageRequestInput, UpdateLeverageResponseDto, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseHyperliquidUserFillsOptions, UseHyperliquidUserFillsState, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserAbstraction, UserProfile, UserSelectionState, WatchlistAssetDto, WatchlistItemDto, WebData3AssetCtx, WebData3PerpDexState, WebData3Response, WebData3UserState, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1886
|
+
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, ReadyState, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePnlCalendar, usePnlHeatmap, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1887
|
+
export type { AccountSummaryResponseDto, ActiveAssetData, ActiveAssetGroupItem, ActiveAssetsAllResponse, ActiveAssetsResponse, AddressState, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, AgentWalletStatus, AllDexsAssetCtxsData, AllDexsClearinghouseStateData, AllPerpMetasItem, AllPerpMetasResponse, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AuthenticateRequest, AuthenticateResponse, AvailableToTrades, BalanceSummaryDto, BaseTriggerOrderNotificationParams, BtcDomTriggerParams, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ChunkFillDto, ClearinghouseState, CloseAllExecutionType, CloseAllPositionsRequestInput, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CloseTriggerType, CollateralToken, CreateAgentWalletResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossAssetPriceTriggerParams, CrossMarginSummaryDto, CumFundingDto, EIP712AuthDetails, EIP712AuthDetailsRequest, ExecutionType, ExternalFillDto, ExternalLiquidationDto, ExtraAgent, GetAgentWalletResponseDto, GetEIP712MessageRequest, GetEIP712MessageResponse, GetKalshiMarketsParams, HLChannel, HLChannelDataMap, HLWebSocketResponse, HistoricalRange, KalshiMarket, KalshiMarketsResponse, KalshiMveLeg, KalshiPriceRange, LadderConfigInput, LadderOrderParameters, LeverageInfo, LogoutRequest, LogoutResponse, MarginRequiredPerCollateral, MarginRequiredResult, MarginSummaryDto, MarginTableDef, MarginTablesEntry, MarginTier, MarketOrderParameters, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderDirection, OrderParameters, OrderStatus, OrderType, PairAssetDto, PairAssetInput, PerformanceOverlay, PeriodSummary, PerpDex, PerpDexsResponse, PerpMetaAsset, PlatformAccountSummaryResponseDto, PnlCalendarAsset, PnlCalendarDay, PnlCalendarMonth, PnlCalendarOptions, PnlCalendarTimeframe, PnlCalendarTrade, PnlCalendarWeek, PnlHeatmapTimeframe, PnlHeatmapTrade, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PredictionMarketOutcomeTriggerParams, PriceRatioTriggerParams, PriceTriggerParams, PrivyAuthDetails, RawAssetDto, RawPositionDto, RealtimeBar, RealtimeBarsCallback, RebalanceAssetPlan, RebalancePlan, RefreshTokenRequest, RefreshTokenResponse, SpotBalance, SpotBalances, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, SyncFillsRequestDto, SyncFillsResponseDto, ToggleWatchlistResponseDto, TokenConflict, TokenEntry, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TokenSelectorConfig, TpSlOrderParameters, TpSlThreshold, TpSlThresholdInput, TpSlThresholdType, TpSlTriggerType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TriggerOrderNotificationAsset, TriggerOrderNotificationParams, TriggerOrderNotificationType, TriggerOrderParameters, TriggerType, TwapChunkStatus, TwapChunkStatusDto, TwapMonitoringDto, TwapOrderOverallStatus, TwapOrderParameters, TwapSliceFillResponseItem, UniverseAsset, UpdateLeverageRequestInput, UpdateLeverageResponseDto, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseHyperliquidUserFillsOptions, UseHyperliquidUserFillsState, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePnlCalendarResult, UsePnlHeatmapResult, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserAbstraction, UserProfile, UserSelectionState, WatchlistAssetDto, WatchlistItemDto, WebData3AssetCtx, WebData3PerpDexState, WebData3Response, WebData3UserState, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -820,8 +820,17 @@ function validateClosePositionRequest(payload) {
|
|
|
820
820
|
}
|
|
821
821
|
|
|
822
822
|
const DEFAULT_STATE = {
|
|
823
|
-
longTokens: [
|
|
824
|
-
|
|
823
|
+
longTokens: [
|
|
824
|
+
{ symbol: "HYPE", weight: 25 },
|
|
825
|
+
{ symbol: "BTC", weight: 25 },
|
|
826
|
+
],
|
|
827
|
+
shortTokens: [
|
|
828
|
+
{ symbol: "AVAX", weight: 10 },
|
|
829
|
+
{ symbol: "SEI", weight: 10 },
|
|
830
|
+
{ symbol: "ADA", weight: 10 },
|
|
831
|
+
{ symbol: "TRUMP", weight: 10 },
|
|
832
|
+
{ symbol: "SUI", weight: 10 },
|
|
833
|
+
],
|
|
825
834
|
openTokenSelector: false,
|
|
826
835
|
selectorConfig: null,
|
|
827
836
|
openConflictModal: false,
|
|
@@ -8465,6 +8474,456 @@ function useHyperliquidUserFills(options) {
|
|
|
8465
8474
|
};
|
|
8466
8475
|
}
|
|
8467
8476
|
|
|
8477
|
+
async function getTradeHistory(baseUrl, params) {
|
|
8478
|
+
const url = joinUrl(baseUrl, '/trade-history');
|
|
8479
|
+
try {
|
|
8480
|
+
const resp = await apiClient.get(url, {
|
|
8481
|
+
params,
|
|
8482
|
+
timeout: 60000,
|
|
8483
|
+
});
|
|
8484
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8485
|
+
}
|
|
8486
|
+
catch (error) {
|
|
8487
|
+
throw toApiError(error);
|
|
8488
|
+
}
|
|
8489
|
+
}
|
|
8490
|
+
|
|
8491
|
+
// ─── helpers ────────────────────────────────────────────────────
|
|
8492
|
+
const EMPTY_SUMMARY = {
|
|
8493
|
+
pnl: 0,
|
|
8494
|
+
volume: 0,
|
|
8495
|
+
winRate: 0,
|
|
8496
|
+
wins: 0,
|
|
8497
|
+
losses: 0,
|
|
8498
|
+
totalProfit: 0,
|
|
8499
|
+
totalLoss: 0,
|
|
8500
|
+
};
|
|
8501
|
+
const getTimeframeDays$1 = (tf) => {
|
|
8502
|
+
switch (tf) {
|
|
8503
|
+
case '2W':
|
|
8504
|
+
return 14;
|
|
8505
|
+
case '3W':
|
|
8506
|
+
return 21;
|
|
8507
|
+
case '2M':
|
|
8508
|
+
return 60;
|
|
8509
|
+
case '3M':
|
|
8510
|
+
return 90;
|
|
8511
|
+
}
|
|
8512
|
+
};
|
|
8513
|
+
const isWeekTimeframe = (tf) => tf === '2W' || tf === '3W';
|
|
8514
|
+
const toDateKey = (date) => {
|
|
8515
|
+
const y = date.getFullYear();
|
|
8516
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
8517
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
8518
|
+
return `${y}-${m}-${d}`;
|
|
8519
|
+
};
|
|
8520
|
+
const toMonthKey = (date) => {
|
|
8521
|
+
const y = date.getFullYear();
|
|
8522
|
+
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
8523
|
+
return `${y}-${m}`;
|
|
8524
|
+
};
|
|
8525
|
+
const formatMonthLabel = (date) => date.toLocaleDateString('en-US', { month: 'short', year: 'numeric' });
|
|
8526
|
+
const getMonday = (date) => {
|
|
8527
|
+
const d = new Date(date);
|
|
8528
|
+
const day = d.getDay(); // 0=Sun … 6=Sat
|
|
8529
|
+
const diff = day === 0 ? -6 : 1 - day;
|
|
8530
|
+
d.setDate(d.getDate() + diff);
|
|
8531
|
+
d.setHours(0, 0, 0, 0);
|
|
8532
|
+
return d;
|
|
8533
|
+
};
|
|
8534
|
+
const toLocalMidnight = (input) => {
|
|
8535
|
+
const d = typeof input === 'string' ? new Date(input + 'T00:00:00') : new Date(input);
|
|
8536
|
+
d.setHours(0, 0, 0, 0);
|
|
8537
|
+
return d;
|
|
8538
|
+
};
|
|
8539
|
+
const diffDays = (start, end) => {
|
|
8540
|
+
return Math.round((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24)) + 1;
|
|
8541
|
+
};
|
|
8542
|
+
const toISODateString$1 = (input) => {
|
|
8543
|
+
const d = typeof input === 'string' ? new Date(input + 'T00:00:00') : new Date(input);
|
|
8544
|
+
return d.toISOString();
|
|
8545
|
+
};
|
|
8546
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
8547
|
+
const mapAsset$1 = (asset, getAssetByName) => {
|
|
8548
|
+
var _a, _b, _c, _d;
|
|
8549
|
+
const metadata = getAssetByName(asset.coin);
|
|
8550
|
+
const marketInfo = getMarketInfoFromSymbol(asset.coin);
|
|
8551
|
+
return {
|
|
8552
|
+
coin: asset.coin,
|
|
8553
|
+
symbol: (_a = metadata === null || metadata === void 0 ? void 0 : metadata.symbolName) !== null && _a !== void 0 ? _a : marketInfo.symbolName,
|
|
8554
|
+
assetName: (_b = metadata === null || metadata === void 0 ? void 0 : metadata.assetName) !== null && _b !== void 0 ? _b : asset.coin,
|
|
8555
|
+
marketPrefix: (_c = metadata === null || metadata === void 0 ? void 0 : metadata.marketName) !== null && _c !== void 0 ? _c : marketInfo.marketName,
|
|
8556
|
+
percentage: asset.closeWeight * 100,
|
|
8557
|
+
collateralToken: (_d = metadata === null || metadata === void 0 ? void 0 : metadata.collateralToken) !== null && _d !== void 0 ? _d : 'USDC',
|
|
8558
|
+
};
|
|
8559
|
+
};
|
|
8560
|
+
const getCollateralTypes$1 = (assets) => {
|
|
8561
|
+
const set = new Set();
|
|
8562
|
+
for (const a of assets)
|
|
8563
|
+
set.add(a.collateralToken);
|
|
8564
|
+
return set.size > 0 ? Array.from(set) : ['USDC'];
|
|
8565
|
+
};
|
|
8566
|
+
const buildSummary = (days) => {
|
|
8567
|
+
let pnl = 0;
|
|
8568
|
+
let volume = 0;
|
|
8569
|
+
let wins = 0;
|
|
8570
|
+
let losses = 0;
|
|
8571
|
+
let totalProfit = 0;
|
|
8572
|
+
let totalLoss = 0;
|
|
8573
|
+
for (const day of days) {
|
|
8574
|
+
pnl += day.totalPnl;
|
|
8575
|
+
volume += day.volume;
|
|
8576
|
+
if (day.positionsClosed === 0)
|
|
8577
|
+
continue;
|
|
8578
|
+
if (day.totalPnl > 0) {
|
|
8579
|
+
wins++;
|
|
8580
|
+
totalProfit += day.totalPnl;
|
|
8581
|
+
}
|
|
8582
|
+
else if (day.totalPnl < 0) {
|
|
8583
|
+
losses++;
|
|
8584
|
+
totalLoss += Math.abs(day.totalPnl);
|
|
8585
|
+
}
|
|
8586
|
+
}
|
|
8587
|
+
const total = wins + losses;
|
|
8588
|
+
const winRate = total > 0 ? Math.round((wins / total) * 100) : 0;
|
|
8589
|
+
return {
|
|
8590
|
+
pnl: round2(pnl),
|
|
8591
|
+
volume: round2(volume),
|
|
8592
|
+
winRate,
|
|
8593
|
+
wins,
|
|
8594
|
+
losses,
|
|
8595
|
+
totalProfit: round2(totalProfit),
|
|
8596
|
+
totalLoss: round2(totalLoss),
|
|
8597
|
+
};
|
|
8598
|
+
};
|
|
8599
|
+
const buildCalendarData = (tradeHistories, timeframe, rangeStart, rangeEnd, totalDays, useCustomDates, getAssetByName) => {
|
|
8600
|
+
const startKey = toDateKey(rangeStart);
|
|
8601
|
+
const endKey = toDateKey(rangeEnd);
|
|
8602
|
+
// Build day buckets for the full range
|
|
8603
|
+
const buckets = new Map();
|
|
8604
|
+
for (let i = 0; i < totalDays; i++) {
|
|
8605
|
+
const d = new Date(rangeStart);
|
|
8606
|
+
d.setDate(rangeStart.getDate() + i);
|
|
8607
|
+
buckets.set(toDateKey(d), {
|
|
8608
|
+
pnl: 0,
|
|
8609
|
+
volume: 0,
|
|
8610
|
+
positionsClosed: 0,
|
|
8611
|
+
trades: [],
|
|
8612
|
+
});
|
|
8613
|
+
}
|
|
8614
|
+
// Populate buckets from trade histories
|
|
8615
|
+
for (const trade of tradeHistories) {
|
|
8616
|
+
if (!trade.createdAt)
|
|
8617
|
+
continue;
|
|
8618
|
+
const date = new Date(trade.createdAt);
|
|
8619
|
+
if (isNaN(date.getTime()))
|
|
8620
|
+
continue;
|
|
8621
|
+
const dateKey = toDateKey(date);
|
|
8622
|
+
if (dateKey < startKey || dateKey > endKey)
|
|
8623
|
+
continue;
|
|
8624
|
+
const bucket = buckets.get(dateKey);
|
|
8625
|
+
if (!bucket)
|
|
8626
|
+
continue;
|
|
8627
|
+
const pnl = trade.realizedPnl;
|
|
8628
|
+
bucket.pnl += isFinite(pnl) ? pnl : 0;
|
|
8629
|
+
const vol = trade.totalValue;
|
|
8630
|
+
bucket.volume += isFinite(vol) ? vol : 0;
|
|
8631
|
+
bucket.positionsClosed += 1;
|
|
8632
|
+
const tradePnl = trade.realizedPnl;
|
|
8633
|
+
const longAssets = trade.closedLongAssets.map((a) => mapAsset$1(a, getAssetByName));
|
|
8634
|
+
const shortAssets = trade.closedShortAssets.map((a) => mapAsset$1(a, getAssetByName));
|
|
8635
|
+
bucket.trades.push({
|
|
8636
|
+
tradeHistoryId: trade.tradeHistoryId,
|
|
8637
|
+
realizedPnl: tradePnl,
|
|
8638
|
+
result: tradePnl > 0 ? 'profit' : tradePnl < 0 ? 'loss' : 'breakeven',
|
|
8639
|
+
collateralTypes: getCollateralTypes$1([...longAssets, ...shortAssets]),
|
|
8640
|
+
closedLongAssets: longAssets,
|
|
8641
|
+
closedShortAssets: shortAssets,
|
|
8642
|
+
});
|
|
8643
|
+
}
|
|
8644
|
+
// Build day objects
|
|
8645
|
+
const allDays = [];
|
|
8646
|
+
const sortedKeys = Array.from(buckets.keys()).sort();
|
|
8647
|
+
for (const key of sortedKeys) {
|
|
8648
|
+
const bucket = buckets.get(key);
|
|
8649
|
+
const roundedPnl = round2(bucket.pnl);
|
|
8650
|
+
const result = roundedPnl > 0 ? 'profit' : roundedPnl < 0 ? 'loss' : 'breakeven';
|
|
8651
|
+
allDays.push({
|
|
8652
|
+
date: key,
|
|
8653
|
+
totalPnl: roundedPnl,
|
|
8654
|
+
volume: round2(bucket.volume),
|
|
8655
|
+
positionsClosed: bucket.positionsClosed,
|
|
8656
|
+
result,
|
|
8657
|
+
trades: bucket.trades,
|
|
8658
|
+
});
|
|
8659
|
+
}
|
|
8660
|
+
// Group into periods
|
|
8661
|
+
let weeks = [];
|
|
8662
|
+
let months = [];
|
|
8663
|
+
const useWeekGrouping = useCustomDates
|
|
8664
|
+
? totalDays <= 28
|
|
8665
|
+
: isWeekTimeframe(timeframe);
|
|
8666
|
+
if (useWeekGrouping) {
|
|
8667
|
+
const weekMap = new Map();
|
|
8668
|
+
for (const day of allDays) {
|
|
8669
|
+
const date = new Date(day.date + 'T00:00:00');
|
|
8670
|
+
const monday = getMonday(date);
|
|
8671
|
+
const mondayKey = toDateKey(monday);
|
|
8672
|
+
if (!weekMap.has(mondayKey)) {
|
|
8673
|
+
weekMap.set(mondayKey, []);
|
|
8674
|
+
}
|
|
8675
|
+
weekMap.get(mondayKey).push(day);
|
|
8676
|
+
}
|
|
8677
|
+
const sortedWeekKeys = Array.from(weekMap.keys()).sort();
|
|
8678
|
+
weeks = sortedWeekKeys.map((mondayKey) => {
|
|
8679
|
+
const days = weekMap.get(mondayKey);
|
|
8680
|
+
const monday = new Date(mondayKey + 'T00:00:00');
|
|
8681
|
+
const sunday = new Date(monday);
|
|
8682
|
+
sunday.setDate(monday.getDate() + 6);
|
|
8683
|
+
return {
|
|
8684
|
+
weekStart: mondayKey,
|
|
8685
|
+
weekEnd: toDateKey(sunday),
|
|
8686
|
+
days,
|
|
8687
|
+
summary: buildSummary(days),
|
|
8688
|
+
};
|
|
8689
|
+
});
|
|
8690
|
+
}
|
|
8691
|
+
else {
|
|
8692
|
+
const monthMap = new Map();
|
|
8693
|
+
for (const day of allDays) {
|
|
8694
|
+
const date = new Date(day.date + 'T00:00:00');
|
|
8695
|
+
const mk = toMonthKey(date);
|
|
8696
|
+
if (!monthMap.has(mk)) {
|
|
8697
|
+
monthMap.set(mk, { days: [], label: formatMonthLabel(date) });
|
|
8698
|
+
}
|
|
8699
|
+
monthMap.get(mk).days.push(day);
|
|
8700
|
+
}
|
|
8701
|
+
const sortedMonthKeys = Array.from(monthMap.keys()).sort();
|
|
8702
|
+
months = sortedMonthKeys.map((mk) => {
|
|
8703
|
+
const { days, label } = monthMap.get(mk);
|
|
8704
|
+
return {
|
|
8705
|
+
month: mk,
|
|
8706
|
+
label,
|
|
8707
|
+
days,
|
|
8708
|
+
summary: buildSummary(days),
|
|
8709
|
+
};
|
|
8710
|
+
});
|
|
8711
|
+
}
|
|
8712
|
+
return {
|
|
8713
|
+
timeframe,
|
|
8714
|
+
weeks,
|
|
8715
|
+
months,
|
|
8716
|
+
overall: buildSummary(allDays),
|
|
8717
|
+
isLoading: false,
|
|
8718
|
+
};
|
|
8719
|
+
};
|
|
8720
|
+
// ─── hook ───────────────────────────────────────────────────────
|
|
8721
|
+
function usePnlCalendar(options) {
|
|
8722
|
+
var _a;
|
|
8723
|
+
const opts = typeof options === 'string'
|
|
8724
|
+
? { timeframe: options }
|
|
8725
|
+
: options !== null && options !== void 0 ? options : {};
|
|
8726
|
+
const timeframe = (_a = opts.timeframe) !== null && _a !== void 0 ? _a : '2W';
|
|
8727
|
+
const customStart = opts.startDate;
|
|
8728
|
+
const customEnd = opts.endDate;
|
|
8729
|
+
const context = useContext(PearHyperliquidContext);
|
|
8730
|
+
if (!context) {
|
|
8731
|
+
throw new Error('usePnlCalendar must be used within a PearHyperliquidProvider');
|
|
8732
|
+
}
|
|
8733
|
+
const { apiBaseUrl } = context;
|
|
8734
|
+
const isAuthenticated = useUserData((state) => state.isAuthenticated);
|
|
8735
|
+
const { getAssetByName } = useMarket();
|
|
8736
|
+
const [trades, setTrades] = useState(null);
|
|
8737
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8738
|
+
const [error, setError] = useState(null);
|
|
8739
|
+
const mountedRef = useRef(true);
|
|
8740
|
+
useEffect(() => {
|
|
8741
|
+
mountedRef.current = true;
|
|
8742
|
+
return () => { mountedRef.current = false; };
|
|
8743
|
+
}, []);
|
|
8744
|
+
// Compute the date range
|
|
8745
|
+
const useCustomDates = !!(customStart && customEnd);
|
|
8746
|
+
let rangeStart;
|
|
8747
|
+
let rangeEnd;
|
|
8748
|
+
let totalDays;
|
|
8749
|
+
if (useCustomDates) {
|
|
8750
|
+
rangeStart = toLocalMidnight(customStart);
|
|
8751
|
+
rangeEnd = toLocalMidnight(customEnd);
|
|
8752
|
+
totalDays = diffDays(rangeStart, rangeEnd);
|
|
8753
|
+
}
|
|
8754
|
+
else {
|
|
8755
|
+
totalDays = getTimeframeDays$1(timeframe);
|
|
8756
|
+
rangeEnd = new Date();
|
|
8757
|
+
rangeEnd.setHours(0, 0, 0, 0);
|
|
8758
|
+
rangeStart = new Date(rangeEnd);
|
|
8759
|
+
rangeStart.setDate(rangeEnd.getDate() - totalDays + 1);
|
|
8760
|
+
}
|
|
8761
|
+
const startIso = toISODateString$1(rangeStart);
|
|
8762
|
+
const endIso = toISODateString$1(rangeEnd);
|
|
8763
|
+
const fetchData = useCallback(async () => {
|
|
8764
|
+
if (!isAuthenticated)
|
|
8765
|
+
return;
|
|
8766
|
+
setIsLoading(true);
|
|
8767
|
+
setError(null);
|
|
8768
|
+
try {
|
|
8769
|
+
const response = await getTradeHistory(apiBaseUrl, {
|
|
8770
|
+
startDate: startIso,
|
|
8771
|
+
endDate: endIso,
|
|
8772
|
+
limit: totalDays * 50,
|
|
8773
|
+
});
|
|
8774
|
+
if (!mountedRef.current)
|
|
8775
|
+
return;
|
|
8776
|
+
setTrades(response.data);
|
|
8777
|
+
}
|
|
8778
|
+
catch (err) {
|
|
8779
|
+
if (!mountedRef.current)
|
|
8780
|
+
return;
|
|
8781
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch trade history');
|
|
8782
|
+
setTrades(null);
|
|
8783
|
+
}
|
|
8784
|
+
finally {
|
|
8785
|
+
if (mountedRef.current)
|
|
8786
|
+
setIsLoading(false);
|
|
8787
|
+
}
|
|
8788
|
+
}, [apiBaseUrl, isAuthenticated, startIso, endIso, totalDays]);
|
|
8789
|
+
useEffect(() => {
|
|
8790
|
+
fetchData();
|
|
8791
|
+
}, [fetchData]);
|
|
8792
|
+
const result = useMemo(() => {
|
|
8793
|
+
const empty = {
|
|
8794
|
+
timeframe,
|
|
8795
|
+
weeks: [],
|
|
8796
|
+
months: [],
|
|
8797
|
+
overall: EMPTY_SUMMARY,
|
|
8798
|
+
isLoading: true,
|
|
8799
|
+
};
|
|
8800
|
+
if (!trades)
|
|
8801
|
+
return empty;
|
|
8802
|
+
if (totalDays <= 0)
|
|
8803
|
+
return empty;
|
|
8804
|
+
return buildCalendarData(trades, timeframe, rangeStart, rangeEnd, totalDays, useCustomDates, getAssetByName);
|
|
8805
|
+
}, [trades, timeframe, startIso, endIso, getAssetByName]);
|
|
8806
|
+
return { ...result, isLoading, error, refetch: fetchData };
|
|
8807
|
+
}
|
|
8808
|
+
|
|
8809
|
+
const HEATMAP_LIMIT = 50;
|
|
8810
|
+
// ─── helpers ────────────────────────────────────────────────────
|
|
8811
|
+
const getTimeframeDays = (tf) => {
|
|
8812
|
+
switch (tf) {
|
|
8813
|
+
case '7D':
|
|
8814
|
+
return 7;
|
|
8815
|
+
case '30D':
|
|
8816
|
+
return 30;
|
|
8817
|
+
case '100D':
|
|
8818
|
+
return 100;
|
|
8819
|
+
case 'allTime':
|
|
8820
|
+
return null;
|
|
8821
|
+
}
|
|
8822
|
+
};
|
|
8823
|
+
const toISODateString = (date) => date.toISOString();
|
|
8824
|
+
const mapAsset = (asset, getAssetByName) => {
|
|
8825
|
+
var _a, _b, _c, _d;
|
|
8826
|
+
const metadata = getAssetByName(asset.coin);
|
|
8827
|
+
const marketInfo = getMarketInfoFromSymbol(asset.coin);
|
|
8828
|
+
return {
|
|
8829
|
+
coin: asset.coin,
|
|
8830
|
+
symbol: (_a = metadata === null || metadata === void 0 ? void 0 : metadata.symbolName) !== null && _a !== void 0 ? _a : marketInfo.symbolName,
|
|
8831
|
+
assetName: (_b = metadata === null || metadata === void 0 ? void 0 : metadata.assetName) !== null && _b !== void 0 ? _b : asset.coin,
|
|
8832
|
+
marketPrefix: (_c = metadata === null || metadata === void 0 ? void 0 : metadata.marketName) !== null && _c !== void 0 ? _c : marketInfo.marketName,
|
|
8833
|
+
percentage: asset.closeWeight * 100,
|
|
8834
|
+
collateralToken: (_d = metadata === null || metadata === void 0 ? void 0 : metadata.collateralToken) !== null && _d !== void 0 ? _d : 'USDC',
|
|
8835
|
+
};
|
|
8836
|
+
};
|
|
8837
|
+
const getCollateralTypes = (assets) => {
|
|
8838
|
+
const set = new Set();
|
|
8839
|
+
for (const a of assets)
|
|
8840
|
+
set.add(a.collateralToken);
|
|
8841
|
+
return set.size > 0 ? Array.from(set) : ['USDC'];
|
|
8842
|
+
};
|
|
8843
|
+
const toCalendarTrade = (trade, getAssetByName) => {
|
|
8844
|
+
const pnl = trade.realizedPnl;
|
|
8845
|
+
const longAssets = trade.closedLongAssets.map((a) => mapAsset(a, getAssetByName));
|
|
8846
|
+
const shortAssets = trade.closedShortAssets.map((a) => mapAsset(a, getAssetByName));
|
|
8847
|
+
return {
|
|
8848
|
+
tradeHistoryId: trade.tradeHistoryId,
|
|
8849
|
+
realizedPnl: pnl,
|
|
8850
|
+
result: pnl > 0 ? 'profit' : pnl < 0 ? 'loss' : 'breakeven',
|
|
8851
|
+
collateralTypes: getCollateralTypes([...longAssets, ...shortAssets]),
|
|
8852
|
+
closedLongAssets: longAssets,
|
|
8853
|
+
closedShortAssets: shortAssets,
|
|
8854
|
+
};
|
|
8855
|
+
};
|
|
8856
|
+
// ─── hook ───────────────────────────────────────────────────────
|
|
8857
|
+
function usePnlHeatmap(timeframe = 'allTime') {
|
|
8858
|
+
const context = useContext(PearHyperliquidContext);
|
|
8859
|
+
if (!context) {
|
|
8860
|
+
throw new Error('usePnlHeatmap must be used within a PearHyperliquidProvider');
|
|
8861
|
+
}
|
|
8862
|
+
const { apiBaseUrl } = context;
|
|
8863
|
+
const isAuthenticated = useUserData((state) => state.isAuthenticated);
|
|
8864
|
+
const { getAssetByName } = useMarket();
|
|
8865
|
+
const [trades, setTrades] = useState(null);
|
|
8866
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8867
|
+
const [error, setError] = useState(null);
|
|
8868
|
+
const mountedRef = useRef(true);
|
|
8869
|
+
useEffect(() => {
|
|
8870
|
+
mountedRef.current = true;
|
|
8871
|
+
return () => { mountedRef.current = false; };
|
|
8872
|
+
}, []);
|
|
8873
|
+
const days = getTimeframeDays(timeframe);
|
|
8874
|
+
let startIso;
|
|
8875
|
+
if (days !== null) {
|
|
8876
|
+
const start = new Date();
|
|
8877
|
+
start.setHours(0, 0, 0, 0);
|
|
8878
|
+
start.setDate(start.getDate() - days);
|
|
8879
|
+
startIso = toISODateString(start);
|
|
8880
|
+
}
|
|
8881
|
+
const fetchData = useCallback(async () => {
|
|
8882
|
+
if (!isAuthenticated)
|
|
8883
|
+
return;
|
|
8884
|
+
setIsLoading(true);
|
|
8885
|
+
setError(null);
|
|
8886
|
+
try {
|
|
8887
|
+
const response = await getTradeHistory(apiBaseUrl, {
|
|
8888
|
+
...(startIso ? { startDate: startIso } : {}),
|
|
8889
|
+
limit: 5000,
|
|
8890
|
+
});
|
|
8891
|
+
if (!mountedRef.current)
|
|
8892
|
+
return;
|
|
8893
|
+
setTrades(response.data);
|
|
8894
|
+
}
|
|
8895
|
+
catch (err) {
|
|
8896
|
+
if (!mountedRef.current)
|
|
8897
|
+
return;
|
|
8898
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch trade history');
|
|
8899
|
+
setTrades(null);
|
|
8900
|
+
}
|
|
8901
|
+
finally {
|
|
8902
|
+
if (mountedRef.current)
|
|
8903
|
+
setIsLoading(false);
|
|
8904
|
+
}
|
|
8905
|
+
}, [apiBaseUrl, isAuthenticated, startIso]);
|
|
8906
|
+
useEffect(() => {
|
|
8907
|
+
fetchData();
|
|
8908
|
+
}, [fetchData]);
|
|
8909
|
+
const result = useMemo(() => {
|
|
8910
|
+
if (!trades)
|
|
8911
|
+
return [];
|
|
8912
|
+
const top = trades
|
|
8913
|
+
.slice()
|
|
8914
|
+
.sort((a, b) => Math.abs(b.realizedPnl) - Math.abs(a.realizedPnl))
|
|
8915
|
+
.slice(0, HEATMAP_LIMIT);
|
|
8916
|
+
const totalAbsPnl = top.reduce((sum, t) => sum + Math.abs(t.realizedPnl), 0);
|
|
8917
|
+
return top.map((t) => ({
|
|
8918
|
+
...toCalendarTrade(t, getAssetByName),
|
|
8919
|
+
percentage: totalAbsPnl > 0
|
|
8920
|
+
? Math.round((Math.abs(t.realizedPnl) / totalAbsPnl) * 10000) / 100
|
|
8921
|
+
: 0,
|
|
8922
|
+
}));
|
|
8923
|
+
}, [trades, getAssetByName]);
|
|
8924
|
+
return { timeframe, trades: result, isLoading, error, refetch: fetchData };
|
|
8925
|
+
}
|
|
8926
|
+
|
|
8468
8927
|
const PearHyperliquidContext = createContext(undefined);
|
|
8469
8928
|
/**
|
|
8470
8929
|
* React Provider for PearHyperliquidClient
|
|
@@ -8816,4 +9275,4 @@ function getOrderTrailingInfo(order) {
|
|
|
8816
9275
|
return undefined;
|
|
8817
9276
|
}
|
|
8818
9277
|
|
|
8819
|
-
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
9278
|
+
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePnlCalendar, usePnlHeatmap, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
package/dist/types.d.ts
CHANGED
|
@@ -476,20 +476,29 @@ export interface EIP712AuthDetails {
|
|
|
476
476
|
message: Record<string, unknown>;
|
|
477
477
|
timestamp: number;
|
|
478
478
|
}
|
|
479
|
+
export interface GetEIP712MessageRequest {
|
|
480
|
+
address: string;
|
|
481
|
+
clientId: string;
|
|
482
|
+
/** EIP-155 chain ID for EIP712 domain. Optional; server falls back to default EIP712_CHAIN_ID. */
|
|
483
|
+
chainId?: number;
|
|
484
|
+
}
|
|
479
485
|
export interface GetEIP712MessageResponse extends EIP712AuthDetails {
|
|
480
486
|
}
|
|
481
487
|
export interface PrivyAuthDetails {
|
|
482
488
|
appId: string;
|
|
483
489
|
accessToken: string;
|
|
484
490
|
}
|
|
491
|
+
export interface EIP712AuthDetailsRequest {
|
|
492
|
+
signature: string;
|
|
493
|
+
timestamp: number;
|
|
494
|
+
/** EIP-155 chain ID used in signed EIP712 domain. Optional; server falls back to default EIP712_CHAIN_ID. */
|
|
495
|
+
chainId?: number;
|
|
496
|
+
}
|
|
485
497
|
export interface AuthenticateRequest {
|
|
486
498
|
method: 'eip712' | 'api_key' | 'privy_access_token';
|
|
487
499
|
address: string;
|
|
488
500
|
clientId: string;
|
|
489
|
-
details: {
|
|
490
|
-
signature: string;
|
|
491
|
-
timestamp: number;
|
|
492
|
-
} | {
|
|
501
|
+
details: EIP712AuthDetailsRequest | {
|
|
493
502
|
apiKey: string;
|
|
494
503
|
} | PrivyAuthDetails;
|
|
495
504
|
}
|