@pear-protocol/hyperliquid-sdk 0.0.32 → 0.0.33
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/hooks/index.d.ts +1 -0
- package/dist/hooks/useNotifications.d.ts +10 -0
- package/dist/index.d.ts +23 -3
- package/dist/index.js +26 -2
- package/dist/types.d.ts +11 -1
- package/package.json +1 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotificationDto } from '../types';
|
|
2
|
+
export interface UseNotificationsResult {
|
|
3
|
+
notifications: NotificationDto[] | null;
|
|
4
|
+
unreadCount: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
8
|
+
* Data is persisted in the SDK's Zustand store.
|
|
9
|
+
*/
|
|
10
|
+
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' | '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,16 @@ 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
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
954
|
+
* Data is persisted in the SDK's Zustand store.
|
|
955
|
+
*/
|
|
956
|
+
declare function useNotifications(): UseNotificationsResult;
|
|
957
|
+
|
|
938
958
|
interface UseHyperliquidWebSocketProps {
|
|
939
959
|
wsUrl: string;
|
|
940
960
|
address: string | null;
|
|
@@ -1058,5 +1078,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1058
1078
|
*/
|
|
1059
1079
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1060
1080
|
|
|
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 };
|
|
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 };
|
|
1082
|
+
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,23 @@ function useTwap() {
|
|
|
8557
8564
|
return { orders, cancelTwap: cancelTwap$1 };
|
|
8558
8565
|
}
|
|
8559
8566
|
|
|
8567
|
+
/**
|
|
8568
|
+
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
8569
|
+
* Data is persisted in the SDK's Zustand store.
|
|
8570
|
+
*/
|
|
8571
|
+
function useNotifications() {
|
|
8572
|
+
const notifications = useUserData((state) => state.notifications);
|
|
8573
|
+
const unreadCount = useMemo(() => {
|
|
8574
|
+
if (!notifications)
|
|
8575
|
+
return 0;
|
|
8576
|
+
return notifications.reduce((acc, n) => acc + (n.is_read ? 0 : 1), 0);
|
|
8577
|
+
}, [notifications]);
|
|
8578
|
+
return {
|
|
8579
|
+
notifications,
|
|
8580
|
+
unreadCount,
|
|
8581
|
+
};
|
|
8582
|
+
}
|
|
8583
|
+
|
|
8560
8584
|
const PearHyperliquidContext = createContext(undefined);
|
|
8561
8585
|
/**
|
|
8562
8586
|
* React Provider for PearHyperliquidClient
|
|
@@ -8855,4 +8879,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8855
8879
|
}
|
|
8856
8880
|
}
|
|
8857
8881
|
|
|
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 };
|
|
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 };
|
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' | '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;
|