@orderly.network/ui-tpsl 2.10.2 → 2.11.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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +54 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SDKError, PositionType, AlgoOrderRootType, OrderType, OrderSide, OrderStatus, AlgoOrderType } from '@orderly.network/types';
|
|
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';
|
|
1
|
+
import { SDKError, MarginMode, PositionType, AlgoOrderRootType, OrderType, OrderSide, OrderStatus, AlgoOrderType } from '@orderly.network/types';
|
|
2
|
+
import { Flex, Input, inputFormatter, cn, Slider, Text, registerSimpleSheet, registerSimpleDialog, useScreen, ScrollArea, DotStatus, Grid, Button, ThrottledButton, Divider, Box, toast, TokenIcon, capitalizeFirstLetter, modal, Tooltip, ExclamationFillIcon, Select, ChevronDownIcon, Badge, textVariants, Checkbox, SimpleDropdownMenu, CaretDownIcon, useModal } from '@orderly.network/ui';
|
|
3
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, useGetEstLiqPrice, useOrderStream, useSubAccountAlgoOrderStream, findPositionTPSLFromOrders, useMutation, useMarkPrice, useIndexPrice, useLeverageBySymbol, useMaxQty, findTPSLFromOrder, findTPSLOrderPriceFromOrder } from '@orderly.network/hooks';
|
|
4
|
+
import { utils, useSymbolsInfo, useAccount, useEventEmitter, useLocalStorage, useMarginModeBySymbol, usePositionStream, useEstLiqPriceBySymbol, useTPSLOrder, useTpslPriceChecker, ERROR_MSG_CODES, useMemoizedFn, useOrderEntry, useGetEstLiqPrice, useOrderStream, useSubAccountAlgoOrderStream, findPositionTPSLFromOrders, useMutation, useMarkPrice, useIndexPrice, useLeverageBySymbol, useMaxQty, findTPSLFromOrder, findTPSLOrderPriceFromOrder } from '@orderly.network/hooks';
|
|
5
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';
|
|
@@ -16,7 +16,10 @@ var OrderInfo = (props) => {
|
|
|
16
16
|
const { symbol } = order2;
|
|
17
17
|
const markPrice = useMarkPrice(symbol);
|
|
18
18
|
const indexPrice = useIndexPrice(symbol);
|
|
19
|
-
const leverage = useLeverageBySymbol(
|
|
19
|
+
const leverage = useLeverageBySymbol(
|
|
20
|
+
symbolLeverage ? void 0 : symbol,
|
|
21
|
+
props.marginMode
|
|
22
|
+
);
|
|
20
23
|
const currentLeverage = symbolLeverage || leverage;
|
|
21
24
|
return /* @__PURE__ */ jsxs(
|
|
22
25
|
Flex,
|
|
@@ -49,6 +52,14 @@ var OrderInfo = (props) => {
|
|
|
49
52
|
}
|
|
50
53
|
)
|
|
51
54
|
] }),
|
|
55
|
+
props.marginMode && /* @__PURE__ */ jsx(
|
|
56
|
+
Text,
|
|
57
|
+
{
|
|
58
|
+
size: "2xs",
|
|
59
|
+
className: "oui-h-[18px] oui-rounded oui-bg-base-7 oui-px-2 oui-font-semibold oui-text-base-contrast-36",
|
|
60
|
+
children: capitalizeFirstLetter(props.marginMode)
|
|
61
|
+
}
|
|
62
|
+
),
|
|
52
63
|
/* @__PURE__ */ jsxs(
|
|
53
64
|
Text,
|
|
54
65
|
{
|
|
@@ -215,7 +226,8 @@ var PnlInfo = (props) => {
|
|
|
215
226
|
var useTPSLInputRowScript = (props) => {
|
|
216
227
|
const { values, side, type, rootOrderPrice } = props;
|
|
217
228
|
const symbolLeverage = useLeverageBySymbol(
|
|
218
|
-
props.symbolLeverage ? void 0 : props.symbol
|
|
229
|
+
props.symbolLeverage ? void 0 : props.symbol,
|
|
230
|
+
props.marginMode
|
|
219
231
|
);
|
|
220
232
|
const leverage = props.symbolLeverage || symbolLeverage;
|
|
221
233
|
const roi = useMemo(() => {
|
|
@@ -946,6 +958,7 @@ var TPSL = (props) => {
|
|
|
946
958
|
order_quantity: position.position_qty.toString(),
|
|
947
959
|
order_price: position.average_open_price.toString()
|
|
948
960
|
},
|
|
961
|
+
marginMode: position.margin_mode ?? MarginMode.CROSS,
|
|
949
962
|
symbolLeverage: position.leverage
|
|
950
963
|
}
|
|
951
964
|
),
|
|
@@ -1326,11 +1339,17 @@ var useTPSLBuilder = (options) => {
|
|
|
1326
1339
|
const { state } = useAccount();
|
|
1327
1340
|
const ee = useEventEmitter();
|
|
1328
1341
|
const [needConfirm] = useLocalStorage("orderly_order_confirm", true);
|
|
1342
|
+
const { marginMode: symbolMarginMode } = useMarginModeBySymbol(symbol);
|
|
1329
1343
|
const [{ rows: positions }] = usePositionStream();
|
|
1330
|
-
const mainAccountPosition = positions.find(
|
|
1344
|
+
const mainAccountPosition = positions.find(
|
|
1345
|
+
(item) => item.symbol === symbol && item.margin_mode === (options.position?.margin_mode ?? symbolMarginMode)
|
|
1346
|
+
);
|
|
1331
1347
|
const isSubAccount = options.position?.account_id && options.position?.account_id !== state.mainAccountId;
|
|
1332
1348
|
const position = isSubAccount ? options.position : mainAccountPosition;
|
|
1333
|
-
const estLiqPrice = useEstLiqPriceBySymbol(
|
|
1349
|
+
const estLiqPrice = useEstLiqPriceBySymbol(
|
|
1350
|
+
symbol,
|
|
1351
|
+
position?.margin_mode ?? options.position?.margin_mode ?? MarginMode.CROSS
|
|
1352
|
+
);
|
|
1334
1353
|
useEffect(() => {
|
|
1335
1354
|
if (!position) {
|
|
1336
1355
|
options.close?.();
|
|
@@ -1353,7 +1372,9 @@ var useTPSLBuilder = (options) => {
|
|
|
1353
1372
|
{
|
|
1354
1373
|
symbol,
|
|
1355
1374
|
position_qty: position?.position_qty ?? 0,
|
|
1356
|
-
average_open_price: position?.average_open_price ?? 0
|
|
1375
|
+
average_open_price: position?.average_open_price ?? 0,
|
|
1376
|
+
// Prefer options.position?.margin_mode: mainAccountPosition (from stream) often has wrong default CROSS
|
|
1377
|
+
margin_mode: options.position?.margin_mode ?? position?.margin_mode
|
|
1357
1378
|
},
|
|
1358
1379
|
{
|
|
1359
1380
|
defaultOrder: order2,
|
|
@@ -1916,7 +1937,8 @@ var useTPSLAdvanced = (props) => {
|
|
|
1916
1937
|
sl_offset_percentage: order2.sl_offset_percentage,
|
|
1917
1938
|
tp_pnl: order2.tp_pnl,
|
|
1918
1939
|
tp_offset: order2.tp_offset,
|
|
1919
|
-
tp_offset_percentage: order2.tp_offset_percentage
|
|
1940
|
+
tp_offset_percentage: order2.tp_offset_percentage,
|
|
1941
|
+
margin_mode: order2.margin_mode
|
|
1920
1942
|
}
|
|
1921
1943
|
});
|
|
1922
1944
|
const slPriceError = useTpslPriceChecker({
|
|
@@ -1967,6 +1989,7 @@ registerSimpleDialog(TPSLAdvancedDialogId, TPSLAdvancedWidget, {
|
|
|
1967
1989
|
var useTPSLDetail = (props) => {
|
|
1968
1990
|
const { position } = props;
|
|
1969
1991
|
const symbol = position.symbol;
|
|
1992
|
+
const marginMode = position.margin_mode;
|
|
1970
1993
|
const symbolInfo = useSymbolsInfo()[symbol];
|
|
1971
1994
|
const ee = useEventEmitter();
|
|
1972
1995
|
const { state } = useAccount();
|
|
@@ -2054,11 +2077,11 @@ var useTPSLDetail = (props) => {
|
|
|
2054
2077
|
};
|
|
2055
2078
|
useEffect(() => {
|
|
2056
2079
|
if (tpslOrders) {
|
|
2057
|
-
const { fullPositionOrder, partialPositionOrders: partialPositionOrders2 } = findPositionTPSLFromOrders(tpslOrders, symbol);
|
|
2080
|
+
const { fullPositionOrder, partialPositionOrders: partialPositionOrders2 } = findPositionTPSLFromOrders(tpslOrders, symbol, marginMode);
|
|
2058
2081
|
setFullPositionOrders(fullPositionOrder ? [fullPositionOrder] : []);
|
|
2059
2082
|
setPartialPositionOrders(partialPositionOrders2 ?? []);
|
|
2060
2083
|
}
|
|
2061
|
-
}, [tpslOrders, symbol]);
|
|
2084
|
+
}, [tpslOrders, symbol, marginMode]);
|
|
2062
2085
|
return {
|
|
2063
2086
|
symbolInfo,
|
|
2064
2087
|
position,
|
|
@@ -2075,7 +2098,10 @@ var useTPSLDetail = (props) => {
|
|
|
2075
2098
|
var TPSLDetailContext = createContext({});
|
|
2076
2099
|
var TPSLDetailProvider = (props) => {
|
|
2077
2100
|
const symbolInfo = useSymbolsInfo()[props.symbol];
|
|
2078
|
-
const estLiqPrice = useEstLiqPriceBySymbol(
|
|
2101
|
+
const estLiqPrice = useEstLiqPriceBySymbol(
|
|
2102
|
+
props.symbol,
|
|
2103
|
+
props.position.margin_mode ?? MarginMode.CROSS
|
|
2104
|
+
);
|
|
2079
2105
|
return /* @__PURE__ */ jsx(
|
|
2080
2106
|
TPSLDetailContext.Provider,
|
|
2081
2107
|
{
|
|
@@ -2594,6 +2620,7 @@ var TPSLDetailUI = (props) => {
|
|
|
2594
2620
|
/* @__PURE__ */ jsx(
|
|
2595
2621
|
OrderInfo,
|
|
2596
2622
|
{
|
|
2623
|
+
marginMode: position.margin_mode ?? MarginMode.CROSS,
|
|
2597
2624
|
order: {
|
|
2598
2625
|
symbol: position.symbol,
|
|
2599
2626
|
order_quantity: position.position_qty.toString(),
|
|
@@ -2885,8 +2912,9 @@ registerSimpleSheet(TPSLDetailSheetId, TPSLDetailWidget, {
|
|
|
2885
2912
|
var useTPSLSimpleDialog = (options) => {
|
|
2886
2913
|
const { type, triggerPrice, symbol } = options;
|
|
2887
2914
|
const symbolInfo = useSymbolsInfo();
|
|
2915
|
+
const { marginMode } = useMarginModeBySymbol(symbol ?? "");
|
|
2888
2916
|
const [{ rows: positions }, positionsInfo] = usePositionStream(symbol);
|
|
2889
|
-
const position = positions?.
|
|
2917
|
+
const position = positions?.find((item) => item.margin_mode === marginMode);
|
|
2890
2918
|
useRef(AlgoOrderRootType.TP_SL);
|
|
2891
2919
|
const [needConfirm] = useLocalStorage("orderly_order_confirm", true);
|
|
2892
2920
|
const { t } = useTranslation();
|
|
@@ -2905,8 +2933,9 @@ var useTPSLSimpleDialog = (options) => {
|
|
|
2905
2933
|
] = useTPSLOrder(
|
|
2906
2934
|
{
|
|
2907
2935
|
symbol,
|
|
2908
|
-
position_qty: position?.position_qty,
|
|
2909
|
-
average_open_price: position?.average_open_price
|
|
2936
|
+
position_qty: position?.position_qty ?? 0,
|
|
2937
|
+
average_open_price: position?.average_open_price ?? 0,
|
|
2938
|
+
margin_mode: position?.margin_mode
|
|
2910
2939
|
},
|
|
2911
2940
|
{
|
|
2912
2941
|
defaultOrder: void 0,
|
|
@@ -2925,8 +2954,8 @@ var useTPSLSimpleDialog = (options) => {
|
|
|
2925
2954
|
setValue(type2, value);
|
|
2926
2955
|
};
|
|
2927
2956
|
const maxQty = useMemo(
|
|
2928
|
-
() => Math.abs(Number(position
|
|
2929
|
-
[position
|
|
2957
|
+
() => Math.abs(Number(position?.position_qty ?? 0)),
|
|
2958
|
+
[position?.position_qty]
|
|
2930
2959
|
);
|
|
2931
2960
|
useEffect(() => {
|
|
2932
2961
|
if (!maxQty) {
|
|
@@ -2940,6 +2969,9 @@ var useTPSLSimpleDialog = (options) => {
|
|
|
2940
2969
|
}
|
|
2941
2970
|
}, [type, triggerPrice, maxQty]);
|
|
2942
2971
|
const onSubmit = async () => {
|
|
2972
|
+
if (!position) {
|
|
2973
|
+
return Promise.reject(new Error("Position is required"));
|
|
2974
|
+
}
|
|
2943
2975
|
try {
|
|
2944
2976
|
const validOrder = await validate();
|
|
2945
2977
|
if (validOrder) {
|
|
@@ -3390,7 +3422,10 @@ var useEditBracketOrder = (props) => {
|
|
|
3390
3422
|
};
|
|
3391
3423
|
function useEditOrderMaxQty(order2, positionQty) {
|
|
3392
3424
|
const { reduce_only } = order2;
|
|
3393
|
-
const maxQty = useMaxQty(order2.symbol, order2.side,
|
|
3425
|
+
const maxQty = useMaxQty(order2.symbol, order2.side, {
|
|
3426
|
+
reduceOnly: reduce_only,
|
|
3427
|
+
marginMode: order2.margin_mode ?? MarginMode.CROSS
|
|
3428
|
+
});
|
|
3394
3429
|
return useMemo(() => {
|
|
3395
3430
|
if (reduce_only) {
|
|
3396
3431
|
return Math.abs(positionQty ?? 0);
|
|
@@ -3531,7 +3566,8 @@ var EditBracketOrderUI = (props) => {
|
|
|
3531
3566
|
onChange: (key, value) => {
|
|
3532
3567
|
setOrderValue(key, value);
|
|
3533
3568
|
},
|
|
3534
|
-
positionType: formattedOrder.position_type ?? PositionType.PARTIAL
|
|
3569
|
+
positionType: formattedOrder.position_type ?? PositionType.PARTIAL,
|
|
3570
|
+
marginMode: formattedOrder.margin_mode
|
|
3535
3571
|
}
|
|
3536
3572
|
),
|
|
3537
3573
|
/* @__PURE__ */ jsx(Divider, { className: "oui-w-full" }),
|
|
@@ -3559,7 +3595,8 @@ var EditBracketOrderUI = (props) => {
|
|
|
3559
3595
|
positionType: formattedOrder.position_type ?? PositionType.PARTIAL,
|
|
3560
3596
|
onChange: (key, value) => {
|
|
3561
3597
|
setOrderValue(key, value);
|
|
3562
|
-
}
|
|
3598
|
+
},
|
|
3599
|
+
marginMode: formattedOrder.margin_mode
|
|
3563
3600
|
}
|
|
3564
3601
|
)
|
|
3565
3602
|
] }),
|