@orderly.network/hooks 2.11.2-alpha.0 → 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.d.mts CHANGED
@@ -37,7 +37,7 @@ declare global {
37
37
  };
38
38
  }
39
39
  }
40
- declare const _default: "2.11.2-alpha.0";
40
+ declare const _default: "2.11.3-rc.0";
41
41
 
42
42
  declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
43
43
  type useQueryOptions<T> = SWRConfiguration & {
@@ -1194,7 +1194,7 @@ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration &
1194
1194
  readonly totalCollateral: _orderly_network_utils.Decimal;
1195
1195
  readonly totalValue: _orderly_network_utils.Decimal | null;
1196
1196
  readonly totalUnrealizedROI: number;
1197
- }, Record<"unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index", <Key extends "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index">(defaultValue?: Omit<API.PositionInfo, "rows">[Key] | undefined) => Omit<API.PositionInfo, "rows">[Key]> & {
1197
+ }, Record<"unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | "total_unsettled_cross_pnl" | "total_unsettled_isolated_pnl", <Key extends "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | "total_unsettled_cross_pnl" | "total_unsettled_isolated_pnl">(defaultValue?: Omit<API.PositionInfo, "rows">[Key] | undefined) => Omit<API.PositionInfo, "rows">[Key]> & {
1198
1198
  isNil: boolean;
1199
1199
  }, {
1200
1200
  /**
package/dist/index.d.ts CHANGED
@@ -37,7 +37,7 @@ declare global {
37
37
  };
38
38
  }
39
39
  }
40
- declare const _default: "2.11.2-alpha.0";
40
+ declare const _default: "2.11.3-rc.0";
41
41
 
42
42
  declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
43
43
  type useQueryOptions<T> = SWRConfiguration & {
@@ -1194,7 +1194,7 @@ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration &
1194
1194
  readonly totalCollateral: _orderly_network_utils.Decimal;
1195
1195
  readonly totalValue: _orderly_network_utils.Decimal | null;
1196
1196
  readonly totalUnrealizedROI: number;
1197
- }, Record<"unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index", <Key extends "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index">(defaultValue?: Omit<API.PositionInfo, "rows">[Key] | undefined) => Omit<API.PositionInfo, "rows">[Key]> & {
1197
+ }, Record<"unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | "total_unsettled_cross_pnl" | "total_unsettled_isolated_pnl", <Key extends "unsettledPnL" | "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | "unrealPnL" | "total_unreal_pnl" | "total_unreal_pnl_index" | "total_unsettled_pnl" | "notional" | "unrealPnlROI" | "unrealPnlROI_index" | "total_unsettled_cross_pnl" | "total_unsettled_isolated_pnl">(defaultValue?: Omit<API.PositionInfo, "rows">[Key] | undefined) => Omit<API.PositionInfo, "rows">[Key]> & {
1198
1198
  isNil: boolean;
1199
1199
  }, {
1200
1200
  /**
package/dist/index.js CHANGED
@@ -64,9 +64,9 @@ var __export = (target, all) => {
64
64
  // src/version.ts
65
65
  if (typeof window !== "undefined") {
66
66
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
67
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.2-alpha.0";
67
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.3-rc.0";
68
68
  }
69
- var version_default = "2.11.2-alpha.0";
69
+ var version_default = "2.11.3-rc.0";
70
70
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
71
71
  var noCacheConfig = {
72
72
  dedupingInterval: 0,
@@ -5453,7 +5453,7 @@ var PositionCalculator = class extends BaseCalculator {
5453
5453
  if (!accountInfo || !fundingRates || !symbolsInfo) {
5454
5454
  return data;
5455
5455
  }
5456
- let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
5456
+ let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
5457
5457
  let rows = data.rows.map((item) => {
5458
5458
  const info = symbolsInfo[item.symbol];
5459
5459
  const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
@@ -5516,6 +5516,12 @@ var PositionCalculator = class extends BaseCalculator {
5516
5516
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
5517
5517
  notional_total = notional_total.add(notional);
5518
5518
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
5519
+ if (item.margin_mode === types.MarginMode.CROSS) {
5520
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
5521
+ }
5522
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
5523
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
5524
+ }
5519
5525
  const fundingFee = new utils.Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
5520
5526
  return {
5521
5527
  ...item,
@@ -5531,7 +5537,8 @@ var PositionCalculator = class extends BaseCalculator {
5531
5537
  unrealized_pnl: unrealPnl,
5532
5538
  unrealized_pnl_index: unrealPnl_index,
5533
5539
  unrealized_pnl_ROI: unrealPnlROI,
5534
- unrealized_pnl_ROI_index: unrealPnlROI_index
5540
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
5541
+ unsettled_pnl: unsettlementPnL2
5535
5542
  };
5536
5543
  });
5537
5544
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -5597,6 +5604,8 @@ var PositionCalculator = class extends BaseCalculator {
5597
5604
  total_unsettled_pnl: unsettlementPnL,
5598
5605
  unrealPnlROI: totalUnrealizedROI,
5599
5606
  unrealPnlROI_index: totalUnrealizedROI_index,
5607
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
5608
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
5600
5609
  rows
5601
5610
  };
5602
5611
  }
@@ -5759,13 +5768,9 @@ var PortfolioCalculator = class extends BaseCalculator {
5759
5768
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
5760
5769
  return null;
5761
5770
  }
5762
- const totallCrossUnsettledPnL = positions3.rows.reduce(
5763
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
5764
- 0
5765
- );
5766
- const totalUnsettlementPnL = positions3.rows.reduce(
5767
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
5768
- 0
5771
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
5772
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(
5773
+ positions3
5769
5774
  );
5770
5775
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
5771
5776
  const [USDC_holding, nonUSDC] = parseHolding(
@@ -5777,7 +5782,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5777
5782
  const totalCollateral = perp.account.totalCollateral({
5778
5783
  USDCHolding: USDC_holding,
5779
5784
  nonUSDCHolding: nonUSDC,
5780
- unsettlementPnL: totallCrossUnsettledPnL,
5785
+ unsettlementPnL: unsettledCrossPnL,
5781
5786
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
5782
5787
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
5783
5788
  });
@@ -5788,7 +5793,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5788
5793
  return acc.add(curr.margin ?? 0);
5789
5794
  }, utils.zero);
5790
5795
  const totalValue = perp.account.totalValue({
5791
- totalUnsettlementPnL,
5796
+ totalUnsettlementPnL: unsettledPnL,
5792
5797
  USDCHolding: USDC_holding,
5793
5798
  nonUSDCHolding: nonUSDC,
5794
5799
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -5832,7 +5837,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5832
5837
  totalUnrealizedROI,
5833
5838
  freeCollateral,
5834
5839
  availableBalance,
5835
- unsettledPnL: totalUnsettlementPnL,
5840
+ unsettledPnL,
5836
5841
  holding,
5837
5842
  usdcHolding: USDC_holding,
5838
5843
  freeCollateralUSDCOnly
@@ -5951,7 +5956,7 @@ var usePositionStream = (symbol = "all", options) => {
5951
5956
  total_unreal_pnl: total_unreal_pnl_index,
5952
5957
  unrealPnlROI: unrealPnlROI_index
5953
5958
  };
5954
- }, [calcMode]);
5959
+ }, [calcMode, formattedPositions]);
5955
5960
  let rows = formattedPositions[0];
5956
5961
  {
5957
5962
  if (!rows) {
@@ -6441,14 +6446,8 @@ function formatPortfolio(inputs) {
6441
6446
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
6442
6447
  return null;
6443
6448
  }
6444
- const totallCrossUnsettledPnL = positions3.rows.reduce(
6445
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
6446
- 0
6447
- );
6448
- const totalUnsettlementPnL = positions3.rows.reduce(
6449
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
6450
- 0
6451
- );
6449
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
6450
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
6452
6451
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
6453
6452
  const [USDC_holding, nonUSDC] = parseHolding(
6454
6453
  holding,
@@ -6459,7 +6458,7 @@ function formatPortfolio(inputs) {
6459
6458
  const totalCollateral = perp.account.totalCollateral({
6460
6459
  USDCHolding: USDC_holding,
6461
6460
  nonUSDCHolding: nonUSDC,
6462
- unsettlementPnL: totallCrossUnsettledPnL,
6461
+ unsettlementPnL: unsettledCrossPnL,
6463
6462
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
6464
6463
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
6465
6464
  });
@@ -6470,7 +6469,7 @@ function formatPortfolio(inputs) {
6470
6469
  return acc.add(curr.margin ?? 0);
6471
6470
  }, utils.zero);
6472
6471
  const totalValue = perp.account.totalValue({
6473
- totalUnsettlementPnL,
6472
+ totalUnsettlementPnL: unsettledPnL,
6474
6473
  USDCHolding: USDC_holding,
6475
6474
  nonUSDCHolding: nonUSDC,
6476
6475
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -6514,7 +6513,7 @@ function formatPortfolio(inputs) {
6514
6513
  totalUnrealizedROI,
6515
6514
  freeCollateral,
6516
6515
  availableBalance,
6517
- unsettledPnL: totalUnsettlementPnL,
6516
+ unsettledPnL,
6518
6517
  holding,
6519
6518
  freeCollateralUSDCOnly
6520
6519
  };
@@ -6523,7 +6522,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6523
6522
  if (!accountInfo || !fundingRates || !symbolsInfo) {
6524
6523
  return data;
6525
6524
  }
6526
- let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
6525
+ let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
6527
6526
  const rows = data.rows.map((item) => {
6528
6527
  const info = symbolsInfo[item.symbol];
6529
6528
  const notional = perp.positions.notional(item.position_qty, item.mark_price);
@@ -6585,6 +6584,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6585
6584
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
6586
6585
  notional_total = notional_total.add(notional);
6587
6586
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
6587
+ if (item.margin_mode === types.MarginMode.CROSS) {
6588
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
6589
+ }
6590
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
6591
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
6592
+ }
6588
6593
  return {
6589
6594
  ...item,
6590
6595
  mm: perp.positions.maintenanceMargin({
@@ -6598,7 +6603,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6598
6603
  unrealized_pnl: unrealPnl,
6599
6604
  unrealized_pnl_index: unrealPnl_index,
6600
6605
  unrealized_pnl_ROI: unrealPnlROI,
6601
- unrealized_pnl_ROI_index: unrealPnlROI_index
6606
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
6607
+ unsettled_pnl: unsettlementPnL2
6602
6608
  };
6603
6609
  });
6604
6610
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -6612,6 +6618,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6612
6618
  notional: notional_total.toNumber(),
6613
6619
  unsettledPnL: unsettlementPnL,
6614
6620
  total_unsettled_pnl: unsettlementPnL,
6621
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
6622
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
6615
6623
  rows
6616
6624
  };
6617
6625
  }