@pear-protocol/hyperliquid-sdk 0.0.53 → 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.
@@ -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 && reconnectAttemptsRef.current < 5) {
202
+ if (!manualCloseRef.current) {
203
+ setLastSubscribedAddress(null);
202
204
  reconnectAttemptsRef.current += 1;
203
205
  setTimeout(() => connect(), 3000);
204
206
  }
@@ -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) : 1735660800000;
6028
+ const firstStartTime = lastSyncAt ? Number(lastSyncAt) : 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
- return syncFills(baseUrl, accessToken, { user, fills: allFills, assetPositions });
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
  /**
package/dist/types.d.ts CHANGED
@@ -45,6 +45,10 @@ export interface SyncFillsResponseDto {
45
45
  createdPositions: number;
46
46
  closedPositions: number;
47
47
  }
48
+ export interface TwapSliceFillResponseItem {
49
+ fill: ExternalFillDto;
50
+ twapId: number;
51
+ }
48
52
  /**
49
53
  * WebSocket connection states
50
54
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",