@pear-protocol/hyperliquid-sdk 0.0.33 → 0.0.34

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.
@@ -0,0 +1,7 @@
1
+ import type { ApiResponse } from '../types';
2
+ /**
3
+ * Mark notifications as read up to a given timestamp (ms)
4
+ */
5
+ export declare function markNotificationsRead(baseUrl: string, accessToken: string, timestampMs: number): Promise<ApiResponse<{
6
+ updated: number;
7
+ }>>;
@@ -2,6 +2,9 @@ import type { NotificationDto } from '../types';
2
2
  export interface UseNotificationsResult {
3
3
  notifications: NotificationDto[] | null;
4
4
  unreadCount: number;
5
+ markReadUntil: (timestampMs: number) => Promise<{
6
+ updated: number;
7
+ }>;
5
8
  }
6
9
  /**
7
10
  * Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
package/dist/index.d.ts CHANGED
@@ -53,7 +53,7 @@ interface WebSocketDataMessage<T = unknown> {
53
53
  channel: WebSocketChannel;
54
54
  data: T;
55
55
  }
56
- type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
56
+ type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'TRADE_CLOSED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
57
57
  interface NotificationDto {
58
58
  id: string;
59
59
  address: string;
@@ -948,6 +948,9 @@ declare function useTwap(): {
948
948
  interface UseNotificationsResult {
949
949
  notifications: NotificationDto[] | null;
950
950
  unreadCount: number;
951
+ markReadUntil: (timestampMs: number) => Promise<{
952
+ updated: number;
953
+ }>;
951
954
  }
952
955
  /**
953
956
  * Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
@@ -976,6 +979,13 @@ interface UseHyperliquidNativeWebSocketReturn {
976
979
  }
977
980
  declare const useHyperliquidNativeWebSocket: ({ address, }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
978
981
 
982
+ /**
983
+ * Mark notifications as read up to a given timestamp (ms)
984
+ */
985
+ declare function markNotificationsRead(baseUrl: string, accessToken: string, timestampMs: number): Promise<ApiResponse<{
986
+ updated: number;
987
+ }>>;
988
+
979
989
  /**
980
990
  * Account summary calculation utility class
981
991
  */
@@ -1078,5 +1088,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
1078
1088
  */
1079
1089
  declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
1080
1090
 
1081
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
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 };
1082
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 };
package/dist/index.js CHANGED
@@ -8564,12 +8564,28 @@ function useTwap() {
8564
8564
  return { orders, cancelTwap: cancelTwap$1 };
8565
8565
  }
8566
8566
 
8567
+ /**
8568
+ * Mark notifications as read up to a given timestamp (ms)
8569
+ */
8570
+ async function markNotificationsRead(baseUrl, accessToken, timestampMs) {
8571
+ const url = joinUrl(baseUrl, '/notifications/read');
8572
+ try {
8573
+ const response = await axios$1.post(url, { timestamp: timestampMs }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}` } });
8574
+ return { data: response.data, status: response.status, headers: response.headers };
8575
+ }
8576
+ catch (error) {
8577
+ throw toApiError(error);
8578
+ }
8579
+ }
8580
+
8567
8581
  /**
8568
8582
  * Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
8569
8583
  * Data is persisted in the SDK's Zustand store.
8570
8584
  */
8571
8585
  function useNotifications() {
8572
8586
  const notifications = useUserData((state) => state.notifications);
8587
+ const setNotifications = useUserData((state) => state.setNotifications);
8588
+ const { apiBaseUrl, accessToken, isAuthenticated } = usePearHyperliquid();
8573
8589
  const unreadCount = useMemo(() => {
8574
8590
  if (!notifications)
8575
8591
  return 0;
@@ -8578,6 +8594,23 @@ function useNotifications() {
8578
8594
  return {
8579
8595
  notifications,
8580
8596
  unreadCount,
8597
+ markReadUntil: useCallback(async (timestampMs) => {
8598
+ if (!isAuthenticated || !accessToken)
8599
+ throw new Error('Not authenticated');
8600
+ const { data } = await markNotificationsRead(apiBaseUrl, accessToken, timestampMs);
8601
+ // Optimistic local update for immediate UI feedback
8602
+ if (notifications) {
8603
+ const updated = notifications.map((n) => {
8604
+ const created = Date.parse(n.created_at);
8605
+ if (!isNaN(created) && created <= timestampMs) {
8606
+ return { ...n, is_read: true };
8607
+ }
8608
+ return n;
8609
+ });
8610
+ setNotifications(updated);
8611
+ }
8612
+ return data;
8613
+ }, [apiBaseUrl, accessToken, isAuthenticated, notifications, setNotifications]),
8581
8614
  };
8582
8615
  }
8583
8616
 
@@ -8879,4 +8912,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
8879
8912
  }
8880
8913
  }
8881
8914
 
8882
- export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closePosition, computeBasketCandles, createCandleLookups, createPosition, getCompleteTimestamps, mapCandleIntervalToTradingViewInterval, mapTradingViewIntervalToCandleInterval, updateRiskParameters, useAccountSummary, useAddress, useAgentWallet, useAuth, useAutoSyncFills, useBasketCandles, useHistoricalPriceData, useHistoricalPriceDataStore, useHyperliquidNativeWebSocket, useHyperliquidWebSocket, useNotifications, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
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 };
package/dist/types.d.ts CHANGED
@@ -74,7 +74,7 @@ export interface WebSocketDataMessage<T = unknown> {
74
74
  channel: WebSocketChannel;
75
75
  data: T;
76
76
  }
77
- export type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
77
+ export type NotificationCategory = 'TRADE_OPENED_OUTSIDE_PEAR' | 'TRADE_CLOSED_OUTSIDE_PEAR' | 'POSITION_LIQUIDATED' | 'LIMIT_ORDER_FILLED' | 'LIMIT_ORDER_FAILED' | 'TP_ORDER_FILLED' | 'TP_ORDER_FAILED' | 'SL_ORDER_FILLED' | 'SL_ORDER_FAILED';
78
78
  export interface NotificationDto {
79
79
  id: string;
80
80
  address: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",