@pear-protocol/hyperliquid-sdk 0.0.53 → 0.0.55-fix
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/hyperliquid.d.ts +5 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +46 -7
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiResponse, CandleInterval, CandleData, ExternalFillDto, AllPerpMetasResponse, ExtraAgent } from '../types';
|
|
1
|
+
import type { ApiResponse, CandleInterval, CandleData, ExternalFillDto, AllPerpMetasResponse, ExtraAgent, TwapSliceFillResponseItem } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Fetch historical candle data from HyperLiquid API
|
|
4
4
|
*/
|
|
@@ -7,6 +7,10 @@ export declare const fetchHistoricalCandles: (coin: string, startTime: number, e
|
|
|
7
7
|
* Retrieve recent user fills from HyperLiquid and map to ExternalFillDto[]
|
|
8
8
|
*/
|
|
9
9
|
export declare const fetchUserFillsFromHyperliquid: (user: string, startTime: number, aggregateByTime?: boolean) => Promise<ApiResponse<ExternalFillDto[]>>;
|
|
10
|
+
/**
|
|
11
|
+
* Retrieve user TWAP slice fills from HyperLiquid and map to ExternalFillDto within items
|
|
12
|
+
*/
|
|
13
|
+
export declare const fetchUserTwapSliceFillsByTime: (user: string, startTime: number, aggregateByTime?: boolean) => Promise<ApiResponse<TwapSliceFillResponseItem[]>>;
|
|
10
14
|
/**
|
|
11
15
|
* Fetch all perp metas from HyperLiquid API
|
|
12
16
|
* Endpoint: https://api.hyperliquid.xyz/info
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,27 @@ interface ApiResponse<T> {
|
|
|
13
13
|
status: number;
|
|
14
14
|
headers: Record<string, string>;
|
|
15
15
|
}
|
|
16
|
+
interface ExternalLiquidationDto {
|
|
17
|
+
liquidatedUser: string;
|
|
18
|
+
markPx: string;
|
|
19
|
+
method: string;
|
|
20
|
+
}
|
|
21
|
+
interface ExternalFillDto {
|
|
22
|
+
coin: string;
|
|
23
|
+
px: string;
|
|
24
|
+
sz: string;
|
|
25
|
+
side: 'B' | 'A';
|
|
26
|
+
time: number;
|
|
27
|
+
dir: string;
|
|
28
|
+
fee: string;
|
|
29
|
+
builderFee?: string;
|
|
30
|
+
oid?: string | number;
|
|
31
|
+
tid?: string | number;
|
|
32
|
+
cloid?: string | null;
|
|
33
|
+
hash?: string | null;
|
|
34
|
+
feeToken?: string | null;
|
|
35
|
+
liquidation?: ExternalLiquidationDto | null;
|
|
36
|
+
}
|
|
16
37
|
interface SyncFillsResponseDto {
|
|
17
38
|
insertedFills: number;
|
|
18
39
|
skippedDuplicates: number;
|
|
@@ -21,6 +42,10 @@ interface SyncFillsResponseDto {
|
|
|
21
42
|
createdPositions: number;
|
|
22
43
|
closedPositions: number;
|
|
23
44
|
}
|
|
45
|
+
interface TwapSliceFillResponseItem {
|
|
46
|
+
fill: ExternalFillDto;
|
|
47
|
+
twapId: number;
|
|
48
|
+
}
|
|
24
49
|
/**
|
|
25
50
|
* WebSocket connection states
|
|
26
51
|
*/
|
|
@@ -1248,4 +1273,4 @@ declare function validatePositionSize(usdValue: number, longAssets?: PairAssetIn
|
|
|
1248
1273
|
declare const useMarketData: any;
|
|
1249
1274
|
|
|
1250
1275
|
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateMinimumPositionValue, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, getPortfolio, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, markNotificationsRead, toggleWatchlist, updateRiskParameters, useAccountSummary, useActiveBaskets, useAgentWallet, useAllBaskets, useAutoSyncFills, useBasketCandles, useFindBasket, useHighlightedBaskets, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useMarketData, useMarketDataAllPayload, useMarketDataPayload, useNotifications, useOpenOrders, useOrders, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePortfolio, usePosition, useTokenSelectionMetadata, useTopGainers, useTopLosers, useTradeHistories, useTwap, useUserSelection, useWatchlist, useWatchlistBaskets, useWebData, validateMinimumAssetSize, validatePositionSize };
|
|
1251
|
-
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, 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, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
1276
|
+
export type { AccountSummaryResponseDto, ActiveAssetGroupItem, ActiveAssetsResponse, 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, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, ExtraAgent, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetDto, PairAssetInput, PerformanceOverlay, PlatformAccountSummaryResponseDto, PortfolioBucketDto, PortfolioInterval, PortfolioIntervalsDto, PortfolioOverallDto, PortfolioResponseDto, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, ToggleWatchlistResponseDto, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, TwapSliceFillResponseItem, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UsePortfolioResult, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WatchlistItemDto, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
package/dist/index.js
CHANGED
|
@@ -188,6 +188,7 @@ const useHyperliquidWebSocket = ({ wsUrl, address, enabled = true, }) => {
|
|
|
188
188
|
const ws = new WebSocket(wsUrl);
|
|
189
189
|
wsRef.current = ws;
|
|
190
190
|
ws.onopen = () => {
|
|
191
|
+
// Reset attempts on successful connection
|
|
191
192
|
reconnectAttemptsRef.current = 0;
|
|
192
193
|
setReadyState(ReadyState.OPEN);
|
|
193
194
|
setLastError(null);
|
|
@@ -198,7 +199,8 @@ const useHyperliquidWebSocket = ({ wsUrl, address, enabled = true, }) => {
|
|
|
198
199
|
};
|
|
199
200
|
ws.onclose = () => {
|
|
200
201
|
setReadyState(ReadyState.CLOSED);
|
|
201
|
-
if (!manualCloseRef.current
|
|
202
|
+
if (!manualCloseRef.current) {
|
|
203
|
+
setLastSubscribedAddress(null);
|
|
202
204
|
reconnectAttemptsRef.current += 1;
|
|
203
205
|
setTimeout(() => connect(), 3000);
|
|
204
206
|
}
|
|
@@ -4789,8 +4791,8 @@ const useAccountSummary = () => {
|
|
|
4789
4791
|
const aggregatedClearingHouseState = useHyperliquidData((state) => state.aggregatedClearingHouseState);
|
|
4790
4792
|
const registeredAgentWallets = useUserData((state) => state.userExtraAgents);
|
|
4791
4793
|
const isLoading = useMemo(() => {
|
|
4792
|
-
return platformAccountSummary
|
|
4793
|
-
}, [platformAccountSummary,
|
|
4794
|
+
return !platformAccountSummary || !registeredAgentWallets || !aggregatedClearingHouseState;
|
|
4795
|
+
}, [platformAccountSummary, registeredAgentWallets, aggregatedClearingHouseState]);
|
|
4794
4796
|
// Create calculator and compute account summary
|
|
4795
4797
|
const calculator = new AccountSummaryCalculator(aggregatedClearingHouseState);
|
|
4796
4798
|
const calculated = calculator.calculateAccountSummary(platformAccountSummary, registeredAgentWallets || []);
|
|
@@ -4841,7 +4843,7 @@ const useWebData = () => {
|
|
|
4841
4843
|
const finalAtOICaps = useHyperliquidData((state) => state.finalAtOICaps);
|
|
4842
4844
|
const hip3Assets = useHyperliquidData((state) => state.hip3DisplayToFull);
|
|
4843
4845
|
let marketDataBySymbol = {};
|
|
4844
|
-
if (finalAssetContexts && perpMetaAssets
|
|
4846
|
+
if (finalAssetContexts && perpMetaAssets) {
|
|
4845
4847
|
const result = {};
|
|
4846
4848
|
for (let index = 0; index < perpMetaAssets.length; index++) {
|
|
4847
4849
|
const name = perpMetaAssets[index].name;
|
|
@@ -5339,6 +5341,21 @@ const fetchUserFillsFromHyperliquid = async (user, startTime, aggregateByTime =
|
|
|
5339
5341
|
throw toApiError(error);
|
|
5340
5342
|
}
|
|
5341
5343
|
};
|
|
5344
|
+
/**
|
|
5345
|
+
* Retrieve user TWAP slice fills from HyperLiquid and map to ExternalFillDto within items
|
|
5346
|
+
*/
|
|
5347
|
+
const fetchUserTwapSliceFillsByTime = async (user, startTime, aggregateByTime = true) => {
|
|
5348
|
+
const request = { type: 'userTwapSliceFillsByTime', user, startTime, aggregateByTime };
|
|
5349
|
+
try {
|
|
5350
|
+
const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
|
|
5351
|
+
headers: { 'Content-Type': 'application/json' },
|
|
5352
|
+
});
|
|
5353
|
+
return { data: response.data, status: response.status, headers: response.headers };
|
|
5354
|
+
}
|
|
5355
|
+
catch (error) {
|
|
5356
|
+
throw toApiError(error);
|
|
5357
|
+
}
|
|
5358
|
+
};
|
|
5342
5359
|
/**
|
|
5343
5360
|
* Fetch all perp metas from HyperLiquid API
|
|
5344
5361
|
* Endpoint: https://api.hyperliquid.xyz/info
|
|
@@ -6008,7 +6025,7 @@ const syncFills = async (baseUrl, accessToken, payload) => {
|
|
|
6008
6025
|
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
6009
6026
|
*/
|
|
6010
6027
|
const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true, lastSyncAt = null, assetPositions) => {
|
|
6011
|
-
const firstStartTime = lastSyncAt ? Number(lastSyncAt) :
|
|
6028
|
+
const firstStartTime = lastSyncAt ? Number(lastSyncAt) + 1 : 0;
|
|
6012
6029
|
const allFills = [];
|
|
6013
6030
|
const seenTids = new Set();
|
|
6014
6031
|
let startTime = firstStartTime;
|
|
@@ -6030,7 +6047,28 @@ const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregat
|
|
|
6030
6047
|
startTime = last.time;
|
|
6031
6048
|
}
|
|
6032
6049
|
} while (batchSize === 2000);
|
|
6033
|
-
|
|
6050
|
+
startTime = firstStartTime;
|
|
6051
|
+
batchSize = 0;
|
|
6052
|
+
do {
|
|
6053
|
+
const { data: twapBatch } = await fetchUserTwapSliceFillsByTime(user, startTime, aggregateByTime);
|
|
6054
|
+
batchSize = twapBatch.length;
|
|
6055
|
+
for (const item of twapBatch) {
|
|
6056
|
+
const fill = item.fill;
|
|
6057
|
+
const tid = fill.tid;
|
|
6058
|
+
if (tid === undefined)
|
|
6059
|
+
continue;
|
|
6060
|
+
if (!seenTids.has(tid)) {
|
|
6061
|
+
seenTids.add(tid);
|
|
6062
|
+
allFills.push(fill);
|
|
6063
|
+
}
|
|
6064
|
+
}
|
|
6065
|
+
if (batchSize === 2000) {
|
|
6066
|
+
const last = twapBatch[twapBatch.length - 1];
|
|
6067
|
+
startTime = last.fill.time;
|
|
6068
|
+
}
|
|
6069
|
+
} while (batchSize === 2000);
|
|
6070
|
+
const sortedFills = [...allFills].sort((a, b) => Number(a.time) - Number(b.time));
|
|
6071
|
+
return syncFills(baseUrl, accessToken, { user, fills: sortedFills, assetPositions });
|
|
6034
6072
|
};
|
|
6035
6073
|
|
|
6036
6074
|
/**
|
|
@@ -6818,7 +6856,8 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
6818
6856
|
useEffect(() => {
|
|
6819
6857
|
if (perpsMetaAssets === null) {
|
|
6820
6858
|
fetchAllPerpMetas().then(res => {
|
|
6821
|
-
|
|
6859
|
+
// Only show HL and XYZ for now as other are using USDH collateral and need more work
|
|
6860
|
+
const aggregatedPerpMetas = res.data.slice(0, 2).flatMap(item => item.universe);
|
|
6822
6861
|
const hip3Map = new Map();
|
|
6823
6862
|
const displayToFull = new Map();
|
|
6824
6863
|
const cleanedPerpMetas = aggregatedPerpMetas.map((asset) => {
|
package/dist/types.d.ts
CHANGED