@pear-protocol/hyperliquid-sdk 0.0.69 → 0.0.70

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 +29 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6640,7 +6640,9 @@ const calculatePositionAsset = (asset, currentPrice, totalInitialPositionSize, l
6640
6640
  positionValue: currentNotional,
6641
6641
  unrealizedPnl: unrealizedPnl,
6642
6642
  entryPositionValue: entryNotional,
6643
- initialWeight: totalInitialPositionSize > 0 ? entryNotional / totalInitialPositionSize : 0,
6643
+ initialWeight: totalInitialPositionSize > 0
6644
+ ? entryNotional / totalInitialPositionSize
6645
+ : 0,
6644
6646
  fundingPaid: (_a = asset.fundingPaid) !== null && _a !== void 0 ? _a : 0,
6645
6647
  };
6646
6648
  };
@@ -6660,15 +6662,16 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6660
6662
  takeProfit: position.takeProfit,
6661
6663
  stopLoss: position.stopLoss,
6662
6664
  };
6663
- const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0) +
6664
- position.shortAssets.reduce((acc, asset) => acc + (asset.entryPrice * asset.size), 0);
6665
- mappedPosition.longAssets = position.longAssets.map(longAsset => {
6665
+ const totalInitialPositionSize = position.longAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0) +
6666
+ position.shortAssets.reduce((acc, asset) => acc + asset.entryPrice * asset.size, 0);
6667
+ mappedPosition.longAssets = position.longAssets.map((longAsset) => {
6666
6668
  var _a, _b, _c;
6667
6669
  const currentPrice = parseFloat(allMids.mids[longAsset.coin]);
6668
- const assetState = (_a = clearinghouseState.assetPositions.find(ap => toDisplaySymbol(ap.position.coin) === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6670
+ const assetState = (_a = clearinghouseState.assetPositions.find((ap) => toDisplaySymbol(ap.position.coin) === longAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6669
6671
  const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : longAsset.leverage;
6670
6672
  const mappedPositionAssets = calculatePositionAsset(longAsset, currentPrice, totalInitialPositionSize, leverage, true);
6671
- mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
6673
+ mappedPosition.entryPositionValue +=
6674
+ mappedPositionAssets.entryPositionValue;
6672
6675
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6673
6676
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6674
6677
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
@@ -6676,13 +6679,14 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6676
6679
  mappedPosition.markRatio *= Math.pow(currentPrice, mappedPositionAssets.initialWeight);
6677
6680
  return mappedPositionAssets;
6678
6681
  });
6679
- mappedPosition.shortAssets = position.shortAssets.map(shortAsset => {
6682
+ mappedPosition.shortAssets = position.shortAssets.map((shortAsset) => {
6680
6683
  var _a, _b, _c;
6681
6684
  const currentPrice = parseFloat(allMids.mids[shortAsset.coin]);
6682
- const assetState = (_a = clearinghouseState.assetPositions.find(ap => toDisplaySymbol(ap.position.coin) === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6685
+ const assetState = (_a = clearinghouseState.assetPositions.find((ap) => toDisplaySymbol(ap.position.coin) === shortAsset.coin)) === null || _a === void 0 ? void 0 : _a.position;
6683
6686
  const leverage = (_c = (_b = assetState === null || assetState === void 0 ? void 0 : assetState.leverage) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : shortAsset.leverage;
6684
6687
  const mappedPositionAssets = calculatePositionAsset(shortAsset, currentPrice, totalInitialPositionSize, leverage, false);
6685
- mappedPosition.entryPositionValue += mappedPositionAssets.entryPositionValue;
6688
+ mappedPosition.entryPositionValue +=
6689
+ mappedPositionAssets.entryPositionValue;
6686
6690
  mappedPosition.unrealizedPnl += mappedPositionAssets.unrealizedPnl;
6687
6691
  mappedPosition.positionValue += mappedPositionAssets.positionValue;
6688
6692
  mappedPosition.marginUsed += mappedPositionAssets.marginUsed;
@@ -6690,7 +6694,8 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6690
6694
  mappedPosition.markRatio *= Math.pow(currentPrice, -mappedPositionAssets.initialWeight);
6691
6695
  return mappedPositionAssets;
6692
6696
  });
6693
- mappedPosition.positionValue = mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
6697
+ mappedPosition.positionValue =
6698
+ mappedPosition.entryPositionValue + mappedPosition.unrealizedPnl;
6694
6699
  if (position.longAssets.length === 1 && position.shortAssets.length === 1) {
6695
6700
  const long = position.longAssets[0];
6696
6701
  const short = position.shortAssets[0];
@@ -6699,7 +6704,20 @@ const buildPositionValue = (rawPositions, clearinghouseState, allMids) => {
6699
6704
  mappedPosition.entryPriceRatio = long.entryPrice / short.entryPrice;
6700
6705
  mappedPosition.markPriceRatio = longMark / shortMark;
6701
6706
  }
6702
- mappedPosition.unrealizedPnlPercentage = mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
6707
+ if (position.longAssets.length === 1 && position.shortAssets.length === 0) {
6708
+ const long = position.longAssets[0];
6709
+ const longMark = parseFloat(allMids.mids[long.coin]);
6710
+ mappedPosition.entryPriceRatio = long.entryPrice;
6711
+ mappedPosition.markPriceRatio = longMark;
6712
+ }
6713
+ if (position.longAssets.length === 0 && position.shortAssets.length === 1) {
6714
+ const short = position.shortAssets[0];
6715
+ const shortMark = parseFloat(allMids.mids[short.coin]);
6716
+ mappedPosition.entryPriceRatio = short.entryPrice;
6717
+ mappedPosition.markPriceRatio = shortMark;
6718
+ }
6719
+ mappedPosition.unrealizedPnlPercentage =
6720
+ mappedPosition.unrealizedPnl / mappedPosition.marginUsed;
6703
6721
  return mappedPosition;
6704
6722
  });
6705
6723
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.69",
3
+ "version": "0.0.70",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",