@pear-protocol/hyperliquid-sdk 0.1.17 → 0.1.18-beta-1
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
|
@@ -1531,11 +1531,6 @@ const useAccountSummary = () => {
|
|
|
1531
1531
|
const aggregatedClearingHouseState = useHyperliquidData((state) => state.aggregatedClearingHouseState);
|
|
1532
1532
|
const registeredAgentWallets = useUserData((state) => state.userExtraAgents);
|
|
1533
1533
|
const isLoading = useMemo(() => {
|
|
1534
|
-
console.log('[USE ACCOUNT SUMMARY DEBUG] Loading check:', {
|
|
1535
|
-
platformAccountSummary,
|
|
1536
|
-
registeredAgentWallets,
|
|
1537
|
-
aggregatedClearingHouseState,
|
|
1538
|
-
});
|
|
1539
1534
|
return !platformAccountSummary || !registeredAgentWallets || !aggregatedClearingHouseState;
|
|
1540
1535
|
}, [platformAccountSummary, registeredAgentWallets, aggregatedClearingHouseState]);
|
|
1541
1536
|
// Create calculator and compute account summary
|
|
@@ -7053,6 +7048,7 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, t
|
|
|
7053
7048
|
initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
|
|
7054
7049
|
currentWeight: totalCurrentPositionSize > 0 ? currentNotional / totalCurrentPositionSize : 0,
|
|
7055
7050
|
fundingPaid: (_a = asset.fundingPaid) !== null && _a !== void 0 ? _a : 0,
|
|
7051
|
+
targetWeight: asset.targetWeight,
|
|
7056
7052
|
metadata,
|
|
7057
7053
|
};
|
|
7058
7054
|
};
|
|
@@ -7158,6 +7154,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
|
|
|
7158
7154
|
});
|
|
7159
7155
|
};
|
|
7160
7156
|
|
|
7157
|
+
const MIN_TRADE_SIZE_USD = 11;
|
|
7161
7158
|
function usePosition() {
|
|
7162
7159
|
const context = useContext(PearHyperliquidContext);
|
|
7163
7160
|
if (!context) {
|
|
@@ -7200,6 +7197,85 @@ function usePosition() {
|
|
|
7200
7197
|
return null;
|
|
7201
7198
|
return buildPositionValue(userOpenPositions, aggregatedClearingHouseState, getAssetByName);
|
|
7202
7199
|
}, [userOpenPositions, aggregatedClearingHouseState, tokenMetadata, getAssetByName]);
|
|
7200
|
+
const planRebalance = (positionId, targetWeights) => {
|
|
7201
|
+
var _a;
|
|
7202
|
+
if (!openPositions) {
|
|
7203
|
+
throw new Error('Open positions not loaded');
|
|
7204
|
+
}
|
|
7205
|
+
const position = openPositions.find((p) => p.positionId === positionId);
|
|
7206
|
+
if (!position) {
|
|
7207
|
+
throw new Error(`Position ${positionId} not found`);
|
|
7208
|
+
}
|
|
7209
|
+
const assets = [];
|
|
7210
|
+
const allAssets = [
|
|
7211
|
+
...position.longAssets.map((a) => ({ asset: a, side: 'long' })),
|
|
7212
|
+
...position.shortAssets.map((a) => ({ asset: a, side: 'short' })),
|
|
7213
|
+
];
|
|
7214
|
+
const totalValue = allAssets.reduce((sum, { asset }) => sum + asset.positionValue, 0);
|
|
7215
|
+
for (const { asset, side } of allAssets) {
|
|
7216
|
+
const tw = (_a = targetWeights === null || targetWeights === void 0 ? void 0 : targetWeights[asset.coin]) !== null && _a !== void 0 ? _a : asset.targetWeight;
|
|
7217
|
+
if (tw === undefined) {
|
|
7218
|
+
assets.push({
|
|
7219
|
+
coin: asset.coin,
|
|
7220
|
+
side,
|
|
7221
|
+
currentWeight: totalValue > 0 ? (asset.positionValue / totalValue) * 100 : 0,
|
|
7222
|
+
targetWeight: 0,
|
|
7223
|
+
currentValue: asset.positionValue,
|
|
7224
|
+
targetValue: asset.positionValue,
|
|
7225
|
+
deltaValue: 0,
|
|
7226
|
+
currentSize: asset.actualSize,
|
|
7227
|
+
newSize: asset.actualSize,
|
|
7228
|
+
deltaSize: 0,
|
|
7229
|
+
skipped: true,
|
|
7230
|
+
skipReason: 'No target weight defined',
|
|
7231
|
+
});
|
|
7232
|
+
continue;
|
|
7233
|
+
}
|
|
7234
|
+
const currentWeight = totalValue > 0 ? (asset.positionValue / totalValue) * 100 : 0;
|
|
7235
|
+
const targetValue = totalValue * (tw / 100);
|
|
7236
|
+
const deltaValue = targetValue - asset.positionValue;
|
|
7237
|
+
const currentPrice = asset.actualSize > 0 ? asset.positionValue / asset.actualSize : 0;
|
|
7238
|
+
const deltaSize = currentPrice > 0 ? deltaValue / currentPrice : 0;
|
|
7239
|
+
const newSize = asset.actualSize + deltaSize;
|
|
7240
|
+
const belowMinimum = Math.abs(deltaValue) > 0 && Math.abs(deltaValue) < MIN_TRADE_SIZE_USD;
|
|
7241
|
+
assets.push({
|
|
7242
|
+
coin: asset.coin,
|
|
7243
|
+
side,
|
|
7244
|
+
currentWeight,
|
|
7245
|
+
targetWeight: tw,
|
|
7246
|
+
currentValue: asset.positionValue,
|
|
7247
|
+
targetValue,
|
|
7248
|
+
deltaValue,
|
|
7249
|
+
currentSize: asset.actualSize,
|
|
7250
|
+
newSize,
|
|
7251
|
+
deltaSize,
|
|
7252
|
+
skipped: belowMinimum,
|
|
7253
|
+
skipReason: belowMinimum
|
|
7254
|
+
? `Trade size $${Math.abs(deltaValue).toFixed(2)} is below minimum $${MIN_TRADE_SIZE_USD}`
|
|
7255
|
+
: undefined,
|
|
7256
|
+
});
|
|
7257
|
+
}
|
|
7258
|
+
const canExecute = assets.some((a) => !a.skipped && Math.abs(a.deltaValue) > 0);
|
|
7259
|
+
return { positionId, assets, canExecute };
|
|
7260
|
+
};
|
|
7261
|
+
const executeRebalance = async (positionId, targetWeights) => {
|
|
7262
|
+
const plan = planRebalance(positionId, targetWeights);
|
|
7263
|
+
if (!plan.canExecute) {
|
|
7264
|
+
throw new Error('No executable rebalance changes — all below minimum trade size or no changes needed');
|
|
7265
|
+
}
|
|
7266
|
+
const executable = plan.assets.filter((a) => !a.skipped && Math.abs(a.deltaValue) > 0);
|
|
7267
|
+
const payload = [
|
|
7268
|
+
{
|
|
7269
|
+
longAssets: executable
|
|
7270
|
+
.filter((a) => a.side === 'long')
|
|
7271
|
+
.map((a) => ({ asset: a.coin, size: a.newSize })),
|
|
7272
|
+
shortAssets: executable
|
|
7273
|
+
.filter((a) => a.side === 'short')
|
|
7274
|
+
.map((a) => ({ asset: a.coin, size: a.newSize })),
|
|
7275
|
+
},
|
|
7276
|
+
];
|
|
7277
|
+
return adjustAdvancePosition$1(positionId, payload);
|
|
7278
|
+
};
|
|
7203
7279
|
return {
|
|
7204
7280
|
createPosition: createPosition$1,
|
|
7205
7281
|
updateRiskParameters: updateRiskParameters$1,
|
|
@@ -7210,6 +7286,8 @@ function usePosition() {
|
|
|
7210
7286
|
updateLeverage: updateLeverage$1,
|
|
7211
7287
|
openPositions,
|
|
7212
7288
|
isLoading,
|
|
7289
|
+
planRebalance,
|
|
7290
|
+
executeRebalance,
|
|
7213
7291
|
};
|
|
7214
7292
|
}
|
|
7215
7293
|
|
|
@@ -8025,14 +8103,20 @@ const useAllUserBalances = () => {
|
|
|
8025
8103
|
}
|
|
8026
8104
|
}
|
|
8027
8105
|
if (!availableToTrades['USDC']) {
|
|
8028
|
-
availableToTrades['USDC'] = parseFloat((aggregatedClearingHouseState === null || aggregatedClearingHouseState === void 0 ? void 0 : aggregatedClearingHouseState.marginSummary.accountValue) || '0') -
|
|
8106
|
+
availableToTrades['USDC'] = Math.max(0, parseFloat((aggregatedClearingHouseState === null || aggregatedClearingHouseState === void 0 ? void 0 : aggregatedClearingHouseState.marginSummary.accountValue) || '0') -
|
|
8107
|
+
parseFloat((aggregatedClearingHouseState === null || aggregatedClearingHouseState === void 0 ? void 0 : aggregatedClearingHouseState.marginSummary.totalMarginUsed) || '0'));
|
|
8029
8108
|
}
|
|
8030
8109
|
return {
|
|
8031
8110
|
spotBalances,
|
|
8032
8111
|
availableToTrades,
|
|
8033
8112
|
isLoading,
|
|
8034
8113
|
};
|
|
8035
|
-
}, [
|
|
8114
|
+
}, [
|
|
8115
|
+
spotState,
|
|
8116
|
+
longTokensMetadata,
|
|
8117
|
+
shortTokensMetadata,
|
|
8118
|
+
aggregatedClearingHouseState,
|
|
8119
|
+
]);
|
|
8036
8120
|
/**
|
|
8037
8121
|
* Calculate margin required for every collateral token based on asset leverages and size.
|
|
8038
8122
|
* 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
|