@orderly.network/hooks 2.8.10 → 2.8.11-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -38,9 +38,9 @@ var __export = (target, all) => {
38
38
  // src/version.ts
39
39
  if (typeof window !== "undefined") {
40
40
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
41
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.10";
41
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.11-alpha.1";
42
42
  }
43
- var version_default = "2.8.10";
43
+ var version_default = "2.8.11-alpha.1";
44
44
  var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
45
45
  var noCacheConfig = {
46
46
  dedupingInterval: 0,
@@ -484,8 +484,7 @@ var usePrivateInfiniteQuery = (getKey, options) => {
484
484
  const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
485
485
  const result = useSWRInfinite(
486
486
  (pageIndex, previousPageData) => {
487
- if (!getKey)
488
- return null;
487
+ if (!getKey) return null;
489
488
  const queryKey = getKey(pageIndex, previousPageData);
490
489
  if (queryKey && (state.status >= AccountStatusEnum.EnableTrading || state.status === AccountStatusEnum.EnableTradingWithoutConnected)) {
491
490
  return [queryKey, state.accountId];
@@ -530,8 +529,8 @@ var useUpdatedRef = (val) => {
530
529
  return latestRef;
531
530
  };
532
531
  var useMemoizedFn = (fn) => {
533
- const safeFn = typeof fn === "function" ? fn : () => {
534
- };
532
+ const safeFn = typeof fn === "function" ? fn : (() => {
533
+ });
535
534
  const fnRef = useRef(safeFn);
536
535
  fnRef.current = useMemo(() => safeFn, [safeFn]);
537
536
  const wrapperRef = useRef(null);
@@ -1112,8 +1111,7 @@ var findPositionTPSLFromOrders = (orders, symbol) => {
1112
1111
  };
1113
1112
  function offsetToPrice(inputs) {
1114
1113
  const { qty, offset, entryPrice, orderType, orderSide } = inputs;
1115
- if (!offset)
1116
- return;
1114
+ if (!offset) return;
1117
1115
  if (orderSide === OrderSide.BUY) {
1118
1116
  if (orderType === AlgoOrderType.TAKE_PROFIT) {
1119
1117
  return new Decimal(entryPrice).add(new Decimal(offset)).toNumber();
@@ -1150,8 +1148,7 @@ function priceToOffset(inputs, options = {}) {
1150
1148
  }
1151
1149
  function offsetPercentageToPrice(inputs) {
1152
1150
  const { qty, percentage, entryPrice, orderType, orderSide } = inputs;
1153
- if (!percentage)
1154
- return;
1151
+ if (!percentage) return;
1155
1152
  if (orderSide === OrderSide.BUY) {
1156
1153
  if (orderType === AlgoOrderType.TAKE_PROFIT) {
1157
1154
  return new Decimal(1).add(new Decimal(percentage)).mul(new Decimal(entryPrice)).toNumber();
@@ -1174,16 +1171,14 @@ function priceToOffsetPercentage(inputs) {
1174
1171
  orderPrice: entryPrice
1175
1172
  });
1176
1173
  if (orderSide === OrderSide.BUY) {
1177
- if (entryPrice === 0)
1178
- return 0;
1174
+ if (entryPrice === 0) return 0;
1179
1175
  if (orderType === AlgoOrderType.TAKE_PROFIT) {
1180
1176
  return new Decimal(price).div(new Decimal(entryPrice)).minus(1).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
1181
1177
  }
1182
1178
  return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
1183
1179
  }
1184
1180
  if (orderSide === OrderSide.SELL) {
1185
- if (entryPrice === 0)
1186
- return 0;
1181
+ if (entryPrice === 0) return 0;
1187
1182
  if (orderType === AlgoOrderType.TAKE_PROFIT) {
1188
1183
  return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
1189
1184
  }
@@ -1195,8 +1190,7 @@ function pnlToPrice(inputs) {
1195
1190
  if (!pnl) {
1196
1191
  return;
1197
1192
  }
1198
- if (qty === 0)
1199
- return;
1193
+ if (qty === 0) return;
1200
1194
  if (orderSide === OrderSide.BUY) {
1201
1195
  if (orderType === AlgoOrderType.TAKE_PROFIT) {
1202
1196
  return new Decimal(entryPrice).plus(new Decimal(pnl).div(new Decimal(qty))).toNumber();
@@ -1278,8 +1272,7 @@ function priceToROI(inputs) {
1278
1272
  function calcTPSL_ROI(inputs) {
1279
1273
  const qtyNum = Number(inputs.qty);
1280
1274
  const priceNum = Number(inputs.price);
1281
- if (qtyNum === 0 || priceNum === 0)
1282
- return "0";
1275
+ if (qtyNum === 0 || priceNum === 0) return "0";
1283
1276
  return new Decimal(inputs.pnl).div(new Decimal(qtyNum).abs().mul(new Decimal(priceNum))).toString();
1284
1277
  }
1285
1278
  function checkTPSLOrderTypeIsMarket(key, values) {
@@ -1328,6 +1321,31 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1328
1321
  }
1329
1322
  break;
1330
1323
  }
1324
+ // case "tp_enable":
1325
+ // case "sl_enable": {
1326
+ // return {
1327
+ // [`${keyPrefix}enable`]: inputs.value,
1328
+ // [`${keyPrefix}order_type`]: OrderType.MARKET,
1329
+ // [`${keyPrefix}trigger_price`]: "",
1330
+ // [`${keyPrefix}order_price`]: "",
1331
+ // [`${keyPrefix}offset`]: "",
1332
+ // [`${keyPrefix}offset_percentage`]: "",
1333
+ // [`${keyPrefix}pnl`]: "",
1334
+ // [`${keyPrefix}ROI`]: "",
1335
+ // };
1336
+ // }
1337
+ // case 'tp_pnl':{
1338
+ // if (inputs.values.tp_order_type !== OrderType.MARKET) {
1339
+ // pnl = inputs.value;
1340
+ // trigger_price = pnlToPrice({
1341
+ // qty,
1342
+ // pnl: Number(inputs.value),
1343
+ // entryPrice,
1344
+ // orderSide: inputs.orderSide,
1345
+ // orderType,
1346
+ // })
1347
+ // }
1348
+ // }
1331
1349
  case "tp_pnl":
1332
1350
  case "sl_pnl": {
1333
1351
  pnl = inputs.value;
@@ -1676,6 +1694,8 @@ var getCalculateHandler = (fieldName) => {
1676
1694
  case "total": {
1677
1695
  return totalInputHandle;
1678
1696
  }
1697
+ // case "tp_enable":
1698
+ // case "sl_enable":
1679
1699
  case "tp_pnl":
1680
1700
  case "sl_pnl":
1681
1701
  case "tp_trigger_price":
@@ -1694,17 +1714,14 @@ var getCalculateHandler = (fieldName) => {
1694
1714
  }
1695
1715
  };
1696
1716
  function formatNumber(qty, dp) {
1697
- if (typeof qty === "undefined")
1698
- return qty;
1699
- if (typeof dp === "undefined")
1700
- return `${qty}`;
1717
+ if (typeof qty === "undefined") return qty;
1718
+ if (typeof dp === "undefined") return `${qty}`;
1701
1719
  const _qty = `${qty}`.replace(/,/g, "");
1702
1720
  try {
1703
1721
  const _dp = new Decimal(dp);
1704
1722
  const _qtyDecimal = new Decimal(_qty);
1705
1723
  if (_dp.lessThan(1)) {
1706
- if (`${_qty}`.endsWith("."))
1707
- return `${_qty}`;
1724
+ if (`${_qty}`.endsWith(".")) return `${_qty}`;
1708
1725
  const numStr = dp.toString();
1709
1726
  const decimalIndex = numStr.indexOf(".");
1710
1727
  const digitsAfterDecimal = decimalIndex === -1 ? 0 : numStr.length - decimalIndex - 1;
@@ -2728,21 +2745,18 @@ var usePreLoadData = () => {
2728
2745
  });
2729
2746
  }, []);
2730
2747
  useEffect(() => {
2731
- if (!urlPrefix)
2732
- return;
2748
+ if (!urlPrefix) return;
2733
2749
  fetchTestTokens(urlPrefix);
2734
2750
  fetchTestChains(urlPrefix, {
2735
2751
  brokerId: configStore.get("brokerId")
2736
2752
  });
2737
2753
  }, [urlPrefix]);
2738
2754
  useEffect(() => {
2739
- if (!mainTokenInfo || !testTokenInfo)
2740
- return;
2755
+ if (!mainTokenInfo || !testTokenInfo) return;
2741
2756
  setTokensInfo(env === "prod" ? mainTokenInfo : testTokenInfo);
2742
2757
  }, [mainTokenInfo, testTokenInfo]);
2743
2758
  useEffect(() => {
2744
- if (swapSupportInfo || !enableSwapDeposit)
2745
- return;
2759
+ if (swapSupportInfo || !enableSwapDeposit) return;
2746
2760
  fetchSwapSupport();
2747
2761
  }, [swapSupportInfo, enableSwapDeposit]);
2748
2762
  const { data: systemInfo } = useSWR__default(
@@ -2760,8 +2774,7 @@ var usePreLoadData = () => {
2760
2774
  }
2761
2775
  );
2762
2776
  useEffect(() => {
2763
- if (timestampOffsetInitialized)
2764
- return;
2777
+ if (timestampOffsetInitialized) return;
2765
2778
  if (typeof systemInfo !== "undefined") {
2766
2779
  const serverTimestamp = systemInfo.timestamp;
2767
2780
  const localTimestamp = Date.now();
@@ -3037,8 +3050,7 @@ var AmplitudeTracker = class {
3037
3050
  this._userId = userId;
3038
3051
  }
3039
3052
  setSdkInfo(sdkInfo) {
3040
- if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag)
3041
- return;
3053
+ if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag) return;
3042
3054
  this.identify(sdkInfo);
3043
3055
  this._sdkInfoTag = sdkInfo.address;
3044
3056
  }
@@ -3166,6 +3178,10 @@ var DEFAULT_TICK_SIZES = {
3166
3178
  var DEFAULT_SYMBOL_DEPTHS = {
3167
3179
  PERP_ETH_USDC: [0.01, 0.1, 0.5, 1, 10]
3168
3180
  };
3181
+ var DEFAULT_SYMBOL_DISPLAY_NAMES = {
3182
+ PERP_XAU_USDC: "XAU (Gold) ",
3183
+ PERP_XAG_USDC: "XAG (Silver)"
3184
+ };
3169
3185
  var ProxyConfigStore = class {
3170
3186
  constructor(_originConfigStore) {
3171
3187
  this._originConfigStore = _originConfigStore;
@@ -3246,10 +3262,8 @@ var useMarketsStream = () => {
3246
3262
  };
3247
3263
  });
3248
3264
  const value = useMemo(() => {
3249
- if (!futures)
3250
- return null;
3251
- if (!tickers)
3252
- return futures;
3265
+ if (!futures) return null;
3266
+ if (!tickers) return futures;
3253
3267
  return futures.map((item) => {
3254
3268
  const ticker = tickers.find(
3255
3269
  (t) => t.symbol === item.symbol
@@ -3292,8 +3306,7 @@ function createGetter(data, depth = 2) {
3292
3306
  }
3293
3307
  if (depth === 1) {
3294
3308
  return (defaultValue) => {
3295
- if (!target)
3296
- return defaultValue;
3309
+ if (!target) return defaultValue;
3297
3310
  return getValue(target[property], defaultValue);
3298
3311
  };
3299
3312
  }
@@ -3634,6 +3647,7 @@ var addFieldToMarkets = (futures, symbolsInfo, rwaSymbolsInfo) => {
3634
3647
  ...item,
3635
3648
  quote_dp: info("quote_dp"),
3636
3649
  created_time: info("created_time"),
3650
+ displayName: info("displayName"),
3637
3651
  leverage: getLeverage(info("base_imr")),
3638
3652
  openInterest: getOpenInterest(item.open_interest, item.index_price),
3639
3653
  "8h_funding": get8hFunding(item.est_funding_rate, info("funding_period")),
@@ -3847,8 +3861,7 @@ var useWSObserver = (calculatorService) => {
3847
3861
  });
3848
3862
  const indexPriceSubscription = ws.subscribe("indexprices", {
3849
3863
  onMessage: (message) => {
3850
- if (!Array.isArray(message))
3851
- return;
3864
+ if (!Array.isArray(message)) return;
3852
3865
  const prices = /* @__PURE__ */ Object.create(null);
3853
3866
  for (let index = 0; index < message.length; index++) {
3854
3867
  const element = message[index];
@@ -4085,10 +4098,8 @@ var useTickerStream = (symbol) => {
4085
4098
  const { data: openInterest } = useOpenInterest(symbol);
4086
4099
  const marketMap = useMarketMap();
4087
4100
  const value = useMemo(() => {
4088
- if (!info)
4089
- return null;
4090
- if (!ticker || ticker.symbol !== symbol)
4091
- return info;
4101
+ if (!info) return null;
4102
+ if (!ticker || ticker.symbol !== symbol) return info;
4092
4103
  const config = {
4093
4104
  ...info,
4094
4105
  mark_price: markPrice,
@@ -5104,8 +5115,7 @@ var CalculatorService = class {
5104
5115
  if (!ctx.isReady && options?.skipPending) {
5105
5116
  return;
5106
5117
  }
5107
- if (options?.skipWhenOnPause && !this.windowIsVisible)
5108
- return;
5118
+ if (options?.skipWhenOnPause && !this.windowIsVisible) return;
5109
5119
  this.calcQueue.push({ scope, data, options });
5110
5120
  await this.handleCalcQueue(ctx);
5111
5121
  this.ctx = ctx;
@@ -5306,8 +5316,7 @@ var PositionCalculator = class extends BaseCalculator {
5306
5316
  return data;
5307
5317
  }
5308
5318
  update(data, scope) {
5309
- if (!data || !Array.isArray(data.rows))
5310
- return;
5319
+ if (!data || !Array.isArray(data.rows)) return;
5311
5320
  usePositionStore.getState().actions.setPositions(this.symbol, data);
5312
5321
  if (Array.isArray(data.rows) && useApiStatusStore.getState().apis.positions.loading) {
5313
5322
  useApiStatusStore.getState().actions.updateApiLoading("positions", false);
@@ -5346,8 +5355,7 @@ var PositionCalculator = class extends BaseCalculator {
5346
5355
  return this.format(positions3, ctx);
5347
5356
  }
5348
5357
  calcByPosition(positions3, ctx) {
5349
- if (positions3.rows.length === 0)
5350
- return positions3;
5358
+ if (positions3.rows.length === 0) return positions3;
5351
5359
  return this.format(positions3, ctx);
5352
5360
  }
5353
5361
  format(data, ctx) {
@@ -5560,8 +5568,7 @@ var IndexPriceCalculator = class extends BaseCalculator {
5560
5568
  return data;
5561
5569
  }
5562
5570
  update(data) {
5563
- if (!data)
5564
- return;
5571
+ if (!data) return;
5565
5572
  useIndexPriceStore.getState().actions.updateIndexPrice(data);
5566
5573
  }
5567
5574
  static getValue() {
@@ -5955,8 +5962,7 @@ var useOrderStream = (params, options) => {
5955
5962
  registerKeyHandler?.(key.replace("orders", "algoOrders"), algoOrderKeyFn);
5956
5963
  }
5957
5964
  return () => {
5958
- if (!options?.stopOnUnmount)
5959
- return;
5965
+ if (!options?.stopOnUnmount) return;
5960
5966
  unregisterKeyHandler(key);
5961
5967
  if (algoOrderKeyFn) {
5962
5968
  unregisterKeyHandler(key.replace("orders", "algoOrders"));
@@ -6522,8 +6528,7 @@ var useSubAccountDataObserver = (accountId) => {
6522
6528
  tokensInfo
6523
6529
  ]);
6524
6530
  useEffect(() => {
6525
- if (!positionsInfo)
6526
- return;
6531
+ if (!positionsInfo) return;
6527
6532
  if (positionsInfo.rows?.length === 0) {
6528
6533
  setPositions(positionsInfo);
6529
6534
  return;
@@ -6555,8 +6560,7 @@ var useSubAccountDataObserver = (accountId) => {
6555
6560
  }
6556
6561
  }, [holdingRes]);
6557
6562
  useEffect(() => {
6558
- if (!accountId)
6559
- return;
6563
+ if (!accountId) return;
6560
6564
  const unsubscribe = ws.privateSubscribe(
6561
6565
  {
6562
6566
  id: "balance",
@@ -6581,8 +6585,7 @@ var useSubAccountDataObserver = (accountId) => {
6581
6585
  return () => unsubscribe?.();
6582
6586
  }, [accountId]);
6583
6587
  useEffect(() => {
6584
- if (!accountId)
6585
- return;
6588
+ if (!accountId) return;
6586
6589
  const key = ["/v1/positions", accountId];
6587
6590
  const unsubscribe = ws.privateSubscribe("position", {
6588
6591
  onMessage: (data) => {
@@ -7066,8 +7069,7 @@ var useLeverageBySymbol = (symbol) => {
7066
7069
  }
7067
7070
  );
7068
7071
  useEffect(() => {
7069
- if (!state.accountId || !symbol)
7070
- return;
7072
+ if (!state.accountId || !symbol) return;
7071
7073
  const unsubscribe = ws.privateSubscribe("account", {
7072
7074
  onMessage: (data2) => {
7073
7075
  const res = data2?.accountDetail?.symbolLeverage || {};
@@ -7096,8 +7098,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
7096
7098
  const { data: markPrices } = useMarkPricesStream();
7097
7099
  const symbolLeverage = useLeverageBySymbol(symbol);
7098
7100
  const maxQty = useMemo(() => {
7099
- if (!symbol)
7100
- return 0;
7101
+ if (!symbol) return 0;
7101
7102
  const positionQty = account.getQtyFromPositions(
7102
7103
  positions3 === null ? [] : positions3,
7103
7104
  symbol
@@ -7200,7 +7201,20 @@ var useMarginRatio = () => {
7200
7201
  positionsNotional: notional
7201
7202
  });
7202
7203
  }, [rows, notional]);
7203
- return { marginRatio, currentLeverage, mmr };
7204
+ const maintenanceMargin = useMemo(() => {
7205
+ if (!rows || rows.length <= 0 || notional == null) {
7206
+ return null;
7207
+ }
7208
+ let maintenanceMargin2 = zero;
7209
+ for (let index = 0; index < rows.length; index++) {
7210
+ const item = rows[index];
7211
+ if (item.mm !== null) {
7212
+ maintenanceMargin2 = maintenanceMargin2.add(item.mm);
7213
+ }
7214
+ }
7215
+ return maintenanceMargin2.toNumber();
7216
+ }, [rows, notional]);
7217
+ return { marginRatio, currentLeverage, mmr, maintenanceMargin };
7204
7218
  };
7205
7219
  var TestNetWhiteList = [
7206
7220
  ARBITRUM_TESTNET_CHAINID,
@@ -7462,8 +7476,7 @@ function formatChains({
7462
7476
  token_infos: [...tokenInfos, ...swapTokens]
7463
7477
  };
7464
7478
  if (typeof filter === "function") {
7465
- if (!filter(_chain))
7466
- continue;
7479
+ if (!filter(_chain)) continue;
7467
7480
  }
7468
7481
  chains.push(_chain);
7469
7482
  }
@@ -7814,12 +7827,9 @@ var useDeposit = (options) => {
7814
7827
  const getAllowance = async (inputs) => {
7815
7828
  const { address, vaultAddress: vaultAddress2, decimals } = inputs;
7816
7829
  const key = `${address}-${vaultAddress2}`;
7817
- if (prevAddress.current === key)
7818
- return;
7819
- if (!address || !vaultAddress2)
7820
- return;
7821
- if (isNativeTokenChecker(address))
7822
- return;
7830
+ if (prevAddress.current === key) return;
7831
+ if (!address || !vaultAddress2) return;
7832
+ if (isNativeTokenChecker(address)) return;
7823
7833
  prevAddress.current = key;
7824
7834
  const allowance2 = await account9.assetsManager.getAllowance({
7825
7835
  address,
@@ -7831,10 +7841,8 @@ var useDeposit = (options) => {
7831
7841
  };
7832
7842
  const getAllowanceByDefaultAddress = async (inputs) => {
7833
7843
  const { address, decimals } = inputs;
7834
- if (prevAddress.current === address)
7835
- return;
7836
- if (!address || isNativeTokenChecker(address))
7837
- return;
7844
+ if (prevAddress.current === address) return;
7845
+ if (!address || isNativeTokenChecker(address)) return;
7838
7846
  prevAddress.current = address;
7839
7847
  const allowance2 = await account9.assetsManager.getAllowance({
7840
7848
  address,
@@ -7877,8 +7885,7 @@ var useDeposit = (options) => {
7877
7885
  100
7878
7886
  );
7879
7887
  useEffect(() => {
7880
- if (state.status < AccountStatusEnum.Connected)
7881
- return;
7888
+ if (state.status < AccountStatusEnum.Connected) return;
7882
7889
  setBalanceRevalidating(true);
7883
7890
  queryBalance(options.address, options.decimals);
7884
7891
  if (account9.walletAdapter?.chainNamespace === ChainNamespace.solana) {
@@ -8082,8 +8089,7 @@ var useDeposit = (options) => {
8082
8089
  balanceRef.current = balance2;
8083
8090
  loopGetBalance();
8084
8091
  } catch (err) {
8085
- if (currentAddressRef.current !== options.address)
8086
- return;
8092
+ if (currentAddressRef.current !== options.address) return;
8087
8093
  loopGetBalance(1e3);
8088
8094
  } finally {
8089
8095
  if (balanceRef.current !== "" && currentAddressRef.current === options.address) {
@@ -8291,8 +8297,7 @@ var useWalletTopic = (options) => {
8291
8297
  const ws = useWS();
8292
8298
  const { state } = useAccount();
8293
8299
  useEffect(() => {
8294
- if (!state.accountId)
8295
- return;
8300
+ if (!state.accountId) return;
8296
8301
  const unsubscribe = ws.privateSubscribe(
8297
8302
  {
8298
8303
  id: "wallet",
@@ -8313,8 +8318,7 @@ var useBalanceTopic = (options) => {
8313
8318
  const ws = useWS();
8314
8319
  const { state } = useAccount();
8315
8320
  useEffect(() => {
8316
- if (!state.accountId)
8317
- return;
8321
+ if (!state.accountId) return;
8318
8322
  const unsubscribe = ws.privateSubscribe(
8319
8323
  {
8320
8324
  id: "balance",
@@ -8414,8 +8418,7 @@ var usePrivateDataObserver = (options) => {
8414
8418
  }
8415
8419
  );
8416
8420
  useEffect(() => {
8417
- if (!account9.accountId)
8418
- return;
8421
+ if (!account9.accountId) return;
8419
8422
  const unsubscribe = ws.privateSubscribe(
8420
8423
  {
8421
8424
  id: "balance",
@@ -8511,10 +8514,8 @@ var usePrivateDataObserver = (options) => {
8511
8514
  return () => unsubscribe?.();
8512
8515
  }, [state.accountId, subOrder]);
8513
8516
  useEffect(() => {
8514
- if (!state.accountId)
8515
- return;
8516
- if (subOrder !== true)
8517
- return;
8517
+ if (!state.accountId) return;
8518
+ if (subOrder !== true) return;
8518
8519
  const unsubscribe = ws.privateSubscribe("algoexecutionreport", {
8519
8520
  onMessage: (data) => {
8520
8521
  updateOrders(data, true);
@@ -8523,8 +8524,7 @@ var usePrivateDataObserver = (options) => {
8523
8524
  return () => unsubscribe?.();
8524
8525
  }, [state.accountId, subOrder]);
8525
8526
  useEffect(() => {
8526
- if (!state.accountId)
8527
- return;
8527
+ if (!state.accountId) return;
8528
8528
  const key = ["/v1/positions", state.accountId];
8529
8529
  const unsubscribe = ws.privateSubscribe("account", {
8530
8530
  onMessage: (data) => {
@@ -8886,8 +8886,7 @@ var BaseOrderCreator = class {
8886
8886
  }
8887
8887
  orders.push(orderItem);
8888
8888
  }
8889
- if (!orders.length)
8890
- return null;
8889
+ if (!orders.length) return null;
8891
8890
  return {
8892
8891
  symbol: data.symbol,
8893
8892
  algo_type: algoType,
@@ -8897,8 +8896,7 @@ var BaseOrderCreator = class {
8897
8896
  validateBracketOrder(values, config, errors) {
8898
8897
  const { tp_trigger_price, sl_trigger_price, side, order_price } = values;
8899
8898
  const { markPrice } = config;
8900
- if (!tp_trigger_price && !sl_trigger_price)
8901
- return errors;
8899
+ if (!tp_trigger_price && !sl_trigger_price) return errors;
8902
8900
  const hasTPPrice = !!tp_trigger_price;
8903
8901
  const hasSLPrice = !!sl_trigger_price;
8904
8902
  const { symbol } = config;
@@ -10397,6 +10395,7 @@ var OrderFactory = class {
10397
10395
  return new ScaledOrderCreator();
10398
10396
  case OrderType.TRAILING_STOP:
10399
10397
  return new TrailingStopOrderCreator();
10398
+ // algo order
10400
10399
  case AlgoOrderRootType.TP_SL:
10401
10400
  return new TPSLOrderCreator();
10402
10401
  case AlgoOrderRootType.POSITIONAL_TP_SL:
@@ -10479,11 +10478,9 @@ var getPriceAndQty = (order, symbolInfo, askAndBid) => {
10479
10478
  var calcEstLiqPrice = (order$1, askAndBid, inputs) => {
10480
10479
  const { symbolInfo } = inputs;
10481
10480
  const result = getPriceAndQty(order$1, symbolInfo, askAndBid);
10482
- if (!result)
10483
- return null;
10481
+ if (!result) return null;
10484
10482
  const { price, quantity } = result;
10485
- if (!price || !quantity)
10486
- return null;
10483
+ if (!price || !quantity) return null;
10487
10484
  const {
10488
10485
  symbol,
10489
10486
  imr_factor,
@@ -10511,18 +10508,15 @@ var calcEstLiqPrice = (order$1, askAndBid, inputs) => {
10511
10508
  symbol
10512
10509
  }
10513
10510
  });
10514
- if (liqPrice <= 0)
10515
- return null;
10511
+ if (liqPrice <= 0) return null;
10516
10512
  return liqPrice;
10517
10513
  };
10518
10514
  var calcEstLeverage = (order$1, askAndBid, inputs) => {
10519
10515
  const { totalCollateral, positions: positions3, symbol, symbolInfo } = inputs;
10520
10516
  const result = getPriceAndQty(order$1, symbolInfo, askAndBid);
10521
- if (!result)
10522
- return null;
10517
+ if (!result) return null;
10523
10518
  const { price, quantity } = result;
10524
- if (!price || !quantity)
10525
- return null;
10519
+ if (!price || !quantity) return null;
10526
10520
  return order.estLeverage({
10527
10521
  totalCollateral,
10528
10522
  positions: positions3,
@@ -10587,8 +10581,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
10587
10581
  });
10588
10582
  const { orderMetadata } = useOrderlyContext();
10589
10583
  useEffect(() => {
10590
- if (!isEditing || !options?.defaultOrder)
10591
- return;
10584
+ if (!isEditing || !options?.defaultOrder) return;
10592
10585
  const trigger_prices = findTPSLFromOrder(options.defaultOrder);
10593
10586
  const order2 = {};
10594
10587
  if (trigger_prices.tp_trigger_price) {
@@ -10746,8 +10739,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
10746
10739
  };
10747
10740
  const compare = () => {
10748
10741
  const quantityNum = Number(order.quantity);
10749
- if (isNaN(quantityNum))
10750
- return false;
10742
+ if (isNaN(quantityNum)) return false;
10751
10743
  return quantityNum === Math.abs(Number(position.position_qty));
10752
10744
  };
10753
10745
  const getOrderCreator2 = () => {
@@ -11298,14 +11290,16 @@ var usePublicDataObserver = () => {
11298
11290
  const arr = item.symbol.split("_");
11299
11291
  const base_dp = getPrecisionByNumber(item.base_tick);
11300
11292
  const quote_dp = getPrecisionByNumber(item.quote_tick);
11301
- obj[item.symbol] = {
11293
+ const symbol = item.symbol;
11294
+ obj[symbol] = {
11302
11295
  ...item,
11303
11296
  base_dp,
11304
11297
  quote_dp,
11305
11298
  base: arr[1],
11306
11299
  quote: arr[2],
11307
11300
  type: arr[0],
11308
- name: `${arr[1]}-${arr[0]}`
11301
+ name: `${arr[1]}-${arr[0]}`,
11302
+ displayName: DEFAULT_SYMBOL_DISPLAY_NAMES[symbol]
11309
11303
  };
11310
11304
  }
11311
11305
  setSymbolsInfo(obj);
@@ -11599,8 +11593,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11599
11593
  );
11600
11594
  const { data: markPrice } = useMarkPrice(symbol);
11601
11595
  const diffOrderEntry = (prev, current) => {
11602
- if (!prev)
11603
- return null;
11596
+ if (!prev) return null;
11604
11597
  let key, value, preValue;
11605
11598
  const keys = Object.keys(current);
11606
11599
  for (let i = 0; i < keys.length; i++) {
@@ -11616,14 +11609,12 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11616
11609
  break;
11617
11610
  }
11618
11611
  }
11619
- if (!key)
11620
- return null;
11612
+ if (!key) return null;
11621
11613
  return { key, value, preValue };
11622
11614
  };
11623
11615
  const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
11624
11616
  const parseString2Number = (order, key, dp) => {
11625
- if (typeof order[key] !== "string")
11626
- return;
11617
+ if (typeof order[key] !== "string") return;
11627
11618
  if (order[key] && order[key].startsWith(".")) {
11628
11619
  order[key] = `0${order[key]}`;
11629
11620
  }
@@ -11827,8 +11818,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11827
11818
  return values;
11828
11819
  }, [parsedData, markPrice]);
11829
11820
  useEffect(() => {
11830
- if (!markPrice || symbolInfo.isNil)
11831
- return;
11821
+ if (!markPrice || symbolInfo.isNil) return;
11832
11822
  validator(formattedOrder)?.then((err) => {
11833
11823
  setErrors(err);
11834
11824
  }).catch((err) => {
@@ -11902,14 +11892,11 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11902
11892
  return { price, quantity };
11903
11893
  };
11904
11894
  const estLiqPrice = useMemo(() => {
11905
- if (!accountInfo || !parsedData || !markPrice)
11906
- return null;
11895
+ if (!accountInfo || !parsedData || !markPrice) return null;
11907
11896
  const result = getPriceAndQty2(formattedOrder);
11908
- if (result === null)
11909
- return null;
11897
+ if (result === null) return null;
11910
11898
  const { price, quantity } = result;
11911
- if (!price || !quantity)
11912
- return null;
11899
+ if (!price || !quantity) return null;
11913
11900
  const orderFee = order.orderFee({
11914
11901
  qty: quantity,
11915
11902
  price,
@@ -11929,8 +11916,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11929
11916
  symbol: parsedData.symbol
11930
11917
  }
11931
11918
  });
11932
- if (liqPrice <= 0)
11933
- return null;
11919
+ if (liqPrice <= 0) return null;
11934
11920
  return liqPrice;
11935
11921
  }, [
11936
11922
  markPrice,
@@ -11944,11 +11930,9 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11944
11930
  accountInfo
11945
11931
  ]);
11946
11932
  const estLeverage = useMemo(() => {
11947
- if (!accountInfo || !parsedData)
11948
- return null;
11933
+ if (!accountInfo || !parsedData) return null;
11949
11934
  const result = getPriceAndQty2(formattedOrder);
11950
- if (result === null || !result.price || !result.quantity)
11951
- return null;
11935
+ if (result === null || !result.price || !result.quantity) return null;
11952
11936
  const leverage = order.estLeverage({
11953
11937
  totalCollateral,
11954
11938
  positions: positions3 === null ? [] : positions3,
@@ -12465,8 +12449,7 @@ var PosterPainter = class {
12465
12449
  requestAnimationFrame(() => this._draw.bind(this)(options));
12466
12450
  }
12467
12451
  async _draw(options) {
12468
- if (this.ctx === null)
12469
- return;
12452
+ if (this.ctx === null) return;
12470
12453
  await new BackgroundPaint(this.ctx, this).draw(options);
12471
12454
  await new DataPaint(this.ctx, this).draw(options);
12472
12455
  }
@@ -12572,8 +12555,7 @@ var usePoster = (data, options) => {
12572
12555
  [target]
12573
12556
  );
12574
12557
  const ref = (ref2) => {
12575
- if (!ref2)
12576
- return;
12558
+ if (!ref2) return;
12577
12559
  if (ref2.tagName.toUpperCase() !== "CANVAS") {
12578
12560
  setError(new SDKError("The ref must be a canvas element"));
12579
12561
  return;
@@ -17813,8 +17795,7 @@ var useApiKeyManager = (queryParams) => {
17813
17795
  ];
17814
17796
  };
17815
17797
  function getQueryParamsFromObject(obj) {
17816
- if (typeof obj === "undefined")
17817
- return "";
17798
+ if (typeof obj === "undefined") return "";
17818
17799
  const queryParams = new URLSearchParams();
17819
17800
  for (const [key, value] of Object.entries(obj)) {
17820
17801
  if (value !== void 0) {
@@ -18043,8 +18024,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18043
18024
  };
18044
18025
  const onMarkPriceUpdated = useCallback(
18045
18026
  (markPrice, baseOn = []) => {
18046
- if (!options.symbolInfo)
18047
- return;
18027
+ if (!options.symbolInfo) return;
18048
18028
  let newValues = { ...orderEntity };
18049
18029
  if (baseOn.length === 0) {
18050
18030
  newValues = calculate2(
@@ -18855,16 +18835,12 @@ var ERROR_MSG_CODES = {
18855
18835
 
18856
18836
  // src/next/tpsl/useTpslPriceChecker.ts
18857
18837
  var isEqual = (a, b) => {
18858
- if (a === b)
18859
- return true;
18860
- if (a === null || b === null)
18861
- return false;
18838
+ if (a === b) return true;
18839
+ if (a === null || b === null) return false;
18862
18840
  const aItem = a.sl_trigger_price;
18863
18841
  const bItem = b.sl_trigger_price;
18864
- if (aItem === bItem)
18865
- return true;
18866
- if (aItem === void 0 || bItem === void 0)
18867
- return false;
18842
+ if (aItem === bItem) return true;
18843
+ if (aItem === void 0 || bItem === void 0) return false;
18868
18844
  return aItem.type === bItem.type && aItem.message === bItem.message;
18869
18845
  };
18870
18846
  var useTpslPriceChecker = (params) => {
@@ -18921,5 +18897,5 @@ var useEstLiqPriceBySymbol = (symbol) => {
18921
18897
  };
18922
18898
 
18923
18899
  export { DefaultLayoutConfig, DistributionId, ENVType2 as ENVType, ERROR_MSG_CODES, EpochStatus, ExtendedConfigStore, MaintenanceStatus, MarketsStorageKey, MarketsType, ORDERLY_ORDERBOOK_DEPTH_KEY, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusProvider, TWType, WalletConnectorContext, WsNetworkStatus, checkNotional, cleanStringStyle, fetcher, findPositionTPSLFromOrders, findTPSLFromOrder, findTPSLOrderPriceFromOrder, getMinNotional, getPriceKey, indexedDBManager, initializeAppDatabase, isCurrentlyClosed, isCurrentlyTrading, noCacheConfig, parseJSON, persistIndexedDB, resetTimestampOffsetState, timestampWaitingMiddleware, useAccount, useAccountInfo2 as useAccountInfo, useAccountInstance, useAccountRewardsHistory, useAllBrokers, useApiKeyManager, useAppStore, useAssetsHistory, useAudioPlayer, useBalanceSubscription, useBalanceTopic, useBoolean, useChain, useChainInfo, useChains, useCheckReferralCode, useCollateral, useCommission, useComputedLTV, useConfig, useConvert, useCurEpochEstimate, useDaily, useDeposit, useDistribution, useDistributionHistory, useEpochInfo, useEstLiqPriceBySymbol, useEventEmitter, useFeeState, useFundingDetails, useFundingFeeHistory, useFundingRate, useFundingRateBySymbol, useFundingRateHistory, useFundingRates, useFundingRatesStore, useGetClaimed, useGetEnv, useGetReferralCode, useGetRwaSymbolCloseTimeInterval, useGetRwaSymbolInfo, useGetRwaSymbolOpenStatus, useGetRwaSymbolOpenTimeInterval, useHoldingStream, useIndexPrice, useIndexPricesStream, useInfiniteQuery, useInitRwaSymbolsRuntime, useInternalTransfer, useKeyStore, useLazyQuery, useLeverage, useLeverageBySymbol, useLocalStorage, useMainTokenStore, useMainnetChainsStore, useMaintenanceStatus, useMarginRatio, useMarkPrice, useMarkPriceBySymbol, useMarkPricesStream, useMarket, useMarketList, useMarketMap, useMarketTradeStream, useMarkets, useMarketsStore, useMarketsStream, useMaxLeverage, useMaxQty, useMaxWithdrawal, useMediaQuery, useMemoizedFn, useMutation, useNetworkInfo, useOdosQuote, useOrderEntity, useOrderEntry2 as useOrderEntry, useOrderEntry as useOrderEntry_deprecated, useOrderStore2 as useOrderStore, useOrderStream, useOrderbookStream, useOrderlyContext, usePortfolio, usePositionActions, usePositionClose, usePositionStream, usePoster, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useRefereeHistory, useRefereeInfo, useRefereeRebateSummary, useReferralInfo, useReferralRebateSummary, useRestrictedInfo, useRwaSymbolsInfo, useRwaSymbolsInfoStore, useSessionStorage, useSettleSubscription, useSimpleDI, useStatisticsDaily, useStorageChain, useStorageLedgerAddress, useSubAccountAlgoOrderStream, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useSubAccountMutation, useSubAccountQuery, useSubAccountWS, useSwapSupportStore, useSymbolInfo, useSymbolLeverage, useSymbolPriceRange, useSymbolsInfo, useSymbolsInfoStore, useTPSLOrder, useTestTokenStore, useTestnetChainsStore, useTickerStream, useTokenInfo, useTokensInfo, useTpslPriceChecker, useTrack, useTrackingInstance, useTradingRewardsStatus, useTransfer, useTransferHistory, useUpdatedRef, useVaultsHistory, useWS, useWalletConnector, useWalletRewardsHistory, useWalletSubscription, useWalletTopic, useWithdraw, useWsStatus, utils_exports as utils, version_default as version };
18924
- //# sourceMappingURL=out.js.map
18900
+ //# sourceMappingURL=index.mjs.map
18925
18901
  //# sourceMappingURL=index.mjs.map