@orderly.network/ui-positions 2.11.0 → 3.0.0-beta.1

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.mjs CHANGED
@@ -1633,7 +1633,17 @@ var usePositionMargin = (symbol, isAdd, isolatedMargin, finalMargin) => {
1633
1633
  if (!currentPosition) return null;
1634
1634
  return new Decimal(currentPosition.notional);
1635
1635
  }, [currentPosition]);
1636
- const unSettledPnl = currentPosition?.unsettled_pnl;
1636
+ const unSettledPnl = useMemo(() => {
1637
+ if (!currentPosition || !notional || !fundingRates) return null;
1638
+ const fundingRate = fundingRates[currentPosition.symbol];
1639
+ return notional.sub(new Decimal(currentPosition.cost_position)).sub(
1640
+ new Decimal(currentPosition.position_qty).mul(
1641
+ new Decimal(fundingRate.sum_unitary_funding ?? 0).sub(
1642
+ new Decimal(currentPosition.last_sum_unitary_funding)
1643
+ )
1644
+ )
1645
+ );
1646
+ }, [notional, currentPosition, fundingRates]);
1637
1647
  const imr = useMemo(() => {
1638
1648
  if (!currentPosition || !symbolsInfo?.[symbol] || !notional) {
1639
1649
  return null;
@@ -1661,12 +1671,12 @@ var usePositionMargin = (symbol, isAdd, isolatedMargin, finalMargin) => {
1661
1671
  }
1662
1672
  const positionNotional = notional;
1663
1673
  const imrValue = imr;
1664
- const unsettledPnlValue = unSettledPnl ?? 0;
1674
+ const unsettledPnlValue = unSettledPnl ?? new Decimal(0);
1665
1675
  return account.maxReduce({
1666
1676
  isolatedPositionMargin: isolatedMargin,
1667
1677
  positionNotional: positionNotional.toNumber(),
1668
1678
  imr: imrValue.toNumber(),
1669
- positionUnsettledPnL: unsettledPnlValue
1679
+ positionUnsettledPnL: unsettledPnlValue.toNumber()
1670
1680
  });
1671
1681
  }, [
1672
1682
  total_cross_unsettled_pnl,
@@ -1683,14 +1693,14 @@ var usePositionMargin = (symbol, isAdd, isolatedMargin, finalMargin) => {
1683
1693
  const currentSymbolInfo = symbolsInfo[symbol];
1684
1694
  const currentPositionNotional = notional?.toNumber() ?? 0;
1685
1695
  const currentPositionIMRFactor = accountInfo.imr_factor[symbol] ?? currentSymbolInfo.imr_factor ?? 0;
1686
- positions.MMR({
1696
+ const currentPositionMMR = positions.MMR({
1687
1697
  baseMMR: currentSymbolInfo.base_mmr ?? 0,
1688
1698
  baseIMR: currentSymbolInfo.base_imr ?? 0,
1689
1699
  IMRFactor: currentPositionIMRFactor,
1690
1700
  positionNotional: currentPositionNotional,
1691
1701
  IMR_factor_power: 4 / 5
1692
1702
  });
1693
- positions2?.filter((item) => item.symbol !== symbol).map((item) => {
1703
+ const otherPositions = positions2?.filter((item) => item.symbol !== symbol).map((item) => {
1694
1704
  const itemSymbolInfo = symbolsInfo[item.symbol];
1695
1705
  const itemIMRFactor = accountInfo.imr_factor[item.symbol] ?? itemSymbolInfo?.imr_factor ?? 0;
1696
1706
  const itemNotional = item.notional ?? new Decimal(item.position_qty).mul(item.mark_price).abs().toNumber();
@@ -1708,19 +1718,18 @@ var usePositionMargin = (symbol, isAdd, isolatedMargin, finalMargin) => {
1708
1718
  mmr: itemMMR
1709
1719
  };
1710
1720
  }) ?? [];
1711
- new Decimal(finalMargin).add(currentPosition.unsettled_pnl ?? 0).toNumber();
1712
- const sumUnitaryFunding = fundingRates?.[symbol]?.sum_unitary_funding ?? 0;
1713
- const liqPrice = positions.liquidationPriceIsolated({
1714
- isolatedPositionMargin: finalMargin,
1715
- costPosition: currentPosition.cost_position ?? 0,
1716
- positionQty: currentPosition.position_qty ?? 0,
1717
- sumUnitaryFunding,
1718
- lastSumUnitaryFunding: currentPosition.last_sum_unitary_funding ?? 0,
1721
+ const totalCollateral = new Decimal(finalMargin).add(currentPosition.unsettled_pnl ?? 0).toNumber();
1722
+ const liqPrice = positions.liqPrice({
1723
+ markPrice,
1724
+ symbol,
1725
+ totalCollateral,
1726
+ positionQty: currentPosition.position_qty,
1727
+ positions: otherPositions,
1728
+ MMR: currentPositionMMR,
1719
1729
  baseMMR: currentSymbolInfo.base_mmr ?? 0,
1720
1730
  baseIMR: currentSymbolInfo.base_imr ?? 0,
1721
1731
  IMRFactor: currentPositionIMRFactor,
1722
- referencePrice: markPrice,
1723
- leverage: currentPosition.leverage ?? 0
1732
+ costPosition: currentPosition.cost_position ?? 0
1724
1733
  });
1725
1734
  return liqPrice;
1726
1735
  }, [
@@ -1866,7 +1875,7 @@ var useAdjustMarginScript = (props) => {
1866
1875
  sliderValue,
1867
1876
  maxAmount: maxAmount ?? 0,
1868
1877
  currentMargin,
1869
- liquidationPrice,
1878
+ liquidationPrice: liquidationPrice ?? 0,
1870
1879
  effectiveLeverage: effectiveLeverage ?? 0,
1871
1880
  isLoading,
1872
1881
  isAdd,