@pear-protocol/hyperliquid-sdk 0.0.1
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 +265 -0
- package/dist/client.d.ts +43 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useAddress.d.ts +9 -0
- package/dist/hooks/useTrading.d.ts +16 -0
- package/dist/index.d.ts +536 -0
- package/dist/index.esm.js +2810 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2824 -0
- package/dist/index.js.map +1 -0
- package/dist/migration-sdk.d.ts +45 -0
- package/dist/provider.d.ts +45 -0
- package/dist/types.d.ts +404 -0
- package/package.json +50 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw value data for trade history positions
|
|
3
|
+
*/
|
|
4
|
+
export interface RawValueDto {
|
|
5
|
+
coin: string;
|
|
6
|
+
size: string;
|
|
7
|
+
leverage: number;
|
|
8
|
+
openPx: string;
|
|
9
|
+
closePx: string;
|
|
10
|
+
marginUsed: string;
|
|
11
|
+
positionValue: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Trade history data structure from V1 API
|
|
15
|
+
*/
|
|
16
|
+
export interface TradeHistoryV1Dto {
|
|
17
|
+
pearId: string;
|
|
18
|
+
openedDate: string;
|
|
19
|
+
closedDate: string;
|
|
20
|
+
time: string;
|
|
21
|
+
pair: string;
|
|
22
|
+
direction: Record<string, string>;
|
|
23
|
+
closedPrice: number;
|
|
24
|
+
openedPrice: number;
|
|
25
|
+
size: string;
|
|
26
|
+
longPositionValue: number;
|
|
27
|
+
shortPositionValue: number;
|
|
28
|
+
positionValue: number;
|
|
29
|
+
fee: number;
|
|
30
|
+
builderFee: number;
|
|
31
|
+
closedPNL: number;
|
|
32
|
+
closedPnlPercentage: number;
|
|
33
|
+
leverage: number;
|
|
34
|
+
rawLongValue: RawValueDto;
|
|
35
|
+
rawShortValue: RawValueDto;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Request payload for syncing trade history
|
|
39
|
+
*/
|
|
40
|
+
export interface SyncTradeHistoryDto {
|
|
41
|
+
address: string;
|
|
42
|
+
data: TradeHistoryV1Dto[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Response from sync trade history endpoint
|
|
46
|
+
*/
|
|
47
|
+
export interface SyncTradeHistoryResponseDto {
|
|
48
|
+
success: boolean;
|
|
49
|
+
positionId: string;
|
|
50
|
+
tradeHistoryId: string;
|
|
51
|
+
message: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Base API error response
|
|
55
|
+
*/
|
|
56
|
+
export interface ApiErrorResponse {
|
|
57
|
+
statusCode: number;
|
|
58
|
+
message: string;
|
|
59
|
+
error?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Configuration options for the SDK
|
|
63
|
+
*/
|
|
64
|
+
export interface PearHyperliquidConfig {
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
timeout?: number;
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* HTTP client response wrapper
|
|
71
|
+
*/
|
|
72
|
+
export interface ApiResponse<T> {
|
|
73
|
+
data: T;
|
|
74
|
+
status: number;
|
|
75
|
+
headers: Record<string, string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook state interface for migration operations
|
|
79
|
+
*/
|
|
80
|
+
export interface MigrationHookState<T> {
|
|
81
|
+
loading: boolean;
|
|
82
|
+
error: ApiErrorResponse | null;
|
|
83
|
+
data: T | null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* PnL data structure for open positions
|
|
87
|
+
*/
|
|
88
|
+
export interface PnlDto {
|
|
89
|
+
value: number;
|
|
90
|
+
percentage: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Take profit and stop loss data structure
|
|
94
|
+
*/
|
|
95
|
+
export interface TpSlDto {
|
|
96
|
+
takeProfit?: number;
|
|
97
|
+
stopLoss?: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Position side data structure for open positions
|
|
101
|
+
*/
|
|
102
|
+
export interface PositionSideDto {
|
|
103
|
+
coin: string;
|
|
104
|
+
size: string;
|
|
105
|
+
leverage: number;
|
|
106
|
+
entryPx: string;
|
|
107
|
+
marginUsed: string;
|
|
108
|
+
liquidationPx: string | undefined;
|
|
109
|
+
unrealizedPnl: string;
|
|
110
|
+
roe: string;
|
|
111
|
+
positionValue: string;
|
|
112
|
+
funding: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Open position data structure from V1 API
|
|
116
|
+
*/
|
|
117
|
+
export interface OpenPositionV1Dto {
|
|
118
|
+
pair: string;
|
|
119
|
+
leverage: number;
|
|
120
|
+
size: number;
|
|
121
|
+
longPositionValue?: number;
|
|
122
|
+
shortPositionValue?: number;
|
|
123
|
+
positionValue: number;
|
|
124
|
+
entryPrice: number;
|
|
125
|
+
markPrice: number;
|
|
126
|
+
pnl: PnlDto;
|
|
127
|
+
liqPrice: string | number;
|
|
128
|
+
margin: number;
|
|
129
|
+
funding: number;
|
|
130
|
+
pearId: string;
|
|
131
|
+
openedDate: string;
|
|
132
|
+
tpsl: TpSlDto;
|
|
133
|
+
long: PositionSideDto;
|
|
134
|
+
short: PositionSideDto;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Request payload for syncing open positions
|
|
138
|
+
*/
|
|
139
|
+
export interface SyncOpenPositionDto {
|
|
140
|
+
address: string;
|
|
141
|
+
data: OpenPositionV1Dto[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Response from sync open positions endpoint
|
|
145
|
+
*/
|
|
146
|
+
export interface SyncOpenPositionResponseDto {
|
|
147
|
+
success: boolean;
|
|
148
|
+
positionIds: string[];
|
|
149
|
+
count: number;
|
|
150
|
+
message: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Open order data structure from V1 API
|
|
154
|
+
*/
|
|
155
|
+
export interface OpenOrderV1Dto {
|
|
156
|
+
id: string;
|
|
157
|
+
time: string;
|
|
158
|
+
pair: string;
|
|
159
|
+
type: string;
|
|
160
|
+
orderValue: number;
|
|
161
|
+
price: number;
|
|
162
|
+
triggerConditions: string;
|
|
163
|
+
status: string;
|
|
164
|
+
leverage?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Request payload for syncing open orders
|
|
168
|
+
*/
|
|
169
|
+
export interface SyncOpenOrderDto {
|
|
170
|
+
address: string;
|
|
171
|
+
data: OpenOrderV1Dto[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Response from sync open orders endpoint
|
|
175
|
+
*/
|
|
176
|
+
export interface SyncOpenOrderResponseDto {
|
|
177
|
+
success: boolean;
|
|
178
|
+
orderIds: string[];
|
|
179
|
+
count: number;
|
|
180
|
+
message: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Migration hooks interface
|
|
184
|
+
*/
|
|
185
|
+
export interface MigrationHooks {
|
|
186
|
+
tradeHistory: {
|
|
187
|
+
sync: (payload: SyncTradeHistoryDto) => Promise<ApiResponse<SyncTradeHistoryResponseDto>>;
|
|
188
|
+
loading: boolean;
|
|
189
|
+
error: ApiErrorResponse | null;
|
|
190
|
+
data: SyncTradeHistoryResponseDto | null;
|
|
191
|
+
reset: () => void;
|
|
192
|
+
};
|
|
193
|
+
openPositions: {
|
|
194
|
+
sync: (payload: SyncOpenPositionDto) => Promise<ApiResponse<SyncOpenPositionResponseDto>>;
|
|
195
|
+
loading: boolean;
|
|
196
|
+
error: ApiErrorResponse | null;
|
|
197
|
+
data: SyncOpenPositionResponseDto | null;
|
|
198
|
+
reset: () => void;
|
|
199
|
+
};
|
|
200
|
+
openOrders: {
|
|
201
|
+
sync: (payload: SyncOpenOrderDto) => Promise<ApiResponse<SyncOpenOrderResponseDto>>;
|
|
202
|
+
loading: boolean;
|
|
203
|
+
error: ApiErrorResponse | null;
|
|
204
|
+
data: SyncOpenOrderResponseDto | null;
|
|
205
|
+
reset: () => void;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* WebSocket connection states
|
|
210
|
+
*/
|
|
211
|
+
export type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'error';
|
|
212
|
+
/**
|
|
213
|
+
* WebSocket channels
|
|
214
|
+
*/
|
|
215
|
+
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary';
|
|
216
|
+
/**
|
|
217
|
+
* WebSocket subscription message
|
|
218
|
+
*/
|
|
219
|
+
export interface WebSocketSubscribeMessage {
|
|
220
|
+
action?: 'subscribe' | 'unsubscribe';
|
|
221
|
+
address: string;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* WebSocket response message
|
|
225
|
+
*/
|
|
226
|
+
export interface WebSocketResponse {
|
|
227
|
+
success?: boolean;
|
|
228
|
+
message?: string;
|
|
229
|
+
error?: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* WebSocket data message
|
|
233
|
+
*/
|
|
234
|
+
export interface WebSocketDataMessage<T = unknown> {
|
|
235
|
+
channel: WebSocketChannel;
|
|
236
|
+
data: T;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Trade history asset data
|
|
240
|
+
*/
|
|
241
|
+
export interface TradeHistoryAssetDataDto {
|
|
242
|
+
coin: string;
|
|
243
|
+
entryPrice: number;
|
|
244
|
+
limitPrice: number;
|
|
245
|
+
size: number;
|
|
246
|
+
externalFeePaid: number;
|
|
247
|
+
builderFeePaid: number;
|
|
248
|
+
realizedPnl: number;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Trade history data structure
|
|
252
|
+
*/
|
|
253
|
+
export interface TradeHistoryDataDto {
|
|
254
|
+
tradeHistoryId: string;
|
|
255
|
+
positionId: string;
|
|
256
|
+
address: string;
|
|
257
|
+
externalFeePaid: number;
|
|
258
|
+
builderFeePaid: number;
|
|
259
|
+
realizedPnl: number;
|
|
260
|
+
totalValue: number;
|
|
261
|
+
entryRatio: number;
|
|
262
|
+
exitRatio: number;
|
|
263
|
+
leverage: number;
|
|
264
|
+
longAssets: TradeHistoryAssetDataDto[];
|
|
265
|
+
shortAssets: TradeHistoryAssetDataDto[];
|
|
266
|
+
createdAt: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Paginated trade history response
|
|
270
|
+
*/
|
|
271
|
+
export interface PaginatedTradeHistoryResponseDto {
|
|
272
|
+
data: TradeHistoryDataDto[];
|
|
273
|
+
hasMore: boolean;
|
|
274
|
+
nextCursor?: string;
|
|
275
|
+
count: number;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Cumulative funding information
|
|
279
|
+
*/
|
|
280
|
+
export interface CumFundingDto {
|
|
281
|
+
allTime: number;
|
|
282
|
+
sinceChange: number;
|
|
283
|
+
sinceOpen: number;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Position asset detail
|
|
287
|
+
*/
|
|
288
|
+
export interface PositionAssetDetailDto {
|
|
289
|
+
coin: string;
|
|
290
|
+
entryPrice: number;
|
|
291
|
+
platformSize: number;
|
|
292
|
+
actualSize: number;
|
|
293
|
+
cumFunding: CumFundingDto;
|
|
294
|
+
marginUsed: number;
|
|
295
|
+
positionValue: number;
|
|
296
|
+
unrealizedPnl: number;
|
|
297
|
+
liquidationPrice: number;
|
|
298
|
+
isExternallyModified: boolean;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Position sync status
|
|
302
|
+
*/
|
|
303
|
+
export type PositionSyncStatus = 'SYNCED' | 'EXTERNALLY_MODIFIED' | 'EXTERNALLY_CLOSED' | 'PAIR_BROKEN';
|
|
304
|
+
/**
|
|
305
|
+
* Open position data structure
|
|
306
|
+
*/
|
|
307
|
+
export interface OpenPositionDto {
|
|
308
|
+
positionId: string;
|
|
309
|
+
address: string;
|
|
310
|
+
leverage: number;
|
|
311
|
+
stopLoss: number | null;
|
|
312
|
+
takeProfit: number | null;
|
|
313
|
+
entryRatio: number;
|
|
314
|
+
markRatio: number;
|
|
315
|
+
netFunding: number;
|
|
316
|
+
positionValue: number;
|
|
317
|
+
marginUsed: number;
|
|
318
|
+
unrealizedPnl: number;
|
|
319
|
+
longAssets: PositionAssetDetailDto[];
|
|
320
|
+
shortAssets: PositionAssetDetailDto[];
|
|
321
|
+
syncStatus: PositionSyncStatus;
|
|
322
|
+
lastSyncAt: string;
|
|
323
|
+
createdAt: string;
|
|
324
|
+
updatedAt: string;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Order asset data
|
|
328
|
+
*/
|
|
329
|
+
export interface OrderAssetDto {
|
|
330
|
+
asset: string;
|
|
331
|
+
weight: number;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Order status
|
|
335
|
+
*/
|
|
336
|
+
export type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
|
|
337
|
+
/**
|
|
338
|
+
* Open limit order data structure
|
|
339
|
+
*/
|
|
340
|
+
export interface OpenLimitOrderDto {
|
|
341
|
+
orderId: string;
|
|
342
|
+
address: string;
|
|
343
|
+
leverage: number;
|
|
344
|
+
usdValue: number;
|
|
345
|
+
limitRatio: number;
|
|
346
|
+
stopLoss: number | null;
|
|
347
|
+
takeProfit: number | null;
|
|
348
|
+
status: OrderStatus;
|
|
349
|
+
longAssets: OrderAssetDto[];
|
|
350
|
+
shortAssets: OrderAssetDto[];
|
|
351
|
+
createdAt: string;
|
|
352
|
+
updatedAt: string;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Cross margin summary
|
|
356
|
+
*/
|
|
357
|
+
export interface CrossMarginSummaryDto {
|
|
358
|
+
accountValue: string;
|
|
359
|
+
totalMarginUsed: string;
|
|
360
|
+
totalNtlPos: string;
|
|
361
|
+
totalRawUsd: string;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Margin summary
|
|
365
|
+
*/
|
|
366
|
+
export interface MarginSummaryDto {
|
|
367
|
+
accountValue: string;
|
|
368
|
+
totalMarginUsed: string;
|
|
369
|
+
totalNtlPos: string;
|
|
370
|
+
totalRawUsd: string;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Balance summary
|
|
374
|
+
*/
|
|
375
|
+
export interface BalanceSummaryDto {
|
|
376
|
+
crossMaintenanceMarginUsed: string;
|
|
377
|
+
crossMarginSummary: CrossMarginSummaryDto;
|
|
378
|
+
marginSummary: MarginSummaryDto;
|
|
379
|
+
time: number;
|
|
380
|
+
withdrawable: string;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Agent wallet information
|
|
384
|
+
*/
|
|
385
|
+
export interface AgentWalletDto {
|
|
386
|
+
address: string;
|
|
387
|
+
status: string;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Account balance response (renamed to AccountSummaryResponseDto for consistency)
|
|
391
|
+
*/
|
|
392
|
+
export interface AccountSummaryResponseDto {
|
|
393
|
+
balanceSummary: BalanceSummaryDto;
|
|
394
|
+
agentWallet: AgentWalletDto;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Address management state
|
|
398
|
+
*/
|
|
399
|
+
export interface AddressState {
|
|
400
|
+
currentAddress: string | null;
|
|
401
|
+
isLoggedIn: boolean;
|
|
402
|
+
autoConnect: boolean;
|
|
403
|
+
previousAddresses: string[];
|
|
404
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "rollup -c",
|
|
14
|
+
"dev": "rollup -c -w",
|
|
15
|
+
"type-check": "tsc --noEmit",
|
|
16
|
+
"clean": "rimraf dist"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"axios": "^1.6.0",
|
|
20
|
+
"react-use-websocket": "^4.8.1"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=16.8.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
28
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
29
|
+
"@types/react": "^18.0.0",
|
|
30
|
+
"react": "^18.0.0",
|
|
31
|
+
"rimraf": "^5.0.0",
|
|
32
|
+
"rollup": "^3.0.0",
|
|
33
|
+
"rollup-plugin-dts": "^6.0.0",
|
|
34
|
+
"tslib": "^2.6.0",
|
|
35
|
+
"typescript": "^5.0.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": ["pear", "hyperliquid", "sdk", "react", "trading", "api"],
|
|
38
|
+
"author": "Pear Protocol",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/pear-protocol/hyperliquid.git",
|
|
43
|
+
"directory": "pear-hyperliquid-sdk"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"registry": "https://registry.npmjs.org",
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"private": false
|
|
50
|
+
}
|