@pear-protocol/hyperliquid-sdk 0.0.33 → 0.0.35
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/useNotifications.d.ts +3 -0
- package/dist/index.d.ts +20 -8
- package/dist/index.js +42 -4
- package/dist/types.d.ts +9 -7
- 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
|
+
}>>;
|
|
@@ -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;
|
|
@@ -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 = '
|
|
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
|
|
213
|
+
positionId?: string | null;
|
|
213
214
|
leverage: number;
|
|
214
215
|
usdValue: number;
|
|
215
|
-
triggerValue
|
|
216
|
-
twapDuration
|
|
217
|
-
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;
|
|
@@ -948,6 +950,9 @@ declare function useTwap(): {
|
|
|
948
950
|
interface UseNotificationsResult {
|
|
949
951
|
notifications: NotificationDto[] | null;
|
|
950
952
|
unreadCount: number;
|
|
953
|
+
markReadUntil: (timestampMs: number) => Promise<{
|
|
954
|
+
updated: number;
|
|
955
|
+
}>;
|
|
951
956
|
}
|
|
952
957
|
/**
|
|
953
958
|
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
@@ -976,6 +981,13 @@ interface UseHyperliquidNativeWebSocketReturn {
|
|
|
976
981
|
}
|
|
977
982
|
declare const useHyperliquidNativeWebSocket: ({ address, }: UseHyperliquidNativeWebSocketProps) => UseHyperliquidNativeWebSocketReturn;
|
|
978
983
|
|
|
984
|
+
/**
|
|
985
|
+
* Mark notifications as read up to a given timestamp (ms)
|
|
986
|
+
*/
|
|
987
|
+
declare function markNotificationsRead(baseUrl: string, accessToken: string, timestampMs: number): Promise<ApiResponse<{
|
|
988
|
+
updated: number;
|
|
989
|
+
}>>;
|
|
990
|
+
|
|
979
991
|
/**
|
|
980
992
|
* Account summary calculation utility class
|
|
981
993
|
*/
|
|
@@ -1078,5 +1090,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1078
1090
|
*/
|
|
1079
1091
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1080
1092
|
|
|
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 };
|
|
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 };
|
|
1082
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 };
|
package/dist/index.js
CHANGED
|
@@ -8363,7 +8363,12 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
|
|
|
8363
8363
|
};
|
|
8364
8364
|
const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
8365
8365
|
return rawPositions.map((position) => {
|
|
8366
|
-
const webData2Position = webData2.clearinghouseState.assetPositions.find(ap =>
|
|
8366
|
+
const webData2Position = webData2.clearinghouseState.assetPositions.find(ap => {
|
|
8367
|
+
var _a, _b, _c, _d;
|
|
8368
|
+
const longCoin = (_b = (_a = position.longAssets) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coin;
|
|
8369
|
+
const shortCoin = (_d = (_c = position.shortAssets) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.coin;
|
|
8370
|
+
return ap.position.coin === longCoin || ap.position.coin === shortCoin;
|
|
8371
|
+
});
|
|
8367
8372
|
let mappedPosition = {
|
|
8368
8373
|
positionId: position.positionId,
|
|
8369
8374
|
address: position.address,
|
|
@@ -8508,10 +8513,10 @@ function useOrders() {
|
|
|
8508
8513
|
if (!openOrders)
|
|
8509
8514
|
return null;
|
|
8510
8515
|
return openOrders.map((ord) => {
|
|
8511
|
-
var _a, _b, _c, _d;
|
|
8516
|
+
var _a, _b, _c, _d, _e;
|
|
8512
8517
|
const isTpSl = ord.orderType === 'TP' || ord.orderType === 'SL';
|
|
8513
8518
|
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);
|
|
8519
|
+
const pos = positionsById.get((_e = ord.positionId) !== null && _e !== void 0 ? _e : '');
|
|
8515
8520
|
if (!isTpSl || !pos)
|
|
8516
8521
|
return ord;
|
|
8517
8522
|
// Build order assets from position weights when TP/SL has no assets
|
|
@@ -8564,12 +8569,28 @@ function useTwap() {
|
|
|
8564
8569
|
return { orders, cancelTwap: cancelTwap$1 };
|
|
8565
8570
|
}
|
|
8566
8571
|
|
|
8572
|
+
/**
|
|
8573
|
+
* Mark notifications as read up to a given timestamp (ms)
|
|
8574
|
+
*/
|
|
8575
|
+
async function markNotificationsRead(baseUrl, accessToken, timestampMs) {
|
|
8576
|
+
const url = joinUrl(baseUrl, '/notifications/read');
|
|
8577
|
+
try {
|
|
8578
|
+
const response = await axios$1.post(url, { timestamp: timestampMs }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}` } });
|
|
8579
|
+
return { data: response.data, status: response.status, headers: response.headers };
|
|
8580
|
+
}
|
|
8581
|
+
catch (error) {
|
|
8582
|
+
throw toApiError(error);
|
|
8583
|
+
}
|
|
8584
|
+
}
|
|
8585
|
+
|
|
8567
8586
|
/**
|
|
8568
8587
|
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
8569
8588
|
* Data is persisted in the SDK's Zustand store.
|
|
8570
8589
|
*/
|
|
8571
8590
|
function useNotifications() {
|
|
8572
8591
|
const notifications = useUserData((state) => state.notifications);
|
|
8592
|
+
const setNotifications = useUserData((state) => state.setNotifications);
|
|
8593
|
+
const { apiBaseUrl, accessToken, isAuthenticated } = usePearHyperliquid();
|
|
8573
8594
|
const unreadCount = useMemo(() => {
|
|
8574
8595
|
if (!notifications)
|
|
8575
8596
|
return 0;
|
|
@@ -8578,6 +8599,23 @@ function useNotifications() {
|
|
|
8578
8599
|
return {
|
|
8579
8600
|
notifications,
|
|
8580
8601
|
unreadCount,
|
|
8602
|
+
markReadUntil: useCallback(async (timestampMs) => {
|
|
8603
|
+
if (!isAuthenticated || !accessToken)
|
|
8604
|
+
throw new Error('Not authenticated');
|
|
8605
|
+
const { data } = await markNotificationsRead(apiBaseUrl, accessToken, timestampMs);
|
|
8606
|
+
// Optimistic local update for immediate UI feedback
|
|
8607
|
+
if (notifications) {
|
|
8608
|
+
const updated = notifications.map((n) => {
|
|
8609
|
+
const created = Date.parse(n.created_at);
|
|
8610
|
+
if (!isNaN(created) && created <= timestampMs) {
|
|
8611
|
+
return { ...n, is_read: true };
|
|
8612
|
+
}
|
|
8613
|
+
return n;
|
|
8614
|
+
});
|
|
8615
|
+
setNotifications(updated);
|
|
8616
|
+
}
|
|
8617
|
+
return data;
|
|
8618
|
+
}, [apiBaseUrl, accessToken, isAuthenticated, notifications, setNotifications]),
|
|
8581
8619
|
};
|
|
8582
8620
|
}
|
|
8583
8621
|
|
|
@@ -8879,4 +8917,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8879
8917
|
}
|
|
8880
8918
|
}
|
|
8881
8919
|
|
|
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 };
|
|
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 };
|
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;
|
|
@@ -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 = '
|
|
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
|
|
234
|
+
positionId?: string | null;
|
|
234
235
|
leverage: number;
|
|
235
236
|
usdValue: number;
|
|
236
|
-
triggerValue
|
|
237
|
-
twapDuration
|
|
238
|
-
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;
|