@orderly.network/hooks 3.0.0-beta.1 → 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,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var net = require('@orderly.network/net');
4
3
  var React = require('react');
4
+ var net = require('@orderly.network/net');
5
5
  var useSWR5 = require('swr');
6
6
  var pluginCore = require('@orderly.network/plugin-core');
7
7
  var types = require('@orderly.network/types');
@@ -61,13 +61,24 @@ var __export = (target, all) => {
61
61
  for (var name in all)
62
62
  __defProp(target, name, { get: all[name], enumerable: true });
63
63
  };
64
+ var MarketCategoriesConfigContext = React.createContext(void 0);
65
+ var MarketCategoriesConfigProvider = ({ value, children }) => {
66
+ return React.createElement(
67
+ MarketCategoriesConfigContext.Provider,
68
+ { value },
69
+ children
70
+ );
71
+ };
72
+ function useMarketCategoriesConfig() {
73
+ return React.useContext(MarketCategoriesConfigContext);
74
+ }
64
75
 
65
76
  // src/version.ts
66
77
  if (typeof window !== "undefined") {
67
78
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
68
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.1";
79
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "3.0.0-beta.10";
69
80
  }
70
- var version_default = "3.0.0-beta.1";
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,
@@ -596,6 +607,20 @@ var useAudioPlayer = (src, options = {}) => {
596
607
  const el = getOrderFilledAudio();
597
608
  el.volume = Math.max(0, Math.min(1, volume));
598
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
+ }, []);
599
624
  const play = React.useCallback(() => {
600
625
  const currentSrc = srcRef.current;
601
626
  const currentEnabled = enabledRef.current;
@@ -1305,7 +1330,7 @@ function checkTPSLOrderTypeIsMarket(key, values) {
1305
1330
  }
1306
1331
  function tpslCalculateHelper(key, inputs, options = {}) {
1307
1332
  const { symbol } = options;
1308
- 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") {
1309
1334
  return {
1310
1335
  [key]: inputs.value
1311
1336
  };
@@ -1313,6 +1338,7 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1313
1338
  const orderType = key.startsWith("tp_") ? types.AlgoOrderType.TAKE_PROFIT : types.AlgoOrderType.STOP_LOSS;
1314
1339
  const keyPrefix = key.slice(0, 3);
1315
1340
  const qty = Number(key === "quantity" ? inputs.value : inputs.qty);
1341
+ const markPrice = inputs.markPrice ?? inputs.entryPrice;
1316
1342
  if (qty === 0 && (key === "tp_pnl" || key === "sl_pnl" || key === "tp_trigger_price" || key === "sl_trigger_price")) {
1317
1343
  return {
1318
1344
  // [`${keyPrefix}trigger_price`]: "",
@@ -1323,7 +1349,7 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1323
1349
  [key]: inputs.value
1324
1350
  };
1325
1351
  }
1326
- 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;
1327
1353
  const entryPrice = new utils.Decimal(inputs.entryPrice).todp(options.symbol?.quote_dp ?? 2, utils.Decimal.ROUND_UP).toNumber();
1328
1354
  switch (key) {
1329
1355
  case "tp_trigger_price":
@@ -1335,6 +1361,8 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1335
1361
  [`${keyPrefix}trigger_price`]: trigger_price,
1336
1362
  [`${keyPrefix}offset`]: "",
1337
1363
  [`${keyPrefix}offset_percentage`]: "",
1364
+ [`${keyPrefix}offset_from_mark`]: "",
1365
+ [`${keyPrefix}offset_percentage_from_mark`]: "",
1338
1366
  [`${keyPrefix}pnl`]: "",
1339
1367
  [`${keyPrefix}ROI`]: ""
1340
1368
  };
@@ -1344,31 +1372,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1344
1372
  }
1345
1373
  break;
1346
1374
  }
1347
- // case "tp_enable":
1348
- // case "sl_enable": {
1349
- // return {
1350
- // [`${keyPrefix}enable`]: inputs.value,
1351
- // [`${keyPrefix}order_type`]: OrderType.MARKET,
1352
- // [`${keyPrefix}trigger_price`]: "",
1353
- // [`${keyPrefix}order_price`]: "",
1354
- // [`${keyPrefix}offset`]: "",
1355
- // [`${keyPrefix}offset_percentage`]: "",
1356
- // [`${keyPrefix}pnl`]: "",
1357
- // [`${keyPrefix}ROI`]: "",
1358
- // };
1359
- // }
1360
- // case 'tp_pnl':{
1361
- // if (inputs.values.tp_order_type !== OrderType.MARKET) {
1362
- // pnl = inputs.value;
1363
- // trigger_price = pnlToPrice({
1364
- // qty,
1365
- // pnl: Number(inputs.value),
1366
- // entryPrice,
1367
- // orderSide: inputs.orderSide,
1368
- // orderType,
1369
- // })
1370
- // }
1371
- // }
1372
1375
  case "tp_pnl":
1373
1376
  case "sl_pnl": {
1374
1377
  pnl = inputs.value;
@@ -1415,6 +1418,30 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1415
1418
  }
1416
1419
  break;
1417
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
+ }
1418
1445
  case "tp_order_price":
1419
1446
  case "sl_order_price": {
1420
1447
  order_price = inputs.value;
@@ -1455,12 +1482,38 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1455
1482
  }
1456
1483
  break;
1457
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
+ }
1458
1509
  }
1459
1510
  if (!trigger_price && checkTPSLOrderTypeIsMarket(key, inputs.values)) {
1460
1511
  return {
1461
1512
  [`${keyPrefix}trigger_price`]: "",
1462
1513
  [`${keyPrefix}offset`]: "",
1463
1514
  [`${keyPrefix}offset_percentage`]: "",
1515
+ [`${keyPrefix}offset_from_mark`]: "",
1516
+ [`${keyPrefix}offset_percentage_from_mark`]: "",
1464
1517
  [`${keyPrefix}pnl`]: "",
1465
1518
  [`${keyPrefix}ROI`]: "",
1466
1519
  [key]: inputs.value
@@ -1505,6 +1558,8 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1505
1558
  [`${keyPrefix}order_price`]: order_price ? utils.todpIfNeed(order_price, symbol?.quote_dp ?? 2) : "",
1506
1559
  [`${keyPrefix}offset`]: offset ?? "",
1507
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`] ?? "",
1508
1563
  [`${keyPrefix}pnl`]: pnl ?? ""
1509
1564
  // [`${keyPrefix}ROI`]: calcROI({
1510
1565
  // pnl: Number(pnl ?? 0),
@@ -1692,6 +1747,7 @@ function tpslInputHandle(inputs) {
1692
1747
  // order price or mark price
1693
1748
  qty: values.side === types.OrderSide.BUY ? Number(values.order_quantity) : Number(values.order_quantity) * -1,
1694
1749
  orderSide: values.side,
1750
+ markPrice,
1695
1751
  // values: newValues,
1696
1752
  values
1697
1753
  },
@@ -1727,6 +1783,10 @@ var getCalculateHandler = (fieldName) => {
1727
1783
  case "sl_offset":
1728
1784
  case "tp_offset_percentage":
1729
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":
1730
1790
  case "tp_order_price":
1731
1791
  case "tp_order_type":
1732
1792
  case "sl_order_type":
@@ -2610,16 +2670,12 @@ var createDataStore = (config) => {
2610
2670
  const brokerIdQuery = typeof options?.brokerId === "string" && options?.brokerId !== "orderly" ? `?broker_id=${options?.brokerId}` : "";
2611
2671
  const url = `${dynamicBaseUrl || baseUrl || ""}${endpoint}${brokerIdQuery}`;
2612
2672
  const data = await fetcher(url, {}, { formatter });
2613
- const dataWithBrokerId = data.map((item) => ({
2614
- ...item,
2615
- broker_id: options?.brokerId
2616
- }));
2617
2673
  set({
2618
- data: dataWithBrokerId,
2674
+ data,
2619
2675
  loading: false,
2620
2676
  error: null
2621
2677
  });
2622
- return dataWithBrokerId;
2678
+ return data;
2623
2679
  } catch (error) {
2624
2680
  set({ error, loading: false });
2625
2681
  return null;
@@ -3155,7 +3211,9 @@ var DEFAULT_SYMBOL_DEPTHS = {
3155
3211
  };
3156
3212
  var DEFAULT_SYMBOL_DISPLAY_NAMES = {
3157
3213
  PERP_XAU_USDC: "XAU (Gold) ",
3158
- 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)"
3159
3217
  };
3160
3218
  var ProxyConfigStore = class {
3161
3219
  constructor(_originConfigStore) {
@@ -3438,7 +3496,10 @@ var useGetRwaSymbolOpenTimeInterval = (symbol, thresholdMinutes = 30) => {
3438
3496
  };
3439
3497
  var useSymbolsInfo = () => {
3440
3498
  const symbolsInfo = useAppStore((state) => state.symbolsInfo);
3441
- return React.useMemo(() => createGetter({ ...symbolsInfo }), [symbolsInfo]);
3499
+ return React.useMemo(
3500
+ () => createGetter(symbolsInfo ? { ...symbolsInfo } : symbolsInfo),
3501
+ [symbolsInfo]
3502
+ );
3442
3503
  };
3443
3504
  var useSymbolsInfoStore = () => {
3444
3505
  return useAppStore((state) => state.symbolsInfo);
@@ -3451,6 +3512,7 @@ var MarketsType = /* @__PURE__ */ ((MarketsType2) => {
3451
3512
  MarketsType2[MarketsType2["ALL"] = 2] = "ALL";
3452
3513
  MarketsType2[MarketsType2["RWA"] = 3] = "RWA";
3453
3514
  MarketsType2[MarketsType2["NEW_LISTING"] = 4] = "NEW_LISTING";
3515
+ MarketsType2[MarketsType2["COMMUNITY"] = 5] = "COMMUNITY";
3454
3516
  return MarketsType2;
3455
3517
  })(MarketsType || {});
3456
3518
  var MarketsStorageKey = "orderly_markets";
@@ -3620,6 +3682,8 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3620
3682
  const rwaInfo = !rwaSymbolsInfo.isNil ? rwaSymbolsInfo[item.symbol]() : null;
3621
3683
  return {
3622
3684
  ...item,
3685
+ broker_id: item.broker_id,
3686
+ display_symbol_name: item.display_symbol_name,
3623
3687
  quote_dp: info("quote_dp"),
3624
3688
  created_time: info("created_time"),
3625
3689
  displayName: info("displayName"),
@@ -3641,7 +3705,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3641
3705
  var filterMarkets = (params) => {
3642
3706
  const { markets, favorites, recent, newListing, type } = params;
3643
3707
  let curData = [];
3644
- if (type === 2 /* ALL */) {
3708
+ if (type === 2 /* ALL */ || type === 5 /* COMMUNITY */) {
3645
3709
  curData = markets;
3646
3710
  } else if (type === 3 /* RWA */) {
3647
3711
  curData = markets.filter((item) => item.isRwa);
@@ -4563,7 +4627,7 @@ var useMarket = (type) => {
4563
4627
  const getData = (type2) => {
4564
4628
  const localData = type2 === 0 /* FAVORITES */ ? [...favorites] : [...recent];
4565
4629
  const keys = localData.map((item) => item.name);
4566
- 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));
4567
4631
  const favoritesData = [...favorites];
4568
4632
  const favoriteKeys = favoritesData.map((item) => item.name);
4569
4633
  if (filter) {
@@ -4762,6 +4826,80 @@ var useSymbolLeverageMap = () => {
4762
4826
  refresh: mutate6
4763
4827
  };
4764
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
4765
4903
  var useMarginModes = () => {
4766
4904
  const { data, error, isLoading, mutate: mutate6 } = usePrivateQuery("/v1/client/margin_modes", {
4767
4905
  revalidateOnFocus: false,
@@ -4803,22 +4941,28 @@ var useMarginModes = () => {
4803
4941
  };
4804
4942
  var useMarginModeBySymbol = (symbol, fallback = types.MarginMode.CROSS) => {
4805
4943
  const { marginModes, isLoading, error, refresh, updateMarginMode } = useMarginModes();
4806
- 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]);
4807
4949
  const update = React.useCallback(
4808
4950
  async (mode) => {
4951
+ if (brokerId) mode = types.MarginMode.ISOLATED;
4809
4952
  return updateMarginMode({
4810
4953
  symbol_list: [symbol],
4811
4954
  default_margin_mode: mode
4812
4955
  });
4813
4956
  },
4814
- [symbol, updateMarginMode]
4957
+ [brokerId, symbol, updateMarginMode]
4815
4958
  );
4816
4959
  return {
4817
4960
  marginMode,
4818
4961
  isLoading,
4819
4962
  error,
4820
4963
  refresh,
4821
- update
4964
+ update,
4965
+ isPermissionlessListing: !!brokerId
4822
4966
  };
4823
4967
  };
4824
4968
 
@@ -5057,6 +5201,11 @@ var MarkPriceCalculator = class extends BaseCalculator {
5057
5201
 
5058
5202
  // src/orderly/calculator/calculatorContext.ts
5059
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
+ }
5060
5209
  static get instance() {
5061
5210
  return this._instance;
5062
5211
  }
@@ -5075,7 +5224,6 @@ var CalculatorContext = class _CalculatorContext {
5075
5224
  update(scope, data) {
5076
5225
  this.setCtxData();
5077
5226
  this.markPrices = scope === "markPrice" /* MARK_PRICE */ ? data : this.output[MarketCalculatorName];
5078
- this.portfolio = this.output["portfolio"] || useAppStore.getState().portfolio;
5079
5227
  return this;
5080
5228
  }
5081
5229
  setCtxData() {
@@ -5093,7 +5241,6 @@ var CalculatorContext = class _CalculatorContext {
5093
5241
  clearCache() {
5094
5242
  this.output = {};
5095
5243
  this.accountInfo = void 0;
5096
- this.portfolio = void 0;
5097
5244
  }
5098
5245
  deleteByName(name) {
5099
5246
  delete this.output[name];
@@ -5461,7 +5608,7 @@ var PositionCalculator = class extends BaseCalculator {
5461
5608
  if (!accountInfo || !fundingRates || !symbolsInfo) {
5462
5609
  return data;
5463
5610
  }
5464
- 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;
5465
5612
  let rows = data.rows.map((item) => {
5466
5613
  const info = symbolsInfo[item.symbol];
5467
5614
  const sum_unitary_funding = fundingRates?.[item.symbol]?.["sum_unitary_funding"] ?? 0;
@@ -5524,6 +5671,12 @@ var PositionCalculator = class extends BaseCalculator {
5524
5671
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
5525
5672
  notional_total = notional_total.add(notional);
5526
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
+ }
5527
5680
  const fundingFee = new utils.Decimal(sum_unitary_funding).sub(item.last_sum_unitary_funding).mul(item.position_qty).negated().toNumber();
5528
5681
  return {
5529
5682
  ...item,
@@ -5539,7 +5692,8 @@ var PositionCalculator = class extends BaseCalculator {
5539
5692
  unrealized_pnl: unrealPnl,
5540
5693
  unrealized_pnl_index: unrealPnl_index,
5541
5694
  unrealized_pnl_ROI: unrealPnlROI,
5542
- unrealized_pnl_ROI_index: unrealPnlROI_index
5695
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
5696
+ unsettled_pnl: unsettlementPnL2
5543
5697
  };
5544
5698
  });
5545
5699
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -5551,18 +5705,34 @@ var PositionCalculator = class extends BaseCalculator {
5551
5705
  rows = rows.map((item) => {
5552
5706
  const info = symbolsInfo[item.symbol];
5553
5707
  const totalCollateral = item.margin_mode === types.MarginMode.ISOLATED ? new utils.Decimal(item.margin ?? 0).add(item.unsettlement_pnl ?? 0).toNumber() : crossMarginCollateral.toNumber();
5554
- const est_liq_price = perp.positions.liqPrice({
5555
- symbol: item.symbol,
5556
- markPrice: item.mark_price,
5557
- totalCollateral,
5558
- positionQty: item.position_qty,
5559
- positions: rows,
5560
- MMR: item.mmr,
5561
- baseMMR: info?.["base_mmr"],
5562
- baseIMR: info?.["base_imr"],
5563
- IMRFactor: accountInfo.imr_factor[item.symbol],
5564
- costPosition: item.cost_position
5565
- });
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
+ }
5566
5736
  return {
5567
5737
  ...item,
5568
5738
  est_liq_price
@@ -5589,6 +5759,8 @@ var PositionCalculator = class extends BaseCalculator {
5589
5759
  total_unsettled_pnl: unsettlementPnL,
5590
5760
  unrealPnlROI: totalUnrealizedROI,
5591
5761
  unrealPnlROI_index: totalUnrealizedROI_index,
5762
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
5763
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
5592
5764
  rows
5593
5765
  };
5594
5766
  }
@@ -5751,13 +5923,9 @@ var PortfolioCalculator = class extends BaseCalculator {
5751
5923
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo) {
5752
5924
  return null;
5753
5925
  }
5754
- const totallCrossUnsettledPnL = positions3.rows.reduce(
5755
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
5756
- 0
5757
- );
5758
- const totalUnsettlementPnL = positions3.rows.reduce(
5759
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
5760
- 0
5926
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
5927
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(
5928
+ positions3
5761
5929
  );
5762
5930
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
5763
5931
  const [USDC_holding, nonUSDC] = parseHolding(
@@ -5769,7 +5937,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5769
5937
  const totalCollateral = perp.account.totalCollateral({
5770
5938
  USDCHolding: USDC_holding,
5771
5939
  nonUSDCHolding: nonUSDC,
5772
- unsettlementPnL: totallCrossUnsettledPnL,
5940
+ unsettlementPnL: unsettledCrossPnL,
5773
5941
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
5774
5942
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
5775
5943
  });
@@ -5780,7 +5948,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5780
5948
  return acc.add(curr.margin ?? 0);
5781
5949
  }, utils.zero);
5782
5950
  const totalValue = perp.account.totalValue({
5783
- totalUnsettlementPnL,
5951
+ totalUnsettlementPnL: unsettledPnL,
5784
5952
  USDCHolding: USDC_holding,
5785
5953
  nonUSDCHolding: nonUSDC,
5786
5954
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -5824,7 +5992,7 @@ var PortfolioCalculator = class extends BaseCalculator {
5824
5992
  totalUnrealizedROI,
5825
5993
  freeCollateral,
5826
5994
  availableBalance,
5827
- unsettledPnL: totalUnsettlementPnL,
5995
+ unsettledPnL,
5828
5996
  holding,
5829
5997
  usdcHolding: USDC_holding,
5830
5998
  freeCollateralUSDCOnly
@@ -5943,7 +6111,7 @@ var usePositionStream = (symbol = "all", options) => {
5943
6111
  total_unreal_pnl: total_unreal_pnl_index,
5944
6112
  unrealPnlROI: unrealPnlROI_index
5945
6113
  };
5946
- }, [calcMode]);
6114
+ }, [calcMode, formattedPositions]);
5947
6115
  let rows = formattedPositions[0];
5948
6116
  {
5949
6117
  if (!rows) {
@@ -6433,14 +6601,8 @@ function formatPortfolio(inputs) {
6433
6601
  if (!holding || !positions3 || !Array.isArray(positions3.rows) || !markPrices || !indexPrices || !accountInfo || symbolsInfo?.isNil) {
6434
6602
  return null;
6435
6603
  }
6436
- const totallCrossUnsettledPnL = positions3.rows.reduce(
6437
- (sum, pos) => pos.margin_mode === types.MarginMode.ISOLATED ? sum : sum + (pos.unsettled_pnl ?? 0),
6438
- 0
6439
- );
6440
- const totalUnsettlementPnL = positions3.rows.reduce(
6441
- (sum, pos) => sum + (pos.unsettled_pnl ?? 0),
6442
- 0
6443
- );
6604
+ const unsettledPnL = ramda.pathOr(0, ["total_unsettled_pnl"])(positions3);
6605
+ const unsettledCrossPnL = ramda.pathOr(0, ["total_unsettled_cross_pnl"])(positions3);
6444
6606
  const unrealizedPnL = ramda.pathOr(0, ["total_unreal_pnl"])(positions3);
6445
6607
  const [USDC_holding, nonUSDC] = parseHolding(
6446
6608
  holding,
@@ -6451,7 +6613,7 @@ function formatPortfolio(inputs) {
6451
6613
  const totalCollateral = perp.account.totalCollateral({
6452
6614
  USDCHolding: USDC_holding,
6453
6615
  nonUSDCHolding: nonUSDC,
6454
- unsettlementPnL: totallCrossUnsettledPnL,
6616
+ unsettlementPnL: unsettledCrossPnL,
6455
6617
  usdcBalancePendingShortQty: usdc?.pending_short ?? 0,
6456
6618
  usdcBalanceIsolatedOrderFrozen: usdc?.isolated_order_frozen ?? 0
6457
6619
  });
@@ -6462,7 +6624,7 @@ function formatPortfolio(inputs) {
6462
6624
  return acc.add(curr.margin ?? 0);
6463
6625
  }, utils.zero);
6464
6626
  const totalValue = perp.account.totalValue({
6465
- totalUnsettlementPnL,
6627
+ totalUnsettlementPnL: unsettledPnL,
6466
6628
  USDCHolding: USDC_holding,
6467
6629
  nonUSDCHolding: nonUSDC,
6468
6630
  totalIsolatedPositionMargin: sumIsolatedMargin.toNumber()
@@ -6506,7 +6668,7 @@ function formatPortfolio(inputs) {
6506
6668
  totalUnrealizedROI,
6507
6669
  freeCollateral,
6508
6670
  availableBalance,
6509
- unsettledPnL: totalUnsettlementPnL,
6671
+ unsettledPnL,
6510
6672
  holding,
6511
6673
  freeCollateralUSDCOnly
6512
6674
  };
@@ -6515,7 +6677,7 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6515
6677
  if (!accountInfo || !fundingRates || !symbolsInfo) {
6516
6678
  return data;
6517
6679
  }
6518
- 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;
6519
6681
  const rows = data.rows.map((item) => {
6520
6682
  const info = symbolsInfo[item.symbol];
6521
6683
  const notional = perp.positions.notional(item.position_qty, item.mark_price);
@@ -6577,6 +6739,12 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6577
6739
  unrealPnL_total_index = unrealPnL_total_index.add(unrealPnl_index);
6578
6740
  notional_total = notional_total.add(notional);
6579
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
+ }
6580
6748
  return {
6581
6749
  ...item,
6582
6750
  mm: perp.positions.maintenanceMargin({
@@ -6590,7 +6758,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6590
6758
  unrealized_pnl: unrealPnl,
6591
6759
  unrealized_pnl_index: unrealPnl_index,
6592
6760
  unrealized_pnl_ROI: unrealPnlROI,
6593
- unrealized_pnl_ROI_index: unrealPnlROI_index
6761
+ unrealized_pnl_ROI_index: unrealPnlROI_index,
6762
+ unsettled_pnl: unsettlementPnL2
6594
6763
  };
6595
6764
  });
6596
6765
  const totalUnrealPnl = unrealPnL_total.toNumber();
@@ -6604,6 +6773,8 @@ function formatPositions(data, accountInfo, symbolsInfo, fundingRates) {
6604
6773
  notional: notional_total.toNumber(),
6605
6774
  unsettledPnL: unsettlementPnL,
6606
6775
  total_unsettled_pnl: unsettlementPnL,
6776
+ total_unsettled_cross_pnl: totalUnsettledCrossPnl.toNumber(),
6777
+ total_unsettled_isolated_pnl: totalUnsettledIsolatedPnl.toNumber(),
6607
6778
  rows
6608
6779
  };
6609
6780
  }
@@ -7986,7 +8157,9 @@ var useDeposit = (options) => {
7986
8157
  const depositPromise = isNativeToken ? account9.assetsManager.depositNativeToken(inputs) : account9.assetsManager.deposit(inputs);
7987
8158
  return depositPromise.then((result) => {
7988
8159
  updateAllowanceWhenTxSuccess(result.hash);
7989
- setBalance((value) => new utils.Decimal(value).sub(quantity).toString());
8160
+ setBalance(
8161
+ (value) => value ? new utils.Decimal(value).sub(quantity).toString() : "0"
8162
+ );
7990
8163
  track2(types.TrackerEventName.depositSuccess, {
7991
8164
  wallet: state?.connectWallet?.name,
7992
8165
  network: targetChain?.network_infos.name,
@@ -8038,16 +8211,16 @@ var useDeposit = (options) => {
8038
8211
  };
8039
8212
  function useBalance(options) {
8040
8213
  const { srcToken, address, decimals, account: account9, status } = options;
8041
- const [balance, setBalance] = React.useState("0");
8214
+ const [balance, setBalance] = React.useState(null);
8042
8215
  const fetchBalance = React.useCallback(
8043
8216
  async (address2, decimals2) => {
8044
8217
  try {
8045
8218
  if (types.isNativeTokenChecker(address2)) {
8046
- return account9.assetsManager.getNativeBalance({
8219
+ return await account9.assetsManager.getNativeBalance({
8047
8220
  decimals: decimals2
8048
8221
  });
8049
8222
  }
8050
- return account9.assetsManager.getBalance(address2, {
8223
+ return await account9.assetsManager.getBalance(address2, {
8051
8224
  decimals: decimals2
8052
8225
  });
8053
8226
  } catch (err) {
@@ -8096,11 +8269,13 @@ function useBalance(options) {
8096
8269
  React.useEffect(() => {
8097
8270
  if (swrBalance !== void 0) {
8098
8271
  setBalance(swrBalance || "0");
8272
+ } else {
8273
+ setBalance(null);
8099
8274
  }
8100
- }, [swrBalance]);
8275
+ }, [swrBalance, address]);
8101
8276
  return {
8102
8277
  balance,
8103
- balanceRevalidating,
8278
+ balanceRevalidating: balanceRevalidating || balance === null,
8104
8279
  setBalance,
8105
8280
  fetchBalance,
8106
8281
  fetchBalances
@@ -9630,6 +9805,9 @@ var PriceValidationStrategy = class {
9630
9805
  }
9631
9806
  const price = new utils.Decimal(order_price);
9632
9807
  const { symbol } = config;
9808
+ if (!symbol) {
9809
+ return;
9810
+ }
9633
9811
  const { quote_max, quote_min, quote_dp, price_range, price_scope } = symbol;
9634
9812
  const maxPriceNumber = perp.order.maxPrice(config.markPrice, price_range);
9635
9813
  const minPriceNumber = perp.order.minPrice(config.markPrice, price_range);
@@ -9676,6 +9854,9 @@ var TriggerPriceValidationStrategy = class {
9676
9854
  validate(values, config) {
9677
9855
  const { trigger_price } = values;
9678
9856
  const { symbol } = config;
9857
+ if (!symbol) {
9858
+ return;
9859
+ }
9679
9860
  const { quote_max, quote_min } = symbol;
9680
9861
  if (!trigger_price) {
9681
9862
  return OrderValidation.required("trigger_price");
@@ -9722,6 +9903,9 @@ var QuantityValidationStrategy = class {
9722
9903
  validate(values, config) {
9723
9904
  let { order_quantity, total, order_price } = values;
9724
9905
  const { maxQty, symbol } = config;
9906
+ if (!symbol) {
9907
+ return;
9908
+ }
9725
9909
  const { base_min, base_dp, quote_dp } = symbol;
9726
9910
  if (!order_quantity && total && order_price) {
9727
9911
  const totalNumber = new utils.Decimal(total);
@@ -10922,7 +11106,11 @@ var tpslFields = [
10922
11106
  "tp_offset",
10923
11107
  "sl_offset",
10924
11108
  "tp_offset_percentage",
10925
- "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"
10926
11114
  ];
10927
11115
  var isBracketOrder = (order) => {
10928
11116
  return !!order.tp_trigger_price || !!order.sl_trigger_price;
@@ -10977,7 +11165,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
10977
11165
  totalCollateral,
10978
11166
  futures_taker_fee_rate,
10979
11167
  positions: positions3,
10980
- // leverage,
11168
+ symbolLeverage,
10981
11169
  sumUnitaryFunding
10982
11170
  } = inputs;
10983
11171
  const orderFee = perp.order.orderFee({
@@ -11002,7 +11190,7 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
11002
11190
  }
11003
11191
  });
11004
11192
  } else {
11005
- let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = 1;
11193
+ let isolatedPositionMargin = 0, costPosition = 0, positionQty = 0, lastSumUnitaryFunding = 0, leverage = symbolLeverage ?? 1;
11006
11194
  if (positions3) {
11007
11195
  const position = positions3.find(
11008
11196
  (p) => p.symbol === symbol && p.margin_mode === types.MarginMode.ISOLATED
@@ -11138,6 +11326,8 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
11138
11326
  entryPrice: position.average_open_price,
11139
11327
  qty: side === types.OrderSide.BUY ? Number(prev.quantity) : -Number(prev.quantity),
11140
11328
  orderSide: side,
11329
+ markPrice: markPrice ?? position.average_open_price,
11330
+ // use mark price as the default value
11141
11331
  values: prev
11142
11332
  },
11143
11333
  {
@@ -12692,6 +12882,12 @@ var DataPaint = class extends BasePaint {
12692
12882
  this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
12693
12883
  this.transformTop = 0;
12694
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";
12695
12891
  }
12696
12892
  async draw(options) {
12697
12893
  const needDrawDetails = Array.isArray(options.data?.position?.informations) && (options.data?.position?.informations?.length ?? 0) > 0;
@@ -12778,6 +12974,49 @@ var DataPaint = class extends BasePaint {
12778
12974
  fontSize: this._ratio(fontSize),
12779
12975
  fontFamily: options.fontFamily
12780
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
+ }
12781
13020
  }
12782
13021
  const marginMode = options.data?.position.marginMode;
12783
13022
  if (marginMode) {
@@ -12792,7 +13031,7 @@ var DataPaint = class extends BasePaint {
12792
13031
  });
12793
13032
  }
12794
13033
  left += (prevElementBoundingBox.width ?? 0) + this._ratio(7);
12795
- const marginModeText = marginMode.charAt(0).toUpperCase() + marginMode.slice(1);
13034
+ const marginModeText = this.formatMarginMode(marginMode);
12796
13035
  prevElementBoundingBox = this._drawText(marginModeText, {
12797
13036
  color: layout.color,
12798
13037
  left,
@@ -12825,6 +13064,20 @@ var DataPaint = class extends BasePaint {
12825
13064
  );
12826
13065
  }
12827
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
+ }
12828
13081
  drawUnrealizedPnL(options, offsetTop = 0) {
12829
13082
  const layout = ramda.path(
12830
13083
  ["layout", "unrealizedPnl"],
@@ -13278,18 +13531,6 @@ var useEpochInfo = (type) => {
13278
13531
  }, [epochInfo]);
13279
13532
  return [epochInfo, { isLoading, curEpochInfo, isNotStared, refresh }];
13280
13533
  };
13281
-
13282
- // src/trading-rewards/useAllBrokers.ts
13283
- var useAllBrokers = () => {
13284
- const { data } = useQuery("/v1/public/broker/name", {
13285
- formatter: (res) => {
13286
- const { rows } = res;
13287
- return rows?.map((item) => ({ [item.broker_id]: item.broker_name })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
13288
- },
13289
- revalidateOnFocus: false
13290
- });
13291
- return [data];
13292
- };
13293
13534
  var useCurEpochEstimate = (type) => {
13294
13535
  const [data, setData] = React.useState(void 0);
13295
13536
  const { account: account9 } = useAccount();
@@ -18425,108 +18666,69 @@ var initialOrderState = {
18425
18666
  tp_trigger_price: "",
18426
18667
  sl_trigger_price: "",
18427
18668
  total: "",
18428
- symbol: ""
18669
+ symbol: "",
18670
+ side: types.OrderSide.BUY,
18671
+ order_type: types.OrderType.LIMIT,
18672
+ margin_mode: types.MarginMode.CROSS
18429
18673
  };
18430
- var useOrderStore = zustand.create()(
18431
- immer.immer((set, get3) => ({
18432
- entry: {
18433
- side: types.OrderSide.BUY,
18434
- order_type: types.OrderType.LIMIT,
18435
- ...initialOrderState
18436
- },
18437
- estLeverage: null,
18438
- estLiquidationPrice: null,
18439
- errors: {},
18440
- actions: {
18441
- initOrder: (symbol, options) => {
18442
- set((state) => {
18443
- state.entry = {
18444
- ...initialOrderState,
18445
- symbol,
18446
- side: options?.side ?? types.OrderSide.BUY,
18447
- order_type: options?.order_type ?? types.OrderType.LIMIT,
18448
- margin_mode: options?.margin_mode ?? types.MarginMode.CROSS
18449
- };
18450
- state.estLeverage = null;
18451
- state.estLiquidationPrice = null;
18452
- state.errors = {};
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
18453
18692
  });
18454
18693
  },
18455
- hasTP_SL: () => {
18456
- const order = get3().entry;
18457
- return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18458
- },
18459
- updateOrderComputed: (data) => {
18460
- set(
18461
- (state) => {
18462
- state.estLeverage = data.estLeverage;
18463
- state.estLiquidationPrice = data.estLiquidationPrice;
18464
- },
18465
- false
18466
- // "updateOrderComputed"
18467
- );
18468
- },
18469
18694
  updateOrder: (order) => {
18470
- set(
18471
- (state) => {
18472
- state.entry = {
18473
- ...state.entry,
18474
- ...order
18475
- };
18476
- },
18477
- false
18478
- // "updateOrder"
18479
- );
18695
+ setOrderEntity((prev) => ({ ...prev, ...order }));
18480
18696
  },
18481
18697
  updateOrderByKey: (key, value) => {
18482
- set(
18483
- (state) => {
18484
- state.entry[key] = value;
18485
- },
18486
- false
18487
- // "updateOrderByKey"
18488
- );
18489
- },
18490
- restoreOrder: (order) => {
18491
- set(
18492
- (state) => {
18493
- state.entry = order;
18494
- },
18495
- false
18496
- // "restoreOrder"
18497
- );
18698
+ setOrderEntity((prev) => ({ ...prev, [key]: value }));
18498
18699
  },
18499
18700
  resetOrder: (_order) => {
18500
- set(
18501
- (state) => {
18502
- state.entry.order_price = "";
18503
- state.entry.order_quantity = "";
18504
- state.entry.trigger_price = "";
18505
- state.entry.total = "";
18506
- state.entry.tp_trigger_price = "";
18507
- state.entry.tp_pnl = "";
18508
- state.entry.tp_offset = "";
18509
- state.entry.tp_offset_percentage = "";
18510
- state.entry.sl_trigger_price = "";
18511
- state.entry.sl_pnl = "";
18512
- state.entry.sl_offset = "";
18513
- state.entry.sl_offset_percentage = "";
18514
- },
18515
- true
18516
- // "resetOrder"
18517
- );
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";
18518
18724
  }
18519
- }
18520
- }))
18521
- );
18522
- var useOrderEntryNextInternal = (symbol, options = {}) => {
18523
- const { symbolInfo, symbolLeverage } = options;
18524
- const orderEntity = useOrderStore((state) => state.entry);
18525
- const orderEntryActions = useOrderStore((state) => state.actions);
18725
+ }),
18726
+ [orderEntity]
18727
+ );
18526
18728
  React.useEffect(() => {
18527
- orderEntryActions.initOrder(symbol, options.initialOrder);
18729
+ actions.initOrder(symbol, options.initialOrder);
18528
18730
  if (options.initialOrder) {
18529
- orderEntryActions.updateOrder(options.initialOrder);
18731
+ actions.updateOrder(options.initialOrder);
18530
18732
  }
18531
18733
  }, [symbol]);
18532
18734
  const calculate2 = React.useCallback(
@@ -18544,10 +18746,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18544
18746
  );
18545
18747
  const setValue = (key, value, additional) => {
18546
18748
  if (!symbolInfo) {
18547
- orderEntryActions.updateOrderByKey(key, value);
18749
+ actions.updateOrderByKey(key, value);
18548
18750
  return;
18549
18751
  }
18550
- const currentEntry = useOrderStore.getState().entry;
18752
+ const currentEntry = orderEntity;
18551
18753
  const { markPrice } = additional ?? { markPrice: 0 };
18552
18754
  let newValues = calculate2(
18553
18755
  { ...currentEntry },
@@ -18581,7 +18783,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18581
18783
  if (sl_ROI) {
18582
18784
  newValues.sl_ROI = sl_ROI;
18583
18785
  }
18584
- orderEntryActions.updateOrder(newValues);
18786
+ actions.updateOrder(newValues);
18585
18787
  return newValues;
18586
18788
  };
18587
18789
  const calculateTPSL = (key, newValues, markPrice, symbolInfo2) => {
@@ -18604,6 +18806,42 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18604
18806
  symbolInfo2
18605
18807
  );
18606
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
+ }
18607
18845
  } else {
18608
18846
  if (typeof newValues.tp_trigger_price !== "undefined") {
18609
18847
  newValues = calculate2(
@@ -18623,16 +18861,51 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18623
18861
  symbolInfo2
18624
18862
  );
18625
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
+ }
18626
18900
  }
18627
18901
  return newValues;
18628
18902
  };
18629
18903
  const setValues = (values, additional) => {
18630
18904
  if (!symbolInfo) {
18631
- orderEntryActions.updateOrder(values);
18905
+ actions.updateOrder(values);
18632
18906
  return;
18633
18907
  }
18634
- const currentEntry = useOrderStore.getState().entry;
18635
- let newValues = { ...currentEntry };
18908
+ let newValues = { ...orderEntity };
18636
18909
  Object.keys(values).forEach((key) => {
18637
18910
  newValues = calculate2(
18638
18911
  newValues,
@@ -18642,17 +18915,28 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18642
18915
  symbolInfo
18643
18916
  );
18644
18917
  });
18645
- 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);
18646
18931
  return newValues;
18647
18932
  };
18648
18933
  const onMarkPriceUpdated = React.useCallback(
18649
18934
  (markPrice, baseOn = []) => {
18650
18935
  if (!options.symbolInfo) return;
18651
- const currentEntry = useOrderStore.getState().entry;
18652
- let newValues = { ...currentEntry };
18936
+ let newValues = { ...orderEntity };
18653
18937
  if (baseOn.length === 0) {
18654
18938
  newValues = calculate2(
18655
- { ...currentEntry },
18939
+ { ...orderEntity },
18656
18940
  "order_price",
18657
18941
  markPrice,
18658
18942
  markPrice,
@@ -18663,7 +18947,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18663
18947
  newValues = calculate2(
18664
18948
  { ...newValues },
18665
18949
  key,
18666
- currentEntry[key],
18950
+ orderEntity[key],
18667
18951
  markPrice,
18668
18952
  options.symbolInfo
18669
18953
  );
@@ -18682,9 +18966,9 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18682
18966
  newValues.sl_ROI = sl_ROI;
18683
18967
  }
18684
18968
  }
18685
- orderEntryActions.updateOrder(newValues);
18969
+ actions.updateOrder(newValues);
18686
18970
  },
18687
- [calculate2, options.symbolInfo, orderEntryActions]
18971
+ [calculate2, options.symbolInfo, symbolLeverage, orderEntity]
18688
18972
  );
18689
18973
  const validate = (order, creator, options2) => {
18690
18974
  return creator?.validate(order, {
@@ -18702,12 +18986,13 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18702
18986
  const submitOrder = React.useCallback(() => {
18703
18987
  }, [orderEntity]);
18704
18988
  const resetOrder = (order) => {
18705
- orderEntryActions.resetOrder(order);
18989
+ actions.resetOrder(order);
18706
18990
  };
18707
18991
  return {
18708
18992
  formattedOrder: orderEntity,
18709
18993
  setValue,
18710
18994
  setValues,
18995
+ setValuesRaw,
18711
18996
  submit: submitOrder,
18712
18997
  reset: resetOrder,
18713
18998
  generateOrder,
@@ -18723,6 +19008,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
18723
19008
  }
18724
19009
  const ee = useEventEmitter();
18725
19010
  const { track: track2 } = useTrack();
19011
+ const apiBaseUrl = useConfig("apiBaseUrl");
19012
+ const fetchSymbols = useSymbolStore((state) => state.fetchData);
18726
19013
  const [meta, setMeta] = React.useState({
18727
19014
  dirty: {},
18728
19015
  submitted: false,
@@ -18742,8 +19029,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18742
19029
  const symbolConfig = useSymbolsInfo();
18743
19030
  const accountInfo = useAccountInfo();
18744
19031
  const positions3 = usePositions();
18745
- const entry = useOrderStore((s) => s.entry);
18746
- const effectiveMarginMode = options?.initialOrder?.margin_mode ?? entry?.margin_mode ?? types.MarginMode.CROSS;
19032
+ const effectiveMarginMode = options?.initialOrder?.margin_mode ?? types.MarginMode.CROSS;
18747
19033
  const symbolLeverage = useLeverageBySymbol(symbol, effectiveMarginMode);
18748
19034
  const symbolInfo = symbolConfig[symbol]();
18749
19035
  const markPrice = actions.getMarkPriceBySymbol(symbol);
@@ -18752,6 +19038,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18752
19038
  formattedOrder,
18753
19039
  setValue: setValueInternal,
18754
19040
  setValues: setValuesInternal,
19041
+ setValuesRaw: setValuesRawInternal,
18755
19042
  validate,
18756
19043
  generateOrder,
18757
19044
  reset,
@@ -18976,6 +19263,21 @@ var useOrderEntry2 = (symbol, options = {}) => {
18976
19263
  interactiveValidate(newValues);
18977
19264
  }
18978
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
+ };
18979
19281
  async function validateFunc(order) {
18980
19282
  const creator = getOrderCreator(order);
18981
19283
  return validate(order, creator, prepareData());
@@ -19030,11 +19332,12 @@ var useOrderEntry2 = (symbol, options = {}) => {
19030
19332
  markPrice: markPrice2,
19031
19333
  totalCollateral,
19032
19334
  futures_taker_fee_rate: accountInfo.futures_taker_fee_rate,
19033
- imr_factor: accountInfo.imr_factor[symbol],
19335
+ imr_factor: accountInfo.imr_factor?.[symbol] ?? 0,
19034
19336
  symbol,
19035
19337
  positions: positions3,
19036
19338
  symbolInfo,
19037
- sumUnitaryFunding
19339
+ sumUnitaryFunding,
19340
+ symbolLeverage
19038
19341
  });
19039
19342
  return estLiqPrice2;
19040
19343
  }, [
@@ -19045,7 +19348,8 @@ var useOrderEntry2 = (symbol, options = {}) => {
19045
19348
  symbol,
19046
19349
  maxQty,
19047
19350
  symbolInfo,
19048
- fundingRates
19351
+ fundingRates,
19352
+ symbolLeverage
19049
19353
  ]);
19050
19354
  const estLiqPriceDistance = React.useMemo(() => {
19051
19355
  if (!estLiqPrice) {
@@ -19117,6 +19421,9 @@ var useOrderEntry2 = (symbol, options = {}) => {
19117
19421
  orders: appendOrderMetadata(order.orders, orderMetadata)
19118
19422
  } : appendOrderMetadata(order, orderMetadata);
19119
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
+ }
19120
19427
  if (result.success) {
19121
19428
  let trackParams = {
19122
19429
  side: order.side,
@@ -19184,6 +19491,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
19184
19491
  freeCollateral: effectiveMarginMode === types.MarginMode.ISOLATED ? freeCollateralUSDCOnly : freeCollateral,
19185
19492
  setValue: useMemoizedFn(setValue),
19186
19493
  setValues: useMemoizedFn(setValues),
19494
+ setValuesRaw: useMemoizedFn(setValuesRaw),
19187
19495
  symbolInfo: symbolInfo || types.EMPTY_OBJECT,
19188
19496
  metaState: meta,
19189
19497
  isMutating,
@@ -19191,6 +19499,107 @@ var useOrderEntry2 = (symbol, options = {}) => {
19191
19499
  symbolLeverage
19192
19500
  };
19193
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
+ );
19194
19603
  var useOrderEntity = (order, options) => {
19195
19604
  const { symbol } = order;
19196
19605
  const { maxQty } = options || {};
@@ -19467,6 +19876,7 @@ var useTpslPriceChecker = (params) => {
19467
19876
  slPrice,
19468
19877
  liqPrice,
19469
19878
  side,
19879
+ markPrice,
19470
19880
  currentPosition,
19471
19881
  orderQuantity
19472
19882
  } = params;
@@ -19522,6 +19932,17 @@ var useTpslPriceChecker = (params) => {
19522
19932
  if (slPrice === void 0 || liqPrice === void 0 || side === void 0 || liqPrice === null) {
19523
19933
  return null;
19524
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
+ }
19525
19946
  let slPriceDecimal;
19526
19947
  let liqPriceDecimal;
19527
19948
  try {
@@ -19548,6 +19969,7 @@ var useTpslPriceChecker = (params) => {
19548
19969
  slPrice,
19549
19970
  liqPrice,
19550
19971
  side,
19972
+ markPrice,
19551
19973
  warning_threshold,
19552
19974
  currentPosition,
19553
19975
  orderQuantity
@@ -19665,6 +20087,7 @@ exports.EpochStatus = EpochStatus;
19665
20087
  exports.ExtendedConfigStore = ExtendedConfigStore;
19666
20088
  exports.FlagKeys = FlagKeys;
19667
20089
  exports.MaintenanceStatus = MaintenanceStatus;
20090
+ exports.MarketCategoriesConfigProvider = MarketCategoriesConfigProvider;
19668
20091
  exports.MarketsStorageKey = MarketsStorageKey;
19669
20092
  exports.MarketsType = MarketsType;
19670
20093
  exports.ORDERLY_ORDERBOOK_DEPTH_KEY = ORDERLY_ORDERBOOK_DEPTH_KEY;
@@ -19681,6 +20104,7 @@ exports.fetcher = fetcher;
19681
20104
  exports.findPositionTPSLFromOrders = findPositionTPSLFromOrders;
19682
20105
  exports.findTPSLFromOrder = findTPSLFromOrder;
19683
20106
  exports.findTPSLOrderPriceFromOrder = findTPSLOrderPriceFromOrder;
20107
+ exports.formatSymbolWithBroker = formatSymbolWithBroker;
19684
20108
  exports.getMinNotional = getMinNotional;
19685
20109
  exports.getPriceKey = getPriceKey;
19686
20110
  exports.indexedDBManager = indexedDBManager;
@@ -19701,6 +20125,7 @@ exports.useApiKeyManager = useApiKeyManager;
19701
20125
  exports.useAppStore = useAppStore;
19702
20126
  exports.useAssetsHistory = useAssetsHistory;
19703
20127
  exports.useAudioPlayer = useAudioPlayer;
20128
+ exports.useBadgeBySymbol = useBadgeBySymbol;
19704
20129
  exports.useBalanceSubscription = useBalanceSubscription;
19705
20130
  exports.useBalanceTopic = useBalanceTopic;
19706
20131
  exports.useBoolean = useBoolean;
@@ -19759,6 +20184,7 @@ exports.useMarkPrice = useMarkPrice;
19759
20184
  exports.useMarkPriceBySymbol = useMarkPriceBySymbol;
19760
20185
  exports.useMarkPricesStream = useMarkPricesStream;
19761
20186
  exports.useMarket = useMarket;
20187
+ exports.useMarketCategoriesConfig = useMarketCategoriesConfig;
19762
20188
  exports.useMarketList = useMarketList;
19763
20189
  exports.useMarketMap = useMarketMap;
19764
20190
  exports.useMarketTradeStream = useMarketTradeStream;
@@ -19816,6 +20242,7 @@ exports.useSymbolInfo = useSymbolInfo;
19816
20242
  exports.useSymbolLeverage = useSymbolLeverage;
19817
20243
  exports.useSymbolLeverageMap = useSymbolLeverageMap;
19818
20244
  exports.useSymbolPriceRange = useSymbolPriceRange;
20245
+ exports.useSymbolWithBroker = useSymbolWithBroker;
19819
20246
  exports.useSymbolsInfo = useSymbolsInfo;
19820
20247
  exports.useSymbolsInfoStore = useSymbolsInfoStore;
19821
20248
  exports.useTPSLOrder = useTPSLOrder;