@pear-protocol/hyperliquid-sdk 0.0.24 → 0.0.26
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/client.d.ts +34 -50
- 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/positions.d.ts +49 -0
- package/dist/clients/sync.d.ts +9 -0
- package/dist/hooks/index.d.ts +4 -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/usePosition.d.ts +7 -0
- package/dist/hooks/useTrading.d.ts +0 -11
- package/dist/index.d.ts +212 -336
- package/dist/index.js +6612 -6356
- package/dist/provider.d.ts +53 -19
- package/dist/store/userSelection.d.ts +1 -2
- package/dist/types.d.ts +131 -199
- package/dist/utils/http.d.ts +3 -0
- package/package.json +1 -1
- 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
|
|
@@ -261,6 +75,7 @@ interface TradeHistoryDataDto {
|
|
|
261
75
|
externalFeePaid: number;
|
|
262
76
|
builderFeePaid: number;
|
|
263
77
|
realizedPnl: number;
|
|
78
|
+
totalEntryValue: number;
|
|
264
79
|
totalValue: number;
|
|
265
80
|
entryRatio: number;
|
|
266
81
|
exitRatio: number;
|
|
@@ -287,16 +102,16 @@ interface PositionAssetDetailDto {
|
|
|
287
102
|
actualSize: number;
|
|
288
103
|
cumFunding: CumFundingDto;
|
|
289
104
|
marginUsed: number;
|
|
105
|
+
entryPositionValue: number;
|
|
290
106
|
positionValue: number;
|
|
291
107
|
unrealizedPnl: number;
|
|
292
108
|
liquidationPrice: number;
|
|
293
|
-
isExternallyModified: boolean;
|
|
294
109
|
initialWeight: number;
|
|
295
110
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
111
|
+
interface TpSlThreshold {
|
|
112
|
+
type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
113
|
+
value: number;
|
|
114
|
+
}
|
|
300
115
|
/**
|
|
301
116
|
* Open position data structure
|
|
302
117
|
*/
|
|
@@ -304,18 +119,17 @@ interface OpenPositionDto {
|
|
|
304
119
|
positionId: string;
|
|
305
120
|
address: string;
|
|
306
121
|
leverage: number;
|
|
307
|
-
stopLoss:
|
|
308
|
-
takeProfit:
|
|
122
|
+
stopLoss: TpSlThreshold | null;
|
|
123
|
+
takeProfit: TpSlThreshold | null;
|
|
309
124
|
entryRatio: number;
|
|
310
125
|
markRatio: number;
|
|
311
126
|
netFunding: number;
|
|
127
|
+
entryPositionValue: number;
|
|
312
128
|
positionValue: number;
|
|
313
129
|
marginUsed: number;
|
|
314
130
|
unrealizedPnl: number;
|
|
315
131
|
longAssets: PositionAssetDetailDto[];
|
|
316
132
|
shortAssets: PositionAssetDetailDto[];
|
|
317
|
-
syncStatus: PositionSyncStatus;
|
|
318
|
-
lastSyncAt: string;
|
|
319
133
|
createdAt: string;
|
|
320
134
|
updatedAt: string;
|
|
321
135
|
}
|
|
@@ -402,6 +216,40 @@ interface AccountSummaryResponseDto {
|
|
|
402
216
|
balanceSummary: BalanceSummaryDto;
|
|
403
217
|
agentWallet: AgentWalletDto;
|
|
404
218
|
}
|
|
219
|
+
declare enum AuthStatus {
|
|
220
|
+
Idle = "idle",
|
|
221
|
+
Authenticating = "authenticating",
|
|
222
|
+
Authenticated = "authenticated",
|
|
223
|
+
Error = "error"
|
|
224
|
+
}
|
|
225
|
+
interface UseAuthOptions {
|
|
226
|
+
baseUrl: string;
|
|
227
|
+
clientId: string;
|
|
228
|
+
}
|
|
229
|
+
interface UserProfile {
|
|
230
|
+
userId: string;
|
|
231
|
+
address: string;
|
|
232
|
+
appId: string;
|
|
233
|
+
}
|
|
234
|
+
type AgentWalletStatus = 'ACTIVE' | 'EXPIRED' | 'NOT_FOUND';
|
|
235
|
+
interface GetAgentWalletResponseDto {
|
|
236
|
+
agentWalletAddress?: string;
|
|
237
|
+
agentName: string;
|
|
238
|
+
status: AgentWalletStatus;
|
|
239
|
+
}
|
|
240
|
+
interface CreateAgentWalletResponseDto {
|
|
241
|
+
agentWalletAddress: string;
|
|
242
|
+
message: string;
|
|
243
|
+
}
|
|
244
|
+
interface UseAgentWalletOptions {
|
|
245
|
+
baseUrl: string;
|
|
246
|
+
}
|
|
247
|
+
interface AgentWalletState {
|
|
248
|
+
address: string | null;
|
|
249
|
+
name: string | null;
|
|
250
|
+
status: AgentWalletStatus | 'PENDING' | null;
|
|
251
|
+
isActive: boolean;
|
|
252
|
+
}
|
|
405
253
|
/**
|
|
406
254
|
* WebSocket message from HyperLiquid native API
|
|
407
255
|
*/
|
|
@@ -641,142 +489,82 @@ interface CandleSnapshotRequest {
|
|
|
641
489
|
};
|
|
642
490
|
type: "candleSnapshot";
|
|
643
491
|
}
|
|
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
492
|
interface TokenSelectorConfig {
|
|
756
493
|
isLong: boolean;
|
|
757
494
|
index: number;
|
|
758
495
|
}
|
|
496
|
+
|
|
497
|
+
interface PearHyperliquidContextType {
|
|
498
|
+
apiBaseUrl: string;
|
|
499
|
+
wsUrl: string;
|
|
500
|
+
address: string | null;
|
|
501
|
+
setAddress: (address: string | null) => void;
|
|
502
|
+
connectionStatus: ReadyState;
|
|
503
|
+
isConnected: boolean;
|
|
504
|
+
lastError: string | null;
|
|
505
|
+
nativeConnectionStatus: ReadyState;
|
|
506
|
+
nativeIsConnected: boolean;
|
|
507
|
+
nativeLastError: string | null;
|
|
508
|
+
authStatus: AuthStatus;
|
|
509
|
+
isAuthenticated: boolean;
|
|
510
|
+
accessToken: string | null;
|
|
511
|
+
user: UserProfile | null;
|
|
512
|
+
authError: string | null;
|
|
513
|
+
getEip712: (address: string) => Promise<any>;
|
|
514
|
+
loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
515
|
+
loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
516
|
+
refreshTokens: () => Promise<any>;
|
|
517
|
+
logout: () => Promise<void>;
|
|
518
|
+
agentWallet: AgentWalletState;
|
|
519
|
+
isAgentWalletReady: boolean;
|
|
520
|
+
agentWalletError: string | null;
|
|
521
|
+
agentWalletLoading: boolean;
|
|
522
|
+
refreshAgentWalletStatus: () => Promise<any>;
|
|
523
|
+
createAgentWallet: () => Promise<any>;
|
|
524
|
+
notifyAgentWalletApproved: () => Promise<any>;
|
|
525
|
+
}
|
|
759
526
|
interface PearHyperliquidProviderProps {
|
|
760
|
-
config: PearHyperliquidConfig;
|
|
761
|
-
/**
|
|
762
|
-
* WebSocket server URL
|
|
763
|
-
* @default 'wss://hl-v2.pearprotocol.io/ws'
|
|
764
|
-
*/
|
|
765
|
-
wsUrl?: string;
|
|
766
527
|
children: ReactNode;
|
|
528
|
+
apiBaseUrl?: string;
|
|
529
|
+
clientId?: string;
|
|
530
|
+
wsUrl?: string;
|
|
767
531
|
}
|
|
768
532
|
/**
|
|
769
533
|
* React Provider for PearHyperliquidClient
|
|
770
534
|
*/
|
|
771
535
|
declare const PearHyperliquidProvider: React.FC<PearHyperliquidProviderProps>;
|
|
772
536
|
/**
|
|
773
|
-
* Hook to
|
|
537
|
+
* Hook to access the entire Pear Hyperliquid context.
|
|
538
|
+
* Prefer using the more specific hooks below when possible.
|
|
774
539
|
*/
|
|
775
|
-
declare
|
|
540
|
+
declare function usePearHyperliquid(): PearHyperliquidContextType;
|
|
776
541
|
/**
|
|
777
|
-
*
|
|
542
|
+
* Provider-aware Auth hook. Uses auth state/actions provided by PearHyperliquidProvider.
|
|
543
|
+
* Callers do not need to pass baseUrl/clientId.
|
|
778
544
|
*/
|
|
779
|
-
declare
|
|
545
|
+
declare function usePearAuth(): {
|
|
546
|
+
readonly status: AuthStatus;
|
|
547
|
+
readonly isAuthenticated: boolean;
|
|
548
|
+
readonly user: UserProfile | null;
|
|
549
|
+
readonly error: string | null;
|
|
550
|
+
readonly getEip712: (address: string) => Promise<any>;
|
|
551
|
+
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
552
|
+
readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
553
|
+
readonly refreshTokens: () => Promise<any>;
|
|
554
|
+
readonly logout: () => Promise<void>;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Provider-aware Agent Wallet hook. Uses agent wallet state/actions provided by PearHyperliquidProvider.
|
|
558
|
+
*/
|
|
559
|
+
declare function usePearAgentWallet(): {
|
|
560
|
+
readonly agentWallet: AgentWalletState;
|
|
561
|
+
readonly isReady: boolean;
|
|
562
|
+
readonly loading: boolean;
|
|
563
|
+
readonly error: string | null;
|
|
564
|
+
readonly refreshAgentWalletStatus: () => Promise<any>;
|
|
565
|
+
readonly createAgentWallet: () => Promise<any>;
|
|
566
|
+
readonly notifyAgentWalletApproved: () => Promise<any>;
|
|
567
|
+
};
|
|
780
568
|
|
|
781
569
|
/**
|
|
782
570
|
* Hook to manage address (login/logout functionality)
|
|
@@ -792,16 +580,6 @@ declare const useTradeHistories: () => {
|
|
|
792
580
|
data: TradeHistoryDataDto[] | null;
|
|
793
581
|
isLoading: boolean;
|
|
794
582
|
};
|
|
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
583
|
/**
|
|
806
584
|
* Hook to access open orders with loading state
|
|
807
585
|
*/
|
|
@@ -886,7 +664,6 @@ interface UseHistoricalPriceDataReturn {
|
|
|
886
664
|
hasHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => boolean;
|
|
887
665
|
getHistoricalPriceData: (startTime: number, endTime: number, interval: CandleInterval) => Record<string, CandleData[]>;
|
|
888
666
|
getAllHistoricalPriceData(): Promise<Record<string, TokenHistoricalPriceData>>;
|
|
889
|
-
fetchFirstCandle: (symbol: string, interval: CandleInterval) => Promise<CandleData | null>;
|
|
890
667
|
isLoading: (symbol?: string) => boolean;
|
|
891
668
|
clearCache: () => void;
|
|
892
669
|
}
|
|
@@ -932,6 +709,105 @@ interface UsePerformanceOverlaysReturn {
|
|
|
932
709
|
}
|
|
933
710
|
declare const usePerformanceOverlays: () => UsePerformanceOverlaysReturn;
|
|
934
711
|
|
|
712
|
+
declare function useAuth(): {
|
|
713
|
+
readonly status: AuthStatus;
|
|
714
|
+
readonly isAuthenticated: boolean;
|
|
715
|
+
readonly accessToken: string | null;
|
|
716
|
+
readonly user: UserProfile | null;
|
|
717
|
+
readonly error: string | null;
|
|
718
|
+
readonly getEip712: (address: string) => Promise<any>;
|
|
719
|
+
readonly loginWithSignedMessage: (address: string, signature: string, timestamp: number) => Promise<void>;
|
|
720
|
+
readonly loginWithPrivyToken: (address: string, appId: string, accessToken: string) => Promise<void>;
|
|
721
|
+
readonly refreshTokens: () => Promise<any>;
|
|
722
|
+
readonly logout: () => Promise<void>;
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
declare function useAgentWallet({ baseUrl }: UseAgentWalletOptions): {
|
|
726
|
+
readonly agentWallet: AgentWalletState;
|
|
727
|
+
readonly isReady: boolean;
|
|
728
|
+
readonly loading: false;
|
|
729
|
+
readonly error: null;
|
|
730
|
+
readonly refreshAgentWalletStatus: () => Promise<GetAgentWalletResponseDto>;
|
|
731
|
+
readonly createAgentWallet: () => Promise<CreateAgentWalletResponseDto>;
|
|
732
|
+
readonly notifyAgentWalletApproved: () => Promise<GetAgentWalletResponseDto>;
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
interface AutoSyncFillsOptions {
|
|
736
|
+
baseUrl: string;
|
|
737
|
+
accessToken: string;
|
|
738
|
+
address: string | null;
|
|
739
|
+
intervalMs?: number;
|
|
740
|
+
aggregateByTime?: boolean;
|
|
741
|
+
enabled?: boolean;
|
|
742
|
+
}
|
|
743
|
+
interface AutoSyncFillsState {
|
|
744
|
+
lastRunAt: number | null;
|
|
745
|
+
lastResult: SyncFillsResponseDto | null;
|
|
746
|
+
error: string | null;
|
|
747
|
+
isSyncing: boolean;
|
|
748
|
+
triggerSync: () => Promise<void>;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Listens to address changes and periodically syncs user fills
|
|
752
|
+
* Defaults: aggregate=true, interval=60s
|
|
753
|
+
*/
|
|
754
|
+
declare function useAutoSyncFills(options: AutoSyncFillsOptions): AutoSyncFillsState;
|
|
755
|
+
|
|
756
|
+
type ExecutionType = 'MARKET' | 'LIMIT' | 'TWAP' | 'LADDER' | 'LIMIT_BTCDOM';
|
|
757
|
+
type TpSlThresholdType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
758
|
+
interface PairAssetInput {
|
|
759
|
+
asset: string;
|
|
760
|
+
weight?: number;
|
|
761
|
+
}
|
|
762
|
+
interface TpSlThresholdInput {
|
|
763
|
+
type: TpSlThresholdType;
|
|
764
|
+
value: number;
|
|
765
|
+
}
|
|
766
|
+
interface CreatePositionRequestInput {
|
|
767
|
+
slippage: number;
|
|
768
|
+
executionType: ExecutionType;
|
|
769
|
+
leverage: number;
|
|
770
|
+
usdValue: number;
|
|
771
|
+
longAssets?: PairAssetInput[];
|
|
772
|
+
shortAssets?: PairAssetInput[];
|
|
773
|
+
triggerValue?: number;
|
|
774
|
+
direction?: 'MORE_THAN' | 'LESS_THAN';
|
|
775
|
+
twapDuration?: number;
|
|
776
|
+
randomizeExecution?: boolean;
|
|
777
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
778
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
779
|
+
}
|
|
780
|
+
type PositionResponseStatus = 'SUCCESS' | 'FAILED' | 'PENDING' | 'PARTIALLY_FILLED' | 'OPEN';
|
|
781
|
+
interface PositionAssetSummaryDto {
|
|
782
|
+
asset: string;
|
|
783
|
+
side: 'LONG' | 'SHORT';
|
|
784
|
+
size: number;
|
|
785
|
+
entryRatio: number;
|
|
786
|
+
usdValue: number;
|
|
787
|
+
orderId: string;
|
|
788
|
+
}
|
|
789
|
+
interface CreatePositionResponseDto {
|
|
790
|
+
positionId: string | null;
|
|
791
|
+
orderId: string;
|
|
792
|
+
status: PositionResponseStatus;
|
|
793
|
+
createdAt: string;
|
|
794
|
+
assets?: PositionAssetSummaryDto[];
|
|
795
|
+
stopLoss?: TpSlThresholdInput | null;
|
|
796
|
+
takeProfit?: TpSlThresholdInput | null;
|
|
797
|
+
hyperliquidResult?: any;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
801
|
+
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
802
|
+
*/
|
|
803
|
+
declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
804
|
+
|
|
805
|
+
declare function usePosition(): {
|
|
806
|
+
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
807
|
+
readonly openPositions: OpenPositionDto[] | null;
|
|
808
|
+
readonly isLoading: boolean;
|
|
809
|
+
};
|
|
810
|
+
|
|
935
811
|
interface UseHyperliquidWebSocketProps {
|
|
936
812
|
wsUrl: string;
|
|
937
813
|
address: string | null;
|
|
@@ -1055,5 +931,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1055
931
|
*/
|
|
1056
932
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1057
933
|
|
|
1058
|
-
export { AccountSummaryCalculator,
|
|
1059
|
-
export type { AccountSummaryResponseDto, AgentWalletDto, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CrossMarginSummaryDto, CumFundingDto, HLWebSocketResponse, HistoricalRange, MarginSummaryDto,
|
|
934
|
+
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, calculateWeightedRatio, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useOpenOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useUserSelection, useWebData };
|
|
935
|
+
export type { AccountSummaryResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, MarginSummaryDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, UniverseAsset, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|