@pear-protocol/hyperliquid-sdk 0.0.32 → 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.
- package/dist/clients/notifications.d.ts +7 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNotifications.d.ts +13 -0
- package/dist/index.d.ts +33 -3
- package/dist/index.js +59 -2
- package/dist/types.d.ts +11 -1
- package/package.json +1 -1
|
@@ -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
|
+
}>>;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NotificationDto } from '../types';
|
|
2
|
+
export interface UseNotificationsResult {
|
|
3
|
+
notifications: NotificationDto[] | null;
|
|
4
|
+
unreadCount: number;
|
|
5
|
+
markReadUntil: (timestampMs: number) => Promise<{
|
|
6
|
+
updated: number;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
11
|
+
* Data is persisted in the SDK's Zustand store.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useNotifications(): UseNotificationsResult;
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnected' | 'e
|
|
|
30
30
|
/**
|
|
31
31
|
* WebSocket channels
|
|
32
32
|
*/
|
|
33
|
-
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
33
|
+
type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
34
34
|
/**
|
|
35
35
|
* WebSocket subscription message
|
|
36
36
|
*/
|
|
@@ -53,6 +53,16 @@ interface WebSocketDataMessage<T = unknown> {
|
|
|
53
53
|
channel: WebSocketChannel;
|
|
54
54
|
data: T;
|
|
55
55
|
}
|
|
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
|
+
interface NotificationDto {
|
|
58
|
+
id: string;
|
|
59
|
+
address: string;
|
|
60
|
+
category: NotificationCategory;
|
|
61
|
+
parameters: Record<string, any>;
|
|
62
|
+
is_read: boolean;
|
|
63
|
+
created_at: string;
|
|
64
|
+
updated_at: string;
|
|
65
|
+
}
|
|
56
66
|
interface ChunkFillDto {
|
|
57
67
|
fillId: string;
|
|
58
68
|
assetName: string;
|
|
@@ -935,6 +945,19 @@ declare function useTwap(): {
|
|
|
935
945
|
readonly cancelTwap: (orderId: string) => Promise<ApiResponse<CancelTwapResponseDto>>;
|
|
936
946
|
};
|
|
937
947
|
|
|
948
|
+
interface UseNotificationsResult {
|
|
949
|
+
notifications: NotificationDto[] | null;
|
|
950
|
+
unreadCount: number;
|
|
951
|
+
markReadUntil: (timestampMs: number) => Promise<{
|
|
952
|
+
updated: number;
|
|
953
|
+
}>;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
957
|
+
* Data is persisted in the SDK's Zustand store.
|
|
958
|
+
*/
|
|
959
|
+
declare function useNotifications(): UseNotificationsResult;
|
|
960
|
+
|
|
938
961
|
interface UseHyperliquidWebSocketProps {
|
|
939
962
|
wsUrl: string;
|
|
940
963
|
address: string | null;
|
|
@@ -956,6 +979,13 @@ interface UseHyperliquidNativeWebSocketReturn {
|
|
|
956
979
|
}
|
|
957
980
|
declare const useHyperliquidNativeWebSocket: ({ address, }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
|
958
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
|
+
|
|
959
989
|
/**
|
|
960
990
|
* Account summary calculation utility class
|
|
961
991
|
*/
|
|
@@ -1058,5 +1088,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1058
1088
|
*/
|
|
1059
1089
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1060
1090
|
|
|
1061
|
-
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, useOpenOrders, useOrders, usePearAgentWallet, usePearAuth, usePearHyperliquid, usePerformanceOverlays, usePosition, useTokenSelectionMetadata, useTradeHistories, useTwap, useUserSelection, useWebData };
|
|
1062
|
-
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, 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, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -2434,22 +2434,25 @@ const useUserData = create((set) => ({
|
|
|
2434
2434
|
openOrders: null,
|
|
2435
2435
|
accountSummary: null,
|
|
2436
2436
|
twapDetails: null,
|
|
2437
|
+
notifications: null,
|
|
2437
2438
|
setTradeHistories: (value) => set({ tradeHistories: value }),
|
|
2438
2439
|
setRawOpenPositions: (value) => set({ rawOpenPositions: value }),
|
|
2439
2440
|
setOpenOrders: (value) => set({ openOrders: value }),
|
|
2440
2441
|
setAccountSummary: (value) => set({ accountSummary: value }),
|
|
2441
2442
|
setTwapDetails: (value) => set({ twapDetails: value }),
|
|
2443
|
+
setNotifications: (value) => set({ notifications: value }),
|
|
2442
2444
|
clean: () => set({
|
|
2443
2445
|
tradeHistories: null,
|
|
2444
2446
|
rawOpenPositions: null,
|
|
2445
2447
|
openOrders: null,
|
|
2446
2448
|
accountSummary: null,
|
|
2447
2449
|
twapDetails: null,
|
|
2450
|
+
notifications: null,
|
|
2448
2451
|
}),
|
|
2449
2452
|
}));
|
|
2450
2453
|
|
|
2451
2454
|
const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
2452
|
-
const { setTradeHistories, setRawOpenPositions, setOpenOrders, setAccountSummary, setTwapDetails, clean } = useUserData();
|
|
2455
|
+
const { setTradeHistories, setRawOpenPositions, setOpenOrders, setAccountSummary, setTwapDetails, setNotifications, clean, } = useUserData();
|
|
2453
2456
|
const [lastError, setLastError] = useState(null);
|
|
2454
2457
|
const [lastSubscribedAddress, setLastSubscribedAddress] = useState(null);
|
|
2455
2458
|
// WebSocket connection
|
|
@@ -2493,6 +2496,10 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
|
2493
2496
|
case 'twap-details':
|
|
2494
2497
|
setTwapDetails(dataMessage.data);
|
|
2495
2498
|
break;
|
|
2499
|
+
case 'notifications':
|
|
2500
|
+
setNotifications(dataMessage.data);
|
|
2501
|
+
break;
|
|
2502
|
+
// 'fills-checkpoint' is intentionally ignored here
|
|
2496
2503
|
}
|
|
2497
2504
|
}
|
|
2498
2505
|
}
|
|
@@ -8557,6 +8564,56 @@ function useTwap() {
|
|
|
8557
8564
|
return { orders, cancelTwap: cancelTwap$1 };
|
|
8558
8565
|
}
|
|
8559
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
|
+
|
|
8581
|
+
/**
|
|
8582
|
+
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
8583
|
+
* Data is persisted in the SDK's Zustand store.
|
|
8584
|
+
*/
|
|
8585
|
+
function useNotifications() {
|
|
8586
|
+
const notifications = useUserData((state) => state.notifications);
|
|
8587
|
+
const setNotifications = useUserData((state) => state.setNotifications);
|
|
8588
|
+
const { apiBaseUrl, accessToken, isAuthenticated } = usePearHyperliquid();
|
|
8589
|
+
const unreadCount = useMemo(() => {
|
|
8590
|
+
if (!notifications)
|
|
8591
|
+
return 0;
|
|
8592
|
+
return notifications.reduce((acc, n) => acc + (n.is_read ? 0 : 1), 0);
|
|
8593
|
+
}, [notifications]);
|
|
8594
|
+
return {
|
|
8595
|
+
notifications,
|
|
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]),
|
|
8614
|
+
};
|
|
8615
|
+
}
|
|
8616
|
+
|
|
8560
8617
|
const PearHyperliquidContext = createContext(undefined);
|
|
8561
8618
|
/**
|
|
8562
8619
|
* React Provider for PearHyperliquidClient
|
|
@@ -8855,4 +8912,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8855
8912
|
}
|
|
8856
8913
|
}
|
|
8857
8914
|
|
|
8858
|
-
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, 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
|
@@ -51,7 +51,7 @@ export type WebSocketConnectionState = 'connecting' | 'connected' | 'disconnecte
|
|
|
51
51
|
/**
|
|
52
52
|
* WebSocket channels
|
|
53
53
|
*/
|
|
54
|
-
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
54
|
+
export type WebSocketChannel = 'trade-histories' | 'open-positions' | 'open-orders' | 'account-summary' | 'twap-details' | 'notifications' | 'webData2' | 'allMids' | 'activeAssetData';
|
|
55
55
|
/**
|
|
56
56
|
* WebSocket subscription message
|
|
57
57
|
*/
|
|
@@ -74,6 +74,16 @@ export interface WebSocketDataMessage<T = unknown> {
|
|
|
74
74
|
channel: WebSocketChannel;
|
|
75
75
|
data: T;
|
|
76
76
|
}
|
|
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
|
+
export interface NotificationDto {
|
|
79
|
+
id: string;
|
|
80
|
+
address: string;
|
|
81
|
+
category: NotificationCategory;
|
|
82
|
+
parameters: Record<string, any>;
|
|
83
|
+
is_read: boolean;
|
|
84
|
+
created_at: string;
|
|
85
|
+
updated_at: string;
|
|
86
|
+
}
|
|
77
87
|
export interface ChunkFillDto {
|
|
78
88
|
fillId: string;
|
|
79
89
|
assetName: string;
|