@pear-protocol/hyperliquid-sdk 0.0.31 → 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 +0 -2
- package/dist/index.js +28 -6
- package/dist/types.d.ts +0 -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
|
@@ -120,7 +120,6 @@ interface TradeHistoryDataDto {
|
|
|
120
120
|
totalValue: number;
|
|
121
121
|
entryRatio: number;
|
|
122
122
|
exitRatio: number;
|
|
123
|
-
leverage: number;
|
|
124
123
|
longAssets: TradeHistoryAssetDataDto[];
|
|
125
124
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
126
125
|
createdAt: string;
|
|
@@ -433,7 +432,6 @@ interface RawAssetDto {
|
|
|
433
432
|
interface RawPositionDto {
|
|
434
433
|
positionId: string;
|
|
435
434
|
address: string;
|
|
436
|
-
leverage: number;
|
|
437
435
|
stopLoss: number | null;
|
|
438
436
|
takeProfit: number | null;
|
|
439
437
|
status: string;
|
package/dist/index.js
CHANGED
|
@@ -7561,8 +7561,8 @@ const fetchHistoricalCandles = async (coin, startTime, endTime, interval) => {
|
|
|
7561
7561
|
/**
|
|
7562
7562
|
* Retrieve recent user fills from HyperLiquid and map to ExternalFillDto[]
|
|
7563
7563
|
*/
|
|
7564
|
-
const fetchUserFillsFromHyperliquid = async (user, aggregateByTime = true) => {
|
|
7565
|
-
const request = { type: '
|
|
7564
|
+
const fetchUserFillsFromHyperliquid = async (user, startTime, aggregateByTime = true) => {
|
|
7565
|
+
const request = { type: 'userFillsByTime', user, startTime, aggregateByTime };
|
|
7566
7566
|
try {
|
|
7567
7567
|
const response = await axios$1.post('https://api.hyperliquid.xyz/info', request, {
|
|
7568
7568
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -8181,8 +8181,29 @@ const syncFills = async (baseUrl, accessToken, payload) => {
|
|
|
8181
8181
|
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
8182
8182
|
*/
|
|
8183
8183
|
const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true) => {
|
|
8184
|
-
const
|
|
8185
|
-
|
|
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 });
|
|
8186
8207
|
};
|
|
8187
8208
|
|
|
8188
8209
|
/**
|
|
@@ -8335,10 +8356,11 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
|
|
|
8335
8356
|
};
|
|
8336
8357
|
const buildPositionValue = (rawPositions, webData2, allMids) => {
|
|
8337
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);
|
|
8338
8360
|
let mappedPosition = {
|
|
8339
8361
|
positionId: position.positionId,
|
|
8340
8362
|
address: position.address,
|
|
8341
|
-
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
|
|
8342
8364
|
entryRatio: 1,
|
|
8343
8365
|
marginUsed: 0,
|
|
8344
8366
|
markRatio: 1,
|
|
@@ -8653,7 +8675,7 @@ const PearHyperliquidProvider = ({ children, apiBaseUrl = 'https://hl-v2.pearpro
|
|
|
8653
8675
|
address,
|
|
8654
8676
|
intervalMs: 60000,
|
|
8655
8677
|
aggregateByTime: true,
|
|
8656
|
-
enabled:
|
|
8678
|
+
enabled: Boolean(isAuthenticated && address && accessToken),
|
|
8657
8679
|
});
|
|
8658
8680
|
const contextValue = useMemo(() => ({
|
|
8659
8681
|
// Config
|
package/dist/types.d.ts
CHANGED
|
@@ -141,7 +141,6 @@ export interface TradeHistoryDataDto {
|
|
|
141
141
|
totalValue: number;
|
|
142
142
|
entryRatio: number;
|
|
143
143
|
exitRatio: number;
|
|
144
|
-
leverage: number;
|
|
145
144
|
longAssets: TradeHistoryAssetDataDto[];
|
|
146
145
|
shortAssets: TradeHistoryAssetDataDto[];
|
|
147
146
|
createdAt: string;
|
|
@@ -518,7 +517,6 @@ export interface RawAssetDto {
|
|
|
518
517
|
export interface RawPositionDto {
|
|
519
518
|
positionId: string;
|
|
520
519
|
address: string;
|
|
521
|
-
leverage: number;
|
|
522
520
|
stopLoss: number | null;
|
|
523
521
|
takeProfit: number | null;
|
|
524
522
|
status: string;
|