@pear-protocol/hyperliquid-sdk 0.0.54 → 0.0.55
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 +38 -2
- 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
|
@@ -5341,6 +5341,21 @@ const fetchUserFillsFromHyperliquid = async (user, startTime, aggregateByTime =
|
|
|
5341
5341
|
throw toApiError(error);
|
|
5342
5342
|
}
|
|
5343
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
|
+
};
|
|
5344
5359
|
/**
|
|
5345
5360
|
* Fetch all perp metas from HyperLiquid API
|
|
5346
5361
|
* Endpoint: https://api.hyperliquid.xyz/info
|
|
@@ -6010,7 +6025,7 @@ const syncFills = async (baseUrl, accessToken, payload) => {
|
|
|
6010
6025
|
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
6011
6026
|
*/
|
|
6012
6027
|
const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true, lastSyncAt = null, assetPositions) => {
|
|
6013
|
-
const firstStartTime = lastSyncAt ? Number(lastSyncAt) :
|
|
6028
|
+
const firstStartTime = lastSyncAt ? Number(lastSyncAt) : 0;
|
|
6014
6029
|
const allFills = [];
|
|
6015
6030
|
const seenTids = new Set();
|
|
6016
6031
|
let startTime = firstStartTime;
|
|
@@ -6032,7 +6047,28 @@ const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregat
|
|
|
6032
6047
|
startTime = last.time;
|
|
6033
6048
|
}
|
|
6034
6049
|
} while (batchSize === 2000);
|
|
6035
|
-
|
|
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 });
|
|
6036
6072
|
};
|
|
6037
6073
|
|
|
6038
6074
|
/**
|
package/dist/types.d.ts
CHANGED