@pear-protocol/hyperliquid-sdk 0.0.24 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +324 -127
- package/dist/clients/agentWallet.d.ts +3 -0
- package/dist/clients/auth.d.ts +14 -0
- package/dist/clients/hyperliquid.d.ts +9 -0
- package/dist/clients/orders.d.ts +24 -0
- package/dist/clients/positions.d.ts +89 -0
- package/dist/clients/sync.d.ts +9 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useAgentWallet.d.ts +10 -0
- package/dist/hooks/useAuth.d.ts +12 -0
- package/dist/hooks/useAutoSyncFills.d.ts +21 -0
- package/dist/hooks/useHistoricalPriceData.d.ts +0 -1
- package/dist/hooks/useOrders.d.ts +10 -0
- package/dist/hooks/usePosition.d.ts +10 -0
- package/dist/hooks/useTrading.d.ts +0 -11
- package/dist/index.d.ts +289 -336
- package/dist/index.js +6689 -6296
- package/dist/provider.d.ts +53 -19
- package/dist/store/userSelection.d.ts +2 -2
- package/dist/types.d.ts +132 -199
- package/dist/utils/http.d.ts +3 -0
- package/package.json +1 -1
- package/dist/client.d.ts +0 -52
- package/dist/migration-sdk.d.ts +0 -59
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ApiResponse } from '../types';
|
|
2
|
+
export type ExecutionType = 'MARKET' | 'LIMIT' | 'TWAP' | 'LADDER' | 'LIMIT_BTCDOM';
|
|
3
|
+
export type TpSlThresholdType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
4
|
+
export interface PairAssetInput {
|
|
5
|
+
asset: string;
|
|
6
|
+
weight?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface TpSlThresholdInput {
|
|
9
|
+
type: TpSlThresholdType;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CreatePositionRequestInput {
|
|
13
|
+
slippage: number;
|
|
14
|
+
executionType: ExecutionType;
|
|
15
|
+
leverage: number;
|
|
16
|
+
usdValue: number;
|
|
17
|
+
longAssets?: PairAssetInput[];
|
|
18
|
+
shortAssets?: PairAssetInput[];
|
|
19
|
+
triggerValue?: number;
|
|
20
|
+
direction?: 'MORE_THAN' | 'LESS_THAN';
|
|
21
|
+
twapDuration?: number;
|
|
22
|
+
randomizeExecution?: boolean;
|
|
23
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
24
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
25
|
+
}
|
|
26
|
+
export type PositionResponseStatus = 'SUCCESS' | 'FAILED' | 'PENDING' | 'PARTIALLY_FILLED' | 'OPEN';
|
|
27
|
+
export interface PositionAssetSummaryDto {
|
|
28
|
+
asset: string;
|
|
29
|
+
side: 'LONG' | 'SHORT';
|
|
30
|
+
size: number;
|
|
31
|
+
entryRatio: number;
|
|
32
|
+
usdValue: number;
|
|
33
|
+
orderId: string;
|
|
34
|
+
}
|
|
35
|
+
export interface CreatePositionResponseDto {
|
|
36
|
+
positionId: string | null;
|
|
37
|
+
orderId: string;
|
|
38
|
+
status: PositionResponseStatus;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
assets?: PositionAssetSummaryDto[];
|
|
41
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
42
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
43
|
+
hyperliquidResult?: any;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
47
|
+
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
48
|
+
*/
|
|
49
|
+
export declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
50
|
+
export interface UpdateRiskParametersRequestInput {
|
|
51
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
52
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
53
|
+
}
|
|
54
|
+
export interface UpdateRiskParametersResponseDto {
|
|
55
|
+
positionId: string;
|
|
56
|
+
stopLoss: TpSlThresholdInput | null;
|
|
57
|
+
takeProfit: TpSlThresholdInput | null;
|
|
58
|
+
updatedAt: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function updateRiskParameters(baseUrl: string, accessToken: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
61
|
+
export type CloseExecutionType = 'MARKET' | 'TWAP';
|
|
62
|
+
export interface ClosePositionRequestInput {
|
|
63
|
+
executionType: CloseExecutionType;
|
|
64
|
+
twapDuration?: number;
|
|
65
|
+
randomizeExecution?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface ClosePositionResponseDto {
|
|
68
|
+
orderId: string;
|
|
69
|
+
executionTime?: string;
|
|
70
|
+
chunksScheduled?: number;
|
|
71
|
+
}
|
|
72
|
+
export declare function closePosition(baseUrl: string, accessToken: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
73
|
+
export type AdjustExecutionType = 'MARKET' | 'LIMIT';
|
|
74
|
+
export type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
|
|
75
|
+
export interface AdjustPositionRequestInput {
|
|
76
|
+
adjustmentType: PositionAdjustmentType;
|
|
77
|
+
adjustmentSize: number;
|
|
78
|
+
executionType: AdjustExecutionType;
|
|
79
|
+
limitRatio?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface AdjustPositionResponseDto {
|
|
82
|
+
orderId: string;
|
|
83
|
+
status: string;
|
|
84
|
+
adjustmentType: PositionAdjustmentType;
|
|
85
|
+
adjustmentSize: number;
|
|
86
|
+
newSize: number;
|
|
87
|
+
executedAt: string;
|
|
88
|
+
}
|
|
89
|
+
export declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApiResponse, SyncFillsRequestDto, SyncFillsResponseDto } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Sync external fills into Pear Hyperliquid service (POST /sync/fills)
|
|
4
|
+
*/
|
|
5
|
+
export declare const syncFills: (baseUrl: string, accessToken: string, payload: SyncFillsRequestDto) => Promise<ApiResponse<SyncFillsResponseDto>>;
|
|
6
|
+
/**
|
|
7
|
+
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
8
|
+
*/
|
|
9
|
+
export declare const syncUserFillsFromHyperliquid: (baseUrl: string, accessToken: string, user: string, aggregateByTime?: boolean) => Promise<ApiResponse<SyncFillsResponseDto>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -6,3 +6,8 @@ export * from './useTokenSelectionMetadata';
|
|
|
6
6
|
export * from './useHistoricalPriceData';
|
|
7
7
|
export * from './useBasketCandles';
|
|
8
8
|
export * from './usePerformanceOverlays';
|
|
9
|
+
export * from './useAuth';
|
|
10
|
+
export * from './useAgentWallet';
|
|
11
|
+
export * from './useAutoSyncFills';
|
|
12
|
+
export * from './usePosition';
|
|
13
|
+
export * from './useOrders';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GetAgentWalletResponseDto, CreateAgentWalletResponseDto, UseAgentWalletOptions, AgentWalletState } from '../types';
|
|
2
|
+
export declare function useAgentWallet({ baseUrl }: UseAgentWalletOptions): {
|
|
3
|
+
readonly agentWallet: AgentWalletState;
|
|
4
|
+
readonly isReady: boolean;
|
|
5
|
+
readonly loading: false;
|
|
6
|
+
readonly error: null;
|
|
7
|
+
readonly refreshAgentWalletStatus: () => Promise<GetAgentWalletResponseDto>;
|
|
8
|
+
readonly createAgentWallet: () => Promise<CreateAgentWalletResponseDto>;
|
|
9
|
+
readonly notifyAgentWalletApproved: () => Promise<GetAgentWalletResponseDto>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SyncFillsResponseDto } from '../types';
|
|
2
|
+
export interface AutoSyncFillsOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
accessToken: string;
|
|
5
|
+
address: string | null;
|
|
6
|
+
intervalMs?: number;
|
|
7
|
+
aggregateByTime?: boolean;
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface AutoSyncFillsState {
|
|
11
|
+
lastRunAt: number | null;
|
|
12
|
+
lastResult: SyncFillsResponseDto | null;
|
|
13
|
+
error: string | null;
|
|
14
|
+
isSyncing: boolean;
|
|
15
|
+
triggerSync: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Listens to address changes and periodically syncs user fills
|
|
19
|
+
* Defaults: aggregate=true, interval=60s
|
|
20
|
+
*/
|
|
21
|
+
export declare function useAutoSyncFills(options: AutoSyncFillsOptions): AutoSyncFillsState;
|
|
@@ -5,7 +5,6 @@ export interface UseHistoricalPriceDataReturn {
|
|
|
5
5
|
hasHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => boolean;
|
|
6
6
|
getHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => Record<string, CandleData[]>;
|
|
7
7
|
getAllHistoricalPriceData(): Promise<Record<string, TokenHistoricalPriceData>>;
|
|
8
|
-
fetchFirstCandle: (symbol: string, interval: CandleInterval) => Promise<CandleData | null>;
|
|
9
8
|
isLoading: (symbol?: string) => boolean;
|
|
10
9
|
clearCache: () => void;
|
|
11
10
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ApiResponse } from '../types';
|
|
2
|
+
import type { OpenLimitOrderDto } from '../types';
|
|
3
|
+
import { type AdjustOrderRequestInput, type AdjustOrderResponseDto, type CancelOrderResponseDto, type CancelTwapResponseDto } from '../clients/orders';
|
|
4
|
+
export declare function useOrders(): {
|
|
5
|
+
readonly adjustOrder: (orderId: string, payload: AdjustOrderRequestInput) => Promise<ApiResponse<AdjustOrderResponseDto>>;
|
|
6
|
+
readonly cancelOrder: (orderId: string) => Promise<ApiResponse<CancelOrderResponseDto>>;
|
|
7
|
+
readonly cancelTwapOrder: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
8
|
+
readonly openOrders: OpenLimitOrderDto[] | null;
|
|
9
|
+
readonly isLoading: boolean;
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CreatePositionRequestInput, type CreatePositionResponseDto, type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto } from '../clients/positions';
|
|
2
|
+
import type { ApiResponse, OpenPositionDto } from '../types';
|
|
3
|
+
export declare function usePosition(): {
|
|
4
|
+
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
5
|
+
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
6
|
+
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
7
|
+
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
8
|
+
readonly openPositions: OpenPositionDto[] | null;
|
|
9
|
+
readonly isLoading: boolean;
|
|
10
|
+
};
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import type { AccountSummaryResponseDto, OpenLimitOrderDto } from '../types';
|
|
2
2
|
import type { TradeHistoryDataDto } from '../types';
|
|
3
|
-
import type { OpenPositionDto } from '../types';
|
|
4
3
|
export declare const useTradeHistories: () => {
|
|
5
4
|
data: TradeHistoryDataDto[] | null;
|
|
6
5
|
isLoading: boolean;
|
|
7
6
|
};
|
|
8
|
-
/**
|
|
9
|
-
* Hook to access open positions with real-time calculations and loading state
|
|
10
|
-
*/
|
|
11
|
-
export declare const useOpenPositions: () => {
|
|
12
|
-
data: null;
|
|
13
|
-
isLoading: boolean;
|
|
14
|
-
} | {
|
|
15
|
-
data: OpenPositionDto[];
|
|
16
|
-
isLoading: boolean;
|
|
17
|
-
};
|
|
18
7
|
/**
|
|
19
8
|
* Hook to access open orders with loading state
|
|
20
9
|
*/
|