@pear-protocol/hyperliquid-sdk 0.1.13 → 0.1.14
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/index.d.ts +1 -0
- package/dist/index.js +16 -5
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -6964,7 +6964,7 @@ async function updateLeverage(baseUrl, positionId, payload) {
|
|
|
6964
6964
|
}
|
|
6965
6965
|
}
|
|
6966
6966
|
|
|
6967
|
-
const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, leverage, metadata, isLong = true) => {
|
|
6967
|
+
const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, totalCurrentPositionSize, leverage, metadata, isLong = true) => {
|
|
6968
6968
|
var _a;
|
|
6969
6969
|
const entryNotional = asset.entryPrice * asset.size;
|
|
6970
6970
|
const currentNotional = currentPrice * asset.size;
|
|
@@ -6985,6 +6985,7 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
|
|
|
6985
6985
|
unrealizedPnl: unrealizedPnl,
|
|
6986
6986
|
entryPositionValue: entryNotional,
|
|
6987
6987
|
initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
|
|
6988
|
+
currentWeight: totalCurrentPositionSize > 0 ? currentNotional / totalCurrentPositionSize : 0,
|
|
6988
6989
|
fundingPaid: (_a = asset.fundingPaid) !== null && _a !== void 0 ? _a : 0,
|
|
6989
6990
|
metadata,
|
|
6990
6991
|
};
|
|
@@ -7009,13 +7010,23 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
|
|
|
7009
7010
|
let entryMarginUsed = 0;
|
|
7010
7011
|
const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0) +
|
|
7011
7012
|
position.shortAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0);
|
|
7013
|
+
const totalCurrentPositionSize = position.longAssets.reduce((acc, asset) => {
|
|
7014
|
+
var _a, _b;
|
|
7015
|
+
const currentPrice = (_b = (_a = getAssetByName(asset.coin)) === null || _a === void 0 ? void 0 : _a.currentPrice) !== null && _b !== void 0 ? _b : 0;
|
|
7016
|
+
return acc + currentPrice * asset.size;
|
|
7017
|
+
}, 0) +
|
|
7018
|
+
position.shortAssets.reduce((acc, asset) => {
|
|
7019
|
+
var _a, _b;
|
|
7020
|
+
const currentPrice = (_b = (_a = getAssetByName(asset.coin)) === null || _a === void 0 ? void 0 : _a.currentPrice) !== null && _b !== void 0 ? _b : 0;
|
|
7021
|
+
return acc + currentPrice * asset.size;
|
|
7022
|
+
}, 0);
|
|
7012
7023
|
mappedPosition.longAssets = position.longAssets.map((longAsset) => {
|
|
7013
7024
|
var _a, _b, _c, _d;
|
|
7014
7025
|
const metadata = getAssetByName(longAsset.coin);
|
|
7015
7026
|
const currentPrice = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.currentPrice) !== null && _a !== void 0 ? _a : 0;
|
|
7016
7027
|
const assetState = (_b = clearinghouseState.assetPositions.find((ap) => ap.position.coin === longAsset.coin)) === null || _b === void 0 ? void 0 : _b.position;
|
|
7017
7028
|
const leverage = (_d = (_c = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : longAsset.leverage;
|
|
7018
|
-
const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, leverage, metadata, true);
|
|
7029
|
+
const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, totalCurrentPositionSize, leverage, metadata, true);
|
|
7019
7030
|
mappedPosition.entryPositionValue +=
|
|
7020
7031
|
mappedPositionAssets.entryPositionValue;
|
|
7021
7032
|
mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
|
|
@@ -7023,7 +7034,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
|
|
|
7023
7034
|
mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
|
|
7024
7035
|
entryMarginUsed += mappedPositionAssets.entryMarginUsed;
|
|
7025
7036
|
mappedPosition.entryRatio *= Math.pow(longAsset.entryPrice, mappedPositionAssets.initialWeight);
|
|
7026
|
-
mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.
|
|
7037
|
+
mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.currentWeight);
|
|
7027
7038
|
return mappedPositionAssets;
|
|
7028
7039
|
});
|
|
7029
7040
|
mappedPosition.shortAssets = position.shortAssets.map((shortAsset) => {
|
|
@@ -7032,7 +7043,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
|
|
|
7032
7043
|
const currentPrice = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.currentPrice) !== null && _a !== void 0 ? _a : 0;
|
|
7033
7044
|
const assetState = (_b = clearinghouseState.assetPositions.find((ap) => ap.position.coin === shortAsset.coin)) === null || _b === void 0 ? void 0 : _b.position;
|
|
7034
7045
|
const leverage = (_d = (_c = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : shortAsset.leverage;
|
|
7035
|
-
const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, leverage, metadata, false);
|
|
7046
|
+
const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, totalCurrentPositionSize, leverage, metadata, false);
|
|
7036
7047
|
mappedPosition.entryPositionValue +=
|
|
7037
7048
|
mappedPositionAssets.entryPositionValue;
|
|
7038
7049
|
mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
|
|
@@ -7040,7 +7051,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
|
|
|
7040
7051
|
mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
|
|
7041
7052
|
entryMarginUsed += mappedPositionAssets.entryMarginUsed;
|
|
7042
7053
|
mappedPosition.entryRatio *= Math.pow(shortAsset.entryPrice, -mappedPositionAssets.initialWeight);
|
|
7043
|
-
mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.
|
|
7054
|
+
mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.currentWeight);
|
|
7044
7055
|
return mappedPositionAssets;
|
|
7045
7056
|
});
|
|
7046
7057
|
mappedPosition.positionValue =
|
package/dist/types.d.ts
CHANGED