@orderly.network/ui-tpsl 2.8.8-alpha.0 → 2.8.9-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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +62 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useTranslation, i18n, Trans } from '@orderly.network/i18n';
|
|
3
|
-
import { SDKError, AlgoOrderRootType, PositionType, OrderType, OrderSide, OrderStatus, AlgoOrderType } from '@orderly.network/types';
|
|
1
|
+
import { SDKError, PositionType, AlgoOrderRootType, OrderType, OrderSide, OrderStatus, AlgoOrderType } from '@orderly.network/types';
|
|
4
2
|
import { Flex, Input, inputFormatter, cn, Slider, Text, registerSimpleSheet, registerSimpleDialog, useScreen, ScrollArea, DotStatus, Grid, Button, ThrottledButton, Divider, Box, toast, TokenIcon, modal, Tooltip, ExclamationFillIcon, Select, ChevronDownIcon, Badge, textVariants, Checkbox, SimpleDropdownMenu, CaretDownIcon, useModal } from '@orderly.network/ui';
|
|
5
3
|
import { memo, useRef, useState, useEffect, createContext, useMemo, useContext, Fragment as Fragment$1 } from 'react';
|
|
4
|
+
import { utils, useSymbolsInfo, useAccount, useEventEmitter, useLocalStorage, usePositionStream, useEstLiqPriceBySymbol, useTPSLOrder, useTpslPriceChecker, ERROR_MSG_CODES, useMemoizedFn, useOrderEntry, useOrderStream, useSubAccountAlgoOrderStream, findPositionTPSLFromOrders, useMutation, useMarkPrice, useIndexPrice, useLeverageBySymbol, useMaxQty, findTPSLFromOrder, findTPSLOrderPriceFromOrder } from '@orderly.network/hooks';
|
|
5
|
+
import { useTranslation, i18n, Trans } from '@orderly.network/i18n';
|
|
6
6
|
import { useOrderEntryFormErrorMsg } from '@orderly.network/react-app';
|
|
7
7
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
8
8
|
import { Decimal, checkIsNaN, transSymbolformString, getTPSLDirection, formatNum, todpIfNeed } from '@orderly.network/utils';
|
|
@@ -905,6 +905,7 @@ var TPSL = (props) => {
|
|
|
905
905
|
props.slPriceError
|
|
906
906
|
);
|
|
907
907
|
const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
908
|
+
const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === ERROR_MSG_CODES.SL_PRICE_ERROR;
|
|
908
909
|
if (!position) {
|
|
909
910
|
return null;
|
|
910
911
|
}
|
|
@@ -1041,7 +1042,7 @@ var TPSL = (props) => {
|
|
|
1041
1042
|
order_type: TPSL_OrderEntity.sl_order_type ?? OrderType.MARKET
|
|
1042
1043
|
},
|
|
1043
1044
|
hideOrderPrice: TPSL_OrderEntity.position_type === PositionType.FULL,
|
|
1044
|
-
errors: validated ? slErrors : null,
|
|
1045
|
+
errors: validated ? slErrors : isSlPriceError ? props.slPriceError : null,
|
|
1045
1046
|
quote_dp: symbolInfo("quote_dp"),
|
|
1046
1047
|
positionType: TPSL_OrderEntity.position_type ?? PositionType.PARTIAL,
|
|
1047
1048
|
disableOrderTypeSelector: isEditing,
|
|
@@ -1321,10 +1322,13 @@ var useTPSLBuilder = (options) => {
|
|
|
1321
1322
|
throw new SDKError("order is required when isEditing is true");
|
|
1322
1323
|
}
|
|
1323
1324
|
const symbolInfo = useSymbolsInfo();
|
|
1324
|
-
|
|
1325
|
-
const
|
|
1325
|
+
const { state } = useAccount();
|
|
1326
|
+
const ee = useEventEmitter();
|
|
1326
1327
|
const [needConfirm] = useLocalStorage("orderly_order_confirm", true);
|
|
1327
|
-
const
|
|
1328
|
+
const [{ rows: positions }] = usePositionStream();
|
|
1329
|
+
const mainAccountPosition = positions.find((item) => item.symbol === symbol);
|
|
1330
|
+
const isSubAccount = options.position?.account_id && options.position?.account_id !== state.mainAccountId;
|
|
1331
|
+
const position = isSubAccount ? options.position : mainAccountPosition;
|
|
1328
1332
|
const estLiqPrice = useEstLiqPriceBySymbol(symbol);
|
|
1329
1333
|
useEffect(() => {
|
|
1330
1334
|
if (!position) {
|
|
@@ -1452,6 +1456,7 @@ var useTPSLBuilder = (options) => {
|
|
|
1452
1456
|
}
|
|
1453
1457
|
}).then(
|
|
1454
1458
|
() => {
|
|
1459
|
+
ee.emit("tpsl:updateOrder", options2.position);
|
|
1455
1460
|
return true;
|
|
1456
1461
|
},
|
|
1457
1462
|
() => {
|
|
@@ -1468,6 +1473,7 @@ var useTPSLBuilder = (options) => {
|
|
|
1468
1473
|
accountId: position?.account_id
|
|
1469
1474
|
});
|
|
1470
1475
|
if (res.success) {
|
|
1476
|
+
ee.emit("tpsl:updateOrder", options2.position);
|
|
1471
1477
|
return res;
|
|
1472
1478
|
}
|
|
1473
1479
|
if (res.message) {
|
|
@@ -1581,8 +1587,6 @@ registerSimpleDialog(TPSLDialogId, TPSLWidget, {
|
|
|
1581
1587
|
});
|
|
1582
1588
|
var PositionTPSLPopover = (props) => {
|
|
1583
1589
|
const { position, order: order2, baseDP, quoteDP, buttonProps, isEditing } = props;
|
|
1584
|
-
const [needConfirm] = useLocalStorage("orderly_order_confirm", true);
|
|
1585
|
-
const { t } = useTranslation();
|
|
1586
1590
|
const isPositionTPSL = isEditing ? order2?.algo_type === AlgoOrderRootType.POSITIONAL_TP_SL : void 0;
|
|
1587
1591
|
const onEdit = () => {
|
|
1588
1592
|
modal.show(TPSLDialogId, {
|
|
@@ -1591,7 +1595,8 @@ var PositionTPSLPopover = (props) => {
|
|
|
1591
1595
|
baseDP,
|
|
1592
1596
|
quoteDP,
|
|
1593
1597
|
positionType: isPositionTPSL ? PositionType.FULL : PositionType.PARTIAL,
|
|
1594
|
-
isEditing
|
|
1598
|
+
isEditing,
|
|
1599
|
+
position
|
|
1595
1600
|
});
|
|
1596
1601
|
};
|
|
1597
1602
|
return /* @__PURE__ */ jsx(Box, { onClick: onEdit, className: "oui-cursor-pointer", children: props.children || /* @__PURE__ */ jsx(
|
|
@@ -1623,6 +1628,7 @@ var TPSLAdvancedUI = (props) => {
|
|
|
1623
1628
|
const { errors, validated } = props.metaState;
|
|
1624
1629
|
const { getErrorMsg } = useOrderEntryFormErrorMsg(props.slPriceError);
|
|
1625
1630
|
const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
1631
|
+
const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === ERROR_MSG_CODES.SL_PRICE_ERROR;
|
|
1626
1632
|
const {
|
|
1627
1633
|
formattedOrder,
|
|
1628
1634
|
setValue: setOrderValue,
|
|
@@ -1799,7 +1805,7 @@ var TPSLAdvancedUI = (props) => {
|
|
|
1799
1805
|
side: formattedOrder.side,
|
|
1800
1806
|
values: slValues,
|
|
1801
1807
|
hideOrderPrice: formattedOrder.position_type === PositionType.FULL,
|
|
1802
|
-
errors: validated ? errors : null,
|
|
1808
|
+
errors: validated ? errors : isSlPriceError ? props.slPriceError : null,
|
|
1803
1809
|
inputWarnNode: isSlPriceWarning && /* @__PURE__ */ jsx(
|
|
1804
1810
|
DotStatus,
|
|
1805
1811
|
{
|
|
@@ -1955,13 +1961,18 @@ var useTPSLDetail = (props) => {
|
|
|
1955
1961
|
const { position } = props;
|
|
1956
1962
|
const symbol = position.symbol;
|
|
1957
1963
|
const symbolInfo = useSymbolsInfo()[symbol];
|
|
1964
|
+
const ee = useEventEmitter();
|
|
1965
|
+
const { state } = useAccount();
|
|
1958
1966
|
const { isMobile } = useScreen();
|
|
1959
|
-
const { t } = useTranslation();
|
|
1960
1967
|
const [fullPositionOrders, setFullPositionOrders] = useState(
|
|
1961
1968
|
[]
|
|
1962
1969
|
);
|
|
1963
1970
|
const [partialPositionOrders, setPartialPositionOrders] = useState([]);
|
|
1964
|
-
const
|
|
1971
|
+
const isSubAccount = position.account_id && position.account_id !== state.mainAccountId;
|
|
1972
|
+
const [
|
|
1973
|
+
mainAccountTpslOrders,
|
|
1974
|
+
{ cancelAlgoOrder, cancelPostionOrdersByTypes }
|
|
1975
|
+
] = useOrderStream(
|
|
1965
1976
|
{
|
|
1966
1977
|
symbol: position.symbol,
|
|
1967
1978
|
status: OrderStatus.INCOMPLETE,
|
|
@@ -1972,10 +1983,46 @@ var useTPSLDetail = (props) => {
|
|
|
1972
1983
|
keeplive: true
|
|
1973
1984
|
}
|
|
1974
1985
|
);
|
|
1986
|
+
const [
|
|
1987
|
+
subAccountTpslOrders,
|
|
1988
|
+
{
|
|
1989
|
+
cancelAlgoOrder: cancelSubAccountAlgoOrder,
|
|
1990
|
+
cancelPostionOrdersByTypes: cancelSubAccountPostionOrdersByTypes,
|
|
1991
|
+
refresh: refreshSubAccountTpslOrders
|
|
1992
|
+
}
|
|
1993
|
+
] = useSubAccountAlgoOrderStream(
|
|
1994
|
+
{
|
|
1995
|
+
symbol: position.symbol,
|
|
1996
|
+
status: OrderStatus.INCOMPLETE,
|
|
1997
|
+
includes: [AlgoOrderRootType.POSITIONAL_TP_SL, AlgoOrderRootType.TP_SL],
|
|
1998
|
+
size: 100
|
|
1999
|
+
},
|
|
2000
|
+
{
|
|
2001
|
+
accountId: position.account_id
|
|
2002
|
+
}
|
|
2003
|
+
);
|
|
2004
|
+
const tpslOrders = isSubAccount ? subAccountTpslOrders : mainAccountTpslOrders;
|
|
1975
2005
|
const onCancelOrder = async (order2) => {
|
|
2006
|
+
if (isSubAccount) {
|
|
2007
|
+
const res = await cancelSubAccountAlgoOrder(
|
|
2008
|
+
order2.algo_order_id,
|
|
2009
|
+
order2.symbol
|
|
2010
|
+
);
|
|
2011
|
+
refreshSubAccountTpslOrders();
|
|
2012
|
+
ee.emit("tpsl:updateOrder", position);
|
|
2013
|
+
return res;
|
|
2014
|
+
}
|
|
1976
2015
|
return await cancelAlgoOrder(order2.algo_order_id, order2.symbol);
|
|
1977
2016
|
};
|
|
1978
2017
|
const onCancelAllTPSLOrders = async () => {
|
|
2018
|
+
if (isSubAccount) {
|
|
2019
|
+
const res = await cancelSubAccountPostionOrdersByTypes(symbol, [
|
|
2020
|
+
AlgoOrderRootType.TP_SL
|
|
2021
|
+
]);
|
|
2022
|
+
refreshSubAccountTpslOrders();
|
|
2023
|
+
ee.emit("tpsl:updateOrder", position);
|
|
2024
|
+
return res;
|
|
2025
|
+
}
|
|
1979
2026
|
return await cancelPostionOrdersByTypes(symbol, [AlgoOrderRootType.TP_SL]);
|
|
1980
2027
|
};
|
|
1981
2028
|
const showTPSLDialog = ({
|
|
@@ -1987,6 +2034,7 @@ var useTPSLDetail = (props) => {
|
|
|
1987
2034
|
modal.show(dialogId, {
|
|
1988
2035
|
order: order2,
|
|
1989
2036
|
symbol: position.symbol,
|
|
2037
|
+
position,
|
|
1990
2038
|
positionType,
|
|
1991
2039
|
isEditing
|
|
1992
2040
|
});
|
|
@@ -3349,6 +3397,7 @@ var EditBracketOrderUI = (props) => {
|
|
|
3349
3397
|
const { errors, validated } = props.metaState;
|
|
3350
3398
|
const { isMobile } = useScreen();
|
|
3351
3399
|
const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
3400
|
+
const isSlPriceError = props.slPriceError?.sl_trigger_price?.type === ERROR_MSG_CODES.SL_PRICE_ERROR;
|
|
3352
3401
|
const { getErrorMsg } = useOrderEntryFormErrorMsg(props.slPriceError);
|
|
3353
3402
|
const {
|
|
3354
3403
|
formattedOrder,
|
|
@@ -3499,7 +3548,7 @@ var EditBracketOrderUI = (props) => {
|
|
|
3499
3548
|
label: getErrorMsg("sl_trigger_price")
|
|
3500
3549
|
}
|
|
3501
3550
|
),
|
|
3502
|
-
errors: validated ? errors : null,
|
|
3551
|
+
errors: validated ? errors : isSlPriceError ? props.slPriceError : null,
|
|
3503
3552
|
quote_dp: symbolInfo.quote_dp,
|
|
3504
3553
|
positionType: formattedOrder.position_type ?? PositionType.PARTIAL,
|
|
3505
3554
|
onChange: (key, value) => {
|