@pear-protocol/hyperliquid-sdk 0.1.18 → 0.1.19
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/hooks/usePosition.d.ts +21 -0
- package/dist/index.d.ts +24 -1
- package/dist/index.js +91 -7
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,5 +1,24 @@
|
|
|
1
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';
|
|
2
2
|
import type { ApiResponse, CreatePositionRequestInput, CreatePositionResponseDto, OpenPositionDto } from '../types';
|
|
3
|
+
export interface RebalanceAssetPlan {
|
|
4
|
+
coin: string;
|
|
5
|
+
side: 'long' | 'short';
|
|
6
|
+
currentWeight: number;
|
|
7
|
+
targetWeight: number;
|
|
8
|
+
currentValue: number;
|
|
9
|
+
targetValue: number;
|
|
10
|
+
deltaValue: number;
|
|
11
|
+
currentSize: number;
|
|
12
|
+
newSize: number;
|
|
13
|
+
deltaSize: number;
|
|
14
|
+
skipped: boolean;
|
|
15
|
+
skipReason?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RebalancePlan {
|
|
18
|
+
positionId: string;
|
|
19
|
+
assets: RebalanceAssetPlan[];
|
|
20
|
+
canExecute: boolean;
|
|
21
|
+
}
|
|
3
22
|
export declare function usePosition(): {
|
|
4
23
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
5
24
|
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
@@ -10,4 +29,6 @@ export declare function usePosition(): {
|
|
|
10
29
|
readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
11
30
|
readonly openPositions: OpenPositionDto[] | null;
|
|
12
31
|
readonly isLoading: boolean;
|
|
32
|
+
readonly planRebalance: (positionId: string, targetWeights?: Record<string, number>) => RebalancePlan;
|
|
33
|
+
readonly executeRebalance: (positionId: string, targetWeights?: Record<string, number>) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
13
34
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -286,6 +286,7 @@ interface PositionAssetDetailDto {
|
|
|
286
286
|
initialWeight: number;
|
|
287
287
|
currentWeight: number;
|
|
288
288
|
fundingPaid?: number;
|
|
289
|
+
targetWeight?: number;
|
|
289
290
|
metadata?: TokenMetadata | null;
|
|
290
291
|
}
|
|
291
292
|
interface TpSlThreshold {
|
|
@@ -763,6 +764,7 @@ interface RawAssetDto {
|
|
|
763
764
|
side: string;
|
|
764
765
|
fundingPaid?: number;
|
|
765
766
|
leverage: number;
|
|
767
|
+
targetWeight?: number;
|
|
766
768
|
}
|
|
767
769
|
/**
|
|
768
770
|
* Raw position data from open-positions channel
|
|
@@ -1295,6 +1297,25 @@ interface UpdateLeverageResponseDto {
|
|
|
1295
1297
|
}
|
|
1296
1298
|
declare function updateLeverage(baseUrl: string, positionId: string, payload: UpdateLeverageRequestInput): Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
1297
1299
|
|
|
1300
|
+
interface RebalanceAssetPlan {
|
|
1301
|
+
coin: string;
|
|
1302
|
+
side: 'long' | 'short';
|
|
1303
|
+
currentWeight: number;
|
|
1304
|
+
targetWeight: number;
|
|
1305
|
+
currentValue: number;
|
|
1306
|
+
targetValue: number;
|
|
1307
|
+
deltaValue: number;
|
|
1308
|
+
currentSize: number;
|
|
1309
|
+
newSize: number;
|
|
1310
|
+
deltaSize: number;
|
|
1311
|
+
skipped: boolean;
|
|
1312
|
+
skipReason?: string;
|
|
1313
|
+
}
|
|
1314
|
+
interface RebalancePlan {
|
|
1315
|
+
positionId: string;
|
|
1316
|
+
assets: RebalanceAssetPlan[];
|
|
1317
|
+
canExecute: boolean;
|
|
1318
|
+
}
|
|
1298
1319
|
declare function usePosition(): {
|
|
1299
1320
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
1300
1321
|
readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
|
|
@@ -1305,6 +1326,8 @@ declare function usePosition(): {
|
|
|
1305
1326
|
readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
1306
1327
|
readonly openPositions: OpenPositionDto[] | null;
|
|
1307
1328
|
readonly isLoading: boolean;
|
|
1329
|
+
readonly planRebalance: (positionId: string, targetWeights?: Record<string, number>) => RebalancePlan;
|
|
1330
|
+
readonly executeRebalance: (positionId: string, targetWeights?: Record<string, number>) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
1308
1331
|
};
|
|
1309
1332
|
|
|
1310
1333
|
declare function useOrders(): {
|
|
@@ -1750,4 +1773,4 @@ interface MarketDataState {
|
|
|
1750
1773
|
declare const useMarketData: zustand.UseBoundStore<zustand.StoreApi<MarketDataState>>;
|
|
1751
1774
|
|
|
1752
1775
|
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 };
|
|
1753
|
-
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, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, 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, 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 };
|
|
1776
|
+
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, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, 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
|
@@ -1576,11 +1576,6 @@ const useAccountSummary = () => {
|
|
|
1576
1576
|
const aggregatedClearingHouseState = useHyperliquidData((state) => state.aggregatedClearingHouseState);
|
|
1577
1577
|
const registeredAgentWallets = useUserData((state) => state.userExtraAgents);
|
|
1578
1578
|
const isLoading = useMemo(() => {
|
|
1579
|
-
console.log('[USE ACCOUNT SUMMARY DEBUG] Loading check:', {
|
|
1580
|
-
platformAccountSummary,
|
|
1581
|
-
registeredAgentWallets,
|
|
1582
|
-
aggregatedClearingHouseState,
|
|
1583
|
-
});
|
|
1584
1579
|
return !platformAccountSummary || !registeredAgentWallets || !aggregatedClearingHouseState;
|
|
1585
1580
|
}, [platformAccountSummary, registeredAgentWallets, aggregatedClearingHouseState]);
|
|
1586
1581
|
// Create calculator and compute account summary
|
|
@@ -7098,6 +7093,7 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, t
|
|
|
7098
7093
|
initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
|
|
7099
7094
|
currentWeight: totalCurrentPositionSize > 0 ? currentNotional / totalCurrentPositionSize : 0,
|
|
7100
7095
|
fundingPaid: (_a = asset.fundingPaid) !== null && _a !== void 0 ? _a : 0,
|
|
7096
|
+
targetWeight: asset.targetWeight,
|
|
7101
7097
|
metadata,
|
|
7102
7098
|
};
|
|
7103
7099
|
};
|
|
@@ -7203,6 +7199,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
|
|
|
7203
7199
|
});
|
|
7204
7200
|
};
|
|
7205
7201
|
|
|
7202
|
+
const MIN_TRADE_SIZE_USD = 11;
|
|
7206
7203
|
function usePosition() {
|
|
7207
7204
|
const context = useContext(PearHyperliquidContext);
|
|
7208
7205
|
if (!context) {
|
|
@@ -7245,6 +7242,85 @@ function usePosition() {
|
|
|
7245
7242
|
return null;
|
|
7246
7243
|
return buildPositionValue(userOpenPositions, aggregatedClearingHouseState, getAssetByName);
|
|
7247
7244
|
}, [userOpenPositions, aggregatedClearingHouseState, tokenMetadata, getAssetByName]);
|
|
7245
|
+
const planRebalance = (positionId, targetWeights) => {
|
|
7246
|
+
var _a;
|
|
7247
|
+
if (!openPositions) {
|
|
7248
|
+
throw new Error('Open positions not loaded');
|
|
7249
|
+
}
|
|
7250
|
+
const position = openPositions.find((p) => p.positionId === positionId);
|
|
7251
|
+
if (!position) {
|
|
7252
|
+
throw new Error(`Position ${positionId} not found`);
|
|
7253
|
+
}
|
|
7254
|
+
const assets = [];
|
|
7255
|
+
const allAssets = [
|
|
7256
|
+
...position.longAssets.map((a) => ({ asset: a, side: 'long' })),
|
|
7257
|
+
...position.shortAssets.map((a) => ({ asset: a, side: 'short' })),
|
|
7258
|
+
];
|
|
7259
|
+
const totalValue = allAssets.reduce((sum, { asset }) => sum + asset.positionValue, 0);
|
|
7260
|
+
for (const { asset, side } of allAssets) {
|
|
7261
|
+
const tw = (_a = targetWeights === null || targetWeights === void 0 ? void 0 : targetWeights[asset.coin]) !== null && _a !== void 0 ? _a : asset.targetWeight;
|
|
7262
|
+
if (tw === undefined) {
|
|
7263
|
+
assets.push({
|
|
7264
|
+
coin: asset.coin,
|
|
7265
|
+
side,
|
|
7266
|
+
currentWeight: totalValue > 0 ? (asset.positionValue / totalValue) * 100 : 0,
|
|
7267
|
+
targetWeight: 0,
|
|
7268
|
+
currentValue: asset.positionValue,
|
|
7269
|
+
targetValue: asset.positionValue,
|
|
7270
|
+
deltaValue: 0,
|
|
7271
|
+
currentSize: asset.actualSize,
|
|
7272
|
+
newSize: asset.actualSize,
|
|
7273
|
+
deltaSize: 0,
|
|
7274
|
+
skipped: true,
|
|
7275
|
+
skipReason: 'No target weight defined',
|
|
7276
|
+
});
|
|
7277
|
+
continue;
|
|
7278
|
+
}
|
|
7279
|
+
const currentWeight = totalValue > 0 ? (asset.positionValue / totalValue) * 100 : 0;
|
|
7280
|
+
const targetValue = totalValue * (tw / 100);
|
|
7281
|
+
const deltaValue = targetValue - asset.positionValue;
|
|
7282
|
+
const currentPrice = asset.actualSize > 0 ? asset.positionValue / asset.actualSize : 0;
|
|
7283
|
+
const deltaSize = currentPrice > 0 ? deltaValue / currentPrice : 0;
|
|
7284
|
+
const newSize = asset.actualSize + deltaSize;
|
|
7285
|
+
const belowMinimum = Math.abs(deltaValue) > 0 && Math.abs(deltaValue) < MIN_TRADE_SIZE_USD;
|
|
7286
|
+
assets.push({
|
|
7287
|
+
coin: asset.coin,
|
|
7288
|
+
side,
|
|
7289
|
+
currentWeight,
|
|
7290
|
+
targetWeight: tw,
|
|
7291
|
+
currentValue: asset.positionValue,
|
|
7292
|
+
targetValue,
|
|
7293
|
+
deltaValue,
|
|
7294
|
+
currentSize: asset.actualSize,
|
|
7295
|
+
newSize,
|
|
7296
|
+
deltaSize,
|
|
7297
|
+
skipped: belowMinimum,
|
|
7298
|
+
skipReason: belowMinimum
|
|
7299
|
+
? `Trade size $${Math.abs(deltaValue).toFixed(2)} is below minimum $${MIN_TRADE_SIZE_USD}`
|
|
7300
|
+
: undefined,
|
|
7301
|
+
});
|
|
7302
|
+
}
|
|
7303
|
+
const canExecute = assets.some((a) => !a.skipped && Math.abs(a.deltaValue) > 0);
|
|
7304
|
+
return { positionId, assets, canExecute };
|
|
7305
|
+
};
|
|
7306
|
+
const executeRebalance = async (positionId, targetWeights) => {
|
|
7307
|
+
const plan = planRebalance(positionId, targetWeights);
|
|
7308
|
+
if (!plan.canExecute) {
|
|
7309
|
+
throw new Error('No executable rebalance changes — all below minimum trade size or no changes needed');
|
|
7310
|
+
}
|
|
7311
|
+
const executable = plan.assets.filter((a) => !a.skipped && Math.abs(a.deltaValue) > 0);
|
|
7312
|
+
const payload = [
|
|
7313
|
+
{
|
|
7314
|
+
longAssets: executable
|
|
7315
|
+
.filter((a) => a.side === 'long')
|
|
7316
|
+
.map((a) => ({ asset: a.coin, size: a.newSize })),
|
|
7317
|
+
shortAssets: executable
|
|
7318
|
+
.filter((a) => a.side === 'short')
|
|
7319
|
+
.map((a) => ({ asset: a.coin, size: a.newSize })),
|
|
7320
|
+
},
|
|
7321
|
+
];
|
|
7322
|
+
return adjustAdvancePosition$1(positionId, payload);
|
|
7323
|
+
};
|
|
7248
7324
|
return {
|
|
7249
7325
|
createPosition: createPosition$1,
|
|
7250
7326
|
updateRiskParameters: updateRiskParameters$1,
|
|
@@ -7255,6 +7331,8 @@ function usePosition() {
|
|
|
7255
7331
|
updateLeverage: updateLeverage$1,
|
|
7256
7332
|
openPositions,
|
|
7257
7333
|
isLoading,
|
|
7334
|
+
planRebalance,
|
|
7335
|
+
executeRebalance,
|
|
7258
7336
|
};
|
|
7259
7337
|
}
|
|
7260
7338
|
|
|
@@ -8070,14 +8148,20 @@ const useAllUserBalances = () => {
|
|
|
8070
8148
|
}
|
|
8071
8149
|
}
|
|
8072
8150
|
if (!availableToTrades['USDC']) {
|
|
8073
|
-
availableToTrades['USDC'] = parseFloat((aggregatedClearingHouseState === null || aggregatedClearingHouseState === void 0 ? void 0 : aggregatedClearingHouseState.marginSummary.accountValue) || '0') -
|
|
8151
|
+
availableToTrades['USDC'] = Math.max(0, parseFloat((aggregatedClearingHouseState === null || aggregatedClearingHouseState === void 0 ? void 0 : aggregatedClearingHouseState.marginSummary.accountValue) || '0') -
|
|
8152
|
+
parseFloat((aggregatedClearingHouseState === null || aggregatedClearingHouseState === void 0 ? void 0 : aggregatedClearingHouseState.marginSummary.totalMarginUsed) || '0'));
|
|
8074
8153
|
}
|
|
8075
8154
|
return {
|
|
8076
8155
|
spotBalances,
|
|
8077
8156
|
availableToTrades,
|
|
8078
8157
|
isLoading,
|
|
8079
8158
|
};
|
|
8080
|
-
}, [
|
|
8159
|
+
}, [
|
|
8160
|
+
spotState,
|
|
8161
|
+
longTokensMetadata,
|
|
8162
|
+
shortTokensMetadata,
|
|
8163
|
+
aggregatedClearingHouseState,
|
|
8164
|
+
]);
|
|
8081
8165
|
/**
|
|
8082
8166
|
* Calculate margin required for every collateral token based on asset leverages and size.
|
|
8083
8167
|
* Returns margin required per collateral and whether there's sufficient margin.
|
package/dist/types.d.ts
CHANGED
|
@@ -258,6 +258,7 @@ export interface PositionAssetDetailDto {
|
|
|
258
258
|
initialWeight: number;
|
|
259
259
|
currentWeight: number;
|
|
260
260
|
fundingPaid?: number;
|
|
261
|
+
targetWeight?: number;
|
|
261
262
|
metadata?: TokenMetadata | null;
|
|
262
263
|
}
|
|
263
264
|
export interface TpSlThreshold {
|
|
@@ -735,6 +736,7 @@ export interface RawAssetDto {
|
|
|
735
736
|
side: string;
|
|
736
737
|
fundingPaid?: number;
|
|
737
738
|
leverage: number;
|
|
739
|
+
targetWeight?: number;
|
|
738
740
|
}
|
|
739
741
|
/**
|
|
740
742
|
* Raw position data from open-positions channel
|