@pear-protocol/hyperliquid-sdk 0.0.36 → 0.0.38
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 +6 -0
- package/dist/hooks/useNotifications.d.ts +3 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.js +45 -37
- package/dist/types.d.ts +1 -3
- package/package.json +1 -1
|
@@ -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
|
+
}>>;
|
|
@@ -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.
|
package/dist/index.d.ts
CHANGED
|
@@ -150,7 +150,7 @@ interface PositionAssetDetailDto {
|
|
|
150
150
|
entryPrice: number;
|
|
151
151
|
platformSize: number;
|
|
152
152
|
actualSize: number;
|
|
153
|
-
|
|
153
|
+
leverage: number;
|
|
154
154
|
marginUsed: number;
|
|
155
155
|
entryPositionValue: number;
|
|
156
156
|
positionValue: number;
|
|
@@ -168,12 +168,10 @@ interface TpSlThreshold {
|
|
|
168
168
|
interface OpenPositionDto {
|
|
169
169
|
positionId: string;
|
|
170
170
|
address: string;
|
|
171
|
-
leverage: number;
|
|
172
171
|
stopLoss: TpSlThreshold | null;
|
|
173
172
|
takeProfit: TpSlThreshold | null;
|
|
174
173
|
entryRatio: number;
|
|
175
174
|
markRatio: number;
|
|
176
|
-
netFunding: number;
|
|
177
175
|
entryPositionValue: number;
|
|
178
176
|
positionValue: number;
|
|
179
177
|
marginUsed: number;
|
|
@@ -964,6 +962,9 @@ interface UseNotificationsResult {
|
|
|
964
962
|
markReadUntil: (timestampMs: number) => Promise<{
|
|
965
963
|
updated: number;
|
|
966
964
|
}>;
|
|
965
|
+
markReadById: (id: string) => Promise<{
|
|
966
|
+
updated: number;
|
|
967
|
+
}>;
|
|
967
968
|
}
|
|
968
969
|
/**
|
|
969
970
|
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
@@ -998,6 +999,12 @@ declare const useHyperliquidNativeWebSocket: ({ address, }: UseHyperliquidNative
|
|
|
998
999
|
declare function markNotificationsRead(baseUrl: string, accessToken: string, timestampMs: number): Promise<ApiResponse<{
|
|
999
1000
|
updated: number;
|
|
1000
1001
|
}>>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Mark a single notification as read by id
|
|
1004
|
+
*/
|
|
1005
|
+
declare function markNotificationReadById(baseUrl: string, accessToken: string, id: string): Promise<ApiResponse<{
|
|
1006
|
+
updated: number;
|
|
1007
|
+
}>>;
|
|
1001
1008
|
|
|
1002
1009
|
/**
|
|
1003
1010
|
* Account summary calculation utility class
|
|
@@ -1101,5 +1108,5 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1101
1108
|
*/
|
|
1102
1109
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1103
1110
|
|
|
1104
|
-
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, 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 };
|
|
1111
|
+
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 };
|
|
1105
1112
|
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
|
@@ -8348,74 +8348,62 @@ async function cancelTwap(baseUrl, accessToken, orderId) {
|
|
|
8348
8348
|
}
|
|
8349
8349
|
}
|
|
8350
8350
|
|
|
8351
|
-
const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage,
|
|
8352
|
-
const
|
|
8353
|
-
const
|
|
8354
|
-
const marginUsed =
|
|
8351
|
+
const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, isLong = true) => {
|
|
8352
|
+
const entryNotional = asset.entryPrice * asset.size;
|
|
8353
|
+
const currentNotional = currentPrice * asset.size;
|
|
8354
|
+
const marginUsed = currentNotional / (leverage || 1);
|
|
8355
8355
|
const unrealizedPnl = isLong
|
|
8356
|
-
?
|
|
8357
|
-
:
|
|
8356
|
+
? currentNotional - entryNotional
|
|
8357
|
+
: entryNotional - currentNotional;
|
|
8358
8358
|
return {
|
|
8359
8359
|
coin: asset.coin,
|
|
8360
8360
|
entryPrice: asset.entryPrice,
|
|
8361
8361
|
actualSize: asset.size,
|
|
8362
|
+
leverage: leverage,
|
|
8362
8363
|
marginUsed: marginUsed,
|
|
8363
|
-
positionValue:
|
|
8364
|
+
positionValue: currentNotional,
|
|
8364
8365
|
unrealizedPnl: unrealizedPnl,
|
|
8365
|
-
entryPositionValue:
|
|
8366
|
-
initialWeight:
|
|
8367
|
-
cumFunding: {
|
|
8368
|
-
allTime: parseFloat((cumFunding === null || cumFunding === void 0 ? void 0 : cumFunding.allTime) || "0"),
|
|
8369
|
-
sinceChange: parseFloat((cumFunding === null || cumFunding === void 0 ? void 0 : cumFunding.sinceChange) || "0"),
|
|
8370
|
-
sinceOpen: parseFloat((cumFunding === null || cumFunding === void 0 ? void 0 : cumFunding.sinceOpen) || "0"),
|
|
8371
|
-
}
|
|
8366
|
+
entryPositionValue: entryNotional,
|
|
8367
|
+
initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
|
|
8372
8368
|
};
|
|
8373
8369
|
};
|
|
8374
8370
|
const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
8375
8371
|
return rawPositions.map((position) => {
|
|
8376
|
-
const webData2Position = webData2.clearinghouseState.assetPositions.find(ap => {
|
|
8377
|
-
var _a, _b, _c, _d;
|
|
8378
|
-
const longCoin = (_b = (_a = position.longAssets) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.coin;
|
|
8379
|
-
const shortCoin = (_d = (_c = position.shortAssets) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.coin;
|
|
8380
|
-
return ap.position.coin === longCoin || ap.position.coin === shortCoin;
|
|
8381
|
-
});
|
|
8382
8372
|
let mappedPosition = {
|
|
8383
8373
|
positionId: position.positionId,
|
|
8384
8374
|
address: position.address,
|
|
8385
|
-
leverage: webData2Position === null || webData2Position === void 0 ? void 0 : webData2Position.position.leverage.value, // TODO: consider if user manually change leverage from the HL UI
|
|
8386
8375
|
entryRatio: 1,
|
|
8387
8376
|
marginUsed: 0,
|
|
8388
8377
|
markRatio: 1,
|
|
8389
8378
|
unrealizedPnl: 0,
|
|
8390
|
-
netFunding: 0,
|
|
8391
8379
|
positionValue: 0,
|
|
8380
|
+
entryPositionValue: 0,
|
|
8392
8381
|
takeProfit: position.takeProfit,
|
|
8393
8382
|
stopLoss: position.stopLoss,
|
|
8394
8383
|
};
|
|
8395
8384
|
const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0) +
|
|
8396
8385
|
position.shortAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0);
|
|
8397
8386
|
mappedPosition.longAssets = position.longAssets.map(longAsset => {
|
|
8398
|
-
var _a;
|
|
8387
|
+
var _a, _b, _c;
|
|
8399
8388
|
const currentPrice = parseFloat(allMids.mids[longAsset.coin]);
|
|
8400
|
-
const
|
|
8401
|
-
const
|
|
8389
|
+
const assetState = (_a = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
|
|
8390
|
+
const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0;
|
|
8391
|
+
const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, leverage, true);
|
|
8402
8392
|
mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
|
|
8403
8393
|
mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
|
|
8404
8394
|
mappedPosition.positionValue += mappedPositionAssets.positionValue;
|
|
8405
8395
|
mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
|
|
8406
|
-
mappedPosition.netFunding += mappedPositionAssets.cumFunding.sinceOpen;
|
|
8407
|
-
// Calculate weighted entry and mark ratios for long positions
|
|
8408
8396
|
mappedPosition.entryRatio *= Math.pow(longAsset.entryPrice, mappedPositionAssets.initialWeight);
|
|
8409
8397
|
mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.initialWeight);
|
|
8410
8398
|
return mappedPositionAssets;
|
|
8411
8399
|
});
|
|
8412
8400
|
mappedPosition.shortAssets = position.shortAssets.map(shortAsset => {
|
|
8413
|
-
var _a;
|
|
8401
|
+
var _a, _b, _c;
|
|
8414
8402
|
const currentPrice = parseFloat(allMids.mids[shortAsset.coin]);
|
|
8415
|
-
const
|
|
8416
|
-
const
|
|
8403
|
+
const assetState = (_a = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
|
|
8404
|
+
const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 0;
|
|
8405
|
+
const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, leverage, false);
|
|
8417
8406
|
mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
|
|
8418
|
-
mappedPosition.netFunding += mappedPositionAssets.cumFunding.sinceOpen;
|
|
8419
8407
|
mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
|
|
8420
8408
|
mappedPosition.positionValue += mappedPositionAssets.positionValue;
|
|
8421
8409
|
mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
|
|
@@ -8423,6 +8411,7 @@ const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
|
8423
8411
|
mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.initialWeight);
|
|
8424
8412
|
return mappedPositionAssets;
|
|
8425
8413
|
});
|
|
8414
|
+
mappedPosition.positionValue = mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
|
|
8426
8415
|
return mappedPosition;
|
|
8427
8416
|
});
|
|
8428
8417
|
};
|
|
@@ -8540,15 +8529,11 @@ function useOrders() {
|
|
|
8540
8529
|
if (!hasAssets) {
|
|
8541
8530
|
return {
|
|
8542
8531
|
...ord,
|
|
8543
|
-
leverage: pos.leverage,
|
|
8544
8532
|
longAssets: mapAssets(pos.longAssets),
|
|
8545
8533
|
shortAssets: mapAssets(pos.shortAssets),
|
|
8546
8534
|
};
|
|
8547
8535
|
}
|
|
8548
|
-
//
|
|
8549
|
-
if (ord.leverage !== pos.leverage) {
|
|
8550
|
-
return { ...ord, leverage: pos.leverage };
|
|
8551
|
-
}
|
|
8536
|
+
// Leverage is now tracked per-asset in positions; keep order leverage as-is
|
|
8552
8537
|
return ord;
|
|
8553
8538
|
});
|
|
8554
8539
|
}, [openOrders, positionsById]);
|
|
@@ -8598,6 +8583,19 @@ async function markNotificationsRead(baseUrl, accessToken, timestampMs) {
|
|
|
8598
8583
|
throw toApiError(error);
|
|
8599
8584
|
}
|
|
8600
8585
|
}
|
|
8586
|
+
/**
|
|
8587
|
+
* Mark a single notification as read by id
|
|
8588
|
+
*/
|
|
8589
|
+
async function markNotificationReadById(baseUrl, accessToken, id) {
|
|
8590
|
+
const url = joinUrl(baseUrl, '/notifications/read');
|
|
8591
|
+
try {
|
|
8592
|
+
const response = await axios$1.post(url, { id }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${accessToken}` } });
|
|
8593
|
+
return { data: response.data, status: response.status, headers: response.headers };
|
|
8594
|
+
}
|
|
8595
|
+
catch (error) {
|
|
8596
|
+
throw toApiError(error);
|
|
8597
|
+
}
|
|
8598
|
+
}
|
|
8601
8599
|
|
|
8602
8600
|
/**
|
|
8603
8601
|
* Provides notifications and fills checkpoint data sourced from the SDK WebSocket.
|
|
@@ -8632,6 +8630,16 @@ function useNotifications() {
|
|
|
8632
8630
|
}
|
|
8633
8631
|
return data;
|
|
8634
8632
|
}, [apiBaseUrl, accessToken, isAuthenticated, notifications, setNotifications]),
|
|
8633
|
+
markReadById: useCallback(async (id) => {
|
|
8634
|
+
if (!isAuthenticated || !accessToken)
|
|
8635
|
+
throw new Error('Not authenticated');
|
|
8636
|
+
const { data } = await markNotificationReadById(apiBaseUrl, accessToken, id);
|
|
8637
|
+
if (notifications) {
|
|
8638
|
+
const updated = notifications.map((n) => (n.id === id ? { ...n, is_read: true } : n));
|
|
8639
|
+
setNotifications(updated);
|
|
8640
|
+
}
|
|
8641
|
+
return data;
|
|
8642
|
+
}, [apiBaseUrl, accessToken, isAuthenticated, notifications, setNotifications]),
|
|
8635
8643
|
};
|
|
8636
8644
|
}
|
|
8637
8645
|
|
|
@@ -8933,4 +8941,4 @@ function mapCandleIntervalToTradingViewInterval(interval) {
|
|
|
8933
8941
|
}
|
|
8934
8942
|
}
|
|
8935
8943
|
|
|
8936
|
-
export { AccountSummaryCalculator, AuthStatus, ConflictDetector, PearHyperliquidProvider, TokenMetadataExtractor, adjustOrder, adjustPosition, calculateWeightedRatio, cancelOrder, cancelTwap, cancelTwapOrder, closeAllPositions, 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 };
|
|
8944
|
+
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/dist/types.d.ts
CHANGED
|
@@ -171,7 +171,7 @@ export interface PositionAssetDetailDto {
|
|
|
171
171
|
entryPrice: number;
|
|
172
172
|
platformSize: number;
|
|
173
173
|
actualSize: number;
|
|
174
|
-
|
|
174
|
+
leverage: number;
|
|
175
175
|
marginUsed: number;
|
|
176
176
|
entryPositionValue: number;
|
|
177
177
|
positionValue: number;
|
|
@@ -189,12 +189,10 @@ export interface TpSlThreshold {
|
|
|
189
189
|
export interface OpenPositionDto {
|
|
190
190
|
positionId: string;
|
|
191
191
|
address: string;
|
|
192
|
-
leverage: number;
|
|
193
192
|
stopLoss: TpSlThreshold | null;
|
|
194
193
|
takeProfit: TpSlThreshold | null;
|
|
195
194
|
entryRatio: number;
|
|
196
195
|
markRatio: number;
|
|
197
|
-
netFunding: number;
|
|
198
196
|
entryPositionValue: number;
|
|
199
197
|
positionValue: number;
|
|
200
198
|
marginUsed: number;
|