@pear-protocol/hyperliquid-sdk 0.1.10 → 0.1.11

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.
Files changed (2) hide show
  1. package/dist/index.js +8 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6910,7 +6910,9 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6910
6910
  var _a;
6911
6911
  const entryNotional = asset.entryPrice * asset.size;
6912
6912
  const currentNotional = currentPrice * asset.size;
6913
- const marginUsed = currentNotional / (leverage || 1);
6913
+ const effectiveLeverage = leverage || 1;
6914
+ const marginUsed = currentNotional / effectiveLeverage;
6915
+ const entryMarginUsed = entryNotional / effectiveLeverage;
6914
6916
  const unrealizedPnl = isLong
6915
6917
  ? currentNotional - entryNotional
6916
6918
  : entryNotional - currentNotional;
@@ -6920,6 +6922,7 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6920
6922
  actualSize: asset.size,
6921
6923
  leverage: leverage,
6922
6924
  marginUsed: marginUsed,
6925
+ entryMarginUsed: entryMarginUsed,
6923
6926
  positionValue: currentNotional,
6924
6927
  unrealizedPnl: unrealizedPnl,
6925
6928
  entryPositionValue: entryNotional,
@@ -6945,6 +6948,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
6945
6948
  takeProfit: position.takeProfit,
6946
6949
  stopLoss: position.stopLoss,
6947
6950
  };
6951
+ let entryMarginUsed = 0;
6948
6952
  const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0) +
6949
6953
  position.shortAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0);
6950
6954
  mappedPosition.longAssets = position.longAssets.map((longAsset) => {
@@ -6959,6 +6963,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
6959
6963
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6960
6964
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6961
6965
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
6966
+ entryMarginUsed += mappedPositionAssets.entryMarginUsed;
6962
6967
  mappedPosition.entryRatio *= Math.pow(longAsset.entryPrice, mappedPositionAssets.initialWeight);
6963
6968
  mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.initialWeight);
6964
6969
  return mappedPositionAssets;
@@ -6975,6 +6980,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
6975
6980
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6976
6981
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6977
6982
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
6983
+ entryMarginUsed += mappedPositionAssets.entryMarginUsed;
6978
6984
  mappedPosition.entryRatio *= Math.pow(shortAsset.entryPrice, -mappedPositionAssets.initialWeight);
6979
6985
  mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.initialWeight);
6980
6986
  return mappedPositionAssets;
@@ -7012,7 +7018,7 @@ const buildPositionValue = (rawPositions, clearinghouseState, getAssetByName) =>
7012
7018
  mappedPosition.markPriceRatio = shortMark;
7013
7019
  }
7014
7020
  mappedPosition.unrealizedPnlPercentage =
7015
- mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
7021
+ entryMarginUsed > 0 ? mappedPosition.unrealizedPnl / entryMarginUsed : 0;
7016
7022
  return mappedPosition;
7017
7023
  });
7018
7024
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",