@pear-protocol/hyperliquid-sdk 0.0.54 → 0.0.56

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
@@ -110,4 +110,18 @@ export interface AdjustPositionResponseDto {
110
110
  executedAt: string;
111
111
  }
112
112
  export declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
113
+ export interface AdjustAdvanceAssetInput {
114
+ asset: string;
115
+ size: number;
116
+ }
117
+ export interface AdjustAdvanceItemInput {
118
+ longAssets?: AdjustAdvanceAssetInput[];
119
+ shortAssets?: AdjustAdvanceAssetInput[];
120
+ }
121
+ export interface AdjustAdvanceResponseDto {
122
+ orderId: string;
123
+ status: string;
124
+ executedAt: string;
125
+ }
126
+ export declare function adjustAdvancePosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustAdvanceItemInput[], displayToFull: Map<string, string>): Promise<ApiResponse<AdjustAdvanceResponseDto>>;
113
127
  export declare function cancelTwap(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
@@ -1,4 +1,4 @@
1
- import { type CreatePositionRequestInput, type CreatePositionResponseDto, type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, type CloseAllPositionsResponseDto, type AdjustPositionRequestInput, type AdjustPositionResponseDto } 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 } 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>>;
@@ -6,6 +6,7 @@ export declare function usePosition(): {
6
6
  readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
7
7
  readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
8
8
  readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
9
+ readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
9
10
  readonly openPositions: OpenPositionDto[] | null;
10
11
  readonly isLoading: boolean;
11
12
  };
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
  */
@@ -146,8 +171,10 @@ interface TradeHistoryDataDto {
146
171
  exitRatio: number;
147
172
  entryPriceRatio?: number;
148
173
  exitpPriceRatio?: number;
149
- longAssets: TradeHistoryAssetDataDto[];
150
- shortAssets: TradeHistoryAssetDataDto[];
174
+ closedLongAssets: TradeHistoryAssetDataDto[];
175
+ closedShortAssets: TradeHistoryAssetDataDto[];
176
+ positionLongAssets?: string[];
177
+ positionShortAssets?: string[];
151
178
  createdAt: string;
152
179
  }
153
180
  /**
@@ -173,6 +200,7 @@ interface PositionAssetDetailDto {
173
200
  unrealizedPnl: number;
174
201
  liquidationPrice: number;
175
202
  initialWeight: number;
203
+ fundingPaid?: number;
176
204
  }
177
205
  interface TpSlThreshold {
178
206
  type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
@@ -479,6 +507,7 @@ interface RawAssetDto {
479
507
  entryPrice: number;
480
508
  size: number;
481
509
  side: string;
510
+ fundingPaid?: number;
482
511
  }
483
512
  /**
484
513
  * Raw position data from open-positions channel
@@ -962,6 +991,20 @@ interface AdjustPositionResponseDto {
962
991
  executedAt: string;
963
992
  }
964
993
  declare function adjustPosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustPositionRequestInput): Promise<ApiResponse<AdjustPositionResponseDto>>;
994
+ interface AdjustAdvanceAssetInput {
995
+ asset: string;
996
+ size: number;
997
+ }
998
+ interface AdjustAdvanceItemInput {
999
+ longAssets?: AdjustAdvanceAssetInput[];
1000
+ shortAssets?: AdjustAdvanceAssetInput[];
1001
+ }
1002
+ interface AdjustAdvanceResponseDto {
1003
+ orderId: string;
1004
+ status: string;
1005
+ executedAt: string;
1006
+ }
1007
+ declare function adjustAdvancePosition(baseUrl: string, accessToken: string, positionId: string, payload: AdjustAdvanceItemInput[], displayToFull: Map<string, string>): Promise<ApiResponse<AdjustAdvanceResponseDto>>;
965
1008
  declare function cancelTwap(baseUrl: string, accessToken: string, orderId: string): Promise<ApiResponse<CancelTwapResponseDto>>;
966
1009
 
967
1010
  declare function usePosition(): {
@@ -970,6 +1013,7 @@ declare function usePosition(): {
970
1013
  readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
971
1014
  readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
972
1015
  readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
1016
+ readonly adjustAdvancePosition: (positionId: string, payload: AdjustAdvanceItemInput[]) => Promise<ApiResponse<AdjustAdvanceResponseDto>>;
973
1017
  readonly openPositions: OpenPositionDto[] | null;
974
1018
  readonly isLoading: boolean;
975
1019
  };
@@ -1247,5 +1291,5 @@ declare function validatePositionSize(usdValue: number, longAssets?: PairAssetIn
1247
1291
 
1248
1292
  declare const useMarketData: any;
1249
1293
 
1250
- 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 };
1294
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, 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 };
1295
+ 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, 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
@@ -104,11 +104,16 @@ const useHyperliquidWebSocket = ({ wsUrl, address, enabled = true, }) => {
104
104
  switch (dataMessage.channel) {
105
105
  case 'trade-histories':
106
106
  {
107
- const list = dataMessage.data.map((item) => ({
108
- ...item,
109
- longAssets: item.longAssets.map((a) => ({ ...a, coin: toDisplaySymbol(a.coin) })),
110
- shortAssets: item.shortAssets.map((a) => ({ ...a, coin: toDisplaySymbol(a.coin) })),
111
- }));
107
+ const list = dataMessage.data.map((item) => {
108
+ var _a, _b;
109
+ return ({
110
+ ...item,
111
+ closedLongAssets: item.closedLongAssets.map((a) => ({ ...a, coin: toDisplaySymbol(a.coin) })),
112
+ closedShortAssets: item.closedShortAssets.map((a) => ({ ...a, coin: toDisplaySymbol(a.coin) })),
113
+ positionLongAssets: (_a = item.positionLongAssets) === null || _a === void 0 ? void 0 : _a.map((a) => toDisplaySymbol(a)),
114
+ positionShortAssets: (_b = item.positionShortAssets) === null || _b === void 0 ? void 0 : _b.map((a) => toDisplaySymbol(a)),
115
+ });
116
+ });
112
117
  setTradeHistories(list);
113
118
  }
114
119
  break;
@@ -5341,6 +5346,21 @@ const fetchUserFillsFromHyperliquid = async (user, startTime, aggregateByTime =
5341
5346
  throw toApiError(error);
5342
5347
  }
5343
5348
  };
5349
+ /**
5350
+ * Retrieve user TWAP slice fills from HyperLiquid and map to ExternalFillDto within items
5351
+ */
5352
+ const fetchUserTwapSliceFillsByTime = async (user, startTime, aggregateByTime = true) => {
5353
+ const request = { type: 'userTwapSliceFillsByTime', user, startTime, aggregateByTime };
5354
+ try {
5355
+ const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
5356
+ headers: { 'Content-Type': 'application/json' },
5357
+ });
5358
+ return { data: response.data, status: response.status, headers: response.headers };
5359
+ }
5360
+ catch (error) {
5361
+ throw toApiError(error);
5362
+ }
5363
+ };
5344
5364
  /**
5345
5365
  * Fetch all perp metas from HyperLiquid API
5346
5366
  * Endpoint: https://api.hyperliquid.xyz/info
@@ -6010,7 +6030,7 @@ const syncFills = async (baseUrl, accessToken, payload) => {
6010
6030
  * Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
6011
6031
  */
6012
6032
  const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true, lastSyncAt = null, assetPositions) => {
6013
- const firstStartTime = lastSyncAt ? Number(lastSyncAt) : 1735660800000;
6033
+ const firstStartTime = lastSyncAt ? Number(lastSyncAt) : 0;
6014
6034
  const allFills = [];
6015
6035
  const seenTids = new Set();
6016
6036
  let startTime = firstStartTime;
@@ -6032,7 +6052,28 @@ const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregat
6032
6052
  startTime = last.time;
6033
6053
  }
6034
6054
  } while (batchSize === 2000);
6035
- return syncFills(baseUrl, accessToken, { user, fills: allFills, assetPositions });
6055
+ startTime = firstStartTime;
6056
+ batchSize = 0;
6057
+ do {
6058
+ const { data: twapBatch } = await fetchUserTwapSliceFillsByTime(user, startTime, aggregateByTime);
6059
+ batchSize = twapBatch.length;
6060
+ for (const item of twapBatch) {
6061
+ const fill = item.fill;
6062
+ const tid = fill.tid;
6063
+ if (tid === undefined)
6064
+ continue;
6065
+ if (!seenTids.has(tid)) {
6066
+ seenTids.add(tid);
6067
+ allFills.push(fill);
6068
+ }
6069
+ }
6070
+ if (batchSize === 2000) {
6071
+ const last = twapBatch[twapBatch.length - 1];
6072
+ startTime = last.fill.time;
6073
+ }
6074
+ } while (batchSize === 2000);
6075
+ const sortedFills = [...allFills].sort((a, b) => Number(a.time) - Number(b.time));
6076
+ return syncFills(baseUrl, accessToken, { user, fills: sortedFills, assetPositions });
6036
6077
  };
6037
6078
 
6038
6079
  /**
@@ -6304,6 +6345,31 @@ async function adjustPosition(baseUrl, accessToken, positionId, payload) {
6304
6345
  throw toApiError(error);
6305
6346
  }
6306
6347
  }
6348
+ async function adjustAdvancePosition(baseUrl, accessToken, positionId, payload, displayToFull) {
6349
+ const url = joinUrl(baseUrl, `/positions/${positionId}/adjust-advance`);
6350
+ const mapAssets = (arr) => arr === null || arr === void 0 ? void 0 : arr.map((a) => ({ ...a, asset: toBackendSymbol(a.asset, displayToFull) }));
6351
+ const translatedPayload = (payload || []).map((item) => ({
6352
+ longAssets: mapAssets(item.longAssets),
6353
+ shortAssets: mapAssets(item.shortAssets),
6354
+ }));
6355
+ try {
6356
+ const resp = await axios$1.post(url, translatedPayload, {
6357
+ headers: {
6358
+ "Content-Type": "application/json",
6359
+ Authorization: `Bearer ${accessToken}`,
6360
+ },
6361
+ timeout: 60000,
6362
+ });
6363
+ return {
6364
+ data: resp.data,
6365
+ status: resp.status,
6366
+ headers: resp.headers,
6367
+ };
6368
+ }
6369
+ catch (error) {
6370
+ throw toApiError(error);
6371
+ }
6372
+ }
6307
6373
  // ---------------- Cancel TWAP (by orderId) ----------------
6308
6374
  // Convenience API colocated with position operations
6309
6375
  async function cancelTwap(baseUrl, accessToken, orderId) {
@@ -6328,6 +6394,7 @@ async function cancelTwap(baseUrl, accessToken, orderId) {
6328
6394
  }
6329
6395
 
6330
6396
  const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, isLong = true) => {
6397
+ var _a;
6331
6398
  const entryNotional = asset.entryPrice * asset.size;
6332
6399
  const currentNotional = currentPrice * asset.size;
6333
6400
  const marginUsed = currentNotional / (leverage || 1);
@@ -6344,6 +6411,7 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6344
6411
  unrealizedPnl: unrealizedPnl,
6345
6412
  entryPositionValue: entryNotional,
6346
6413
  initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
6414
+ fundingPaid: (_a = asset.fundingPaid) !== null && _a !== void 0 ? _a : 0,
6347
6415
  };
6348
6416
  };
6349
6417
  const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
@@ -6443,6 +6511,12 @@ function usePosition() {
6443
6511
  throw new Error('Not authenticated');
6444
6512
  return adjustPosition(apiBaseUrl, accessToken, positionId, payload);
6445
6513
  };
6514
+ // Adjust to absolute target sizes per asset, optionally adding new assets
6515
+ const adjustAdvancePosition$1 = async (positionId, payload) => {
6516
+ if (!accessToken)
6517
+ throw new Error('Not authenticated');
6518
+ return adjustAdvancePosition(apiBaseUrl, accessToken, positionId, payload, displayToFull);
6519
+ };
6446
6520
  // Open positions using WS data, with derived values
6447
6521
  const userOpenPositions = useUserData((state) => state.rawOpenPositions);
6448
6522
  const aggregatedClearingHouseState = useHyperliquidData((state) => state.aggregatedClearingHouseState);
@@ -6455,7 +6529,7 @@ function usePosition() {
6455
6529
  return null;
6456
6530
  return buildPositionValue(userOpenPositions, aggregatedClearingHouseState, allMids);
6457
6531
  }, [userOpenPositions, aggregatedClearingHouseState, allMids]);
6458
- return { createPosition: createPosition$1, updateRiskParameters: updateRiskParameters$1, closePosition: closePosition$1, closeAllPositions: closeAllPositions$1, adjustPosition: adjustPosition$1, openPositions, isLoading };
6532
+ return { createPosition: createPosition$1, updateRiskParameters: updateRiskParameters$1, closePosition: closePosition$1, closeAllPositions: closeAllPositions$1, adjustPosition: adjustPosition$1, adjustAdvancePosition: adjustAdvancePosition$1, openPositions, isLoading };
6459
6533
  }
6460
6534
 
6461
6535
  async function adjustOrder(baseUrl, accessToken, orderId, payload) {
@@ -7090,4 +7164,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
7090
7164
  }
7091
7165
  }
7092
7166
 
7093
- 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 };
7167
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, MINIMUM_ASSET_USD_VALUE, MinimumPositionSizeError, PearHyperliquidProvider, TokenMetadataExtractor, adjustAdvancePosition, 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 };
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
  */
@@ -176,8 +180,10 @@ export interface TradeHistoryDataDto {
176
180
  exitRatio: number;
177
181
  entryPriceRatio?: number;
178
182
  exitpPriceRatio?: number;
179
- longAssets: TradeHistoryAssetDataDto[];
180
- shortAssets: TradeHistoryAssetDataDto[];
183
+ closedLongAssets: TradeHistoryAssetDataDto[];
184
+ closedShortAssets: TradeHistoryAssetDataDto[];
185
+ positionLongAssets?: string[];
186
+ positionShortAssets?: string[];
181
187
  createdAt: string;
182
188
  }
183
189
  /**
@@ -203,6 +209,7 @@ export interface PositionAssetDetailDto {
203
209
  unrealizedPnl: number;
204
210
  liquidationPrice: number;
205
211
  initialWeight: number;
212
+ fundingPaid?: number;
206
213
  }
207
214
  export interface TpSlThreshold {
208
215
  type: 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
@@ -596,6 +603,7 @@ export interface RawAssetDto {
596
603
  entryPrice: number;
597
604
  size: number;
598
605
  side: string;
606
+ fundingPaid?: number;
599
607
  }
600
608
  /**
601
609
  * Raw position data from open-positions channel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",