@pear-protocol/hyperliquid-sdk 0.0.50 → 0.0.52
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/sync.d.ts +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -6
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
package/dist/clients/sync.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiResponse, SyncFillsRequestDto, SyncFillsResponseDto } from '../types';
|
|
1
|
+
import type { ApiResponse, AssetPosition, SyncFillsRequestDto, SyncFillsResponseDto } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Sync external fills into Pear Hyperliquid service (POST /sync/fills)
|
|
4
4
|
*/
|
|
@@ -6,4 +6,4 @@ export declare const syncFills: (baseUrl: string, accessToken: string, payload:
|
|
|
6
6
|
/**
|
|
7
7
|
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
8
8
|
*/
|
|
9
|
-
export declare const syncUserFillsFromHyperliquid: (baseUrl: string, accessToken: string, user: string, aggregateByTime
|
|
9
|
+
export declare const syncUserFillsFromHyperliquid: (baseUrl: string, accessToken: string, user: string, aggregateByTime: boolean | undefined, lastSyncAt: number | null | undefined, assetPositions: AssetPosition[]) => Promise<ApiResponse<SyncFillsResponseDto>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,7 @@ interface TradeHistoryAssetDataDto {
|
|
|
123
123
|
entryWeight: number;
|
|
124
124
|
entryPrice: number;
|
|
125
125
|
limitPrice: number;
|
|
126
|
+
leverage: number;
|
|
126
127
|
size: number;
|
|
127
128
|
externalFeePaid: number;
|
|
128
129
|
builderFeePaid: number;
|
|
@@ -138,6 +139,7 @@ interface TradeHistoryDataDto {
|
|
|
138
139
|
externalFeePaid: number;
|
|
139
140
|
builderFeePaid: number;
|
|
140
141
|
realizedPnl: number;
|
|
142
|
+
realizedPnlPercentage: number;
|
|
141
143
|
totalEntryValue: number;
|
|
142
144
|
totalValue: number;
|
|
143
145
|
entryRatio: number;
|
|
@@ -192,6 +194,7 @@ interface OpenPositionDto {
|
|
|
192
194
|
positionValue: number;
|
|
193
195
|
marginUsed: number;
|
|
194
196
|
unrealizedPnl: number;
|
|
197
|
+
unrealizedPnlPercentage: number;
|
|
195
198
|
longAssets: PositionAssetDetailDto[];
|
|
196
199
|
shortAssets: PositionAssetDetailDto[];
|
|
197
200
|
createdAt: string;
|
package/dist/index.js
CHANGED
|
@@ -6007,7 +6007,7 @@ const syncFills = async (baseUrl, accessToken, payload) => {
|
|
|
6007
6007
|
/**
|
|
6008
6008
|
* Convenience: fetch user fills from HyperLiquid, then sync them to Pear backend
|
|
6009
6009
|
*/
|
|
6010
|
-
const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true, lastSyncAt = null) => {
|
|
6010
|
+
const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregateByTime = true, lastSyncAt = null, assetPositions) => {
|
|
6011
6011
|
const firstStartTime = lastSyncAt ? Number(lastSyncAt) : 1735660800000;
|
|
6012
6012
|
const allFills = [];
|
|
6013
6013
|
const seenTids = new Set();
|
|
@@ -6030,7 +6030,7 @@ const syncUserFillsFromHyperliquid = async (baseUrl, accessToken, user, aggregat
|
|
|
6030
6030
|
startTime = last.time;
|
|
6031
6031
|
}
|
|
6032
6032
|
} while (batchSize === 2000);
|
|
6033
|
-
return syncFills(baseUrl, accessToken, { user, fills: allFills });
|
|
6033
|
+
return syncFills(baseUrl, accessToken, { user, fills: allFills, assetPositions });
|
|
6034
6034
|
};
|
|
6035
6035
|
|
|
6036
6036
|
/**
|
|
@@ -6054,18 +6054,21 @@ function useAutoSyncFills(options) {
|
|
|
6054
6054
|
return Boolean(enabled && address && baseUrl && accessToken);
|
|
6055
6055
|
}, [enabled, address, baseUrl, accessToken]);
|
|
6056
6056
|
const doSync = useCallback(async () => {
|
|
6057
|
+
var _a;
|
|
6057
6058
|
if (!canRun)
|
|
6058
6059
|
return;
|
|
6059
6060
|
if (runningRef.current)
|
|
6060
6061
|
return;
|
|
6061
6062
|
if (!useUserData.getState().accountSummary)
|
|
6062
6063
|
return;
|
|
6064
|
+
if (!((_a = useHyperliquidData.getState().aggregatedClearingHouseState) === null || _a === void 0 ? void 0 : _a.assetPositions))
|
|
6065
|
+
return;
|
|
6063
6066
|
setIsSyncing(true);
|
|
6064
6067
|
setError(null);
|
|
6065
6068
|
const promise = (async () => {
|
|
6066
6069
|
var _a;
|
|
6067
6070
|
try {
|
|
6068
|
-
const { data } = await syncUserFillsFromHyperliquid(baseUrl, accessToken, address, aggregateByTime, lastSyncedAt);
|
|
6071
|
+
const { data } = await syncUserFillsFromHyperliquid(baseUrl, accessToken, address, aggregateByTime, lastSyncedAt, useHyperliquidData.getState().aggregatedClearingHouseState.assetPositions);
|
|
6069
6072
|
if (!mountedRef.current)
|
|
6070
6073
|
return;
|
|
6071
6074
|
setLastResult(data);
|
|
@@ -6386,17 +6389,15 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
|
|
|
6386
6389
|
return mappedPositionAssets;
|
|
6387
6390
|
});
|
|
6388
6391
|
mappedPosition.positionValue = mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
|
|
6389
|
-
// If exactly one long and one short asset, include simple price ratios
|
|
6390
6392
|
if (position.longAssets.length === 1 && position.shortAssets.length === 1) {
|
|
6391
6393
|
const long = position.longAssets[0];
|
|
6392
6394
|
const short = position.shortAssets[0];
|
|
6393
6395
|
const longMark = parseFloat(allMids.mids[long.coin]);
|
|
6394
6396
|
const shortMark = parseFloat(allMids.mids[short.coin]);
|
|
6395
|
-
// entryPriceRatio = long entry price / short entry price
|
|
6396
6397
|
mappedPosition.entryPriceRatio = long.entryPrice / short.entryPrice;
|
|
6397
|
-
// markPriceRatio = long current price / short current price
|
|
6398
6398
|
mappedPosition.markPriceRatio = longMark / shortMark;
|
|
6399
6399
|
}
|
|
6400
|
+
mappedPosition.unrealizedPnlPercentage = mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
|
|
6400
6401
|
return mappedPosition;
|
|
6401
6402
|
});
|
|
6402
6403
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface ExternalFillDto {
|
|
|
35
35
|
export interface SyncFillsRequestDto {
|
|
36
36
|
user: string;
|
|
37
37
|
fills: ExternalFillDto[];
|
|
38
|
+
assetPositions?: AssetPosition[];
|
|
38
39
|
}
|
|
39
40
|
export interface SyncFillsResponseDto {
|
|
40
41
|
insertedFills: number;
|
|
@@ -152,6 +153,7 @@ export interface TradeHistoryAssetDataDto {
|
|
|
152
153
|
entryWeight: number;
|
|
153
154
|
entryPrice: number;
|
|
154
155
|
limitPrice: number;
|
|
156
|
+
leverage: number;
|
|
155
157
|
size: number;
|
|
156
158
|
externalFeePaid: number;
|
|
157
159
|
builderFeePaid: number;
|
|
@@ -167,6 +169,7 @@ export interface TradeHistoryDataDto {
|
|
|
167
169
|
externalFeePaid: number;
|
|
168
170
|
builderFeePaid: number;
|
|
169
171
|
realizedPnl: number;
|
|
172
|
+
realizedPnlPercentage: number;
|
|
170
173
|
totalEntryValue: number;
|
|
171
174
|
totalValue: number;
|
|
172
175
|
entryRatio: number;
|
|
@@ -221,6 +224,7 @@ export interface OpenPositionDto {
|
|
|
221
224
|
positionValue: number;
|
|
222
225
|
marginUsed: number;
|
|
223
226
|
unrealizedPnl: number;
|
|
227
|
+
unrealizedPnlPercentage: number;
|
|
224
228
|
longAssets: PositionAssetDetailDto[];
|
|
225
229
|
shortAssets: PositionAssetDetailDto[];
|
|
226
230
|
createdAt: string;
|