@pear-protocol/hyperliquid-sdk 0.0.43 → 0.0.45
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/positions.d.ts +11 -10
- package/dist/clients/watchlist.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useMarketData.d.ts +1 -0
- package/dist/hooks/useWatchlist.d.ts +6 -0
- package/dist/index.d.ts +74 -10
- package/dist/index.js +194 -15
- package/dist/types.d.ts +13 -0
- package/dist/utils/position-validator.d.ts +41 -0
- package/package.json +1 -1
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
|
})}
|
|
@@ -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;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { ApiResponse, ToggleWatchlistResponseDto, WatchlistAssetDto } from '../types';
|
|
2
|
+
export declare function toggleWatchlist(baseUrl: string, accessToken: string, longAssets: WatchlistAssetDto[], shortAssets: WatchlistAssetDto[]): Promise<ApiResponse<ToggleWatchlistResponseDto>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare const useActiveBaskets: () => ActiveAssetGroupItem[];
|
|
|
4
4
|
export declare const useTopGainers: (limit?: number) => ActiveAssetGroupItem[];
|
|
5
5
|
export declare const useTopLosers: (limit?: number) => ActiveAssetGroupItem[];
|
|
6
6
|
export declare const useHighlightedBaskets: () => ActiveAssetGroupItem[];
|
|
7
|
+
export declare const useWatchlistBaskets: () => ActiveAssetGroupItem[];
|
|
7
8
|
export declare const useFindBasket: (longs: string[], shorts: string[]) => ActiveAssetGroupItem | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ApiResponse, ToggleWatchlistResponseDto, WatchlistAssetDto, ActiveAssetGroupItem } from '../types';
|
|
2
|
+
export declare function useWatchlist(): {
|
|
3
|
+
readonly watchlists: ActiveAssetGroupItem[] | null;
|
|
4
|
+
readonly isLoading: boolean;
|
|
5
|
+
readonly toggle: (longAssets: WatchlistAssetDto[], shortAssets: WatchlistAssetDto[]) => Promise<ApiResponse<ToggleWatchlistResponseDto>>;
|
|
6
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,18 @@ interface WebSocketDataMessage<T = unknown> {
|
|
|
53
53
|
channel: WebSocketChannel;
|
|
54
54
|
data: T;
|
|
55
55
|
}
|
|
56
|
+
interface WatchlistAssetDto {
|
|
57
|
+
asset: string;
|
|
58
|
+
weight: number;
|
|
59
|
+
}
|
|
60
|
+
interface WatchlistItemDto {
|
|
61
|
+
id: string;
|
|
62
|
+
longAssets: WatchlistAssetDto[];
|
|
63
|
+
shortAssets: WatchlistAssetDto[];
|
|
64
|
+
}
|
|
65
|
+
interface ToggleWatchlistResponseDto {
|
|
66
|
+
items: WatchlistItemDto[];
|
|
67
|
+
}
|
|
56
68
|
type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'TRADE_CLOSED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
|
|
57
69
|
interface NotificationDto {
|
|
58
70
|
id: string;
|
|
@@ -532,6 +544,7 @@ interface ActiveAssetsResponse {
|
|
|
532
544
|
topGainers: ActiveAssetGroupItem[];
|
|
533
545
|
topLosers: ActiveAssetGroupItem[];
|
|
534
546
|
highlighted: ActiveAssetGroupItem[];
|
|
547
|
+
watchlist: ActiveAssetGroupItem[];
|
|
535
548
|
}
|
|
536
549
|
/**
|
|
537
550
|
* Candle interval options
|
|
@@ -859,8 +872,8 @@ interface CancelTwapResponseDto {
|
|
|
859
872
|
}
|
|
860
873
|
declare function cancelTwapOrder(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
861
874
|
|
|
862
|
-
type ExecutionType =
|
|
863
|
-
type TpSlThresholdType =
|
|
875
|
+
type ExecutionType = "MARKET" | "LIMIT" | "TWAP" | "LADDER" | "LIMIT_BTCDOM";
|
|
876
|
+
type TpSlThresholdType = "PERCENTAGE" | "DOLLAR" | "POSITION_VALUE";
|
|
864
877
|
interface PairAssetInput {
|
|
865
878
|
asset: string;
|
|
866
879
|
weight?: number;
|
|
@@ -882,7 +895,7 @@ interface CreatePositionRequestInput {
|
|
|
882
895
|
longAssets?: PairAssetInput[];
|
|
883
896
|
shortAssets?: PairAssetInput[];
|
|
884
897
|
triggerValue?: number;
|
|
885
|
-
direction?:
|
|
898
|
+
direction?: "MORE_THAN" | "LESS_THAN";
|
|
886
899
|
twapDuration?: number;
|
|
887
900
|
twapIntervalSeconds?: number;
|
|
888
901
|
randomizeExecution?: boolean;
|
|
@@ -890,10 +903,10 @@ interface CreatePositionRequestInput {
|
|
|
890
903
|
takeProfit?: TpSlThresholdInput | null;
|
|
891
904
|
stopLoss?: TpSlThresholdInput | null;
|
|
892
905
|
}
|
|
893
|
-
type PositionResponseStatus =
|
|
906
|
+
type PositionResponseStatus = "SUCCESS" | "FAILED" | "PENDING" | "PARTIALLY_FILLED" | "OPEN";
|
|
894
907
|
interface PositionAssetSummaryDto {
|
|
895
908
|
asset: string;
|
|
896
|
-
side:
|
|
909
|
+
side: "LONG" | "SHORT";
|
|
897
910
|
size: number;
|
|
898
911
|
entryRatio: number;
|
|
899
912
|
usdValue: number;
|
|
@@ -912,6 +925,7 @@ interface CreatePositionResponseDto {
|
|
|
912
925
|
/**
|
|
913
926
|
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
914
927
|
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
928
|
+
* @throws MinimumPositionSizeError if any asset has less than $11 USD value
|
|
915
929
|
*/
|
|
916
930
|
declare function createPosition(baseUrl: string, accessToken: string, payload: CreatePositionRequestInput): Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
917
931
|
interface UpdateRiskParametersRequestInput {
|
|
@@ -925,7 +939,7 @@ interface UpdateRiskParametersResponseDto {
|
|
|
925
939
|
updatedAt: string;
|
|
926
940
|
}
|
|
927
941
|
declare function updateRiskParameters(baseUrl: string, accessToken: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
928
|
-
type CloseExecutionType =
|
|
942
|
+
type CloseExecutionType = "MARKET" | "TWAP";
|
|
929
943
|
interface ClosePositionRequestInput {
|
|
930
944
|
executionType: CloseExecutionType;
|
|
931
945
|
twapDuration?: number;
|
|
@@ -948,8 +962,8 @@ interface CloseAllPositionsResponseDto {
|
|
|
948
962
|
results: CloseAllPositionsResultDto[];
|
|
949
963
|
}
|
|
950
964
|
declare function closeAllPositions(baseUrl: string, accessToken: string, payload: ClosePositionRequestInput): Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
951
|
-
type AdjustExecutionType =
|
|
952
|
-
type PositionAdjustmentType =
|
|
965
|
+
type AdjustExecutionType = "MARKET" | "LIMIT";
|
|
966
|
+
type PositionAdjustmentType = "REDUCE" | "INCREASE";
|
|
953
967
|
interface AdjustPositionRequestInput {
|
|
954
968
|
adjustmentType: PositionAdjustmentType;
|
|
955
969
|
adjustmentSize: number;
|
|
@@ -1011,8 +1025,15 @@ declare const useActiveBaskets: () => ActiveAssetGroupItem[];
|
|
|
1011
1025
|
declare const useTopGainers: (limit?: number) => ActiveAssetGroupItem[];
|
|
1012
1026
|
declare const useTopLosers: (limit?: number) => ActiveAssetGroupItem[];
|
|
1013
1027
|
declare const useHighlightedBaskets: () => ActiveAssetGroupItem[];
|
|
1028
|
+
declare const useWatchlistBaskets: () => ActiveAssetGroupItem[];
|
|
1014
1029
|
declare const useFindBasket: (longs: string[], shorts: string[]) => ActiveAssetGroupItem | undefined;
|
|
1015
1030
|
|
|
1031
|
+
declare function useWatchlist(): {
|
|
1032
|
+
readonly watchlists: ActiveAssetGroupItem[] | null;
|
|
1033
|
+
readonly isLoading: boolean;
|
|
1034
|
+
readonly toggle: (longAssets: WatchlistAssetDto[], shortAssets: WatchlistAssetDto[]) => Promise<ApiResponse<ToggleWatchlistResponseDto>>;
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1016
1037
|
interface UseHyperliquidWebSocketProps {
|
|
1017
1038
|
wsUrl: string;
|
|
1018
1039
|
address: string | null;
|
|
@@ -1047,6 +1068,8 @@ declare function markNotificationReadById(baseUrl: string, accessToken: string,
|
|
|
1047
1068
|
updated: number;
|
|
1048
1069
|
}>>;
|
|
1049
1070
|
|
|
1071
|
+
declare function toggleWatchlist(baseUrl: string, accessToken: string, longAssets: WatchlistAssetDto[], shortAssets: WatchlistAssetDto[]): Promise<ApiResponse<ToggleWatchlistResponseDto>>;
|
|
1072
|
+
|
|
1050
1073
|
/**
|
|
1051
1074
|
* Account summary calculation utility class
|
|
1052
1075
|
*/
|
|
@@ -1149,7 +1172,48 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1149
1172
|
*/
|
|
1150
1173
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1151
1174
|
|
|
1175
|
+
/**
|
|
1176
|
+
* Minimum USD value required per asset when creating a position
|
|
1177
|
+
*/
|
|
1178
|
+
declare const MINIMUM_ASSET_USD_VALUE = 11;
|
|
1179
|
+
/**
|
|
1180
|
+
* Validation error for minimum position size
|
|
1181
|
+
*/
|
|
1182
|
+
declare class MinimumPositionSizeError extends Error {
|
|
1183
|
+
assetName: string;
|
|
1184
|
+
assetValue: number;
|
|
1185
|
+
minimumRequired: number;
|
|
1186
|
+
constructor(assetName: string, assetValue: number, minimumRequired: number);
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Validates that each asset in a position has at least the minimum USD value
|
|
1190
|
+
* @param usdValue Total USD value for the position
|
|
1191
|
+
* @param longAssets Array of long assets with weights
|
|
1192
|
+
* @param shortAssets Array of short assets with weights
|
|
1193
|
+
* @throws MinimumPositionSizeError if any asset has less than the minimum USD value
|
|
1194
|
+
*/
|
|
1195
|
+
declare function validateMinimumAssetSize(usdValue: number, longAssets?: PairAssetInput[], shortAssets?: PairAssetInput[]): void;
|
|
1196
|
+
/**
|
|
1197
|
+
* Calculates the minimum USD value required for a position based on the number of assets
|
|
1198
|
+
* @param longAssets Array of long assets
|
|
1199
|
+
* @param shortAssets Array of short assets
|
|
1200
|
+
* @returns The minimum total USD value required
|
|
1201
|
+
*/
|
|
1202
|
+
declare function calculateMinimumPositionValue(longAssets?: PairAssetInput[], shortAssets?: PairAssetInput[]): number;
|
|
1203
|
+
/**
|
|
1204
|
+
* Validates and provides a user-friendly error message with suggestions
|
|
1205
|
+
* @param usdValue Total USD value for the position
|
|
1206
|
+
* @param longAssets Array of long assets with weights
|
|
1207
|
+
* @param shortAssets Array of short assets with weights
|
|
1208
|
+
* @returns Validation result with success flag and optional error message
|
|
1209
|
+
*/
|
|
1210
|
+
declare function validatePositionSize(usdValue: number, longAssets?: PairAssetInput[], shortAssets?: PairAssetInput[]): {
|
|
1211
|
+
valid: boolean;
|
|
1212
|
+
error?: string;
|
|
1213
|
+
minimumRequired?: number;
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1152
1216
|
declare const useMarketData: any;
|
|
1153
1217
|
|
|
1154
|
-
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWebData };
|
|
1155
|
-
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1218
|
+
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1219
|
+
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -2459,7 +2459,7 @@ const useMarketData = create((set) => ({
|
|
|
2459
2459
|
|
|
2460
2460
|
const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
2461
2461
|
const { setTradeHistories, setRawOpenPositions, setOpenOrders, setAccountSummary, setTwapDetails, setNotifications, clean, } = useUserData();
|
|
2462
|
-
const { setMarketData
|
|
2462
|
+
const { setMarketData } = useMarketData();
|
|
2463
2463
|
const [lastError, setLastError] = useState(null);
|
|
2464
2464
|
const [lastSubscribedAddress, setLastSubscribedAddress] = useState(null);
|
|
2465
2465
|
// WebSocket connection
|
|
@@ -8364,15 +8364,109 @@ function useAutoSyncFills(options) {
|
|
|
8364
8364
|
};
|
|
8365
8365
|
}
|
|
8366
8366
|
|
|
8367
|
+
/**
|
|
8368
|
+
* Minimum USD value required per asset when creating a position
|
|
8369
|
+
*/
|
|
8370
|
+
const MINIMUM_ASSET_USD_VALUE = 11;
|
|
8371
|
+
/**
|
|
8372
|
+
* Validation error for minimum position size
|
|
8373
|
+
*/
|
|
8374
|
+
class MinimumPositionSizeError extends Error {
|
|
8375
|
+
constructor(assetName, assetValue, minimumRequired) {
|
|
8376
|
+
super(`Asset "${assetName}" has a USD value of $${assetValue.toFixed(2)}, which is below the minimum required value of $${minimumRequired.toFixed(2)}`);
|
|
8377
|
+
this.assetName = assetName;
|
|
8378
|
+
this.assetValue = assetValue;
|
|
8379
|
+
this.minimumRequired = minimumRequired;
|
|
8380
|
+
this.name = "MinimumPositionSizeError";
|
|
8381
|
+
}
|
|
8382
|
+
}
|
|
8383
|
+
/**
|
|
8384
|
+
* Validates that each asset in a position has at least the minimum USD value
|
|
8385
|
+
* @param usdValue Total USD value for the position
|
|
8386
|
+
* @param longAssets Array of long assets with weights
|
|
8387
|
+
* @param shortAssets Array of short assets with weights
|
|
8388
|
+
* @throws MinimumPositionSizeError if any asset has less than the minimum USD value
|
|
8389
|
+
*/
|
|
8390
|
+
function validateMinimumAssetSize(usdValue, longAssets, shortAssets) {
|
|
8391
|
+
var _a;
|
|
8392
|
+
const allAssets = [...(longAssets || []), ...(shortAssets || [])];
|
|
8393
|
+
if (allAssets.length === 0) {
|
|
8394
|
+
return; // No assets to validate
|
|
8395
|
+
}
|
|
8396
|
+
// Calculate total weight
|
|
8397
|
+
const totalWeight = allAssets.reduce((sum, asset) => { var _a; return sum + ((_a = asset.weight) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
8398
|
+
// If weights are not provided or sum to 0, assume equal distribution
|
|
8399
|
+
const hasWeights = totalWeight > 0;
|
|
8400
|
+
const equalWeight = hasWeights ? 0 : 1 / allAssets.length;
|
|
8401
|
+
// Validate each asset
|
|
8402
|
+
for (const asset of allAssets) {
|
|
8403
|
+
const weight = hasWeights ? (_a = asset.weight) !== null && _a !== void 0 ? _a : 0 : equalWeight;
|
|
8404
|
+
const assetUsdValue = usdValue * weight;
|
|
8405
|
+
if (assetUsdValue < MINIMUM_ASSET_USD_VALUE) {
|
|
8406
|
+
throw new MinimumPositionSizeError(asset.asset, assetUsdValue, MINIMUM_ASSET_USD_VALUE);
|
|
8407
|
+
}
|
|
8408
|
+
}
|
|
8409
|
+
}
|
|
8410
|
+
/**
|
|
8411
|
+
* Calculates the minimum USD value required for a position based on the number of assets
|
|
8412
|
+
* @param longAssets Array of long assets
|
|
8413
|
+
* @param shortAssets Array of short assets
|
|
8414
|
+
* @returns The minimum total USD value required
|
|
8415
|
+
*/
|
|
8416
|
+
function calculateMinimumPositionValue(longAssets, shortAssets) {
|
|
8417
|
+
const totalAssets = ((longAssets === null || longAssets === void 0 ? void 0 : longAssets.length) || 0) + ((shortAssets === null || shortAssets === void 0 ? void 0 : shortAssets.length) || 0);
|
|
8418
|
+
if (totalAssets === 0) {
|
|
8419
|
+
return 0;
|
|
8420
|
+
}
|
|
8421
|
+
return MINIMUM_ASSET_USD_VALUE * totalAssets;
|
|
8422
|
+
}
|
|
8423
|
+
/**
|
|
8424
|
+
* Validates and provides a user-friendly error message with suggestions
|
|
8425
|
+
* @param usdValue Total USD value for the position
|
|
8426
|
+
* @param longAssets Array of long assets with weights
|
|
8427
|
+
* @param shortAssets Array of short assets with weights
|
|
8428
|
+
* @returns Validation result with success flag and optional error message
|
|
8429
|
+
*/
|
|
8430
|
+
function validatePositionSize(usdValue, longAssets, shortAssets) {
|
|
8431
|
+
try {
|
|
8432
|
+
validateMinimumAssetSize(usdValue, longAssets, shortAssets);
|
|
8433
|
+
return { valid: true };
|
|
8434
|
+
}
|
|
8435
|
+
catch (error) {
|
|
8436
|
+
if (error instanceof MinimumPositionSizeError) {
|
|
8437
|
+
const minimumRequired = calculateMinimumPositionValue(longAssets, shortAssets);
|
|
8438
|
+
return {
|
|
8439
|
+
valid: false,
|
|
8440
|
+
error: error.message,
|
|
8441
|
+
minimumRequired,
|
|
8442
|
+
};
|
|
8443
|
+
}
|
|
8444
|
+
throw error;
|
|
8445
|
+
}
|
|
8446
|
+
}
|
|
8447
|
+
|
|
8367
8448
|
/**
|
|
8368
8449
|
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
8369
8450
|
* Caller should supply an accessToken from localStorage.getItem('accessToken')
|
|
8451
|
+
* @throws MinimumPositionSizeError if any asset has less than $11 USD value
|
|
8370
8452
|
*/
|
|
8371
8453
|
async function createPosition(baseUrl, accessToken, payload) {
|
|
8372
|
-
|
|
8454
|
+
// Validate minimum asset size before creating position
|
|
8455
|
+
validateMinimumAssetSize(payload.usdValue, payload.longAssets, payload.shortAssets);
|
|
8456
|
+
const url = joinUrl(baseUrl, "/positions");
|
|
8373
8457
|
try {
|
|
8374
|
-
const resp = await axios$1.post(url, payload, {
|
|
8375
|
-
|
|
8458
|
+
const resp = await axios$1.post(url, payload, {
|
|
8459
|
+
headers: {
|
|
8460
|
+
"Content-Type": "application/json",
|
|
8461
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8462
|
+
},
|
|
8463
|
+
timeout: 60000,
|
|
8464
|
+
});
|
|
8465
|
+
return {
|
|
8466
|
+
data: resp.data,
|
|
8467
|
+
status: resp.status,
|
|
8468
|
+
headers: resp.headers,
|
|
8469
|
+
};
|
|
8376
8470
|
}
|
|
8377
8471
|
catch (error) {
|
|
8378
8472
|
throw toApiError(error);
|
|
@@ -8381,8 +8475,18 @@ async function createPosition(baseUrl, accessToken, payload) {
|
|
|
8381
8475
|
async function updateRiskParameters(baseUrl, accessToken, positionId, payload) {
|
|
8382
8476
|
const url = joinUrl(baseUrl, `/positions/${positionId}/riskParameters`);
|
|
8383
8477
|
try {
|
|
8384
|
-
const resp = await axios$1.put(url, payload, {
|
|
8385
|
-
|
|
8478
|
+
const resp = await axios$1.put(url, payload, {
|
|
8479
|
+
headers: {
|
|
8480
|
+
"Content-Type": "application/json",
|
|
8481
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8482
|
+
},
|
|
8483
|
+
timeout: 60000,
|
|
8484
|
+
});
|
|
8485
|
+
return {
|
|
8486
|
+
data: resp.data,
|
|
8487
|
+
status: resp.status,
|
|
8488
|
+
headers: resp.headers,
|
|
8489
|
+
};
|
|
8386
8490
|
}
|
|
8387
8491
|
catch (error) {
|
|
8388
8492
|
throw toApiError(error);
|
|
@@ -8391,8 +8495,18 @@ async function updateRiskParameters(baseUrl, accessToken, positionId, payload) {
|
|
|
8391
8495
|
async function closePosition(baseUrl, accessToken, positionId, payload) {
|
|
8392
8496
|
const url = joinUrl(baseUrl, `/positions/${positionId}/close`);
|
|
8393
8497
|
try {
|
|
8394
|
-
const resp = await axios$1.post(url, payload, {
|
|
8395
|
-
|
|
8498
|
+
const resp = await axios$1.post(url, payload, {
|
|
8499
|
+
headers: {
|
|
8500
|
+
"Content-Type": "application/json",
|
|
8501
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8502
|
+
},
|
|
8503
|
+
timeout: 60000,
|
|
8504
|
+
});
|
|
8505
|
+
return {
|
|
8506
|
+
data: resp.data,
|
|
8507
|
+
status: resp.status,
|
|
8508
|
+
headers: resp.headers,
|
|
8509
|
+
};
|
|
8396
8510
|
}
|
|
8397
8511
|
catch (error) {
|
|
8398
8512
|
throw toApiError(error);
|
|
@@ -8401,8 +8515,18 @@ async function closePosition(baseUrl, accessToken, positionId, payload) {
|
|
|
8401
8515
|
async function closeAllPositions(baseUrl, accessToken, payload) {
|
|
8402
8516
|
const url = joinUrl(baseUrl, `/positions/close-all`);
|
|
8403
8517
|
try {
|
|
8404
|
-
const resp = await axios$1.post(url, payload, {
|
|
8405
|
-
|
|
8518
|
+
const resp = await axios$1.post(url, payload, {
|
|
8519
|
+
headers: {
|
|
8520
|
+
"Content-Type": "application/json",
|
|
8521
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8522
|
+
},
|
|
8523
|
+
timeout: 60000,
|
|
8524
|
+
});
|
|
8525
|
+
return {
|
|
8526
|
+
data: resp.data,
|
|
8527
|
+
status: resp.status,
|
|
8528
|
+
headers: resp.headers,
|
|
8529
|
+
};
|
|
8406
8530
|
}
|
|
8407
8531
|
catch (error) {
|
|
8408
8532
|
throw toApiError(error);
|
|
@@ -8411,8 +8535,18 @@ async function closeAllPositions(baseUrl, accessToken, payload) {
|
|
|
8411
8535
|
async function adjustPosition(baseUrl, accessToken, positionId, payload) {
|
|
8412
8536
|
const url = joinUrl(baseUrl, `/positions/${positionId}/adjust`);
|
|
8413
8537
|
try {
|
|
8414
|
-
const resp = await axios$1.post(url, payload, {
|
|
8415
|
-
|
|
8538
|
+
const resp = await axios$1.post(url, payload, {
|
|
8539
|
+
headers: {
|
|
8540
|
+
"Content-Type": "application/json",
|
|
8541
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8542
|
+
},
|
|
8543
|
+
timeout: 60000,
|
|
8544
|
+
});
|
|
8545
|
+
return {
|
|
8546
|
+
data: resp.data,
|
|
8547
|
+
status: resp.status,
|
|
8548
|
+
headers: resp.headers,
|
|
8549
|
+
};
|
|
8416
8550
|
}
|
|
8417
8551
|
catch (error) {
|
|
8418
8552
|
throw toApiError(error);
|
|
@@ -8423,8 +8557,18 @@ async function adjustPosition(baseUrl, accessToken, positionId, payload) {
|
|
|
8423
8557
|
async function cancelTwap(baseUrl, accessToken, orderId) {
|
|
8424
8558
|
const url = joinUrl(baseUrl, `/orders/${orderId}/twap/cancel`);
|
|
8425
8559
|
try {
|
|
8426
|
-
const resp = await axios$1.post(url, {}, {
|
|
8427
|
-
|
|
8560
|
+
const resp = await axios$1.post(url, {}, {
|
|
8561
|
+
headers: {
|
|
8562
|
+
"Content-Type": "application/json",
|
|
8563
|
+
Authorization: `Bearer ${accessToken}`,
|
|
8564
|
+
},
|
|
8565
|
+
timeout: 60000,
|
|
8566
|
+
});
|
|
8567
|
+
return {
|
|
8568
|
+
data: resp.data,
|
|
8569
|
+
status: resp.status,
|
|
8570
|
+
headers: resp.headers,
|
|
8571
|
+
};
|
|
8428
8572
|
}
|
|
8429
8573
|
catch (error) {
|
|
8430
8574
|
throw toApiError(error);
|
|
@@ -8771,6 +8915,12 @@ const useHighlightedBaskets = () => {
|
|
|
8771
8915
|
const data = useMarketDataPayload();
|
|
8772
8916
|
return (_a = data === null || data === void 0 ? void 0 : data.highlighted) !== null && _a !== void 0 ? _a : [];
|
|
8773
8917
|
};
|
|
8918
|
+
// Watchlist baskets (from market-data payload when subscribed with address)
|
|
8919
|
+
const useWatchlistBaskets = () => {
|
|
8920
|
+
var _a;
|
|
8921
|
+
const data = useMarketDataPayload();
|
|
8922
|
+
return (_a = data === null || data === void 0 ? void 0 : data.watchlist) !== null && _a !== void 0 ? _a : [];
|
|
8923
|
+
};
|
|
8774
8924
|
// Find a basket by its exact asset composition (order-insensitive)
|
|
8775
8925
|
const useFindBasket = (longs, shorts) => {
|
|
8776
8926
|
const data = useMarketDataPayload();
|
|
@@ -8792,6 +8942,35 @@ const useFindBasket = (longs, shorts) => {
|
|
|
8792
8942
|
}, [data, longs, shorts]);
|
|
8793
8943
|
};
|
|
8794
8944
|
|
|
8945
|
+
async function toggleWatchlist(baseUrl, accessToken, longAssets, shortAssets) {
|
|
8946
|
+
const url = joinUrl(baseUrl, '/watchlist');
|
|
8947
|
+
try {
|
|
8948
|
+
const response = await axios$1.post(url, { longAssets, shortAssets }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}` } });
|
|
8949
|
+
return { data: response.data, status: response.status, headers: response.headers };
|
|
8950
|
+
}
|
|
8951
|
+
catch (error) {
|
|
8952
|
+
throw toApiError(error);
|
|
8953
|
+
}
|
|
8954
|
+
}
|
|
8955
|
+
|
|
8956
|
+
function useWatchlist() {
|
|
8957
|
+
const context = useContext(PearHyperliquidContext);
|
|
8958
|
+
if (!context)
|
|
8959
|
+
throw new Error('useWatchlist must be used within a PearHyperliquidProvider');
|
|
8960
|
+
const { apiBaseUrl, accessToken, isConnected } = context;
|
|
8961
|
+
const marketData = useMarketDataPayload();
|
|
8962
|
+
const isLoading = useMemo(() => !marketData && isConnected, [marketData, isConnected]);
|
|
8963
|
+
const toggle = async (longAssets, shortAssets) => {
|
|
8964
|
+
if (!accessToken)
|
|
8965
|
+
throw new Error('Not authenticated');
|
|
8966
|
+
const resp = await toggleWatchlist(apiBaseUrl, accessToken, longAssets, shortAssets);
|
|
8967
|
+
// Server will push updated market-data over WS; nothing to set here
|
|
8968
|
+
return resp;
|
|
8969
|
+
};
|
|
8970
|
+
const watchlists = marketData === null || marketData === void 0 ? void 0 : marketData.watchlist;
|
|
8971
|
+
return { watchlists: watchlists !== null && watchlists !== void 0 ? watchlists : null, isLoading, toggle };
|
|
8972
|
+
}
|
|
8973
|
+
|
|
8795
8974
|
const PearHyperliquidContext = createContext(undefined);
|
|
8796
8975
|
/**
|
|
8797
8976
|
* React Provider for PearHyperliquidClient
|
|
@@ -9090,4 +9269,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
9090
9269
|
}
|
|
9091
9270
|
}
|
|
9092
9271
|
|
|
9093
|
-
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWebData };
|
|
9272
|
+
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
package/dist/types.d.ts
CHANGED
|
@@ -74,6 +74,18 @@ export interface WebSocketDataMessage<T = unknown> {
|
|
|
74
74
|
channel: WebSocketChannel;
|
|
75
75
|
data: T;
|
|
76
76
|
}
|
|
77
|
+
export interface WatchlistAssetDto {
|
|
78
|
+
asset: string;
|
|
79
|
+
weight: number;
|
|
80
|
+
}
|
|
81
|
+
export interface WatchlistItemDto {
|
|
82
|
+
id: string;
|
|
83
|
+
longAssets: WatchlistAssetDto[];
|
|
84
|
+
shortAssets: WatchlistAssetDto[];
|
|
85
|
+
}
|
|
86
|
+
export interface ToggleWatchlistResponseDto {
|
|
87
|
+
items: WatchlistItemDto[];
|
|
88
|
+
}
|
|
77
89
|
export type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'TRADE_CLOSED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
|
|
78
90
|
export interface NotificationDto {
|
|
79
91
|
id: string;
|
|
@@ -617,6 +629,7 @@ export interface ActiveAssetsResponse {
|
|
|
617
629
|
topGainers: ActiveAssetGroupItem[];
|
|
618
630
|
topLosers: ActiveAssetGroupItem[];
|
|
619
631
|
highlighted: ActiveAssetGroupItem[];
|
|
632
|
+
watchlist: ActiveAssetGroupItem[];
|
|
620
633
|
}
|
|
621
634
|
/**
|
|
622
635
|
* Candle interval options
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PairAssetInput } from "../clients/positions";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum USD value required per asset when creating a position
|
|
4
|
+
*/
|
|
5
|
+
export declare const MINIMUM_ASSET_USD_VALUE = 11;
|
|
6
|
+
/**
|
|
7
|
+
* Validation error for minimum position size
|
|
8
|
+
*/
|
|
9
|
+
export declare class MinimumPositionSizeError extends Error {
|
|
10
|
+
assetName: string;
|
|
11
|
+
assetValue: number;
|
|
12
|
+
minimumRequired: number;
|
|
13
|
+
constructor(assetName: string, assetValue: number, minimumRequired: number);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates that each asset in a position has at least the minimum USD value
|
|
17
|
+
* @param usdValue Total USD value for the position
|
|
18
|
+
* @param longAssets Array of long assets with weights
|
|
19
|
+
* @param shortAssets Array of short assets with weights
|
|
20
|
+
* @throws MinimumPositionSizeError if any asset has less than the minimum USD value
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateMinimumAssetSize(usdValue: number, longAssets?: PairAssetInput[], shortAssets?: PairAssetInput[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the minimum USD value required for a position based on the number of assets
|
|
25
|
+
* @param longAssets Array of long assets
|
|
26
|
+
* @param shortAssets Array of short assets
|
|
27
|
+
* @returns The minimum total USD value required
|
|
28
|
+
*/
|
|
29
|
+
export declare function calculateMinimumPositionValue(longAssets?: PairAssetInput[], shortAssets?: PairAssetInput[]): number;
|
|
30
|
+
/**
|
|
31
|
+
* Validates and provides a user-friendly error message with suggestions
|
|
32
|
+
* @param usdValue Total USD value for the position
|
|
33
|
+
* @param longAssets Array of long assets with weights
|
|
34
|
+
* @param shortAssets Array of short assets with weights
|
|
35
|
+
* @returns Validation result with success flag and optional error message
|
|
36
|
+
*/
|
|
37
|
+
export declare function validatePositionSize(usdValue: number, longAssets?: PairAssetInput[], shortAssets?: PairAssetInput[]): {
|
|
38
|
+
valid: boolean;
|
|
39
|
+
error?: string;
|
|
40
|
+
minimumRequired?: number;
|
|
41
|
+
};
|