@orderly.network/ui-tpsl 2.8.8 → 2.8.9

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.d.mts CHANGED
@@ -171,7 +171,7 @@ declare const useTPSLBuilder: (options: TPSLBuilderOptions$1 & PropsWithTriggerP
171
171
  readonly isCreateMutating: boolean;
172
172
  readonly isUpdateMutating: boolean;
173
173
  };
174
- readonly position: API.PositionTPSLExt | undefined;
174
+ readonly position: API.Position | undefined;
175
175
  readonly setValues: (values: Partial<ComputedAlgoOrder>) => void;
176
176
  };
177
177
  type TPSLBuilderState = ReturnType<typeof useTPSLBuilder>;
package/dist/index.d.ts CHANGED
@@ -171,7 +171,7 @@ declare const useTPSLBuilder: (options: TPSLBuilderOptions$1 & PropsWithTriggerP
171
171
  readonly isCreateMutating: boolean;
172
172
  readonly isUpdateMutating: boolean;
173
173
  };
174
- readonly position: API.PositionTPSLExt | undefined;
174
+ readonly position: API.Position | undefined;
175
175
  readonly setValues: (values: Partial<ComputedAlgoOrder>) => void;
176
176
  };
177
177
  type TPSLBuilderState = ReturnType<typeof useTPSLBuilder>;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var hooks = require('@orderly.network/hooks');
4
- var i18n = require('@orderly.network/i18n');
5
3
  var types = require('@orderly.network/types');
6
4
  var ui = require('@orderly.network/ui');
7
5
  var react = require('react');
6
+ var hooks = require('@orderly.network/hooks');
7
+ var i18n = require('@orderly.network/i18n');
8
8
  var reactApp = require('@orderly.network/react-app');
9
9
  var jsxRuntime = require('react/jsx-runtime');
10
10
  var utils = require('@orderly.network/utils');
@@ -907,6 +907,7 @@ var TPSL = (props) => {
907
907
  props.slPriceError
908
908
  );
909
909
  const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
910
+ const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_ERROR;
910
911
  if (!position) {
911
912
  return null;
912
913
  }
@@ -1043,7 +1044,7 @@ var TPSL = (props) => {
1043
1044
  order_type: TPSL_OrderEntity.sl_order_type ?? types.OrderType.MARKET
1044
1045
  },
1045
1046
  hideOrderPrice: TPSL_OrderEntity.position_type === types.PositionType.FULL,
1046
- errors: validated ? slErrors : null,
1047
+ errors: validated ? slErrors : isSlPriceError ? props.slPriceError : null,
1047
1048
  quote_dp: symbolInfo("quote_dp"),
1048
1049
  positionType: TPSL_OrderEntity.position_type ?? types.PositionType.PARTIAL,
1049
1050
  disableOrderTypeSelector: isEditing,
@@ -1323,10 +1324,13 @@ var useTPSLBuilder = (options) => {
1323
1324
  throw new types.SDKError("order is required when isEditing is true");
1324
1325
  }
1325
1326
  const symbolInfo = hooks.useSymbolsInfo();
1326
- react.useRef(types.AlgoOrderRootType.TP_SL);
1327
- const [{ rows: positions }] = hooks.usePositionStream();
1327
+ const { state } = hooks.useAccount();
1328
+ const ee = hooks.useEventEmitter();
1328
1329
  const [needConfirm] = hooks.useLocalStorage("orderly_order_confirm", true);
1329
- const position = positions.find((item) => item.symbol === symbol);
1330
+ const [{ rows: positions }] = hooks.usePositionStream();
1331
+ const mainAccountPosition = positions.find((item) => item.symbol === symbol);
1332
+ const isSubAccount = options.position?.account_id && options.position?.account_id !== state.mainAccountId;
1333
+ const position = isSubAccount ? options.position : mainAccountPosition;
1330
1334
  const estLiqPrice = hooks.useEstLiqPriceBySymbol(symbol);
1331
1335
  react.useEffect(() => {
1332
1336
  if (!position) {
@@ -1454,6 +1458,7 @@ var useTPSLBuilder = (options) => {
1454
1458
  }
1455
1459
  }).then(
1456
1460
  () => {
1461
+ ee.emit("tpsl:updateOrder", options2.position);
1457
1462
  return true;
1458
1463
  },
1459
1464
  () => {
@@ -1470,6 +1475,7 @@ var useTPSLBuilder = (options) => {
1470
1475
  accountId: position?.account_id
1471
1476
  });
1472
1477
  if (res.success) {
1478
+ ee.emit("tpsl:updateOrder", options2.position);
1473
1479
  return res;
1474
1480
  }
1475
1481
  if (res.message) {
@@ -1583,8 +1589,6 @@ ui.registerSimpleDialog(TPSLDialogId, TPSLWidget, {
1583
1589
  });
1584
1590
  var PositionTPSLPopover = (props) => {
1585
1591
  const { position, order: order2, baseDP, quoteDP, buttonProps, isEditing } = props;
1586
- const [needConfirm] = hooks.useLocalStorage("orderly_order_confirm", true);
1587
- const { t } = i18n.useTranslation();
1588
1592
  const isPositionTPSL = isEditing ? order2?.algo_type === types.AlgoOrderRootType.POSITIONAL_TP_SL : void 0;
1589
1593
  const onEdit = () => {
1590
1594
  ui.modal.show(TPSLDialogId, {
@@ -1593,7 +1597,8 @@ var PositionTPSLPopover = (props) => {
1593
1597
  baseDP,
1594
1598
  quoteDP,
1595
1599
  positionType: isPositionTPSL ? types.PositionType.FULL : types.PositionType.PARTIAL,
1596
- isEditing
1600
+ isEditing,
1601
+ position
1597
1602
  });
1598
1603
  };
1599
1604
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { onClick: onEdit, className: "oui-cursor-pointer", children: props.children || /* @__PURE__ */ jsxRuntime.jsx(
@@ -1625,6 +1630,7 @@ var TPSLAdvancedUI = (props) => {
1625
1630
  const { errors, validated } = props.metaState;
1626
1631
  const { getErrorMsg } = reactApp.useOrderEntryFormErrorMsg(props.slPriceError);
1627
1632
  const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
1633
+ const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_ERROR;
1628
1634
  const {
1629
1635
  formattedOrder,
1630
1636
  setValue: setOrderValue,
@@ -1801,7 +1807,7 @@ var TPSLAdvancedUI = (props) => {
1801
1807
  side: formattedOrder.side,
1802
1808
  values: slValues,
1803
1809
  hideOrderPrice: formattedOrder.position_type === types.PositionType.FULL,
1804
- errors: validated ? errors : null,
1810
+ errors: validated ? errors : isSlPriceError ? props.slPriceError : null,
1805
1811
  inputWarnNode: isSlPriceWarning && /* @__PURE__ */ jsxRuntime.jsx(
1806
1812
  ui.DotStatus,
1807
1813
  {
@@ -1957,13 +1963,18 @@ var useTPSLDetail = (props) => {
1957
1963
  const { position } = props;
1958
1964
  const symbol = position.symbol;
1959
1965
  const symbolInfo = hooks.useSymbolsInfo()[symbol];
1966
+ const ee = hooks.useEventEmitter();
1967
+ const { state } = hooks.useAccount();
1960
1968
  const { isMobile } = ui.useScreen();
1961
- const { t } = i18n.useTranslation();
1962
1969
  const [fullPositionOrders, setFullPositionOrders] = react.useState(
1963
1970
  []
1964
1971
  );
1965
1972
  const [partialPositionOrders, setPartialPositionOrders] = react.useState([]);
1966
- const [tpslOrders, { cancelAlgoOrder, cancelPostionOrdersByTypes, refresh }] = hooks.useOrderStream(
1973
+ const isSubAccount = position.account_id && position.account_id !== state.mainAccountId;
1974
+ const [
1975
+ mainAccountTpslOrders,
1976
+ { cancelAlgoOrder, cancelPostionOrdersByTypes }
1977
+ ] = hooks.useOrderStream(
1967
1978
  {
1968
1979
  symbol: position.symbol,
1969
1980
  status: types.OrderStatus.INCOMPLETE,
@@ -1974,10 +1985,46 @@ var useTPSLDetail = (props) => {
1974
1985
  keeplive: true
1975
1986
  }
1976
1987
  );
1988
+ const [
1989
+ subAccountTpslOrders,
1990
+ {
1991
+ cancelAlgoOrder: cancelSubAccountAlgoOrder,
1992
+ cancelPostionOrdersByTypes: cancelSubAccountPostionOrdersByTypes,
1993
+ refresh: refreshSubAccountTpslOrders
1994
+ }
1995
+ ] = hooks.useSubAccountAlgoOrderStream(
1996
+ {
1997
+ symbol: position.symbol,
1998
+ status: types.OrderStatus.INCOMPLETE,
1999
+ includes: [types.AlgoOrderRootType.POSITIONAL_TP_SL, types.AlgoOrderRootType.TP_SL],
2000
+ size: 100
2001
+ },
2002
+ {
2003
+ accountId: position.account_id
2004
+ }
2005
+ );
2006
+ const tpslOrders = isSubAccount ? subAccountTpslOrders : mainAccountTpslOrders;
1977
2007
  const onCancelOrder = async (order2) => {
2008
+ if (isSubAccount) {
2009
+ const res = await cancelSubAccountAlgoOrder(
2010
+ order2.algo_order_id,
2011
+ order2.symbol
2012
+ );
2013
+ refreshSubAccountTpslOrders();
2014
+ ee.emit("tpsl:updateOrder", position);
2015
+ return res;
2016
+ }
1978
2017
  return await cancelAlgoOrder(order2.algo_order_id, order2.symbol);
1979
2018
  };
1980
2019
  const onCancelAllTPSLOrders = async () => {
2020
+ if (isSubAccount) {
2021
+ const res = await cancelSubAccountPostionOrdersByTypes(symbol, [
2022
+ types.AlgoOrderRootType.TP_SL
2023
+ ]);
2024
+ refreshSubAccountTpslOrders();
2025
+ ee.emit("tpsl:updateOrder", position);
2026
+ return res;
2027
+ }
1981
2028
  return await cancelPostionOrdersByTypes(symbol, [types.AlgoOrderRootType.TP_SL]);
1982
2029
  };
1983
2030
  const showTPSLDialog = ({
@@ -1989,6 +2036,7 @@ var useTPSLDetail = (props) => {
1989
2036
  ui.modal.show(dialogId, {
1990
2037
  order: order2,
1991
2038
  symbol: position.symbol,
2039
+ position,
1992
2040
  positionType,
1993
2041
  isEditing
1994
2042
  });
@@ -3351,6 +3399,7 @@ var EditBracketOrderUI = (props) => {
3351
3399
  const { errors, validated } = props.metaState;
3352
3400
  const { isMobile } = ui.useScreen();
3353
3401
  const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
3402
+ const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === hooks.ERROR_MSG_CODES.SL_PRICE_ERROR;
3354
3403
  const { getErrorMsg } = reactApp.useOrderEntryFormErrorMsg(props.slPriceError);
3355
3404
  const {
3356
3405
  formattedOrder,
@@ -3501,7 +3550,7 @@ var EditBracketOrderUI = (props) => {
3501
3550
  label: getErrorMsg("sl_trigger_price")
3502
3551
  }
3503
3552
  ),
3504
- errors: validated ? errors : null,
3553
+ errors: validated ? errors : isSlPriceError ? props.slPriceError : null,
3505
3554
  quote_dp: symbolInfo.quote_dp,
3506
3555
  positionType: formattedOrder.position_type ?? types.PositionType.PARTIAL,
3507
3556
  onChange: (key, value) => {