@pear-protocol/hyperliquid-sdk 0.0.35 → 0.0.37

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.
@@ -5,3 +5,9 @@ import type { ApiResponse } from '../types';
5
5
  export declare function markNotificationsRead(baseUrl: string, accessToken: string, timestampMs: number): Promise<ApiResponse<{
6
6
  updated: number;
7
7
  }>>;
8
+ /**
9
+ * Mark a single notification as read by id
10
+ */
11
+ export declare function markNotificationReadById(baseUrl: string, accessToken: string, id: string): Promise<ApiResponse<{
12
+ updated: number;
13
+ }>>;
@@ -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 {
@@ -5,6 +5,9 @@ export interface UseNotificationsResult {
5
5
  markReadUntil: (timestampMs: number) => Promise<{
6
6
  updated: number;
7
7
  }>;
8
+ markReadById: (id: string) => Promise<{
9
+ updated: number;
10
+ }>;
8
11
  }
9
12
  /**
10
13
  * Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
@@ -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
@@ -906,6 +906,16 @@ interface ClosePositionResponseDto {
906
906
  chunksScheduled?: number;
907
907
  }
908
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>>;
909
919
  type AdjustExecutionType = 'MARKET' | 'LIMIT';
910
920
  type PositionAdjustmentType = 'REDUCE' | 'INCREASE';
911
921
  interface AdjustPositionRequestInput {
@@ -929,6 +939,7 @@ declare function usePosition(): {
929
939
  readonly createPosition: (payload: CreatePositionRequestInput) => Promise<ApiResponse<CreatePositionResponseDto>>;
930
940
  readonly updateRiskParameters: (positionId: string, payload: UpdateRiskParametersRequestInput) => Promise<ApiResponse<UpdateRiskParametersResponseDto>>;
931
941
  readonly closePosition: (positionId: string, payload: ClosePositionRequestInput) => Promise<ApiResponse<ClosePositionResponseDto>>;
942
+ readonly closeAllPositions: (payload: ClosePositionRequestInput) => Promise<ApiResponse<CloseAllPositionsResponseDto>>;
932
943
  readonly adjustPosition: (positionId: string, payload: AdjustPositionRequestInput) => Promise<ApiResponse<AdjustPositionResponseDto>>;
933
944
  readonly openPositions: OpenPositionDto[] | null;
934
945
  readonly isLoading: boolean;
@@ -953,6 +964,9 @@ interface UseNotificationsResult {
953
964
  markReadUntil: (timestampMs: number) => Promise<{
954
965
  updated: number;
955
966
  }>;
967
+ markReadById: (id: string) => Promise<{
968
+ updated: number;
969
+ }>;
956
970
  }
957
971
  /**
958
972
  * Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
@@ -987,6 +1001,12 @@ declare const useHyperliquidNativeWebSocket: ({ address, }: UseHyperliquidNative
987
1001
  declare function markNotificationsRead(baseUrl: string, accessToken: string, timestampMs: number): Promise<ApiResponse<{
988
1002
  updated: number;
989
1003
  }>>;
1004
+ /**
1005
+ * Mark a single notification as read by id
1006
+ */
1007
+ declare function markNotificationReadById(baseUrl: string, accessToken: string, id: string): Promise<ApiResponse<{
1008
+ updated: number;
1009
+ }>>;
990
1010
 
991
1011
  /**
992
1012
  * Account summary calculation utility class
@@ -1090,5 +1110,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
1090
1110
  */
1091
1111
  declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
1092
1112
 
1093
- 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 };
1094
- 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 };
1113
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, 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 };
1114
+ 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 {
@@ -8441,6 +8451,12 @@ function usePosition() {
8441
8451
  throw new Error('Not authenticated');
8442
8452
  return closePosition(apiBaseUrl, accessToken, positionId, payload);
8443
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
+ };
8444
8460
  // Adjust a position (REDUCE/INCREASE by %; MARKET or LIMIT)
8445
8461
  const adjustPosition$1 = async (positionId, payload) => {
8446
8462
  if (!accessToken)
@@ -8459,7 +8475,7 @@ function usePosition() {
8459
8475
  return null;
8460
8476
  return buildPositionValue(userOpenPositions, webData2, allMids);
8461
8477
  }, [userOpenPositions, webData2, allMids]);
8462
- 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 };
8463
8479
  }
8464
8480
 
8465
8481
  async function adjustOrder(baseUrl, accessToken, orderId, payload) {
@@ -8582,6 +8598,19 @@ async function markNotificationsRead(baseUrl, accessToken, timestampMs) {
8582
8598
  throw toApiError(error);
8583
8599
  }
8584
8600
  }
8601
+ /**
8602
+ * Mark a single notification as read by id
8603
+ */
8604
+ async function markNotificationReadById(baseUrl, accessToken, id) {
8605
+ const url = joinUrl(baseUrl, '/notifications/read');
8606
+ try {
8607
+ const response = await axios$1.post(url, { id }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}` } });
8608
+ return { data: response.data, status: response.status, headers: response.headers };
8609
+ }
8610
+ catch (error) {
8611
+ throw toApiError(error);
8612
+ }
8613
+ }
8585
8614
 
8586
8615
  /**
8587
8616
  * Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
@@ -8616,6 +8645,16 @@ function useNotifications() {
8616
8645
  }
8617
8646
  return data;
8618
8647
  }, [apiBaseUrl, accessToken, isAuthenticated, notifications, setNotifications]),
8648
+ markReadById: useCallback(async (id) => {
8649
+ if (!isAuthenticated || !accessToken)
8650
+ throw new Error('Not authenticated');
8651
+ const { data } = await markNotificationReadById(apiBaseUrl, accessToken, id);
8652
+ if (notifications) {
8653
+ const updated = notifications.map((n) => (n.id === id ? { ...n, is_read: true } : n));
8654
+ setNotifications(updated);
8655
+ }
8656
+ return data;
8657
+ }, [apiBaseUrl, accessToken, isAuthenticated, notifications, setNotifications]),
8619
8658
  };
8620
8659
  }
8621
8660
 
@@ -8917,4 +8956,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
8917
8956
  }
8918
8957
  }
8919
8958
 
8920
- 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 };
8959
+ export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, markNotificationReadById, 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",