@pear-protocol/hyperliquid-sdk 0.1.36 → 0.1.38
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/dist/clients/positions.d.ts +25 -1
- package/dist/hooks/usePosition.d.ts +2 -1
- package/dist/index.d.ts +28 -2
- package/dist/index.js +46 -4
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiResponse, CloseExecutionType, CloseTriggerType, CreatePositionRequestInput, CreatePositionResponseDto, OrderDirection, TpSlThresholdInput } from "../types";
|
|
1
|
+
import type { ApiResponse, CloseExecutionType, CloseTriggerType, CreatePositionRequestInput, CreatePositionResponseDto, ExternalFillDto, OrderDirection, ReverseExecutionType, TpSlThresholdInput } from "../types";
|
|
2
2
|
import type { CancelTwapResponseDto } from "./orders";
|
|
3
3
|
/**
|
|
4
4
|
* Create a position (MARKET/LIMIT/TWAP) using Pear Hyperliquid service
|
|
@@ -37,6 +37,30 @@ export interface ClosePositionResponseDto {
|
|
|
37
37
|
chunksScheduled?: number;
|
|
38
38
|
}
|
|
39
39
|
export declare function closePosition(baseUrl: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
40
|
+
export type ReversePositionExecutionType = ReverseExecutionType;
|
|
41
|
+
export interface ReversePositionRequestInput {
|
|
42
|
+
executionType?: ReverseExecutionType;
|
|
43
|
+
slippage?: number;
|
|
44
|
+
referralCode?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ReversePositionAssetSummaryDto {
|
|
47
|
+
asset: string;
|
|
48
|
+
originalSide: string;
|
|
49
|
+
reverseSide: string;
|
|
50
|
+
originalSize: string;
|
|
51
|
+
submittedSize: string;
|
|
52
|
+
filledSize: string;
|
|
53
|
+
reversedOpenSize: string;
|
|
54
|
+
residualSize: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ReversePositionResponseDto {
|
|
57
|
+
orderId: string;
|
|
58
|
+
reversedPositionId: string;
|
|
59
|
+
fills?: ExternalFillDto[];
|
|
60
|
+
fullyReversed: boolean;
|
|
61
|
+
assets?: ReversePositionAssetSummaryDto[];
|
|
62
|
+
}
|
|
63
|
+
export declare function reversePosition(baseUrl: string, positionId: string, payload?: ReversePositionRequestInput): Promise<ApiResponse<ReversePositionResponseDto>>;
|
|
40
64
|
export interface CloseAllPositionsResultDto {
|
|
41
65
|
positionId: string;
|
|
42
66
|
success: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
1
|
+
import { type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type ReversePositionRequestInput, type ReversePositionResponseDto, 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,6 +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 reversePosition: (positionId: string, payload?: ReversePositionRequestInput) => Promise<ApiResponse<ReversePositionResponseDto>>;
|
|
26
27
|
readonly closeAllPositions: (payload: CloseAllPositionsRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
27
28
|
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
28
29
|
readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -344,6 +344,7 @@ type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRICE' | 'P
|
|
|
344
344
|
type TriggerType = 'PRICE' | 'PRICE_LIMIT' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'BTC_DOM' | 'CROSS_ASSET_PRICE' | 'PREDICTION_MARKET_OUTCOME';
|
|
345
345
|
type CloseTriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
346
346
|
type CloseExecutionType = 'MARKET' | 'TWAP' | 'TRIGGER';
|
|
347
|
+
type ReverseExecutionType = 'MARKET';
|
|
347
348
|
type OrderDirection = 'MORE_THAN' | 'LESS_THAN';
|
|
348
349
|
/**
|
|
349
350
|
* Market order parameters
|
|
@@ -1265,6 +1266,30 @@ interface ClosePositionResponseDto {
|
|
|
1265
1266
|
chunksScheduled?: number;
|
|
1266
1267
|
}
|
|
1267
1268
|
declare function closePosition(baseUrl: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
1269
|
+
type ReversePositionExecutionType = ReverseExecutionType;
|
|
1270
|
+
interface ReversePositionRequestInput {
|
|
1271
|
+
executionType?: ReverseExecutionType;
|
|
1272
|
+
slippage?: number;
|
|
1273
|
+
referralCode?: string;
|
|
1274
|
+
}
|
|
1275
|
+
interface ReversePositionAssetSummaryDto {
|
|
1276
|
+
asset: string;
|
|
1277
|
+
originalSide: string;
|
|
1278
|
+
reverseSide: string;
|
|
1279
|
+
originalSize: string;
|
|
1280
|
+
submittedSize: string;
|
|
1281
|
+
filledSize: string;
|
|
1282
|
+
reversedOpenSize: string;
|
|
1283
|
+
residualSize: string;
|
|
1284
|
+
}
|
|
1285
|
+
interface ReversePositionResponseDto {
|
|
1286
|
+
orderId: string;
|
|
1287
|
+
reversedPositionId: string;
|
|
1288
|
+
fills?: ExternalFillDto[];
|
|
1289
|
+
fullyReversed: boolean;
|
|
1290
|
+
assets?: ReversePositionAssetSummaryDto[];
|
|
1291
|
+
}
|
|
1292
|
+
declare function reversePosition(baseUrl: string, positionId: string, payload?: ReversePositionRequestInput): Promise<ApiResponse<ReversePositionResponseDto>>;
|
|
1268
1293
|
interface CloseAllPositionsResultDto {
|
|
1269
1294
|
positionId: string;
|
|
1270
1295
|
success: boolean;
|
|
@@ -1346,6 +1371,7 @@ declare function usePosition(): {
|
|
|
1346
1371
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
1347
1372
|
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
1348
1373
|
readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
|
|
1374
|
+
readonly reversePosition: (positionId: string, payload?: ReversePositionRequestInput) => Promise<ApiResponse<ReversePositionResponseDto>>;
|
|
1349
1375
|
readonly closeAllPositions: (payload: CloseAllPositionsRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
1350
1376
|
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
1351
1377
|
readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
@@ -1893,5 +1919,5 @@ interface MarketDataState {
|
|
|
1893
1919
|
}
|
|
1894
1920
|
declare const useMarketData: zustand.UseBoundStore<zustand.StoreApi<MarketDataState>>;
|
|
1895
1921
|
|
|
1896
|
-
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, ReadyState, SYMBOL_DISPLAY_ALIASES, 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, matchesSymbolOrAlias, toDisplaySymbol, toHlSymbol, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllMids, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePnlCalendar, usePnlHeatmap, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1897
|
-
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, CloseExecutionType, ClosePositionExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CloseTriggerType, CollateralToken, CreateAgentWalletResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossAssetPriceTriggerParams, CrossMarginSummaryDto, CumFundingDto, EIP712AuthDetails, EIP712AuthDetailsRequest, ExecutionType, ExternalFillDto, ExternalLiquidationDto, ExtraAgent, GetAgentWalletResponseDto, GetEIP712MessageRequest, 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, PeriodSummary, PerpDex, PerpDexsResponse, PerpMetaAsset, PlatformAccountSummaryResponseDto, PnlCalendarAsset, PnlCalendarDay, PnlCalendarMonth, PnlCalendarOptions, PnlCalendarTimeframe, PnlCalendarTrade, PnlCalendarWeek, PnlHeatmapTimeframe, PnlHeatmapTrade, 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, UsePnlCalendarResult, UsePnlHeatmapResult, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserAbstraction, UserProfile, UserSelectionState, WatchlistAssetDto, WatchlistItemDto, WebData3AssetCtx, WebData3PerpDexState, WebData3Response, WebData3UserState, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1922
|
+
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, ReadyState, SYMBOL_DISPLAY_ALIASES, 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, matchesSymbolOrAlias, reversePosition, toDisplaySymbol, toHlSymbol, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllMids, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePnlCalendar, usePnlHeatmap, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1923
|
+
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, CloseExecutionType, ClosePositionExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CloseTriggerType, CollateralToken, CreateAgentWalletResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossAssetPriceTriggerParams, CrossMarginSummaryDto, CumFundingDto, EIP712AuthDetails, EIP712AuthDetailsRequest, ExecutionType, ExternalFillDto, ExternalLiquidationDto, ExtraAgent, GetAgentWalletResponseDto, GetEIP712MessageRequest, 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, PeriodSummary, PerpDex, PerpDexsResponse, PerpMetaAsset, PlatformAccountSummaryResponseDto, PnlCalendarAsset, PnlCalendarDay, PnlCalendarMonth, PnlCalendarOptions, PnlCalendarTimeframe, PnlCalendarTrade, PnlCalendarWeek, PnlHeatmapTimeframe, PnlHeatmapTrade, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PredictionMarketOutcomeTriggerParams, PriceRatioTriggerParams, PriceTriggerParams, PrivyAuthDetails, RawAssetDto, RawPositionDto, RealtimeBar, RealtimeBarsCallback, RebalanceAssetPlan, RebalancePlan, RefreshTokenRequest, RefreshTokenResponse, ReverseExecutionType, ReversePositionAssetSummaryDto, ReversePositionExecutionType, ReversePositionRequestInput, ReversePositionResponseDto, 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, UsePnlCalendarResult, UsePnlHeatmapResult, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserAbstraction, UserProfile, UserSelectionState, WatchlistAssetDto, WatchlistItemDto, WebData3AssetCtx, WebData3PerpDexState, WebData3Response, WebData3UserState, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -6801,6 +6801,8 @@ const CANDLE_INTERVAL_MS = {
|
|
|
6801
6801
|
'1w': 7 * 24 * 60 * 60 * 1000,
|
|
6802
6802
|
'1M': 30 * 24 * 60 * 60 * 1000,
|
|
6803
6803
|
};
|
|
6804
|
+
const FIXED_PRICE_SYMBOLS = new Set(['USDC', 'USDH', 'USDE', 'USDT0']);
|
|
6805
|
+
const isFixedPriceSymbol = (symbol) => FIXED_PRICE_SYMBOLS.has(symbol.toUpperCase());
|
|
6804
6806
|
/**
|
|
6805
6807
|
* Composes historical price fetching with basket candle computation.
|
|
6806
6808
|
* - Listens to `longTokens` and `shortTokens` from user selection.
|
|
@@ -6931,7 +6933,7 @@ const useBasketCandles = () => {
|
|
|
6931
6933
|
for (const symbol of symbolSet) {
|
|
6932
6934
|
const c = candleData.get(symbol);
|
|
6933
6935
|
if (!c)
|
|
6934
|
-
|
|
6936
|
+
continue; // no candle feed (e.g. stablecoin), handled per-token below
|
|
6935
6937
|
snapshot[symbol] = c;
|
|
6936
6938
|
if (t === null || c.t > t) {
|
|
6937
6939
|
t = c.t;
|
|
@@ -6944,6 +6946,19 @@ const useBasketCandles = () => {
|
|
|
6944
6946
|
const maxCarryForwardMs = intervalMs * 2;
|
|
6945
6947
|
const getCandleForTargetWindow = (symbol) => {
|
|
6946
6948
|
const c = snapshot[symbol];
|
|
6949
|
+
if (!c) {
|
|
6950
|
+
if (!isFixedPriceSymbol(symbol))
|
|
6951
|
+
return null;
|
|
6952
|
+
return {
|
|
6953
|
+
s: symbol,
|
|
6954
|
+
t,
|
|
6955
|
+
T,
|
|
6956
|
+
o: 1,
|
|
6957
|
+
h: 1,
|
|
6958
|
+
l: 1,
|
|
6959
|
+
c: 1,
|
|
6960
|
+
};
|
|
6961
|
+
}
|
|
6947
6962
|
if (c.t === t)
|
|
6948
6963
|
return c;
|
|
6949
6964
|
if (c.t > t || t - c.t > maxCarryForwardMs)
|
|
@@ -6965,10 +6980,12 @@ const useBasketCandles = () => {
|
|
|
6965
6980
|
let longOpen = 1, longHigh = 1, longLow = 1, longClose = 1;
|
|
6966
6981
|
let shortOpen = 1, shortHigh = 1, shortLow = 1, shortClose = 1;
|
|
6967
6982
|
for (const token of longTokens) {
|
|
6983
|
+
const w = token.weight / 100;
|
|
6984
|
+
if (w === 0)
|
|
6985
|
+
continue;
|
|
6968
6986
|
const c = getCandleForTargetWindow(token.symbol);
|
|
6969
6987
|
if (!c)
|
|
6970
6988
|
return null;
|
|
6971
|
-
const w = token.weight / 100;
|
|
6972
6989
|
const o = c.o, h = c.h, l = c.l, cl = c.c;
|
|
6973
6990
|
if (!(o > 0 && h > 0 && l > 0 && cl > 0))
|
|
6974
6991
|
return null;
|
|
@@ -6978,10 +6995,12 @@ const useBasketCandles = () => {
|
|
|
6978
6995
|
longClose *= Math.pow(cl, w);
|
|
6979
6996
|
}
|
|
6980
6997
|
for (const token of shortTokens) {
|
|
6998
|
+
const w = -(token.weight / 100);
|
|
6999
|
+
if (w === 0)
|
|
7000
|
+
continue;
|
|
6981
7001
|
const c = getCandleForTargetWindow(token.symbol);
|
|
6982
7002
|
if (!c)
|
|
6983
7003
|
return null;
|
|
6984
|
-
const w = -(token.weight / 100);
|
|
6985
7004
|
const o = c.o, h = c.h, l = c.l, cl = c.c;
|
|
6986
7005
|
if (!(o > 0 && h > 0 && l > 0 && cl > 0))
|
|
6987
7006
|
return null;
|
|
@@ -7211,6 +7230,25 @@ async function closePosition(baseUrl, positionId, payload) {
|
|
|
7211
7230
|
throw toApiError(error);
|
|
7212
7231
|
}
|
|
7213
7232
|
}
|
|
7233
|
+
async function reversePosition(baseUrl, positionId, payload = {}) {
|
|
7234
|
+
const url = joinUrl(baseUrl, `/positions/${positionId}/reverse`);
|
|
7235
|
+
try {
|
|
7236
|
+
const resp = await apiClient.post(url, payload, {
|
|
7237
|
+
headers: {
|
|
7238
|
+
"Content-Type": "application/json",
|
|
7239
|
+
},
|
|
7240
|
+
timeout: 60000,
|
|
7241
|
+
});
|
|
7242
|
+
return {
|
|
7243
|
+
data: resp.data,
|
|
7244
|
+
status: resp.status,
|
|
7245
|
+
headers: resp.headers,
|
|
7246
|
+
};
|
|
7247
|
+
}
|
|
7248
|
+
catch (error) {
|
|
7249
|
+
throw toApiError(error);
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7214
7252
|
async function closeAllPositions(baseUrl, payload) {
|
|
7215
7253
|
const url = joinUrl(baseUrl, `/positions/close-all`);
|
|
7216
7254
|
try {
|
|
@@ -7459,6 +7497,9 @@ function usePosition() {
|
|
|
7459
7497
|
const closePosition$1 = async (positionId, payload) => {
|
|
7460
7498
|
return closePosition(apiBaseUrl, positionId, payload);
|
|
7461
7499
|
};
|
|
7500
|
+
const reversePosition$1 = async (positionId, payload = {}) => {
|
|
7501
|
+
return reversePosition(apiBaseUrl, positionId, payload);
|
|
7502
|
+
};
|
|
7462
7503
|
const closeAllPositions$1 = async (payload) => {
|
|
7463
7504
|
return closeAllPositions(apiBaseUrl, payload);
|
|
7464
7505
|
};
|
|
@@ -7577,6 +7618,7 @@ function usePosition() {
|
|
|
7577
7618
|
createPosition: createPosition$1,
|
|
7578
7619
|
updateRiskParameters: updateRiskParameters$1,
|
|
7579
7620
|
closePosition: closePosition$1,
|
|
7621
|
+
reversePosition: reversePosition$1,
|
|
7580
7622
|
closeAllPositions: closeAllPositions$1,
|
|
7581
7623
|
adjustPosition: adjustPosition$1,
|
|
7582
7624
|
adjustAdvancePosition: adjustAdvancePosition$1,
|
|
@@ -9483,4 +9525,4 @@ function getOrderTrailingInfo(order) {
|
|
|
9483
9525
|
return undefined;
|
|
9484
9526
|
}
|
|
9485
9527
|
|
|
9486
|
-
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, SYMBOL_DISPLAY_ALIASES, 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, matchesSymbolOrAlias, toDisplaySymbol, toHlSymbol, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllMids, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePnlCalendar, usePnlHeatmap, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
9528
|
+
export { ClosePositionValidationError, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, SYMBOL_DISPLAY_ALIASES, 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, matchesSymbolOrAlias, reversePosition, toDisplaySymbol, toHlSymbol, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useAgentWallet, useAllMids, useAllUserBalances, useAuth, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidUserFills, useMarket, useMarketData, useMarketDataHook, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePnlCalendar, usePnlHeatmap, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWatchlist, validateClosePositionRequest, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
package/dist/types.d.ts
CHANGED
|
@@ -316,6 +316,7 @@ export type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE' | 'PRIC
|
|
|
316
316
|
export type TriggerType = 'PRICE' | 'PRICE_LIMIT' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'BTC_DOM' | 'CROSS_ASSET_PRICE' | 'PREDICTION_MARKET_OUTCOME';
|
|
317
317
|
export type CloseTriggerType = 'PRICE' | 'PRICE_RATIO' | 'WEIGHTED_RATIO' | 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
|
|
318
318
|
export type CloseExecutionType = 'MARKET' | 'TWAP' | 'TRIGGER';
|
|
319
|
+
export type ReverseExecutionType = 'MARKET';
|
|
319
320
|
export type OrderDirection = 'MORE_THAN' | 'LESS_THAN';
|
|
320
321
|
/**
|
|
321
322
|
* Market order parameters
|