@orderly.network/hooks 3.0.0-beta.0 → 3.0.0-beta.10

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,10 +1,10 @@
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
- var types = require('@orderly.network/types');
7
6
  var pluginCore = require('@orderly.network/plugin-core');
7
+ var types = require('@orderly.network/types');
8
8
  var utils = require('@orderly.network/utils');
9
9
  var useSWRMutation = require('swr/mutation');
10
10
  var useConstant = require('use-constant');
@@ -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.0";
79
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.10";
69
80
  }
70
- var version_default = "3.0.0-beta.0";
81
+ var version_default = "3.0.0-beta.10";
71
82
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
72
83
  var noCacheConfig = {
73
84
  dedupingInterval: 0,
@@ -98,6 +109,8 @@ function useConfig(key, defaultValue) {
98
109
  }
99
110
  return configStore;
100
111
  }
112
+
113
+ // src/useQuery.ts
101
114
  var PLUGIN_ID_HEADER = "X-Orderly-Plugin-Id";
102
115
  var useQuery = (query, options) => {
103
116
  const apiBaseUrl = useConfig("apiBaseUrl");
@@ -594,6 +607,20 @@ var useAudioPlayer = (src, options = {}) => {
594
607
  const el = getOrderFilledAudio();
595
608
  el.volume = Math.max(0, Math.min(1, volume));
596
609
  }, [volume]);
610
+ React.useEffect(() => {
611
+ const handleVisibilityChange = () => {
612
+ if (document.visibilityState === "visible") {
613
+ const el = getOrderFilledAudio();
614
+ el.pause();
615
+ el.removeAttribute("src");
616
+ el.load();
617
+ }
618
+ };
619
+ document.addEventListener("visibilitychange", handleVisibilityChange);
620
+ return () => {
621
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
622
+ };
623
+ }, []);
597
624
  const play = React.useCallback(() => {
598
625
  const currentSrc = srcRef.current;
599
626
  const currentEnabled = enabledRef.current;
@@ -1303,7 +1330,7 @@ function checkTPSLOrderTypeIsMarket(key, values) {
1303
1330
  }
1304
1331
  function tpslCalculateHelper(key, inputs, options = {}) {
1305
1332
  const { symbol } = options;
1306
- if (key !== "quantity" && key !== "tp_trigger_price" && key !== "sl_trigger_price" && key !== "tp_pnl" && key !== "sl_pnl" && key !== "tp_offset" && key !== "sl_offset" && key !== "tp_offset_percentage" && key !== "sl_offset_percentage" && key !== "tp_order_price" && key !== "sl_order_price" && key !== "tp_order_type" && key !== "sl_order_type") {
1333
+ if (key !== "quantity" && key !== "tp_trigger_price" && key !== "sl_trigger_price" && key !== "tp_pnl" && key !== "sl_pnl" && key !== "tp_offset" && key !== "sl_offset" && key !== "tp_offset_percentage" && key !== "sl_offset_percentage" && key !== "tp_offset_from_mark" && key !== "sl_offset_from_mark" && key !== "tp_offset_percentage_from_mark" && key !== "sl_offset_percentage_from_mark" && key !== "tp_order_price" && key !== "sl_order_price" && key !== "tp_order_type" && key !== "sl_order_type") {
1307
1334
  return {
1308
1335
  [key]: inputs.value
1309
1336
  };
@@ -1311,6 +1338,7 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1311
1338
  const orderType = key.startsWith("tp_") ? types.AlgoOrderType.TAKE_PROFIT : types.AlgoOrderType.STOP_LOSS;
1312
1339
  const keyPrefix = key.slice(0, 3);
1313
1340
  const qty = Number(key === "quantity" ? inputs.value : inputs.qty);
1341
+ const markPrice = inputs.markPrice ?? inputs.entryPrice;
1314
1342
  if (qty === 0 && (key === "tp_pnl" || key === "sl_pnl" || key === "tp_trigger_price" || key === "sl_trigger_price")) {
1315
1343
  return {
1316
1344
  // [`${keyPrefix}trigger_price`]: "",
@@ -1321,7 +1349,7 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1321
1349
  [key]: inputs.value
1322
1350
  };
1323
1351
  }
1324
- let trigger_price, offset, offset_percentage, pnl, order_price, tpsl_order_type = inputs.values[`${keyPrefix}order_type`] ?? types.OrderType.MARKET;
1352
+ let trigger_price, offset, offset_percentage, offset_from_mark, offset_percentage_from_mark, pnl, order_price, tpsl_order_type = inputs.values[`${keyPrefix}order_type`] ?? types.OrderType.MARKET;
1325
1353
  const entryPrice = new utils.Decimal(inputs.entryPrice).todp(options.symbol?.quote_dp ?? 2, utils.Decimal.ROUND_UP).toNumber();
1326
1354
  switch (key) {
1327
1355
  case "tp_trigger_price":
@@ -1333,6 +1361,8 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1333
1361
  [`${keyPrefix}trigger_price`]: trigger_price,
1334
1362
  [`${keyPrefix}offset`]: "",
1335
1363
  [`${keyPrefix}offset_percentage`]: "",
1364
+ [`${keyPrefix}offset_from_mark`]: "",
1365
+ [`${keyPrefix}offset_percentage_from_mark`]: "",
1336
1366
  [`${keyPrefix}pnl`]: "",
1337
1367
  [`${keyPrefix}ROI`]: ""
1338
1368
  };
@@ -1342,31 +1372,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1342
1372
  }
1343
1373
  break;
1344
1374
  }
1345
- // case "tp_enable":
1346
- // case "sl_enable": {
1347
- // return {
1348
- // [`${keyPrefix}enable`]: inputs.value,
1349
- // [`${keyPrefix}order_type`]: OrderType.MARKET,
1350
- // [`${keyPrefix}trigger_price`]: "",
1351
- // [`${keyPrefix}order_price`]: "",
1352
- // [`${keyPrefix}offset`]: "",
1353
- // [`${keyPrefix}offset_percentage`]: "",
1354
- // [`${keyPrefix}pnl`]: "",
1355
- // [`${keyPrefix}ROI`]: "",
1356
- // };
1357
- // }
1358
- // case 'tp_pnl':{
1359
- // if (inputs.values.tp_order_type !== OrderType.MARKET) {
1360
- // pnl = inputs.value;
1361
- // trigger_price = pnlToPrice({
1362
- // qty,
1363
- // pnl: Number(inputs.value),
1364
- // entryPrice,
1365
- // orderSide: inputs.orderSide,
1366
- // orderType,
1367
- // })
1368
- // }
1369
- // }
1370
1375
  case "tp_pnl":
1371
1376
  case "sl_pnl": {
1372
1377
  pnl = inputs.value;
@@ -1413,6 +1418,30 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1413
1418
  }
1414
1419
  break;
1415
1420
  }
1421
+ case "tp_offset_from_mark":
1422
+ case "sl_offset_from_mark": {
1423
+ offset_from_mark = inputs.value;
1424
+ if (!checkTPSLOrderTypeIsMarket(key, inputs.values)) {
1425
+ order_price = offsetToPrice({
1426
+ qty,
1427
+ offset: Number(inputs.value),
1428
+ entryPrice: markPrice,
1429
+ orderSide: inputs.orderSide,
1430
+ orderType: key === "tp_offset_from_mark" ? types.AlgoOrderType.TAKE_PROFIT : types.AlgoOrderType.STOP_LOSS
1431
+ });
1432
+ trigger_price = inputs.values[`${keyPrefix}trigger_price`] ?? order_price;
1433
+ } else {
1434
+ trigger_price = offsetToPrice({
1435
+ qty,
1436
+ offset: Number(inputs.value),
1437
+ // entryPrice,
1438
+ entryPrice: markPrice,
1439
+ orderSide: inputs.orderSide,
1440
+ orderType: key === "tp_offset_from_mark" ? types.AlgoOrderType.TAKE_PROFIT : types.AlgoOrderType.STOP_LOSS
1441
+ });
1442
+ }
1443
+ break;
1444
+ }
1416
1445
  case "tp_order_price":
1417
1446
  case "sl_order_price": {
1418
1447
  order_price = inputs.value;
@@ -1453,12 +1482,38 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1453
1482
  }
1454
1483
  break;
1455
1484
  }
1485
+ case "tp_offset_percentage_from_mark":
1486
+ case "sl_offset_percentage_from_mark": {
1487
+ offset_percentage_from_mark = inputs.value;
1488
+ const markBase = Number(markPrice);
1489
+ if (!checkTPSLOrderTypeIsMarket(key, inputs.values)) {
1490
+ order_price = offsetPercentageToPrice({
1491
+ qty,
1492
+ percentage: Number(`${inputs.value}`.replace(/\.0{0,2}$/, "")),
1493
+ entryPrice: markBase,
1494
+ orderSide: inputs.orderSide,
1495
+ orderType
1496
+ });
1497
+ trigger_price = inputs.values[`${keyPrefix}trigger_price`] ?? order_price;
1498
+ } else {
1499
+ trigger_price = offsetPercentageToPrice({
1500
+ qty,
1501
+ percentage: Number(`${inputs.value}`.replace(/\.0{0,2}$/, "")),
1502
+ entryPrice: markBase,
1503
+ orderSide: inputs.orderSide,
1504
+ orderType
1505
+ });
1506
+ }
1507
+ break;
1508
+ }
1456
1509
  }
1457
1510
  if (!trigger_price && checkTPSLOrderTypeIsMarket(key, inputs.values)) {
1458
1511
  return {
1459
1512
  [`${keyPrefix}trigger_price`]: "",
1460
1513
  [`${keyPrefix}offset`]: "",
1461
1514
  [`${keyPrefix}offset_percentage`]: "",
1515
+ [`${keyPrefix}offset_from_mark`]: "",
1516
+ [`${keyPrefix}offset_percentage_from_mark`]: "",
1462
1517
  [`${keyPrefix}pnl`]: "",
1463
1518
  [`${keyPrefix}ROI`]: "",
1464
1519
  [key]: inputs.value
@@ -1503,6 +1558,8 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1503
1558
  [`${keyPrefix}order_price`]: order_price ? utils.todpIfNeed(order_price, symbol?.quote_dp ?? 2) : "",
1504
1559
  [`${keyPrefix}offset`]: offset ?? "",
1505
1560
  [`${keyPrefix}offset_percentage`]: offset_percentage ?? "",
1561
+ [`${keyPrefix}offset_from_mark`]: offset_from_mark ?? inputs.values[`${keyPrefix}offset_from_mark`] ?? "",
1562
+ [`${keyPrefix}offset_percentage_from_mark`]: offset_percentage_from_mark ?? inputs.values[`${keyPrefix}offset_percentage_from_mark`] ?? "",
1506
1563
  [`${keyPrefix}pnl`]: pnl ?? ""
1507
1564
  // [`${keyPrefix}ROI`]: calcROI({
1508
1565
  // pnl: Number(pnl ?? 0),
@@ -1690,6 +1747,7 @@ function tpslInputHandle(inputs) {
1690
1747
  // order price or mark price
1691
1748
  qty: values.side === types.OrderSide.BUY ? Number(values.order_quantity) : Number(values.order_quantity) * -1,
1692
1749
  orderSide: values.side,
1750
+ markPrice,
1693
1751
  // values: newValues,
1694
1752
  values
1695
1753
  },
@@ -1725,6 +1783,10 @@ var getCalculateHandler = (fieldName) => {
1725
1783
  case "sl_offset":
1726
1784
  case "tp_offset_percentage":
1727
1785
  case "sl_offset_percentage":
1786
+ case "tp_offset_from_mark":
1787
+ case "sl_offset_from_mark":
1788
+ case "tp_offset_percentage_from_mark":
1789
+ case "sl_offset_percentage_from_mark":
1728
1790
  case "tp_order_price":
1729
1791
  case "tp_order_type":
1730
1792
  case "sl_order_type":
@@ -2608,16 +2670,12 @@ var createDataStore = (config) => {
2608
2670
  const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
2609
2671
  const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
2610
2672
  const data = await fetcher(url, {}, { formatter });
2611
- const dataWithBrokerId = data.map((item) => ({
2612
- ...item,
2613
- broker_id: options?.brokerId
2614
- }));
2615
2673
  set({
2616
- data: dataWithBrokerId,
2674
+ data,
2617
2675
  loading: false,
2618
2676
  error: null
2619
2677
  });
2620
- return dataWithBrokerId;
2678
+ return data;
2621
2679
  } catch (error) {
2622
2680
  set({ error, loading: false });
2623
2681
  return null;
@@ -3153,7 +3211,9 @@ var DEFAULT_SYMBOL_DEPTHS = {
3153
3211
  };
3154
3212
  var DEFAULT_SYMBOL_DISPLAY_NAMES = {
3155
3213
  PERP_XAU_USDC: "XAU (Gold) ",
3156
- PERP_XAG_USDC: "XAG (Silver)"
3214
+ PERP_XAG_USDC: "XAG (Silver)",
3215
+ PERP_CL_USDC: "CL (WTI Crude Oil)",
3216
+ PERP_BZ_USDC: "BZ (Brent Crude Oil)"
3157
3217
  };
3158
3218
  var ProxyConfigStore = class {
3159
3219
  constructor(_originConfigStore) {
@@ -3436,7 +3496,10 @@ var useGetRwaSymbolOpenTimeInterval = (symbol, thresholdMinutes = 30) => {
3436
3496
  };
3437
3497
  var useSymbolsInfo = () => {
3438
3498
  const symbolsInfo = useAppStore((state) => state.symbolsInfo);
3439
- return React.useMemo(() => createGetter({ ...symbolsInfo }), [symbolsInfo]);
3499
+ return React.useMemo(
3500
+ () => createGetter(symbolsInfo ? { ...symbolsInfo } : symbolsInfo),
3501
+ [symbolsInfo]
3502
+ );
3440
3503
  };
3441
3504
  var useSymbolsInfoStore = () => {
3442
3505
  return useAppStore((state) => state.symbolsInfo);
@@ -3449,6 +3512,7 @@ var MarketsType = /* @__PURE__ */ ((MarketsType2) => {
3449
3512
  MarketsType2[MarketsType2["ALL"] = 2] = "ALL";
3450
3513
  MarketsType2[MarketsType2["RWA"] = 3] = "RWA";
3451
3514
  MarketsType2[MarketsType2["NEW_LISTING"] = 4] = "NEW_LISTING";
3515
+ MarketsType2[MarketsType2["COMMUNITY"] = 5] = "COMMUNITY";
3452
3516
  return MarketsType2;
3453
3517
  })(MarketsType || {});
3454
3518
  var MarketsStorageKey = "orderly_markets";
@@ -3618,6 +3682,8 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3618
3682
  const rwaInfo = !rwaSymbolsInfo.isNil ? rwaSymbolsInfo[item.symbol]() : null;
3619
3683
  return {
3620
3684
  ...item,
3685
+ broker_id: item.broker_id,
3686
+ display_symbol_name: item.display_symbol_name,
3621
3687
  quote_dp: info("quote_dp"),
3622
3688
  created_time: info("created_time"),
3623
3689
  displayName: info("displayName"),
@@ -3639,7 +3705,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3639
3705
  var filterMarkets = (params) => {
3640
3706
  const { markets, favorites, recent, newListing, type } = params;
3641
3707
  let curData = [];
3642
- if (type === 2 /* ALL */) {
3708
+ if (type === 2 /* ALL */ || type === 5 /* COMMUNITY */) {
3643
3709
  curData = markets;
3644
3710
  } else if (type === 3 /* RWA */) {
3645
3711
  curData = markets.filter((item) => item.isRwa);
@@ -4561,7 +4627,7 @@ var useMarket = (type) => {
4561
4627
  const getData = (type2) => {
4562
4628
  const localData = type2 === 0 /* FAVORITES */ ? [...favorites] : [...recent];
4563
4629
  const keys = localData.map((item) => item.name);
4564
- const filter = type2 == 2 /* ALL */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
4630
+ const filter = type2 == 2 /* ALL */ || type2 == 4 /* COMMUNITY */ ? marketsList : marketsList?.filter((item) => keys.includes(item.symbol));
4565
4631
  const favoritesData = [...favorites];
4566
4632
  const favoriteKeys = favoritesData.map((item) => item.name);
4567
4633
  if (filter) {
@@ -4760,6 +4826,80 @@ var useSymbolLeverageMap = () => {
4760
4826
  refresh: mutate6
4761
4827
  };
4762
4828
  };
4829
+
4830
+ // src/trading-rewards/useAllBrokers.ts
4831
+ var useAllBrokers = () => {
4832
+ const { data } = useQuery("/v1/public/broker/name", {
4833
+ formatter: (res) => {
4834
+ const { rows } = res;
4835
+ return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
4836
+ },
4837
+ revalidateOnFocus: false
4838
+ });
4839
+ return [data];
4840
+ };
4841
+
4842
+ // src/useBadgeBySymbol.ts
4843
+ function brokerNameBaseFromRaw(rawBrokerName) {
4844
+ if (!rawBrokerName) return void 0;
4845
+ const first = rawBrokerName.trim().split(/[ _-]/, 1)[0]?.trim() ?? "";
4846
+ return first.length > 0 ? first : void 0;
4847
+ }
4848
+ var useBadgeBySymbol = (symbol) => {
4849
+ const symbolsInfo = useSymbolsInfo();
4850
+ const [brokers] = useAllBrokers();
4851
+ return React.useMemo(() => {
4852
+ if (!symbol || symbolsInfo.isNil) {
4853
+ return {
4854
+ displayName: symbol ?? "",
4855
+ brokerId: void 0,
4856
+ brokerName: void 0,
4857
+ brokerNameRaw: void 0
4858
+ };
4859
+ }
4860
+ const getter = symbolsInfo[symbol];
4861
+ const info = typeof getter === "function" ? getter() : void 0;
4862
+ const displayName = info?.displayName ?? info?.display_symbol_name ?? symbol;
4863
+ const brokerId = info?.broker_id ?? void 0;
4864
+ const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
4865
+ const base = brokerNameBaseFromRaw(rawBrokerName);
4866
+ const brokerName = base ? base.length > 7 ? `${base.slice(0, 7)}...` : base : void 0;
4867
+ return {
4868
+ displayName,
4869
+ brokerId,
4870
+ brokerName,
4871
+ brokerNameRaw: rawBrokerName
4872
+ };
4873
+ }, [brokers, symbolsInfo, symbol]);
4874
+ };
4875
+ function formatSymbolWithBroker(symbol, symbolsInfo, brokers) {
4876
+ if (!symbol) return "";
4877
+ let brokerNameBase;
4878
+ if (!symbolsInfo.isNil) {
4879
+ const getter = symbolsInfo[symbol];
4880
+ const info = typeof getter === "function" ? getter() : void 0;
4881
+ const brokerId = info?.broker_id ?? void 0;
4882
+ const rawBrokerName = brokerId ? brokers?.[brokerId] : void 0;
4883
+ brokerNameBase = brokerNameBaseFromRaw(rawBrokerName);
4884
+ }
4885
+ const parts = symbol.split("_");
4886
+ const base = parts.length >= 3 ? parts[1] ?? "" : symbol.match(/^([A-Za-z]+)/)?.[1] ?? symbol;
4887
+ const hasBrokerSuffix = symbol.includes("-") || symbol.split("_").length > 3;
4888
+ if (brokerNameBase && hasBrokerSuffix) {
4889
+ return `${base}-${brokerNameBase}`;
4890
+ }
4891
+ return base;
4892
+ }
4893
+ var useSymbolWithBroker = (symbol) => {
4894
+ const symbolsInfo = useSymbolsInfo();
4895
+ const [brokers] = useAllBrokers();
4896
+ return React.useMemo(
4897
+ () => formatSymbolWithBroker(symbol, symbolsInfo, brokers),
4898
+ [brokers, symbolsInfo, symbol]
4899
+ );
4900
+ };
4901
+
4902
+ // src/orderly/useMarginModes.ts
4763
4903
  var useMarginModes = () => {
4764
4904
  const { data, error, isLoading, mutate: mutate6 } = usePrivateQuery("/v1/client/margin_modes", {
4765
4905
  revalidateOnFocus: false,
@@ -4801,22 +4941,28 @@ var useMarginModes = () => {
4801
4941
  };
4802
4942
  var useMarginModeBySymbol = (symbol, fallback = types.MarginMode.CROSS) => {
4803
4943
  const { marginModes, isLoading, error, refresh, updateMarginMode } = useMarginModes();
4804
- const marginMode = fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
4944
+ const { brokerId } = useBadgeBySymbol(symbol);
4945
+ const marginMode = React.useMemo(() => {
4946
+ if (brokerId) return types.MarginMode.ISOLATED;
4947
+ return fallback === null ? marginModes[symbol] : marginModes[symbol] ?? fallback;
4948
+ }, [brokerId, fallback, marginModes, symbol]);
4805
4949
  const update = React.useCallback(
4806
4950
  async (mode) => {
4951
+ if (brokerId) mode = types.MarginMode.ISOLATED;
4807
4952
  return updateMarginMode({
4808
4953
  symbol_list: [symbol],
4809
4954
  default_margin_mode: mode
4810
4955
  });
4811
4956
  },
4812
- [symbol, updateMarginMode]
4957
+ [brokerId, symbol, updateMarginMode]
4813
4958
  );
4814
4959
  return {
4815
4960
  marginMode,
4816
4961
  isLoading,
4817
4962
  error,
4818
4963
  refresh,
4819
- update
4964
+ update,
4965
+ isPermissionlessListing: !!brokerId
4820
4966
  };
4821
4967
  };
4822
4968
 
@@ -5055,6 +5201,11 @@ var MarkPriceCalculator = class extends BaseCalculator {
5055
5201
 
5056
5202
  // src/orderly/calculator/calculatorContext.ts
5057
5203
  var CalculatorContext = class _CalculatorContext {
5204
+ // holding: API.Holding[];
5205
+ // portfolio — dynamic getter to always read the latest output from PortfolioCalculator
5206
+ get portfolio() {
5207
+ return this.output["portfolio"] || useAppStore.getState().portfolio;
5208
+ }
5058
5209
  static get instance() {
5059
5210
  return this._instance;
5060
5211
  }
@@ -5073,7 +5224,6 @@ var CalculatorContext = class _CalculatorContext {
5073
5224
  update(scope, data) {
5074
5225
  this.setCtxData();
5075
5226
  this.markPrices = scope === "markPrice" /* MARK_PRICE */ ? data : this.output[MarketCalculatorName];
5076
- this.portfolio = this.output["portfolio"] || useAppStore.getState().portfolio;
5077
5227
  return this;
5078
5228
  }
5079
5229
  setCtxData() {
@@ -5091,7 +5241,6 @@ var CalculatorContext = class _CalculatorContext {
5091
5241
  clearCache() {
5092
5242
  this.output = {};
5093
5243
  this.accountInfo = void 0;
5094
- this.portfolio = void 0;
5095
5244
  }
5096
5245
  deleteByName(name) {
5097
5246
  delete this.output[name];
@@ -5459,7 +5608,7 @@ var PositionCalculator = class extends BaseCalculator {
5459
5608
  if (!accountInfo || !fundingRates || !symbolsInfo) {
5460
5609
  return data;
5461
5610
  }
5462
- let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
5611
+ let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
5463
5612
  let rows = data.rows.map((item) => {
5464
5613
  const info = symbolsInfo[item.symbol];
5465
5614
  const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
@@ -5522,6 +5671,12 @@ var PositionCalculator = class extends BaseCalculator {
5522
5671
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
5523
5672
  notional_total = notional_total.add(notional);
5524
5673
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
5674
+ if (item.margin_mode === types.MarginMode.CROSS) {
5675
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
5676
+ }
5677
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
5678
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
5679
+ }
5525
5680
  const fundingFee = new utils.Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
5526
5681
  return {
5527
5682
  ...item,
@@ -5537,7 +5692,8 @@ var PositionCalculator = class extends BaseCalculator {
5537
5692
  unrealized_pnl: unrealPnl,
5538
5693
  unrealized_pnl_index: unrealPnl_index,
5539
5694
  unrealized_pnl_ROI: unrealPnlROI,
5540
- unrealized_pnl_ROI_index: unrealPnlROI_index
5695
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
5696
+ unsettled_pnl: unsettlementPnL2
5541
5697
  };
5542
5698
  });
5543
5699
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -5549,18 +5705,34 @@ var PositionCalculator = class extends BaseCalculator {
5549
5705
  rows = rows.map((item) => {
5550
5706
  const info = symbolsInfo[item.symbol];
5551
5707
  const totalCollateral = item.margin_mode === types.MarginMode.ISOLATED ? new utils.Decimal(item.margin ?? 0).add(item.unsettlement_pnl ?? 0).toNumber() : crossMarginCollateral.toNumber();
5552
- const est_liq_price = perp.positions.liqPrice({
5553
- symbol: item.symbol,
5554
- markPrice: item.mark_price,
5555
- totalCollateral,
5556
- positionQty: item.position_qty,
5557
- positions: rows,
5558
- MMR: item.mmr,
5559
- baseMMR: info?.["base_mmr"],
5560
- baseIMR: info?.["base_imr"],
5561
- IMRFactor: accountInfo.imr_factor[item.symbol],
5562
- costPosition: item.cost_position
5563
- });
5708
+ let est_liq_price;
5709
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
5710
+ est_liq_price = perp.positions.liquidationPriceIsolated({
5711
+ isolatedPositionMargin: item.margin ?? 0,
5712
+ costPosition: item.cost_position ?? 0,
5713
+ positionQty: item.position_qty ?? 0,
5714
+ sumUnitaryFunding: fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0,
5715
+ lastSumUnitaryFunding: item.last_sum_unitary_funding ?? 0,
5716
+ baseMMR: info?.["base_mmr"] ?? 0,
5717
+ baseIMR: info?.["base_imr"] ?? 0,
5718
+ IMRFactor: accountInfo.imr_factor[item.symbol],
5719
+ referencePrice: item.mark_price,
5720
+ leverage: item.leverage ?? 0
5721
+ });
5722
+ } else {
5723
+ est_liq_price = perp.positions.liqPrice({
5724
+ symbol: item.symbol,
5725
+ markPrice: item.mark_price,
5726
+ totalCollateral,
5727
+ positionQty: item.position_qty,
5728
+ positions: rows,
5729
+ MMR: item.mmr,
5730
+ baseMMR: info?.["base_mmr"],
5731
+ baseIMR: info?.["base_imr"],
5732
+ IMRFactor: accountInfo.imr_factor[item.symbol],
5733
+ costPosition: item.cost_position
5734
+ });
5735
+ }
5564
5736
  return {
5565
5737
  ...item,
5566
5738
  est_liq_price
@@ -5587,6 +5759,8 @@ var PositionCalculator = class extends BaseCalculator {
5587
5759
  total_unsettled_pnl: unsettlementPnL,
5588
5760
  unrealPnlROI: totalUnrealizedROI,
5589
5761
  unrealPnlROI_index: totalUnrealizedROI_index,
5762
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
5763
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
5590
5764
  rows
5591
5765
  };
5592
5766
  }
@@ -5749,13 +5923,9 @@ var PortfolioCalculator = class extends BaseCalculator {
5749
5923
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
5750
5924
  return null;
5751
5925
  }
5752
- const totallCrossUnsettledPnL = positions3.rows.reduce(
5753
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
5754
- 0
5755
- );
5756
- const totalUnsettlementPnL = positions3.rows.reduce(
5757
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
5758
- 0
5926
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
5927
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(
5928
+ positions3
5759
5929
  );
5760
5930
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
5761
5931
  const [USDC_holding, nonUSDC] = parseHolding(
@@ -5767,7 +5937,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5767
5937
  const totalCollateral = perp.account.totalCollateral({
5768
5938
  USDCHolding: USDC_holding,
5769
5939
  nonUSDCHolding: nonUSDC,
5770
- unsettlementPnL: totallCrossUnsettledPnL,
5940
+ unsettlementPnL: unsettledCrossPnL,
5771
5941
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
5772
5942
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
5773
5943
  });
@@ -5778,7 +5948,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5778
5948
  return acc.add(curr.margin ?? 0);
5779
5949
  }, utils.zero);
5780
5950
  const totalValue = perp.account.totalValue({
5781
- totalUnsettlementPnL,
5951
+ totalUnsettlementPnL: unsettledPnL,
5782
5952
  USDCHolding: USDC_holding,
5783
5953
  nonUSDCHolding: nonUSDC,
5784
5954
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -5822,7 +5992,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5822
5992
  totalUnrealizedROI,
5823
5993
  freeCollateral,
5824
5994
  availableBalance,
5825
- unsettledPnL: totalUnsettlementPnL,
5995
+ unsettledPnL,
5826
5996
  holding,
5827
5997
  usdcHolding: USDC_holding,
5828
5998
  freeCollateralUSDCOnly
@@ -5941,7 +6111,7 @@ var usePositionStream = (symbol = "all", options) => {
5941
6111
  total_unreal_pnl: total_unreal_pnl_index,
5942
6112
  unrealPnlROI: unrealPnlROI_index
5943
6113
  };
5944
- }, [calcMode]);
6114
+ }, [calcMode, formattedPositions]);
5945
6115
  let rows = formattedPositions[0];
5946
6116
  {
5947
6117
  if (!rows) {
@@ -6431,14 +6601,8 @@ function formatPortfolio(inputs) {
6431
6601
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
6432
6602
  return null;
6433
6603
  }
6434
- const totallCrossUnsettledPnL = positions3.rows.reduce(
6435
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
6436
- 0
6437
- );
6438
- const totalUnsettlementPnL = positions3.rows.reduce(
6439
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
6440
- 0
6441
- );
6604
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
6605
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
6442
6606
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
6443
6607
  const [USDC_holding, nonUSDC] = parseHolding(
6444
6608
  holding,
@@ -6449,7 +6613,7 @@ function formatPortfolio(inputs) {
6449
6613
  const totalCollateral = perp.account.totalCollateral({
6450
6614
  USDCHolding: USDC_holding,
6451
6615
  nonUSDCHolding: nonUSDC,
6452
- unsettlementPnL: totallCrossUnsettledPnL,
6616
+ unsettlementPnL: unsettledCrossPnL,
6453
6617
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
6454
6618
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
6455
6619
  });
@@ -6460,7 +6624,7 @@ function formatPortfolio(inputs) {
6460
6624
  return acc.add(curr.margin ?? 0);
6461
6625
  }, utils.zero);
6462
6626
  const totalValue = perp.account.totalValue({
6463
- totalUnsettlementPnL,
6627
+ totalUnsettlementPnL: unsettledPnL,
6464
6628
  USDCHolding: USDC_holding,
6465
6629
  nonUSDCHolding: nonUSDC,
6466
6630
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -6504,7 +6668,7 @@ function formatPortfolio(inputs) {
6504
6668
  totalUnrealizedROI,
6505
6669
  freeCollateral,
6506
6670
  availableBalance,
6507
- unsettledPnL: totalUnsettlementPnL,
6671
+ unsettledPnL,
6508
6672
  holding,
6509
6673
  freeCollateralUSDCOnly
6510
6674
  };
@@ -6513,7 +6677,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6513
6677
  if (!accountInfo || !fundingRates || !symbolsInfo) {
6514
6678
  return data;
6515
6679
  }
6516
- let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
6680
+ let unrealPnL_total = utils.zero, unrealPnL_total_index = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero, totalUnsettledIsolatedPnl = utils.zero, totalUnsettledCrossPnl = utils.zero;
6517
6681
  const rows = data.rows.map((item) => {
6518
6682
  const info = symbolsInfo[item.symbol];
6519
6683
  const notional = perp.positions.notional(item.position_qty, item.mark_price);
@@ -6575,6 +6739,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6575
6739
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
6576
6740
  notional_total = notional_total.add(notional);
6577
6741
  unsettlementPnL_total = unsettlementPnL_total.add(unsettlementPnL2);
6742
+ if (item.margin_mode === types.MarginMode.CROSS) {
6743
+ totalUnsettledCrossPnl = totalUnsettledCrossPnl.add(unsettlementPnL2);
6744
+ }
6745
+ if (item.margin_mode === types.MarginMode.ISOLATED) {
6746
+ totalUnsettledIsolatedPnl = totalUnsettledIsolatedPnl.add(unsettlementPnL2);
6747
+ }
6578
6748
  return {
6579
6749
  ...item,
6580
6750
  mm: perp.positions.maintenanceMargin({
@@ -6588,7 +6758,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6588
6758
  unrealized_pnl: unrealPnl,
6589
6759
  unrealized_pnl_index: unrealPnl_index,
6590
6760
  unrealized_pnl_ROI: unrealPnlROI,
6591
- unrealized_pnl_ROI_index: unrealPnlROI_index
6761
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
6762
+ unsettled_pnl: unsettlementPnL2
6592
6763
  };
6593
6764
  });
6594
6765
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -6602,6 +6773,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6602
6773
  notional: notional_total.toNumber(),
6603
6774
  unsettledPnL: unsettlementPnL,
6604
6775
  total_unsettled_pnl: unsettlementPnL,
6776
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
6777
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
6605
6778
  rows
6606
6779
  };
6607
6780
  }
@@ -7984,7 +8157,9 @@ var useDeposit = (options) => {
7984
8157
  const depositPromise = isNativeToken ? account9.assetsManager.depositNativeToken(inputs) : account9.assetsManager.deposit(inputs);
7985
8158
  return depositPromise.then((result) => {
7986
8159
  updateAllowanceWhenTxSuccess(result.hash);
7987
- setBalance((value) => new utils.Decimal(value).sub(quantity).toString());
8160
+ setBalance(
8161
+ (value) => value ? new utils.Decimal(value).sub(quantity).toString() : "0"
8162
+ );
7988
8163
  track2(types.TrackerEventName.depositSuccess, {
7989
8164
  wallet: state?.connectWallet?.name,
7990
8165
  network: targetChain?.network_infos.name,
@@ -8036,16 +8211,16 @@ var useDeposit = (options) => {
8036
8211
  };
8037
8212
  function useBalance(options) {
8038
8213
  const { srcToken, address, decimals, account: account9, status } = options;
8039
- const [balance, setBalance] = React.useState("0");
8214
+ const [balance, setBalance] = React.useState(null);
8040
8215
  const fetchBalance = React.useCallback(
8041
8216
  async (address2, decimals2) => {
8042
8217
  try {
8043
8218
  if (types.isNativeTokenChecker(address2)) {
8044
- return account9.assetsManager.getNativeBalance({
8219
+ return await account9.assetsManager.getNativeBalance({
8045
8220
  decimals: decimals2
8046
8221
  });
8047
8222
  }
8048
- return account9.assetsManager.getBalance(address2, {
8223
+ return await account9.assetsManager.getBalance(address2, {
8049
8224
  decimals: decimals2
8050
8225
  });
8051
8226
  } catch (err) {
@@ -8094,11 +8269,13 @@ function useBalance(options) {
8094
8269
  React.useEffect(() => {
8095
8270
  if (swrBalance !== void 0) {
8096
8271
  setBalance(swrBalance || "0");
8272
+ } else {
8273
+ setBalance(null);
8097
8274
  }
8098
- }, [swrBalance]);
8275
+ }, [swrBalance, address]);
8099
8276
  return {
8100
8277
  balance,
8101
- balanceRevalidating,
8278
+ balanceRevalidating: balanceRevalidating || balance === null,
8102
8279
  setBalance,
8103
8280
  fetchBalance,
8104
8281
  fetchBalances
@@ -9628,6 +9805,9 @@ var PriceValidationStrategy = class {
9628
9805
  }
9629
9806
  const price = new utils.Decimal(order_price);
9630
9807
  const { symbol } = config;
9808
+ if (!symbol) {
9809
+ return;
9810
+ }
9631
9811
  const { quote_max, quote_min, quote_dp, price_range, price_scope } = symbol;
9632
9812
  const maxPriceNumber = perp.order.maxPrice(config.markPrice, price_range);
9633
9813
  const minPriceNumber = perp.order.minPrice(config.markPrice, price_range);
@@ -9674,6 +9854,9 @@ var TriggerPriceValidationStrategy = class {
9674
9854
  validate(values, config) {
9675
9855
  const { trigger_price } = values;
9676
9856
  const { symbol } = config;
9857
+ if (!symbol) {
9858
+ return;
9859
+ }
9677
9860
  const { quote_max, quote_min } = symbol;
9678
9861
  if (!trigger_price) {
9679
9862
  return OrderValidation.required("trigger_price");
@@ -9720,6 +9903,9 @@ var QuantityValidationStrategy = class {
9720
9903
  validate(values, config) {
9721
9904
  let { order_quantity, total, order_price } = values;
9722
9905
  const { maxQty, symbol } = config;
9906
+ if (!symbol) {
9907
+ return;
9908
+ }
9723
9909
  const { base_min, base_dp, quote_dp } = symbol;
9724
9910
  if (!order_quantity && total && order_price) {
9725
9911
  const totalNumber = new utils.Decimal(total);
@@ -10920,7 +11106,11 @@ var tpslFields = [
10920
11106
  "tp_offset",
10921
11107
  "sl_offset",
10922
11108
  "tp_offset_percentage",
10923
- "sl_offset_percentage"
11109
+ "sl_offset_percentage",
11110
+ "tp_offset_from_mark",
11111
+ "sl_offset_from_mark",
11112
+ "tp_offset_percentage_from_mark",
11113
+ "sl_offset_percentage_from_mark"
10924
11114
  ];
10925
11115
  var isBracketOrder = (order) => {
10926
11116
  return !!order.tp_trigger_price || !!order.sl_trigger_price;
@@ -10975,7 +11165,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
10975
11165
  totalCollateral,
10976
11166
  futures_taker_fee_rate,
10977
11167
  positions: positions3,
10978
- // leverage,
11168
+ symbolLeverage,
10979
11169
  sumUnitaryFunding
10980
11170
  } = inputs;
10981
11171
  const orderFee = perp.order.orderFee({
@@ -11000,7 +11190,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
11000
11190
  }
11001
11191
  });
11002
11192
  } else {
11003
- let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = 1;
11193
+ let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = symbolLeverage ?? 1;
11004
11194
  if (positions3) {
11005
11195
  const position = positions3.find(
11006
11196
  (p) => p.symbol === symbol && p.margin_mode === types.MarginMode.ISOLATED
@@ -11136,6 +11326,8 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
11136
11326
  entryPrice: position.average_open_price,
11137
11327
  qty: side === types.OrderSide.BUY ? Number(prev.quantity) : -Number(prev.quantity),
11138
11328
  orderSide: side,
11329
+ markPrice: markPrice ?? position.average_open_price,
11330
+ // use mark price as the default value
11139
11331
  values: prev
11140
11332
  },
11141
11333
  {
@@ -12690,6 +12882,12 @@ var DataPaint = class extends BasePaint {
12690
12882
  this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
12691
12883
  this.transformTop = 0;
12692
12884
  this.QRCODE_SIZE = 56;
12885
+ this.BROKER_BADGE_HEIGHT = 18;
12886
+ this.BROKER_BADGE_PADDING_X = 8;
12887
+ this.BROKER_BADGE_RADIUS = 4;
12888
+ }
12889
+ formatMarginMode(marginMode) {
12890
+ return marginMode === types.MarginMode.ISOLATED ? "Isolated" : "Cross";
12693
12891
  }
12694
12892
  async draw(options) {
12695
12893
  const needDrawDetails = Array.isArray(options.data?.position?.informations) && (options.data?.position?.informations?.length ?? 0) > 0;
@@ -12776,6 +12974,49 @@ var DataPaint = class extends BasePaint {
12776
12974
  fontSize: this._ratio(fontSize),
12777
12975
  fontFamily: options.fontFamily
12778
12976
  });
12977
+ const brokerName = options.data?.position.brokerName?.trim();
12978
+ if (brokerName) {
12979
+ left += (prevElementBoundingBox.width ?? 0) + this._ratio(10);
12980
+ const badgeHeight = this._ratio(this.BROKER_BADGE_HEIGHT);
12981
+ const badgePaddingX = this._ratio(this.BROKER_BADGE_PADDING_X);
12982
+ const badgeRadius = this._ratio(this.BROKER_BADGE_RADIUS);
12983
+ const badgeFontSize = this._ratio(12);
12984
+ const badgeFontWeight = 600;
12985
+ const textMetrics = this._drawText(
12986
+ brokerName,
12987
+ {
12988
+ left: 0,
12989
+ top: 0,
12990
+ fontSize: badgeFontSize,
12991
+ fontWeight: badgeFontWeight,
12992
+ fontFamily: options.fontFamily
12993
+ },
12994
+ true
12995
+ );
12996
+ const badgeWidth = (textMetrics.width ?? 0) + badgePaddingX * 2;
12997
+ const badgeTop = this._ratio(top) - badgeHeight / 2;
12998
+ this._fillRoundedRect(
12999
+ left,
13000
+ badgeTop,
13001
+ badgeWidth,
13002
+ badgeHeight,
13003
+ badgeRadius,
13004
+ "rgba(255,255,255,0.06)"
13005
+ );
13006
+ this._drawText(brokerName, {
13007
+ color: "rgba(255,255,255,0.36)",
13008
+ left: left + badgePaddingX,
13009
+ top: badgeTop + badgeHeight / 2,
13010
+ fontSize: badgeFontSize,
13011
+ fontWeight: badgeFontWeight,
13012
+ fontFamily: options.fontFamily,
13013
+ textBaseline: "middle"
13014
+ });
13015
+ prevElementBoundingBox = {
13016
+ ...prevElementBoundingBox,
13017
+ width: badgeWidth
13018
+ };
13019
+ }
12779
13020
  }
12780
13021
  const marginMode = options.data?.position.marginMode;
12781
13022
  if (marginMode) {
@@ -12790,7 +13031,7 @@ var DataPaint = class extends BasePaint {
12790
13031
  });
12791
13032
  }
12792
13033
  left += (prevElementBoundingBox.width ?? 0) + this._ratio(7);
12793
- const marginModeText = marginMode.charAt(0).toUpperCase() + marginMode.slice(1);
13034
+ const marginModeText = this.formatMarginMode(marginMode);
12794
13035
  prevElementBoundingBox = this._drawText(marginModeText, {
12795
13036
  color: layout.color,
12796
13037
  left,
@@ -12823,6 +13064,20 @@ var DataPaint = class extends BasePaint {
12823
13064
  );
12824
13065
  }
12825
13066
  }
13067
+ _fillRoundedRect(x, y, width, height, radius, color) {
13068
+ const r = Math.min(radius, width / 2, height / 2);
13069
+ this.ctx.save();
13070
+ this.ctx.fillStyle = color;
13071
+ this.ctx.beginPath();
13072
+ this.ctx.moveTo(x + r, y);
13073
+ this.ctx.arcTo(x + width, y, x + width, y + height, r);
13074
+ this.ctx.arcTo(x + width, y + height, x, y + height, r);
13075
+ this.ctx.arcTo(x, y + height, x, y, r);
13076
+ this.ctx.arcTo(x, y, x + width, y, r);
13077
+ this.ctx.closePath();
13078
+ this.ctx.fill();
13079
+ this.ctx.restore();
13080
+ }
12826
13081
  drawUnrealizedPnL(options, offsetTop = 0) {
12827
13082
  const layout = ramda.path(
12828
13083
  ["layout", "unrealizedPnl"],
@@ -13276,18 +13531,6 @@ var useEpochInfo = (type) => {
13276
13531
  }, [epochInfo]);
13277
13532
  return [epochInfo, { isLoading, curEpochInfo, isNotStared, refresh }];
13278
13533
  };
13279
-
13280
- // src/trading-rewards/useAllBrokers.ts
13281
- var useAllBrokers = () => {
13282
- const { data } = useQuery("/v1/public/broker/name", {
13283
- formatter: (res) => {
13284
- const { rows } = res;
13285
- return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
13286
- },
13287
- revalidateOnFocus: false
13288
- });
13289
- return [data];
13290
- };
13291
13534
  var useCurEpochEstimate = (type) => {
13292
13535
  const [data, setData] = React.useState(void 0);
13293
13536
  const { account: account9 } = useAccount();
@@ -18423,108 +18666,69 @@ var initialOrderState = {
18423
18666
  tp_trigger_price: "",
18424
18667
  sl_trigger_price: "",
18425
18668
  total: "",
18426
- symbol: ""
18669
+ symbol: "",
18670
+ side: types.OrderSide.BUY,
18671
+ order_type: types.OrderType.LIMIT,
18672
+ margin_mode: types.MarginMode.CROSS
18427
18673
  };
18428
- var useOrderStore = zustand.create()(
18429
- immer.immer((set, get3) => ({
18430
- entry: {
18431
- side: types.OrderSide.BUY,
18432
- order_type: types.OrderType.LIMIT,
18433
- ...initialOrderState
18434
- },
18435
- estLeverage: null,
18436
- estLiquidationPrice: null,
18437
- errors: {},
18438
- actions: {
18439
- initOrder: (symbol, options) => {
18440
- set((state) => {
18441
- state.entry = {
18442
- ...initialOrderState,
18443
- symbol,
18444
- side: options?.side ?? types.OrderSide.BUY,
18445
- order_type: options?.order_type ?? types.OrderType.LIMIT,
18446
- margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
18447
- };
18448
- state.estLeverage = null;
18449
- state.estLiquidationPrice = null;
18450
- state.errors = {};
18674
+ var useOrderEntryNextInternal = (symbol, options = {}) => {
18675
+ const { symbolInfo, symbolLeverage } = options;
18676
+ const [orderEntity, setOrderEntity] = React.useState(
18677
+ () => ({
18678
+ ...initialOrderState,
18679
+ ...options.initialOrder,
18680
+ symbol
18681
+ })
18682
+ );
18683
+ const actions = React.useMemo(
18684
+ () => ({
18685
+ initOrder: (sym, opts) => {
18686
+ setOrderEntity({
18687
+ ...initialOrderState,
18688
+ symbol: sym,
18689
+ side: opts?.side ?? types.OrderSide.BUY,
18690
+ order_type: opts?.order_type ?? types.OrderType.LIMIT,
18691
+ margin_mode: opts?.margin_mode ?? types.MarginMode.CROSS
18451
18692
  });
18452
18693
  },
18453
- hasTP_SL: () => {
18454
- const order = get3().entry;
18455
- return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18456
- },
18457
- updateOrderComputed: (data) => {
18458
- set(
18459
- (state) => {
18460
- state.estLeverage = data.estLeverage;
18461
- state.estLiquidationPrice = data.estLiquidationPrice;
18462
- },
18463
- false
18464
- // "updateOrderComputed"
18465
- );
18466
- },
18467
18694
  updateOrder: (order) => {
18468
- set(
18469
- (state) => {
18470
- state.entry = {
18471
- ...state.entry,
18472
- ...order
18473
- };
18474
- },
18475
- false
18476
- // "updateOrder"
18477
- );
18695
+ setOrderEntity((prev) => ({ ...prev, ...order }));
18478
18696
  },
18479
18697
  updateOrderByKey: (key, value) => {
18480
- set(
18481
- (state) => {
18482
- state.entry[key] = value;
18483
- },
18484
- false
18485
- // "updateOrderByKey"
18486
- );
18487
- },
18488
- restoreOrder: (order) => {
18489
- set(
18490
- (state) => {
18491
- state.entry = order;
18492
- },
18493
- false
18494
- // "restoreOrder"
18495
- );
18698
+ setOrderEntity((prev) => ({ ...prev, [key]: value }));
18496
18699
  },
18497
18700
  resetOrder: (_order) => {
18498
- set(
18499
- (state) => {
18500
- state.entry.order_price = "";
18501
- state.entry.order_quantity = "";
18502
- state.entry.trigger_price = "";
18503
- state.entry.total = "";
18504
- state.entry.tp_trigger_price = "";
18505
- state.entry.tp_pnl = "";
18506
- state.entry.tp_offset = "";
18507
- state.entry.tp_offset_percentage = "";
18508
- state.entry.sl_trigger_price = "";
18509
- state.entry.sl_pnl = "";
18510
- state.entry.sl_offset = "";
18511
- state.entry.sl_offset_percentage = "";
18512
- },
18513
- true
18514
- // "resetOrder"
18515
- );
18701
+ setOrderEntity((prev) => ({
18702
+ ...prev,
18703
+ order_price: "",
18704
+ order_quantity: "",
18705
+ trigger_price: "",
18706
+ total: "",
18707
+ tp_trigger_price: "",
18708
+ tp_pnl: "",
18709
+ tp_offset: "",
18710
+ tp_offset_percentage: "",
18711
+ tp_offset_from_mark: "",
18712
+ tp_offset_percentage_from_mark: "",
18713
+ sl_trigger_price: "",
18714
+ sl_pnl: "",
18715
+ sl_offset: "",
18716
+ sl_offset_percentage: "",
18717
+ sl_offset_from_mark: "",
18718
+ sl_offset_percentage_from_mark: ""
18719
+ }));
18720
+ },
18721
+ hasTP_SL: () => {
18722
+ const order = orderEntity;
18723
+ return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18516
18724
  }
18517
- }
18518
- }))
18519
- );
18520
- var useOrderEntryNextInternal = (symbol, options = {}) => {
18521
- const { symbolInfo, symbolLeverage } = options;
18522
- const orderEntity = useOrderStore((state) => state.entry);
18523
- const orderEntryActions = useOrderStore((state) => state.actions);
18725
+ }),
18726
+ [orderEntity]
18727
+ );
18524
18728
  React.useEffect(() => {
18525
- orderEntryActions.initOrder(symbol, options.initialOrder);
18729
+ actions.initOrder(symbol, options.initialOrder);
18526
18730
  if (options.initialOrder) {
18527
- orderEntryActions.updateOrder(options.initialOrder);
18731
+ actions.updateOrder(options.initialOrder);
18528
18732
  }
18529
18733
  }, [symbol]);
18530
18734
  const calculate2 = React.useCallback(
@@ -18542,10 +18746,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18542
18746
  );
18543
18747
  const setValue = (key, value, additional) => {
18544
18748
  if (!symbolInfo) {
18545
- orderEntryActions.updateOrderByKey(key, value);
18749
+ actions.updateOrderByKey(key, value);
18546
18750
  return;
18547
18751
  }
18548
- const currentEntry = useOrderStore.getState().entry;
18752
+ const currentEntry = orderEntity;
18549
18753
  const { markPrice } = additional ?? { markPrice: 0 };
18550
18754
  let newValues = calculate2(
18551
18755
  { ...currentEntry },
@@ -18579,7 +18783,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18579
18783
  if (sl_ROI) {
18580
18784
  newValues.sl_ROI = sl_ROI;
18581
18785
  }
18582
- orderEntryActions.updateOrder(newValues);
18786
+ actions.updateOrder(newValues);
18583
18787
  return newValues;
18584
18788
  };
18585
18789
  const calculateTPSL = (key, newValues, markPrice, symbolInfo2) => {
@@ -18602,6 +18806,42 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18602
18806
  symbolInfo2
18603
18807
  );
18604
18808
  }
18809
+ if (newValues.tp_offset_from_mark !== void 0 && newValues.tp_offset_from_mark !== "") {
18810
+ newValues = calculate2(
18811
+ newValues,
18812
+ "tp_offset_from_mark",
18813
+ newValues.tp_offset_from_mark,
18814
+ markPrice,
18815
+ symbolInfo2
18816
+ );
18817
+ }
18818
+ if (newValues.tp_offset_percentage_from_mark !== void 0 && newValues.tp_offset_percentage_from_mark !== "") {
18819
+ newValues = calculate2(
18820
+ newValues,
18821
+ "tp_offset_percentage_from_mark",
18822
+ newValues.tp_offset_percentage_from_mark,
18823
+ markPrice,
18824
+ symbolInfo2
18825
+ );
18826
+ }
18827
+ if (newValues.sl_offset_from_mark !== void 0 && newValues.sl_offset_from_mark !== "") {
18828
+ newValues = calculate2(
18829
+ newValues,
18830
+ "sl_offset_from_mark",
18831
+ newValues.sl_offset_from_mark,
18832
+ markPrice,
18833
+ symbolInfo2
18834
+ );
18835
+ }
18836
+ if (newValues.sl_offset_percentage_from_mark !== void 0 && newValues.sl_offset_percentage_from_mark !== "") {
18837
+ newValues = calculate2(
18838
+ newValues,
18839
+ "sl_offset_percentage_from_mark",
18840
+ newValues.sl_offset_percentage_from_mark,
18841
+ markPrice,
18842
+ symbolInfo2
18843
+ );
18844
+ }
18605
18845
  } else {
18606
18846
  if (typeof newValues.tp_trigger_price !== "undefined") {
18607
18847
  newValues = calculate2(
@@ -18621,16 +18861,51 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18621
18861
  symbolInfo2
18622
18862
  );
18623
18863
  }
18864
+ if (newValues.tp_offset_from_mark !== void 0 && newValues.tp_offset_from_mark !== "") {
18865
+ newValues = calculate2(
18866
+ newValues,
18867
+ "tp_offset_from_mark",
18868
+ newValues.tp_offset_from_mark,
18869
+ markPrice,
18870
+ symbolInfo2
18871
+ );
18872
+ }
18873
+ if (newValues.tp_offset_percentage_from_mark !== void 0 && newValues.tp_offset_percentage_from_mark !== "") {
18874
+ newValues = calculate2(
18875
+ newValues,
18876
+ "tp_offset_percentage_from_mark",
18877
+ newValues.tp_offset_percentage_from_mark,
18878
+ markPrice,
18879
+ symbolInfo2
18880
+ );
18881
+ }
18882
+ if (newValues.sl_offset_from_mark !== void 0 && newValues.sl_offset_from_mark !== "") {
18883
+ newValues = calculate2(
18884
+ newValues,
18885
+ "sl_offset_from_mark",
18886
+ newValues.sl_offset_from_mark,
18887
+ markPrice,
18888
+ symbolInfo2
18889
+ );
18890
+ }
18891
+ if (newValues.sl_offset_percentage_from_mark !== void 0 && newValues.sl_offset_percentage_from_mark !== "") {
18892
+ newValues = calculate2(
18893
+ newValues,
18894
+ "sl_offset_percentage_from_mark",
18895
+ newValues.sl_offset_percentage_from_mark,
18896
+ markPrice,
18897
+ symbolInfo2
18898
+ );
18899
+ }
18624
18900
  }
18625
18901
  return newValues;
18626
18902
  };
18627
18903
  const setValues = (values, additional) => {
18628
18904
  if (!symbolInfo) {
18629
- orderEntryActions.updateOrder(values);
18905
+ actions.updateOrder(values);
18630
18906
  return;
18631
18907
  }
18632
- const currentEntry = useOrderStore.getState().entry;
18633
- let newValues = { ...currentEntry };
18908
+ let newValues = { ...orderEntity };
18634
18909
  Object.keys(values).forEach((key) => {
18635
18910
  newValues = calculate2(
18636
18911
  newValues,
@@ -18640,17 +18915,28 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18640
18915
  symbolInfo
18641
18916
  );
18642
18917
  });
18643
- orderEntryActions.updateOrder(newValues);
18918
+ actions.updateOrder(newValues);
18919
+ return newValues;
18920
+ };
18921
+ const setValuesRaw = (values) => {
18922
+ if (!symbolInfo) {
18923
+ actions.updateOrder(values);
18924
+ return;
18925
+ }
18926
+ const newValues = {
18927
+ ...orderEntity,
18928
+ ...values
18929
+ };
18930
+ actions.updateOrder(newValues);
18644
18931
  return newValues;
18645
18932
  };
18646
18933
  const onMarkPriceUpdated = React.useCallback(
18647
18934
  (markPrice, baseOn = []) => {
18648
18935
  if (!options.symbolInfo) return;
18649
- const currentEntry = useOrderStore.getState().entry;
18650
- let newValues = { ...currentEntry };
18936
+ let newValues = { ...orderEntity };
18651
18937
  if (baseOn.length === 0) {
18652
18938
  newValues = calculate2(
18653
- { ...currentEntry },
18939
+ { ...orderEntity },
18654
18940
  "order_price",
18655
18941
  markPrice,
18656
18942
  markPrice,
@@ -18661,7 +18947,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18661
18947
  newValues = calculate2(
18662
18948
  { ...newValues },
18663
18949
  key,
18664
- currentEntry[key],
18950
+ orderEntity[key],
18665
18951
  markPrice,
18666
18952
  options.symbolInfo
18667
18953
  );
@@ -18680,9 +18966,9 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18680
18966
  newValues.sl_ROI = sl_ROI;
18681
18967
  }
18682
18968
  }
18683
- orderEntryActions.updateOrder(newValues);
18969
+ actions.updateOrder(newValues);
18684
18970
  },
18685
- [calculate2, options.symbolInfo, orderEntryActions]
18971
+ [calculate2, options.symbolInfo, symbolLeverage, orderEntity]
18686
18972
  );
18687
18973
  const validate = (order, creator, options2) => {
18688
18974
  return creator?.validate(order, {
@@ -18700,12 +18986,13 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18700
18986
  const submitOrder = React.useCallback(() => {
18701
18987
  }, [orderEntity]);
18702
18988
  const resetOrder = (order) => {
18703
- orderEntryActions.resetOrder(order);
18989
+ actions.resetOrder(order);
18704
18990
  };
18705
18991
  return {
18706
18992
  formattedOrder: orderEntity,
18707
18993
  setValue,
18708
18994
  setValues,
18995
+ setValuesRaw,
18709
18996
  submit: submitOrder,
18710
18997
  reset: resetOrder,
18711
18998
  generateOrder,
@@ -18721,6 +19008,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
18721
19008
  }
18722
19009
  const ee = useEventEmitter();
18723
19010
  const { track: track2 } = useTrack();
19011
+ const apiBaseUrl = useConfig("apiBaseUrl");
19012
+ const fetchSymbols = useSymbolStore((state) => state.fetchData);
18724
19013
  const [meta, setMeta] = React.useState({
18725
19014
  dirty: {},
18726
19015
  submitted: false,
@@ -18740,8 +19029,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18740
19029
  const symbolConfig = useSymbolsInfo();
18741
19030
  const accountInfo = useAccountInfo();
18742
19031
  const positions3 = usePositions();
18743
- const entry = useOrderStore((s) => s.entry);
18744
- const effectiveMarginMode = options?.initialOrder?.margin_mode ?? entry?.margin_mode ?? types.MarginMode.CROSS;
19032
+ const effectiveMarginMode = options?.initialOrder?.margin_mode ?? types.MarginMode.CROSS;
18745
19033
  const symbolLeverage = useLeverageBySymbol(symbol, effectiveMarginMode);
18746
19034
  const symbolInfo = symbolConfig[symbol]();
18747
19035
  const markPrice = actions.getMarkPriceBySymbol(symbol);
@@ -18750,6 +19038,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18750
19038
  formattedOrder,
18751
19039
  setValue: setValueInternal,
18752
19040
  setValues: setValuesInternal,
19041
+ setValuesRaw: setValuesRawInternal,
18753
19042
  validate,
18754
19043
  generateOrder,
18755
19044
  reset,
@@ -18974,6 +19263,21 @@ var useOrderEntry2 = (symbol, options = {}) => {
18974
19263
  interactiveValidate(newValues);
18975
19264
  }
18976
19265
  };
19266
+ const setValuesRaw = (values) => {
19267
+ if (!Object.keys(values).every(
19268
+ (key) => canSetTPSLPrice(
19269
+ key,
19270
+ values[key],
19271
+ formattedOrder.order_type
19272
+ )
19273
+ )) {
19274
+ return;
19275
+ }
19276
+ const newValues = setValuesRawInternal(values);
19277
+ if (newValues) {
19278
+ interactiveValidate(newValues);
19279
+ }
19280
+ };
18977
19281
  async function validateFunc(order) {
18978
19282
  const creator = getOrderCreator(order);
18979
19283
  return validate(order, creator, prepareData());
@@ -19028,11 +19332,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
19028
19332
  markPrice: markPrice2,
19029
19333
  totalCollateral,
19030
19334
  futures_taker_fee_rate: accountInfo.futures_taker_fee_rate,
19031
- imr_factor: accountInfo.imr_factor[symbol],
19335
+ imr_factor: accountInfo.imr_factor?.[symbol] ?? 0,
19032
19336
  symbol,
19033
19337
  positions: positions3,
19034
19338
  symbolInfo,
19035
- sumUnitaryFunding
19339
+ sumUnitaryFunding,
19340
+ symbolLeverage
19036
19341
  });
19037
19342
  return estLiqPrice2;
19038
19343
  }, [
@@ -19043,7 +19348,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
19043
19348
  symbol,
19044
19349
  maxQty,
19045
19350
  symbolInfo,
19046
- fundingRates
19351
+ fundingRates,
19352
+ symbolLeverage
19047
19353
  ]);
19048
19354
  const estLiqPriceDistance = React.useMemo(() => {
19049
19355
  if (!estLiqPrice) {
@@ -19115,6 +19421,9 @@ var useOrderEntry2 = (symbol, options = {}) => {
19115
19421
  orders: appendOrderMetadata(order.orders, orderMetadata)
19116
19422
  } : appendOrderMetadata(order, orderMetadata);
19117
19423
  const result = await doCreateOrder(params);
19424
+ if (!result.success && (order.order_type === types.OrderType.MARKET || order.order_type === types.OrderType.STOP_MARKET)) {
19425
+ void fetchSymbols(apiBaseUrl);
19426
+ }
19118
19427
  if (result.success) {
19119
19428
  let trackParams = {
19120
19429
  side: order.side,
@@ -19182,6 +19491,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
19182
19491
  freeCollateral: effectiveMarginMode === types.MarginMode.ISOLATED ? freeCollateralUSDCOnly : freeCollateral,
19183
19492
  setValue: useMemoizedFn(setValue),
19184
19493
  setValues: useMemoizedFn(setValues),
19494
+ setValuesRaw: useMemoizedFn(setValuesRaw),
19185
19495
  symbolInfo: symbolInfo || types.EMPTY_OBJECT,
19186
19496
  metaState: meta,
19187
19497
  isMutating,
@@ -19189,6 +19499,107 @@ var useOrderEntry2 = (symbol, options = {}) => {
19189
19499
  symbolLeverage
19190
19500
  };
19191
19501
  };
19502
+ var initialOrderState2 = {
19503
+ order_price: "",
19504
+ order_quantity: "",
19505
+ trigger_price: "",
19506
+ tp_trigger_price: "",
19507
+ sl_trigger_price: "",
19508
+ total: "",
19509
+ symbol: ""
19510
+ };
19511
+ var useOrderStore = zustand.create()(
19512
+ immer.immer((set, get3) => ({
19513
+ entry: {
19514
+ side: types.OrderSide.BUY,
19515
+ order_type: types.OrderType.LIMIT,
19516
+ ...initialOrderState2
19517
+ },
19518
+ estLeverage: null,
19519
+ estLiquidationPrice: null,
19520
+ errors: {},
19521
+ actions: {
19522
+ initOrder: (symbol, options) => {
19523
+ set((state) => {
19524
+ state.entry = {
19525
+ ...initialOrderState2,
19526
+ symbol,
19527
+ side: options?.side ?? types.OrderSide.BUY,
19528
+ order_type: options?.order_type ?? types.OrderType.LIMIT,
19529
+ margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
19530
+ };
19531
+ state.estLeverage = null;
19532
+ state.estLiquidationPrice = null;
19533
+ state.errors = {};
19534
+ });
19535
+ },
19536
+ hasTP_SL: () => {
19537
+ const order = get3().entry;
19538
+ return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
19539
+ },
19540
+ updateOrderComputed: (data) => {
19541
+ set(
19542
+ (state) => {
19543
+ state.estLeverage = data.estLeverage;
19544
+ state.estLiquidationPrice = data.estLiquidationPrice;
19545
+ },
19546
+ false
19547
+ // "updateOrderComputed"
19548
+ );
19549
+ },
19550
+ updateOrder: (order) => {
19551
+ set(
19552
+ (state) => {
19553
+ state.entry = {
19554
+ ...state.entry,
19555
+ ...order
19556
+ };
19557
+ },
19558
+ false
19559
+ // "updateOrder"
19560
+ );
19561
+ },
19562
+ updateOrderByKey: (key, value) => {
19563
+ set(
19564
+ (state) => {
19565
+ state.entry[key] = value;
19566
+ },
19567
+ false
19568
+ // "updateOrderByKey"
19569
+ );
19570
+ },
19571
+ restoreOrder: (order) => {
19572
+ set(
19573
+ (state) => {
19574
+ state.entry = order;
19575
+ },
19576
+ false
19577
+ // "restoreOrder"
19578
+ );
19579
+ },
19580
+ resetOrder: (_order) => {
19581
+ set(
19582
+ (state) => {
19583
+ state.entry.order_price = "";
19584
+ state.entry.order_quantity = "";
19585
+ state.entry.trigger_price = "";
19586
+ state.entry.total = "";
19587
+ state.entry.tp_trigger_price = "";
19588
+ state.entry.tp_pnl = "";
19589
+ state.entry.tp_offset = "";
19590
+ state.entry.tp_offset_percentage = "";
19591
+ state.entry.sl_trigger_price = "";
19592
+ state.entry.sl_pnl = "";
19593
+ state.entry.sl_offset = "";
19594
+ state.entry.sl_offset_percentage = "";
19595
+ },
19596
+ true
19597
+ // "resetOrder"
19598
+ );
19599
+ }
19600
+ }
19601
+ }))
19602
+ );
19192
19603
  var useOrderEntity = (order, options) => {
19193
19604
  const { symbol } = order;
19194
19605
  const { maxQty } = options || {};
@@ -19465,6 +19876,7 @@ var useTpslPriceChecker = (params) => {
19465
19876
  slPrice,
19466
19877
  liqPrice,
19467
19878
  side,
19879
+ markPrice,
19468
19880
  currentPosition,
19469
19881
  orderQuantity
19470
19882
  } = params;
@@ -19520,6 +19932,17 @@ var useTpslPriceChecker = (params) => {
19520
19932
  if (slPrice === void 0 || liqPrice === void 0 || side === void 0 || liqPrice === null) {
19521
19933
  return null;
19522
19934
  }
19935
+ if (markPrice != null && Number.isFinite(markPrice) && markPrice > 0) {
19936
+ if (side === types.OrderSide.BUY && liqPrice > markPrice) {
19937
+ return null;
19938
+ }
19939
+ if (side === types.OrderSide.SELL && liqPrice < markPrice) {
19940
+ return null;
19941
+ }
19942
+ }
19943
+ if (typeof liqPrice === "number" && (!Number.isFinite(liqPrice) || liqPrice <= 0)) {
19944
+ return null;
19945
+ }
19523
19946
  let slPriceDecimal;
19524
19947
  let liqPriceDecimal;
19525
19948
  try {
@@ -19546,6 +19969,7 @@ var useTpslPriceChecker = (params) => {
19546
19969
  slPrice,
19547
19970
  liqPrice,
19548
19971
  side,
19972
+ markPrice,
19549
19973
  warning_threshold,
19550
19974
  currentPosition,
19551
19975
  orderQuantity
@@ -19663,6 +20087,7 @@ exports.EpochStatus = EpochStatus;
19663
20087
  exports.ExtendedConfigStore = ExtendedConfigStore;
19664
20088
  exports.FlagKeys = FlagKeys;
19665
20089
  exports.MaintenanceStatus = MaintenanceStatus;
20090
+ exports.MarketCategoriesConfigProvider = MarketCategoriesConfigProvider;
19666
20091
  exports.MarketsStorageKey = MarketsStorageKey;
19667
20092
  exports.MarketsType = MarketsType;
19668
20093
  exports.ORDERLY_ORDERBOOK_DEPTH_KEY = ORDERLY_ORDERBOOK_DEPTH_KEY;
@@ -19679,6 +20104,7 @@ exports.fetcher = fetcher;
19679
20104
  exports.findPositionTPSLFromOrders = findPositionTPSLFromOrders;
19680
20105
  exports.findTPSLFromOrder = findTPSLFromOrder;
19681
20106
  exports.findTPSLOrderPriceFromOrder = findTPSLOrderPriceFromOrder;
20107
+ exports.formatSymbolWithBroker = formatSymbolWithBroker;
19682
20108
  exports.getMinNotional = getMinNotional;
19683
20109
  exports.getPriceKey = getPriceKey;
19684
20110
  exports.indexedDBManager = indexedDBManager;
@@ -19699,6 +20125,7 @@ exports.useApiKeyManager = useApiKeyManager;
19699
20125
  exports.useAppStore = useAppStore;
19700
20126
  exports.useAssetsHistory = useAssetsHistory;
19701
20127
  exports.useAudioPlayer = useAudioPlayer;
20128
+ exports.useBadgeBySymbol = useBadgeBySymbol;
19702
20129
  exports.useBalanceSubscription = useBalanceSubscription;
19703
20130
  exports.useBalanceTopic = useBalanceTopic;
19704
20131
  exports.useBoolean = useBoolean;
@@ -19757,6 +20184,7 @@ exports.useMarkPrice = useMarkPrice;
19757
20184
  exports.useMarkPriceBySymbol = useMarkPriceBySymbol;
19758
20185
  exports.useMarkPricesStream = useMarkPricesStream;
19759
20186
  exports.useMarket = useMarket;
20187
+ exports.useMarketCategoriesConfig = useMarketCategoriesConfig;
19760
20188
  exports.useMarketList = useMarketList;
19761
20189
  exports.useMarketMap = useMarketMap;
19762
20190
  exports.useMarketTradeStream = useMarketTradeStream;
@@ -19814,6 +20242,7 @@ exports.useSymbolInfo = useSymbolInfo;
19814
20242
  exports.useSymbolLeverage = useSymbolLeverage;
19815
20243
  exports.useSymbolLeverageMap = useSymbolLeverageMap;
19816
20244
  exports.useSymbolPriceRange = useSymbolPriceRange;
20245
+ exports.useSymbolWithBroker = useSymbolWithBroker;
19817
20246
  exports.useSymbolsInfo = useSymbolsInfo;
19818
20247
  exports.useSymbolsInfoStore = useSymbolsInfoStore;
19819
20248
  exports.useTPSLOrder = useTPSLOrder;