@pear-protocol/hyperliquid-sdk 0.0.34 → 0.0.36

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.
@@ -77,6 +77,16 @@ export interface ClosePositionResponseDto {
77
77
  chunksScheduled?: number;
78
78
  }
79
79
  export declare function closePosition(baseUrl: string, accessToken: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
80
+ export interface CloseAllPositionsResultDto {
81
+ positionId: string;
82
+ success: boolean;
83
+ orderId?: string;
84
+ error?: string;
85
+ }
86
+ export interface CloseAllPositionsResponseDto {
87
+ results: CloseAllPositionsResultDto[];
88
+ }
89
+ export declare function closeAllPositions(baseUrl: string, accessToken: string, payload: ClosePositionRequestInput): Promise<ApiResponse<CloseAllPositionsResponseDto>>;
80
90
  export type AdjustExecutionType = 'MARKET' | 'LIMIT';
81
91
  export type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
82
92
  export interface AdjustPositionRequestInput {
@@ -1,9 +1,10 @@
1
- import { type CreatePositionRequestInput, type CreatePositionResponseDto, type UpdateRiskParametersRequestInput, type UpdateRiskParametersResponseDto, type ClosePositionRequestInput, type ClosePositionResponseDto, 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 } 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>>;
5
5
  readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
6
6
  readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
7
+ readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
7
8
  readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
8
9
  readonly openPositions: OpenPositionDto[] | null;
9
10
  readonly isLoading: boolean;
package/dist/index.d.ts CHANGED
@@ -197,11 +197,12 @@ type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
197
197
  /**
198
198
  * Order type
199
199
  */
200
- type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET';
200
+ type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET' | 'LIMIT_BTCDOM' | 'TWAP';
201
201
  /**
202
202
  * TP/SL trigger type
203
203
  */
204
- type TpSlTriggerType = 'RATIO' | 'PERCENTAGE' | 'PNL';
204
+ type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
205
+ type OrderDirection = 'MORE_THAN' | 'LESS_THAN' | null;
205
206
  /**
206
207
  * Open limit order data structure
207
208
  */
@@ -209,16 +210,17 @@ interface OpenLimitOrderDto {
209
210
  orderId: string;
210
211
  address: string;
211
212
  clientId: string | null;
212
- positionId: string;
213
+ positionId?: string | null;
213
214
  leverage: number;
214
215
  usdValue: number;
215
- triggerValue: number;
216
- twapDuration: number | null;
217
- tpSlTriggerType: TpSlTriggerType;
216
+ triggerValue?: number | null;
217
+ twapDuration?: string | null;
218
+ tpSlTriggerType?: TpSlTriggerType | null;
218
219
  randomizeFlag: boolean;
219
220
  reduceOnlyFlag: boolean;
220
221
  status: OrderStatus;
221
222
  orderType: OrderType;
223
+ direction?: OrderDirection | null;
222
224
  longAssets: OrderAssetDto[];
223
225
  shortAssets: OrderAssetDto[];
224
226
  createdAt: string;
@@ -904,6 +906,16 @@ interface ClosePositionResponseDto {
904
906
  chunksScheduled?: number;
905
907
  }
906
908
  declare function closePosition(baseUrl: string, accessToken: string, positionId: string, payload: ClosePositionRequestInput): Promise<ApiResponse<ClosePositionResponseDto>>;
909
+ interface CloseAllPositionsResultDto {
910
+ positionId: string;
911
+ success: boolean;
912
+ orderId?: string;
913
+ error?: string;
914
+ }
915
+ interface CloseAllPositionsResponseDto {
916
+ results: CloseAllPositionsResultDto[];
917
+ }
918
+ declare function closeAllPositions(baseUrl: string, accessToken: string, payload: ClosePositionRequestInput): Promise<ApiResponse<CloseAllPositionsResponseDto>>;
907
919
  type AdjustExecutionType = 'MARKET' | 'LIMIT';
908
920
  type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
909
921
  interface AdjustPositionRequestInput {
@@ -927,6 +939,7 @@ declare function usePosition(): {
927
939
  readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
928
940
  readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
929
941
  readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
942
+ readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
930
943
  readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
931
944
  readonly openPositions: OpenPositionDto[] | null;
932
945
  readonly isLoading: boolean;
@@ -1088,5 +1101,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
1088
1101
  */
1089
1102
  declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
1090
1103
 
1091
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationsRead, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
1092
- export type { AccountSummaryResponseDto, AdjustExecutionType, AdjustOrderRequestInput, AdjustOrderResponseDto, AdjustPositionRequestInput, AdjustPositionResponseDto, AgentWalletDto, AgentWalletState, ApiErrorResponse, ApiResponse, AssetCtx, AssetInformationDetail, AssetMarketData, AssetPosition, AutoSyncFillsOptions, AutoSyncFillsState, BalanceSummaryDto, CancelOrderResponseDto, CancelTwapResponseDto, CandleChartData, CandleData, CandleInterval, CandleSnapshotRequest, ClearinghouseState, CloseExecutionType, ClosePositionRequestInput, ClosePositionResponseDto, CreatePositionRequestInput, CreatePositionResponseDto, CrossMarginSummaryDto, CumFundingDto, ExecutionType, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
1104
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationsRead, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
1105
+ export type { AccountSummaryResponseDto, 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, HLWebSocketResponse, HistoricalRange, LadderConfigInput, MarginSummaryDto, NotificationCategory, NotificationDto, OpenLimitOrderDto, OpenPositionDto, OrderAssetDto, OrderStatus, PairAssetInput, PerformanceOverlay, PositionAdjustmentType, PositionAssetDetailDto, PositionAssetSummaryDto, PositionResponseStatus, RealtimeBar, RealtimeBarsCallback, TokenConflict, TokenHistoricalPriceData, TokenMetadata, TokenSelection, TpSlThresholdInput, TpSlThresholdType, TradeHistoryAssetDataDto, TradeHistoryDataDto, TwapChunkStatusDto, TwapMonitoringDto, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UseNotificationsResult, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
package/dist/index.js CHANGED
@@ -8315,6 +8315,16 @@ async function closePosition(baseUrl, accessToken, positionId, payload) {
8315
8315
  throw toApiError(error);
8316
8316
  }
8317
8317
  }
8318
+ async function closeAllPositions(baseUrl, accessToken, payload) {
8319
+ const url = joinUrl(baseUrl, `/positions/close-all`);
8320
+ try {
8321
+ const resp = await axios$1.post(url, payload, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, timeout: 60000 });
8322
+ return { data: resp.data, status: resp.status, headers: resp.headers };
8323
+ }
8324
+ catch (error) {
8325
+ throw toApiError(error);
8326
+ }
8327
+ }
8318
8328
  async function adjustPosition(baseUrl, accessToken, positionId, payload) {
8319
8329
  const url = joinUrl(baseUrl, `/positions/${positionId}/adjust`);
8320
8330
  try {
@@ -8363,7 +8373,12 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
8363
8373
  };
8364
8374
  const buildPositionValue = (rawPositions, webData2, allMids) => {
8365
8375
  return rawPositions.map((position) => {
8366
- const webData2Position = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === position.longAssets[0].coin || ap.position.coin === position.shortAssets[0].coin);
8376
+ const webData2Position = webData2.clearinghouseState.assetPositions.find(ap => {
8377
+ var _a, _b, _c, _d;
8378
+ const longCoin = (_b = (_a = position.longAssets) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coin;
8379
+ const shortCoin = (_d = (_c = position.shortAssets) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.coin;
8380
+ return ap.position.coin === longCoin || ap.position.coin === shortCoin;
8381
+ });
8367
8382
  let mappedPosition = {
8368
8383
  positionId: position.positionId,
8369
8384
  address: position.address,
@@ -8436,6 +8451,12 @@ function usePosition() {
8436
8451
  throw new Error('Not authenticated');
8437
8452
  return closePosition(apiBaseUrl, accessToken, positionId, payload);
8438
8453
  };
8454
+ // Close all positions (MARKET or TWAP)
8455
+ const closeAllPositions$1 = async (payload) => {
8456
+ if (!accessToken)
8457
+ throw new Error('Not authenticated');
8458
+ return closeAllPositions(apiBaseUrl, accessToken, payload);
8459
+ };
8439
8460
  // Adjust a position (REDUCE/INCREASE by %; MARKET or LIMIT)
8440
8461
  const adjustPosition$1 = async (positionId, payload) => {
8441
8462
  if (!accessToken)
@@ -8454,7 +8475,7 @@ function usePosition() {
8454
8475
  return null;
8455
8476
  return buildPositionValue(userOpenPositions, webData2, allMids);
8456
8477
  }, [userOpenPositions, webData2, allMids]);
8457
- return { createPosition: createPosition$1, updateRiskParameters: updateRiskParameters$1, closePosition: closePosition$1, adjustPosition: adjustPosition$1, openPositions, isLoading };
8478
+ return { createPosition: createPosition$1, updateRiskParameters: updateRiskParameters$1, closePosition: closePosition$1, closeAllPositions: closeAllPositions$1, adjustPosition: adjustPosition$1, openPositions, isLoading };
8458
8479
  }
8459
8480
 
8460
8481
  async function adjustOrder(baseUrl, accessToken, orderId, payload) {
@@ -8508,10 +8529,10 @@ function useOrders() {
8508
8529
  if (!openOrders)
8509
8530
  return null;
8510
8531
  return openOrders.map((ord) => {
8511
- var _a, _b, _c, _d;
8532
+ var _a, _b, _c, _d, _e;
8512
8533
  const isTpSl = ord.orderType === 'TP' || ord.orderType === 'SL';
8513
8534
  const hasAssets = ((_b = (_a = ord.longAssets) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 || ((_d = (_c = ord.shortAssets) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0;
8514
- const pos = positionsById.get(ord.positionId);
8535
+ const pos = positionsById.get((_e = ord.positionId) !== null && _e !== void 0 ? _e : '');
8515
8536
  if (!isTpSl || !pos)
8516
8537
  return ord;
8517
8538
  // Build order assets from position weights when TP/SL has no assets
@@ -8912,4 +8933,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
8912
8933
  }
8913
8934
  }
8914
8935
 
8915
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationsRead, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
8936
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationsRead, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
package/dist/types.d.ts CHANGED
@@ -218,11 +218,12 @@ export type OrderStatus = 'OPEN' | 'PARTIALLY_FILLED' | 'PROCESSING';
218
218
  /**
219
219
  * Order type
220
220
  */
221
- export type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET';
221
+ export type OrderType = 'TP' | 'SL' | 'LIMIT' | 'MARKET' | 'LIMIT_BTCDOM' | 'TWAP';
222
222
  /**
223
223
  * TP/SL trigger type
224
224
  */
225
- export type TpSlTriggerType = 'RATIO' | 'PERCENTAGE' | 'PNL';
225
+ export type TpSlTriggerType = 'PERCENTAGE' | 'DOLLAR' | 'POSITION_VALUE';
226
+ export type OrderDirection = 'MORE_THAN' | 'LESS_THAN' | null;
226
227
  /**
227
228
  * Open limit order data structure
228
229
  */
@@ -230,16 +231,17 @@ export interface OpenLimitOrderDto {
230
231
  orderId: string;
231
232
  address: string;
232
233
  clientId: string | null;
233
- positionId: string;
234
+ positionId?: string | null;
234
235
  leverage: number;
235
236
  usdValue: number;
236
- triggerValue: number;
237
- twapDuration: number | null;
238
- tpSlTriggerType: TpSlTriggerType;
237
+ triggerValue?: number | null;
238
+ twapDuration?: string | null;
239
+ tpSlTriggerType?: TpSlTriggerType | null;
239
240
  randomizeFlag: boolean;
240
241
  reduceOnlyFlag: boolean;
241
242
  status: OrderStatus;
242
243
  orderType: OrderType;
244
+ direction?: OrderDirection | null;
243
245
  longAssets: OrderAssetDto[];
244
246
  shortAssets: OrderAssetDto[];
245
247
  createdAt: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",