@orderly.network/hooks 2.11.2 → 2.12.0-alpha.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
@@ -1,10 +1,10 @@
1
+ import React, { createContext, createElement, useContext, useCallback, useState, useEffect, useMemo, useRef, useId, useLayoutEffect } from 'react';
1
2
  import { get, WS, mutate as mutate$1 } from '@orderly.network/net';
2
3
  import useSWR5__default, { mutate } from 'swr';
3
4
  import * as useSWR5 from 'swr';
4
5
  export { useSWR5 as swr };
5
6
  export { unstable_serialize, default as useSWR, useSWRConfig } from 'swr';
6
7
  import { TesnetTokenFallback, ArbitrumSepoliaTokenInfo, SolanaDevnetTokenInfo, OrderType, OrderSide, MarginMode, SDKError, TrackerEventName, AccountStatusEnum, AlgoOrderType, AlgoOrderRootType, OrderStatus, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, EMPTY_LIST, EMPTY_OBJECT, isNativeTokenChecker, nativeTokenAddress, ChainKey, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, ChainNamespace, MaxUint256, DEPOSIT_FEE_RATE, ETHEREUM_MAINNET_CHAINID, LedgerWalletKey, SOLANA_TESTNET_CHAINID, MONAD_TESTNET_CHAINID, ABSTRACT_TESTNET_CHAINID, BSC_TESTNET_CHAINID, SolanaChains, PositionType, DistributionType, TriggerPriceType } from '@orderly.network/types';
7
- import React, { createContext, useContext, useCallback, useState, useEffect, useMemo, useRef, useId, useLayoutEffect } from 'react';
8
8
  import { zero, windowGuard, getTimestamp, getGlobalObject, Decimal, timeConvertString, isTestnet, getPrecisionByNumber, getBBOType, camelCaseToUnderscoreCase, commify, todpIfNeed, getTPSLDirection } from '@orderly.network/utils';
9
9
  import useSWRMutation from 'swr/mutation';
10
10
  import useConstant from 'use-constant';
@@ -34,13 +34,24 @@ var __export = (target, all) => {
34
34
  for (var name in all)
35
35
  __defProp(target, name, { get: all[name], enumerable: true });
36
36
  };
37
+ var MarketCategoriesConfigContext = createContext(void 0);
38
+ var MarketCategoriesConfigProvider = ({ value, children }) => {
39
+ return createElement(
40
+ MarketCategoriesConfigContext.Provider,
41
+ { value },
42
+ children
43
+ );
44
+ };
45
+ function useMarketCategoriesConfig() {
46
+ return useContext(MarketCategoriesConfigContext);
47
+ }
37
48
 
38
49
  // src/version.ts
39
50
  if (typeof window !== "undefined") {
40
51
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
41
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.11.2";
52
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.12.0-alpha.0";
42
53
  }
43
- var version_default = "2.11.2";
54
+ var version_default = "2.12.0-alpha.0";
44
55
  var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
45
56
  var noCacheConfig = {
46
57
  dedupingInterval: 0,
@@ -2576,16 +2587,12 @@ var createDataStore = (config) => {
2576
2587
  const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
2577
2588
  const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
2578
2589
  const data = await fetcher(url, {}, { formatter });
2579
- const dataWithBrokerId = data.map((item) => ({
2580
- ...item,
2581
- broker_id: options?.brokerId
2582
- }));
2583
2590
  set({
2584
- data: dataWithBrokerId,
2591
+ data,
2585
2592
  loading: false,
2586
2593
  error: null
2587
2594
  });
2588
- return dataWithBrokerId;
2595
+ return data;
2589
2596
  } catch (error) {
2590
2597
  set({ error, loading: false });
2591
2598
  return null;
@@ -3417,6 +3424,7 @@ var MarketsType = /* @__PURE__ */ ((MarketsType2) => {
3417
3424
  MarketsType2[MarketsType2["ALL"] = 2] = "ALL";
3418
3425
  MarketsType2[MarketsType2["RWA"] = 3] = "RWA";
3419
3426
  MarketsType2[MarketsType2["NEW_LISTING"] = 4] = "NEW_LISTING";
3427
+ MarketsType2[MarketsType2["COMMUNITY"] = 5] = "COMMUNITY";
3420
3428
  return MarketsType2;
3421
3429
  })(MarketsType || {});
3422
3430
  var MarketsStorageKey = "orderly_markets";
@@ -3586,6 +3594,8 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3586
3594
  const rwaInfo = !rwaSymbolsInfo.isNil ? rwaSymbolsInfo[item.symbol]() : null;
3587
3595
  return {
3588
3596
  ...item,
3597
+ broker_id: item.broker_id,
3598
+ display_symbol_name: item.display_symbol_name,
3589
3599
  quote_dp: info("quote_dp"),
3590
3600
  created_time: info("created_time"),
3591
3601
  displayName: info("displayName"),
@@ -3607,7 +3617,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3607
3617
  var filterMarkets = (params) => {
3608
3618
  const { markets, favorites, recent, newListing, type } = params;
3609
3619
  let curData = [];
3610
- if (type === 2 /* ALL */) {
3620
+ if (type === 2 /* ALL */ || type === 5 /* COMMUNITY */) {
3611
3621
  curData = markets;
3612
3622
  } else if (type === 3 /* RWA */) {
3613
3623
  curData = markets.filter((item) => item.isRwa);
@@ -4529,7 +4539,7 @@ var useMarket = (type) => {
4529
4539
  const getData = (type2) => {
4530
4540
  const localData = type2 === 0 /* FAVORITES */ ? [...favorites] : [...recent];
4531
4541
  const keys = localData.map((item) => item.name);
4532
- const filter = type2 == 2 /* ALL */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
4542
+ const filter = type2 == 2 /* ALL */ || type2 == 4 /* COMMUNITY */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
4533
4543
  const favoritesData = [...favorites];
4534
4544
  const favoriteKeys = favoritesData.map((item) => item.name);
4535
4545
  if (filter) {
@@ -4728,6 +4738,80 @@ var useSymbolLeverageMap = () => {
4728
4738
  refresh: mutate6
4729
4739
  };
4730
4740
  };
4741
+
4742
+ // src/trading-rewards/useAllBrokers.ts
4743
+ var useAllBrokers = () => {
4744
+ const { data } = useQuery("/v1/public/broker/name", {
4745
+ formatter: (res) => {
4746
+ const { rows } = res;
4747
+ return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
4748
+ },
4749
+ revalidateOnFocus: false
4750
+ });
4751
+ return [data];
4752
+ };
4753
+
4754
+ // src/useBadgeBySymbol.ts
4755
+ function brokerNameBaseFromRaw(rawBrokerName) {
4756
+ if (!rawBrokerName) return void 0;
4757
+ const first = rawBrokerName.trim().split(/[ _-]/, 1)[0]?.trim() ?? "";
4758
+ return first.length > 0 ? first : void 0;
4759
+ }
4760
+ var useBadgeBySymbol = (symbol) => {
4761
+ const symbolsInfo = useSymbolsInfo();
4762
+ const [brokers] = useAllBrokers();
4763
+ return useMemo(() => {
4764
+ if (!symbol || symbolsInfo.isNil) {
4765
+ return {
4766
+ displayName: symbol ?? "",
4767
+ brokerId: void 0,
4768
+ brokerName: void 0,
4769
+ brokerNameRaw: void 0
4770
+ };
4771
+ }
4772
+ const getter = symbolsInfo[symbol];
4773
+ const info = typeof getter === "function" ? getter() : void 0;
4774
+ const displayName = info?.displayName ?? info?.display_symbol_name ?? symbol;
4775
+ const brokerId = info?.broker_id ?? void 0;
4776
+ const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
4777
+ const base = brokerNameBaseFromRaw(rawBrokerName);
4778
+ const brokerName = base ? base.length > 7 ? `${base.slice(0, 7)}...` : base : void 0;
4779
+ return {
4780
+ displayName,
4781
+ brokerId,
4782
+ brokerName,
4783
+ brokerNameRaw: rawBrokerName
4784
+ };
4785
+ }, [brokers, symbolsInfo, symbol]);
4786
+ };
4787
+ function formatSymbolWithBroker(symbol, symbolsInfo, brokers) {
4788
+ if (!symbol) return "";
4789
+ let brokerNameBase;
4790
+ if (!symbolsInfo.isNil) {
4791
+ const getter = symbolsInfo[symbol];
4792
+ const info = typeof getter === "function" ? getter() : void 0;
4793
+ const brokerId = info?.broker_id ?? void 0;
4794
+ const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
4795
+ brokerNameBase = brokerNameBaseFromRaw(rawBrokerName);
4796
+ }
4797
+ const parts = symbol.split("_");
4798
+ const base = parts.length >= 3 ? parts[1] ?? "" : symbol.match(/^([A-Za-z]+)/)?.[1] ?? symbol;
4799
+ const hasBrokerSuffix = symbol.includes("-") || symbol.split("_").length > 3;
4800
+ if (brokerNameBase && hasBrokerSuffix) {
4801
+ return `${base}-${brokerNameBase}`;
4802
+ }
4803
+ return base;
4804
+ }
4805
+ var useSymbolWithBroker = (symbol) => {
4806
+ const symbolsInfo = useSymbolsInfo();
4807
+ const [brokers] = useAllBrokers();
4808
+ return useMemo(
4809
+ () => formatSymbolWithBroker(symbol, symbolsInfo, brokers),
4810
+ [brokers, symbolsInfo, symbol]
4811
+ );
4812
+ };
4813
+
4814
+ // src/orderly/useMarginModes.ts
4731
4815
  var useMarginModes = () => {
4732
4816
  const { data, error, isLoading, mutate: mutate6 } = usePrivateQuery("/v1/client/margin_modes", {
4733
4817
  revalidateOnFocus: false,
@@ -4769,22 +4853,28 @@ var useMarginModes = () => {
4769
4853
  };
4770
4854
  var useMarginModeBySymbol = (symbol, fallback = MarginMode.CROSS) => {
4771
4855
  const { marginModes, isLoading, error, refresh, updateMarginMode } = useMarginModes();
4772
- const marginMode = fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
4856
+ const { brokerId } = useBadgeBySymbol(symbol);
4857
+ const marginMode = useMemo(() => {
4858
+ if (brokerId) return MarginMode.ISOLATED;
4859
+ return fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
4860
+ }, [brokerId, fallback, marginModes, symbol]);
4773
4861
  const update = useCallback(
4774
4862
  async (mode) => {
4863
+ if (brokerId) mode = MarginMode.ISOLATED;
4775
4864
  return updateMarginMode({
4776
4865
  symbol_list: [symbol],
4777
4866
  default_margin_mode: mode
4778
4867
  });
4779
4868
  },
4780
- [symbol, updateMarginMode]
4869
+ [brokerId, symbol, updateMarginMode]
4781
4870
  );
4782
4871
  return {
4783
4872
  marginMode,
4784
4873
  isLoading,
4785
4874
  error,
4786
4875
  refresh,
4787
- update
4876
+ update,
4877
+ isPermissionlessListing: !!brokerId
4788
4878
  };
4789
4879
  };
4790
4880
 
@@ -5427,7 +5517,7 @@ var PositionCalculator = class extends BaseCalculator {
5427
5517
  if (!accountInfo || !fundingRates || !symbolsInfo) {
5428
5518
  return data;
5429
5519
  }
5430
- let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero;
5520
+ let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero, totalUnsettledIsolatedPnl = zero, totalUnsettledCrossPnl = zero;
5431
5521
  let rows = data.rows.map((item) => {
5432
5522
  const info = symbolsInfo[item.symbol];
5433
5523
  const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
@@ -5490,6 +5580,12 @@ var PositionCalculator = class extends BaseCalculator {
5490
5580
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
5491
5581
  notional_total = notional_total.add(notional);
5492
5582
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
5583
+ if (item.margin_mode === MarginMode.CROSS) {
5584
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
5585
+ }
5586
+ if (item.margin_mode === MarginMode.ISOLATED) {
5587
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
5588
+ }
5493
5589
  const fundingFee = new Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
5494
5590
  return {
5495
5591
  ...item,
@@ -5505,7 +5601,8 @@ var PositionCalculator = class extends BaseCalculator {
5505
5601
  unrealized_pnl: unrealPnl,
5506
5602
  unrealized_pnl_index: unrealPnl_index,
5507
5603
  unrealized_pnl_ROI: unrealPnlROI,
5508
- unrealized_pnl_ROI_index: unrealPnlROI_index
5604
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
5605
+ unsettled_pnl: unsettlementPnL2
5509
5606
  };
5510
5607
  });
5511
5608
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -5571,6 +5668,8 @@ var PositionCalculator = class extends BaseCalculator {
5571
5668
  total_unsettled_pnl: unsettlementPnL,
5572
5669
  unrealPnlROI: totalUnrealizedROI,
5573
5670
  unrealPnlROI_index: totalUnrealizedROI_index,
5671
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
5672
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
5574
5673
  rows
5575
5674
  };
5576
5675
  }
@@ -5733,13 +5832,9 @@ var PortfolioCalculator = class extends BaseCalculator {
5733
5832
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
5734
5833
  return null;
5735
5834
  }
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
5835
+ const unsettledPnL = pathOr(0, ["total_unsettled_pnl"])(positions3);
5836
+ const unsettledCrossPnL = pathOr(0, ["total_unsettled_cross_pnl"])(
5837
+ positions3
5743
5838
  );
5744
5839
  const unrealizedPnL = pathOr(0, ["total_unreal_pnl"])(positions3);
5745
5840
  const [USDC_holding, nonUSDC] = parseHolding(
@@ -5751,7 +5846,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5751
5846
  const totalCollateral = account.totalCollateral({
5752
5847
  USDCHolding: USDC_holding,
5753
5848
  nonUSDCHolding: nonUSDC,
5754
- unsettlementPnL: totallCrossUnsettledPnL,
5849
+ unsettlementPnL: unsettledCrossPnL,
5755
5850
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
5756
5851
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
5757
5852
  });
@@ -5762,7 +5857,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5762
5857
  return acc.add(curr.margin ?? 0);
5763
5858
  }, zero);
5764
5859
  const totalValue = account.totalValue({
5765
- totalUnsettlementPnL,
5860
+ totalUnsettlementPnL: unsettledPnL,
5766
5861
  USDCHolding: USDC_holding,
5767
5862
  nonUSDCHolding: nonUSDC,
5768
5863
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -5806,7 +5901,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5806
5901
  totalUnrealizedROI,
5807
5902
  freeCollateral,
5808
5903
  availableBalance,
5809
- unsettledPnL: totalUnsettlementPnL,
5904
+ unsettledPnL,
5810
5905
  holding,
5811
5906
  usdcHolding: USDC_holding,
5812
5907
  freeCollateralUSDCOnly
@@ -5925,7 +6020,7 @@ var usePositionStream = (symbol = "all", options) => {
5925
6020
  total_unreal_pnl: total_unreal_pnl_index,
5926
6021
  unrealPnlROI: unrealPnlROI_index
5927
6022
  };
5928
- }, [calcMode]);
6023
+ }, [calcMode, formattedPositions]);
5929
6024
  let rows = formattedPositions[0];
5930
6025
  {
5931
6026
  if (!rows) {
@@ -6415,14 +6510,8 @@ function formatPortfolio(inputs) {
6415
6510
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
6416
6511
  return null;
6417
6512
  }
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
- );
6513
+ const unsettledPnL = pathOr(0, ["total_unsettled_pnl"])(positions3);
6514
+ const unsettledCrossPnL = pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
6426
6515
  const unrealizedPnL = pathOr(0, ["total_unreal_pnl"])(positions3);
6427
6516
  const [USDC_holding, nonUSDC] = parseHolding(
6428
6517
  holding,
@@ -6433,7 +6522,7 @@ function formatPortfolio(inputs) {
6433
6522
  const totalCollateral = account.totalCollateral({
6434
6523
  USDCHolding: USDC_holding,
6435
6524
  nonUSDCHolding: nonUSDC,
6436
- unsettlementPnL: totallCrossUnsettledPnL,
6525
+ unsettlementPnL: unsettledCrossPnL,
6437
6526
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
6438
6527
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
6439
6528
  });
@@ -6444,7 +6533,7 @@ function formatPortfolio(inputs) {
6444
6533
  return acc.add(curr.margin ?? 0);
6445
6534
  }, zero);
6446
6535
  const totalValue = account.totalValue({
6447
- totalUnsettlementPnL,
6536
+ totalUnsettlementPnL: unsettledPnL,
6448
6537
  USDCHolding: USDC_holding,
6449
6538
  nonUSDCHolding: nonUSDC,
6450
6539
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -6488,7 +6577,7 @@ function formatPortfolio(inputs) {
6488
6577
  totalUnrealizedROI,
6489
6578
  freeCollateral,
6490
6579
  availableBalance,
6491
- unsettledPnL: totalUnsettlementPnL,
6580
+ unsettledPnL,
6492
6581
  holding,
6493
6582
  freeCollateralUSDCOnly
6494
6583
  };
@@ -6497,7 +6586,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6497
6586
  if (!accountInfo || !fundingRates || !symbolsInfo) {
6498
6587
  return data;
6499
6588
  }
6500
- let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero;
6589
+ let unrealPnL_total = zero, unrealPnL_total_index = zero, notional_total = zero, unsettlementPnL_total = zero, totalUnsettledIsolatedPnl = zero, totalUnsettledCrossPnl = zero;
6501
6590
  const rows = data.rows.map((item) => {
6502
6591
  const info = symbolsInfo[item.symbol];
6503
6592
  const notional = positions.notional(item.position_qty, item.mark_price);
@@ -6559,6 +6648,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6559
6648
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
6560
6649
  notional_total = notional_total.add(notional);
6561
6650
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
6651
+ if (item.margin_mode === MarginMode.CROSS) {
6652
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
6653
+ }
6654
+ if (item.margin_mode === MarginMode.ISOLATED) {
6655
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
6656
+ }
6562
6657
  return {
6563
6658
  ...item,
6564
6659
  mm: positions.maintenanceMargin({
@@ -6572,7 +6667,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6572
6667
  unrealized_pnl: unrealPnl,
6573
6668
  unrealized_pnl_index: unrealPnl_index,
6574
6669
  unrealized_pnl_ROI: unrealPnlROI,
6575
- unrealized_pnl_ROI_index: unrealPnlROI_index
6670
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
6671
+ unsettled_pnl: unsettlementPnL2
6576
6672
  };
6577
6673
  });
6578
6674
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -6586,6 +6682,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6586
6682
  notional: notional_total.toNumber(),
6587
6683
  unsettledPnL: unsettlementPnL,
6588
6684
  total_unsettled_pnl: unsettlementPnL,
6685
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
6686
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
6589
6687
  rows
6590
6688
  };
6591
6689
  }
@@ -12678,6 +12776,9 @@ var DataPaint = class extends BasePaint {
12678
12776
  this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
12679
12777
  this.transformTop = 0;
12680
12778
  this.QRCODE_SIZE = 56;
12779
+ this.BROKER_BADGE_HEIGHT = 18;
12780
+ this.BROKER_BADGE_PADDING_X = 8;
12781
+ this.BROKER_BADGE_RADIUS = 4;
12681
12782
  }
12682
12783
  formatMarginMode(marginMode) {
12683
12784
  return marginMode === MarginMode.ISOLATED ? "Isolated" : "Cross";
@@ -12767,6 +12868,49 @@ var DataPaint = class extends BasePaint {
12767
12868
  fontSize: this._ratio(fontSize),
12768
12869
  fontFamily: options.fontFamily
12769
12870
  });
12871
+ const brokerName = options.data?.position.brokerName?.trim();
12872
+ if (brokerName) {
12873
+ left += (prevElementBoundingBox.width ?? 0) + this._ratio(10);
12874
+ const badgeHeight = this._ratio(this.BROKER_BADGE_HEIGHT);
12875
+ const badgePaddingX = this._ratio(this.BROKER_BADGE_PADDING_X);
12876
+ const badgeRadius = this._ratio(this.BROKER_BADGE_RADIUS);
12877
+ const badgeFontSize = this._ratio(12);
12878
+ const badgeFontWeight = 600;
12879
+ const textMetrics = this._drawText(
12880
+ brokerName,
12881
+ {
12882
+ left: 0,
12883
+ top: 0,
12884
+ fontSize: badgeFontSize,
12885
+ fontWeight: badgeFontWeight,
12886
+ fontFamily: options.fontFamily
12887
+ },
12888
+ true
12889
+ );
12890
+ const badgeWidth = (textMetrics.width ?? 0) + badgePaddingX * 2;
12891
+ const badgeTop = this._ratio(top) - badgeHeight / 2;
12892
+ this._fillRoundedRect(
12893
+ left,
12894
+ badgeTop,
12895
+ badgeWidth,
12896
+ badgeHeight,
12897
+ badgeRadius,
12898
+ "rgba(255,255,255,0.06)"
12899
+ );
12900
+ this._drawText(brokerName, {
12901
+ color: "rgba(255,255,255,0.36)",
12902
+ left: left + badgePaddingX,
12903
+ top: badgeTop + badgeHeight / 2,
12904
+ fontSize: badgeFontSize,
12905
+ fontWeight: badgeFontWeight,
12906
+ fontFamily: options.fontFamily,
12907
+ textBaseline: "middle"
12908
+ });
12909
+ prevElementBoundingBox = {
12910
+ ...prevElementBoundingBox,
12911
+ width: badgeWidth
12912
+ };
12913
+ }
12770
12914
  }
12771
12915
  const marginMode = options.data?.position.marginMode;
12772
12916
  if (marginMode) {
@@ -12814,6 +12958,20 @@ var DataPaint = class extends BasePaint {
12814
12958
  );
12815
12959
  }
12816
12960
  }
12961
+ _fillRoundedRect(x, y, width, height, radius, color) {
12962
+ const r = Math.min(radius, width / 2, height / 2);
12963
+ this.ctx.save();
12964
+ this.ctx.fillStyle = color;
12965
+ this.ctx.beginPath();
12966
+ this.ctx.moveTo(x + r, y);
12967
+ this.ctx.arcTo(x + width, y, x + width, y + height, r);
12968
+ this.ctx.arcTo(x + width, y + height, x, y + height, r);
12969
+ this.ctx.arcTo(x, y + height, x, y, r);
12970
+ this.ctx.arcTo(x, y, x + width, y, r);
12971
+ this.ctx.closePath();
12972
+ this.ctx.fill();
12973
+ this.ctx.restore();
12974
+ }
12817
12975
  drawUnrealizedPnL(options, offsetTop = 0) {
12818
12976
  const layout = path(
12819
12977
  ["layout", "unrealizedPnl"],
@@ -13267,18 +13425,6 @@ var useEpochInfo = (type) => {
13267
13425
  }, [epochInfo]);
13268
13426
  return [epochInfo, { isLoading, curEpochInfo, isNotStared, refresh }];
13269
13427
  };
13270
-
13271
- // src/trading-rewards/useAllBrokers.ts
13272
- var useAllBrokers = () => {
13273
- const { data } = useQuery("/v1/public/broker/name", {
13274
- formatter: (res) => {
13275
- const { rows } = res;
13276
- return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
13277
- },
13278
- revalidateOnFocus: false
13279
- });
13280
- return [data];
13281
- };
13282
13428
  var useCurEpochEstimate = (type) => {
13283
13429
  const [data, setData] = useState(void 0);
13284
13430
  const { account: account9 } = useAccount();
@@ -18634,6 +18780,19 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18634
18780
  orderEntryActions.updateOrder(newValues);
18635
18781
  return newValues;
18636
18782
  };
18783
+ const setValuesRaw = (values) => {
18784
+ if (!symbolInfo) {
18785
+ orderEntryActions.updateOrder(values);
18786
+ return;
18787
+ }
18788
+ const currentEntry = useOrderStore.getState().entry;
18789
+ const newValues = {
18790
+ ...currentEntry,
18791
+ ...values
18792
+ };
18793
+ orderEntryActions.updateOrder(newValues);
18794
+ return newValues;
18795
+ };
18637
18796
  const onMarkPriceUpdated = useCallback(
18638
18797
  (markPrice, baseOn = []) => {
18639
18798
  if (!options.symbolInfo) return;
@@ -18697,6 +18856,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18697
18856
  formattedOrder: orderEntity,
18698
18857
  setValue,
18699
18858
  setValues,
18859
+ setValuesRaw,
18700
18860
  submit: submitOrder,
18701
18861
  reset: resetOrder,
18702
18862
  generateOrder,
@@ -18712,6 +18872,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
18712
18872
  }
18713
18873
  const ee = useEventEmitter();
18714
18874
  const { track: track2 } = useTrack();
18875
+ const apiBaseUrl = useConfig("apiBaseUrl");
18876
+ const fetchSymbols = useSymbolStore((state) => state.fetchData);
18715
18877
  const [meta, setMeta] = useState({
18716
18878
  dirty: {},
18717
18879
  submitted: false,
@@ -18741,6 +18903,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18741
18903
  formattedOrder,
18742
18904
  setValue: setValueInternal,
18743
18905
  setValues: setValuesInternal,
18906
+ setValuesRaw: setValuesRawInternal,
18744
18907
  validate,
18745
18908
  generateOrder,
18746
18909
  reset,
@@ -18940,6 +19103,21 @@ var useOrderEntry2 = (symbol, options = {}) => {
18940
19103
  interactiveValidate(newValues);
18941
19104
  }
18942
19105
  };
19106
+ const setValuesRaw = (values) => {
19107
+ if (!Object.keys(values).every(
19108
+ (key) => canSetTPSLPrice(
19109
+ key,
19110
+ values[key],
19111
+ formattedOrder.order_type
19112
+ )
19113
+ )) {
19114
+ return;
19115
+ }
19116
+ const newValues = setValuesRawInternal(values);
19117
+ if (newValues) {
19118
+ interactiveValidate(newValues);
19119
+ }
19120
+ };
18943
19121
  async function validateFunc(order) {
18944
19122
  const creator = getOrderCreator(order);
18945
19123
  return validate(order, creator, prepareData());
@@ -18994,7 +19172,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18994
19172
  markPrice: markPrice2,
18995
19173
  totalCollateral,
18996
19174
  futures_taker_fee_rate: accountInfo.futures_taker_fee_rate,
18997
- imr_factor: accountInfo.imr_factor[symbol],
19175
+ imr_factor: accountInfo.imr_factor?.[symbol] ?? 0,
18998
19176
  symbol,
18999
19177
  positions: positions3,
19000
19178
  symbolInfo,
@@ -19083,6 +19261,9 @@ var useOrderEntry2 = (symbol, options = {}) => {
19083
19261
  orders: appendOrderMetadata(order.orders, orderMetadata)
19084
19262
  } : appendOrderMetadata(order, orderMetadata);
19085
19263
  const result = await doCreateOrder(params);
19264
+ if (!result.success && (order.order_type === OrderType.MARKET || order.order_type === OrderType.STOP_MARKET)) {
19265
+ void fetchSymbols(apiBaseUrl);
19266
+ }
19086
19267
  if (result.success) {
19087
19268
  let trackParams = {
19088
19269
  side: order.side,
@@ -19149,6 +19330,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
19149
19330
  freeCollateral: effectiveMarginMode === MarginMode.ISOLATED ? freeCollateralUSDCOnly : freeCollateral,
19150
19331
  setValue: useMemoizedFn(setValue),
19151
19332
  setValues: useMemoizedFn(setValues),
19333
+ setValuesRaw: useMemoizedFn(setValuesRaw),
19152
19334
  symbolInfo: symbolInfo || EMPTY_OBJECT,
19153
19335
  metaState: meta,
19154
19336
  isMutating,
@@ -19605,6 +19787,6 @@ var FlagKeys = /* @__PURE__ */ ((FlagKeys2) => {
19605
19787
  return FlagKeys2;
19606
19788
  })(FlagKeys || {});
19607
19789
 
19608
- export { DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ERROR_MSG_CODES, EpochStatus, ExtendedConfigStore, FlagKeys, MaintenanceStatus, MarketsStorageKey, MarketsType, ORDERLY_ORDERBOOK_DEPTH_KEY, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAppStore, useAssetsHistory, useAudioPlayer, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEstLiqPriceBySymbol, useEventEmitter, useFeatureFlag, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetEstLiqPrice, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMainTokenStore, useMainnetChainsStore, useMaintenanceStatus, useMarginModeBySymbol, useMarginModes, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePositions, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountAlgoOrderStream, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSwapSupportStore, useSymbolInfo, useSymbolLeverage, useSymbolLeverageMap, useSymbolPriceRange, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTestTokenStore, useTestnetChainsStore, useTickerStream, useTokenInfo, useTokensInfo, useTpslPriceChecker, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useUserStatistics, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
19790
+ export { DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ERROR_MSG_CODES, EpochStatus, ExtendedConfigStore, FlagKeys, MaintenanceStatus, MarketCategoriesConfigProvider, MarketsStorageKey, MarketsType, ORDERLY_ORDERBOOK_DEPTH_KEY, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, formatSymbolWithBroker, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAppStore, useAssetsHistory, useAudioPlayer, useBadgeBySymbol, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEstLiqPriceBySymbol, useEventEmitter, useFeatureFlag, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetEstLiqPrice, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMainTokenStore, useMainnetChainsStore, useMaintenanceStatus, useMarginModeBySymbol, useMarginModes, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketCategoriesConfig, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePositions, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountAlgoOrderStream, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSwapSupportStore, useSymbolInfo, useSymbolLeverage, useSymbolLeverageMap, useSymbolPriceRange, useSymbolWithBroker, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTestTokenStore, useTestnetChainsStore, useTickerStream, useTokenInfo, useTokensInfo, useTpslPriceChecker, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useUserStatistics, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
19609
19791
  //# sourceMappingURL=index.mjs.map
19610
19792
  //# sourceMappingURL=index.mjs.map