@pear-protocol/hyperliquid-sdk 0.1.1-9.1-pnl → 0.1.2-1.beta
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 +11 -3
- package/dist/clients/positions.d.ts +15 -4
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/usePosition.d.ts +2 -2
- package/dist/index.d.ts +18 -45
- package/dist/index.js +2 -227
- package/dist/types.d.ts +1 -0
- package/package.json +3 -3
- package/dist/hooks/usePnlCalendar.d.ts +0 -38
package/README.md
CHANGED
|
@@ -557,8 +557,16 @@ const result = await createPosition(apiBaseUrl, {
|
|
|
557
557
|
executionType: 'MARKET',
|
|
558
558
|
});
|
|
559
559
|
|
|
560
|
-
// Close position
|
|
561
|
-
await closePosition(apiBaseUrl, positionId, {
|
|
560
|
+
// Close position immediately
|
|
561
|
+
await closePosition(apiBaseUrl, positionId, { executionType: 'MARKET' });
|
|
562
|
+
|
|
563
|
+
// Close position conditionally
|
|
564
|
+
await closePosition(apiBaseUrl, positionId, {
|
|
565
|
+
executionType: 'TRIGGER',
|
|
566
|
+
triggerType: 'WEIGHTED_RATIO',
|
|
567
|
+
triggerValue: '1.08',
|
|
568
|
+
direction: 'MORE_THAN',
|
|
569
|
+
});
|
|
562
570
|
|
|
563
571
|
// Update TP/SL
|
|
564
572
|
await updateRiskParameters(apiBaseUrl, positionId, {
|
|
@@ -864,7 +872,7 @@ function TradingInterface() {
|
|
|
864
872
|
{openPositions?.map(pos => (
|
|
865
873
|
<div key={pos.positionId}>
|
|
866
874
|
PnL: ${pos.unrealizedPnl.toFixed(2)}
|
|
867
|
-
<button onClick={() => closePosition(pos.positionId, {
|
|
875
|
+
<button onClick={() => closePosition(pos.positionId, { executionType: 'MARKET' })}>
|
|
868
876
|
Close
|
|
869
877
|
</button>
|
|
870
878
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiResponse, CreatePositionRequestInput, CreatePositionResponseDto, TpSlThresholdInput } from "../types";
|
|
1
|
+
import type { ApiResponse, CloseTriggerType, CreatePositionRequestInput, CreatePositionResponseDto, OrderDirection, TpSlThresholdInput } from "../types";
|
|
2
2
|
import type { CancelTwapResponseDto } from "./orders";
|
|
3
3
|
/**
|
|
4
4
|
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
@@ -18,12 +18,16 @@ export interface UpdateRiskParametersResponseDto {
|
|
|
18
18
|
updatedAt: string;
|
|
19
19
|
}
|
|
20
20
|
export declare function updateRiskParameters(baseUrl: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
21
|
-
export type
|
|
21
|
+
export type ClosePositionExecutionType = "MARKET" | "TWAP" | "TRIGGER";
|
|
22
|
+
export type CloseAllExecutionType = "MARKET" | "TWAP";
|
|
22
23
|
export interface ClosePositionRequestInput {
|
|
23
|
-
executionType:
|
|
24
|
+
executionType: ClosePositionExecutionType;
|
|
24
25
|
twapDuration?: number;
|
|
25
26
|
twapIntervalSeconds?: number;
|
|
26
27
|
randomizeExecution?: boolean;
|
|
28
|
+
triggerType?: CloseTriggerType;
|
|
29
|
+
triggerValue?: string | number;
|
|
30
|
+
direction?: OrderDirection;
|
|
27
31
|
referralCode?: string;
|
|
28
32
|
}
|
|
29
33
|
export interface ClosePositionResponseDto {
|
|
@@ -41,7 +45,14 @@ export interface CloseAllPositionsResultDto {
|
|
|
41
45
|
export interface CloseAllPositionsResponseDto {
|
|
42
46
|
results: CloseAllPositionsResultDto[];
|
|
43
47
|
}
|
|
44
|
-
export
|
|
48
|
+
export interface CloseAllPositionsRequestInput {
|
|
49
|
+
executionType: CloseAllExecutionType;
|
|
50
|
+
twapDuration?: number;
|
|
51
|
+
twapIntervalSeconds?: number;
|
|
52
|
+
randomizeExecution?: boolean;
|
|
53
|
+
referralCode?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function closeAllPositions(baseUrl: string, payload: CloseAllPositionsRequestInput): Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
45
56
|
export type AdjustExecutionType = "MARKET" | "LIMIT";
|
|
46
57
|
export type PositionAdjustmentType = "REDUCE" | "INCREASE";
|
|
47
58
|
export interface AdjustPositionRequestInput {
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type CloseAllPositionsResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto, type AdjustAdvanceItemInput, type AdjustAdvanceResponseDto, type UpdateLeverageResponseDto } from '../clients/positions';
|
|
1
|
+
import { type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type CloseAllPositionsRequestInput, type CloseAllPositionsResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto, type AdjustAdvanceItemInput, type AdjustAdvanceResponseDto, type UpdateLeverageResponseDto } from '../clients/positions';
|
|
2
2
|
import type { ApiResponse, CreatePositionRequestInput, CreatePositionResponseDto, OpenPositionDto } from '../types';
|
|
3
3
|
export interface RebalanceAssetPlan {
|
|
4
4
|
coin: string;
|
|
@@ -23,7 +23,7 @@ export declare function usePosition(): {
|
|
|
23
23
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
24
24
|
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
25
25
|
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
26
|
-
readonly closeAllPositions: (payload:
|
|
26
|
+
readonly closeAllPositions: (payload: CloseAllPositionsRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
27
27
|
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
28
28
|
readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
29
29
|
readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -342,6 +342,7 @@ type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRICE' | 'P
|
|
|
342
342
|
* Trigger type for trigger orders
|
|
343
343
|
*/
|
|
344
344
|
type TriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'BTC_DOM' | 'CROSS_ASSET_PRICE' | 'PREDICTION_MARKET_OUTCOME';
|
|
345
|
+
type CloseTriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
345
346
|
type OrderDirection = 'MORE_THAN' | 'LESS_THAN';
|
|
346
347
|
/**
|
|
347
348
|
* Market order parameters
|
|
@@ -1232,12 +1233,16 @@ interface UpdateRiskParametersResponseDto {
|
|
|
1232
1233
|
updatedAt: string;
|
|
1233
1234
|
}
|
|
1234
1235
|
declare function updateRiskParameters(baseUrl: string, positionId: string, payload: UpdateRiskParametersRequestInput): Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
1235
|
-
type
|
|
1236
|
+
type ClosePositionExecutionType = "MARKET" | "TWAP" | "TRIGGER";
|
|
1237
|
+
type CloseAllExecutionType = "MARKET" | "TWAP";
|
|
1236
1238
|
interface ClosePositionRequestInput {
|
|
1237
|
-
executionType:
|
|
1239
|
+
executionType: ClosePositionExecutionType;
|
|
1238
1240
|
twapDuration?: number;
|
|
1239
1241
|
twapIntervalSeconds?: number;
|
|
1240
1242
|
randomizeExecution?: boolean;
|
|
1243
|
+
triggerType?: CloseTriggerType;
|
|
1244
|
+
triggerValue?: string | number;
|
|
1245
|
+
direction?: OrderDirection;
|
|
1241
1246
|
referralCode?: string;
|
|
1242
1247
|
}
|
|
1243
1248
|
interface ClosePositionResponseDto {
|
|
@@ -1255,7 +1260,14 @@ interface CloseAllPositionsResultDto {
|
|
|
1255
1260
|
interface CloseAllPositionsResponseDto {
|
|
1256
1261
|
results: CloseAllPositionsResultDto[];
|
|
1257
1262
|
}
|
|
1258
|
-
|
|
1263
|
+
interface CloseAllPositionsRequestInput {
|
|
1264
|
+
executionType: CloseAllExecutionType;
|
|
1265
|
+
twapDuration?: number;
|
|
1266
|
+
twapIntervalSeconds?: number;
|
|
1267
|
+
randomizeExecution?: boolean;
|
|
1268
|
+
referralCode?: string;
|
|
1269
|
+
}
|
|
1270
|
+
declare function closeAllPositions(baseUrl: string, payload: CloseAllPositionsRequestInput): Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
1259
1271
|
type AdjustExecutionType = "MARKET" | "LIMIT";
|
|
1260
1272
|
type PositionAdjustmentType = "REDUCE" | "INCREASE";
|
|
1261
1273
|
interface AdjustPositionRequestInput {
|
|
@@ -1320,7 +1332,7 @@ declare function usePosition(): {
|
|
|
1320
1332
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
1321
1333
|
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
1322
1334
|
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
1323
|
-
readonly closeAllPositions: (payload:
|
|
1335
|
+
readonly closeAllPositions: (payload: CloseAllPositionsRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
1324
1336
|
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
1325
1337
|
readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
1326
1338
|
readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
@@ -1498,45 +1510,6 @@ interface UseHyperliquidUserFillsState {
|
|
|
1498
1510
|
*/
|
|
1499
1511
|
declare function useHyperliquidUserFills(options: UseHyperliquidUserFillsOptions): UseHyperliquidUserFillsState;
|
|
1500
1512
|
|
|
1501
|
-
type PnlCalendarTimeframe = '2W' | '3W' | '2M' | '3M';
|
|
1502
|
-
interface PnlCalendarDay {
|
|
1503
|
-
date: string;
|
|
1504
|
-
totalPnl: number;
|
|
1505
|
-
volume: number;
|
|
1506
|
-
positionsClosed: number;
|
|
1507
|
-
result: 'profit' | 'loss' | 'breakeven';
|
|
1508
|
-
tokens: string[];
|
|
1509
|
-
}
|
|
1510
|
-
interface PeriodSummary {
|
|
1511
|
-
pnl: number;
|
|
1512
|
-
volume: number;
|
|
1513
|
-
winRate: number;
|
|
1514
|
-
wins: number;
|
|
1515
|
-
losses: number;
|
|
1516
|
-
totalProfit: number;
|
|
1517
|
-
totalLoss: number;
|
|
1518
|
-
}
|
|
1519
|
-
interface PnlCalendarWeek {
|
|
1520
|
-
weekStart: string;
|
|
1521
|
-
weekEnd: string;
|
|
1522
|
-
days: PnlCalendarDay[];
|
|
1523
|
-
summary: PeriodSummary;
|
|
1524
|
-
}
|
|
1525
|
-
interface PnlCalendarMonth {
|
|
1526
|
-
month: string;
|
|
1527
|
-
label: string;
|
|
1528
|
-
days: PnlCalendarDay[];
|
|
1529
|
-
summary: PeriodSummary;
|
|
1530
|
-
}
|
|
1531
|
-
interface UsePnlCalendarResult {
|
|
1532
|
-
timeframe: PnlCalendarTimeframe;
|
|
1533
|
-
weeks: PnlCalendarWeek[];
|
|
1534
|
-
months: PnlCalendarMonth[];
|
|
1535
|
-
overall: PeriodSummary;
|
|
1536
|
-
isLoading: boolean;
|
|
1537
|
-
}
|
|
1538
|
-
declare function usePnlCalendar(timeframe?: PnlCalendarTimeframe): UsePnlCalendarResult;
|
|
1539
|
-
|
|
1540
1513
|
/**
|
|
1541
1514
|
* Mark notifications as read up to a given timestamp (ms)
|
|
1542
1515
|
*/
|
|
@@ -1811,5 +1784,5 @@ interface MarketDataState {
|
|
|
1811
1784
|
}
|
|
1812
1785
|
declare const useMarketData: zustand.UseBoundStore<zustand.StoreApi<MarketDataState>>;
|
|
1813
1786
|
|
|
1814
|
-
export { ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, ReadyState, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays,
|
|
1815
|
-
export type { AccountSummaryResponseDto, ActiveAssetData, ActiveAssetGroupItem, ActiveAssetsAllResponse, ActiveAssetsResponse, AddressState, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, AgentWalletStatus, AllDexsAssetCtxsData, AllDexsClearinghouseStateData, AllPerpMetasItem, AllPerpMetasResponse, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AuthenticateRequest, AuthenticateResponse, AvailableToTrades, BalanceSummaryDto, BaseTriggerOrderNotificationParams, BtcDomTriggerParams, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ChunkFillDto, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto,
|
|
1787
|
+
export { ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, ReadyState, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1788
|
+
export type { AccountSummaryResponseDto, ActiveAssetData, ActiveAssetGroupItem, ActiveAssetsAllResponse, ActiveAssetsResponse, AddressState, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, AgentWalletStatus, AllDexsAssetCtxsData, AllDexsClearinghouseStateData, AllPerpMetasItem, AllPerpMetasResponse, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AuthenticateRequest, AuthenticateResponse, AvailableToTrades, BalanceSummaryDto, BaseTriggerOrderNotificationParams, BtcDomTriggerParams, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ChunkFillDto, ClearinghouseState, CloseAllExecutionType, CloseAllPositionsRequestInput, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, ClosePositionExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CloseTriggerType, CollateralToken, CreateAgentWalletResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossAssetPriceTriggerParams, CrossMarginSummaryDto, CumFundingDto, EIP712AuthDetails, ExecutionType, ExternalFillDto, ExternalLiquidationDto, ExtraAgent, GetAgentWalletResponseDto, GetEIP712MessageResponse, GetKalshiMarketsParams, HLChannel, HLChannelDataMap, HLWebSocketResponse, HistoricalRange, KalshiMarket, KalshiMarketsResponse, KalshiMveLeg, KalshiPriceRange, LadderConfigInput, LadderOrderParameters, LeverageInfo, LogoutRequest, LogoutResponse, MarginRequiredPerCollateral, MarginRequiredResult, MarginSummaryDto, MarginTableDef, MarginTablesEntry, MarginTier, MarketOrderParameters, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderDirection, OrderParameters, OrderStatus, OrderType, PairAssetDto, PairAssetInput, PerformanceOverlay, PerpDex, PerpDexsResponse, PerpMetaAsset, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PredictionMarketOutcomeTriggerParams, PriceRatioTriggerParams, PriceTriggerParams, PrivyAuthDetails, RawAssetDto, RawPositionDto, RealtimeBar, RealtimeBarsCallback, RebalanceAssetPlan, RebalancePlan, RefreshTokenRequest, RefreshTokenResponse, SpotBalance, SpotBalances, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, SyncFillsRequestDto, SyncFillsResponseDto, ToggleWatchlistResponseDto, TokenConflict, TokenEntry, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TokenSelectorConfig, TpSlOrderParameters, TpSlThreshold, TpSlThresholdInput, TpSlThresholdType, TpSlTriggerType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TriggerOrderNotificationAsset, TriggerOrderNotificationParams, TriggerOrderNotificationType, TriggerOrderParameters, TriggerType, TwapChunkStatus, TwapChunkStatusDto, TwapMonitoringDto, TwapOrderOverallStatus, TwapOrderParameters, TwapSliceFillResponseItem, UniverseAsset, UpdateLeverageRequestInput, UpdateLeverageResponseDto, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseHyperliquidUserFillsOptions, UseHyperliquidUserFillsState, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserAbstraction, UserProfile, UserSelectionState, WatchlistAssetDto, WatchlistItemDto, WebData3AssetCtx, WebData3PerpDexState, WebData3Response, WebData3UserState, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -981,7 +981,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
|
|
|
981
981
|
// finalAssetContexts now sourced from allDexsAssetCtxs channel
|
|
982
982
|
const finalAtOICaps = webData3.perpDexStates.flatMap((dex) => dex.perpsAtOpenInterestCap);
|
|
983
983
|
setFinalAtOICaps(finalAtOICaps);
|
|
984
|
-
setUserAbstractionMode(webData3.userState.abstraction ||
|
|
984
|
+
setUserAbstractionMode(webData3.userState.abstraction || 'disabled');
|
|
985
985
|
break;
|
|
986
986
|
case "allDexsAssetCtxs":
|
|
987
987
|
{
|
|
@@ -8422,231 +8422,6 @@ function useHyperliquidUserFills(options) {
|
|
|
8422
8422
|
};
|
|
8423
8423
|
}
|
|
8424
8424
|
|
|
8425
|
-
// ─── helpers ────────────────────────────────────────────────────
|
|
8426
|
-
const EMPTY_SUMMARY = {
|
|
8427
|
-
pnl: 0,
|
|
8428
|
-
volume: 0,
|
|
8429
|
-
winRate: 0,
|
|
8430
|
-
wins: 0,
|
|
8431
|
-
losses: 0,
|
|
8432
|
-
totalProfit: 0,
|
|
8433
|
-
totalLoss: 0,
|
|
8434
|
-
};
|
|
8435
|
-
const getTimeframeDays = (tf) => {
|
|
8436
|
-
switch (tf) {
|
|
8437
|
-
case '2W':
|
|
8438
|
-
return 14;
|
|
8439
|
-
case '3W':
|
|
8440
|
-
return 21;
|
|
8441
|
-
case '2M':
|
|
8442
|
-
return 60;
|
|
8443
|
-
case '3M':
|
|
8444
|
-
return 90;
|
|
8445
|
-
}
|
|
8446
|
-
};
|
|
8447
|
-
const isWeekTimeframe = (tf) => tf === '2W' || tf === '3W';
|
|
8448
|
-
const toDateKey = (date) => {
|
|
8449
|
-
const y = date.getFullYear();
|
|
8450
|
-
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
8451
|
-
const d = String(date.getDate()).padStart(2, '0');
|
|
8452
|
-
return `${y}-${m}-${d}`;
|
|
8453
|
-
};
|
|
8454
|
-
const toMonthKey = (date) => {
|
|
8455
|
-
const y = date.getFullYear();
|
|
8456
|
-
const m = String(date.getMonth() + 1).padStart(2, '0');
|
|
8457
|
-
return `${y}-${m}`;
|
|
8458
|
-
};
|
|
8459
|
-
const formatMonthLabel = (date) => date.toLocaleDateString('en-US', { month: 'short', year: 'numeric' });
|
|
8460
|
-
const getMonday = (date) => {
|
|
8461
|
-
const d = new Date(date);
|
|
8462
|
-
const day = d.getDay(); // 0=Sun … 6=Sat
|
|
8463
|
-
const diff = day === 0 ? -6 : 1 - day;
|
|
8464
|
-
d.setDate(d.getDate() + diff);
|
|
8465
|
-
d.setHours(0, 0, 0, 0);
|
|
8466
|
-
return d;
|
|
8467
|
-
};
|
|
8468
|
-
const round2 = (n) => Math.round(n * 100) / 100;
|
|
8469
|
-
const buildSummary = (days) => {
|
|
8470
|
-
let pnl = 0;
|
|
8471
|
-
let volume = 0;
|
|
8472
|
-
let wins = 0;
|
|
8473
|
-
let losses = 0;
|
|
8474
|
-
let totalProfit = 0;
|
|
8475
|
-
let totalLoss = 0;
|
|
8476
|
-
for (const day of days) {
|
|
8477
|
-
pnl += day.totalPnl;
|
|
8478
|
-
volume += day.volume;
|
|
8479
|
-
if (day.positionsClosed === 0)
|
|
8480
|
-
continue;
|
|
8481
|
-
if (day.totalPnl > 0) {
|
|
8482
|
-
wins++;
|
|
8483
|
-
totalProfit += day.totalPnl;
|
|
8484
|
-
}
|
|
8485
|
-
else if (day.totalPnl < 0) {
|
|
8486
|
-
losses++;
|
|
8487
|
-
totalLoss += Math.abs(day.totalPnl);
|
|
8488
|
-
}
|
|
8489
|
-
}
|
|
8490
|
-
const total = wins + losses;
|
|
8491
|
-
const winRate = total > 0 ? Math.round((wins / total) * 100) : 0;
|
|
8492
|
-
return {
|
|
8493
|
-
pnl: round2(pnl),
|
|
8494
|
-
volume: round2(volume),
|
|
8495
|
-
winRate,
|
|
8496
|
-
wins,
|
|
8497
|
-
losses,
|
|
8498
|
-
totalProfit: round2(totalProfit),
|
|
8499
|
-
totalLoss: round2(totalLoss),
|
|
8500
|
-
};
|
|
8501
|
-
};
|
|
8502
|
-
const extractTokens = (trade) => {
|
|
8503
|
-
const tokens = new Set();
|
|
8504
|
-
for (const asset of trade.closedLongAssets) {
|
|
8505
|
-
if (asset.coin)
|
|
8506
|
-
tokens.add(asset.coin);
|
|
8507
|
-
}
|
|
8508
|
-
for (const asset of trade.closedShortAssets) {
|
|
8509
|
-
if (asset.coin)
|
|
8510
|
-
tokens.add(asset.coin);
|
|
8511
|
-
}
|
|
8512
|
-
return Array.from(tokens);
|
|
8513
|
-
};
|
|
8514
|
-
// ─── hook ───────────────────────────────────────────────────────
|
|
8515
|
-
function usePnlCalendar(timeframe = '2W') {
|
|
8516
|
-
const context = useContext(PearHyperliquidContext);
|
|
8517
|
-
if (!context) {
|
|
8518
|
-
throw new Error('usePnlCalendar must be used within a PearHyperliquidProvider');
|
|
8519
|
-
}
|
|
8520
|
-
const tradeHistories = useUserData((state) => state.tradeHistories);
|
|
8521
|
-
const isLoading = useMemo(() => {
|
|
8522
|
-
return tradeHistories === null && context.isConnected;
|
|
8523
|
-
}, [tradeHistories, context.isConnected]);
|
|
8524
|
-
const result = useMemo(() => {
|
|
8525
|
-
const empty = {
|
|
8526
|
-
timeframe,
|
|
8527
|
-
weeks: [],
|
|
8528
|
-
months: [],
|
|
8529
|
-
overall: EMPTY_SUMMARY,
|
|
8530
|
-
isLoading: true,
|
|
8531
|
-
};
|
|
8532
|
-
if (!tradeHistories)
|
|
8533
|
-
return empty;
|
|
8534
|
-
const totalDays = getTimeframeDays(timeframe);
|
|
8535
|
-
const now = new Date();
|
|
8536
|
-
const startDate = new Date(now);
|
|
8537
|
-
startDate.setDate(now.getDate() - totalDays + 1);
|
|
8538
|
-
startDate.setHours(0, 0, 0, 0);
|
|
8539
|
-
const startKey = toDateKey(startDate);
|
|
8540
|
-
// Build day buckets for the full range
|
|
8541
|
-
const buckets = new Map();
|
|
8542
|
-
for (let i = 0; i < totalDays; i++) {
|
|
8543
|
-
const d = new Date(startDate);
|
|
8544
|
-
d.setDate(startDate.getDate() + i);
|
|
8545
|
-
buckets.set(toDateKey(d), {
|
|
8546
|
-
pnl: 0,
|
|
8547
|
-
volume: 0,
|
|
8548
|
-
positionsClosed: 0,
|
|
8549
|
-
tokens: new Set(),
|
|
8550
|
-
});
|
|
8551
|
-
}
|
|
8552
|
-
// Populate buckets from trade histories
|
|
8553
|
-
for (const trade of tradeHistories) {
|
|
8554
|
-
if (!trade.createdAt)
|
|
8555
|
-
continue;
|
|
8556
|
-
const date = new Date(trade.createdAt);
|
|
8557
|
-
if (isNaN(date.getTime()))
|
|
8558
|
-
continue;
|
|
8559
|
-
const dateKey = toDateKey(date);
|
|
8560
|
-
if (dateKey < startKey)
|
|
8561
|
-
continue;
|
|
8562
|
-
const bucket = buckets.get(dateKey);
|
|
8563
|
-
if (!bucket)
|
|
8564
|
-
continue;
|
|
8565
|
-
const pnl = trade.realizedPnl;
|
|
8566
|
-
bucket.pnl += isFinite(pnl) ? pnl : 0;
|
|
8567
|
-
const vol = trade.totalValue;
|
|
8568
|
-
bucket.volume += isFinite(vol) ? vol : 0;
|
|
8569
|
-
bucket.positionsClosed += 1;
|
|
8570
|
-
for (const token of extractTokens(trade)) {
|
|
8571
|
-
bucket.tokens.add(token);
|
|
8572
|
-
}
|
|
8573
|
-
}
|
|
8574
|
-
// Build day objects
|
|
8575
|
-
const allDays = [];
|
|
8576
|
-
const sortedKeys = Array.from(buckets.keys()).sort();
|
|
8577
|
-
for (const key of sortedKeys) {
|
|
8578
|
-
const bucket = buckets.get(key);
|
|
8579
|
-
const roundedPnl = round2(bucket.pnl);
|
|
8580
|
-
const result = roundedPnl > 0 ? 'profit' : roundedPnl < 0 ? 'loss' : 'breakeven';
|
|
8581
|
-
allDays.push({
|
|
8582
|
-
date: key,
|
|
8583
|
-
totalPnl: roundedPnl,
|
|
8584
|
-
volume: round2(bucket.volume),
|
|
8585
|
-
positionsClosed: bucket.positionsClosed,
|
|
8586
|
-
result,
|
|
8587
|
-
tokens: Array.from(bucket.tokens),
|
|
8588
|
-
});
|
|
8589
|
-
}
|
|
8590
|
-
// Group into periods
|
|
8591
|
-
let weeks = [];
|
|
8592
|
-
let months = [];
|
|
8593
|
-
if (isWeekTimeframe(timeframe)) {
|
|
8594
|
-
const weekMap = new Map();
|
|
8595
|
-
for (const day of allDays) {
|
|
8596
|
-
const date = new Date(day.date + 'T00:00:00');
|
|
8597
|
-
const monday = getMonday(date);
|
|
8598
|
-
const mondayKey = toDateKey(monday);
|
|
8599
|
-
if (!weekMap.has(mondayKey)) {
|
|
8600
|
-
weekMap.set(mondayKey, []);
|
|
8601
|
-
}
|
|
8602
|
-
weekMap.get(mondayKey).push(day);
|
|
8603
|
-
}
|
|
8604
|
-
const sortedWeekKeys = Array.from(weekMap.keys()).sort();
|
|
8605
|
-
weeks = sortedWeekKeys.map((mondayKey) => {
|
|
8606
|
-
const days = weekMap.get(mondayKey);
|
|
8607
|
-
const monday = new Date(mondayKey + 'T00:00:00');
|
|
8608
|
-
const sunday = new Date(monday);
|
|
8609
|
-
sunday.setDate(monday.getDate() + 6);
|
|
8610
|
-
return {
|
|
8611
|
-
weekStart: mondayKey,
|
|
8612
|
-
weekEnd: toDateKey(sunday),
|
|
8613
|
-
days,
|
|
8614
|
-
summary: buildSummary(days),
|
|
8615
|
-
};
|
|
8616
|
-
});
|
|
8617
|
-
}
|
|
8618
|
-
else {
|
|
8619
|
-
const monthMap = new Map();
|
|
8620
|
-
for (const day of allDays) {
|
|
8621
|
-
const date = new Date(day.date + 'T00:00:00');
|
|
8622
|
-
const mk = toMonthKey(date);
|
|
8623
|
-
if (!monthMap.has(mk)) {
|
|
8624
|
-
monthMap.set(mk, { days: [], label: formatMonthLabel(date) });
|
|
8625
|
-
}
|
|
8626
|
-
monthMap.get(mk).days.push(day);
|
|
8627
|
-
}
|
|
8628
|
-
const sortedMonthKeys = Array.from(monthMap.keys()).sort();
|
|
8629
|
-
months = sortedMonthKeys.map((mk) => {
|
|
8630
|
-
const { days, label } = monthMap.get(mk);
|
|
8631
|
-
return {
|
|
8632
|
-
month: mk,
|
|
8633
|
-
label,
|
|
8634
|
-
days,
|
|
8635
|
-
summary: buildSummary(days),
|
|
8636
|
-
};
|
|
8637
|
-
});
|
|
8638
|
-
}
|
|
8639
|
-
return {
|
|
8640
|
-
timeframe,
|
|
8641
|
-
weeks,
|
|
8642
|
-
months,
|
|
8643
|
-
overall: buildSummary(allDays),
|
|
8644
|
-
isLoading: false,
|
|
8645
|
-
};
|
|
8646
|
-
}, [tradeHistories, timeframe]);
|
|
8647
|
-
return { ...result, isLoading };
|
|
8648
|
-
}
|
|
8649
|
-
|
|
8650
8425
|
const PearHyperliquidContext = createContext(undefined);
|
|
8651
8426
|
/**
|
|
8652
8427
|
* React Provider for PearHyperliquidClient
|
|
@@ -8998,4 +8773,4 @@ function getOrderTrailingInfo(order) {
|
|
|
8998
8773
|
return undefined;
|
|
8999
8774
|
}
|
|
9000
8775
|
|
|
9001
|
-
export { ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays,
|
|
8776
|
+
export { ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getCompleteTimestamps, getKalshiMarkets, getOrderDirection, getOrderLadderConfig, getOrderLeverage, getOrderReduceOnly, getOrderTpSlTriggerType, getOrderTrailingInfo, getOrderTriggerType, getOrderTriggerValue, getOrderTwapDuration, getOrderUsdValue, getPortfolio, isBtcDomOrder, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
package/dist/types.d.ts
CHANGED
|
@@ -314,6 +314,7 @@ export type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRIC
|
|
|
314
314
|
* Trigger type for trigger orders
|
|
315
315
|
*/
|
|
316
316
|
export type TriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'BTC_DOM' | 'CROSS_ASSET_PRICE' | 'PREDICTION_MARKET_OUTCOME';
|
|
317
|
+
export type CloseTriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
317
318
|
export type OrderDirection = 'MORE_THAN' | 'LESS_THAN';
|
|
318
319
|
/**
|
|
319
320
|
* Market order parameters
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/hyperliquid-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21.beta",
|
|
4
4
|
"description": "React SDK for Pear Protocol Hyperliquid API integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"zustand": "^5.0.9"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"react": "^18.0.0",
|
|
32
|
-
"react-dom": "^18.0.0"
|
|
31
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
32
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type PnlCalendarTimeframe = '2W' | '3W' | '2M' | '3M';
|
|
2
|
-
export interface PnlCalendarDay {
|
|
3
|
-
date: string;
|
|
4
|
-
totalPnl: number;
|
|
5
|
-
volume: number;
|
|
6
|
-
positionsClosed: number;
|
|
7
|
-
result: 'profit' | 'loss' | 'breakeven';
|
|
8
|
-
tokens: string[];
|
|
9
|
-
}
|
|
10
|
-
export interface PeriodSummary {
|
|
11
|
-
pnl: number;
|
|
12
|
-
volume: number;
|
|
13
|
-
winRate: number;
|
|
14
|
-
wins: number;
|
|
15
|
-
losses: number;
|
|
16
|
-
totalProfit: number;
|
|
17
|
-
totalLoss: number;
|
|
18
|
-
}
|
|
19
|
-
export interface PnlCalendarWeek {
|
|
20
|
-
weekStart: string;
|
|
21
|
-
weekEnd: string;
|
|
22
|
-
days: PnlCalendarDay[];
|
|
23
|
-
summary: PeriodSummary;
|
|
24
|
-
}
|
|
25
|
-
export interface PnlCalendarMonth {
|
|
26
|
-
month: string;
|
|
27
|
-
label: string;
|
|
28
|
-
days: PnlCalendarDay[];
|
|
29
|
-
summary: PeriodSummary;
|
|
30
|
-
}
|
|
31
|
-
export interface UsePnlCalendarResult {
|
|
32
|
-
timeframe: PnlCalendarTimeframe;
|
|
33
|
-
weeks: PnlCalendarWeek[];
|
|
34
|
-
months: PnlCalendarMonth[];
|
|
35
|
-
overall: PeriodSummary;
|
|
36
|
-
isLoading: boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare function usePnlCalendar(timeframe?: PnlCalendarTimeframe): UsePnlCalendarResult;
|