@pear-protocol/hyperliquid-sdk 0.0.30 → 0.0.32
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/hyperliquid.d.ts +1 -1
- package/dist/index.d.ts +41 -3
- package/dist/index.js +29 -8
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -6,4 +6,4 @@ export declare const fetchHistoricalCandles: (coin: string, startTime: number, e
|
|
|
6
6
|
/**
|
|
7
7
|
* Retrieve recent user fills from HyperLiquid and map to ExternalFillDto[]
|
|
8
8
|
*/
|
|
9
|
-
export declare const fetchUserFillsFromHyperliquid: (user: string, aggregateByTime?: boolean) => Promise<ApiResponse<ExternalFillDto[]>>;
|
|
9
|
+
export declare const fetchUserFillsFromHyperliquid: (user: string, startTime: number, aggregateByTime?: boolean) => Promise<ApiResponse<ExternalFillDto[]>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,46 @@ interface WebSocketDataMessage<T = unknown> {
|
|
|
53
53
|
channel: WebSocketChannel;
|
|
54
54
|
data: T;
|
|
55
55
|
}
|
|
56
|
+
interface ChunkFillDto {
|
|
57
|
+
fillId: string;
|
|
58
|
+
assetName: string;
|
|
59
|
+
price: number;
|
|
60
|
+
size: number;
|
|
61
|
+
executedAt: string;
|
|
62
|
+
}
|
|
63
|
+
type TwapChunkStatus = 'PENDING' | 'SCHEDULED' | 'EXECUTING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
64
|
+
interface TwapChunkStatusDto {
|
|
65
|
+
chunkId: string;
|
|
66
|
+
chunkIndex: number;
|
|
67
|
+
scheduledTime: string;
|
|
68
|
+
executedTime?: string;
|
|
69
|
+
status: TwapChunkStatus;
|
|
70
|
+
chunkSize: number;
|
|
71
|
+
fills: ChunkFillDto[];
|
|
72
|
+
errorMessage?: string;
|
|
73
|
+
}
|
|
74
|
+
type TwapOrderOverallStatus = 'OPEN' | 'EXECUTING' | 'COMPLETED' | 'PARTIALLY_COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
75
|
+
interface TwapMonitoringDto {
|
|
76
|
+
orderId: string;
|
|
77
|
+
positionId?: string;
|
|
78
|
+
address: string;
|
|
79
|
+
orderType: string;
|
|
80
|
+
status: TwapOrderOverallStatus;
|
|
81
|
+
totalUsdValue: number;
|
|
82
|
+
filledUsdValue: number;
|
|
83
|
+
remainingUsdValue: number;
|
|
84
|
+
twapDuration: string;
|
|
85
|
+
randomizeExecution: boolean;
|
|
86
|
+
reduceOnly: boolean;
|
|
87
|
+
chunks: TwapChunkStatusDto[];
|
|
88
|
+
estimatedCompletionTime?: string;
|
|
89
|
+
actualCompletionTime?: string;
|
|
90
|
+
remainingChunks: number;
|
|
91
|
+
longAssets: OrderAssetDto[];
|
|
92
|
+
shortAssets: OrderAssetDto[];
|
|
93
|
+
createdAt: string;
|
|
94
|
+
updatedAt: string;
|
|
95
|
+
}
|
|
56
96
|
/**
|
|
57
97
|
* Trade history asset data
|
|
58
98
|
*/
|
|
@@ -80,7 +120,6 @@ interface TradeHistoryDataDto {
|
|
|
80
120
|
totalValue: number;
|
|
81
121
|
entryRatio: number;
|
|
82
122
|
exitRatio: number;
|
|
83
|
-
leverage: number;
|
|
84
123
|
longAssets: TradeHistoryAssetDataDto[];
|
|
85
124
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
86
125
|
createdAt: string;
|
|
@@ -393,7 +432,6 @@ interface RawAssetDto {
|
|
|
393
432
|
interface RawPositionDto {
|
|
394
433
|
positionId: string;
|
|
395
434
|
address: string;
|
|
396
|
-
leverage: number;
|
|
397
435
|
stopLoss: number | null;
|
|
398
436
|
takeProfit: number | null;
|
|
399
437
|
status: string;
|
|
@@ -1021,4 +1059,4 @@ declare function mapTradingViewIntervalToCandleInterval(interval: string): Candl
|
|
|
1021
1059
|
declare function mapCandleIntervalToTradingViewInterval(interval: CandleInterval): string;
|
|
1022
1060
|
|
|
1023
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 };
|
|
1024
|
-
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, UniverseAsset, UpdateRiskParametersRequestInput, UpdateRiskParametersResponseDto, UseAgentWalletOptions, UseAuthOptions, UseBasketCandlesReturn, UseHistoricalPriceDataReturn, UsePerformanceOverlaysReturn, UseTokenSelectionMetadataReturn, UserProfile, UserSelectionState, WebData2Response, WebSocketAckResponse, WebSocketChannel, WebSocketConnectionState, WebSocketDataMessage, WebSocketMessage, WebSocketSubscribeMessage, WsAllMidsData };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -2491,8 +2491,7 @@ const useHyperliquidWebSocket = ({ wsUrl, address }) => {
|
|
|
2491
2491
|
setAccountSummary(dataMessage.data);
|
|
2492
2492
|
break;
|
|
2493
2493
|
case 'twap-details':
|
|
2494
|
-
|
|
2495
|
-
setTwapDetails && setTwapDetails(dataMessage.data);
|
|
2494
|
+
setTwapDetails(dataMessage.data);
|
|
2496
2495
|
break;
|
|
2497
2496
|
}
|
|
2498
2497
|
}
|
|
@@ -7562,8 +7561,8 @@ const fetchHistoricalCandles = async (coin, startTime, endTime, interval) => {
|
|
|
7562
7561
|
/**
|
|
7563
7562
|
* Retrieve recent user fills from HyperLiquid and map to ExternalFillDto[]
|
|
7564
7563
|
*/
|
|
7565
|
-
const fetchUserFillsFromHyperliquid = async (user, aggregateByTime = true) => {
|
|
7566
|
-
const request = { type: '
|
|
7564
|
+
const fetchUserFillsFromHyperliquid = async (user, startTime, aggregateByTime = true) => {
|
|
7565
|
+
const request = { type: 'userFillsByTime', user, startTime, aggregateByTime };
|
|
7567
7566
|
try {
|
|
7568
7567
|
const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
|
|
7569
7568
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -8182,8 +8181,29 @@ const syncFills = async (baseUrl, accessToken, payload) => {
|
|
|
8182
8181
|
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
8183
8182
|
*/
|
|
8184
8183
|
const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true) => {
|
|
8185
|
-
const
|
|
8186
|
-
|
|
8184
|
+
const firstStartTime = 1735660800000; // 1 January 2025
|
|
8185
|
+
const allFills = [];
|
|
8186
|
+
const seenTids = new Set();
|
|
8187
|
+
let startTime = firstStartTime;
|
|
8188
|
+
let batchSize = 0;
|
|
8189
|
+
do {
|
|
8190
|
+
const { data: batch } = await fetchUserFillsFromHyperliquid(user, startTime, aggregateByTime);
|
|
8191
|
+
batchSize = batch.length;
|
|
8192
|
+
for (const fill of batch) {
|
|
8193
|
+
const tid = fill.tid;
|
|
8194
|
+
if (tid === undefined)
|
|
8195
|
+
continue;
|
|
8196
|
+
if (!seenTids.has(tid)) {
|
|
8197
|
+
seenTids.add(tid);
|
|
8198
|
+
allFills.push(fill);
|
|
8199
|
+
}
|
|
8200
|
+
}
|
|
8201
|
+
if (batchSize === 2000) {
|
|
8202
|
+
const last = batch[batch.length - 1];
|
|
8203
|
+
startTime = last.time;
|
|
8204
|
+
}
|
|
8205
|
+
} while (batchSize === 2000);
|
|
8206
|
+
return syncFills(baseUrl, accessToken, { user, fills: allFills });
|
|
8187
8207
|
};
|
|
8188
8208
|
|
|
8189
8209
|
/**
|
|
@@ -8336,10 +8356,11 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
|
|
|
8336
8356
|
};
|
|
8337
8357
|
const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
8338
8358
|
return rawPositions.map((position) => {
|
|
8359
|
+
const webData2Position = webData2.clearinghouseState.assetPositions.find(ap => ap.position.coin === position.longAssets[0].coin || ap.position.coin === position.shortAssets[0].coin);
|
|
8339
8360
|
let mappedPosition = {
|
|
8340
8361
|
positionId: position.positionId,
|
|
8341
8362
|
address: position.address,
|
|
8342
|
-
leverage: position.leverage,
|
|
8363
|
+
leverage: webData2Position === null || webData2Position === void 0 ? void 0 : webData2Position.position.leverage.value, // TODO: consider if user manually change leverage from the HL UI
|
|
8343
8364
|
entryRatio: 1,
|
|
8344
8365
|
marginUsed: 0,
|
|
8345
8366
|
markRatio: 1,
|
|
@@ -8654,7 +8675,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
8654
8675
|
address,
|
|
8655
8676
|
intervalMs: 60000,
|
|
8656
8677
|
aggregateByTime: true,
|
|
8657
|
-
enabled:
|
|
8678
|
+
enabled: Boolean(isAuthenticated && address && accessToken),
|
|
8658
8679
|
});
|
|
8659
8680
|
const contextValue = useMemo(() => ({
|
|
8660
8681
|
// Config
|
package/dist/types.d.ts
CHANGED
|
@@ -109,6 +109,8 @@ export interface TwapMonitoringDto {
|
|
|
109
109
|
estimatedCompletionTime?: string;
|
|
110
110
|
actualCompletionTime?: string;
|
|
111
111
|
remainingChunks: number;
|
|
112
|
+
longAssets: OrderAssetDto[];
|
|
113
|
+
shortAssets: OrderAssetDto[];
|
|
112
114
|
createdAt: string;
|
|
113
115
|
updatedAt: string;
|
|
114
116
|
}
|
|
@@ -139,7 +141,6 @@ export interface TradeHistoryDataDto {
|
|
|
139
141
|
totalValue: number;
|
|
140
142
|
entryRatio: number;
|
|
141
143
|
exitRatio: number;
|
|
142
|
-
leverage: number;
|
|
143
144
|
longAssets: TradeHistoryAssetDataDto[];
|
|
144
145
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
145
146
|
createdAt: string;
|
|
@@ -516,7 +517,6 @@ export interface RawAssetDto {
|
|
|
516
517
|
export interface RawPositionDto {
|
|
517
518
|
positionId: string;
|
|
518
519
|
address: string;
|
|
519
|
-
leverage: number;
|
|
520
520
|
stopLoss: number | null;
|
|
521
521
|
takeProfit: number | null;
|
|
522
522
|
status: string;
|