@pear-protocol/hyperliquid-sdk 0.0.45 → 0.0.47-alpha

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.
@@ -0,0 +1,39 @@
1
+ import type { ApiResponse } from '../types';
2
+ export type PortfolioInterval = '1d' | '1w' | '1m' | '1y' | 'all';
3
+ export interface PortfolioBucketDto {
4
+ periodStart: string;
5
+ periodEnd: string;
6
+ volume: number;
7
+ openInterest: number;
8
+ winningTradesCount: number;
9
+ winningTradesUsd: number;
10
+ losingTradesCount: number;
11
+ losingTradesUsd: number;
12
+ }
13
+ export interface PortfolioOverallDto {
14
+ totalWinningTradesCount: number;
15
+ totalLosingTradesCount: number;
16
+ totalWinningUsd: number;
17
+ totalLosingUsd: number;
18
+ currentOpenInterest: number;
19
+ currentTotalVolume: number;
20
+ unrealizedPnl: number;
21
+ totalTrades: number;
22
+ }
23
+ export interface PortfolioIntervalsDto {
24
+ oneDay: PortfolioBucketDto[];
25
+ oneWeek: PortfolioBucketDto[];
26
+ oneMonth: PortfolioBucketDto[];
27
+ oneYear: PortfolioBucketDto[];
28
+ all: PortfolioBucketDto[];
29
+ }
30
+ export interface PortfolioResponseDto {
31
+ intervals: PortfolioIntervalsDto;
32
+ overall: PortfolioOverallDto;
33
+ }
34
+ /**
35
+ * Get portfolio summary buckets and overall metrics
36
+ * Returns bucketed volume, open interest snapshot, win/loss trade counts, and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
37
+ * Caller should supply an accessToken from localStorage.getItem('accessToken')
38
+ */
39
+ export declare function getPortfolio(baseUrl: string, accessToken: string): Promise<ApiResponse<PortfolioResponseDto>>;
@@ -27,6 +27,7 @@ export interface CreatePositionRequestInput {
27
27
  twapDuration?: number;
28
28
  twapIntervalSeconds?: number;
29
29
  randomizeExecution?: boolean;
30
+ referralCode?: string;
30
31
  ladderConfig?: LadderConfigInput;
31
32
  takeProfit?: TpSlThresholdInput | null;
32
33
  stopLoss?: TpSlThresholdInput | null;
@@ -73,6 +74,7 @@ export interface ClosePositionRequestInput {
73
74
  twapDuration?: number;
74
75
  twapIntervalSeconds?: number;
75
76
  randomizeExecution?: boolean;
77
+ referralCode?: string;
76
78
  }
77
79
  export interface ClosePositionResponseDto {
78
80
  orderId: string;
@@ -97,6 +99,7 @@ export interface AdjustPositionRequestInput {
97
99
  adjustmentSize: number;
98
100
  executionType: AdjustExecutionType;
99
101
  limitRatio?: number;
102
+ referralCode?: string;
100
103
  }
101
104
  export interface AdjustPositionResponseDto {
102
105
  orderId: string;
@@ -6,7 +6,6 @@ export * from './useTokenSelectionMetadata';
6
6
  export * from './useHistoricalPriceData';
7
7
  export * from './useBasketCandles';
8
8
  export * from './usePerformanceOverlays';
9
- export * from './useAuth';
10
9
  export * from './useAgentWallet';
11
10
  export * from './useAutoSyncFills';
12
11
  export * from './usePosition';
@@ -15,3 +14,4 @@ export * from './useTwap';
15
14
  export * from './useNotifications';
16
15
  export * from './useMarketData';
17
16
  export * from './useWatchlist';
17
+ export * from './usePortfolio';
@@ -0,0 +1,13 @@
1
+ import { type PortfolioResponseDto } from '../clients/portfolio';
2
+ export interface UsePortfolioResult {
3
+ data: PortfolioResponseDto | null;
4
+ isLoading: boolean;
5
+ error: Error | null;
6
+ refetch: () => Promise<void>;
7
+ }
8
+ /**
9
+ * Hook to fetch and manage portfolio data
10
+ * Returns bucketed volume, open interest snapshot, win/loss trade counts,
11
+ * and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
12
+ */
13
+ export declare function usePortfolio(): UsePortfolioResult;
@@ -7,6 +7,5 @@ export declare const useWebData: () => {
7
7
  perpsAtOpenInterestCap: string[] | undefined;
8
8
  marketDataBySymbol: Record<string, AssetMarketData>;
9
9
  isConnected: boolean;
10
- connectionStatus: import("react-use-websocket").ReadyState;
11
10
  error: string | null;
12
11
  };
@@ -1,10 +1,8 @@
1
- import { ReadyState } from 'react-use-websocket';
2
1
  export interface UseHyperliquidNativeWebSocketProps {
3
2
  address: string | null;
4
3
  tokens?: string[];
5
4
  }
6
5
  export interface UseHyperliquidNativeWebSocketReturn {
7
- connectionStatus: ReadyState;
8
6
  isConnected: boolean;
9
7
  lastError: string | null;
10
8
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import React, { ReactNode } from 'react';
2
- import * as react_use_websocket from 'react-use-websocket';
3
- import { ReadyState } from 'react-use-websocket';
4
2
 
5
3
  interface ApiErrorResponse {
6
4
  statusCode: number;
@@ -589,10 +587,8 @@ interface PearHyperliquidContextType {
589
587
  wsUrl: string;
590
588
  address: string | null;
591
589
  setAddress: (address: string | null) => void;
592
- connectionStatus: ReadyState;
593
590
  isConnected: boolean;
594
591
  lastError: string | null;
595
- nativeConnectionStatus: ReadyState;
596
592
  nativeIsConnected: boolean;
597
593
  nativeLastError: string | null;
598
594
  authStatus: AuthStatus;
@@ -719,7 +715,6 @@ declare const useWebData: () => {
719
715
  perpsAtOpenInterestCap: string[] | undefined;
720
716
  marketDataBySymbol: Record<string, AssetMarketData>;
721
717
  isConnected: boolean;
722
- connectionStatus: react_use_websocket.ReadyState;
723
718
  error: string | null;
724
719
  };
725
720
 
@@ -804,19 +799,6 @@ interface UsePerformanceOverlaysReturn {
804
799
  }
805
800
  declare const usePerformanceOverlays: () => UsePerformanceOverlaysReturn;
806
801
 
807
- declare function useAuth(): {
808
- readonly status: AuthStatus;
809
- readonly isAuthenticated: boolean;
810
- readonly accessToken: string | null;
811
- readonly user: UserProfile | null;
812
- readonly error: string | null;
813
- readonly getEip712: (address: string) => Promise<any>;
814
- readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
815
- readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
816
- readonly refreshTokens: () => Promise<any>;
817
- readonly logout: () => Promise<void>;
818
- };
819
-
820
802
  declare function useAgentWallet({ baseUrl }: UseAgentWalletOptions): {
821
803
  readonly agentWallet: AgentWalletState;
822
804
  readonly isReady: boolean;
@@ -899,6 +881,7 @@ interface CreatePositionRequestInput {
899
881
  twapDuration?: number;
900
882
  twapIntervalSeconds?: number;
901
883
  randomizeExecution?: boolean;
884
+ referralCode?: string;
902
885
  ladderConfig?: LadderConfigInput;
903
886
  takeProfit?: TpSlThresholdInput | null;
904
887
  stopLoss?: TpSlThresholdInput | null;
@@ -945,6 +928,7 @@ interface ClosePositionRequestInput {
945
928
  twapDuration?: number;
946
929
  twapIntervalSeconds?: number;
947
930
  randomizeExecution?: boolean;
931
+ referralCode?: string;
948
932
  }
949
933
  interface ClosePositionResponseDto {
950
934
  orderId: string;
@@ -969,6 +953,7 @@ interface AdjustPositionRequestInput {
969
953
  adjustmentSize: number;
970
954
  executionType: AdjustExecutionType;
971
955
  limitRatio?: number;
956
+ referralCode?: string;
972
957
  }
973
958
  interface AdjustPositionResponseDto {
974
959
  orderId: string;
@@ -1034,12 +1019,63 @@ declare function useWatchlist(): {
1034
1019
  readonly toggle: (longAssets: WatchlistAssetDto[], shortAssets: WatchlistAssetDto[]) => Promise<ApiResponse<ToggleWatchlistResponseDto>>;
1035
1020
  };
1036
1021
 
1022
+ type PortfolioInterval = '1d' | '1w' | '1m' | '1y' | 'all';
1023
+ interface PortfolioBucketDto {
1024
+ periodStart: string;
1025
+ periodEnd: string;
1026
+ volume: number;
1027
+ openInterest: number;
1028
+ winningTradesCount: number;
1029
+ winningTradesUsd: number;
1030
+ losingTradesCount: number;
1031
+ losingTradesUsd: number;
1032
+ }
1033
+ interface PortfolioOverallDto {
1034
+ totalWinningTradesCount: number;
1035
+ totalLosingTradesCount: number;
1036
+ totalWinningUsd: number;
1037
+ totalLosingUsd: number;
1038
+ currentOpenInterest: number;
1039
+ currentTotalVolume: number;
1040
+ unrealizedPnl: number;
1041
+ totalTrades: number;
1042
+ }
1043
+ interface PortfolioIntervalsDto {
1044
+ oneDay: PortfolioBucketDto[];
1045
+ oneWeek: PortfolioBucketDto[];
1046
+ oneMonth: PortfolioBucketDto[];
1047
+ oneYear: PortfolioBucketDto[];
1048
+ all: PortfolioBucketDto[];
1049
+ }
1050
+ interface PortfolioResponseDto {
1051
+ intervals: PortfolioIntervalsDto;
1052
+ overall: PortfolioOverallDto;
1053
+ }
1054
+ /**
1055
+ * Get portfolio summary buckets and overall metrics
1056
+ * Returns bucketed volume, open interest snapshot, win/loss trade counts, and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
1057
+ * Caller should supply an accessToken from localStorage.getItem('accessToken')
1058
+ */
1059
+ declare function getPortfolio(baseUrl: string, accessToken: string): Promise<ApiResponse<PortfolioResponseDto>>;
1060
+
1061
+ interface UsePortfolioResult {
1062
+ data: PortfolioResponseDto | null;
1063
+ isLoading: boolean;
1064
+ error: Error | null;
1065
+ refetch: () => Promise<void>;
1066
+ }
1067
+ /**
1068
+ * Hook to fetch and manage portfolio data
1069
+ * Returns bucketed volume, open interest snapshot, win/loss trade counts,
1070
+ * and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
1071
+ */
1072
+ declare function usePortfolio(): UsePortfolioResult;
1073
+
1037
1074
  interface UseHyperliquidWebSocketProps {
1038
1075
  wsUrl: string;
1039
1076
  address: string | null;
1040
1077
  }
1041
1078
  declare const useHyperliquidWebSocket: ({ wsUrl, address }: UseHyperliquidWebSocketProps) => {
1042
- connectionStatus: ReadyState;
1043
1079
  isConnected: boolean;
1044
1080
  lastError: string | null;
1045
1081
  };
@@ -1049,7 +1085,6 @@ interface UseHyperliquidNativeWebSocketProps {
1049
1085
  tokens?: string[];
1050
1086
  }
1051
1087
  interface UseHyperliquidNativeWebSocketReturn {
1052
- connectionStatus: ReadyState;
1053
1088
  isConnected: boolean;
1054
1089
  lastError: string | null;
1055
1090
  }
@@ -1215,5 +1250,5 @@ declare function validatePositionSize(usdValue: number, longAssets?: PairAssetIn
1215
1250
 
1216
1251
  declare const useMarketData: any;
1217
1252
 
1218
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, 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, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
1219
- 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, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
1253
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, getPortfolio, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
1254
+ 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, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };