@pear-protocol/hyperliquid-sdk 0.0.44 → 0.0.46
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 +111 -98
- package/dist/clients/portfolio.d.ts +39 -0
- package/dist/clients/positions.d.ts +11 -10
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/usePortfolio.d.ts +13 -0
- package/dist/index.d.ts +104 -23
- package/dist/index.js +231 -44
- package/dist/utils/position-validator.d.ts +41 -0
- package/package.json +1 -1
- package/dist/hooks/useAuth.d.ts +0 -12
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ yarn add react react-dom
|
|
|
37
37
|
### 1. Wrap your application with the Provider
|
|
38
38
|
|
|
39
39
|
```tsx
|
|
40
|
-
import { PearHyperliquidProvider } from
|
|
40
|
+
import { PearHyperliquidProvider } from "@pear-protocol/hyperliquid-sdk";
|
|
41
41
|
|
|
42
42
|
function App() {
|
|
43
43
|
return (
|
|
@@ -59,8 +59,8 @@ import {
|
|
|
59
59
|
usePearAuth,
|
|
60
60
|
usePearHyperliquid,
|
|
61
61
|
usePosition,
|
|
62
|
-
useOrders
|
|
63
|
-
} from
|
|
62
|
+
useOrders,
|
|
63
|
+
} from "@pear-protocol/hyperliquid-sdk";
|
|
64
64
|
|
|
65
65
|
function TradingComponent() {
|
|
66
66
|
const { address, setAddress } = usePearHyperliquid();
|
|
@@ -78,11 +78,11 @@ function TradingComponent() {
|
|
|
78
78
|
|
|
79
79
|
The `PearHyperliquidProvider` accepts the following props:
|
|
80
80
|
|
|
81
|
-
| Prop
|
|
82
|
-
|
|
83
|
-
| `apiBaseUrl` | `string` | `https://hl-v2.pearprotocol.io`
|
|
84
|
-
| `wsUrl`
|
|
85
|
-
| `clientId`
|
|
81
|
+
| Prop | Type | Default | Description |
|
|
82
|
+
| ------------ | -------- | -------------------------------- | ------------------------------------ |
|
|
83
|
+
| `apiBaseUrl` | `string` | `https://hl-v2.pearprotocol.io` | Pear API base URL |
|
|
84
|
+
| `wsUrl` | `string` | `wss://hl-v2.pearprotocol.io/ws` | Pear WebSocket URL |
|
|
85
|
+
| `clientId` | `string` | `PEARPROTOCOLUI` | Client identifier for authentication |
|
|
86
86
|
|
|
87
87
|
### Authentication
|
|
88
88
|
|
|
@@ -91,7 +91,7 @@ The SDK supports two authentication methods:
|
|
|
91
91
|
#### EIP-712 Signature Authentication
|
|
92
92
|
|
|
93
93
|
```tsx
|
|
94
|
-
import { usePearAuth } from
|
|
94
|
+
import { usePearAuth } from "@pear-protocol/hyperliquid-sdk";
|
|
95
95
|
|
|
96
96
|
function LoginComponent() {
|
|
97
97
|
const { getEip712, loginWithSignedMessage, isAuthenticated } = usePearAuth();
|
|
@@ -111,23 +111,23 @@ function LoginComponent() {
|
|
|
111
111
|
await loginWithSignedMessage(address, signature, eip712Data.timestamp);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
return
|
|
115
|
-
<div>
|
|
116
|
-
{isAuthenticated ? 'Logged In' : 'Logged Out'}
|
|
117
|
-
</div>
|
|
118
|
-
);
|
|
114
|
+
return <div>{isAuthenticated ? "Logged In" : "Logged Out"}</div>;
|
|
119
115
|
}
|
|
120
116
|
```
|
|
121
117
|
|
|
122
118
|
#### Privy Token Authentication
|
|
123
119
|
|
|
124
120
|
```tsx
|
|
125
|
-
import { usePearAuth } from
|
|
121
|
+
import { usePearAuth } from "@pear-protocol/hyperliquid-sdk";
|
|
126
122
|
|
|
127
123
|
function PrivyLoginComponent() {
|
|
128
124
|
const { loginWithPrivyToken, isAuthenticated } = usePearAuth();
|
|
129
125
|
|
|
130
|
-
const handlePrivyLogin = async (
|
|
126
|
+
const handlePrivyLogin = async (
|
|
127
|
+
address: string,
|
|
128
|
+
appId: string,
|
|
129
|
+
accessToken: string
|
|
130
|
+
) => {
|
|
131
131
|
await loginWithPrivyToken(address, appId, accessToken);
|
|
132
132
|
};
|
|
133
133
|
}
|
|
@@ -167,15 +167,15 @@ Authentication state and actions.
|
|
|
167
167
|
|
|
168
168
|
```tsx
|
|
169
169
|
const {
|
|
170
|
-
status,
|
|
171
|
-
isAuthenticated,
|
|
172
|
-
user,
|
|
173
|
-
error,
|
|
174
|
-
getEip712,
|
|
170
|
+
status, // AuthStatus enum
|
|
171
|
+
isAuthenticated, // boolean
|
|
172
|
+
user, // UserProfile | null
|
|
173
|
+
error, // string | null
|
|
174
|
+
getEip712, // (address: string) => Promise<EIP712MessageResponse>
|
|
175
175
|
loginWithSignedMessage, // (address, signature, timestamp) => Promise<void>
|
|
176
|
-
loginWithPrivyToken,
|
|
177
|
-
refreshTokens,
|
|
178
|
-
logout,
|
|
176
|
+
loginWithPrivyToken, // (address, appId, accessToken) => Promise<void>
|
|
177
|
+
refreshTokens, // () => Promise<any>
|
|
178
|
+
logout, // () => Promise<void>
|
|
179
179
|
} = usePearAuth();
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -185,12 +185,12 @@ Agent wallet management.
|
|
|
185
185
|
|
|
186
186
|
```tsx
|
|
187
187
|
const {
|
|
188
|
-
agentWallet,
|
|
189
|
-
isReady,
|
|
190
|
-
loading,
|
|
191
|
-
error,
|
|
188
|
+
agentWallet, // AgentWalletState
|
|
189
|
+
isReady, // boolean
|
|
190
|
+
loading, // boolean
|
|
191
|
+
error, // string | null
|
|
192
192
|
refreshAgentWalletStatus, // () => Promise<any>
|
|
193
|
-
createAgentWallet,
|
|
193
|
+
createAgentWallet, // () => Promise<any>
|
|
194
194
|
notifyAgentWalletApproved, // () => Promise<any>
|
|
195
195
|
} = usePearAgentWallet();
|
|
196
196
|
```
|
|
@@ -203,13 +203,13 @@ Manage trading positions.
|
|
|
203
203
|
|
|
204
204
|
```tsx
|
|
205
205
|
const {
|
|
206
|
-
createPosition,
|
|
207
|
-
updateRiskParameters,
|
|
208
|
-
closePosition,
|
|
209
|
-
closeAllPositions,
|
|
210
|
-
adjustPosition,
|
|
211
|
-
openPositions,
|
|
212
|
-
isLoading,
|
|
206
|
+
createPosition, // (payload) => Promise<ApiResponse<CreatePositionResponseDto>>
|
|
207
|
+
updateRiskParameters, // (positionId, payload) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>
|
|
208
|
+
closePosition, // (positionId, payload) => Promise<ApiResponse<ClosePositionResponseDto>>
|
|
209
|
+
closeAllPositions, // (payload) => Promise<ApiResponse<CloseAllPositionsResponseDto>>
|
|
210
|
+
adjustPosition, // (positionId, payload) => Promise<ApiResponse<AdjustPositionResponseDto>>
|
|
211
|
+
openPositions, // OpenPositionDto[] | null
|
|
212
|
+
isLoading, // boolean
|
|
213
213
|
} = usePosition();
|
|
214
214
|
```
|
|
215
215
|
|
|
@@ -223,13 +223,13 @@ const handleCreatePosition = async () => {
|
|
|
223
223
|
const response = await createPosition({
|
|
224
224
|
leverage: 5,
|
|
225
225
|
usdValue: 1000,
|
|
226
|
-
longAssets: [{ asset:
|
|
227
|
-
shortAssets: [{ asset:
|
|
228
|
-
orderType:
|
|
226
|
+
longAssets: [{ asset: "ETH", weight: 1 }],
|
|
227
|
+
shortAssets: [{ asset: "BTC", weight: 1 }],
|
|
228
|
+
orderType: "MARKET",
|
|
229
229
|
});
|
|
230
|
-
console.log(
|
|
230
|
+
console.log("Position created:", response.data);
|
|
231
231
|
} catch (error) {
|
|
232
|
-
console.error(
|
|
232
|
+
console.error("Failed to create position:", error);
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
```
|
|
@@ -242,11 +242,11 @@ const { closePosition } = usePosition();
|
|
|
242
242
|
const handleClosePosition = async (positionId: string) => {
|
|
243
243
|
try {
|
|
244
244
|
const response = await closePosition(positionId, {
|
|
245
|
-
orderType:
|
|
245
|
+
orderType: "MARKET",
|
|
246
246
|
});
|
|
247
|
-
console.log(
|
|
247
|
+
console.log("Position closed:", response.data);
|
|
248
248
|
} catch (error) {
|
|
249
|
-
console.error(
|
|
249
|
+
console.error("Failed to close position:", error);
|
|
250
250
|
}
|
|
251
251
|
};
|
|
252
252
|
```
|
|
@@ -259,11 +259,11 @@ Manage orders (LIMIT, TP/SL, TWAP).
|
|
|
259
259
|
|
|
260
260
|
```tsx
|
|
261
261
|
const {
|
|
262
|
-
adjustOrder,
|
|
263
|
-
cancelOrder,
|
|
264
|
-
cancelTwapOrder,
|
|
265
|
-
openOrders,
|
|
266
|
-
isLoading,
|
|
262
|
+
adjustOrder, // (orderId, payload) => Promise<ApiResponse<AdjustOrderResponseDto>>
|
|
263
|
+
cancelOrder, // (orderId) => Promise<ApiResponse<CancelOrderResponseDto>>
|
|
264
|
+
cancelTwapOrder, // (orderId) => Promise<ApiResponse<CancelTwapResponseDto>>
|
|
265
|
+
openOrders, // OpenLimitOrderDto[] | null
|
|
266
|
+
isLoading, // boolean
|
|
267
267
|
} = useOrders();
|
|
268
268
|
```
|
|
269
269
|
|
|
@@ -275,9 +275,9 @@ const { cancelOrder } = useOrders();
|
|
|
275
275
|
const handleCancelOrder = async (orderId: string) => {
|
|
276
276
|
try {
|
|
277
277
|
await cancelOrder(orderId);
|
|
278
|
-
console.log(
|
|
278
|
+
console.log("Order cancelled successfully");
|
|
279
279
|
} catch (error) {
|
|
280
|
-
console.error(
|
|
280
|
+
console.error("Failed to cancel order:", error);
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
283
|
```
|
|
@@ -316,7 +316,7 @@ const { data, isLoading } = useAccountSummary();
|
|
|
316
316
|
Access real-time market data from Zustand store.
|
|
317
317
|
|
|
318
318
|
```tsx
|
|
319
|
-
import { useMarketData } from
|
|
319
|
+
import { useMarketData } from "@pear-protocol/hyperliquid-sdk";
|
|
320
320
|
|
|
321
321
|
function MarketDataComponent() {
|
|
322
322
|
const activeAssets = useMarketData((state) => state.activeAssets);
|
|
@@ -325,8 +325,8 @@ function MarketDataComponent() {
|
|
|
325
325
|
<div>
|
|
326
326
|
{activeAssets?.active.map((asset, idx) => (
|
|
327
327
|
<div key={idx}>
|
|
328
|
-
Long: {asset.longAssets.map(a => a.asset).join(
|
|
329
|
-
|
|
328
|
+
Long: {asset.longAssets.map((a) => a.asset).join(", ")} vs Short:{" "}
|
|
329
|
+
{asset.shortAssets.map((a) => a.asset).join(", ")}
|
|
330
330
|
</div>
|
|
331
331
|
))}
|
|
332
332
|
</div>
|
|
@@ -339,16 +339,16 @@ function MarketDataComponent() {
|
|
|
339
339
|
Fetch and manage historical price data for tokens.
|
|
340
340
|
|
|
341
341
|
```tsx
|
|
342
|
-
import { useHistoricalPriceData } from
|
|
342
|
+
import { useHistoricalPriceData } from "@pear-protocol/hyperliquid-sdk";
|
|
343
343
|
|
|
344
344
|
function ChartComponent() {
|
|
345
345
|
const { fetchHistoricalData, getTokenData } = useHistoricalPriceData();
|
|
346
346
|
|
|
347
347
|
useEffect(() => {
|
|
348
|
-
fetchHistoricalData(
|
|
348
|
+
fetchHistoricalData("ETH", "1d"); // 1 day range
|
|
349
349
|
}, []);
|
|
350
350
|
|
|
351
|
-
const ethData = getTokenData(
|
|
351
|
+
const ethData = getTokenData("ETH");
|
|
352
352
|
}
|
|
353
353
|
```
|
|
354
354
|
|
|
@@ -357,13 +357,16 @@ function ChartComponent() {
|
|
|
357
357
|
Get candle data for basket (multi-asset) positions.
|
|
358
358
|
|
|
359
359
|
```tsx
|
|
360
|
-
import { useBasketCandles } from
|
|
360
|
+
import { useBasketCandles } from "@pear-protocol/hyperliquid-sdk";
|
|
361
361
|
|
|
362
362
|
function BasketChartComponent() {
|
|
363
363
|
const { candles, isLoading, error } = useBasketCandles({
|
|
364
|
-
longAssets: [
|
|
365
|
-
|
|
366
|
-
|
|
364
|
+
longAssets: [
|
|
365
|
+
{ symbol: "ETH", weight: 0.5 },
|
|
366
|
+
{ symbol: "BTC", weight: 0.5 },
|
|
367
|
+
],
|
|
368
|
+
shortAssets: [{ symbol: "SOL", weight: 1 }],
|
|
369
|
+
interval: "1h",
|
|
367
370
|
lookbackHours: 24,
|
|
368
371
|
});
|
|
369
372
|
}
|
|
@@ -374,12 +377,12 @@ function BasketChartComponent() {
|
|
|
374
377
|
Get metadata for selected tokens including prices, funding, and leverage info.
|
|
375
378
|
|
|
376
379
|
```tsx
|
|
377
|
-
import { useTokenSelectionMetadata } from
|
|
380
|
+
import { useTokenSelectionMetadata } from "@pear-protocol/hyperliquid-sdk";
|
|
378
381
|
|
|
379
382
|
function TokenSelector() {
|
|
380
383
|
const { getMetadata, isLoading } = useTokenSelectionMetadata();
|
|
381
384
|
|
|
382
|
-
const ethMetadata = getMetadata(
|
|
385
|
+
const ethMetadata = getMetadata("ETH");
|
|
383
386
|
// ethMetadata: { currentPrice, priceChange24hPercent, maxLeverage, ... }
|
|
384
387
|
}
|
|
385
388
|
```
|
|
@@ -401,17 +404,17 @@ Access HyperLiquid native WebSocket connection (managed by provider).
|
|
|
401
404
|
Access TWAP (Time-Weighted Average Price) order monitoring.
|
|
402
405
|
|
|
403
406
|
```tsx
|
|
404
|
-
import { useTwap } from
|
|
407
|
+
import { useTwap } from "@pear-protocol/hyperliquid-sdk";
|
|
405
408
|
|
|
406
409
|
function TwapMonitor() {
|
|
407
410
|
const { twapOrders, isLoading } = useTwap();
|
|
408
411
|
|
|
409
412
|
return (
|
|
410
413
|
<div>
|
|
411
|
-
{twapOrders?.map(order => (
|
|
414
|
+
{twapOrders?.map((order) => (
|
|
412
415
|
<div key={order.orderId}>
|
|
413
416
|
Status: {order.status}
|
|
414
|
-
Progress: {order.filledUsdValue / order.totalUsdValue * 100}%
|
|
417
|
+
Progress: {(order.filledUsdValue / order.totalUsdValue) * 100}%
|
|
415
418
|
</div>
|
|
416
419
|
))}
|
|
417
420
|
</div>
|
|
@@ -426,14 +429,15 @@ function TwapMonitor() {
|
|
|
426
429
|
Access user notifications.
|
|
427
430
|
|
|
428
431
|
```tsx
|
|
429
|
-
import { useNotifications } from
|
|
432
|
+
import { useNotifications } from "@pear-protocol/hyperliquid-sdk";
|
|
430
433
|
|
|
431
434
|
function NotificationCenter() {
|
|
432
|
-
const { notifications, isLoading, markAsRead, markAllAsRead } =
|
|
435
|
+
const { notifications, isLoading, markAsRead, markAllAsRead } =
|
|
436
|
+
useNotifications();
|
|
433
437
|
|
|
434
438
|
return (
|
|
435
439
|
<div>
|
|
436
|
-
{notifications?.map(notif => (
|
|
440
|
+
{notifications?.map((notif) => (
|
|
437
441
|
<div key={notif.id} onClick={() => markAsRead(notif.id)}>
|
|
438
442
|
{notif.category}: {JSON.stringify(notif.parameters)}
|
|
439
443
|
</div>
|
|
@@ -450,7 +454,7 @@ function NotificationCenter() {
|
|
|
450
454
|
Calculate account summary with real-time data.
|
|
451
455
|
|
|
452
456
|
```tsx
|
|
453
|
-
import { AccountSummaryCalculator } from
|
|
457
|
+
import { AccountSummaryCalculator } from "@pear-protocol/hyperliquid-sdk";
|
|
454
458
|
|
|
455
459
|
const calculator = new AccountSummaryCalculator(webData2);
|
|
456
460
|
const summary = calculator.calculateAccountSummary(
|
|
@@ -466,7 +470,7 @@ const summary = calculator.calculateAccountSummary(
|
|
|
466
470
|
Detect position conflicts for new trades.
|
|
467
471
|
|
|
468
472
|
```tsx
|
|
469
|
-
import { ConflictDetector } from
|
|
473
|
+
import { ConflictDetector } from "@pear-protocol/hyperliquid-sdk";
|
|
470
474
|
|
|
471
475
|
const conflicts = ConflictDetector.detectConflicts(
|
|
472
476
|
longTokens,
|
|
@@ -480,10 +484,10 @@ const conflicts = ConflictDetector.detectConflicts(
|
|
|
480
484
|
Extract token metadata from WebSocket data.
|
|
481
485
|
|
|
482
486
|
```tsx
|
|
483
|
-
import { TokenMetadataExtractor } from
|
|
487
|
+
import { TokenMetadataExtractor } from "@pear-protocol/hyperliquid-sdk";
|
|
484
488
|
|
|
485
489
|
const metadata = TokenMetadataExtractor.extractMetadata(
|
|
486
|
-
|
|
490
|
+
"ETH",
|
|
487
491
|
webData2,
|
|
488
492
|
allMids,
|
|
489
493
|
activeAssetData
|
|
@@ -501,15 +505,15 @@ import {
|
|
|
501
505
|
closePosition,
|
|
502
506
|
adjustOrder,
|
|
503
507
|
cancelOrder,
|
|
504
|
-
} from
|
|
508
|
+
} from "@pear-protocol/hyperliquid-sdk";
|
|
505
509
|
|
|
506
510
|
// All client functions require baseUrl and accessToken
|
|
507
511
|
const response = await createPosition(baseUrl, accessToken, {
|
|
508
512
|
leverage: 5,
|
|
509
513
|
usdValue: 1000,
|
|
510
|
-
longAssets: [{ asset:
|
|
511
|
-
shortAssets: [{ asset:
|
|
512
|
-
orderType:
|
|
514
|
+
longAssets: [{ asset: "ETH", weight: 1 }],
|
|
515
|
+
shortAssets: [{ asset: "BTC", weight: 1 }],
|
|
516
|
+
orderType: "MARKET",
|
|
513
517
|
});
|
|
514
518
|
```
|
|
515
519
|
|
|
@@ -527,7 +531,7 @@ import type {
|
|
|
527
531
|
CandleInterval,
|
|
528
532
|
TokenMetadata,
|
|
529
533
|
// ... and many more
|
|
530
|
-
} from
|
|
534
|
+
} from "@pear-protocol/hyperliquid-sdk";
|
|
531
535
|
```
|
|
532
536
|
|
|
533
537
|
## WebSocket Data Flow
|
|
@@ -553,7 +557,7 @@ try {
|
|
|
553
557
|
await createPosition(payload);
|
|
554
558
|
} catch (error) {
|
|
555
559
|
if (error instanceof Error) {
|
|
556
|
-
console.error(
|
|
560
|
+
console.error("Error:", error.message);
|
|
557
561
|
}
|
|
558
562
|
}
|
|
559
563
|
```
|
|
@@ -581,14 +585,14 @@ When using the SDK, you may want to configure different environments:
|
|
|
581
585
|
### Complete Trading Component
|
|
582
586
|
|
|
583
587
|
```tsx
|
|
584
|
-
import { useState } from
|
|
588
|
+
import { useState } from "react";
|
|
585
589
|
import {
|
|
586
590
|
usePearAuth,
|
|
587
591
|
usePearHyperliquid,
|
|
588
592
|
usePosition,
|
|
589
593
|
useOrders,
|
|
590
594
|
useAccountSummary,
|
|
591
|
-
} from
|
|
595
|
+
} from "@pear-protocol/hyperliquid-sdk";
|
|
592
596
|
|
|
593
597
|
function TradingDashboard() {
|
|
594
598
|
const { address, setAddress, isConnected } = usePearHyperliquid();
|
|
@@ -602,12 +606,12 @@ function TradingDashboard() {
|
|
|
602
606
|
await createPosition({
|
|
603
607
|
leverage: 3,
|
|
604
608
|
usdValue: 500,
|
|
605
|
-
longAssets: [{ asset:
|
|
606
|
-
shortAssets: [{ asset:
|
|
607
|
-
orderType:
|
|
609
|
+
longAssets: [{ asset: "ETH", weight: 1 }],
|
|
610
|
+
shortAssets: [{ asset: "BTC", weight: 1 }],
|
|
611
|
+
orderType: "MARKET",
|
|
608
612
|
});
|
|
609
613
|
} catch (error) {
|
|
610
|
-
console.error(
|
|
614
|
+
console.error("Failed to create position:", error);
|
|
611
615
|
}
|
|
612
616
|
};
|
|
613
617
|
|
|
@@ -617,24 +621,31 @@ function TradingDashboard() {
|
|
|
617
621
|
|
|
618
622
|
<div>
|
|
619
623
|
<h2>Account</h2>
|
|
620
|
-
<p>Address: {address ||
|
|
621
|
-
<p>Status: {isAuthenticated ?
|
|
622
|
-
<p>WebSocket: {isConnected ?
|
|
624
|
+
<p>Address: {address || "Not connected"}</p>
|
|
625
|
+
<p>Status: {isAuthenticated ? "Authenticated" : "Not authenticated"}</p>
|
|
626
|
+
<p>WebSocket: {isConnected ? "Connected" : "Disconnected"}</p>
|
|
623
627
|
</div>
|
|
624
628
|
|
|
625
629
|
<div>
|
|
626
630
|
<h2>Account Summary</h2>
|
|
627
|
-
<p>
|
|
631
|
+
<p>
|
|
632
|
+
Account Value: $
|
|
633
|
+
{accountSummary?.balanceSummary.marginSummary.accountValue}
|
|
634
|
+
</p>
|
|
628
635
|
<p>Withdrawable: ${accountSummary?.balanceSummary.withdrawable}</p>
|
|
629
636
|
</div>
|
|
630
637
|
|
|
631
638
|
<div>
|
|
632
639
|
<h2>Open Positions</h2>
|
|
633
|
-
{openPositions?.map(pos => (
|
|
640
|
+
{openPositions?.map((pos) => (
|
|
634
641
|
<div key={pos.positionId}>
|
|
635
642
|
<p>PNL: ${pos.unrealizedPnl.toFixed(2)}</p>
|
|
636
643
|
<p>Value: ${pos.positionValue.toFixed(2)}</p>
|
|
637
|
-
<button
|
|
644
|
+
<button
|
|
645
|
+
onClick={() =>
|
|
646
|
+
closePosition(pos.positionId, { orderType: "MARKET" })
|
|
647
|
+
}
|
|
648
|
+
>
|
|
638
649
|
Close
|
|
639
650
|
</button>
|
|
640
651
|
</div>
|
|
@@ -643,7 +654,7 @@ function TradingDashboard() {
|
|
|
643
654
|
|
|
644
655
|
<div>
|
|
645
656
|
<h2>Open Orders</h2>
|
|
646
|
-
{openOrders?.map(order => (
|
|
657
|
+
{openOrders?.map((order) => (
|
|
647
658
|
<div key={order.orderId}>
|
|
648
659
|
<p>Type: {order.orderType}</p>
|
|
649
660
|
<p>Value: ${order.usdValue}</p>
|
|
@@ -652,9 +663,7 @@ function TradingDashboard() {
|
|
|
652
663
|
))}
|
|
653
664
|
</div>
|
|
654
665
|
|
|
655
|
-
<button onClick={handleCreatePosition}>
|
|
656
|
-
Create New Position
|
|
657
|
-
</button>
|
|
666
|
+
<button onClick={handleCreatePosition}>Create New Position</button>
|
|
658
667
|
</div>
|
|
659
668
|
);
|
|
660
669
|
}
|
|
@@ -669,7 +678,7 @@ import {
|
|
|
669
678
|
useMarketData,
|
|
670
679
|
useTokenSelectionMetadata,
|
|
671
680
|
useHyperliquidWebSocket,
|
|
672
|
-
} from
|
|
681
|
+
} from "@pear-protocol/hyperliquid-sdk";
|
|
673
682
|
|
|
674
683
|
function MarketOverview() {
|
|
675
684
|
const activeAssets = useMarketData((state) => state.activeAssets);
|
|
@@ -684,7 +693,9 @@ function MarketOverview() {
|
|
|
684
693
|
|
|
685
694
|
return (
|
|
686
695
|
<div key={idx}>
|
|
687
|
-
<p>
|
|
696
|
+
<p>
|
|
697
|
+
{longAsset}: {metadata?.priceChange24hPercent.toFixed(2)}%
|
|
698
|
+
</p>
|
|
688
699
|
</div>
|
|
689
700
|
);
|
|
690
701
|
})}
|
|
@@ -696,7 +707,9 @@ function MarketOverview() {
|
|
|
696
707
|
|
|
697
708
|
return (
|
|
698
709
|
<div key={idx}>
|
|
699
|
-
<p>
|
|
710
|
+
<p>
|
|
711
|
+
{shortAsset}: {metadata?.priceChange24hPercent.toFixed(2)}%
|
|
712
|
+
</p>
|
|
700
713
|
</div>
|
|
701
714
|
);
|
|
702
715
|
})}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ApiResponse } from '../types';
|
|
2
|
+
export type PortfolioInterval = '1d' | '1w' | '1m' | '1y' | 'all';
|
|
3
|
+
export interface PortfolioBucketDto {
|
|
4
|
+
periodStart: string;
|
|
5
|
+
periodEnd: string;
|
|
6
|
+
volume: number;
|
|
7
|
+
openInterest: number;
|
|
8
|
+
winningTradesCount: number;
|
|
9
|
+
winningTradesUsd: number;
|
|
10
|
+
losingTradesCount: number;
|
|
11
|
+
losingTradesUsd: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PortfolioOverallDto {
|
|
14
|
+
totalWinningTradesCount: number;
|
|
15
|
+
totalLosingTradesCount: number;
|
|
16
|
+
totalWinningUsd: number;
|
|
17
|
+
totalLosingUsd: number;
|
|
18
|
+
currentOpenInterest: number;
|
|
19
|
+
currentTotalVolume: number;
|
|
20
|
+
unrealizedPnl: number;
|
|
21
|
+
totalTrades: number;
|
|
22
|
+
}
|
|
23
|
+
export interface PortfolioIntervalsDto {
|
|
24
|
+
oneDay: PortfolioBucketDto[];
|
|
25
|
+
oneWeek: PortfolioBucketDto[];
|
|
26
|
+
oneMonth: PortfolioBucketDto[];
|
|
27
|
+
oneYear: PortfolioBucketDto[];
|
|
28
|
+
all: PortfolioBucketDto[];
|
|
29
|
+
}
|
|
30
|
+
export interface PortfolioResponseDto {
|
|
31
|
+
intervals: PortfolioIntervalsDto;
|
|
32
|
+
overall: PortfolioOverallDto;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get portfolio summary buckets and overall metrics
|
|
36
|
+
* Returns bucketed volume, open interest snapshot, win/loss trade counts, and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
|
|
37
|
+
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
38
|
+
*/
|
|
39
|
+
export declare function getPortfolio(baseUrl: string, accessToken: string): Promise<ApiResponse<PortfolioResponseDto>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ApiResponse } from
|
|
2
|
-
import type { CancelTwapResponseDto } from
|
|
3
|
-
export type ExecutionType =
|
|
4
|
-
export type TpSlThresholdType =
|
|
1
|
+
import type { ApiResponse } from "../types";
|
|
2
|
+
import type { CancelTwapResponseDto } from "./orders";
|
|
3
|
+
export type ExecutionType = "MARKET" | "LIMIT" | "TWAP" | "LADDER" | "LIMIT_BTCDOM";
|
|
4
|
+
export type TpSlThresholdType = "PERCENTAGE" | "DOLLAR" | "POSITION_VALUE";
|
|
5
5
|
export interface PairAssetInput {
|
|
6
6
|
asset: string;
|
|
7
7
|
weight?: number;
|
|
@@ -23,7 +23,7 @@ export interface CreatePositionRequestInput {
|
|
|
23
23
|
longAssets?: PairAssetInput[];
|
|
24
24
|
shortAssets?: PairAssetInput[];
|
|
25
25
|
triggerValue?: number;
|
|
26
|
-
direction?:
|
|
26
|
+
direction?: "MORE_THAN" | "LESS_THAN";
|
|
27
27
|
twapDuration?: number;
|
|
28
28
|
twapIntervalSeconds?: number;
|
|
29
29
|
randomizeExecution?: boolean;
|
|
@@ -31,10 +31,10 @@ export interface CreatePositionRequestInput {
|
|
|
31
31
|
takeProfit?: TpSlThresholdInput | null;
|
|
32
32
|
stopLoss?: TpSlThresholdInput | null;
|
|
33
33
|
}
|
|
34
|
-
export type PositionResponseStatus =
|
|
34
|
+
export type PositionResponseStatus = "SUCCESS" | "FAILED" | "PENDING" | "PARTIALLY_FILLED" | "OPEN";
|
|
35
35
|
export interface PositionAssetSummaryDto {
|
|
36
36
|
asset: string;
|
|
37
|
-
side:
|
|
37
|
+
side: "LONG" | "SHORT";
|
|
38
38
|
size: number;
|
|
39
39
|
entryRatio: number;
|
|
40
40
|
usdValue: number;
|
|
@@ -53,6 +53,7 @@ export interface CreatePositionResponseDto {
|
|
|
53
53
|
/**
|
|
54
54
|
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
55
55
|
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
56
|
+
* @throws MinimumPositionSizeError if any asset has less than $11 USD value
|
|
56
57
|
*/
|
|
57
58
|
export declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
58
59
|
export interface UpdateRiskParametersRequestInput {
|
|
@@ -66,7 +67,7 @@ export interface UpdateRiskParametersResponseDto {
|
|
|
66
67
|
updatedAt: string;
|
|
67
68
|
}
|
|
68
69
|
export declare function updateRiskParameters(baseUrl: string, accessToken: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
69
|
-
export type CloseExecutionType =
|
|
70
|
+
export type CloseExecutionType = "MARKET" | "TWAP";
|
|
70
71
|
export interface ClosePositionRequestInput {
|
|
71
72
|
executionType: CloseExecutionType;
|
|
72
73
|
twapDuration?: number;
|
|
@@ -89,8 +90,8 @@ export interface CloseAllPositionsResponseDto {
|
|
|
89
90
|
results: CloseAllPositionsResultDto[];
|
|
90
91
|
}
|
|
91
92
|
export declare function closeAllPositions(baseUrl: string, accessToken: string, payload: ClosePositionRequestInput): Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
92
|
-
export type AdjustExecutionType =
|
|
93
|
-
export type PositionAdjustmentType =
|
|
93
|
+
export type AdjustExecutionType = "MARKET" | "LIMIT";
|
|
94
|
+
export type PositionAdjustmentType = "REDUCE" | "INCREASE";
|
|
94
95
|
export interface AdjustPositionRequestInput {
|
|
95
96
|
adjustmentType: PositionAdjustmentType;
|
|
96
97
|
adjustmentSize: number;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export * from './useTokenSelectionMetadata';
|
|
|
6
6
|
export * from './useHistoricalPriceData';
|
|
7
7
|
export * from './useBasketCandles';
|
|
8
8
|
export * from './usePerformanceOverlays';
|
|
9
|
-
export * from './useAuth';
|
|
10
9
|
export * from './useAgentWallet';
|
|
11
10
|
export * from './useAutoSyncFills';
|
|
12
11
|
export * from './usePosition';
|
|
@@ -15,3 +14,4 @@ export * from './useTwap';
|
|
|
15
14
|
export * from './useNotifications';
|
|
16
15
|
export * from './useMarketData';
|
|
17
16
|
export * from './useWatchlist';
|
|
17
|
+
export * from './usePortfolio';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PortfolioResponseDto } from '../clients/portfolio';
|
|
2
|
+
export interface UsePortfolioResult {
|
|
3
|
+
data: PortfolioResponseDto | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
error: Error | null;
|
|
6
|
+
refetch: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Hook to fetch and manage portfolio data
|
|
10
|
+
* Returns bucketed volume, open interest snapshot, win/loss trade counts,
|
|
11
|
+
* and overall metrics filtered to PEAR fills (cloid LIKE 0x50454152%)
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePortfolio(): UsePortfolioResult;
|