@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
package/dist/index.d.ts
CHANGED
|
@@ -2,74 +2,11 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import * as react_use_websocket from 'react-use-websocket';
|
|
3
3
|
import { ReadyState } from 'react-use-websocket';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Raw value data for trade history positions
|
|
7
|
-
*/
|
|
8
|
-
interface RawValueDto {
|
|
9
|
-
coin: string;
|
|
10
|
-
size: string;
|
|
11
|
-
leverage: number;
|
|
12
|
-
openPx: string;
|
|
13
|
-
closePx: string;
|
|
14
|
-
marginUsed: string;
|
|
15
|
-
positionValue: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Trade history data structure from V1 API
|
|
19
|
-
*/
|
|
20
|
-
interface TradeHistoryV1Dto {
|
|
21
|
-
pearId: string;
|
|
22
|
-
openedDate: string;
|
|
23
|
-
closedDate: string;
|
|
24
|
-
time: string;
|
|
25
|
-
pair: string;
|
|
26
|
-
direction: Record<string, string>;
|
|
27
|
-
closedPrice: number;
|
|
28
|
-
openedPrice: number;
|
|
29
|
-
size: string;
|
|
30
|
-
longPositionValue: number;
|
|
31
|
-
shortPositionValue: number;
|
|
32
|
-
positionValue: number;
|
|
33
|
-
fee: number;
|
|
34
|
-
builderFee: number;
|
|
35
|
-
closedPNL: number;
|
|
36
|
-
closedPnlPercentage: number;
|
|
37
|
-
leverage: number;
|
|
38
|
-
rawLongValue: RawValueDto;
|
|
39
|
-
rawShortValue: RawValueDto;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Request payload for syncing trade history
|
|
43
|
-
*/
|
|
44
|
-
interface SyncTradeHistoryDto {
|
|
45
|
-
address: string;
|
|
46
|
-
data: TradeHistoryV1Dto[];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Response from sync trade history endpoint
|
|
50
|
-
*/
|
|
51
|
-
interface SyncTradeHistoryResponseDto {
|
|
52
|
-
success: boolean;
|
|
53
|
-
positionId: string;
|
|
54
|
-
tradeHistoryId: string;
|
|
55
|
-
message: string;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Base API error response
|
|
59
|
-
*/
|
|
60
5
|
interface ApiErrorResponse {
|
|
61
6
|
statusCode: number;
|
|
62
7
|
message: string;
|
|
63
8
|
error?: string;
|
|
64
9
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Configuration options for the SDK
|
|
67
|
-
*/
|
|
68
|
-
interface PearHyperliquidConfig {
|
|
69
|
-
baseUrl: string;
|
|
70
|
-
timeout?: number;
|
|
71
|
-
headers?: Record<string, string>;
|
|
72
|
-
}
|
|
73
10
|
/**
|
|
74
11
|
* HTTP client response wrapper
|
|
75
12
|
*/
|
|
@@ -78,136 +15,13 @@ interface ApiResponse<T> {
|
|
|
78
15
|
status: number;
|
|
79
16
|
headers: Record<string, string>;
|
|
80
17
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* PnL data structure for open positions
|
|
91
|
-
*/
|
|
92
|
-
interface PnlDto {
|
|
93
|
-
value: number;
|
|
94
|
-
percentage: number;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Take profit and stop loss data structure
|
|
98
|
-
*/
|
|
99
|
-
interface TpSlDto {
|
|
100
|
-
takeProfit?: number;
|
|
101
|
-
stopLoss?: number;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Position side data structure for open positions
|
|
105
|
-
*/
|
|
106
|
-
interface PositionSideDto {
|
|
107
|
-
coin: string;
|
|
108
|
-
size: string;
|
|
109
|
-
leverage: number;
|
|
110
|
-
entryPx: string;
|
|
111
|
-
marginUsed: string;
|
|
112
|
-
liquidationPx: string | undefined;
|
|
113
|
-
unrealizedPnl: string;
|
|
114
|
-
roe: string;
|
|
115
|
-
positionValue: string;
|
|
116
|
-
funding: string;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Open position data structure from V1 API
|
|
120
|
-
*/
|
|
121
|
-
interface OpenPositionV1Dto {
|
|
122
|
-
pair: string;
|
|
123
|
-
leverage: number;
|
|
124
|
-
size: number;
|
|
125
|
-
longPositionValue?: number;
|
|
126
|
-
shortPositionValue?: number;
|
|
127
|
-
positionValue: number;
|
|
128
|
-
entryPrice: number;
|
|
129
|
-
markPrice: number;
|
|
130
|
-
pnl: PnlDto;
|
|
131
|
-
liqPrice: string | number;
|
|
132
|
-
margin: number;
|
|
133
|
-
funding: number;
|
|
134
|
-
pearId: string;
|
|
135
|
-
openedDate: string;
|
|
136
|
-
tpsl: TpSlDto;
|
|
137
|
-
long: PositionSideDto;
|
|
138
|
-
short: PositionSideDto;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Request payload for syncing open positions
|
|
142
|
-
*/
|
|
143
|
-
interface SyncOpenPositionDto {
|
|
144
|
-
address: string;
|
|
145
|
-
data: OpenPositionV1Dto[];
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Response from sync open positions endpoint
|
|
149
|
-
*/
|
|
150
|
-
interface SyncOpenPositionResponseDto {
|
|
151
|
-
success: boolean;
|
|
152
|
-
positionIds: string[];
|
|
153
|
-
count: number;
|
|
154
|
-
message: string;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Open order data structure from V1 API
|
|
158
|
-
*/
|
|
159
|
-
interface OpenOrderV1Dto {
|
|
160
|
-
id: string;
|
|
161
|
-
time: string;
|
|
162
|
-
pair: string;
|
|
163
|
-
type: string;
|
|
164
|
-
orderValue: number;
|
|
165
|
-
price: number;
|
|
166
|
-
triggerConditions: string;
|
|
167
|
-
status: string;
|
|
168
|
-
leverage?: string;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Request payload for syncing open orders
|
|
172
|
-
*/
|
|
173
|
-
interface SyncOpenOrderDto {
|
|
174
|
-
address: string;
|
|
175
|
-
data: OpenOrderV1Dto[];
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Response from sync open orders endpoint
|
|
179
|
-
*/
|
|
180
|
-
interface SyncOpenOrderResponseDto {
|
|
181
|
-
success: boolean;
|
|
182
|
-
orderIds: string[];
|
|
183
|
-
count: number;
|
|
184
|
-
message: string;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Migration hooks interface
|
|
188
|
-
*/
|
|
189
|
-
interface MigrationHooks {
|
|
190
|
-
tradeHistory: {
|
|
191
|
-
sync: (payload: SyncTradeHistoryDto) => Promise<ApiResponse<SyncTradeHistoryResponseDto>>;
|
|
192
|
-
loading: boolean;
|
|
193
|
-
error: ApiErrorResponse | null;
|
|
194
|
-
data: SyncTradeHistoryResponseDto | null;
|
|
195
|
-
reset: () => void;
|
|
196
|
-
};
|
|
197
|
-
openPositions: {
|
|
198
|
-
sync: (payload: SyncOpenPositionDto) => Promise<ApiResponse<SyncOpenPositionResponseDto>>;
|
|
199
|
-
loading: boolean;
|
|
200
|
-
error: ApiErrorResponse | null;
|
|
201
|
-
data: SyncOpenPositionResponseDto | null;
|
|
202
|
-
reset: () => void;
|
|
203
|
-
};
|
|
204
|
-
openOrders: {
|
|
205
|
-
sync: (payload: SyncOpenOrderDto) => Promise<ApiResponse<SyncOpenOrderResponseDto>>;
|
|
206
|
-
loading: boolean;
|
|
207
|
-
error: ApiErrorResponse | null;
|
|
208
|
-
data: SyncOpenOrderResponseDto | null;
|
|
209
|
-
reset: () => void;
|
|
210
|
-
};
|
|
18
|
+
interface SyncFillsResponseDto {
|
|
19
|
+
insertedFills: number;
|
|
20
|
+
skippedDuplicates: number;
|
|
21
|
+
createdOrders: number;
|
|
22
|
+
updatedPositions: number;
|
|
23
|
+
createdPositions: number;
|
|
24
|
+
closedPositions: number;
|
|
211
25
|
}
|
|
212
26
|
/**
|
|
213
27
|
* WebSocket connection states
|
|
@@ -244,6 +58,7 @@ interface WebSocketDataMessage<T = unknown> {
|
|
|
244
58
|
*/
|
|
245
59
|
interface TradeHistoryAssetDataDto {
|
|
246
60
|
coin: string;
|
|
61
|
+
entryWeight: number;
|
|
247
62
|
entryPrice: number;
|
|
248
63
|
limitPrice: number;
|
|
249
64
|
size: number;
|
|
@@ -261,6 +76,7 @@ interface TradeHistoryDataDto {
|
|
|
261
76
|
externalFeePaid: number;
|
|
262
77
|
builderFeePaid: number;
|
|
263
78
|
realizedPnl: number;
|
|
79
|
+
totalEntryValue: number;
|
|
264
80
|
totalValue: number;
|
|
265
81
|
entryRatio: number;
|
|
266
82
|
exitRatio: number;
|
|
@@ -287,16 +103,16 @@ interface PositionAssetDetailDto {
|
|
|
287
103
|
actualSize: number;
|
|
288
104
|
cumFunding: CumFundingDto;
|
|
289
105
|
marginUsed: number;
|
|
106
|
+
entryPositionValue: number;
|
|
290
107
|
positionValue: number;
|
|
291
108
|
unrealizedPnl: number;
|
|
292
109
|
liquidationPrice: number;
|
|
293
|
-
isExternallyModified: boolean;
|
|
294
110
|
initialWeight: number;
|
|
295
111
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
112
|
+
interface TpSlThreshold {
|
|
113
|
+
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
114
|
+
value: number;
|
|
115
|
+
}
|
|
300
116
|
/**
|
|
301
117
|
* Open position data structure
|
|
302
118
|
*/
|
|
@@ -304,18 +120,17 @@ interface OpenPositionDto {
|
|
|
304
120
|
positionId: string;
|
|
305
121
|
address: string;
|
|
306
122
|
leverage: number;
|
|
307
|
-
stopLoss:
|
|
308
|
-
takeProfit:
|
|
123
|
+
stopLoss: TpSlThreshold | null;
|
|
124
|
+
takeProfit: TpSlThreshold | null;
|
|
309
125
|
entryRatio: number;
|
|
310
126
|
markRatio: number;
|
|
311
127
|
netFunding: number;
|
|
128
|
+
entryPositionValue: number;
|
|
312
129
|
positionValue: number;
|
|
313
130
|
marginUsed: number;
|
|
314
131
|
unrealizedPnl: number;
|
|
315
132
|
longAssets: PositionAssetDetailDto[];
|
|
316
133
|
shortAssets: PositionAssetDetailDto[];
|
|
317
|
-
syncStatus: PositionSyncStatus;
|
|
318
|
-
lastSyncAt: string;
|
|
319
134
|
createdAt: string;
|
|
320
135
|
updatedAt: string;
|
|
321
136
|
}
|
|
@@ -402,6 +217,40 @@ interface AccountSummaryResponseDto {
|
|
|
402
217
|
balanceSummary: BalanceSummaryDto;
|
|
403
218
|
agentWallet: AgentWalletDto;
|
|
404
219
|
}
|
|
220
|
+
declare enum AuthStatus {
|
|
221
|
+
Idle = "idle",
|
|
222
|
+
Authenticating = "authenticating",
|
|
223
|
+
Authenticated = "authenticated",
|
|
224
|
+
Error = "error"
|
|
225
|
+
}
|
|
226
|
+
interface UseAuthOptions {
|
|
227
|
+
baseUrl: string;
|
|
228
|
+
clientId: string;
|
|
229
|
+
}
|
|
230
|
+
interface UserProfile {
|
|
231
|
+
userId: string;
|
|
232
|
+
address: string;
|
|
233
|
+
appId: string;
|
|
234
|
+
}
|
|
235
|
+
type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
|
|
236
|
+
interface GetAgentWalletResponseDto {
|
|
237
|
+
agentWalletAddress?: string;
|
|
238
|
+
agentName: string;
|
|
239
|
+
status: AgentWalletStatus;
|
|
240
|
+
}
|
|
241
|
+
interface CreateAgentWalletResponseDto {
|
|
242
|
+
agentWalletAddress: string;
|
|
243
|
+
message: string;
|
|
244
|
+
}
|
|
245
|
+
interface UseAgentWalletOptions {
|
|
246
|
+
baseUrl: string;
|
|
247
|
+
}
|
|
248
|
+
interface AgentWalletState {
|
|
249
|
+
address: string | null;
|
|
250
|
+
name: string | null;
|
|
251
|
+
status: AgentWalletStatus | 'PENDING' | null;
|
|
252
|
+
isActive: boolean;
|
|
253
|
+
}
|
|
405
254
|
/**
|
|
406
255
|
* WebSocket message from HyperLiquid native API
|
|
407
256
|
*/
|
|
@@ -641,142 +490,82 @@ interface CandleSnapshotRequest {
|
|
|
641
490
|
};
|
|
642
491
|
type: "candleSnapshot";
|
|
643
492
|
}
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* Main SDK client for Pear Protocol Hyperliquid API integration
|
|
647
|
-
*/
|
|
648
|
-
declare class PearHyperliquidClient {
|
|
649
|
-
private httpClient;
|
|
650
|
-
private baseUrl;
|
|
651
|
-
constructor(config: PearHyperliquidConfig);
|
|
652
|
-
/**
|
|
653
|
-
* Get the configured base URL
|
|
654
|
-
*/
|
|
655
|
-
getBaseUrl(): string;
|
|
656
|
-
/**
|
|
657
|
-
* Update request headers
|
|
658
|
-
*/
|
|
659
|
-
setHeaders(headers: Record<string, string>): void;
|
|
660
|
-
/**
|
|
661
|
-
* Set authorization header
|
|
662
|
-
*/
|
|
663
|
-
setAuthToken(token: string): void;
|
|
664
|
-
/**
|
|
665
|
-
* Make a generic HTTP request
|
|
666
|
-
*/
|
|
667
|
-
private makeRequest;
|
|
668
|
-
/**
|
|
669
|
-
* Sync trade history data from old database structure to new database format
|
|
670
|
-
* @param payload - Trade history data with user address
|
|
671
|
-
* @returns Promise with sync result
|
|
672
|
-
*/
|
|
673
|
-
syncTradeHistory(payload: SyncTradeHistoryDto): Promise<ApiResponse<SyncTradeHistoryResponseDto>>;
|
|
674
|
-
/**
|
|
675
|
-
* Sync open positions data from old database structure to new database format
|
|
676
|
-
* @param payload - Open positions data with user address
|
|
677
|
-
* @returns Promise with sync result
|
|
678
|
-
*/
|
|
679
|
-
syncOpenPositions(payload: SyncOpenPositionDto): Promise<ApiResponse<SyncOpenPositionResponseDto>>;
|
|
680
|
-
/**
|
|
681
|
-
* Sync open orders data from old database structure to new database format
|
|
682
|
-
* @param payload - Open orders data with user address
|
|
683
|
-
* @returns Promise with sync result
|
|
684
|
-
*/
|
|
685
|
-
syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto>>;
|
|
686
|
-
/**
|
|
687
|
-
* Fetch historical candle data from HyperLiquid API
|
|
688
|
-
* @param coin - Token symbol (e.g., 'BTC', 'ETH')
|
|
689
|
-
* @param startTime - Start time in milliseconds
|
|
690
|
-
* @param endTime - End time in milliseconds
|
|
691
|
-
* @param interval - Candle interval
|
|
692
|
-
* @returns Promise with historical candle data
|
|
693
|
-
*/
|
|
694
|
-
fetchHistoricalCandles(coin: string, startTime: number, endTime: number, interval: CandleInterval): Promise<ApiResponse<CandleData[]>>;
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* Main Migration SDK Class - Simple request/response pattern
|
|
699
|
-
*/
|
|
700
|
-
declare class PearMigrationSDK {
|
|
701
|
-
private client;
|
|
702
|
-
private isTradeHistorySyncRunning;
|
|
703
|
-
private isOpenPositionsSyncRunning;
|
|
704
|
-
private isOpenOrdersSyncRunning;
|
|
705
|
-
constructor(client: PearHyperliquidClient);
|
|
706
|
-
/**
|
|
707
|
-
* Sync trade history data - can only run one at a time
|
|
708
|
-
* If called while already running, returns immediately without making request
|
|
709
|
-
*/
|
|
710
|
-
syncTradeHistory(payload: SyncTradeHistoryDto): Promise<ApiResponse<SyncTradeHistoryResponseDto> | null>;
|
|
711
|
-
/**
|
|
712
|
-
* Sync open positions data - can only run one at a time
|
|
713
|
-
* If called while already running, returns immediately without making request
|
|
714
|
-
*/
|
|
715
|
-
syncOpenPositions(payload: SyncOpenPositionDto): Promise<ApiResponse<SyncOpenPositionResponseDto> | null>;
|
|
716
|
-
/**
|
|
717
|
-
* Sync open orders data - can only run one at a time
|
|
718
|
-
* If called while already running, returns immediately without making request
|
|
719
|
-
*/
|
|
720
|
-
syncOpenOrders(payload: SyncOpenOrderDto): Promise<ApiResponse<SyncOpenOrderResponseDto> | null>;
|
|
721
|
-
/**
|
|
722
|
-
* Check if any sync is currently running
|
|
723
|
-
*/
|
|
724
|
-
isSyncInProgress(): boolean;
|
|
725
|
-
/**
|
|
726
|
-
* Check if trade history sync is currently running
|
|
727
|
-
*/
|
|
728
|
-
isTradeHistorySyncInProgress(): boolean;
|
|
729
|
-
/**
|
|
730
|
-
* Check if open positions sync is currently running
|
|
731
|
-
*/
|
|
732
|
-
isOpenPositionsSyncInProgress(): boolean;
|
|
733
|
-
/**
|
|
734
|
-
* Check if open orders sync is currently running
|
|
735
|
-
*/
|
|
736
|
-
isOpenOrdersSyncInProgress(): boolean;
|
|
737
|
-
/**
|
|
738
|
-
* Get the underlying client instance
|
|
739
|
-
*/
|
|
740
|
-
getClient(): PearHyperliquidClient;
|
|
741
|
-
/**
|
|
742
|
-
* Set authorization token on the client
|
|
743
|
-
*/
|
|
744
|
-
setAuthToken(token: string): void;
|
|
745
|
-
/**
|
|
746
|
-
* Set custom headers on the client
|
|
747
|
-
*/
|
|
748
|
-
setHeaders(headers: Record<string, string>): void;
|
|
749
|
-
/**
|
|
750
|
-
* Get base URL from client
|
|
751
|
-
*/
|
|
752
|
-
getBaseUrl(): string;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
493
|
interface TokenSelectorConfig {
|
|
756
494
|
isLong: boolean;
|
|
757
495
|
index: number;
|
|
758
496
|
}
|
|
497
|
+
|
|
498
|
+
interface PearHyperliquidContextType {
|
|
499
|
+
apiBaseUrl: string;
|
|
500
|
+
wsUrl: string;
|
|
501
|
+
address: string | null;
|
|
502
|
+
setAddress: (address: string | null) => void;
|
|
503
|
+
connectionStatus: ReadyState;
|
|
504
|
+
isConnected: boolean;
|
|
505
|
+
lastError: string | null;
|
|
506
|
+
nativeConnectionStatus: ReadyState;
|
|
507
|
+
nativeIsConnected: boolean;
|
|
508
|
+
nativeLastError: string | null;
|
|
509
|
+
authStatus: AuthStatus;
|
|
510
|
+
isAuthenticated: boolean;
|
|
511
|
+
accessToken: string | null;
|
|
512
|
+
user: UserProfile | null;
|
|
513
|
+
authError: string | null;
|
|
514
|
+
getEip712: (address: string) => Promise<any>;
|
|
515
|
+
loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
516
|
+
loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
517
|
+
refreshTokens: () => Promise<any>;
|
|
518
|
+
logout: () => Promise<void>;
|
|
519
|
+
agentWallet: AgentWalletState;
|
|
520
|
+
isAgentWalletReady: boolean;
|
|
521
|
+
agentWalletError: string | null;
|
|
522
|
+
agentWalletLoading: boolean;
|
|
523
|
+
refreshAgentWalletStatus: () => Promise<any>;
|
|
524
|
+
createAgentWallet: () => Promise<any>;
|
|
525
|
+
notifyAgentWalletApproved: () => Promise<any>;
|
|
526
|
+
}
|
|
759
527
|
interface PearHyperliquidProviderProps {
|
|
760
|
-
config: PearHyperliquidConfig;
|
|
761
|
-
/**
|
|
762
|
-
* WebSocket server URL
|
|
763
|
-
* @default 'wss://hl-v2.pearprotocol.io/ws'
|
|
764
|
-
*/
|
|
765
|
-
wsUrl?: string;
|
|
766
528
|
children: ReactNode;
|
|
529
|
+
apiBaseUrl?: string;
|
|
530
|
+
clientId?: string;
|
|
531
|
+
wsUrl?: string;
|
|
767
532
|
}
|
|
768
533
|
/**
|
|
769
534
|
* React Provider for PearHyperliquidClient
|
|
770
535
|
*/
|
|
771
536
|
declare const PearHyperliquidProvider: React.FC<PearHyperliquidProviderProps>;
|
|
772
537
|
/**
|
|
773
|
-
* Hook to
|
|
538
|
+
* Hook to access the entire Pear Hyperliquid context.
|
|
539
|
+
* Prefer using the more specific hooks below when possible.
|
|
774
540
|
*/
|
|
775
|
-
declare
|
|
541
|
+
declare function usePearHyperliquid(): PearHyperliquidContextType;
|
|
776
542
|
/**
|
|
777
|
-
*
|
|
543
|
+
* Provider-aware Auth hook. Uses auth state/actions provided by PearHyperliquidProvider.
|
|
544
|
+
* Callers do not need to pass baseUrl/clientId.
|
|
778
545
|
*/
|
|
779
|
-
declare
|
|
546
|
+
declare function usePearAuth(): {
|
|
547
|
+
readonly status: AuthStatus;
|
|
548
|
+
readonly isAuthenticated: boolean;
|
|
549
|
+
readonly user: UserProfile | null;
|
|
550
|
+
readonly error: string | null;
|
|
551
|
+
readonly getEip712: (address: string) => Promise<any>;
|
|
552
|
+
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
553
|
+
readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
554
|
+
readonly refreshTokens: () => Promise<any>;
|
|
555
|
+
readonly logout: () => Promise<void>;
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Provider-aware Agent Wallet hook. Uses agent wallet state/actions provided by PearHyperliquidProvider.
|
|
559
|
+
*/
|
|
560
|
+
declare function usePearAgentWallet(): {
|
|
561
|
+
readonly agentWallet: AgentWalletState;
|
|
562
|
+
readonly isReady: boolean;
|
|
563
|
+
readonly loading: boolean;
|
|
564
|
+
readonly error: string | null;
|
|
565
|
+
readonly refreshAgentWalletStatus: () => Promise<any>;
|
|
566
|
+
readonly createAgentWallet: () => Promise<any>;
|
|
567
|
+
readonly notifyAgentWalletApproved: () => Promise<any>;
|
|
568
|
+
};
|
|
780
569
|
|
|
781
570
|
/**
|
|
782
571
|
* Hook to manage address (login/logout functionality)
|
|
@@ -792,16 +581,6 @@ declare const useTradeHistories: () => {
|
|
|
792
581
|
data: TradeHistoryDataDto[] | null;
|
|
793
582
|
isLoading: boolean;
|
|
794
583
|
};
|
|
795
|
-
/**
|
|
796
|
-
* Hook to access open positions with real-time calculations and loading state
|
|
797
|
-
*/
|
|
798
|
-
declare const useOpenPositions: () => {
|
|
799
|
-
data: null;
|
|
800
|
-
isLoading: boolean;
|
|
801
|
-
} | {
|
|
802
|
-
data: OpenPositionDto[];
|
|
803
|
-
isLoading: boolean;
|
|
804
|
-
};
|
|
805
584
|
/**
|
|
806
585
|
* Hook to access open orders with loading state
|
|
807
586
|
*/
|
|
@@ -837,6 +616,7 @@ interface UserSelectionState {
|
|
|
837
616
|
addToken: (isLong: boolean) => void;
|
|
838
617
|
removeToken: (isLong: boolean, index: number) => void;
|
|
839
618
|
handleTokenSelect: (selectedToken: string) => void;
|
|
619
|
+
setTokenSelections: (longTokens: TokenSelection[], shortTokens: TokenSelection[]) => void;
|
|
840
620
|
resetToDefaults: () => void;
|
|
841
621
|
}
|
|
842
622
|
|
|
@@ -886,7 +666,6 @@ interface UseHistoricalPriceDataReturn {
|
|
|
886
666
|
hasHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => boolean;
|
|
887
667
|
getHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => Record<string, CandleData[]>;
|
|
888
668
|
getAllHistoricalPriceData(): Promise<Record<string, TokenHistoricalPriceData>>;
|
|
889
|
-
fetchFirstCandle: (symbol: string, interval: CandleInterval) => Promise<CandleData | null>;
|
|
890
669
|
isLoading: (symbol?: string) => boolean;
|
|
891
670
|
clearCache: () => void;
|
|
892
671
|
}
|
|
@@ -932,6 +711,180 @@ interface UsePerformanceOverlaysReturn {
|
|
|
932
711
|
}
|
|
933
712
|
declare const usePerformanceOverlays: () => UsePerformanceOverlaysReturn;
|
|
934
713
|
|
|
714
|
+
declare function useAuth(): {
|
|
715
|
+
readonly status: AuthStatus;
|
|
716
|
+
readonly isAuthenticated: boolean;
|
|
717
|
+
readonly accessToken: string | null;
|
|
718
|
+
readonly user: UserProfile | null;
|
|
719
|
+
readonly error: string | null;
|
|
720
|
+
readonly getEip712: (address: string) => Promise<any>;
|
|
721
|
+
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
722
|
+
readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
723
|
+
readonly refreshTokens: () => Promise<any>;
|
|
724
|
+
readonly logout: () => Promise<void>;
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
declare function useAgentWallet({ baseUrl }: UseAgentWalletOptions): {
|
|
728
|
+
readonly agentWallet: AgentWalletState;
|
|
729
|
+
readonly isReady: boolean;
|
|
730
|
+
readonly loading: false;
|
|
731
|
+
readonly error: null;
|
|
732
|
+
readonly refreshAgentWalletStatus: () => Promise<GetAgentWalletResponseDto>;
|
|
733
|
+
readonly createAgentWallet: () => Promise<CreateAgentWalletResponseDto>;
|
|
734
|
+
readonly notifyAgentWalletApproved: () => Promise<GetAgentWalletResponseDto>;
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
interface AutoSyncFillsOptions {
|
|
738
|
+
baseUrl: string;
|
|
739
|
+
accessToken: string;
|
|
740
|
+
address: string | null;
|
|
741
|
+
intervalMs?: number;
|
|
742
|
+
aggregateByTime?: boolean;
|
|
743
|
+
enabled?: boolean;
|
|
744
|
+
}
|
|
745
|
+
interface AutoSyncFillsState {
|
|
746
|
+
lastRunAt: number | null;
|
|
747
|
+
lastResult: SyncFillsResponseDto | null;
|
|
748
|
+
error: string | null;
|
|
749
|
+
isSyncing: boolean;
|
|
750
|
+
triggerSync: () => Promise<void>;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Listens to address changes and periodically syncs user fills
|
|
754
|
+
* Defaults: aggregate=true, interval=60s
|
|
755
|
+
*/
|
|
756
|
+
declare function useAutoSyncFills(options: AutoSyncFillsOptions): AutoSyncFillsState;
|
|
757
|
+
|
|
758
|
+
type ExecutionType = 'MARKET' | 'LIMIT' | 'TWAP' | 'LADDER' | 'LIMIT_BTCDOM';
|
|
759
|
+
type TpSlThresholdType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
760
|
+
interface PairAssetInput {
|
|
761
|
+
asset: string;
|
|
762
|
+
weight?: number;
|
|
763
|
+
}
|
|
764
|
+
interface TpSlThresholdInput {
|
|
765
|
+
type: TpSlThresholdType;
|
|
766
|
+
value: number;
|
|
767
|
+
}
|
|
768
|
+
interface CreatePositionRequestInput {
|
|
769
|
+
slippage: number;
|
|
770
|
+
executionType: ExecutionType;
|
|
771
|
+
leverage: number;
|
|
772
|
+
usdValue: number;
|
|
773
|
+
longAssets?: PairAssetInput[];
|
|
774
|
+
shortAssets?: PairAssetInput[];
|
|
775
|
+
triggerValue?: number;
|
|
776
|
+
direction?: 'MORE_THAN' | 'LESS_THAN';
|
|
777
|
+
twapDuration?: number;
|
|
778
|
+
randomizeExecution?: boolean;
|
|
779
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
780
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
781
|
+
}
|
|
782
|
+
type PositionResponseStatus = 'SUCCESS' | 'FAILED' | 'PENDING' | 'PARTIALLY_FILLED' | 'OPEN';
|
|
783
|
+
interface PositionAssetSummaryDto {
|
|
784
|
+
asset: string;
|
|
785
|
+
side: 'LONG' | 'SHORT';
|
|
786
|
+
size: number;
|
|
787
|
+
entryRatio: number;
|
|
788
|
+
usdValue: number;
|
|
789
|
+
orderId: string;
|
|
790
|
+
}
|
|
791
|
+
interface CreatePositionResponseDto {
|
|
792
|
+
positionId: string | null;
|
|
793
|
+
orderId: string;
|
|
794
|
+
status: PositionResponseStatus;
|
|
795
|
+
createdAt: string;
|
|
796
|
+
assets?: PositionAssetSummaryDto[];
|
|
797
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
798
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
799
|
+
hyperliquidResult?: any;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
803
|
+
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
804
|
+
*/
|
|
805
|
+
declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
806
|
+
interface UpdateRiskParametersRequestInput {
|
|
807
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
808
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
809
|
+
}
|
|
810
|
+
interface UpdateRiskParametersResponseDto {
|
|
811
|
+
positionId: string;
|
|
812
|
+
stopLoss: TpSlThresholdInput | null;
|
|
813
|
+
takeProfit: TpSlThresholdInput | null;
|
|
814
|
+
updatedAt: string;
|
|
815
|
+
}
|
|
816
|
+
declare function updateRiskParameters(baseUrl: string, accessToken: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
817
|
+
type CloseExecutionType = 'MARKET' | 'TWAP';
|
|
818
|
+
interface ClosePositionRequestInput {
|
|
819
|
+
executionType: CloseExecutionType;
|
|
820
|
+
twapDuration?: number;
|
|
821
|
+
randomizeExecution?: boolean;
|
|
822
|
+
}
|
|
823
|
+
interface ClosePositionResponseDto {
|
|
824
|
+
orderId: string;
|
|
825
|
+
executionTime?: string;
|
|
826
|
+
chunksScheduled?: number;
|
|
827
|
+
}
|
|
828
|
+
declare function closePosition(baseUrl: string, accessToken: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
829
|
+
type AdjustExecutionType = 'MARKET' | 'LIMIT';
|
|
830
|
+
type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
|
|
831
|
+
interface AdjustPositionRequestInput {
|
|
832
|
+
adjustmentType: PositionAdjustmentType;
|
|
833
|
+
adjustmentSize: number;
|
|
834
|
+
executionType: AdjustExecutionType;
|
|
835
|
+
limitRatio?: number;
|
|
836
|
+
}
|
|
837
|
+
interface AdjustPositionResponseDto {
|
|
838
|
+
orderId: string;
|
|
839
|
+
status: string;
|
|
840
|
+
adjustmentType: PositionAdjustmentType;
|
|
841
|
+
adjustmentSize: number;
|
|
842
|
+
newSize: number;
|
|
843
|
+
executedAt: string;
|
|
844
|
+
}
|
|
845
|
+
declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
846
|
+
|
|
847
|
+
declare function usePosition(): {
|
|
848
|
+
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
849
|
+
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
850
|
+
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
851
|
+
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
852
|
+
readonly openPositions: OpenPositionDto[] | null;
|
|
853
|
+
readonly isLoading: boolean;
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
interface AdjustOrderRequestInput {
|
|
857
|
+
limitRatio?: number;
|
|
858
|
+
usdValue?: number;
|
|
859
|
+
}
|
|
860
|
+
interface AdjustOrderResponseDto {
|
|
861
|
+
orderId: string;
|
|
862
|
+
limitRatio: number;
|
|
863
|
+
usdValue: number;
|
|
864
|
+
updatedAt: string;
|
|
865
|
+
}
|
|
866
|
+
declare function adjustOrder(baseUrl: string, accessToken: string, orderId: string, payload: AdjustOrderRequestInput): Promise<ApiResponse<AdjustOrderResponseDto>>;
|
|
867
|
+
interface CancelOrderResponseDto {
|
|
868
|
+
orderId: string;
|
|
869
|
+
status: string;
|
|
870
|
+
cancelledAt: string;
|
|
871
|
+
}
|
|
872
|
+
declare function cancelOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelOrderResponseDto>>;
|
|
873
|
+
interface CancelTwapResponseDto {
|
|
874
|
+
orderId: string;
|
|
875
|
+
status: string;
|
|
876
|
+
cancelledAt: string;
|
|
877
|
+
}
|
|
878
|
+
declare function cancelTwapOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
879
|
+
|
|
880
|
+
declare function useOrders(): {
|
|
881
|
+
readonly adjustOrder: (orderId: string, payload: AdjustOrderRequestInput) => Promise<ApiResponse<AdjustOrderResponseDto>>;
|
|
882
|
+
readonly cancelOrder: (orderId: string) => Promise<ApiResponse<CancelOrderResponseDto>>;
|
|
883
|
+
readonly cancelTwapOrder: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
884
|
+
readonly openOrders: OpenLimitOrderDto[] | null;
|
|
885
|
+
readonly isLoading: boolean;
|
|
886
|
+
};
|
|
887
|
+
|
|
935
888
|
interface UseHyperliquidWebSocketProps {
|
|
936
889
|
wsUrl: string;
|
|
937
890
|
address: string | null;
|
|
@@ -1055,5 +1008,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1055
1008
|
*/
|
|
1056
1009
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1057
1010
|
|
|
1058
|
-
export { AccountSummaryCalculator,
|
|
1059
|
-
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState,
|
|
1011
|
+
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
|
|
1012
|
+
export type { AccountSummaryResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, MarginSummaryDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|