@orderly.network/hooks 2.11.2 → 2.11.3-rc.0

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
@@ -38,9 +38,9 @@ var __export = (target, all) => {
38
38
  // src/version.ts
39
39
  if (typeof window !== "undefined") {
40
40
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
41
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.2";
41
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.3-rc.0";
42
42
  }
43
- var version_default = "2.11.2";
43
+ var version_default = "2.11.3-rc.0";
44
44
  var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
45
45
  var noCacheConfig = {
46
46
  dedupingInterval: 0,
@@ -5427,7 +5427,7 @@ var PositionCalculator = class extends BaseCalculator {
5427
5427
  if (!accountInfo || !fundingRates || !symbolsInfo) {
5428
5428
  return data;
5429
5429
  }
5430
- let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero;
5430
+ let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero, totalUnsettledIsolatedPnl = zero, totalUnsettledCrossPnl = zero;
5431
5431
  let rows = data.rows.map((item) => {
5432
5432
  const info = symbolsInfo[item.symbol];
5433
5433
  const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
@@ -5490,6 +5490,12 @@ var PositionCalculator = class extends BaseCalculator {
5490
5490
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
5491
5491
  notional_total = notional_total.add(notional);
5492
5492
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
5493
+ if (item.margin_mode === MarginMode.CROSS) {
5494
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
5495
+ }
5496
+ if (item.margin_mode === MarginMode.ISOLATED) {
5497
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
5498
+ }
5493
5499
  const fundingFee = new Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
5494
5500
  return {
5495
5501
  ...item,
@@ -5505,7 +5511,8 @@ var PositionCalculator = class extends BaseCalculator {
5505
5511
  unrealized_pnl: unrealPnl,
5506
5512
  unrealized_pnl_index: unrealPnl_index,
5507
5513
  unrealized_pnl_ROI: unrealPnlROI,
5508
- unrealized_pnl_ROI_index: unrealPnlROI_index
5514
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
5515
+ unsettled_pnl: unsettlementPnL2
5509
5516
  };
5510
5517
  });
5511
5518
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -5571,6 +5578,8 @@ var PositionCalculator = class extends BaseCalculator {
5571
5578
  total_unsettled_pnl: unsettlementPnL,
5572
5579
  unrealPnlROI: totalUnrealizedROI,
5573
5580
  unrealPnlROI_index: totalUnrealizedROI_index,
5581
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
5582
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
5574
5583
  rows
5575
5584
  };
5576
5585
  }
@@ -5733,13 +5742,9 @@ var PortfolioCalculator = class extends BaseCalculator {
5733
5742
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
5734
5743
  return null;
5735
5744
  }
5736
- const totallCrossUnsettledPnL = positions3.rows.reduce(
5737
- (sum, pos) => pos.margin_mode === MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
5738
- 0
5739
- );
5740
- const totalUnsettlementPnL = positions3.rows.reduce(
5741
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
5742
- 0
5745
+ const unsettledPnL = pathOr(0, ["total_unsettled_pnl"])(positions3);
5746
+ const unsettledCrossPnL = pathOr(0, ["total_unsettled_cross_pnl"])(
5747
+ positions3
5743
5748
  );
5744
5749
  const unrealizedPnL = pathOr(0, ["total_unreal_pnl"])(positions3);
5745
5750
  const [USDC_holding, nonUSDC] = parseHolding(
@@ -5751,7 +5756,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5751
5756
  const totalCollateral = account.totalCollateral({
5752
5757
  USDCHolding: USDC_holding,
5753
5758
  nonUSDCHolding: nonUSDC,
5754
- unsettlementPnL: totallCrossUnsettledPnL,
5759
+ unsettlementPnL: unsettledCrossPnL,
5755
5760
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
5756
5761
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
5757
5762
  });
@@ -5762,7 +5767,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5762
5767
  return acc.add(curr.margin ?? 0);
5763
5768
  }, zero);
5764
5769
  const totalValue = account.totalValue({
5765
- totalUnsettlementPnL,
5770
+ totalUnsettlementPnL: unsettledPnL,
5766
5771
  USDCHolding: USDC_holding,
5767
5772
  nonUSDCHolding: nonUSDC,
5768
5773
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -5806,7 +5811,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5806
5811
  totalUnrealizedROI,
5807
5812
  freeCollateral,
5808
5813
  availableBalance,
5809
- unsettledPnL: totalUnsettlementPnL,
5814
+ unsettledPnL,
5810
5815
  holding,
5811
5816
  usdcHolding: USDC_holding,
5812
5817
  freeCollateralUSDCOnly
@@ -5925,7 +5930,7 @@ var usePositionStream = (symbol = "all", options) => {
5925
5930
  total_unreal_pnl: total_unreal_pnl_index,
5926
5931
  unrealPnlROI: unrealPnlROI_index
5927
5932
  };
5928
- }, [calcMode]);
5933
+ }, [calcMode, formattedPositions]);
5929
5934
  let rows = formattedPositions[0];
5930
5935
  {
5931
5936
  if (!rows) {
@@ -6415,14 +6420,8 @@ function formatPortfolio(inputs) {
6415
6420
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
6416
6421
  return null;
6417
6422
  }
6418
- const totallCrossUnsettledPnL = positions3.rows.reduce(
6419
- (sum, pos) => pos.margin_mode === MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
6420
- 0
6421
- );
6422
- const totalUnsettlementPnL = positions3.rows.reduce(
6423
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
6424
- 0
6425
- );
6423
+ const unsettledPnL = pathOr(0, ["total_unsettled_pnl"])(positions3);
6424
+ const unsettledCrossPnL = pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
6426
6425
  const unrealizedPnL = pathOr(0, ["total_unreal_pnl"])(positions3);
6427
6426
  const [USDC_holding, nonUSDC] = parseHolding(
6428
6427
  holding,
@@ -6433,7 +6432,7 @@ function formatPortfolio(inputs) {
6433
6432
  const totalCollateral = account.totalCollateral({
6434
6433
  USDCHolding: USDC_holding,
6435
6434
  nonUSDCHolding: nonUSDC,
6436
- unsettlementPnL: totallCrossUnsettledPnL,
6435
+ unsettlementPnL: unsettledCrossPnL,
6437
6436
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
6438
6437
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
6439
6438
  });
@@ -6444,7 +6443,7 @@ function formatPortfolio(inputs) {
6444
6443
  return acc.add(curr.margin ?? 0);
6445
6444
  }, zero);
6446
6445
  const totalValue = account.totalValue({
6447
- totalUnsettlementPnL,
6446
+ totalUnsettlementPnL: unsettledPnL,
6448
6447
  USDCHolding: USDC_holding,
6449
6448
  nonUSDCHolding: nonUSDC,
6450
6449
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -6488,7 +6487,7 @@ function formatPortfolio(inputs) {
6488
6487
  totalUnrealizedROI,
6489
6488
  freeCollateral,
6490
6489
  availableBalance,
6491
- unsettledPnL: totalUnsettlementPnL,
6490
+ unsettledPnL,
6492
6491
  holding,
6493
6492
  freeCollateralUSDCOnly
6494
6493
  };
@@ -6497,7 +6496,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6497
6496
  if (!accountInfo || !fundingRates || !symbolsInfo) {
6498
6497
  return data;
6499
6498
  }
6500
- let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero;
6499
+ let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero, totalUnsettledIsolatedPnl = zero, totalUnsettledCrossPnl = zero;
6501
6500
  const rows = data.rows.map((item) => {
6502
6501
  const info = symbolsInfo[item.symbol];
6503
6502
  const notional = positions.notional(item.position_qty, item.mark_price);
@@ -6559,6 +6558,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6559
6558
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
6560
6559
  notional_total = notional_total.add(notional);
6561
6560
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
6561
+ if (item.margin_mode === MarginMode.CROSS) {
6562
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
6563
+ }
6564
+ if (item.margin_mode === MarginMode.ISOLATED) {
6565
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
6566
+ }
6562
6567
  return {
6563
6568
  ...item,
6564
6569
  mm: positions.maintenanceMargin({
@@ -6572,7 +6577,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6572
6577
  unrealized_pnl: unrealPnl,
6573
6578
  unrealized_pnl_index: unrealPnl_index,
6574
6579
  unrealized_pnl_ROI: unrealPnlROI,
6575
- unrealized_pnl_ROI_index: unrealPnlROI_index
6580
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
6581
+ unsettled_pnl: unsettlementPnL2
6576
6582
  };
6577
6583
  });
6578
6584
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -6586,6 +6592,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6586
6592
  notional: notional_total.toNumber(),
6587
6593
  unsettledPnL: unsettlementPnL,
6588
6594
  total_unsettled_pnl: unsettlementPnL,
6595
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
6596
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
6589
6597
  rows
6590
6598
  };
6591
6599
  }