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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -64,9 +64,9 @@ var __export = (target, all) => {
64
64
  // src/version.ts
65
65
  if (typeof window !== "undefined") {
66
66
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
67
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.10-alpha.0";
67
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.8.11-alpha.0";
68
68
  }
69
- var version_default = "2.8.10-alpha.0";
69
+ var version_default = "2.8.11-alpha.0";
70
70
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
71
71
  var noCacheConfig = {
72
72
  dedupingInterval: 0,
@@ -510,8 +510,7 @@ var usePrivateInfiniteQuery = (getKey, options) => {
510
510
  const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
511
511
  const result = useSWRInfinite__default.default(
512
512
  (pageIndex, previousPageData) => {
513
- if (!getKey)
514
- return null;
513
+ if (!getKey) return null;
515
514
  const queryKey = getKey(pageIndex, previousPageData);
516
515
  if (queryKey && (state.status >= types.AccountStatusEnum.EnableTrading || state.status === types.AccountStatusEnum.EnableTradingWithoutConnected)) {
517
516
  return [queryKey, state.accountId];
@@ -556,8 +555,8 @@ var useUpdatedRef = (val) => {
556
555
  return latestRef;
557
556
  };
558
557
  var useMemoizedFn = (fn) => {
559
- const safeFn = typeof fn === "function" ? fn : () => {
560
- };
558
+ const safeFn = typeof fn === "function" ? fn : (() => {
559
+ });
561
560
  const fnRef = React2.useRef(safeFn);
562
561
  fnRef.current = React2.useMemo(() => safeFn, [safeFn]);
563
562
  const wrapperRef = React2.useRef(null);
@@ -1138,8 +1137,7 @@ var findPositionTPSLFromOrders = (orders, symbol) => {
1138
1137
  };
1139
1138
  function offsetToPrice(inputs) {
1140
1139
  const { qty, offset, entryPrice, orderType, orderSide } = inputs;
1141
- if (!offset)
1142
- return;
1140
+ if (!offset) return;
1143
1141
  if (orderSide === types.OrderSide.BUY) {
1144
1142
  if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
1145
1143
  return new utils.Decimal(entryPrice).add(new utils.Decimal(offset)).toNumber();
@@ -1176,8 +1174,7 @@ function priceToOffset(inputs, options = {}) {
1176
1174
  }
1177
1175
  function offsetPercentageToPrice(inputs) {
1178
1176
  const { qty, percentage, entryPrice, orderType, orderSide } = inputs;
1179
- if (!percentage)
1180
- return;
1177
+ if (!percentage) return;
1181
1178
  if (orderSide === types.OrderSide.BUY) {
1182
1179
  if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
1183
1180
  return new utils.Decimal(1).add(new utils.Decimal(percentage)).mul(new utils.Decimal(entryPrice)).toNumber();
@@ -1200,16 +1197,14 @@ function priceToOffsetPercentage(inputs) {
1200
1197
  orderPrice: entryPrice
1201
1198
  });
1202
1199
  if (orderSide === types.OrderSide.BUY) {
1203
- if (entryPrice === 0)
1204
- return 0;
1200
+ if (entryPrice === 0) return 0;
1205
1201
  if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
1206
1202
  return new utils.Decimal(price).div(new utils.Decimal(entryPrice)).minus(1).abs().mul(direction).toDecimalPlaces(4, utils.Decimal.ROUND_DOWN).toNumber();
1207
1203
  }
1208
1204
  return new utils.Decimal(1).minus(new utils.Decimal(price).div(new utils.Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, utils.Decimal.ROUND_DOWN).toNumber();
1209
1205
  }
1210
1206
  if (orderSide === types.OrderSide.SELL) {
1211
- if (entryPrice === 0)
1212
- return 0;
1207
+ if (entryPrice === 0) return 0;
1213
1208
  if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
1214
1209
  return new utils.Decimal(1).minus(new utils.Decimal(price).div(new utils.Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, utils.Decimal.ROUND_DOWN).toNumber();
1215
1210
  }
@@ -1221,8 +1216,7 @@ function pnlToPrice(inputs) {
1221
1216
  if (!pnl) {
1222
1217
  return;
1223
1218
  }
1224
- if (qty === 0)
1225
- return;
1219
+ if (qty === 0) return;
1226
1220
  if (orderSide === types.OrderSide.BUY) {
1227
1221
  if (orderType === types.AlgoOrderType.TAKE_PROFIT) {
1228
1222
  return new utils.Decimal(entryPrice).plus(new utils.Decimal(pnl).div(new utils.Decimal(qty))).toNumber();
@@ -1304,8 +1298,7 @@ function priceToROI(inputs) {
1304
1298
  function calcTPSL_ROI(inputs) {
1305
1299
  const qtyNum = Number(inputs.qty);
1306
1300
  const priceNum = Number(inputs.price);
1307
- if (qtyNum === 0 || priceNum === 0)
1308
- return "0";
1301
+ if (qtyNum === 0 || priceNum === 0) return "0";
1309
1302
  return new utils.Decimal(inputs.pnl).div(new utils.Decimal(qtyNum).abs().mul(new utils.Decimal(priceNum))).toString();
1310
1303
  }
1311
1304
  function checkTPSLOrderTypeIsMarket(key, values) {
@@ -1354,6 +1347,31 @@ function tpslCalculateHelper(key, inputs, options = {}) {
1354
1347
  }
1355
1348
  break;
1356
1349
  }
1350
+ // case "tp_enable":
1351
+ // case "sl_enable": {
1352
+ // return {
1353
+ // [`${keyPrefix}enable`]: inputs.value,
1354
+ // [`${keyPrefix}order_type`]: OrderType.MARKET,
1355
+ // [`${keyPrefix}trigger_price`]: "",
1356
+ // [`${keyPrefix}order_price`]: "",
1357
+ // [`${keyPrefix}offset`]: "",
1358
+ // [`${keyPrefix}offset_percentage`]: "",
1359
+ // [`${keyPrefix}pnl`]: "",
1360
+ // [`${keyPrefix}ROI`]: "",
1361
+ // };
1362
+ // }
1363
+ // case 'tp_pnl':{
1364
+ // if (inputs.values.tp_order_type !== OrderType.MARKET) {
1365
+ // pnl = inputs.value;
1366
+ // trigger_price = pnlToPrice({
1367
+ // qty,
1368
+ // pnl: Number(inputs.value),
1369
+ // entryPrice,
1370
+ // orderSide: inputs.orderSide,
1371
+ // orderType,
1372
+ // })
1373
+ // }
1374
+ // }
1357
1375
  case "tp_pnl":
1358
1376
  case "sl_pnl": {
1359
1377
  pnl = inputs.value;
@@ -1702,6 +1720,8 @@ var getCalculateHandler = (fieldName) => {
1702
1720
  case "total": {
1703
1721
  return totalInputHandle;
1704
1722
  }
1723
+ // case "tp_enable":
1724
+ // case "sl_enable":
1705
1725
  case "tp_pnl":
1706
1726
  case "sl_pnl":
1707
1727
  case "tp_trigger_price":
@@ -1720,17 +1740,14 @@ var getCalculateHandler = (fieldName) => {
1720
1740
  }
1721
1741
  };
1722
1742
  function formatNumber(qty, dp) {
1723
- if (typeof qty === "undefined")
1724
- return qty;
1725
- if (typeof dp === "undefined")
1726
- return `${qty}`;
1743
+ if (typeof qty === "undefined") return qty;
1744
+ if (typeof dp === "undefined") return `${qty}`;
1727
1745
  const _qty = `${qty}`.replace(/,/g, "");
1728
1746
  try {
1729
1747
  const _dp = new utils.Decimal(dp);
1730
1748
  const _qtyDecimal = new utils.Decimal(_qty);
1731
1749
  if (_dp.lessThan(1)) {
1732
- if (`${_qty}`.endsWith("."))
1733
- return `${_qty}`;
1750
+ if (`${_qty}`.endsWith(".")) return `${_qty}`;
1734
1751
  const numStr = dp.toString();
1735
1752
  const decimalIndex = numStr.indexOf(".");
1736
1753
  const digitsAfterDecimal = decimalIndex === -1 ? 0 : numStr.length - decimalIndex - 1;
@@ -2754,21 +2771,18 @@ var usePreLoadData = () => {
2754
2771
  });
2755
2772
  }, []);
2756
2773
  React2.useEffect(() => {
2757
- if (!urlPrefix)
2758
- return;
2774
+ if (!urlPrefix) return;
2759
2775
  fetchTestTokens(urlPrefix);
2760
2776
  fetchTestChains(urlPrefix, {
2761
2777
  brokerId: configStore.get("brokerId")
2762
2778
  });
2763
2779
  }, [urlPrefix]);
2764
2780
  React2.useEffect(() => {
2765
- if (!mainTokenInfo || !testTokenInfo)
2766
- return;
2781
+ if (!mainTokenInfo || !testTokenInfo) return;
2767
2782
  setTokensInfo(env === "prod" ? mainTokenInfo : testTokenInfo);
2768
2783
  }, [mainTokenInfo, testTokenInfo]);
2769
2784
  React2.useEffect(() => {
2770
- if (swapSupportInfo || !enableSwapDeposit)
2771
- return;
2785
+ if (swapSupportInfo || !enableSwapDeposit) return;
2772
2786
  fetchSwapSupport();
2773
2787
  }, [swapSupportInfo, enableSwapDeposit]);
2774
2788
  const { data: systemInfo } = useSWR__namespace.default(
@@ -2786,8 +2800,7 @@ var usePreLoadData = () => {
2786
2800
  }
2787
2801
  );
2788
2802
  React2.useEffect(() => {
2789
- if (timestampOffsetInitialized)
2790
- return;
2803
+ if (timestampOffsetInitialized) return;
2791
2804
  if (typeof systemInfo !== "undefined") {
2792
2805
  const serverTimestamp = systemInfo.timestamp;
2793
2806
  const localTimestamp = Date.now();
@@ -3063,8 +3076,7 @@ var AmplitudeTracker = class {
3063
3076
  this._userId = userId;
3064
3077
  }
3065
3078
  setSdkInfo(sdkInfo) {
3066
- if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag)
3067
- return;
3079
+ if (this._sdkInfoTag && sdkInfo.address === this._sdkInfoTag) return;
3068
3080
  this.identify(sdkInfo);
3069
3081
  this._sdkInfoTag = sdkInfo.address;
3070
3082
  }
@@ -3272,10 +3284,8 @@ var useMarketsStream = () => {
3272
3284
  };
3273
3285
  });
3274
3286
  const value = React2.useMemo(() => {
3275
- if (!futures)
3276
- return null;
3277
- if (!tickers)
3278
- return futures;
3287
+ if (!futures) return null;
3288
+ if (!tickers) return futures;
3279
3289
  return futures.map((item) => {
3280
3290
  const ticker = tickers.find(
3281
3291
  (t) => t.symbol === item.symbol
@@ -3318,8 +3328,7 @@ function createGetter(data, depth = 2) {
3318
3328
  }
3319
3329
  if (depth === 1) {
3320
3330
  return (defaultValue) => {
3321
- if (!target)
3322
- return defaultValue;
3331
+ if (!target) return defaultValue;
3323
3332
  return getValue(target[property], defaultValue);
3324
3333
  };
3325
3334
  }
@@ -3873,8 +3882,7 @@ var useWSObserver = (calculatorService) => {
3873
3882
  });
3874
3883
  const indexPriceSubscription = ws.subscribe("indexprices", {
3875
3884
  onMessage: (message) => {
3876
- if (!Array.isArray(message))
3877
- return;
3885
+ if (!Array.isArray(message)) return;
3878
3886
  const prices = /* @__PURE__ */ Object.create(null);
3879
3887
  for (let index = 0; index < message.length; index++) {
3880
3888
  const element = message[index];
@@ -4111,10 +4119,8 @@ var useTickerStream = (symbol) => {
4111
4119
  const { data: openInterest } = useOpenInterest(symbol);
4112
4120
  const marketMap = useMarketMap();
4113
4121
  const value = React2.useMemo(() => {
4114
- if (!info)
4115
- return null;
4116
- if (!ticker || ticker.symbol !== symbol)
4117
- return info;
4122
+ if (!info) return null;
4123
+ if (!ticker || ticker.symbol !== symbol) return info;
4118
4124
  const config = {
4119
4125
  ...info,
4120
4126
  mark_price: markPrice,
@@ -5130,8 +5136,7 @@ var CalculatorService = class {
5130
5136
  if (!ctx.isReady && options?.skipPending) {
5131
5137
  return;
5132
5138
  }
5133
- if (options?.skipWhenOnPause && !this.windowIsVisible)
5134
- return;
5139
+ if (options?.skipWhenOnPause && !this.windowIsVisible) return;
5135
5140
  this.calcQueue.push({ scope, data, options });
5136
5141
  await this.handleCalcQueue(ctx);
5137
5142
  this.ctx = ctx;
@@ -5332,8 +5337,7 @@ var PositionCalculator = class extends BaseCalculator {
5332
5337
  return data;
5333
5338
  }
5334
5339
  update(data, scope) {
5335
- if (!data || !Array.isArray(data.rows))
5336
- return;
5340
+ if (!data || !Array.isArray(data.rows)) return;
5337
5341
  usePositionStore.getState().actions.setPositions(this.symbol, data);
5338
5342
  if (Array.isArray(data.rows) && useApiStatusStore.getState().apis.positions.loading) {
5339
5343
  useApiStatusStore.getState().actions.updateApiLoading("positions", false);
@@ -5372,8 +5376,7 @@ var PositionCalculator = class extends BaseCalculator {
5372
5376
  return this.format(positions3, ctx);
5373
5377
  }
5374
5378
  calcByPosition(positions3, ctx) {
5375
- if (positions3.rows.length === 0)
5376
- return positions3;
5379
+ if (positions3.rows.length === 0) return positions3;
5377
5380
  return this.format(positions3, ctx);
5378
5381
  }
5379
5382
  format(data, ctx) {
@@ -5586,8 +5589,7 @@ var IndexPriceCalculator = class extends BaseCalculator {
5586
5589
  return data;
5587
5590
  }
5588
5591
  update(data) {
5589
- if (!data)
5590
- return;
5592
+ if (!data) return;
5591
5593
  useIndexPriceStore.getState().actions.updateIndexPrice(data);
5592
5594
  }
5593
5595
  static getValue() {
@@ -5981,8 +5983,7 @@ var useOrderStream = (params, options) => {
5981
5983
  registerKeyHandler?.(key.replace("orders", "algoOrders"), algoOrderKeyFn);
5982
5984
  }
5983
5985
  return () => {
5984
- if (!options?.stopOnUnmount)
5985
- return;
5986
+ if (!options?.stopOnUnmount) return;
5986
5987
  unregisterKeyHandler(key);
5987
5988
  if (algoOrderKeyFn) {
5988
5989
  unregisterKeyHandler(key.replace("orders", "algoOrders"));
@@ -6548,8 +6549,7 @@ var useSubAccountDataObserver = (accountId) => {
6548
6549
  tokensInfo
6549
6550
  ]);
6550
6551
  React2.useEffect(() => {
6551
- if (!positionsInfo)
6552
- return;
6552
+ if (!positionsInfo) return;
6553
6553
  if (positionsInfo.rows?.length === 0) {
6554
6554
  setPositions(positionsInfo);
6555
6555
  return;
@@ -6581,8 +6581,7 @@ var useSubAccountDataObserver = (accountId) => {
6581
6581
  }
6582
6582
  }, [holdingRes]);
6583
6583
  React2.useEffect(() => {
6584
- if (!accountId)
6585
- return;
6584
+ if (!accountId) return;
6586
6585
  const unsubscribe = ws.privateSubscribe(
6587
6586
  {
6588
6587
  id: "balance",
@@ -6607,8 +6606,7 @@ var useSubAccountDataObserver = (accountId) => {
6607
6606
  return () => unsubscribe?.();
6608
6607
  }, [accountId]);
6609
6608
  React2.useEffect(() => {
6610
- if (!accountId)
6611
- return;
6609
+ if (!accountId) return;
6612
6610
  const key = ["/v1/positions", accountId];
6613
6611
  const unsubscribe = ws.privateSubscribe("position", {
6614
6612
  onMessage: (data) => {
@@ -7092,8 +7090,7 @@ var useLeverageBySymbol = (symbol) => {
7092
7090
  }
7093
7091
  );
7094
7092
  React2.useEffect(() => {
7095
- if (!state.accountId || !symbol)
7096
- return;
7093
+ if (!state.accountId || !symbol) return;
7097
7094
  const unsubscribe = ws.privateSubscribe("account", {
7098
7095
  onMessage: (data2) => {
7099
7096
  const res = data2?.accountDetail?.symbolLeverage || {};
@@ -7122,8 +7119,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
7122
7119
  const { data: markPrices } = useMarkPricesStream();
7123
7120
  const symbolLeverage = useLeverageBySymbol(symbol);
7124
7121
  const maxQty = React2.useMemo(() => {
7125
- if (!symbol)
7126
- return 0;
7122
+ if (!symbol) return 0;
7127
7123
  const positionQty = perp.account.getQtyFromPositions(
7128
7124
  positions3 === null ? [] : positions3,
7129
7125
  symbol
@@ -7226,7 +7222,20 @@ var useMarginRatio = () => {
7226
7222
  positionsNotional: notional
7227
7223
  });
7228
7224
  }, [rows, notional]);
7229
- return { marginRatio, currentLeverage, mmr };
7225
+ const maintenanceMargin = React2.useMemo(() => {
7226
+ if (!rows || rows.length <= 0 || notional == null) {
7227
+ return null;
7228
+ }
7229
+ let maintenanceMargin2 = utils.zero;
7230
+ for (let index = 0; index < rows.length; index++) {
7231
+ const item = rows[index];
7232
+ if (item.mm !== null) {
7233
+ maintenanceMargin2 = maintenanceMargin2.add(item.mm);
7234
+ }
7235
+ }
7236
+ return maintenanceMargin2.toNumber();
7237
+ }, [rows, notional]);
7238
+ return { marginRatio, currentLeverage, mmr, maintenanceMargin };
7230
7239
  };
7231
7240
  var TestNetWhiteList = [
7232
7241
  types.ARBITRUM_TESTNET_CHAINID,
@@ -7488,8 +7497,7 @@ function formatChains({
7488
7497
  token_infos: [...tokenInfos, ...swapTokens]
7489
7498
  };
7490
7499
  if (typeof filter === "function") {
7491
- if (!filter(_chain))
7492
- continue;
7500
+ if (!filter(_chain)) continue;
7493
7501
  }
7494
7502
  chains.push(_chain);
7495
7503
  }
@@ -7840,12 +7848,9 @@ var useDeposit = (options) => {
7840
7848
  const getAllowance = async (inputs) => {
7841
7849
  const { address, vaultAddress: vaultAddress2, decimals } = inputs;
7842
7850
  const key = `${address}-${vaultAddress2}`;
7843
- if (prevAddress.current === key)
7844
- return;
7845
- if (!address || !vaultAddress2)
7846
- return;
7847
- if (types.isNativeTokenChecker(address))
7848
- return;
7851
+ if (prevAddress.current === key) return;
7852
+ if (!address || !vaultAddress2) return;
7853
+ if (types.isNativeTokenChecker(address)) return;
7849
7854
  prevAddress.current = key;
7850
7855
  const allowance2 = await account9.assetsManager.getAllowance({
7851
7856
  address,
@@ -7857,10 +7862,8 @@ var useDeposit = (options) => {
7857
7862
  };
7858
7863
  const getAllowanceByDefaultAddress = async (inputs) => {
7859
7864
  const { address, decimals } = inputs;
7860
- if (prevAddress.current === address)
7861
- return;
7862
- if (!address || types.isNativeTokenChecker(address))
7863
- return;
7865
+ if (prevAddress.current === address) return;
7866
+ if (!address || types.isNativeTokenChecker(address)) return;
7864
7867
  prevAddress.current = address;
7865
7868
  const allowance2 = await account9.assetsManager.getAllowance({
7866
7869
  address,
@@ -7903,8 +7906,7 @@ var useDeposit = (options) => {
7903
7906
  100
7904
7907
  );
7905
7908
  React2.useEffect(() => {
7906
- if (state.status < types.AccountStatusEnum.Connected)
7907
- return;
7909
+ if (state.status < types.AccountStatusEnum.Connected) return;
7908
7910
  setBalanceRevalidating(true);
7909
7911
  queryBalance(options.address, options.decimals);
7910
7912
  if (account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana) {
@@ -8108,8 +8110,7 @@ var useDeposit = (options) => {
8108
8110
  balanceRef.current = balance2;
8109
8111
  loopGetBalance();
8110
8112
  } catch (err) {
8111
- if (currentAddressRef.current !== options.address)
8112
- return;
8113
+ if (currentAddressRef.current !== options.address) return;
8113
8114
  loopGetBalance(1e3);
8114
8115
  } finally {
8115
8116
  if (balanceRef.current !== "" && currentAddressRef.current === options.address) {
@@ -8317,8 +8318,7 @@ var useWalletTopic = (options) => {
8317
8318
  const ws = useWS();
8318
8319
  const { state } = useAccount();
8319
8320
  React2.useEffect(() => {
8320
- if (!state.accountId)
8321
- return;
8321
+ if (!state.accountId) return;
8322
8322
  const unsubscribe = ws.privateSubscribe(
8323
8323
  {
8324
8324
  id: "wallet",
@@ -8339,8 +8339,7 @@ var useBalanceTopic = (options) => {
8339
8339
  const ws = useWS();
8340
8340
  const { state } = useAccount();
8341
8341
  React2.useEffect(() => {
8342
- if (!state.accountId)
8343
- return;
8342
+ if (!state.accountId) return;
8344
8343
  const unsubscribe = ws.privateSubscribe(
8345
8344
  {
8346
8345
  id: "balance",
@@ -8440,8 +8439,7 @@ var usePrivateDataObserver = (options) => {
8440
8439
  }
8441
8440
  );
8442
8441
  React2.useEffect(() => {
8443
- if (!account9.accountId)
8444
- return;
8442
+ if (!account9.accountId) return;
8445
8443
  const unsubscribe = ws.privateSubscribe(
8446
8444
  {
8447
8445
  id: "balance",
@@ -8537,10 +8535,8 @@ var usePrivateDataObserver = (options) => {
8537
8535
  return () => unsubscribe?.();
8538
8536
  }, [state.accountId, subOrder]);
8539
8537
  React2.useEffect(() => {
8540
- if (!state.accountId)
8541
- return;
8542
- if (subOrder !== true)
8543
- return;
8538
+ if (!state.accountId) return;
8539
+ if (subOrder !== true) return;
8544
8540
  const unsubscribe = ws.privateSubscribe("algoexecutionreport", {
8545
8541
  onMessage: (data) => {
8546
8542
  updateOrders(data, true);
@@ -8549,8 +8545,7 @@ var usePrivateDataObserver = (options) => {
8549
8545
  return () => unsubscribe?.();
8550
8546
  }, [state.accountId, subOrder]);
8551
8547
  React2.useEffect(() => {
8552
- if (!state.accountId)
8553
- return;
8548
+ if (!state.accountId) return;
8554
8549
  const key = ["/v1/positions", state.accountId];
8555
8550
  const unsubscribe = ws.privateSubscribe("account", {
8556
8551
  onMessage: (data) => {
@@ -8912,8 +8907,7 @@ var BaseOrderCreator = class {
8912
8907
  }
8913
8908
  orders.push(orderItem);
8914
8909
  }
8915
- if (!orders.length)
8916
- return null;
8910
+ if (!orders.length) return null;
8917
8911
  return {
8918
8912
  symbol: data.symbol,
8919
8913
  algo_type: algoType,
@@ -8923,8 +8917,7 @@ var BaseOrderCreator = class {
8923
8917
  validateBracketOrder(values, config, errors) {
8924
8918
  const { tp_trigger_price, sl_trigger_price, side, order_price } = values;
8925
8919
  const { markPrice } = config;
8926
- if (!tp_trigger_price && !sl_trigger_price)
8927
- return errors;
8920
+ if (!tp_trigger_price && !sl_trigger_price) return errors;
8928
8921
  const hasTPPrice = !!tp_trigger_price;
8929
8922
  const hasSLPrice = !!sl_trigger_price;
8930
8923
  const { symbol } = config;
@@ -10423,6 +10416,7 @@ var OrderFactory = class {
10423
10416
  return new ScaledOrderCreator();
10424
10417
  case types.OrderType.TRAILING_STOP:
10425
10418
  return new TrailingStopOrderCreator();
10419
+ // algo order
10426
10420
  case types.AlgoOrderRootType.TP_SL:
10427
10421
  return new TPSLOrderCreator();
10428
10422
  case types.AlgoOrderRootType.POSITIONAL_TP_SL:
@@ -10505,11 +10499,9 @@ var getPriceAndQty = (order, symbolInfo, askAndBid) => {
10505
10499
  var calcEstLiqPrice = (order, askAndBid, inputs) => {
10506
10500
  const { symbolInfo } = inputs;
10507
10501
  const result = getPriceAndQty(order, symbolInfo, askAndBid);
10508
- if (!result)
10509
- return null;
10502
+ if (!result) return null;
10510
10503
  const { price, quantity } = result;
10511
- if (!price || !quantity)
10512
- return null;
10504
+ if (!price || !quantity) return null;
10513
10505
  const {
10514
10506
  symbol,
10515
10507
  imr_factor,
@@ -10537,18 +10529,15 @@ var calcEstLiqPrice = (order, askAndBid, inputs) => {
10537
10529
  symbol
10538
10530
  }
10539
10531
  });
10540
- if (liqPrice <= 0)
10541
- return null;
10532
+ if (liqPrice <= 0) return null;
10542
10533
  return liqPrice;
10543
10534
  };
10544
10535
  var calcEstLeverage = (order, askAndBid, inputs) => {
10545
10536
  const { totalCollateral, positions: positions3, symbol, symbolInfo } = inputs;
10546
10537
  const result = getPriceAndQty(order, symbolInfo, askAndBid);
10547
- if (!result)
10548
- return null;
10538
+ if (!result) return null;
10549
10539
  const { price, quantity } = result;
10550
- if (!price || !quantity)
10551
- return null;
10540
+ if (!price || !quantity) return null;
10552
10541
  return perp.order.estLeverage({
10553
10542
  totalCollateral,
10554
10543
  positions: positions3,
@@ -10613,8 +10602,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
10613
10602
  });
10614
10603
  const { orderMetadata } = useOrderlyContext();
10615
10604
  React2.useEffect(() => {
10616
- if (!isEditing || !options?.defaultOrder)
10617
- return;
10605
+ if (!isEditing || !options?.defaultOrder) return;
10618
10606
  const trigger_prices = findTPSLFromOrder(options.defaultOrder);
10619
10607
  const order2 = {};
10620
10608
  if (trigger_prices.tp_trigger_price) {
@@ -10772,8 +10760,7 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
10772
10760
  };
10773
10761
  const compare = () => {
10774
10762
  const quantityNum = Number(order.quantity);
10775
- if (isNaN(quantityNum))
10776
- return false;
10763
+ if (isNaN(quantityNum)) return false;
10777
10764
  return quantityNum === Math.abs(Number(position.position_qty));
10778
10765
  };
10779
10766
  const getOrderCreator2 = () => {
@@ -11625,8 +11612,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11625
11612
  );
11626
11613
  const { data: markPrice } = useMarkPrice(symbol);
11627
11614
  const diffOrderEntry = (prev, current) => {
11628
- if (!prev)
11629
- return null;
11615
+ if (!prev) return null;
11630
11616
  let key, value, preValue;
11631
11617
  const keys = Object.keys(current);
11632
11618
  for (let i = 0; i < keys.length; i++) {
@@ -11642,14 +11628,12 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11642
11628
  break;
11643
11629
  }
11644
11630
  }
11645
- if (!key)
11646
- return null;
11631
+ if (!key) return null;
11647
11632
  return { key, value, preValue };
11648
11633
  };
11649
11634
  const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
11650
11635
  const parseString2Number = (order, key, dp) => {
11651
- if (typeof order[key] !== "string")
11652
- return;
11636
+ if (typeof order[key] !== "string") return;
11653
11637
  if (order[key] && order[key].startsWith(".")) {
11654
11638
  order[key] = `0${order[key]}`;
11655
11639
  }
@@ -11853,8 +11837,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11853
11837
  return values;
11854
11838
  }, [parsedData, markPrice]);
11855
11839
  React2.useEffect(() => {
11856
- if (!markPrice || symbolInfo.isNil)
11857
- return;
11840
+ if (!markPrice || symbolInfo.isNil) return;
11858
11841
  validator(formattedOrder)?.then((err) => {
11859
11842
  setErrors(err);
11860
11843
  }).catch((err) => {
@@ -11928,14 +11911,11 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11928
11911
  return { price, quantity };
11929
11912
  };
11930
11913
  const estLiqPrice = React2.useMemo(() => {
11931
- if (!accountInfo || !parsedData || !markPrice)
11932
- return null;
11914
+ if (!accountInfo || !parsedData || !markPrice) return null;
11933
11915
  const result = getPriceAndQty2(formattedOrder);
11934
- if (result === null)
11935
- return null;
11916
+ if (result === null) return null;
11936
11917
  const { price, quantity } = result;
11937
- if (!price || !quantity)
11938
- return null;
11918
+ if (!price || !quantity) return null;
11939
11919
  const orderFee = perp.order.orderFee({
11940
11920
  qty: quantity,
11941
11921
  price,
@@ -11955,8 +11935,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11955
11935
  symbol: parsedData.symbol
11956
11936
  }
11957
11937
  });
11958
- if (liqPrice <= 0)
11959
- return null;
11938
+ if (liqPrice <= 0) return null;
11960
11939
  return liqPrice;
11961
11940
  }, [
11962
11941
  markPrice,
@@ -11970,11 +11949,9 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
11970
11949
  accountInfo
11971
11950
  ]);
11972
11951
  const estLeverage = React2.useMemo(() => {
11973
- if (!accountInfo || !parsedData)
11974
- return null;
11952
+ if (!accountInfo || !parsedData) return null;
11975
11953
  const result = getPriceAndQty2(formattedOrder);
11976
- if (result === null || !result.price || !result.quantity)
11977
- return null;
11954
+ if (result === null || !result.price || !result.quantity) return null;
11978
11955
  const leverage = perp.order.estLeverage({
11979
11956
  totalCollateral,
11980
11957
  positions: positions3 === null ? [] : positions3,
@@ -12491,8 +12468,7 @@ var PosterPainter = class {
12491
12468
  requestAnimationFrame(() => this._draw.bind(this)(options));
12492
12469
  }
12493
12470
  async _draw(options) {
12494
- if (this.ctx === null)
12495
- return;
12471
+ if (this.ctx === null) return;
12496
12472
  await new BackgroundPaint(this.ctx, this).draw(options);
12497
12473
  await new DataPaint(this.ctx, this).draw(options);
12498
12474
  }
@@ -12598,8 +12574,7 @@ var usePoster = (data, options) => {
12598
12574
  [target]
12599
12575
  );
12600
12576
  const ref = (ref2) => {
12601
- if (!ref2)
12602
- return;
12577
+ if (!ref2) return;
12603
12578
  if (ref2.tagName.toUpperCase() !== "CANVAS") {
12604
12579
  setError(new types.SDKError("The ref must be a canvas element"));
12605
12580
  return;
@@ -17839,8 +17814,7 @@ var useApiKeyManager = (queryParams) => {
17839
17814
  ];
17840
17815
  };
17841
17816
  function getQueryParamsFromObject(obj) {
17842
- if (typeof obj === "undefined")
17843
- return "";
17817
+ if (typeof obj === "undefined") return "";
17844
17818
  const queryParams = new URLSearchParams();
17845
17819
  for (const [key, value] of Object.entries(obj)) {
17846
17820
  if (value !== void 0) {
@@ -18069,8 +18043,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18069
18043
  };
18070
18044
  const onMarkPriceUpdated = React2.useCallback(
18071
18045
  (markPrice, baseOn = []) => {
18072
- if (!options.symbolInfo)
18073
- return;
18046
+ if (!options.symbolInfo) return;
18074
18047
  let newValues = { ...orderEntity };
18075
18048
  if (baseOn.length === 0) {
18076
18049
  newValues = calculate2(
@@ -18881,16 +18854,12 @@ var ERROR_MSG_CODES = {
18881
18854
 
18882
18855
  // src/next/tpsl/useTpslPriceChecker.ts
18883
18856
  var isEqual = (a, b) => {
18884
- if (a === b)
18885
- return true;
18886
- if (a === null || b === null)
18887
- return false;
18857
+ if (a === b) return true;
18858
+ if (a === null || b === null) return false;
18888
18859
  const aItem = a.sl_trigger_price;
18889
18860
  const bItem = b.sl_trigger_price;
18890
- if (aItem === bItem)
18891
- return true;
18892
- if (aItem === void 0 || bItem === void 0)
18893
- return false;
18861
+ if (aItem === bItem) return true;
18862
+ if (aItem === void 0 || bItem === void 0) return false;
18894
18863
  return aItem.type === bItem.type && aItem.message === bItem.message;
18895
18864
  };
18896
18865
  var useTpslPriceChecker = (params) => {
@@ -19146,5 +19115,5 @@ Object.keys(useDebounce).forEach(function (k) {
19146
19115
  get: function () { return useDebounce[k]; }
19147
19116
  });
19148
19117
  });
19149
- //# sourceMappingURL=out.js.map
19118
+ //# sourceMappingURL=index.js.map
19150
19119
  //# sourceMappingURL=index.js.map