@pear-protocol/hyperliquid-sdk 0.0.45 → 0.0.46
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/portfolio.d.ts +39 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/usePortfolio.d.ts +13 -0
- package/dist/index.d.ts +54 -15
- package/dist/index.js +74 -31
- package/package.json +1 -1
- package/dist/hooks/useAuth.d.ts +0 -12
|
@@ -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>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -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;
|
package/dist/index.d.ts
CHANGED
|
@@ -804,19 +804,6 @@ interface UsePerformanceOverlaysReturn {
|
|
|
804
804
|
}
|
|
805
805
|
declare const usePerformanceOverlays: () => UsePerformanceOverlaysReturn;
|
|
806
806
|
|
|
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
807
|
declare function useAgentWallet({ baseUrl }: UseAgentWalletOptions): {
|
|
821
808
|
readonly agentWallet: AgentWalletState;
|
|
822
809
|
readonly isReady: boolean;
|
|
@@ -1034,6 +1021,58 @@ declare function useWatchlist(): {
|
|
|
1034
1021
|
readonly toggle: (longAssets: WatchlistAssetDto[], shortAssets: WatchlistAssetDto[]) => Promise<ApiResponse<ToggleWatchlistResponseDto>>;
|
|
1035
1022
|
};
|
|
1036
1023
|
|
|
1024
|
+
type PortfolioInterval = '1d' | '1w' | '1m' | '1y' | 'all';
|
|
1025
|
+
interface PortfolioBucketDto {
|
|
1026
|
+
periodStart: string;
|
|
1027
|
+
periodEnd: string;
|
|
1028
|
+
volume: number;
|
|
1029
|
+
openInterest: number;
|
|
1030
|
+
winningTradesCount: number;
|
|
1031
|
+
winningTradesUsd: number;
|
|
1032
|
+
losingTradesCount: number;
|
|
1033
|
+
losingTradesUsd: number;
|
|
1034
|
+
}
|
|
1035
|
+
interface PortfolioOverallDto {
|
|
1036
|
+
totalWinningTradesCount: number;
|
|
1037
|
+
totalLosingTradesCount: number;
|
|
1038
|
+
totalWinningUsd: number;
|
|
1039
|
+
totalLosingUsd: number;
|
|
1040
|
+
currentOpenInterest: number;
|
|
1041
|
+
currentTotalVolume: number;
|
|
1042
|
+
unrealizedPnl: number;
|
|
1043
|
+
totalTrades: number;
|
|
1044
|
+
}
|
|
1045
|
+
interface PortfolioIntervalsDto {
|
|
1046
|
+
oneDay: PortfolioBucketDto[];
|
|
1047
|
+
oneWeek: PortfolioBucketDto[];
|
|
1048
|
+
oneMonth: PortfolioBucketDto[];
|
|
1049
|
+
oneYear: PortfolioBucketDto[];
|
|
1050
|
+
all: PortfolioBucketDto[];
|
|
1051
|
+
}
|
|
1052
|
+
interface PortfolioResponseDto {
|
|
1053
|
+
intervals: PortfolioIntervalsDto;
|
|
1054
|
+
overall: PortfolioOverallDto;
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Get portfolio summary buckets and overall metrics
|
|
1058
|
+
* Returns bucketed volume, open interest snapshot, win/loss trade counts, and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
|
|
1059
|
+
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
1060
|
+
*/
|
|
1061
|
+
declare function getPortfolio(baseUrl: string, accessToken: string): Promise<ApiResponse<PortfolioResponseDto>>;
|
|
1062
|
+
|
|
1063
|
+
interface UsePortfolioResult {
|
|
1064
|
+
data: PortfolioResponseDto | null;
|
|
1065
|
+
isLoading: boolean;
|
|
1066
|
+
error: Error | null;
|
|
1067
|
+
refetch: () => Promise<void>;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Hook to fetch and manage portfolio data
|
|
1071
|
+
* Returns bucketed volume, open interest snapshot, win/loss trade counts,
|
|
1072
|
+
* and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
|
|
1073
|
+
*/
|
|
1074
|
+
declare function usePortfolio(): UsePortfolioResult;
|
|
1075
|
+
|
|
1037
1076
|
interface UseHyperliquidWebSocketProps {
|
|
1038
1077
|
wsUrl: string;
|
|
1039
1078
|
address: string | null;
|
|
@@ -1215,5 +1254,5 @@ declare function validatePositionSize(usdValue: number, longAssets?: PairAssetIn
|
|
|
1215
1254
|
|
|
1216
1255
|
declare const useMarketData: any;
|
|
1217
1256
|
|
|
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,
|
|
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 };
|
|
1257
|
+
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 };
|
|
1258
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import require$$0, { useState, useEffect, useMemo, useRef, useCallback, useContext, createContext } from 'react';
|
|
2
2
|
import require$$1 from 'react-dom';
|
|
3
3
|
import { create } from 'zustand';
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ var hasRequiredReactJsxRuntime_production_min;
|
|
|
27
27
|
function requireReactJsxRuntime_production_min () {
|
|
28
28
|
if (hasRequiredReactJsxRuntime_production_min) return reactJsxRuntime_production_min;
|
|
29
29
|
hasRequiredReactJsxRuntime_production_min = 1;
|
|
30
|
-
var f=
|
|
30
|
+
var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};
|
|
31
31
|
function q(c,a,g){var b,d={},e=null,h=null;void 0!==g&&(e=""+g);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return {$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;
|
|
32
32
|
return reactJsxRuntime_production_min;
|
|
33
33
|
}
|
|
@@ -53,7 +53,7 @@ function requireReactJsxRuntime_development () {
|
|
|
53
53
|
if (process.env.NODE_ENV !== "production") {
|
|
54
54
|
(function() {
|
|
55
55
|
|
|
56
|
-
var React
|
|
56
|
+
var React = require$$0;
|
|
57
57
|
|
|
58
58
|
// ATTENTION
|
|
59
59
|
// When adding new symbols to this file,
|
|
@@ -88,7 +88,7 @@ function requireReactJsxRuntime_development () {
|
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
var ReactSharedInternals = React
|
|
91
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
92
92
|
|
|
93
93
|
function error(format) {
|
|
94
94
|
{
|
|
@@ -2142,7 +2142,7 @@ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || func
|
|
|
2142
2142
|
};
|
|
2143
2143
|
Object.defineProperty(useWebsocket, "__esModule", { value: true });
|
|
2144
2144
|
useWebsocket.useWebSocket = void 0;
|
|
2145
|
-
var react_1$2 =
|
|
2145
|
+
var react_1$2 = require$$0;
|
|
2146
2146
|
var react_dom_1 = require$$1;
|
|
2147
2147
|
var constants_1$2 = constants;
|
|
2148
2148
|
var create_or_join_1 = createOrJoin;
|
|
@@ -2308,7 +2308,7 @@ var __assign$1 = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
|
2308
2308
|
};
|
|
2309
2309
|
Object.defineProperty(useSocketIo, "__esModule", { value: true });
|
|
2310
2310
|
useSocketIo.useSocketIO = void 0;
|
|
2311
|
-
var react_1$1 =
|
|
2311
|
+
var react_1$1 = require$$0;
|
|
2312
2312
|
var use_websocket_1$1 = useWebsocket;
|
|
2313
2313
|
var constants_1$1 = constants;
|
|
2314
2314
|
var emptyEvent = {
|
|
@@ -2377,7 +2377,7 @@ var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) {
|
|
|
2377
2377
|
};
|
|
2378
2378
|
Object.defineProperty(useEventSource$1, "__esModule", { value: true });
|
|
2379
2379
|
useEventSource$1.useEventSource = void 0;
|
|
2380
|
-
var react_1 =
|
|
2380
|
+
var react_1 = require$$0;
|
|
2381
2381
|
var use_websocket_1 = useWebsocket;
|
|
2382
2382
|
var constants_1 = constants;
|
|
2383
2383
|
var useEventSource = function (url, _a, connect) {
|
|
@@ -8234,23 +8234,6 @@ const usePerformanceOverlays = () => {
|
|
|
8234
8234
|
};
|
|
8235
8235
|
};
|
|
8236
8236
|
|
|
8237
|
-
// Refactored to read auth state/actions from Provider context
|
|
8238
|
-
function useAuth() {
|
|
8239
|
-
const ctx = usePearHyperliquid();
|
|
8240
|
-
return {
|
|
8241
|
-
status: ctx.authStatus,
|
|
8242
|
-
isAuthenticated: ctx.isAuthenticated,
|
|
8243
|
-
accessToken: ctx.accessToken,
|
|
8244
|
-
user: ctx.user,
|
|
8245
|
-
error: ctx.authError,
|
|
8246
|
-
getEip712: ctx.getEip712,
|
|
8247
|
-
loginWithSignedMessage: ctx.loginWithSignedMessage,
|
|
8248
|
-
loginWithPrivyToken: ctx.loginWithPrivyToken,
|
|
8249
|
-
refreshTokens: ctx.refreshTokens,
|
|
8250
|
-
logout: ctx.logout,
|
|
8251
|
-
};
|
|
8252
|
-
}
|
|
8253
|
-
|
|
8254
8237
|
/**
|
|
8255
8238
|
* Sync external fills into Pear Hyperliquid service (POST /sync/fills)
|
|
8256
8239
|
*/
|
|
@@ -8971,6 +8954,63 @@ function useWatchlist() {
|
|
|
8971
8954
|
return { watchlists: watchlists !== null && watchlists !== void 0 ? watchlists : null, isLoading, toggle };
|
|
8972
8955
|
}
|
|
8973
8956
|
|
|
8957
|
+
/**
|
|
8958
|
+
* Get portfolio summary buckets and overall metrics
|
|
8959
|
+
* Returns bucketed volume, open interest snapshot, win/loss trade counts, and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
|
|
8960
|
+
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
8961
|
+
*/
|
|
8962
|
+
async function getPortfolio(baseUrl, accessToken) {
|
|
8963
|
+
const url = joinUrl(baseUrl, '/portfolio');
|
|
8964
|
+
try {
|
|
8965
|
+
const resp = await axios$1.get(url, { headers: { Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
|
|
8966
|
+
return { data: resp.data, status: resp.status, headers: resp.headers };
|
|
8967
|
+
}
|
|
8968
|
+
catch (error) {
|
|
8969
|
+
throw toApiError(error);
|
|
8970
|
+
}
|
|
8971
|
+
}
|
|
8972
|
+
|
|
8973
|
+
/**
|
|
8974
|
+
* Hook to fetch and manage portfolio data
|
|
8975
|
+
* Returns bucketed volume, open interest snapshot, win/loss trade counts,
|
|
8976
|
+
* and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
|
|
8977
|
+
*/
|
|
8978
|
+
function usePortfolio() {
|
|
8979
|
+
const context = useContext(PearHyperliquidContext);
|
|
8980
|
+
if (!context) {
|
|
8981
|
+
throw new Error('usePortfolio must be used within a PearHyperliquidProvider');
|
|
8982
|
+
}
|
|
8983
|
+
const { apiBaseUrl, accessToken, isAuthenticated } = context;
|
|
8984
|
+
const [data, setData] = useState(null);
|
|
8985
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
8986
|
+
const [error, setError] = useState(null);
|
|
8987
|
+
const fetchPortfolio = useCallback(async () => {
|
|
8988
|
+
if (!isAuthenticated || !accessToken) {
|
|
8989
|
+
setError(new Error('Not authenticated'));
|
|
8990
|
+
return;
|
|
8991
|
+
}
|
|
8992
|
+
setIsLoading(true);
|
|
8993
|
+
setError(null);
|
|
8994
|
+
try {
|
|
8995
|
+
const response = await getPortfolio(apiBaseUrl, accessToken);
|
|
8996
|
+
setData(response.data);
|
|
8997
|
+
}
|
|
8998
|
+
catch (err) {
|
|
8999
|
+
setError(err instanceof Error ? err : new Error('Failed to fetch portfolio'));
|
|
9000
|
+
setData(null);
|
|
9001
|
+
}
|
|
9002
|
+
finally {
|
|
9003
|
+
setIsLoading(false);
|
|
9004
|
+
}
|
|
9005
|
+
}, [apiBaseUrl, accessToken, isAuthenticated]);
|
|
9006
|
+
return {
|
|
9007
|
+
data,
|
|
9008
|
+
isLoading,
|
|
9009
|
+
error,
|
|
9010
|
+
refetch: fetchPortfolio,
|
|
9011
|
+
};
|
|
9012
|
+
}
|
|
9013
|
+
|
|
8974
9014
|
const PearHyperliquidContext = createContext(undefined);
|
|
8975
9015
|
/**
|
|
8976
9016
|
* React Provider for PearHyperliquidClient
|
|
@@ -8994,7 +9034,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
8994
9034
|
const [accessToken, setAccessToken] = useState(null);
|
|
8995
9035
|
const isAuthenticated = useMemo(() => !!accessToken, [accessToken]);
|
|
8996
9036
|
// Hydrate from existing token
|
|
8997
|
-
|
|
9037
|
+
useEffect(() => {
|
|
8998
9038
|
const access = localStorage.getItem('accessToken');
|
|
8999
9039
|
if (access) {
|
|
9000
9040
|
try {
|
|
@@ -9011,11 +9051,11 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9011
9051
|
}
|
|
9012
9052
|
}
|
|
9013
9053
|
}, [clientId]);
|
|
9014
|
-
const getEip712 =
|
|
9054
|
+
const getEip712 = useCallback(async (address) => {
|
|
9015
9055
|
const { data } = await getEIP712Message(apiBaseUrl, address, clientId);
|
|
9016
9056
|
return data;
|
|
9017
9057
|
}, [apiBaseUrl, clientId]);
|
|
9018
|
-
const loginWithSignedMessage =
|
|
9058
|
+
const loginWithSignedMessage = useCallback(async (address, signature, timestamp) => {
|
|
9019
9059
|
setAuthError(null);
|
|
9020
9060
|
setAuthStatus(AuthStatus.Authenticating);
|
|
9021
9061
|
try {
|
|
@@ -9031,6 +9071,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9031
9071
|
const lower = data.address.toLowerCase();
|
|
9032
9072
|
setUser({ userId: lower, address: lower, appId: clientId });
|
|
9033
9073
|
setAuthStatus(AuthStatus.Authenticated);
|
|
9074
|
+
setAddress(lower);
|
|
9034
9075
|
}
|
|
9035
9076
|
catch (e) {
|
|
9036
9077
|
setAuthError((e === null || e === void 0 ? void 0 : e.message) || 'Authentication failed');
|
|
@@ -9038,7 +9079,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9038
9079
|
throw e;
|
|
9039
9080
|
}
|
|
9040
9081
|
}, [apiBaseUrl, clientId]);
|
|
9041
|
-
const refreshTokens =
|
|
9082
|
+
const refreshTokens = useCallback(async () => {
|
|
9042
9083
|
const refresh = localStorage.getItem('refreshToken');
|
|
9043
9084
|
if (!refresh)
|
|
9044
9085
|
throw new Error('No refresh token');
|
|
@@ -9048,7 +9089,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9048
9089
|
setAccessToken(data.accessToken);
|
|
9049
9090
|
return data;
|
|
9050
9091
|
}, [apiBaseUrl]);
|
|
9051
|
-
const loginWithPrivyToken =
|
|
9092
|
+
const loginWithPrivyToken = useCallback(async (address, appId, privyAccessToken) => {
|
|
9052
9093
|
setAuthError(null);
|
|
9053
9094
|
setAuthStatus(AuthStatus.Authenticating);
|
|
9054
9095
|
try {
|
|
@@ -9059,6 +9100,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9059
9100
|
const lower = data.address.toLowerCase();
|
|
9060
9101
|
setUser({ userId: lower, address: lower, appId: clientId });
|
|
9061
9102
|
setAuthStatus(AuthStatus.Authenticated);
|
|
9103
|
+
setAddress(lower);
|
|
9062
9104
|
}
|
|
9063
9105
|
catch (e) {
|
|
9064
9106
|
setAuthError((e === null || e === void 0 ? void 0 : e.message) || 'Authentication failed');
|
|
@@ -9066,7 +9108,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9066
9108
|
throw e;
|
|
9067
9109
|
}
|
|
9068
9110
|
}, [apiBaseUrl, clientId]);
|
|
9069
|
-
const logout$1 =
|
|
9111
|
+
const logout$1 = useCallback(async () => {
|
|
9070
9112
|
const refresh = localStorage.getItem('refreshToken');
|
|
9071
9113
|
if (refresh) {
|
|
9072
9114
|
try {
|
|
@@ -9080,6 +9122,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
9080
9122
|
setUser(null);
|
|
9081
9123
|
setAuthStatus(AuthStatus.Idle);
|
|
9082
9124
|
setAuthError(null);
|
|
9125
|
+
setAddress(null);
|
|
9083
9126
|
}, [apiBaseUrl]);
|
|
9084
9127
|
// Agent wallet hook
|
|
9085
9128
|
const { agentWallet, isReady: isAgentWalletReady, loading: agentWalletLoading, error: agentWalletError, refreshAgentWalletStatus, createAgentWallet, notifyAgentWalletApproved, } = useAgentWallet({ baseUrl: apiBaseUrl });
|
|
@@ -9269,4 +9312,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
9269
9312
|
}
|
|
9270
9313
|
}
|
|
9271
9314
|
|
|
9272
|
-
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,
|
|
9315
|
+
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 };
|
package/package.json
CHANGED
package/dist/hooks/useAuth.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare function useAuth(): {
|
|
2
|
-
readonly status: import("..").AuthStatus;
|
|
3
|
-
readonly isAuthenticated: boolean;
|
|
4
|
-
readonly accessToken: string | null;
|
|
5
|
-
readonly user: import("..").UserProfile | null;
|
|
6
|
-
readonly error: string | null;
|
|
7
|
-
readonly getEip712: (address: string) => Promise<any>;
|
|
8
|
-
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
9
|
-
readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
10
|
-
readonly refreshTokens: () => Promise<any>;
|
|
11
|
-
readonly logout: () => Promise<void>;
|
|
12
|
-
};
|