@pear-protocol/hyperliquid-sdk 0.1.2 → 0.1.4-pnl

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.
@@ -1,4 +1,4 @@
1
- import type { ApiResponse, GetEIP712MessageResponse, AuthenticateRequest, AuthenticateResponse, RefreshTokenResponse, LogoutResponse } from '../types';
1
+ import type { ApiResponse, GetEIP712MessageResponse, AuthenticateRequest, AuthenticateResponse, RefreshTokenResponse, LogoutResponse } from "../types";
2
2
  export declare function getEIP712Message(baseUrl: string, address: string, clientId: string): Promise<ApiResponse<GetEIP712MessageResponse>>;
3
3
  export declare function authenticate(baseUrl: string, body: AuthenticateRequest): Promise<ApiResponse<AuthenticateResponse>>;
4
4
  /**
@@ -1,48 +1,5 @@
1
- import type { ApiResponse, ExternalFillDto } from "../types";
1
+ import type { ApiResponse, CreatePositionRequestInput, CreatePositionResponseDto, TpSlThresholdInput } from "../types";
2
2
  import type { CancelTwapResponseDto } from "./orders";
3
- export type ExecutionType = "MARKET" | "TRIGGER" | "TWAP" | "LADDER" | "TP" | "SL" | "SPOT_MARKET" | "SPOT_LIMIT" | "SPOT_TWAP";
4
- export type TriggerType = "PRICE" | "PRICE_RATIO" | "WEIGHTED_RATIO" | "BTC_DOM" | "CROSS_ASSET_PRICE" | "PREDICTION_MARKET_OUTCOME";
5
- export type TpSlThresholdType = "PERCENTAGE" | "DOLLAR" | "POSITION_VALUE" | "PRICE" | "PRICE_RATIO" | "WEIGHTED_RATIO";
6
- export interface PairAssetInput {
7
- asset: string;
8
- weight?: number;
9
- }
10
- export interface TpSlThresholdInput {
11
- type: TpSlThresholdType;
12
- value?: number;
13
- isTrailing?: boolean;
14
- trailingDeltaValue?: number;
15
- trailingActivationValue?: number;
16
- }
17
- export interface LadderConfigInput {
18
- ratioStart: number;
19
- ratioEnd: number;
20
- numberOfLevels: number;
21
- }
22
- export interface CreatePositionRequestInput {
23
- slippage: number;
24
- executionType: ExecutionType;
25
- leverage: number;
26
- usdValue: number;
27
- longAssets?: PairAssetInput[];
28
- shortAssets?: PairAssetInput[];
29
- triggerValue?: string | number;
30
- triggerType?: TriggerType;
31
- direction?: "MORE_THAN" | "LESS_THAN";
32
- assetName?: string;
33
- marketCode?: string;
34
- twapDuration?: number;
35
- twapIntervalSeconds?: number;
36
- randomizeExecution?: boolean;
37
- referralCode?: string;
38
- ladderConfig?: LadderConfigInput;
39
- takeProfit?: TpSlThresholdInput | null;
40
- stopLoss?: TpSlThresholdInput | null;
41
- }
42
- export interface CreatePositionResponseDto {
43
- orderId: string;
44
- fills?: ExternalFillDto[];
45
- }
46
3
  /**
47
4
  * Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
48
5
  * Authorization is derived from headers (Axios defaults or browser localStorage fallback)
@@ -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[]>>;
@@ -18,3 +18,5 @@ export * from './usePortfolio';
18
18
  export * from './useAuth';
19
19
  export * from './useAllUserBalances';
20
20
  export * from './useHyperliquidUserFills';
21
+ export * from './usePnlCalendar';
22
+ export * from './usePnlHeatmap';
@@ -1,5 +1,5 @@
1
1
  export declare function useAgentWallet(): {
2
2
  readonly refreshAgentWalletStatus: () => Promise<void>;
3
- readonly createAgentWallet: () => Promise<import("../types").CreateAgentWalletResponseDto>;
3
+ readonly createAgentWallet: () => Promise<import("..").CreateAgentWalletResponseDto>;
4
4
  readonly notifyAgentWalletApproved: () => Promise<void>;
5
5
  };
@@ -1,9 +1,24 @@
1
- interface AllUserBalances {
2
- spotUsdcBalance: number | undefined;
3
- availableToTradeUsdc: number | undefined;
4
- spotUsdhBalance: number | undefined;
5
- availableToTradeUsdh: number | undefined;
1
+ import { AvailableToTrades, SpotBalances, CollateralToken, UserAbstraction } from '../types';
2
+ export interface MarginRequiredPerCollateral {
3
+ collateral: CollateralToken;
4
+ marginRequired: number;
5
+ availableBalance: number;
6
+ hasEnough: boolean;
7
+ shortfall: number;
8
+ }
9
+ export interface MarginRequiredResult {
10
+ totalMarginRequired: number;
11
+ orderValue: number;
12
+ perCollateral: MarginRequiredPerCollateral[];
13
+ hasEnoughTotal: boolean;
14
+ }
15
+ interface AllUserBalancesResult {
16
+ spotBalances: SpotBalances;
17
+ availableToTrades: AvailableToTrades;
6
18
  isLoading: boolean;
19
+ abstractionMode: UserAbstraction | null;
20
+ getMarginRequired: (assetsLeverage: Record<string, number>, size: number) => MarginRequiredResult;
21
+ getMaxSize: (assetsLeverage: Record<string, number>) => number;
7
22
  }
8
- export declare const useAllUserBalances: () => AllUserBalances;
23
+ export declare const useAllUserBalances: () => AllUserBalancesResult;
9
24
  export {};
@@ -1,7 +1,8 @@
1
- import type { GetEIP712MessageResponse } from "../types";
1
+ import type { GetEIP712MessageResponse } from '../types';
2
2
  export declare function useAuth(): {
3
3
  readonly isReady: boolean;
4
4
  readonly isAuthenticated: boolean;
5
+ readonly address: string | null;
5
6
  readonly accessToken: string | null;
6
7
  readonly refreshToken: string | null;
7
8
  readonly getEip712: (address: string) => Promise<GetEIP712MessageResponse>;
@@ -9,4 +10,6 @@ export declare function useAuth(): {
9
10
  readonly loginWithPrivyToken: (address: string, appId: string, privyAccessToken: string) => Promise<void>;
10
11
  readonly refreshTokens: () => Promise<import("../types").RefreshTokenResponse>;
11
12
  readonly logout: () => Promise<void>;
13
+ readonly clearSession: () => void;
14
+ readonly setAddress: (address: string | null) => void;
12
15
  };
@@ -3,6 +3,7 @@ export interface UseBasketCandlesReturn {
3
3
  fetchBasketCandles: (startTime: number, endTime: number, interval: CandleInterval) => Promise<CandleData[]>;
4
4
  fetchPerformanceCandles: (startTime: number, endTime: number, interval: CandleInterval, symbol: string) => Promise<CandleData[]>;
5
5
  fetchOverallPerformanceCandles: (startTime: number, endTime: number, interval: CandleInterval) => Promise<CandleData[]>;
6
+ getEffectiveDataBoundary: (interval: CandleInterval) => number | null;
6
7
  isLoading: boolean;
7
8
  addRealtimeListener: (cb: RealtimeBarsCallback) => string;
8
9
  removeRealtimeListener: (id: string) => void;
@@ -4,6 +4,7 @@ export interface UseHistoricalPriceDataReturn {
4
4
  fetchHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval, callback?: (data: Record<string, CandleData[]>) => void) => Promise<Record<string, CandleData[]>>;
5
5
  hasHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => boolean;
6
6
  getHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => Record<string, CandleData[]>;
7
+ getEffectiveDataBoundary: (interval: CandleInterval) => number | null;
7
8
  getAllHistoricalPriceData(): Promise<Record<string, TokenHistoricalPriceData>>;
8
9
  isLoading: (symbol?: string) => boolean;
9
10
  clearCache: () => void;
@@ -1,9 +1,15 @@
1
1
  import type { ActiveAssetGroupItem, ActiveAssetsResponse } from '../types';
2
- export type CollateralFilter = 'USDC' | 'USDH' | 'ALL';
3
- export declare const useMarketDataPayload: () => ActiveAssetsResponse | null;
4
- export declare const useActiveBaskets: (collateralFilter?: CollateralFilter) => ActiveAssetGroupItem[];
5
- export declare const useTopGainers: (limit?: number, collateralFilter?: CollateralFilter) => ActiveAssetGroupItem[];
6
- export declare const useTopLosers: (limit?: number, collateralFilter?: CollateralFilter) => ActiveAssetGroupItem[];
7
- export declare const useHighlightedBaskets: (collateralFilter?: CollateralFilter) => ActiveAssetGroupItem[];
8
- export declare const useWatchlistBaskets: (collateralFilter?: CollateralFilter) => ActiveAssetGroupItem[];
9
- export declare const useFindBasket: (longs: string[], shorts: string[]) => ActiveAssetGroupItem | undefined;
2
+ interface UseMarketDataHookOptions {
3
+ topGainersLimit?: number;
4
+ topLosersLimit?: number;
5
+ }
6
+ interface UseMarketDataHookResult {
7
+ marketData: ActiveAssetsResponse | null;
8
+ activeBaskets: ActiveAssetGroupItem[];
9
+ topGainers: ActiveAssetGroupItem[];
10
+ topLosers: ActiveAssetGroupItem[];
11
+ highlightedBaskets: ActiveAssetGroupItem[];
12
+ watchlistBaskets: ActiveAssetGroupItem[];
13
+ }
14
+ export declare const useMarketDataHook: (options?: UseMarketDataHookOptions) => UseMarketDataHookResult;
15
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { TokenMetadata } from '../types';
2
+ export type PnlCalendarTimeframe = '2W' | '3W' | '2M' | '3M';
3
+ export interface PnlCalendarOptions {
4
+ timeframe?: PnlCalendarTimeframe;
5
+ startDate?: Date | string;
6
+ endDate?: Date | string;
7
+ }
8
+ export interface PnlCalendarAsset {
9
+ coin: string;
10
+ metadata: TokenMetadata | null;
11
+ }
12
+ export interface PnlCalendarTrade {
13
+ tradeHistoryId: string;
14
+ realizedPnl: number;
15
+ result: 'profit' | 'loss' | 'breakeven';
16
+ closedLongAssets: PnlCalendarAsset[];
17
+ closedShortAssets: PnlCalendarAsset[];
18
+ }
19
+ export interface PnlCalendarDay {
20
+ date: string;
21
+ totalPnl: number;
22
+ volume: number;
23
+ positionsClosed: number;
24
+ result: 'profit' | 'loss' | 'breakeven';
25
+ trades: PnlCalendarTrade[];
26
+ }
27
+ export interface PeriodSummary {
28
+ pnl: number;
29
+ volume: number;
30
+ winRate: number;
31
+ wins: number;
32
+ losses: number;
33
+ totalProfit: number;
34
+ totalLoss: number;
35
+ }
36
+ export interface PnlCalendarWeek {
37
+ weekStart: string;
38
+ weekEnd: string;
39
+ days: PnlCalendarDay[];
40
+ summary: PeriodSummary;
41
+ }
42
+ export interface PnlCalendarMonth {
43
+ month: string;
44
+ label: string;
45
+ days: PnlCalendarDay[];
46
+ summary: PeriodSummary;
47
+ }
48
+ export interface UsePnlCalendarResult {
49
+ timeframe: PnlCalendarTimeframe;
50
+ weeks: PnlCalendarWeek[];
51
+ months: PnlCalendarMonth[];
52
+ overall: PeriodSummary;
53
+ isLoading: boolean;
54
+ error: string | null;
55
+ refetch: () => void;
56
+ }
57
+ 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;
@@ -1,5 +1,24 @@
1
- import { type CreatePositionRequestInput, type CreatePositionResponseDto, type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type CloseAllPositionsResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto, type AdjustAdvanceItemInput, type AdjustAdvanceResponseDto, type UpdateLeverageResponseDto } from '../clients/positions';
2
- import type { ApiResponse, OpenPositionDto } from '../types';
1
+ import { type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type CloseAllPositionsResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto, type AdjustAdvanceItemInput, type AdjustAdvanceResponseDto, type UpdateLeverageResponseDto } from '../clients/positions';
2
+ import type { ApiResponse, CreatePositionRequestInput, CreatePositionResponseDto, OpenPositionDto } from '../types';
3
+ export interface RebalanceAssetPlan {
4
+ coin: string;
5
+ side: 'long' | 'short';
6
+ currentWeight: number;
7
+ targetWeight: number;
8
+ currentValue: number;
9
+ targetValue: number;
10
+ deltaValue: number;
11
+ currentSize: number;
12
+ newSize: number;
13
+ deltaSize: number;
14
+ skipped: boolean;
15
+ skipReason?: string;
16
+ }
17
+ export interface RebalancePlan {
18
+ positionId: string;
19
+ assets: RebalanceAssetPlan[];
20
+ canExecute: boolean;
21
+ }
3
22
  export declare function usePosition(): {
4
23
  readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
5
24
  readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
@@ -10,4 +29,6 @@ export declare function usePosition(): {
10
29
  readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
11
30
  readonly openPositions: OpenPositionDto[] | null;
12
31
  readonly isLoading: boolean;
32
+ readonly planRebalance: (positionId: string, targetWeights?: Record<string, number>) => RebalancePlan;
33
+ readonly executeRebalance: (positionId: string, targetWeights?: Record<string, number>) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
13
34
  };
@@ -12,7 +12,7 @@ export interface UseTokenSelectionMetadataReturn {
12
12
  volume: string;
13
13
  sumNetFunding: number;
14
14
  maxLeverage: number;
15
- minMargin: number;
16
15
  leverageMatched: boolean;
16
+ minSize: Record<string, number>;
17
17
  }
18
18
  export declare const useTokenSelectionMetadata: () => UseTokenSelectionMetadataReturn;
@@ -1,3 +1,18 @@
1
1
  import type { UserSelectionState } from "../store/userSelection";
2
- export declare const useUserSelection: () => UserSelectionState;
2
+ export declare const useUserSelection: () => {
3
+ longTokens: import("..").TokenSelection[];
4
+ shortTokens: import("..").TokenSelection[];
5
+ candleInterval: import("..").CandleInterval;
6
+ openTokenSelector: boolean;
7
+ selectorConfig: import("..").TokenSelectorConfig | null;
8
+ openConflictModal: boolean;
9
+ setLongTokens: (tokens: import("..").TokenSelection[]) => void;
10
+ setShortTokens: (tokens: import("..").TokenSelection[]) => void;
11
+ setCandleInterval: (interval: import("..").CandleInterval) => void;
12
+ setTokenSelections: (longTokens: import("..").TokenSelection[], shortTokens: import("..").TokenSelection[]) => void;
13
+ setOpenTokenSelector: (open: boolean) => void;
14
+ setSelectorConfig: (config: import("..").TokenSelectorConfig | null) => void;
15
+ setOpenConflictModal: (open: boolean) => void;
16
+ addToken: (isLong: boolean) => boolean;
17
+ };
3
18
  export type { UserSelectionState };