@orderly.network/hooks 3.0.0-beta.1 → 3.0.0-beta.3

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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var net = require('@orderly.network/net');
4
3
  var React = require('react');
4
+ var net = require('@orderly.network/net');
5
5
  var useSWR5 = require('swr');
6
6
  var pluginCore = require('@orderly.network/plugin-core');
7
7
  var types = require('@orderly.network/types');
@@ -61,13 +61,24 @@ var __export = (target, all) => {
61
61
  for (var name in all)
62
62
  __defProp(target, name, { get: all[name], enumerable: true });
63
63
  };
64
+ var MarketCategoriesConfigContext = React.createContext(void 0);
65
+ var MarketCategoriesConfigProvider = ({ value, children }) => {
66
+ return React.createElement(
67
+ MarketCategoriesConfigContext.Provider,
68
+ { value },
69
+ children
70
+ );
71
+ };
72
+ function useMarketCategoriesConfig() {
73
+ return React.useContext(MarketCategoriesConfigContext);
74
+ }
64
75
 
65
76
  // src/version.ts
66
77
  if (typeof window !== "undefined") {
67
78
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
68
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.1";
79
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.3";
69
80
  }
70
- var version_default = "3.0.0-beta.1";
81
+ var version_default = "3.0.0-beta.3";
71
82
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
72
83
  var noCacheConfig = {
73
84
  dedupingInterval: 0,
@@ -2610,16 +2621,12 @@ var createDataStore = (config) => {
2610
2621
  const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
2611
2622
  const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
2612
2623
  const data = await fetcher(url, {}, { formatter });
2613
- const dataWithBrokerId = data.map((item) => ({
2614
- ...item,
2615
- broker_id: options?.brokerId
2616
- }));
2617
2624
  set({
2618
- data: dataWithBrokerId,
2625
+ data,
2619
2626
  loading: false,
2620
2627
  error: null
2621
2628
  });
2622
- return dataWithBrokerId;
2629
+ return data;
2623
2630
  } catch (error) {
2624
2631
  set({ error, loading: false });
2625
2632
  return null;
@@ -3438,7 +3445,10 @@ var useGetRwaSymbolOpenTimeInterval = (symbol, thresholdMinutes = 30) => {
3438
3445
  };
3439
3446
  var useSymbolsInfo = () => {
3440
3447
  const symbolsInfo = useAppStore((state) => state.symbolsInfo);
3441
- return React.useMemo(() => createGetter({ ...symbolsInfo }), [symbolsInfo]);
3448
+ return React.useMemo(
3449
+ () => createGetter(symbolsInfo ? { ...symbolsInfo } : symbolsInfo),
3450
+ [symbolsInfo]
3451
+ );
3442
3452
  };
3443
3453
  var useSymbolsInfoStore = () => {
3444
3454
  return useAppStore((state) => state.symbolsInfo);
@@ -3451,6 +3461,7 @@ var MarketsType = /* @__PURE__ */ ((MarketsType2) => {
3451
3461
  MarketsType2[MarketsType2["ALL"] = 2] = "ALL";
3452
3462
  MarketsType2[MarketsType2["RWA"] = 3] = "RWA";
3453
3463
  MarketsType2[MarketsType2["NEW_LISTING"] = 4] = "NEW_LISTING";
3464
+ MarketsType2[MarketsType2["COMMUNITY"] = 5] = "COMMUNITY";
3454
3465
  return MarketsType2;
3455
3466
  })(MarketsType || {});
3456
3467
  var MarketsStorageKey = "orderly_markets";
@@ -3620,6 +3631,8 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3620
3631
  const rwaInfo = !rwaSymbolsInfo.isNil ? rwaSymbolsInfo[item.symbol]() : null;
3621
3632
  return {
3622
3633
  ...item,
3634
+ broker_id: item.broker_id,
3635
+ display_symbol_name: item.display_symbol_name,
3623
3636
  quote_dp: info("quote_dp"),
3624
3637
  created_time: info("created_time"),
3625
3638
  displayName: info("displayName"),
@@ -3641,7 +3654,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3641
3654
  var filterMarkets = (params) => {
3642
3655
  const { markets, favorites, recent, newListing, type } = params;
3643
3656
  let curData = [];
3644
- if (type === 2 /* ALL */) {
3657
+ if (type === 2 /* ALL */ || type === 5 /* COMMUNITY */) {
3645
3658
  curData = markets;
3646
3659
  } else if (type === 3 /* RWA */) {
3647
3660
  curData = markets.filter((item) => item.isRwa);
@@ -4563,7 +4576,7 @@ var useMarket = (type) => {
4563
4576
  const getData = (type2) => {
4564
4577
  const localData = type2 === 0 /* FAVORITES */ ? [...favorites] : [...recent];
4565
4578
  const keys = localData.map((item) => item.name);
4566
- const filter = type2 == 2 /* ALL */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
4579
+ const filter = type2 == 2 /* ALL */ || type2 == 4 /* COMMUNITY */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
4567
4580
  const favoritesData = [...favorites];
4568
4581
  const favoriteKeys = favoritesData.map((item) => item.name);
4569
4582
  if (filter) {
@@ -4762,6 +4775,80 @@ var useSymbolLeverageMap = () => {
4762
4775
  refresh: mutate6
4763
4776
  };
4764
4777
  };
4778
+
4779
+ // src/trading-rewards/useAllBrokers.ts
4780
+ var useAllBrokers = () => {
4781
+ const { data } = useQuery("/v1/public/broker/name", {
4782
+ formatter: (res) => {
4783
+ const { rows } = res;
4784
+ return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
4785
+ },
4786
+ revalidateOnFocus: false
4787
+ });
4788
+ return [data];
4789
+ };
4790
+
4791
+ // src/useBadgeBySymbol.ts
4792
+ function brokerNameBaseFromRaw(rawBrokerName) {
4793
+ if (!rawBrokerName) return void 0;
4794
+ const first = rawBrokerName.trim().split(/[ _-]/, 1)[0]?.trim() ?? "";
4795
+ return first.length > 0 ? first : void 0;
4796
+ }
4797
+ var useBadgeBySymbol = (symbol) => {
4798
+ const symbolsInfo = useSymbolsInfo();
4799
+ const [brokers] = useAllBrokers();
4800
+ return React.useMemo(() => {
4801
+ if (!symbol || symbolsInfo.isNil) {
4802
+ return {
4803
+ displayName: symbol ?? "",
4804
+ brokerId: void 0,
4805
+ brokerName: void 0,
4806
+ brokerNameRaw: void 0
4807
+ };
4808
+ }
4809
+ const getter = symbolsInfo[symbol];
4810
+ const info = typeof getter === "function" ? getter() : void 0;
4811
+ const displayName = info?.displayName ?? info?.display_symbol_name ?? symbol;
4812
+ const brokerId = info?.broker_id ?? void 0;
4813
+ const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
4814
+ const base = brokerNameBaseFromRaw(rawBrokerName);
4815
+ const brokerName = base ? base.length > 7 ? `${base.slice(0, 7)}...` : base : void 0;
4816
+ return {
4817
+ displayName,
4818
+ brokerId,
4819
+ brokerName,
4820
+ brokerNameRaw: rawBrokerName
4821
+ };
4822
+ }, [brokers, symbolsInfo, symbol]);
4823
+ };
4824
+ function formatSymbolWithBroker(symbol, symbolsInfo, brokers) {
4825
+ if (!symbol) return "";
4826
+ let brokerNameBase;
4827
+ if (!symbolsInfo.isNil) {
4828
+ const getter = symbolsInfo[symbol];
4829
+ const info = typeof getter === "function" ? getter() : void 0;
4830
+ const brokerId = info?.broker_id ?? void 0;
4831
+ const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
4832
+ brokerNameBase = brokerNameBaseFromRaw(rawBrokerName);
4833
+ }
4834
+ const parts = symbol.split("_");
4835
+ const base = parts.length >= 3 ? parts[1] ?? "" : symbol.match(/^([A-Za-z]+)/)?.[1] ?? symbol;
4836
+ const hasBrokerSuffix = symbol.includes("-") || symbol.split("_").length > 3;
4837
+ if (brokerNameBase && hasBrokerSuffix) {
4838
+ return `${base}-${brokerNameBase}`;
4839
+ }
4840
+ return base;
4841
+ }
4842
+ var useSymbolWithBroker = (symbol) => {
4843
+ const symbolsInfo = useSymbolsInfo();
4844
+ const [brokers] = useAllBrokers();
4845
+ return React.useMemo(
4846
+ () => formatSymbolWithBroker(symbol, symbolsInfo, brokers),
4847
+ [brokers, symbolsInfo, symbol]
4848
+ );
4849
+ };
4850
+
4851
+ // src/orderly/useMarginModes.ts
4765
4852
  var useMarginModes = () => {
4766
4853
  const { data, error, isLoading, mutate: mutate6 } = usePrivateQuery("/v1/client/margin_modes", {
4767
4854
  revalidateOnFocus: false,
@@ -4803,22 +4890,28 @@ var useMarginModes = () => {
4803
4890
  };
4804
4891
  var useMarginModeBySymbol = (symbol, fallback = types.MarginMode.CROSS) => {
4805
4892
  const { marginModes, isLoading, error, refresh, updateMarginMode } = useMarginModes();
4806
- const marginMode = fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
4893
+ const { brokerId } = useBadgeBySymbol(symbol);
4894
+ const marginMode = React.useMemo(() => {
4895
+ if (brokerId) return types.MarginMode.ISOLATED;
4896
+ return fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
4897
+ }, [brokerId, fallback, marginModes, symbol]);
4807
4898
  const update = React.useCallback(
4808
4899
  async (mode) => {
4900
+ if (brokerId) mode = types.MarginMode.ISOLATED;
4809
4901
  return updateMarginMode({
4810
4902
  symbol_list: [symbol],
4811
4903
  default_margin_mode: mode
4812
4904
  });
4813
4905
  },
4814
- [symbol, updateMarginMode]
4906
+ [brokerId, symbol, updateMarginMode]
4815
4907
  );
4816
4908
  return {
4817
4909
  marginMode,
4818
4910
  isLoading,
4819
4911
  error,
4820
4912
  refresh,
4821
- update
4913
+ update,
4914
+ isPermissionlessListing: !!brokerId
4822
4915
  };
4823
4916
  };
4824
4917
 
@@ -5461,7 +5554,7 @@ var PositionCalculator = class extends BaseCalculator {
5461
5554
  if (!accountInfo || !fundingRates || !symbolsInfo) {
5462
5555
  return data;
5463
5556
  }
5464
- let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
5557
+ let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
5465
5558
  let rows = data.rows.map((item) => {
5466
5559
  const info = symbolsInfo[item.symbol];
5467
5560
  const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
@@ -5524,6 +5617,12 @@ var PositionCalculator = class extends BaseCalculator {
5524
5617
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
5525
5618
  notional_total = notional_total.add(notional);
5526
5619
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
5620
+ if (item.margin_mode === types.MarginMode.CROSS) {
5621
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
5622
+ }
5623
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
5624
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
5625
+ }
5527
5626
  const fundingFee = new utils.Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
5528
5627
  return {
5529
5628
  ...item,
@@ -5539,7 +5638,8 @@ var PositionCalculator = class extends BaseCalculator {
5539
5638
  unrealized_pnl: unrealPnl,
5540
5639
  unrealized_pnl_index: unrealPnl_index,
5541
5640
  unrealized_pnl_ROI: unrealPnlROI,
5542
- unrealized_pnl_ROI_index: unrealPnlROI_index
5641
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
5642
+ unsettled_pnl: unsettlementPnL2
5543
5643
  };
5544
5644
  });
5545
5645
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -5551,18 +5651,34 @@ var PositionCalculator = class extends BaseCalculator {
5551
5651
  rows = rows.map((item) => {
5552
5652
  const info = symbolsInfo[item.symbol];
5553
5653
  const totalCollateral = item.margin_mode === types.MarginMode.ISOLATED ? new utils.Decimal(item.margin ?? 0).add(item.unsettlement_pnl ?? 0).toNumber() : crossMarginCollateral.toNumber();
5554
- const est_liq_price = perp.positions.liqPrice({
5555
- symbol: item.symbol,
5556
- markPrice: item.mark_price,
5557
- totalCollateral,
5558
- positionQty: item.position_qty,
5559
- positions: rows,
5560
- MMR: item.mmr,
5561
- baseMMR: info?.["base_mmr"],
5562
- baseIMR: info?.["base_imr"],
5563
- IMRFactor: accountInfo.imr_factor[item.symbol],
5564
- costPosition: item.cost_position
5565
- });
5654
+ let est_liq_price;
5655
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
5656
+ est_liq_price = perp.positions.liquidationPriceIsolated({
5657
+ isolatedPositionMargin: item.margin ?? 0,
5658
+ costPosition: item.cost_position ?? 0,
5659
+ positionQty: item.position_qty ?? 0,
5660
+ sumUnitaryFunding: fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0,
5661
+ lastSumUnitaryFunding: item.last_sum_unitary_funding ?? 0,
5662
+ baseMMR: info?.["base_mmr"] ?? 0,
5663
+ baseIMR: info?.["base_imr"] ?? 0,
5664
+ IMRFactor: accountInfo.imr_factor[item.symbol],
5665
+ referencePrice: item.mark_price,
5666
+ leverage: item.leverage ?? 0
5667
+ });
5668
+ } else {
5669
+ est_liq_price = perp.positions.liqPrice({
5670
+ symbol: item.symbol,
5671
+ markPrice: item.mark_price,
5672
+ totalCollateral,
5673
+ positionQty: item.position_qty,
5674
+ positions: rows,
5675
+ MMR: item.mmr,
5676
+ baseMMR: info?.["base_mmr"],
5677
+ baseIMR: info?.["base_imr"],
5678
+ IMRFactor: accountInfo.imr_factor[item.symbol],
5679
+ costPosition: item.cost_position
5680
+ });
5681
+ }
5566
5682
  return {
5567
5683
  ...item,
5568
5684
  est_liq_price
@@ -5589,6 +5705,8 @@ var PositionCalculator = class extends BaseCalculator {
5589
5705
  total_unsettled_pnl: unsettlementPnL,
5590
5706
  unrealPnlROI: totalUnrealizedROI,
5591
5707
  unrealPnlROI_index: totalUnrealizedROI_index,
5708
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
5709
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
5592
5710
  rows
5593
5711
  };
5594
5712
  }
@@ -5751,13 +5869,9 @@ var PortfolioCalculator = class extends BaseCalculator {
5751
5869
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
5752
5870
  return null;
5753
5871
  }
5754
- const totallCrossUnsettledPnL = positions3.rows.reduce(
5755
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
5756
- 0
5757
- );
5758
- const totalUnsettlementPnL = positions3.rows.reduce(
5759
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
5760
- 0
5872
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
5873
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(
5874
+ positions3
5761
5875
  );
5762
5876
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
5763
5877
  const [USDC_holding, nonUSDC] = parseHolding(
@@ -5769,7 +5883,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5769
5883
  const totalCollateral = perp.account.totalCollateral({
5770
5884
  USDCHolding: USDC_holding,
5771
5885
  nonUSDCHolding: nonUSDC,
5772
- unsettlementPnL: totallCrossUnsettledPnL,
5886
+ unsettlementPnL: unsettledCrossPnL,
5773
5887
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
5774
5888
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
5775
5889
  });
@@ -5780,7 +5894,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5780
5894
  return acc.add(curr.margin ?? 0);
5781
5895
  }, utils.zero);
5782
5896
  const totalValue = perp.account.totalValue({
5783
- totalUnsettlementPnL,
5897
+ totalUnsettlementPnL: unsettledPnL,
5784
5898
  USDCHolding: USDC_holding,
5785
5899
  nonUSDCHolding: nonUSDC,
5786
5900
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -5824,7 +5938,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5824
5938
  totalUnrealizedROI,
5825
5939
  freeCollateral,
5826
5940
  availableBalance,
5827
- unsettledPnL: totalUnsettlementPnL,
5941
+ unsettledPnL,
5828
5942
  holding,
5829
5943
  usdcHolding: USDC_holding,
5830
5944
  freeCollateralUSDCOnly
@@ -5943,7 +6057,7 @@ var usePositionStream = (symbol = "all", options) => {
5943
6057
  total_unreal_pnl: total_unreal_pnl_index,
5944
6058
  unrealPnlROI: unrealPnlROI_index
5945
6059
  };
5946
- }, [calcMode]);
6060
+ }, [calcMode, formattedPositions]);
5947
6061
  let rows = formattedPositions[0];
5948
6062
  {
5949
6063
  if (!rows) {
@@ -6433,14 +6547,8 @@ function formatPortfolio(inputs) {
6433
6547
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
6434
6548
  return null;
6435
6549
  }
6436
- const totallCrossUnsettledPnL = positions3.rows.reduce(
6437
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
6438
- 0
6439
- );
6440
- const totalUnsettlementPnL = positions3.rows.reduce(
6441
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
6442
- 0
6443
- );
6550
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
6551
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
6444
6552
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
6445
6553
  const [USDC_holding, nonUSDC] = parseHolding(
6446
6554
  holding,
@@ -6451,7 +6559,7 @@ function formatPortfolio(inputs) {
6451
6559
  const totalCollateral = perp.account.totalCollateral({
6452
6560
  USDCHolding: USDC_holding,
6453
6561
  nonUSDCHolding: nonUSDC,
6454
- unsettlementPnL: totallCrossUnsettledPnL,
6562
+ unsettlementPnL: unsettledCrossPnL,
6455
6563
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
6456
6564
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
6457
6565
  });
@@ -6462,7 +6570,7 @@ function formatPortfolio(inputs) {
6462
6570
  return acc.add(curr.margin ?? 0);
6463
6571
  }, utils.zero);
6464
6572
  const totalValue = perp.account.totalValue({
6465
- totalUnsettlementPnL,
6573
+ totalUnsettlementPnL: unsettledPnL,
6466
6574
  USDCHolding: USDC_holding,
6467
6575
  nonUSDCHolding: nonUSDC,
6468
6576
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -6506,7 +6614,7 @@ function formatPortfolio(inputs) {
6506
6614
  totalUnrealizedROI,
6507
6615
  freeCollateral,
6508
6616
  availableBalance,
6509
- unsettledPnL: totalUnsettlementPnL,
6617
+ unsettledPnL,
6510
6618
  holding,
6511
6619
  freeCollateralUSDCOnly
6512
6620
  };
@@ -6515,7 +6623,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6515
6623
  if (!accountInfo || !fundingRates || !symbolsInfo) {
6516
6624
  return data;
6517
6625
  }
6518
- let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
6626
+ let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
6519
6627
  const rows = data.rows.map((item) => {
6520
6628
  const info = symbolsInfo[item.symbol];
6521
6629
  const notional = perp.positions.notional(item.position_qty, item.mark_price);
@@ -6577,6 +6685,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6577
6685
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
6578
6686
  notional_total = notional_total.add(notional);
6579
6687
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
6688
+ if (item.margin_mode === types.MarginMode.CROSS) {
6689
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
6690
+ }
6691
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
6692
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
6693
+ }
6580
6694
  return {
6581
6695
  ...item,
6582
6696
  mm: perp.positions.maintenanceMargin({
@@ -6590,7 +6704,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6590
6704
  unrealized_pnl: unrealPnl,
6591
6705
  unrealized_pnl_index: unrealPnl_index,
6592
6706
  unrealized_pnl_ROI: unrealPnlROI,
6593
- unrealized_pnl_ROI_index: unrealPnlROI_index
6707
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
6708
+ unsettled_pnl: unsettlementPnL2
6594
6709
  };
6595
6710
  });
6596
6711
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -6604,6 +6719,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6604
6719
  notional: notional_total.toNumber(),
6605
6720
  unsettledPnL: unsettlementPnL,
6606
6721
  total_unsettled_pnl: unsettlementPnL,
6722
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
6723
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
6607
6724
  rows
6608
6725
  };
6609
6726
  }
@@ -7986,7 +8103,9 @@ var useDeposit = (options) => {
7986
8103
  const depositPromise = isNativeToken ? account9.assetsManager.depositNativeToken(inputs) : account9.assetsManager.deposit(inputs);
7987
8104
  return depositPromise.then((result) => {
7988
8105
  updateAllowanceWhenTxSuccess(result.hash);
7989
- setBalance((value) => new utils.Decimal(value).sub(quantity).toString());
8106
+ setBalance(
8107
+ (value) => value ? new utils.Decimal(value).sub(quantity).toString() : "0"
8108
+ );
7990
8109
  track2(types.TrackerEventName.depositSuccess, {
7991
8110
  wallet: state?.connectWallet?.name,
7992
8111
  network: targetChain?.network_infos.name,
@@ -8038,16 +8157,16 @@ var useDeposit = (options) => {
8038
8157
  };
8039
8158
  function useBalance(options) {
8040
8159
  const { srcToken, address, decimals, account: account9, status } = options;
8041
- const [balance, setBalance] = React.useState("0");
8160
+ const [balance, setBalance] = React.useState(null);
8042
8161
  const fetchBalance = React.useCallback(
8043
8162
  async (address2, decimals2) => {
8044
8163
  try {
8045
8164
  if (types.isNativeTokenChecker(address2)) {
8046
- return account9.assetsManager.getNativeBalance({
8165
+ return await account9.assetsManager.getNativeBalance({
8047
8166
  decimals: decimals2
8048
8167
  });
8049
8168
  }
8050
- return account9.assetsManager.getBalance(address2, {
8169
+ return await account9.assetsManager.getBalance(address2, {
8051
8170
  decimals: decimals2
8052
8171
  });
8053
8172
  } catch (err) {
@@ -8096,11 +8215,13 @@ function useBalance(options) {
8096
8215
  React.useEffect(() => {
8097
8216
  if (swrBalance !== void 0) {
8098
8217
  setBalance(swrBalance || "0");
8218
+ } else {
8219
+ setBalance(null);
8099
8220
  }
8100
- }, [swrBalance]);
8221
+ }, [swrBalance, address]);
8101
8222
  return {
8102
8223
  balance,
8103
- balanceRevalidating,
8224
+ balanceRevalidating: balanceRevalidating || balance === null,
8104
8225
  setBalance,
8105
8226
  fetchBalance,
8106
8227
  fetchBalances
@@ -9630,6 +9751,9 @@ var PriceValidationStrategy = class {
9630
9751
  }
9631
9752
  const price = new utils.Decimal(order_price);
9632
9753
  const { symbol } = config;
9754
+ if (!symbol) {
9755
+ return;
9756
+ }
9633
9757
  const { quote_max, quote_min, quote_dp, price_range, price_scope } = symbol;
9634
9758
  const maxPriceNumber = perp.order.maxPrice(config.markPrice, price_range);
9635
9759
  const minPriceNumber = perp.order.minPrice(config.markPrice, price_range);
@@ -9676,6 +9800,9 @@ var TriggerPriceValidationStrategy = class {
9676
9800
  validate(values, config) {
9677
9801
  const { trigger_price } = values;
9678
9802
  const { symbol } = config;
9803
+ if (!symbol) {
9804
+ return;
9805
+ }
9679
9806
  const { quote_max, quote_min } = symbol;
9680
9807
  if (!trigger_price) {
9681
9808
  return OrderValidation.required("trigger_price");
@@ -9722,6 +9849,9 @@ var QuantityValidationStrategy = class {
9722
9849
  validate(values, config) {
9723
9850
  let { order_quantity, total, order_price } = values;
9724
9851
  const { maxQty, symbol } = config;
9852
+ if (!symbol) {
9853
+ return;
9854
+ }
9725
9855
  const { base_min, base_dp, quote_dp } = symbol;
9726
9856
  if (!order_quantity && total && order_price) {
9727
9857
  const totalNumber = new utils.Decimal(total);
@@ -10977,7 +11107,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
10977
11107
  totalCollateral,
10978
11108
  futures_taker_fee_rate,
10979
11109
  positions: positions3,
10980
- // leverage,
11110
+ symbolLeverage,
10981
11111
  sumUnitaryFunding
10982
11112
  } = inputs;
10983
11113
  const orderFee = perp.order.orderFee({
@@ -11002,7 +11132,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
11002
11132
  }
11003
11133
  });
11004
11134
  } else {
11005
- let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = 1;
11135
+ let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = symbolLeverage ?? 1;
11006
11136
  if (positions3) {
11007
11137
  const position = positions3.find(
11008
11138
  (p) => p.symbol === symbol && p.margin_mode === types.MarginMode.ISOLATED
@@ -12692,6 +12822,12 @@ var DataPaint = class extends BasePaint {
12692
12822
  this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
12693
12823
  this.transformTop = 0;
12694
12824
  this.QRCODE_SIZE = 56;
12825
+ this.BROKER_BADGE_HEIGHT = 18;
12826
+ this.BROKER_BADGE_PADDING_X = 8;
12827
+ this.BROKER_BADGE_RADIUS = 4;
12828
+ }
12829
+ formatMarginMode(marginMode) {
12830
+ return marginMode === types.MarginMode.ISOLATED ? "Isolated" : "Cross";
12695
12831
  }
12696
12832
  async draw(options) {
12697
12833
  const needDrawDetails = Array.isArray(options.data?.position?.informations) && (options.data?.position?.informations?.length ?? 0) > 0;
@@ -12778,6 +12914,49 @@ var DataPaint = class extends BasePaint {
12778
12914
  fontSize: this._ratio(fontSize),
12779
12915
  fontFamily: options.fontFamily
12780
12916
  });
12917
+ const brokerName = options.data?.position.brokerName?.trim();
12918
+ if (brokerName) {
12919
+ left += (prevElementBoundingBox.width ?? 0) + this._ratio(10);
12920
+ const badgeHeight = this._ratio(this.BROKER_BADGE_HEIGHT);
12921
+ const badgePaddingX = this._ratio(this.BROKER_BADGE_PADDING_X);
12922
+ const badgeRadius = this._ratio(this.BROKER_BADGE_RADIUS);
12923
+ const badgeFontSize = this._ratio(12);
12924
+ const badgeFontWeight = 600;
12925
+ const textMetrics = this._drawText(
12926
+ brokerName,
12927
+ {
12928
+ left: 0,
12929
+ top: 0,
12930
+ fontSize: badgeFontSize,
12931
+ fontWeight: badgeFontWeight,
12932
+ fontFamily: options.fontFamily
12933
+ },
12934
+ true
12935
+ );
12936
+ const badgeWidth = (textMetrics.width ?? 0) + badgePaddingX * 2;
12937
+ const badgeTop = this._ratio(top) - badgeHeight / 2;
12938
+ this._fillRoundedRect(
12939
+ left,
12940
+ badgeTop,
12941
+ badgeWidth,
12942
+ badgeHeight,
12943
+ badgeRadius,
12944
+ "rgba(255,255,255,0.06)"
12945
+ );
12946
+ this._drawText(brokerName, {
12947
+ color: "rgba(255,255,255,0.36)",
12948
+ left: left + badgePaddingX,
12949
+ top: badgeTop + badgeHeight / 2,
12950
+ fontSize: badgeFontSize,
12951
+ fontWeight: badgeFontWeight,
12952
+ fontFamily: options.fontFamily,
12953
+ textBaseline: "middle"
12954
+ });
12955
+ prevElementBoundingBox = {
12956
+ ...prevElementBoundingBox,
12957
+ width: badgeWidth
12958
+ };
12959
+ }
12781
12960
  }
12782
12961
  const marginMode = options.data?.position.marginMode;
12783
12962
  if (marginMode) {
@@ -12792,7 +12971,7 @@ var DataPaint = class extends BasePaint {
12792
12971
  });
12793
12972
  }
12794
12973
  left += (prevElementBoundingBox.width ?? 0) + this._ratio(7);
12795
- const marginModeText = marginMode.charAt(0).toUpperCase() + marginMode.slice(1);
12974
+ const marginModeText = this.formatMarginMode(marginMode);
12796
12975
  prevElementBoundingBox = this._drawText(marginModeText, {
12797
12976
  color: layout.color,
12798
12977
  left,
@@ -12825,6 +13004,20 @@ var DataPaint = class extends BasePaint {
12825
13004
  );
12826
13005
  }
12827
13006
  }
13007
+ _fillRoundedRect(x, y, width, height, radius, color) {
13008
+ const r = Math.min(radius, width / 2, height / 2);
13009
+ this.ctx.save();
13010
+ this.ctx.fillStyle = color;
13011
+ this.ctx.beginPath();
13012
+ this.ctx.moveTo(x + r, y);
13013
+ this.ctx.arcTo(x + width, y, x + width, y + height, r);
13014
+ this.ctx.arcTo(x + width, y + height, x, y + height, r);
13015
+ this.ctx.arcTo(x, y + height, x, y, r);
13016
+ this.ctx.arcTo(x, y, x + width, y, r);
13017
+ this.ctx.closePath();
13018
+ this.ctx.fill();
13019
+ this.ctx.restore();
13020
+ }
12828
13021
  drawUnrealizedPnL(options, offsetTop = 0) {
12829
13022
  const layout = ramda.path(
12830
13023
  ["layout", "unrealizedPnl"],
@@ -13278,18 +13471,6 @@ var useEpochInfo = (type) => {
13278
13471
  }, [epochInfo]);
13279
13472
  return [epochInfo, { isLoading, curEpochInfo, isNotStared, refresh }];
13280
13473
  };
13281
-
13282
- // src/trading-rewards/useAllBrokers.ts
13283
- var useAllBrokers = () => {
13284
- const { data } = useQuery("/v1/public/broker/name", {
13285
- formatter: (res) => {
13286
- const { rows } = res;
13287
- return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
13288
- },
13289
- revalidateOnFocus: false
13290
- });
13291
- return [data];
13292
- };
13293
13474
  var useCurEpochEstimate = (type) => {
13294
13475
  const [data, setData] = React.useState(void 0);
13295
13476
  const { account: account9 } = useAccount();
@@ -18425,108 +18606,65 @@ var initialOrderState = {
18425
18606
  tp_trigger_price: "",
18426
18607
  sl_trigger_price: "",
18427
18608
  total: "",
18428
- symbol: ""
18609
+ symbol: "",
18610
+ side: types.OrderSide.BUY,
18611
+ order_type: types.OrderType.LIMIT,
18612
+ margin_mode: types.MarginMode.CROSS
18429
18613
  };
18430
- var useOrderStore = zustand.create()(
18431
- immer.immer((set, get3) => ({
18432
- entry: {
18433
- side: types.OrderSide.BUY,
18434
- order_type: types.OrderType.LIMIT,
18435
- ...initialOrderState
18436
- },
18437
- estLeverage: null,
18438
- estLiquidationPrice: null,
18439
- errors: {},
18440
- actions: {
18441
- initOrder: (symbol, options) => {
18442
- set((state) => {
18443
- state.entry = {
18444
- ...initialOrderState,
18445
- symbol,
18446
- side: options?.side ?? types.OrderSide.BUY,
18447
- order_type: options?.order_type ?? types.OrderType.LIMIT,
18448
- margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
18449
- };
18450
- state.estLeverage = null;
18451
- state.estLiquidationPrice = null;
18452
- state.errors = {};
18614
+ var useOrderEntryNextInternal = (symbol, options = {}) => {
18615
+ const { symbolInfo, symbolLeverage } = options;
18616
+ const [orderEntity, setOrderEntity] = React.useState(
18617
+ () => ({
18618
+ ...initialOrderState,
18619
+ ...options.initialOrder,
18620
+ symbol
18621
+ })
18622
+ );
18623
+ const actions = React.useMemo(
18624
+ () => ({
18625
+ initOrder: (sym, opts) => {
18626
+ setOrderEntity({
18627
+ ...initialOrderState,
18628
+ symbol: sym,
18629
+ side: opts?.side ?? types.OrderSide.BUY,
18630
+ order_type: opts?.order_type ?? types.OrderType.LIMIT,
18631
+ margin_mode: opts?.margin_mode ?? types.MarginMode.CROSS
18453
18632
  });
18454
18633
  },
18455
- hasTP_SL: () => {
18456
- const order = get3().entry;
18457
- return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18458
- },
18459
- updateOrderComputed: (data) => {
18460
- set(
18461
- (state) => {
18462
- state.estLeverage = data.estLeverage;
18463
- state.estLiquidationPrice = data.estLiquidationPrice;
18464
- },
18465
- false
18466
- // "updateOrderComputed"
18467
- );
18468
- },
18469
18634
  updateOrder: (order) => {
18470
- set(
18471
- (state) => {
18472
- state.entry = {
18473
- ...state.entry,
18474
- ...order
18475
- };
18476
- },
18477
- false
18478
- // "updateOrder"
18479
- );
18635
+ setOrderEntity((prev) => ({ ...prev, ...order }));
18480
18636
  },
18481
18637
  updateOrderByKey: (key, value) => {
18482
- set(
18483
- (state) => {
18484
- state.entry[key] = value;
18485
- },
18486
- false
18487
- // "updateOrderByKey"
18488
- );
18489
- },
18490
- restoreOrder: (order) => {
18491
- set(
18492
- (state) => {
18493
- state.entry = order;
18494
- },
18495
- false
18496
- // "restoreOrder"
18497
- );
18638
+ setOrderEntity((prev) => ({ ...prev, [key]: value }));
18498
18639
  },
18499
18640
  resetOrder: (_order) => {
18500
- set(
18501
- (state) => {
18502
- state.entry.order_price = "";
18503
- state.entry.order_quantity = "";
18504
- state.entry.trigger_price = "";
18505
- state.entry.total = "";
18506
- state.entry.tp_trigger_price = "";
18507
- state.entry.tp_pnl = "";
18508
- state.entry.tp_offset = "";
18509
- state.entry.tp_offset_percentage = "";
18510
- state.entry.sl_trigger_price = "";
18511
- state.entry.sl_pnl = "";
18512
- state.entry.sl_offset = "";
18513
- state.entry.sl_offset_percentage = "";
18514
- },
18515
- true
18516
- // "resetOrder"
18517
- );
18641
+ setOrderEntity((prev) => ({
18642
+ ...prev,
18643
+ order_price: "",
18644
+ order_quantity: "",
18645
+ trigger_price: "",
18646
+ total: "",
18647
+ tp_trigger_price: "",
18648
+ tp_pnl: "",
18649
+ tp_offset: "",
18650
+ tp_offset_percentage: "",
18651
+ sl_trigger_price: "",
18652
+ sl_pnl: "",
18653
+ sl_offset: "",
18654
+ sl_offset_percentage: ""
18655
+ }));
18656
+ },
18657
+ hasTP_SL: () => {
18658
+ const order = orderEntity;
18659
+ return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18518
18660
  }
18519
- }
18520
- }))
18521
- );
18522
- var useOrderEntryNextInternal = (symbol, options = {}) => {
18523
- const { symbolInfo, symbolLeverage } = options;
18524
- const orderEntity = useOrderStore((state) => state.entry);
18525
- const orderEntryActions = useOrderStore((state) => state.actions);
18661
+ }),
18662
+ [orderEntity]
18663
+ );
18526
18664
  React.useEffect(() => {
18527
- orderEntryActions.initOrder(symbol, options.initialOrder);
18665
+ actions.initOrder(symbol, options.initialOrder);
18528
18666
  if (options.initialOrder) {
18529
- orderEntryActions.updateOrder(options.initialOrder);
18667
+ actions.updateOrder(options.initialOrder);
18530
18668
  }
18531
18669
  }, [symbol]);
18532
18670
  const calculate2 = React.useCallback(
@@ -18544,10 +18682,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18544
18682
  );
18545
18683
  const setValue = (key, value, additional) => {
18546
18684
  if (!symbolInfo) {
18547
- orderEntryActions.updateOrderByKey(key, value);
18685
+ actions.updateOrderByKey(key, value);
18548
18686
  return;
18549
18687
  }
18550
- const currentEntry = useOrderStore.getState().entry;
18688
+ const currentEntry = orderEntity;
18551
18689
  const { markPrice } = additional ?? { markPrice: 0 };
18552
18690
  let newValues = calculate2(
18553
18691
  { ...currentEntry },
@@ -18581,7 +18719,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18581
18719
  if (sl_ROI) {
18582
18720
  newValues.sl_ROI = sl_ROI;
18583
18721
  }
18584
- orderEntryActions.updateOrder(newValues);
18722
+ actions.updateOrder(newValues);
18585
18723
  return newValues;
18586
18724
  };
18587
18725
  const calculateTPSL = (key, newValues, markPrice, symbolInfo2) => {
@@ -18628,11 +18766,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18628
18766
  };
18629
18767
  const setValues = (values, additional) => {
18630
18768
  if (!symbolInfo) {
18631
- orderEntryActions.updateOrder(values);
18769
+ actions.updateOrder(values);
18632
18770
  return;
18633
18771
  }
18634
- const currentEntry = useOrderStore.getState().entry;
18635
- let newValues = { ...currentEntry };
18772
+ let newValues = { ...orderEntity };
18636
18773
  Object.keys(values).forEach((key) => {
18637
18774
  newValues = calculate2(
18638
18775
  newValues,
@@ -18642,17 +18779,28 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18642
18779
  symbolInfo
18643
18780
  );
18644
18781
  });
18645
- orderEntryActions.updateOrder(newValues);
18782
+ actions.updateOrder(newValues);
18783
+ return newValues;
18784
+ };
18785
+ const setValuesRaw = (values) => {
18786
+ if (!symbolInfo) {
18787
+ actions.updateOrder(values);
18788
+ return;
18789
+ }
18790
+ const newValues = {
18791
+ ...orderEntity,
18792
+ ...values
18793
+ };
18794
+ actions.updateOrder(newValues);
18646
18795
  return newValues;
18647
18796
  };
18648
18797
  const onMarkPriceUpdated = React.useCallback(
18649
18798
  (markPrice, baseOn = []) => {
18650
18799
  if (!options.symbolInfo) return;
18651
- const currentEntry = useOrderStore.getState().entry;
18652
- let newValues = { ...currentEntry };
18800
+ let newValues = { ...orderEntity };
18653
18801
  if (baseOn.length === 0) {
18654
18802
  newValues = calculate2(
18655
- { ...currentEntry },
18803
+ { ...orderEntity },
18656
18804
  "order_price",
18657
18805
  markPrice,
18658
18806
  markPrice,
@@ -18663,7 +18811,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18663
18811
  newValues = calculate2(
18664
18812
  { ...newValues },
18665
18813
  key,
18666
- currentEntry[key],
18814
+ orderEntity[key],
18667
18815
  markPrice,
18668
18816
  options.symbolInfo
18669
18817
  );
@@ -18682,9 +18830,9 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18682
18830
  newValues.sl_ROI = sl_ROI;
18683
18831
  }
18684
18832
  }
18685
- orderEntryActions.updateOrder(newValues);
18833
+ actions.updateOrder(newValues);
18686
18834
  },
18687
- [calculate2, options.symbolInfo, orderEntryActions]
18835
+ [calculate2, options.symbolInfo, symbolLeverage, orderEntity]
18688
18836
  );
18689
18837
  const validate = (order, creator, options2) => {
18690
18838
  return creator?.validate(order, {
@@ -18702,12 +18850,13 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18702
18850
  const submitOrder = React.useCallback(() => {
18703
18851
  }, [orderEntity]);
18704
18852
  const resetOrder = (order) => {
18705
- orderEntryActions.resetOrder(order);
18853
+ actions.resetOrder(order);
18706
18854
  };
18707
18855
  return {
18708
18856
  formattedOrder: orderEntity,
18709
18857
  setValue,
18710
18858
  setValues,
18859
+ setValuesRaw,
18711
18860
  submit: submitOrder,
18712
18861
  reset: resetOrder,
18713
18862
  generateOrder,
@@ -18723,6 +18872,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
18723
18872
  }
18724
18873
  const ee = useEventEmitter();
18725
18874
  const { track: track2 } = useTrack();
18875
+ const apiBaseUrl = useConfig("apiBaseUrl");
18876
+ const fetchSymbols = useSymbolStore((state) => state.fetchData);
18726
18877
  const [meta, setMeta] = React.useState({
18727
18878
  dirty: {},
18728
18879
  submitted: false,
@@ -18742,8 +18893,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18742
18893
  const symbolConfig = useSymbolsInfo();
18743
18894
  const accountInfo = useAccountInfo();
18744
18895
  const positions3 = usePositions();
18745
- const entry = useOrderStore((s) => s.entry);
18746
- const effectiveMarginMode = options?.initialOrder?.margin_mode ?? entry?.margin_mode ?? types.MarginMode.CROSS;
18896
+ const effectiveMarginMode = options?.initialOrder?.margin_mode ?? types.MarginMode.CROSS;
18747
18897
  const symbolLeverage = useLeverageBySymbol(symbol, effectiveMarginMode);
18748
18898
  const symbolInfo = symbolConfig[symbol]();
18749
18899
  const markPrice = actions.getMarkPriceBySymbol(symbol);
@@ -18752,6 +18902,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18752
18902
  formattedOrder,
18753
18903
  setValue: setValueInternal,
18754
18904
  setValues: setValuesInternal,
18905
+ setValuesRaw: setValuesRawInternal,
18755
18906
  validate,
18756
18907
  generateOrder,
18757
18908
  reset,
@@ -18976,6 +19127,21 @@ var useOrderEntry2 = (symbol, options = {}) => {
18976
19127
  interactiveValidate(newValues);
18977
19128
  }
18978
19129
  };
19130
+ const setValuesRaw = (values) => {
19131
+ if (!Object.keys(values).every(
19132
+ (key) => canSetTPSLPrice(
19133
+ key,
19134
+ values[key],
19135
+ formattedOrder.order_type
19136
+ )
19137
+ )) {
19138
+ return;
19139
+ }
19140
+ const newValues = setValuesRawInternal(values);
19141
+ if (newValues) {
19142
+ interactiveValidate(newValues);
19143
+ }
19144
+ };
18979
19145
  async function validateFunc(order) {
18980
19146
  const creator = getOrderCreator(order);
18981
19147
  return validate(order, creator, prepareData());
@@ -19030,11 +19196,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
19030
19196
  markPrice: markPrice2,
19031
19197
  totalCollateral,
19032
19198
  futures_taker_fee_rate: accountInfo.futures_taker_fee_rate,
19033
- imr_factor: accountInfo.imr_factor[symbol],
19199
+ imr_factor: accountInfo.imr_factor?.[symbol] ?? 0,
19034
19200
  symbol,
19035
19201
  positions: positions3,
19036
19202
  symbolInfo,
19037
- sumUnitaryFunding
19203
+ sumUnitaryFunding,
19204
+ symbolLeverage
19038
19205
  });
19039
19206
  return estLiqPrice2;
19040
19207
  }, [
@@ -19045,7 +19212,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
19045
19212
  symbol,
19046
19213
  maxQty,
19047
19214
  symbolInfo,
19048
- fundingRates
19215
+ fundingRates,
19216
+ symbolLeverage
19049
19217
  ]);
19050
19218
  const estLiqPriceDistance = React.useMemo(() => {
19051
19219
  if (!estLiqPrice) {
@@ -19117,6 +19285,9 @@ var useOrderEntry2 = (symbol, options = {}) => {
19117
19285
  orders: appendOrderMetadata(order.orders, orderMetadata)
19118
19286
  } : appendOrderMetadata(order, orderMetadata);
19119
19287
  const result = await doCreateOrder(params);
19288
+ if (!result.success && (order.order_type === types.OrderType.MARKET || order.order_type === types.OrderType.STOP_MARKET)) {
19289
+ void fetchSymbols(apiBaseUrl);
19290
+ }
19120
19291
  if (result.success) {
19121
19292
  let trackParams = {
19122
19293
  side: order.side,
@@ -19184,6 +19355,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
19184
19355
  freeCollateral: effectiveMarginMode === types.MarginMode.ISOLATED ? freeCollateralUSDCOnly : freeCollateral,
19185
19356
  setValue: useMemoizedFn(setValue),
19186
19357
  setValues: useMemoizedFn(setValues),
19358
+ setValuesRaw: useMemoizedFn(setValuesRaw),
19187
19359
  symbolInfo: symbolInfo || types.EMPTY_OBJECT,
19188
19360
  metaState: meta,
19189
19361
  isMutating,
@@ -19191,6 +19363,107 @@ var useOrderEntry2 = (symbol, options = {}) => {
19191
19363
  symbolLeverage
19192
19364
  };
19193
19365
  };
19366
+ var initialOrderState2 = {
19367
+ order_price: "",
19368
+ order_quantity: "",
19369
+ trigger_price: "",
19370
+ tp_trigger_price: "",
19371
+ sl_trigger_price: "",
19372
+ total: "",
19373
+ symbol: ""
19374
+ };
19375
+ var useOrderStore = zustand.create()(
19376
+ immer.immer((set, get3) => ({
19377
+ entry: {
19378
+ side: types.OrderSide.BUY,
19379
+ order_type: types.OrderType.LIMIT,
19380
+ ...initialOrderState2
19381
+ },
19382
+ estLeverage: null,
19383
+ estLiquidationPrice: null,
19384
+ errors: {},
19385
+ actions: {
19386
+ initOrder: (symbol, options) => {
19387
+ set((state) => {
19388
+ state.entry = {
19389
+ ...initialOrderState2,
19390
+ symbol,
19391
+ side: options?.side ?? types.OrderSide.BUY,
19392
+ order_type: options?.order_type ?? types.OrderType.LIMIT,
19393
+ margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
19394
+ };
19395
+ state.estLeverage = null;
19396
+ state.estLiquidationPrice = null;
19397
+ state.errors = {};
19398
+ });
19399
+ },
19400
+ hasTP_SL: () => {
19401
+ const order = get3().entry;
19402
+ return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
19403
+ },
19404
+ updateOrderComputed: (data) => {
19405
+ set(
19406
+ (state) => {
19407
+ state.estLeverage = data.estLeverage;
19408
+ state.estLiquidationPrice = data.estLiquidationPrice;
19409
+ },
19410
+ false
19411
+ // "updateOrderComputed"
19412
+ );
19413
+ },
19414
+ updateOrder: (order) => {
19415
+ set(
19416
+ (state) => {
19417
+ state.entry = {
19418
+ ...state.entry,
19419
+ ...order
19420
+ };
19421
+ },
19422
+ false
19423
+ // "updateOrder"
19424
+ );
19425
+ },
19426
+ updateOrderByKey: (key, value) => {
19427
+ set(
19428
+ (state) => {
19429
+ state.entry[key] = value;
19430
+ },
19431
+ false
19432
+ // "updateOrderByKey"
19433
+ );
19434
+ },
19435
+ restoreOrder: (order) => {
19436
+ set(
19437
+ (state) => {
19438
+ state.entry = order;
19439
+ },
19440
+ false
19441
+ // "restoreOrder"
19442
+ );
19443
+ },
19444
+ resetOrder: (_order) => {
19445
+ set(
19446
+ (state) => {
19447
+ state.entry.order_price = "";
19448
+ state.entry.order_quantity = "";
19449
+ state.entry.trigger_price = "";
19450
+ state.entry.total = "";
19451
+ state.entry.tp_trigger_price = "";
19452
+ state.entry.tp_pnl = "";
19453
+ state.entry.tp_offset = "";
19454
+ state.entry.tp_offset_percentage = "";
19455
+ state.entry.sl_trigger_price = "";
19456
+ state.entry.sl_pnl = "";
19457
+ state.entry.sl_offset = "";
19458
+ state.entry.sl_offset_percentage = "";
19459
+ },
19460
+ true
19461
+ // "resetOrder"
19462
+ );
19463
+ }
19464
+ }
19465
+ }))
19466
+ );
19194
19467
  var useOrderEntity = (order, options) => {
19195
19468
  const { symbol } = order;
19196
19469
  const { maxQty } = options || {};
@@ -19665,6 +19938,7 @@ exports.EpochStatus = EpochStatus;
19665
19938
  exports.ExtendedConfigStore = ExtendedConfigStore;
19666
19939
  exports.FlagKeys = FlagKeys;
19667
19940
  exports.MaintenanceStatus = MaintenanceStatus;
19941
+ exports.MarketCategoriesConfigProvider = MarketCategoriesConfigProvider;
19668
19942
  exports.MarketsStorageKey = MarketsStorageKey;
19669
19943
  exports.MarketsType = MarketsType;
19670
19944
  exports.ORDERLY_ORDERBOOK_DEPTH_KEY = ORDERLY_ORDERBOOK_DEPTH_KEY;
@@ -19681,6 +19955,7 @@ exports.fetcher = fetcher;
19681
19955
  exports.findPositionTPSLFromOrders = findPositionTPSLFromOrders;
19682
19956
  exports.findTPSLFromOrder = findTPSLFromOrder;
19683
19957
  exports.findTPSLOrderPriceFromOrder = findTPSLOrderPriceFromOrder;
19958
+ exports.formatSymbolWithBroker = formatSymbolWithBroker;
19684
19959
  exports.getMinNotional = getMinNotional;
19685
19960
  exports.getPriceKey = getPriceKey;
19686
19961
  exports.indexedDBManager = indexedDBManager;
@@ -19701,6 +19976,7 @@ exports.useApiKeyManager = useApiKeyManager;
19701
19976
  exports.useAppStore = useAppStore;
19702
19977
  exports.useAssetsHistory = useAssetsHistory;
19703
19978
  exports.useAudioPlayer = useAudioPlayer;
19979
+ exports.useBadgeBySymbol = useBadgeBySymbol;
19704
19980
  exports.useBalanceSubscription = useBalanceSubscription;
19705
19981
  exports.useBalanceTopic = useBalanceTopic;
19706
19982
  exports.useBoolean = useBoolean;
@@ -19759,6 +20035,7 @@ exports.useMarkPrice = useMarkPrice;
19759
20035
  exports.useMarkPriceBySymbol = useMarkPriceBySymbol;
19760
20036
  exports.useMarkPricesStream = useMarkPricesStream;
19761
20037
  exports.useMarket = useMarket;
20038
+ exports.useMarketCategoriesConfig = useMarketCategoriesConfig;
19762
20039
  exports.useMarketList = useMarketList;
19763
20040
  exports.useMarketMap = useMarketMap;
19764
20041
  exports.useMarketTradeStream = useMarketTradeStream;
@@ -19816,6 +20093,7 @@ exports.useSymbolInfo = useSymbolInfo;
19816
20093
  exports.useSymbolLeverage = useSymbolLeverage;
19817
20094
  exports.useSymbolLeverageMap = useSymbolLeverageMap;
19818
20095
  exports.useSymbolPriceRange = useSymbolPriceRange;
20096
+ exports.useSymbolWithBroker = useSymbolWithBroker;
19819
20097
  exports.useSymbolsInfo = useSymbolsInfo;
19820
20098
  exports.useSymbolsInfoStore = useSymbolsInfoStore;
19821
20099
  exports.useTPSLOrder = useTPSLOrder;