@pear-protocol/hyperliquid-sdk 0.0.66-usdh-3 → 0.0.66-usdh-5
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 +7 -0
- package/dist/hooks/usePosition.d.ts +2 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.js +62 -35
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -126,3 +126,10 @@ export interface AdjustAdvanceResponseDto {
|
|
|
126
126
|
}
|
|
127
127
|
export declare function adjustAdvancePosition(baseUrl: string, positionId: string, payload: AdjustAdvanceItemInput[], hip3Assets: Map<string, string[]>): Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
128
128
|
export declare function cancelTwap(baseUrl: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
129
|
+
export interface UpdateLeverageRequestInput {
|
|
130
|
+
leverage: number;
|
|
131
|
+
}
|
|
132
|
+
export interface UpdateLeverageResponseDto {
|
|
133
|
+
message?: string;
|
|
134
|
+
}
|
|
135
|
+
export declare function updateLeverage(baseUrl: string, positionId: string, payload: UpdateLeverageRequestInput): Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CreatePositionRequestInput, type CreatePositionResponseDto, type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type CloseAllPositionsResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto, type AdjustAdvanceItemInput, type AdjustAdvanceResponseDto } from '../clients/positions';
|
|
1
|
+
import { type CreatePositionRequestInput, type CreatePositionResponseDto, 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, OpenPositionDto } from '../types';
|
|
3
3
|
export declare function usePosition(): {
|
|
4
4
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
@@ -7,6 +7,7 @@ export declare function usePosition(): {
|
|
|
7
7
|
readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
8
8
|
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
9
9
|
readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
10
|
+
readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
10
11
|
readonly openPositions: OpenPositionDto[] | null;
|
|
11
12
|
readonly isLoading: boolean;
|
|
12
13
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -580,6 +580,7 @@ interface RawAssetDto {
|
|
|
580
580
|
fundingPaid?: number;
|
|
581
581
|
marketPrefix?: string | null;
|
|
582
582
|
collateralToken?: CollateralToken;
|
|
583
|
+
leverage: number;
|
|
583
584
|
}
|
|
584
585
|
/**
|
|
585
586
|
* Raw position data from open-positions channel
|
|
@@ -1117,6 +1118,13 @@ interface AdjustAdvanceResponseDto {
|
|
|
1117
1118
|
}
|
|
1118
1119
|
declare function adjustAdvancePosition(baseUrl: string, positionId: string, payload: AdjustAdvanceItemInput[], hip3Assets: Map<string, string[]>): Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
1119
1120
|
declare function cancelTwap(baseUrl: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
1121
|
+
interface UpdateLeverageRequestInput {
|
|
1122
|
+
leverage: number;
|
|
1123
|
+
}
|
|
1124
|
+
interface UpdateLeverageResponseDto {
|
|
1125
|
+
message?: string;
|
|
1126
|
+
}
|
|
1127
|
+
declare function updateLeverage(baseUrl: string, positionId: string, payload: UpdateLeverageRequestInput): Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
1120
1128
|
|
|
1121
1129
|
declare function usePosition(): {
|
|
1122
1130
|
readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
|
|
@@ -1125,6 +1133,7 @@ declare function usePosition(): {
|
|
|
1125
1133
|
readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
|
|
1126
1134
|
readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
|
|
1127
1135
|
readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
|
|
1136
|
+
readonly updateLeverage: (positionId: string, leverage: number) => Promise<ApiResponse<UpdateLeverageResponseDto | null>>;
|
|
1128
1137
|
readonly openPositions: OpenPositionDto[] | null;
|
|
1129
1138
|
readonly isLoading: boolean;
|
|
1130
1139
|
};
|
|
@@ -1502,5 +1511,5 @@ declare function isHip3Market(symbol: string): boolean;
|
|
|
1502
1511
|
|
|
1503
1512
|
declare const useMarketData: any;
|
|
1504
1513
|
|
|
1505
|
-
export { AccountSummaryCalculator, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAllUserBalances, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1506
|
-
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotBalance, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1514
|
+
export { AccountSummaryCalculator, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAllUserBalances, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
1515
|
+
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, AdjustAdvanceAssetInput, AdjustAdvanceItemInput, AdjustAdvanceResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseAllPositionsResponseDto, CloseAllPositionsResultDto, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CollateralFilter, CollateralToken, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, MarketDataBySymbol, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, SpotBalance, SpotOrderFilledStatus, SpotOrderHyperliquidData, SpotOrderHyperliquidResult, SpotOrderRequestInput, SpotOrderResponseDto, SpotState, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateLeverageRequestInput, UpdateLeverageResponseDto, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseSpotOrderResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -779,8 +779,8 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
779
779
|
case 'allDexsAssetCtxs':
|
|
780
780
|
{
|
|
781
781
|
const data = response.data;
|
|
782
|
-
// Filter out
|
|
783
|
-
const FILTERED_DEX_PREFIXES = ['
|
|
782
|
+
// Filter out hyna to match perpMetaAssets filtering
|
|
783
|
+
const FILTERED_DEX_PREFIXES = ['hyna'];
|
|
784
784
|
const filtered = (data.ctxs || [])
|
|
785
785
|
.filter(([prefix]) => !FILTERED_DEX_PREFIXES.includes((prefix || '').toLowerCase()))
|
|
786
786
|
.sort((a, b) => {
|
|
@@ -923,7 +923,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
923
923
|
}
|
|
924
924
|
manualCloseRef.current = false;
|
|
925
925
|
setReadyState(ReadyState.CONNECTING);
|
|
926
|
-
const ws = new WebSocket(
|
|
926
|
+
const ws = new WebSocket("wss://api.hyperliquid.xyz/ws");
|
|
927
927
|
wsRef.current = ws;
|
|
928
928
|
ws.onopen = () => {
|
|
929
929
|
reconnectAttemptsRef.current = 0;
|
|
@@ -932,8 +932,8 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
932
932
|
};
|
|
933
933
|
ws.onmessage = handleMessage;
|
|
934
934
|
ws.onerror = (event) => {
|
|
935
|
-
console.error(
|
|
936
|
-
setLastError(
|
|
935
|
+
console.error("[HyperLiquid WS] Connection error:", event);
|
|
936
|
+
setLastError("WebSocket error");
|
|
937
937
|
};
|
|
938
938
|
ws.onclose = () => {
|
|
939
939
|
setReadyState(ReadyState.CLOSED);
|
|
@@ -974,7 +974,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
974
974
|
if (isConnected) {
|
|
975
975
|
// Send ping every 30 seconds
|
|
976
976
|
pingIntervalRef.current = setInterval(() => {
|
|
977
|
-
sendJsonMessage({ method:
|
|
977
|
+
sendJsonMessage({ method: "ping" });
|
|
978
978
|
}, 30000);
|
|
979
979
|
}
|
|
980
980
|
else {
|
|
@@ -994,16 +994,16 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
994
994
|
useEffect(() => {
|
|
995
995
|
if (!isConnected)
|
|
996
996
|
return;
|
|
997
|
-
const DEFAULT_ADDRESS =
|
|
997
|
+
const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
998
998
|
const userAddress = address || DEFAULT_ADDRESS;
|
|
999
999
|
if (subscribedAddress === userAddress)
|
|
1000
1000
|
return;
|
|
1001
1001
|
// Unsubscribe from previous address if exists
|
|
1002
1002
|
if (subscribedAddress) {
|
|
1003
1003
|
const unsubscribeMessage = {
|
|
1004
|
-
method:
|
|
1004
|
+
method: "unsubscribe",
|
|
1005
1005
|
subscription: {
|
|
1006
|
-
type:
|
|
1006
|
+
type: "webData3",
|
|
1007
1007
|
user: subscribedAddress,
|
|
1008
1008
|
},
|
|
1009
1009
|
};
|
|
@@ -1020,42 +1020,42 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1020
1020
|
sendJsonMessage(unsubscribeSpotState);
|
|
1021
1021
|
}
|
|
1022
1022
|
const unsubscribeAllDexsClearinghouseState = {
|
|
1023
|
-
method:
|
|
1023
|
+
method: "unsubscribe",
|
|
1024
1024
|
subscription: {
|
|
1025
|
-
type:
|
|
1025
|
+
type: "allDexsClearinghouseState",
|
|
1026
1026
|
user: subscribedAddress,
|
|
1027
1027
|
},
|
|
1028
1028
|
};
|
|
1029
1029
|
sendJsonMessage(unsubscribeAllDexsClearinghouseState);
|
|
1030
1030
|
}
|
|
1031
1031
|
const subscribeWebData3 = {
|
|
1032
|
-
method:
|
|
1032
|
+
method: "subscribe",
|
|
1033
1033
|
subscription: {
|
|
1034
|
-
type:
|
|
1034
|
+
type: "webData3",
|
|
1035
1035
|
user: userAddress,
|
|
1036
1036
|
},
|
|
1037
1037
|
};
|
|
1038
1038
|
// Subscribe to allDexsClearinghouseState with the same payload as webData3
|
|
1039
1039
|
const subscribeAllDexsClearinghouseState = {
|
|
1040
|
-
method:
|
|
1040
|
+
method: "subscribe",
|
|
1041
1041
|
subscription: {
|
|
1042
|
-
type:
|
|
1042
|
+
type: "allDexsClearinghouseState",
|
|
1043
1043
|
user: userAddress,
|
|
1044
1044
|
},
|
|
1045
1045
|
};
|
|
1046
1046
|
// Subscribe to allMids
|
|
1047
1047
|
const subscribeAllMids = {
|
|
1048
|
-
method:
|
|
1048
|
+
method: "subscribe",
|
|
1049
1049
|
subscription: {
|
|
1050
|
-
type:
|
|
1051
|
-
dex:
|
|
1050
|
+
type: "allMids",
|
|
1051
|
+
dex: "ALL_DEXS",
|
|
1052
1052
|
},
|
|
1053
1053
|
};
|
|
1054
1054
|
// Subscribe to allDexsAssetCtxs (no payload params, global feed)
|
|
1055
1055
|
const subscribeAllDexsAssetCtxs = {
|
|
1056
|
-
method:
|
|
1056
|
+
method: "subscribe",
|
|
1057
1057
|
subscription: {
|
|
1058
|
-
type:
|
|
1058
|
+
type: "allDexsAssetCtxs",
|
|
1059
1059
|
},
|
|
1060
1060
|
};
|
|
1061
1061
|
sendJsonMessage(subscribeWebData3);
|
|
@@ -1102,9 +1102,9 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1102
1102
|
// Unsubscribe from tokens no longer in the list
|
|
1103
1103
|
tokensToUnsubscribe.forEach((token) => {
|
|
1104
1104
|
const unsubscribeMessage = {
|
|
1105
|
-
method:
|
|
1105
|
+
method: "unsubscribe",
|
|
1106
1106
|
subscription: {
|
|
1107
|
-
type:
|
|
1107
|
+
type: "activeAssetData",
|
|
1108
1108
|
user: address,
|
|
1109
1109
|
coin: token,
|
|
1110
1110
|
},
|
|
@@ -1114,9 +1114,9 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1114
1114
|
// Subscribe to new tokens
|
|
1115
1115
|
tokensToSubscribe.forEach((token) => {
|
|
1116
1116
|
const subscribeMessage = {
|
|
1117
|
-
method:
|
|
1117
|
+
method: "subscribe",
|
|
1118
1118
|
subscription: {
|
|
1119
|
-
type:
|
|
1119
|
+
type: "activeAssetData",
|
|
1120
1120
|
user: address,
|
|
1121
1121
|
coin: token,
|
|
1122
1122
|
},
|
|
@@ -1145,9 +1145,9 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1145
1145
|
if (prevInterval && prevInterval !== candleInterval) {
|
|
1146
1146
|
subscribedCandleTokens.forEach((token) => {
|
|
1147
1147
|
const unsubscribeMessage = {
|
|
1148
|
-
method:
|
|
1148
|
+
method: "unsubscribe",
|
|
1149
1149
|
subscription: {
|
|
1150
|
-
type:
|
|
1150
|
+
type: "candle",
|
|
1151
1151
|
coin: token,
|
|
1152
1152
|
interval: prevInterval,
|
|
1153
1153
|
},
|
|
@@ -1162,9 +1162,9 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1162
1162
|
// Unsubscribe from tokens no longer in the list
|
|
1163
1163
|
tokensToUnsubscribe.forEach((token) => {
|
|
1164
1164
|
const unsubscribeMessage = {
|
|
1165
|
-
method:
|
|
1165
|
+
method: "unsubscribe",
|
|
1166
1166
|
subscription: {
|
|
1167
|
-
type:
|
|
1167
|
+
type: "candle",
|
|
1168
1168
|
coin: token,
|
|
1169
1169
|
interval: candleInterval,
|
|
1170
1170
|
},
|
|
@@ -1174,9 +1174,9 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, }) => {
|
|
|
1174
1174
|
// Subscribe to new tokens
|
|
1175
1175
|
tokensToSubscribe.forEach((token) => {
|
|
1176
1176
|
const subscribeMessage = {
|
|
1177
|
-
method:
|
|
1177
|
+
method: "subscribe",
|
|
1178
1178
|
subscription: {
|
|
1179
|
-
type:
|
|
1179
|
+
type: "candle",
|
|
1180
1180
|
coin: token,
|
|
1181
1181
|
interval: candleInterval,
|
|
1182
1182
|
},
|
|
@@ -7019,6 +7019,28 @@ async function cancelTwap(baseUrl, orderId) {
|
|
|
7019
7019
|
throw toApiError(error);
|
|
7020
7020
|
}
|
|
7021
7021
|
}
|
|
7022
|
+
async function updateLeverage(baseUrl, positionId, payload) {
|
|
7023
|
+
var _a;
|
|
7024
|
+
const url = joinUrl(baseUrl, `/positions/${positionId}/adjust-leverage`);
|
|
7025
|
+
try {
|
|
7026
|
+
const resp = await apiClient.post(url, payload, {
|
|
7027
|
+
headers: {
|
|
7028
|
+
"Content-Type": "application/json",
|
|
7029
|
+
},
|
|
7030
|
+
timeout: 60000,
|
|
7031
|
+
});
|
|
7032
|
+
// If backend returns 204, resp.data may be empty; normalize to null for callers
|
|
7033
|
+
const normalizedData = ((_a = resp.data) !== null && _a !== void 0 ? _a : null);
|
|
7034
|
+
return {
|
|
7035
|
+
data: normalizedData,
|
|
7036
|
+
status: resp.status,
|
|
7037
|
+
headers: resp.headers,
|
|
7038
|
+
};
|
|
7039
|
+
}
|
|
7040
|
+
catch (error) {
|
|
7041
|
+
throw toApiError(error);
|
|
7042
|
+
}
|
|
7043
|
+
}
|
|
7022
7044
|
|
|
7023
7045
|
const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, isLong = true) => {
|
|
7024
7046
|
var _a;
|
|
@@ -7066,7 +7088,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
|
|
|
7066
7088
|
var _a, _b, _c;
|
|
7067
7089
|
const currentPrice = parseFloat(allMids.mids[longAsset.coin]);
|
|
7068
7090
|
const assetState = (_a = clearinghouseState.assetPositions.find(ap => toDisplaySymbol(ap.position.coin) === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
|
|
7069
|
-
const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c :
|
|
7091
|
+
const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : longAsset.leverage;
|
|
7070
7092
|
const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, leverage, true);
|
|
7071
7093
|
mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
|
|
7072
7094
|
mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
|
|
@@ -7080,7 +7102,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
|
|
|
7080
7102
|
var _a, _b, _c;
|
|
7081
7103
|
const currentPrice = parseFloat(allMids.mids[shortAsset.coin]);
|
|
7082
7104
|
const assetState = (_a = clearinghouseState.assetPositions.find(ap => toDisplaySymbol(ap.position.coin) === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
|
|
7083
|
-
const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c :
|
|
7105
|
+
const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : shortAsset.leverage;
|
|
7084
7106
|
const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, leverage, false);
|
|
7085
7107
|
mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
|
|
7086
7108
|
mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
|
|
@@ -7207,6 +7229,10 @@ function usePosition() {
|
|
|
7207
7229
|
const adjustAdvancePosition$1 = async (positionId, payload) => {
|
|
7208
7230
|
return adjustAdvancePosition(apiBaseUrl, positionId, payload, hip3Assets);
|
|
7209
7231
|
};
|
|
7232
|
+
const updateLeverage$1 = async (positionId, leverage) => {
|
|
7233
|
+
return updateLeverage(apiBaseUrl, positionId, { leverage });
|
|
7234
|
+
};
|
|
7235
|
+
// Open positions using WS data, with derived values
|
|
7210
7236
|
const userOpenPositions = useUserData((state) => state.rawOpenPositions);
|
|
7211
7237
|
const aggregatedClearingHouseState = useHyperliquidData((state) => state.aggregatedClearingHouseState);
|
|
7212
7238
|
const allMids = useHyperliquidData((state) => state.allMids);
|
|
@@ -7232,6 +7258,7 @@ function usePosition() {
|
|
|
7232
7258
|
closeAllPositions: closeAllPositions$1,
|
|
7233
7259
|
adjustPosition: adjustPosition$1,
|
|
7234
7260
|
adjustAdvancePosition: adjustAdvancePosition$1,
|
|
7261
|
+
updateLeverage: updateLeverage$1,
|
|
7235
7262
|
openPositions,
|
|
7236
7263
|
isLoading,
|
|
7237
7264
|
};
|
|
@@ -8266,9 +8293,9 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-ui.pearpro
|
|
|
8266
8293
|
.then((res) => {
|
|
8267
8294
|
const assetToMarkets = new Map();
|
|
8268
8295
|
const marketPrefixes = new Map();
|
|
8269
|
-
const FILTERED_PREFIXES = ['
|
|
8296
|
+
const FILTERED_PREFIXES = ['hyna'];
|
|
8270
8297
|
// Group assets by market prefix to match WebSocket flattening order
|
|
8271
|
-
// WebSocket sends in order: "", "flx", "hyna", "vntl", "xyz"
|
|
8298
|
+
// WebSocket sends in order: "", "flx", "hyna", "vntl", "xyz" (we filter out hyna)
|
|
8272
8299
|
const assetsByPrefix = new Map();
|
|
8273
8300
|
const allAssetsByPrefix = new Map();
|
|
8274
8301
|
res.data.forEach((item) => {
|
|
@@ -8493,4 +8520,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8493
8520
|
}
|
|
8494
8521
|
}
|
|
8495
8522
|
|
|
8496
|
-
export { AccountSummaryCalculator, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAllUserBalances, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
|
8523
|
+
export { AccountSummaryCalculator, ConflictDetector, MAX_ASSETS_PER_LEG, MINIMUM_ASSET_USD_VALUE, MaxAssetsPerLegError, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, executeSpotOrder, getAvailableMarkets, getCompleteTimestamps, getMarketPrefix, getPortfolio, isHip3Market, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toBackendSymbol, toBackendSymbolWithMarket, toDisplaySymbol, toggleWatchlist, updateLeverage, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAllUserBalances, useAuth, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearHyperliquid, usePerformanceOverlays, usePerpMetaAssets, usePortfolio, usePosition, useSpotOrder, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMaxAssetsPerLeg, validateMinimumAssetSize, validatePositionSize };
|
package/dist/types.d.ts
CHANGED