@kodiak-finance/orderly-ui-tpsl 2.8.18 → 2.8.19-rc.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 +14 -9
- package/dist/index.d.ts +14 -9
- package/dist/index.js +3584 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3561 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -4,40 +4,3595 @@ var orderlyHooks = require('@kodiak-finance/orderly-hooks');
|
|
|
4
4
|
var orderlyI18n = require('@kodiak-finance/orderly-i18n');
|
|
5
5
|
var orderlyTypes = require('@kodiak-finance/orderly-types');
|
|
6
6
|
var orderlyUi = require('@kodiak-finance/orderly-ui');
|
|
7
|
+
var react = require('react');
|
|
7
8
|
var orderlyReactApp = require('@kodiak-finance/orderly-react-app');
|
|
8
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
-
var react = require('react');
|
|
10
10
|
var orderlyUtils = require('@kodiak-finance/orderly-utils');
|
|
11
|
-
var orderlyUiConnector = require('@kodiak-finance/orderly-ui-connector');
|
|
12
11
|
var orderlyPerp = require('@kodiak-finance/orderly-perp');
|
|
12
|
+
var orderlyUiConnector = require('@kodiak-finance/orderly-ui-connector');
|
|
13
|
+
|
|
14
|
+
// src/editorPopover.tsx
|
|
15
|
+
var OrderInfo = (props) => {
|
|
16
|
+
const { t } = orderlyI18n.useTranslation();
|
|
17
|
+
const { order: order2, symbolLeverage } = props;
|
|
18
|
+
const { symbol } = order2;
|
|
19
|
+
const markPrice = orderlyHooks.useMarkPrice(symbol);
|
|
20
|
+
const indexPrice = orderlyHooks.useIndexPrice(symbol);
|
|
21
|
+
const leverage = orderlyHooks.useLeverageBySymbol(symbolLeverage ? void 0 : symbol);
|
|
22
|
+
const currentLeverage = symbolLeverage || leverage;
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
24
|
+
orderlyUi.Flex,
|
|
25
|
+
{
|
|
26
|
+
direction: "column",
|
|
27
|
+
itemAlign: "start",
|
|
28
|
+
className: orderlyUi.cn(
|
|
29
|
+
"oui-w-full oui-gap-3 oui-font-semibold ",
|
|
30
|
+
props.classNames?.root
|
|
31
|
+
),
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
34
|
+
orderlyUi.Flex,
|
|
35
|
+
{
|
|
36
|
+
itemAlign: "center",
|
|
37
|
+
className: orderlyUi.cn("oui-gap-2 ", props.classNames?.symbol),
|
|
38
|
+
children: [
|
|
39
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 1, itemAlign: "center", children: [
|
|
40
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.TokenIcon, { symbol, className: "oui-size-5" }),
|
|
41
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
42
|
+
orderlyUi.Text.formatted,
|
|
43
|
+
{
|
|
44
|
+
className: "oui-whitespace-nowrap oui-break-normal",
|
|
45
|
+
rule: "symbol",
|
|
46
|
+
formatString: "base-type",
|
|
47
|
+
size: "sm",
|
|
48
|
+
weight: "semibold",
|
|
49
|
+
intensity: 98,
|
|
50
|
+
children: symbol
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
] }),
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
55
|
+
orderlyUi.Text,
|
|
56
|
+
{
|
|
57
|
+
size: "2xs",
|
|
58
|
+
className: "oui-h-[18px] oui-rounded oui-bg-base-7 oui-px-2 oui-font-semibold oui-text-base-contrast-36",
|
|
59
|
+
children: [
|
|
60
|
+
currentLeverage,
|
|
61
|
+
"x"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
69
|
+
orderlyUi.Grid,
|
|
70
|
+
{
|
|
71
|
+
cols: 2,
|
|
72
|
+
gapX: 2,
|
|
73
|
+
gapY: 1,
|
|
74
|
+
className: orderlyUi.cn("oui-w-full oui-gap-x-2 ", props.classNames?.container),
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: " oui-text-base-contrast-36", children: [
|
|
77
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("common.quantity") }),
|
|
78
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
79
|
+
orderlyUi.Text.numeral,
|
|
80
|
+
{
|
|
81
|
+
rule: "price",
|
|
82
|
+
className: "oui-text-base-contrast-80",
|
|
83
|
+
size: "2xs",
|
|
84
|
+
dp: props.baseDP ?? 2,
|
|
85
|
+
children: Number(order2.order_quantity)
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
] }),
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-text-base-contrast-36", children: [
|
|
90
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("common.lastPrice") }),
|
|
91
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
92
|
+
orderlyUi.Text.numeral,
|
|
93
|
+
{
|
|
94
|
+
rule: "price",
|
|
95
|
+
className: "oui-text-base-contrast-80",
|
|
96
|
+
size: "2xs",
|
|
97
|
+
dp: props.quoteDP ?? 2,
|
|
98
|
+
children: indexPrice?.data
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
] }),
|
|
102
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-text-base-contrast-36", children: [
|
|
103
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("common.orderPrice") }),
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
105
|
+
orderlyUi.Text.numeral,
|
|
106
|
+
{
|
|
107
|
+
rule: "price",
|
|
108
|
+
className: "oui-text-base-contrast-80",
|
|
109
|
+
size: "2xs",
|
|
110
|
+
dp: props.quoteDP ?? 2,
|
|
111
|
+
children: Number(order2.order_price)
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
] }),
|
|
115
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-text-base-contrast-36", children: [
|
|
116
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("common.markPrice") }),
|
|
117
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
118
|
+
orderlyUi.Text.numeral,
|
|
119
|
+
{
|
|
120
|
+
rule: "price",
|
|
121
|
+
className: "oui-text-base-contrast-80",
|
|
122
|
+
size: "2xs",
|
|
123
|
+
dp: props.quoteDP ?? 2,
|
|
124
|
+
children: markPrice?.data
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
] }),
|
|
128
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-text-base-contrast-36", children: [
|
|
129
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("positions.column.liqPrice") }),
|
|
130
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
131
|
+
orderlyUi.Text.numeral,
|
|
132
|
+
{
|
|
133
|
+
rule: "price",
|
|
134
|
+
className: "oui-text-warning",
|
|
135
|
+
size: "2xs",
|
|
136
|
+
dp: props.quoteDP ?? 2,
|
|
137
|
+
children: props.estLiqPrice ?? "--"
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
] })
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
var PnlInfo = (props) => {
|
|
149
|
+
const { t } = orderlyI18n.useTranslation();
|
|
150
|
+
const { tp_pnl, sl_pnl } = props;
|
|
151
|
+
const riskRatio = react.useMemo(() => {
|
|
152
|
+
const defaultNode = /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36", children: "-- x" });
|
|
153
|
+
if (tp_pnl === void 0 || sl_pnl === void 0) {
|
|
154
|
+
return defaultNode;
|
|
155
|
+
}
|
|
156
|
+
if (orderlyUtils.checkIsNaN(tp_pnl) || orderlyUtils.checkIsNaN(sl_pnl)) {
|
|
157
|
+
return defaultNode;
|
|
158
|
+
}
|
|
159
|
+
const tpDecimal = new orderlyUtils.Decimal(tp_pnl);
|
|
160
|
+
const slDecimal = new orderlyUtils.Decimal(sl_pnl);
|
|
161
|
+
if (slDecimal.isZero() || tpDecimal.isZero()) {
|
|
162
|
+
return defaultNode;
|
|
163
|
+
}
|
|
164
|
+
const ratio = tpDecimal.div(slDecimal).abs().toNumber().toFixed(2);
|
|
165
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 1, itemAlign: "center", className: "oui-text-base-contrast-80", children: [
|
|
166
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: ratio }),
|
|
167
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36", children: "x" })
|
|
168
|
+
] });
|
|
169
|
+
}, [tp_pnl, sl_pnl]);
|
|
170
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
171
|
+
orderlyUi.Flex,
|
|
172
|
+
{
|
|
173
|
+
direction: "column",
|
|
174
|
+
itemAlign: "start",
|
|
175
|
+
className: orderlyUi.cn(
|
|
176
|
+
"oui-w-full oui-gap-1 oui-text-2xs oui-text-base-contrast-36",
|
|
177
|
+
props.className
|
|
178
|
+
),
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
181
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("tpsl.totalEstTpPnl") }),
|
|
182
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
183
|
+
orderlyUi.Text.numeral,
|
|
184
|
+
{
|
|
185
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36 oui-ml-1", children: "USDC" }),
|
|
186
|
+
rule: "price",
|
|
187
|
+
coloring: true,
|
|
188
|
+
visible: true,
|
|
189
|
+
size: "2xs",
|
|
190
|
+
dp: 2,
|
|
191
|
+
children: tp_pnl ? Number(tp_pnl) : "--"
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
] }),
|
|
195
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
196
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("tpsl.totalEstSlPnl") }),
|
|
197
|
+
sl_pnl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
198
|
+
orderlyUi.Text.numeral,
|
|
199
|
+
{
|
|
200
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36 oui-ml-1", children: "USDC" }),
|
|
201
|
+
coloring: true,
|
|
202
|
+
visible: true,
|
|
203
|
+
size: "2xs",
|
|
204
|
+
dp: 2,
|
|
205
|
+
children: Number(sl_pnl)
|
|
206
|
+
}
|
|
207
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: "-- USDC" })
|
|
208
|
+
] }),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
210
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("tpsl.riskRewardRatio") }),
|
|
211
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-80", size: "2xs", children: riskRatio })
|
|
212
|
+
] })
|
|
213
|
+
]
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
};
|
|
217
|
+
var useTPSLInputRowScript = (props) => {
|
|
218
|
+
const { values, side, type, rootOrderPrice } = props;
|
|
219
|
+
const symbolLeverage = orderlyHooks.useLeverageBySymbol(
|
|
220
|
+
props.symbolLeverage ? void 0 : props.symbol
|
|
221
|
+
);
|
|
222
|
+
const leverage = props.symbolLeverage || symbolLeverage;
|
|
223
|
+
const roi = react.useMemo(() => {
|
|
224
|
+
if (!leverage || !rootOrderPrice || Number(rootOrderPrice) === 0) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
let closePrice;
|
|
228
|
+
if (values.order_type === orderlyTypes.OrderType.MARKET) {
|
|
229
|
+
closePrice = values.trigger_price;
|
|
230
|
+
} else if (values.order_type === orderlyTypes.OrderType.LIMIT) {
|
|
231
|
+
closePrice = values.order_price;
|
|
232
|
+
}
|
|
233
|
+
if (!closePrice) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
const roi2 = orderlyPerp.order.tpslROI({
|
|
238
|
+
side,
|
|
239
|
+
type,
|
|
240
|
+
closePrice: Number(closePrice),
|
|
241
|
+
orderPrice: Number(rootOrderPrice),
|
|
242
|
+
leverage
|
|
243
|
+
});
|
|
244
|
+
return roi2 * 100;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}, [values, leverage, rootOrderPrice, type, side]);
|
|
249
|
+
return {
|
|
250
|
+
...props,
|
|
251
|
+
roi
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
var usePNLInputBuilder = (props) => {
|
|
255
|
+
const { type, values } = props;
|
|
256
|
+
const [mode, setMode] = orderlyHooks.useLocalStorage(
|
|
257
|
+
"TP/SL_Mode",
|
|
258
|
+
"Offset%" /* PERCENTAGE */
|
|
259
|
+
);
|
|
260
|
+
const [focus, setFocus] = react.useState(true);
|
|
261
|
+
const { t } = orderlyI18n.useTranslation();
|
|
262
|
+
const key = react.useMemo(() => {
|
|
263
|
+
switch (mode) {
|
|
264
|
+
case "Offset" /* OFFSET */:
|
|
265
|
+
return `${type.toLowerCase()}_offset`;
|
|
266
|
+
case "Offset%" /* PERCENTAGE */:
|
|
267
|
+
return `${type.toLowerCase()}_offset_percentage`;
|
|
268
|
+
default:
|
|
269
|
+
return `${type.toLowerCase()}_pnl`;
|
|
270
|
+
}
|
|
271
|
+
}, [mode]);
|
|
272
|
+
const value = react.useMemo(() => {
|
|
273
|
+
return values[mode];
|
|
274
|
+
}, [values, mode]);
|
|
275
|
+
const modes = react.useMemo(() => {
|
|
276
|
+
return [
|
|
277
|
+
{
|
|
278
|
+
label: t("tpsl.pnl"),
|
|
279
|
+
value: "PnL" /* PnL */,
|
|
280
|
+
testId: `${"PnL" /* PnL */}_menu_item`
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
label: t("tpsl.offset"),
|
|
284
|
+
value: "Offset" /* OFFSET */,
|
|
285
|
+
testId: `${"Offset" /* OFFSET */}_mneu_item`
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
label: `${t("tpsl.offset")}%`,
|
|
289
|
+
value: "Offset%" /* PERCENTAGE */,
|
|
290
|
+
testId: `${"Offset%" /* PERCENTAGE */}_menu_item`
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
}, [t]);
|
|
294
|
+
const percentageSuffix = react.useRef("");
|
|
295
|
+
const onValueChange = (value2) => {
|
|
296
|
+
props.onChange(key, value2);
|
|
297
|
+
};
|
|
298
|
+
const formatter = (options) => {
|
|
299
|
+
const { dp = 2 } = options;
|
|
300
|
+
return {
|
|
301
|
+
onRenderBefore: (value2, options2) => {
|
|
302
|
+
value2 = `${value2}`;
|
|
303
|
+
if (value2 === "" || value2 === "-")
|
|
304
|
+
return "";
|
|
305
|
+
if (mode === "Offset%" /* PERCENTAGE */) {
|
|
306
|
+
return `${new orderlyUtils.Decimal(
|
|
307
|
+
value2.replace(
|
|
308
|
+
new RegExp(percentageSuffix.current.replace(".", "\\.") + "$"),
|
|
309
|
+
""
|
|
310
|
+
)
|
|
311
|
+
).mul(100).todp(2, 4).toString()}${percentageSuffix.current}`;
|
|
312
|
+
} else if (mode === "Offset" /* OFFSET */) {
|
|
313
|
+
value2 = orderlyUtils.todpIfNeed(value2, dp);
|
|
314
|
+
} else ;
|
|
315
|
+
return `${value2}`;
|
|
316
|
+
},
|
|
317
|
+
onSendBefore: (value2) => {
|
|
318
|
+
if (/^\-?0{2,}$/.test(value2)) {
|
|
319
|
+
return "0";
|
|
320
|
+
}
|
|
321
|
+
if (mode === "Offset%" /* PERCENTAGE */) {
|
|
322
|
+
if (value2 !== "") {
|
|
323
|
+
value2 = orderlyUtils.todpIfNeed(value2, 2);
|
|
324
|
+
const endStr = value2.match(/\.0{0,2}$/);
|
|
325
|
+
if (!!endStr) {
|
|
326
|
+
percentageSuffix.current = endStr[0];
|
|
327
|
+
} else {
|
|
328
|
+
percentageSuffix.current = "";
|
|
329
|
+
}
|
|
330
|
+
value2 = new orderlyUtils.Decimal(value2).div(100).toString();
|
|
331
|
+
value2 = `${value2}${percentageSuffix.current}`;
|
|
332
|
+
}
|
|
333
|
+
} else if (mode === "PnL" /* PnL */ && type === "SL" && focus) {
|
|
334
|
+
value2 = value2.startsWith("-") ? value2 : "-" + value2;
|
|
335
|
+
} else {
|
|
336
|
+
value2 = orderlyUtils.todpIfNeed(value2, dp);
|
|
337
|
+
}
|
|
338
|
+
if (value2 === "" || value2 === "-")
|
|
339
|
+
return "";
|
|
340
|
+
return value2;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
return {
|
|
345
|
+
mode,
|
|
346
|
+
modes,
|
|
347
|
+
type: props.type,
|
|
348
|
+
formatter,
|
|
349
|
+
onModeChange: (mode2) => {
|
|
350
|
+
setMode(mode2);
|
|
351
|
+
},
|
|
352
|
+
value,
|
|
353
|
+
pnl: values["PnL" /* PnL */],
|
|
354
|
+
onValueChange,
|
|
355
|
+
quote_dp: props.quote_dp,
|
|
356
|
+
setFocus
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
var PNLInput = (props) => {
|
|
360
|
+
const {
|
|
361
|
+
mode,
|
|
362
|
+
modes,
|
|
363
|
+
onModeChange,
|
|
364
|
+
onValueChange,
|
|
365
|
+
quote,
|
|
366
|
+
quote_dp,
|
|
367
|
+
value,
|
|
368
|
+
pnl
|
|
369
|
+
} = props;
|
|
370
|
+
const { t } = orderlyI18n.useTranslation();
|
|
371
|
+
const [prefix, setPrefix] = react.useState(mode);
|
|
372
|
+
const [placeholder, setPlaceholder] = react.useState(
|
|
373
|
+
mode === "Offset%" /* PERCENTAGE */ ? "%" : quote
|
|
374
|
+
);
|
|
375
|
+
const color = react.useMemo(() => {
|
|
376
|
+
const num = Number(pnl);
|
|
377
|
+
if (isNaN(num) || num === 0)
|
|
378
|
+
return "";
|
|
379
|
+
if (num > 0)
|
|
380
|
+
return "oui-text-trade-profit";
|
|
381
|
+
if (num < 0)
|
|
382
|
+
return "oui-text-trade-loss";
|
|
383
|
+
}, [pnl]);
|
|
384
|
+
react.useEffect(() => {
|
|
385
|
+
const label = modes.find((item) => item.value === mode)?.label;
|
|
386
|
+
setPrefix(label);
|
|
387
|
+
setPlaceholder(mode === "Offset%" /* PERCENTAGE */ ? "%" : quote);
|
|
388
|
+
}, [mode, modes]);
|
|
389
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
390
|
+
orderlyUi.Input,
|
|
391
|
+
{
|
|
392
|
+
prefix,
|
|
393
|
+
size: {
|
|
394
|
+
initial: "lg",
|
|
395
|
+
lg: "md"
|
|
396
|
+
},
|
|
397
|
+
placeholder,
|
|
398
|
+
align: "right",
|
|
399
|
+
value,
|
|
400
|
+
"data-testid": props.testId,
|
|
401
|
+
autoComplete: "off",
|
|
402
|
+
onValueChange,
|
|
403
|
+
formatters: [
|
|
404
|
+
// inputFormatter.numberFormatter,
|
|
405
|
+
props.formatter({ dp: quote_dp, mode }),
|
|
406
|
+
orderlyUi.inputFormatter.currencyFormatter,
|
|
407
|
+
orderlyUi.inputFormatter.decimalPointFormatter
|
|
408
|
+
],
|
|
409
|
+
classNames: {
|
|
410
|
+
input: orderlyUi.cn("oui-text-2xs", color),
|
|
411
|
+
prefix: "oui-text-base-contrast-54 oui-text-2xs",
|
|
412
|
+
root: "oui-outline-line-12 focus-within:oui-outline-primary-light"
|
|
413
|
+
},
|
|
414
|
+
onFocus: () => {
|
|
415
|
+
setPlaceholder("");
|
|
416
|
+
props.setFocus(true);
|
|
417
|
+
},
|
|
418
|
+
onBlur: () => {
|
|
419
|
+
setPlaceholder(mode === "Offset%" /* PERCENTAGE */ ? "%" : quote);
|
|
420
|
+
props.setFocus(false);
|
|
421
|
+
},
|
|
422
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
423
|
+
mode === "Offset%" /* PERCENTAGE */ && !!value && /* @__PURE__ */ jsxRuntime.jsx(
|
|
424
|
+
orderlyUi.Text,
|
|
425
|
+
{
|
|
426
|
+
size: "2xs",
|
|
427
|
+
color: "inherit",
|
|
428
|
+
className: orderlyUi.cn("oui-ml-[2px]", color),
|
|
429
|
+
children: "%"
|
|
430
|
+
}
|
|
431
|
+
),
|
|
432
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
433
|
+
PNLMenus,
|
|
434
|
+
{
|
|
435
|
+
mode,
|
|
436
|
+
modes,
|
|
437
|
+
onModeChange: (item) => onModeChange(item.value)
|
|
438
|
+
}
|
|
439
|
+
)
|
|
440
|
+
] })
|
|
441
|
+
}
|
|
442
|
+
);
|
|
443
|
+
};
|
|
444
|
+
var PNLMenus = (props) => {
|
|
445
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
446
|
+
orderlyUi.SimpleDropdownMenu,
|
|
447
|
+
{
|
|
448
|
+
currentValue: props.mode,
|
|
449
|
+
menu: props.modes,
|
|
450
|
+
align: "end",
|
|
451
|
+
size: "xs",
|
|
452
|
+
className: "oui-min-w-[80px]",
|
|
453
|
+
onSelect: (item) => props.onModeChange(item),
|
|
454
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("button", { className: "oui-p-2", children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.CaretDownIcon, { size: 12, color: "white" }) })
|
|
455
|
+
}
|
|
456
|
+
);
|
|
457
|
+
};
|
|
458
|
+
var PnlInputWidget = (props) => {
|
|
459
|
+
const { testId, quote, ...rest } = props;
|
|
460
|
+
const state = usePNLInputBuilder(rest);
|
|
461
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PNLInput, { ...state, testId, quote });
|
|
462
|
+
};
|
|
463
|
+
var OrderPriceType = (props) => {
|
|
464
|
+
const { t } = orderlyI18n.useTranslation();
|
|
465
|
+
const options = [
|
|
466
|
+
{ label: t("orderEntry.orderType.limitOrder"), value: orderlyTypes.OrderType.LIMIT },
|
|
467
|
+
{ label: t("orderEntry.orderType.marketOrder"), value: orderlyTypes.OrderType.MARKET }
|
|
468
|
+
];
|
|
469
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
470
|
+
orderlyUi.Select.options,
|
|
471
|
+
{
|
|
472
|
+
value: props.type,
|
|
473
|
+
options,
|
|
474
|
+
disabled: props.disabled,
|
|
475
|
+
onValueChange: props.onChange,
|
|
476
|
+
size: "xs",
|
|
477
|
+
classNames: {
|
|
478
|
+
trigger: "oui-bg-transparent oui-w-auto oui-outline-line-1 oui-input-root oui-bg-base-6 oui-h-10 lg:oui-h-8 oui-outline-line-12 "
|
|
479
|
+
},
|
|
480
|
+
valueFormatter: (value, option) => {
|
|
481
|
+
const displayLabel = {
|
|
482
|
+
[orderlyTypes.OrderType.LIMIT]: t("orderEntry.orderType.limit"),
|
|
483
|
+
[orderlyTypes.OrderType.MARKET]: t("common.marketPrice")
|
|
484
|
+
}[value];
|
|
485
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: displayLabel });
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
);
|
|
489
|
+
};
|
|
490
|
+
var PriceInput = (props) => {
|
|
491
|
+
const [placeholder, setPlaceholder] = react.useState("USDC");
|
|
492
|
+
const { t } = orderlyI18n.useTranslation();
|
|
493
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
494
|
+
orderlyUi.Input.tooltip,
|
|
495
|
+
{
|
|
496
|
+
"data-testid": `oui-testid-tpsl-popUp-${props.type.toLowerCase()}-input`,
|
|
497
|
+
prefix: props.label ?? t("common.markPrice"),
|
|
498
|
+
size: { initial: "lg", lg: "md" },
|
|
499
|
+
tooltip: props.error,
|
|
500
|
+
placeholder,
|
|
501
|
+
disabled: props.disabled,
|
|
502
|
+
align: "right",
|
|
503
|
+
autoComplete: "off",
|
|
504
|
+
inputMode: "decimal",
|
|
505
|
+
value: props.value,
|
|
506
|
+
color: props.error ? "danger" : void 0,
|
|
507
|
+
classNames: {
|
|
508
|
+
input: orderlyUi.cn(
|
|
509
|
+
"oui-text-2xs placeholder:oui-text-2xs",
|
|
510
|
+
props.classNames?.input
|
|
511
|
+
),
|
|
512
|
+
prefix: orderlyUi.cn(
|
|
513
|
+
"oui-text-base-contrast-54 oui-text-2xs",
|
|
514
|
+
props.classNames?.prefix
|
|
515
|
+
),
|
|
516
|
+
root: orderlyUi.cn("oui-w-full", props.classNames?.root)
|
|
517
|
+
},
|
|
518
|
+
onValueChange: props.onValueChange,
|
|
519
|
+
onFocus: () => {
|
|
520
|
+
setPlaceholder("");
|
|
521
|
+
},
|
|
522
|
+
onBlur: () => {
|
|
523
|
+
setPlaceholder("USDC");
|
|
524
|
+
},
|
|
525
|
+
formatters: [
|
|
526
|
+
orderlyUi.inputFormatter.numberFormatter,
|
|
527
|
+
orderlyUi.inputFormatter.dpFormatter(props.quote_dp),
|
|
528
|
+
orderlyUi.inputFormatter.currencyFormatter,
|
|
529
|
+
orderlyUi.inputFormatter.decimalPointFormatter
|
|
530
|
+
]
|
|
531
|
+
}
|
|
532
|
+
);
|
|
533
|
+
};
|
|
534
|
+
var TPSLInputRowUI = (props) => {
|
|
535
|
+
const { t } = orderlyI18n.useTranslation();
|
|
536
|
+
const { getErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(props.errors);
|
|
537
|
+
const { values, positionType } = props;
|
|
538
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
539
|
+
orderlyUi.Flex,
|
|
540
|
+
{
|
|
541
|
+
direction: "column",
|
|
542
|
+
itemAlign: "start",
|
|
543
|
+
justify: "start",
|
|
544
|
+
className: "oui-w-full",
|
|
545
|
+
children: [
|
|
546
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "sm", intensity: 98, children: props.type === "tp" ? t("tpsl.takeProfit") : t("tpsl.stopLoss") }),
|
|
547
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
548
|
+
orderlyUi.Flex,
|
|
549
|
+
{
|
|
550
|
+
direction: "column",
|
|
551
|
+
gap: 2,
|
|
552
|
+
itemAlign: "start",
|
|
553
|
+
className: "oui-w-full oui-pt-2",
|
|
554
|
+
children: [
|
|
555
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
556
|
+
orderlyUi.Flex,
|
|
557
|
+
{
|
|
558
|
+
direction: "column",
|
|
559
|
+
itemAlign: "start",
|
|
560
|
+
className: "oui-w-full oui-gap-0.5",
|
|
561
|
+
children: [
|
|
562
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-2xs oui-text-base-contrast-54", children: t("common.triggerPrice") }),
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Grid, { cols: 2, gap: 2, className: "oui-w-full oui-px-0.5", children: [
|
|
564
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
565
|
+
PriceInput,
|
|
566
|
+
{
|
|
567
|
+
type: `${props.type} price`,
|
|
568
|
+
value: values.trigger_price,
|
|
569
|
+
error: getErrorMsg(`${props.type}_trigger_price`),
|
|
570
|
+
onValueChange: (value) => {
|
|
571
|
+
props.onChange(`${props.type}_trigger_price`, value);
|
|
572
|
+
},
|
|
573
|
+
quote_dp: props.quote_dp,
|
|
574
|
+
classNames: {
|
|
575
|
+
root: props.inputWarnNode ? "oui-outline-warning-darken focus-within:oui-outline-warning-darken" : void 0
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
),
|
|
579
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
580
|
+
PnlInputWidget,
|
|
581
|
+
{
|
|
582
|
+
type: props.type === "tp" ? "TP" : "SL",
|
|
583
|
+
onChange: (key, value) => {
|
|
584
|
+
props.onChange(key, value);
|
|
585
|
+
},
|
|
586
|
+
quote: "USDC",
|
|
587
|
+
quote_dp: 2,
|
|
588
|
+
values
|
|
589
|
+
}
|
|
590
|
+
)
|
|
591
|
+
] })
|
|
592
|
+
]
|
|
593
|
+
}
|
|
594
|
+
),
|
|
595
|
+
props.inputWarnNode,
|
|
596
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
597
|
+
orderlyUi.Flex,
|
|
598
|
+
{
|
|
599
|
+
direction: "column",
|
|
600
|
+
className: orderlyUi.cn(
|
|
601
|
+
"oui-w-full oui-gap-0.5",
|
|
602
|
+
props.hideOrderPrice ? "oui-hidden" : ""
|
|
603
|
+
),
|
|
604
|
+
itemAlign: "start",
|
|
605
|
+
children: [
|
|
606
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-2xs oui-text-base-contrast-54", children: t("common.orderPrice") }),
|
|
607
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Grid, { cols: 2, gap: 2, className: "oui-w-full oui-px-0.5", children: [
|
|
608
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
609
|
+
PriceInput,
|
|
610
|
+
{
|
|
611
|
+
disabled: positionType === orderlyTypes.PositionType.FULL || values.order_type === orderlyTypes.OrderType.MARKET,
|
|
612
|
+
type: "order price",
|
|
613
|
+
label: values.order_type === orderlyTypes.OrderType.LIMIT ? t("common.limit") : t("common.market"),
|
|
614
|
+
value: values.order_price,
|
|
615
|
+
error: getErrorMsg(`${props.type}_order_price`),
|
|
616
|
+
onValueChange: (value) => {
|
|
617
|
+
props.onChange(`${props.type}_order_price`, value);
|
|
618
|
+
},
|
|
619
|
+
quote_dp: props.quote_dp
|
|
620
|
+
}
|
|
621
|
+
),
|
|
622
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
623
|
+
OrderPriceType,
|
|
624
|
+
{
|
|
625
|
+
disabled: positionType === orderlyTypes.PositionType.FULL || props.disableOrderTypeSelector,
|
|
626
|
+
type: values.order_type,
|
|
627
|
+
onChange: (value) => {
|
|
628
|
+
props.onChange(`${props.type}_order_type`, value);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
)
|
|
632
|
+
] })
|
|
633
|
+
]
|
|
634
|
+
}
|
|
635
|
+
)
|
|
636
|
+
]
|
|
637
|
+
}
|
|
638
|
+
),
|
|
639
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
640
|
+
RenderROI,
|
|
641
|
+
{
|
|
642
|
+
price: values.order_type === orderlyTypes.OrderType.MARKET ? values.trigger_price : values.order_price,
|
|
643
|
+
orderType: values.order_type,
|
|
644
|
+
pnl: values.PnL,
|
|
645
|
+
roi: props.roi,
|
|
646
|
+
dp: props.quote_dp,
|
|
647
|
+
className: "oui-mt-1"
|
|
648
|
+
}
|
|
649
|
+
)
|
|
650
|
+
]
|
|
651
|
+
}
|
|
652
|
+
);
|
|
653
|
+
};
|
|
654
|
+
var RenderROI = (props) => {
|
|
655
|
+
const { t } = orderlyI18n.useTranslation();
|
|
656
|
+
const { price, pnl, roi, dp, className, orderType } = props;
|
|
657
|
+
if (!roi || !price || !pnl) {
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: orderlyUi.cn("oui-text-2xs oui-text-base-contrast-36", className), children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
661
|
+
orderlyI18n.Trans,
|
|
662
|
+
{
|
|
663
|
+
i18nKey: "tpsl.advanced.ROI",
|
|
664
|
+
components: [
|
|
665
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
666
|
+
orderlyUi.Text.numeral,
|
|
667
|
+
{
|
|
668
|
+
className: "oui-px-1 oui-text-base-contrast",
|
|
669
|
+
dp,
|
|
670
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-pl-0.5", children: "USDC" }),
|
|
671
|
+
children: price
|
|
672
|
+
}
|
|
673
|
+
) }, "price"),
|
|
674
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-px-1 oui-text-base-contrast", children: orderType === orderlyTypes.OrderType.MARKET ? t("common.market") : t("common.limit") }) }, "orderType"),
|
|
675
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
676
|
+
orderlyUi.Text.numeral,
|
|
677
|
+
{
|
|
678
|
+
coloring: true,
|
|
679
|
+
className: "oui-whitespace-nowrap oui-px-1",
|
|
680
|
+
dp: 2,
|
|
681
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-pl-0.5", children: "USDC" }),
|
|
682
|
+
children: pnl
|
|
683
|
+
}
|
|
684
|
+
) }, "pnl"),
|
|
685
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
686
|
+
orderlyUi.Text.numeral,
|
|
687
|
+
{
|
|
688
|
+
coloring: true,
|
|
689
|
+
className: "oui-whitespace-nowrap oui-px-1",
|
|
690
|
+
dp: 2,
|
|
691
|
+
suffix: "%",
|
|
692
|
+
children: roi
|
|
693
|
+
}
|
|
694
|
+
) }, "roi")
|
|
695
|
+
]
|
|
696
|
+
}
|
|
697
|
+
) });
|
|
698
|
+
};
|
|
699
|
+
var TPSLInputRowWidget = (props) => {
|
|
700
|
+
const state = useTPSLInputRowScript(props);
|
|
701
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TPSLInputRowUI, { ...state });
|
|
702
|
+
};
|
|
13
703
|
|
|
14
|
-
var H=e=>{let{t}=orderlyI18n.useTranslation(),{order:o,symbolLeverage:r}=e,{symbol:s}=o,i=orderlyHooks.useMarkPrice(s),n=orderlyHooks.useIndexPrice(s),a=orderlyHooks.useLeverageBySymbol(r?void 0:s),l=r||a;return jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",itemAlign:"start",className:orderlyUi.cn("oui-w-full oui-gap-3 oui-font-semibold ",e.classNames?.root),children:[jsxRuntime.jsxs(orderlyUi.Flex,{itemAlign:"center",className:orderlyUi.cn("oui-gap-2 ",e.classNames?.symbol),children:[jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,itemAlign:"center",children:[jsxRuntime.jsx(orderlyUi.TokenIcon,{symbol:s,className:"oui-size-5"}),jsxRuntime.jsx(orderlyUi.Text.formatted,{className:"oui-whitespace-nowrap oui-break-normal",rule:"symbol",formatString:"base-type",size:"sm",weight:"semibold",intensity:98,children:s})]}),jsxRuntime.jsxs(orderlyUi.Text,{size:"2xs",className:"oui-h-[18px] oui-rounded oui-bg-base-7 oui-px-2 oui-font-semibold oui-text-base-contrast-36",children:[l,"x"]})]}),jsxRuntime.jsxs(orderlyUi.Grid,{cols:2,gapX:2,gapY:1,className:orderlyUi.cn("oui-w-full oui-gap-x-2 ",e.classNames?.container),children:[jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:" oui-text-base-contrast-36",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("tpsl.advanced.quantity")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{rule:"price",className:"oui-text-base-contrast-80",size:"2xs",dp:e.baseDP??2,children:Number(o.order_quantity)})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-text-base-contrast-36",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("tpsl.advanced.lastPrice")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{rule:"price",className:"oui-text-base-contrast-80",size:"2xs",dp:e.quoteDP??2,children:n?.data})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-text-base-contrast-36",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("tpsl.advanced.orderPrice")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{rule:"price",className:"oui-text-base-contrast-80",size:"2xs",dp:e.quoteDP??2,children:Number(o.order_price)})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-text-base-contrast-36",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("common.markPrice")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{rule:"price",className:"oui-text-base-contrast-80",size:"2xs",dp:e.quoteDP??2,children:i?.data})]})]})]})};var pe=e=>{let{t}=orderlyI18n.useTranslation(),{tp_pnl:o,sl_pnl:r}=e,s=react.useMemo(()=>{let i=jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36",children:"-- x"});if(o===void 0||r===void 0||orderlyUtils.checkIsNaN(o)||orderlyUtils.checkIsNaN(r))return i;let n=new orderlyUtils.Decimal(o),a=new orderlyUtils.Decimal(r);if(a.isZero()||n.isZero())return i;let l=n.div(a).abs().toNumber().toFixed(2);return jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,itemAlign:"center",className:"oui-text-base-contrast-80",children:[jsxRuntime.jsx(orderlyUi.Text,{children:l}),jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36",children:"x"})]})},[o,r]);return jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",itemAlign:"start",className:orderlyUi.cn("oui-w-full oui-gap-1 oui-text-2xs oui-text-base-contrast-36",e.className),children:[jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("tpsl.totalEstTpPnl")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),rule:"price",coloring:true,visible:true,size:"2xs",dp:2,children:o?Number(o):"--"})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("tpsl.totalEstSlPnl")}),r?jsxRuntime.jsx(orderlyUi.Text.numeral,{suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),coloring:true,visible:true,size:"2xs",dp:2,children:Number(r)}):jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:"-- USDC"})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:t("tpsl.riskRewardRatio")}),jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-80",size:"2xs",children:s})]})]})};var it=e=>({disableOrderTypeSelector:e.disableOrderTypeSelector,values:e.values,onChange:e.onChange,type:e.type,quote_dp:e.quote_dp,positionType:e.positionType,errors:e.errors,hideOrderPrice:e.hideOrderPrice,rootOrderPrice:e.rootOrderPrice,symbol:e.symbol,disableEnableCheckbox:e.disableEnableCheckbox,symbolLeverage:e.symbolLeverage,side:e.side});var kt=e=>{let{type:t,values:o}=e,[r,s]=orderlyHooks.useLocalStorage("TP/SL_Mode","Offset%"),[i,n]=react.useState(true),{t:a}=orderlyI18n.useTranslation(),l=react.useMemo(()=>{switch(r){case "Offset":return `${t.toLowerCase()}_offset`;case "Offset%":return `${t.toLowerCase()}_offset_percentage`;default:return `${t.toLowerCase()}_pnl`}},[r]),m=react.useMemo(()=>o[r],[o,r]),f=react.useMemo(()=>[{label:a("tpsl.pnl"),value:"PnL",testId:"PnL_menu_item"},{label:a("tpsl.offset"),value:"Offset",testId:"Offset_mneu_item"},{label:`${a("tpsl.offset")}%`,value:"Offset%",testId:"Offset%_menu_item"}],[a]),u=react.useRef(""),d=p=>{e.onChange(l,p);},g=p=>{let{dp:y=2}=p;return {onRenderBefore:(c,P)=>(c=`${c}`,c===""||c==="-"?"":r==="Offset%"?`${new orderlyUtils.Decimal(c.replace(new RegExp(u.current.replace(".","\\.")+"$"),"")).mul(100).todp(2,4).toString()}${u.current}`:(r==="Offset"&&(c=orderlyUtils.todpIfNeed(c,y)),`${c}`)),onSendBefore:c=>{if(/^\-?0{2,}$/.test(c))return "0";if(r==="Offset%"){if(c!==""){c=orderlyUtils.todpIfNeed(c,2);let P=c.match(/\.0{0,2}$/);P?u.current=P[0]:u.current="",c=new orderlyUtils.Decimal(c).div(100).toString(),c=`${c}${u.current}`;}}else r==="PnL"&&t==="SL"&&i||(c=orderlyUtils.todpIfNeed(c,y));return c===""||c==="-"?"":c}}};return {mode:r,modes:f,type:e.type,formatter:g,onModeChange:p=>{s(p);},value:m,pnl:o.PnL,onValueChange:d,quote_dp:e.quote_dp,setFocus:n}};var zt=e=>{let{mode:t,modes:o,onModeChange:r,onValueChange:s,quote:i,quote_dp:n,value:a,pnl:l}=e,{t:m}=orderlyI18n.useTranslation(),[f,u]=react.useState(t),[d,g]=react.useState(t==="Offset%"?"%":i),p=react.useMemo(()=>{let y=Number(l);if(isNaN(y)||y===0)return "";if(y>0)return "oui-text-trade-profit";if(y<0)return "oui-text-trade-loss"},[l]);return react.useEffect(()=>{let y=o.find(c=>c.value===t)?.label;u(y),g(t==="Offset%"?"%":i);},[t,o]),jsxRuntime.jsx(orderlyUi.Input,{prefix:f,size:{initial:"lg",lg:"md"},placeholder:d,align:"right",value:a,"data-testid":e.testId,autoComplete:"off",onValueChange:s,formatters:[e.formatter({dp:n,mode:t}),orderlyUi.inputFormatter.currencyFormatter,orderlyUi.inputFormatter.decimalPointFormatter],classNames:{input:orderlyUi.cn("oui-text-2xs",p),prefix:"oui-text-base-contrast-54 oui-text-2xs",root:"oui-outline-line-12 focus-within:oui-outline-primary-light"},onFocus:()=>{g(""),e.setFocus(true);},onBlur:()=>{g(t==="Offset%"?"%":i),e.setFocus(false);},suffix:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[t==="Offset%"&&!!a&&jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",color:"inherit",className:orderlyUi.cn("oui-ml-[2px]",p),children:"%"}),jsxRuntime.jsx(Fo,{mode:t,modes:o,onModeChange:y=>r(y.value)})]})})},Fo=e=>jsxRuntime.jsx(orderlyUi.SimpleDropdownMenu,{currentValue:e.mode,menu:e.modes,align:"end",size:"xs",className:"oui-min-w-[80px]",onSelect:t=>e.onModeChange(t),children:jsxRuntime.jsx("button",{className:"oui-p-2",children:jsxRuntime.jsx(orderlyUi.CaretDownIcon,{size:12,color:"white"})})});var Qt=e=>{let{testId:t,quote:o,...r}=e,s=kt(r);return jsxRuntime.jsx(zt,{...s,testId:t,quote:o})};var Kt=e=>{let{t}=orderlyI18n.useTranslation(),o=[{label:t("orderEntry.orderType.limitOrder"),value:orderlyTypes.OrderType.LIMIT},{label:t("orderEntry.orderType.marketOrder"),value:orderlyTypes.OrderType.MARKET}];return jsxRuntime.jsx(orderlyUi.Select.options,{value:e.type,options:o,disabled:e.disabled,onValueChange:e.onChange,size:"xs",classNames:{trigger:"oui-bg-transparent oui-w-auto oui-outline-line-1 oui-input-root oui-bg-base-6 oui-h-10 lg:oui-h-8 oui-outline-line-12 "},valueFormatter:(r,s)=>{let i={[orderlyTypes.OrderType.LIMIT]:t("orderEntry.orderType.limit"),[orderlyTypes.OrderType.MARKET]:t("common.marketPrice")}[r];return jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:i})}})};var lt=e=>{let[t,o]=react.useState("USDC"),{t:r}=orderlyI18n.useTranslation();return jsxRuntime.jsx(orderlyUi.Input.tooltip,{"data-testid":`oui-testid-tpsl-popUp-${e.type.toLowerCase()}-input`,prefix:e.label??r("common.markPrice"),size:{initial:"lg",lg:"md"},tooltip:e.error,placeholder:t,disabled:e.disabled,align:"right",autoComplete:"off",inputMode:"decimal",value:e.value,color:e.error?"danger":void 0,classNames:{input:"oui-text-2xs placeholder:oui-text-2xs",prefix:"oui-text-base-contrast-54 oui-text-2xs",root:"oui-w-full"},onValueChange:e.onValueChange,onFocus:()=>{o("");},onBlur:()=>{o("USDC");},formatters:[orderlyUi.inputFormatter.numberFormatter,orderlyUi.inputFormatter.dpFormatter(e.quote_dp),orderlyUi.inputFormatter.currencyFormatter,orderlyUi.inputFormatter.decimalPointFormatter]})};var at=e=>{let{t}=orderlyI18n.useTranslation(),{getErrorMsg:o}=orderlyReactApp.useOrderEntryFormErrorMsg(e.errors),{values:r,positionType:s}=e,i=orderlyHooks.useLeverageBySymbol(e.symbolLeverage?void 0:e.symbol),n=e.symbolLeverage||i,a=react.useMemo(()=>{if(!n||isNaN(Number(n)))return null;let l=null;if(!e.rootOrderPrice||!r.trigger_price&&!r.order_price)return null;let m=new orderlyUtils.Decimal(0);if(r.order_type===orderlyTypes.OrderType.MARKET){if(!r.trigger_price)return null;m=new orderlyUtils.Decimal(r.trigger_price);}else if(r.order_type===orderlyTypes.OrderType.LIMIT){if(!r.order_price)return null;m=new orderlyUtils.Decimal(r.order_price);}let f=new orderlyUtils.Decimal(e.rootOrderPrice),u=orderlyUtils.getTPSLDirection({side:e.side,type:e.type,closePrice:m.toNumber(),orderPrice:f.toNumber()});return l=m.minus(f).div(f).mul(n).abs().mul(100).mul(u).toNumber(),l},[r,e.rootOrderPrice,i,e.type,e.side]);return jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",itemAlign:"start",justify:"start",className:"oui-w-full",children:[jsxRuntime.jsxs(orderlyUi.Flex,{className:"oui-w-full",itemAlign:"center",justify:"start",children:[!e.disableEnableCheckbox&&jsxRuntime.jsx(orderlyUi.Checkbox,{"data-testid":`oui-testid-orderEntry-${e.type}-enable-checkBox`,id:`enable_${e.type}`,color:"white",checked:r.enable,onCheckedChange:l=>{e.onChange(`${e.type}_enable`,!!l);}}),jsxRuntime.jsx("label",{htmlFor:`enable_${e.type}`,className:orderlyUi.cn("oui-cursor-pointer oui-text-sm",e.disableEnableCheckbox?"oui-ml-0 oui-text-base-contrast":"oui-ml-1 oui-text-base-contrast-36"),children:e.type==="tp"?t("tpsl.advanced.TP.label"):t("tpsl.advanced.SL.label")})]}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",gap:2,itemAlign:"start",className:orderlyUi.cn("oui-w-full oui-pt-2",r.enable?"":"oui-hidden"),children:[jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",itemAlign:"start",className:"oui-w-full oui-gap-0.5",children:[jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-text-base-contrast-54",children:t("tpsl.advanced.triggerPrice")}),jsxRuntime.jsxs(orderlyUi.Grid,{cols:2,gap:2,className:"oui-w-full oui-px-0.5",children:[jsxRuntime.jsx(lt,{type:`${e.type} price`,value:r.trigger_price,error:o(`${e.type}_trigger_price`),onValueChange:l=>{e.onChange(`${e.type}_trigger_price`,l);},quote_dp:e.quote_dp}),jsxRuntime.jsx(Qt,{type:e.type==="tp"?"TP":"SL",onChange:(l,m)=>{e.onChange(l,m);},quote:"USDC",quote_dp:2,values:r})]})]}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",className:orderlyUi.cn("oui-w-full oui-gap-0.5",e.hideOrderPrice?"oui-hidden":""),itemAlign:"start",children:[jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-text-base-contrast-54",children:t("tpsl.advanced.orderPrice")}),jsxRuntime.jsxs(orderlyUi.Grid,{cols:2,gap:2,className:"oui-w-full oui-px-0.5",children:[jsxRuntime.jsx(lt,{disabled:s===orderlyTypes.PositionType.FULL||r.order_type===orderlyTypes.OrderType.MARKET,type:"order price",label:r.order_type===orderlyTypes.OrderType.LIMIT?t("tpsl.advanced.limit"):t("tpsl.advanced.market"),value:r.order_price,error:o(`${e.type}_order_price`),onValueChange:l=>{e.onChange(`${e.type}_order_price`,l);},quote_dp:e.quote_dp}),jsxRuntime.jsx(Kt,{disabled:s===orderlyTypes.PositionType.FULL||e.disableOrderTypeSelector,type:r.order_type,onChange:l=>{e.onChange(`${e.type}_order_type`,l);}})]})]})]}),jsxRuntime.jsx(jo,{price:r.order_type===orderlyTypes.OrderType.MARKET?r.trigger_price:r.order_price,orderType:r.order_type,pnl:r.PnL,roi:a,dp:e.quote_dp,className:"oui-mt-1"})]})},jo=e=>{let{t}=orderlyI18n.useTranslation(),{price:o,pnl:r,roi:s,dp:i,className:n,orderType:a}=e;return !s||!o||!r?null:jsxRuntime.jsx(orderlyUi.Text,{className:orderlyUi.cn("oui-text-2xs oui-text-base-contrast-36",n),children:jsxRuntime.jsx(orderlyI18n.Trans,{i18nKey:"tpsl.advanced.ROI",components:[jsxRuntime.jsx(react.Fragment,{children:jsxRuntime.jsx(orderlyUi.Text.numeral,{className:"oui-px-1 oui-text-base-contrast",dp:i,suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-pl-0.5",children:"USDC"}),children:o})},"price"),jsxRuntime.jsx(react.Fragment,{children:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-px-1 oui-text-base-contrast",children:a===orderlyTypes.OrderType.MARKET?t("common.market"):t("common.limit")})},"orderType"),jsxRuntime.jsx(react.Fragment,{children:jsxRuntime.jsx(orderlyUi.Text.numeral,{coloring:true,className:"oui-whitespace-nowrap oui-px-1",dp:2,suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-pl-0.5",children:"USDC"}),children:r})},"pnl"),jsxRuntime.jsx(react.Fragment,{children:jsxRuntime.jsx(orderlyUi.Text.numeral,{coloring:true,className:"oui-whitespace-nowrap oui-px-1",dp:2,suffix:"%",children:s})},"roi")]})})};var $=e=>{let t=it(e);return jsxRuntime.jsx(at,{...t})};var Ht=e=>({value:e.value,onChange:e.onChange,disableSelector:e.disableSelector});var ti="position_type",Zt=e=>{let{t}=orderlyI18n.useTranslation(),o=[{label:t("tpsl.positionType.partial"),value:orderlyTypes.PositionType.PARTIAL},{label:t("tpsl.positionType.full"),value:orderlyTypes.PositionType.FULL}];return jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,itemAlign:"center",justify:"start",children:[jsxRuntime.jsx(orderlyUi.Tooltip,{className:"oui-w-[280px] oui-p-3",content:e.value===orderlyTypes.PositionType.FULL?t("tpsl.positionType.full.tips"):t("tpsl.positionType.partial.tips"),children:jsxRuntime.jsx(orderlyUi.ExclamationFillIcon,{className:"oui-cursor-pointer oui-text-base-contrast-54",size:12})}),e.disableSelector?e.value===orderlyTypes.PositionType.FULL?jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-font-semibold oui-text-base-contrast-54",children:t("tpsl.positionType.full")}):jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-font-semibold oui-text-base-contrast-54",children:t("tpsl.positionType.partial")}):jsxRuntime.jsx(orderlyUi.Select.options,{value:e.value,options:o,onValueChange:r=>{e.onChange(ti,r);},size:"xs",classNames:{trigger:" oui-bg-transparent oui-border-0 oui-w-auto oui-px-0"},contentProps:{className:" oui-bg-base-8 oui-border-0"}})]})};var Y=e=>{let t=Ht(e);return jsxRuntime.jsx(Zt,{...t})};var Ue=react.memo(e=>{let{maxQty:t,base_dp:o,baseTick:r,quantity:s}=e,i=react.useRef(null),{t:n}=orderlyI18n.useTranslation(),[a,l]=react.useState(0),m=d=>{let g=d;Number(d)>t&&(g=t.toString()),r>0&&e.onQuantityChange?.(orderlyHooks.utils.formatNumber(g,r)??d);},f=d=>{l(d);let g=new orderlyUtils.Decimal(d).div(100).mul(t).toFixed(o,orderlyUtils.Decimal.ROUND_DOWN);m(g);};react.useEffect(()=>{let d=Math.min(Number(s||0),t),g=new orderlyUtils.Decimal(d).div(t).mul(100).toDecimalPlaces(2,orderlyUtils.Decimal.ROUND_DOWN).toNumber();l(g);},[s,t]);let u=e.quantity.toString().length>0?e.errorMsg:void 0;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(orderlyUi.Flex,{gap:2,children:jsxRuntime.jsx("div",{className:"oui-flex-1",children:jsxRuntime.jsx(orderlyUi.Input.tooltip,{"data-testid":"oui-testid-tpsl-popUp-quantity-input",ref:i,prefix:n("common.quantity"),size:{initial:"md",lg:"sm"},align:"right",value:e.quantity,autoComplete:"off",inputMode:"decimal",classNames:{prefix:"oui-text-base-contrast-54",root:orderlyUi.cn("oui-bg-base-5 oui-outline-line-12",u&&"oui-outline-danger")},tooltipProps:{content:{className:"oui-bg-base-6 oui-text-base-contrast-80"},arrow:{className:"oui-fill-base-6"}},tooltip:u,color:u?"danger":void 0,formatters:[orderlyUi.inputFormatter.dpFormatter(e.base_dp),orderlyUi.inputFormatter.numberFormatter,orderlyUi.inputFormatter.currencyFormatter,orderlyUi.inputFormatter.decimalPointFormatter],onValueChange:d=>{e.onQuantityChange?.(d);let g=Number(d);if(g&&g>e.maxQty){let p=e.maxQty;e.onQuantityChange?.(p),i.current?.blur();}},onBlur:d=>m(d.target.value),suffix:jsxRuntime.jsx("span",{className:"oui-px-3 oui-text-2xs oui-text-base-contrast-54",children:e.base})})})}),jsxRuntime.jsx(orderlyUi.Flex,{mt:2,itemAlign:"center",height:"15px",children:jsxRuntime.jsx(orderlyUi.Slider,{min:0,max:100,markCount:5,showTip:true,value:[a],color:"primary",onValueChange:d=>{f(d[0]);}})}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",children:[jsxRuntime.jsx(orderlyUi.Text.numeral,{color:"primary",size:"2xs",suffix:"%",children:a}),jsxRuntime.jsxs(orderlyUi.Flex,{itemAlign:"center",gap:1,children:[jsxRuntime.jsx("button",{className:"oui-leading-none",style:{lineHeight:0},onClick:()=>{e.onQuantityChange?.(e.maxQty);},children:jsxRuntime.jsx(orderlyUi.Text,{color:"primary",size:"2xs",children:n("common.max")})}),jsxRuntime.jsx(orderlyUi.Text.numeral,{rule:"price",size:"2xs",intensity:54,tick:e.baseTick,children:e.maxQty})]})]})]})});var er=e=>{let{TPSL_OrderEntity:t,symbolInfo:o,onCancel:r,onComplete:s,status:i,position:n,setValues:a,onClose:l,isEditing:m}=e,{errors:f,validated:u}=e.metaState,{t:d}=orderlyI18n.useTranslation(),{isMobile:g}=orderlyUi.useScreen(),{getErrorMsg:p}=orderlyReactApp.useOrderEntryFormErrorMsg(f);if(!n)return null;let y=()=>t.position_type===orderlyTypes.PositionType.FULL?null:jsxRuntime.jsx(orderlyUi.Box,{className:"oui-px-0.5",children:jsxRuntime.jsx(Ue,{maxQty:e.maxQty,quantity:e.orderQuantity??e.maxQty,baseTick:o("base_tick"),base_dp:o("base_dp"),onQuantityChange:e.setQuantity,base:o("base"),isEditing:e.isEditing,errorMsg:u?p("quantity"):void 0})});return jsxRuntime.jsxs("div",{id:"orderly-tp_sl-order-edit-content",children:[jsxRuntime.jsx(orderlyUi.ScrollArea,{className:orderlyUi.cn(g&&"oui-h-[calc(100vh-200px)]"),children:jsxRuntime.jsxs("div",{className:"oui-px-2",children:[jsxRuntime.jsx(H,{baseDP:o("base_dp"),quoteDP:o("quote_dp"),classNames:{root:"oui-mb-3",container:"oui-gap-x-[30px]"},order:{symbol:n.symbol,order_quantity:n.position_qty.toString(),order_price:n.average_open_price.toString()},symbolLeverage:n.leverage}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"start",itemAlign:"start",gap:3,className:"oui-mb-3 oui-w-full",children:[!m&&jsxRuntime.jsx(Y,{disableSelector:true,value:t.position_type??orderlyTypes.PositionType.PARTIAL,onChange:(c,P)=>{e.setOrderValue(c,P);}}),t.position_type===orderlyTypes.PositionType.FULL&&jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-text-warning",children:d("tpsl.positionType.full.tips.market")})]}),y(),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",itemAlign:"start",justify:"start",gap:6,className:"oui-mt-3 oui-w-full",children:[jsxRuntime.jsx($,{symbol:n.symbol,rootOrderPrice:n.average_open_price.toString(),type:"tp",side:n.position_qty>0?orderlyTypes.OrderSide.BUY:orderlyTypes.OrderSide.SELL,values:{enable:t.tp_enable??true,trigger_price:t.tp_trigger_price?.toString()??void 0,PnL:t.tp_pnl?.toString()??void 0,Offset:t.tp_offset?.toString()??void 0,"Offset%":t.tp_offset_percentage?.toString()??void 0,order_price:t.tp_order_price?.toString()??void 0,order_type:t.tp_order_type??orderlyTypes.OrderType.MARKET},hideOrderPrice:t.position_type===orderlyTypes.PositionType.FULL,errors:u?f:null,disableOrderTypeSelector:m,quote_dp:o("quote_dp"),positionType:t.position_type??orderlyTypes.PositionType.PARTIAL,onChange:(c,P)=>{e.setOrderValue(c,P);},symbolLeverage:n.leverage}),jsxRuntime.jsx($,{symbol:n.symbol,rootOrderPrice:n.average_open_price.toString(),type:"sl",side:n.position_qty>0?orderlyTypes.OrderSide.BUY:orderlyTypes.OrderSide.SELL,values:{enable:t.sl_enable??true,trigger_price:t.sl_trigger_price?.toString()??void 0,PnL:t.sl_pnl?.toString()??void 0,Offset:t.sl_offset?.toString()??void 0,"Offset%":t.sl_offset_percentage?.toString()??void 0,order_price:t.sl_order_price?.toString()??void 0,order_type:t.sl_order_type??orderlyTypes.OrderType.MARKET},hideOrderPrice:t.position_type===orderlyTypes.PositionType.FULL,errors:u?f:null,quote_dp:o("quote_dp"),positionType:t.position_type??orderlyTypes.PositionType.PARTIAL,disableOrderTypeSelector:m,onChange:(c,P)=>{e.setOrderValue(c,P);},symbolLeverage:n.leverage})]}),jsxRuntime.jsx(pe,{tp_pnl:t.tp_pnl,sl_pnl:t.sl_pnl,className:"oui-my-3"})]})}),jsxRuntime.jsxs(orderlyUi.Grid,{px:2,cols:2,gap:3,mt:4,children:[jsxRuntime.jsx(orderlyUi.Button,{size:"md",color:"secondary","data-testid":"tpsl-cancel",onClick:()=>{e.close?.();},children:d("common.cancel")}),jsxRuntime.jsx(orderlyUi.ThrottledButton,{size:"md","data-testid":"tpsl-confirm",disabled:i.isCreateMutating,loading:i.isCreateMutating||i.isUpdateMutating,onClick:()=>{e.onSubmit().then(()=>{e.close?.(),s?.();}).catch(c=>{});},children:d("common.confirm")})]})]})};var vi=e=>{let{tpPrice:t,slPrice:o}=e,{t:r}=orderlyI18n.useTranslation();return t&&o?jsxRuntime.jsx(orderlyUi.Badge,{size:"xs",color:"neutral",children:r("common.tpsl")}):t?jsxRuntime.jsx(orderlyUi.Badge,{size:"xs",color:"neutral",children:r("tpsl.tp")}):o?jsxRuntime.jsx(orderlyUi.Badge,{size:"xs",color:"neutral",children:r("tpsl.sl")}):null},Ne=e=>{let{symbol:t,tpPrice:o,slPrice:r,qty:s,maxQty:i,side:n,quoteDP:a,baseDP:l,isEditing:m,isPositionTPSL:f,orderInfo:u}=e,{t:d}=orderlyI18n.useTranslation(),[g,p]=orderlyHooks.useLocalStorage("orderly_order_confirm",true),y=()=>u.position_type===orderlyTypes.PositionType.FULL?jsxRuntime.jsx(orderlyUi.Text,{children:d("tpsl.positionType.full")}):jsxRuntime.jsx(orderlyUi.Text,{children:d("tpsl.positionType.partial")}),c=({price:N,isOrderPrice:O,isEnable:w,colorType:oe})=>w?!N&&O?jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36",children:d("common.market")}):jsxRuntime.jsx(orderlyUi.Text.numeral,{unit:"USDC",rule:"price",className:orderlyUi.cn("oui-text-base-contrast",oe==="TP"?"oui-text-trade-profit":"oui-text-trade-loss"),unitClassName:"oui-text-base-contrast-36 oui-ml-1",dp:a,padding:false,children:N}):jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36",children:"-- USDC"}),P=f;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[m&&jsxRuntime.jsx(orderlyUi.Text,{as:"div",size:"2xs",intensity:80,className:"oui-mb-3",children:d("tpsl.agreement",{symbol:orderlyUtils.transSymbolformString(t)})}),jsxRuntime.jsxs(orderlyUi.Flex,{pb:4,children:[jsxRuntime.jsx(orderlyUi.Box,{grow:true,children:jsxRuntime.jsx(orderlyUi.Text.formatted,{rule:"symbol",formatString:"base-type",size:"base",showIcon:true,as:"div",intensity:80,children:t})}),jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,children:[P&&jsxRuntime.jsx(orderlyUi.Badge,{size:"xs",color:"primary",children:d("common.position")}),jsxRuntime.jsx(vi,{tpPrice:o,slPrice:r}),n===orderlyTypes.OrderSide.SELL?jsxRuntime.jsx(orderlyUi.Badge,{size:"xs",color:"success",children:d("common.buy")}):jsxRuntime.jsx(orderlyUi.Badge,{size:"xs",color:"danger",children:d("common.sell")})]})]}),jsxRuntime.jsx(orderlyUi.Divider,{}),u.tp_trigger_price||u.sl_trigger_price?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(orderlyUi.Divider,{className:"oui-my-4"}),jsxRuntime.jsxs("div",{className:orderlyUi.textVariants({size:"sm",intensity:54,className:"oui-space-y-1 oui-w-full oui-flex oui-flex-col oui-gap-3"}),children:[jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast",children:y()}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",children:[jsxRuntime.jsx(orderlyUi.Text,{children:d("common.orderQty")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{rule:"price",dp:l,padding:false,className:"oui-text-base-contrast",children:u.quantity??"-"})]}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"between",itemAlign:"start",gap:1,className:"oui-w-full",children:[jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{children:d("tpsl.tpTriggerPrice")})," ",c({price:u.tp_trigger_price??"",isOrderPrice:false,isEnable:!!u.tp_trigger_price,colorType:"TP"})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{children:d("tpsl.tpOrderPrice")}),c({price:u.tp_order_price??"",isOrderPrice:true,isEnable:!!u.tp_trigger_price,colorType:"TP"})]})]}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"between",itemAlign:"start",gap:1,className:"oui-w-full",children:[jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{children:d("tpsl.slTriggerPrice")}),c({price:u.sl_trigger_price??"",isOrderPrice:false,isEnable:!!u.sl_trigger_price,colorType:"SL"})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{children:d("tpsl.slOrderPrice")}),c({price:u.sl_order_price??"",isOrderPrice:true,isEnable:!!u.sl_trigger_price,colorType:"SL"})]})]})]})]}):null,jsxRuntime.jsx(orderlyUi.Box,{pt:2,children:jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,children:[jsxRuntime.jsx(orderlyUi.Checkbox,{id:"disabledConfirm",color:"white",checked:!g,onCheckedChange:N=>{p(!N);}}),jsxRuntime.jsx("label",{htmlFor:"disabledConfirm",className:orderlyUi.textVariants({size:"xs",intensity:54,className:"oui-ml-1"}),children:d("orderEntry.disableOrderConfirm")})]})})]})};var mr=e=>{let{symbol:t,order:o,isEditing:r,positionType:s,triggerPrice:i,type:n,withTriggerPrice:a}=e,{t:l}=orderlyI18n.useTranslation();if(r&&!o)throw new orderlyTypes.SDKError("order is required when isEditing is true");let m=orderlyHooks.useSymbolsInfo();react.useRef(orderlyTypes.AlgoOrderRootType.TP_SL);let [{rows:u}]=orderlyHooks.usePositionStream(),[d]=orderlyHooks.useLocalStorage("orderly_order_confirm",true),g=u.find(x=>x.symbol===t);react.useEffect(()=>{g||e.close?.();},[g]);let [p,{submit:y,deleteOrder:c,setValue:P,setValues:N,validate:O,metaState:w,errors:oe,isCreateMutating:be,isUpdateMutating:ie}]=orderlyHooks.useTPSLOrder({symbol:t,position_qty:g?.position_qty??0,average_open_price:g?.average_open_price??0},{defaultOrder:o,positionType:i?orderlyTypes.PositionType.PARTIAL:s,tpslEnable:{tp_enable:a?n==="tp":true,sl_enable:a?n==="sl":true},isEditing:r}),tt=x=>{P("quantity",x);},k=(x,L)=>{P(x,L);},h=(x,L)=>{P(x,L);},wt=react.useMemo(()=>Math.abs(Number(g?.position_qty)),[g?.position_qty]);react.useMemo(()=>{let x=o?.algo_type===orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL?wt:o?.quantity,L=0;if((Number(p.quantity)!==x||!r&&p.quantity)&&(L=1),o&&r){let{tp_trigger_price:rt,sl_trigger_price:W}=orderlyHooks.utils.findTPSLFromOrder(o),{tp_order_price:Dt,sl_order_price:Et}=orderlyHooks.utils.findTPSLOrderPriceFromOrder(o);rt!==Number(p.tp_trigger_price)&&typeof typeof p.tp_trigger_price<"u"&&(L=2),W!==Number(p.sl_trigger_price)&&typeof p.sl_trigger_price<"u"&&(L=3),typeof p.tp_order_price<"u"&&Dt!==orderlyTypes.OrderType.MARKET&&Dt!==Number(p.tp_order_price)&&(L=4),typeof p.sl_order_price<"u"&&Et!==orderlyTypes.OrderType.MARKET&&Et!==Number(p.sl_order_price)&&(L=5);}return L===1&&!p.tp_trigger_price&&!p.sl_trigger_price&&(L=-1),L},[p.tp_trigger_price,p.tp_order_price,p.sl_trigger_price,p.sl_order_price,p.quantity,o,r]);react.useEffect(()=>{a&&i&&(P(n==="tp"?"tp_trigger_price":"sl_trigger_price",i),e.qty&&P("quantity",e.qty));},[n,i,e.qty]);let lo=()=>o?.algo_order_id&&o?.symbol?c(o?.algo_order_id,o?.symbol):Promise.reject("order id or symbol is invalid"),ao=(x,L)=>{if(!d)return Promise.resolve(true);let rt=Math.abs(Number(g?.position_qty));return `${x.tp_trigger_price??""}`.length===0&&`${x.sl_trigger_price??""}`.length===0?orderlyUi.modal.confirm({title:l("orders.cancelOrder"),content:l("tpsl.cancelOrder.description"),onOk:()=>L.cancel()}).then(()=>true,()=>Promise.reject(false)):orderlyUi.modal.confirm({title:l("tpsl.confirmOrder"),onOk:async()=>{try{let W=await L.submit({accountId:g?.account_id});return W.success?W:(W.message&&orderlyUi.toast.error(W.message),!1)}catch(W){return W?.message&&orderlyUi.toast.error(W.message),false}},classNames:{body:"!oui-pb-0"},content:jsxRuntime.jsx(Ne,{isPositionTPSL:s===orderlyTypes.PositionType.FULL,isEditing:r,symbol:x.symbol,qty:Number(x.quantity),maxQty:rt,tpPrice:Number(x.tp_trigger_price),slPrice:Number(x.sl_trigger_price),side:x.side,orderInfo:x,quoteDP:m[t]("quote_dp")??2,baseDP:m[t]("base_dp")??2})}).then(()=>true,()=>Promise.reject(false))},uo=async()=>{try{if(await O())return d?ao(p,{position:g,submit:y,cancel:lo}):y({accountId:g?.account_id}).then(()=>!0).catch(L=>{throw L?.message&&orderlyUi.toast.error(L.message),!1})}catch(x){return Promise.reject(x)}};return {isEditing:r,symbolInfo:m[t],maxQty:wt,setQuantity:orderlyHooks.useMemoizedFn(tt),orderQuantity:p.quantity,TPSL_OrderEntity:p,setOrderValue:P,setPnL:h,setOrderPrice:k,onSubmit:uo,metaState:w,errors:oe,status:{isCreateMutating:be,isUpdateMutating:ie},position:g,setValues:N}};var he=e=>{let{onCancel:t,onComplete:o,...r}=e,s=mr(r);return jsxRuntime.jsx(er,{...s,onCancel:t,onComplete:o,close:r.close})},ze="TPSLSheetId",fe="TPSLDialogId";orderlyUi.registerSimpleSheet(ze,he);orderlyUi.registerSimpleDialog(fe,he,{classNames:{content:"oui-w-[420px]"}});var Hi=e=>{let{position:t,order:o,baseDP:r,quoteDP:s,buttonProps:i,isEditing:n}=e,[a]=orderlyHooks.useLocalStorage("orderly_order_confirm",true),{t:l}=orderlyI18n.useTranslation(),m=n?o?.algo_type===orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL:void 0;return jsxRuntime.jsx(orderlyUi.Box,{onClick:()=>{orderlyUi.modal.show(fe,{order:o,symbol:t.symbol,baseDP:r,quoteDP:s,positionType:m?orderlyTypes.PositionType.FULL:orderlyTypes.PositionType.PARTIAL,isEditing:n});},className:"oui-cursor-pointer",children:e.children||jsxRuntime.jsx(orderlyUi.Button,{variant:"outlined",size:"sm",color:"secondary",...i,children:e.label})})};var Xi=e=>{let{position:t,order:o,symbolInfo:r,isEditing:s}=e,{resolve:i,hide:n,updateArgs:a}=orderlyUi.useModal(),l=s?o?.algo_type===orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL:void 0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(he,{...e,positionType:e.positionType??(l?orderlyTypes.PositionType.FULL:orderlyTypes.PositionType.PARTIAL),onCancel:()=>{n();}})})};var br=e=>{let{t}=orderlyI18n.useTranslation(),{errors:o,validated:r}=e.metaState,{formattedOrder:s,setValue:i,symbolInfo:n,setValues:a}=e,[l,m]=react.useState({enable:true,order_type:s.tp_order_type??orderlyTypes.OrderType.MARKET,order_price:s.tp_order_price??"",trigger_price:s.tp_trigger_price??"",PnL:s.tp_pnl??"",Offset:s.tp_offset??"","Offset%":s.tp_offset_percentage??"",ROI:s.tp_ROI??""}),[f,u]=react.useState({enable:true,order_type:s.sl_order_type??orderlyTypes.OrderType.MARKET,order_price:s.sl_order_price??"",trigger_price:s.sl_trigger_price??"",PnL:s.sl_pnl??"",Offset:s.sl_offset??"","Offset%":s.sl_offset_percentage??"",ROI:s.sl_ROI??""});return react.useEffect(()=>{m(d=>({...d,enable:s.tp_enable??true,order_type:s.tp_order_type??orderlyTypes.OrderType.MARKET,order_price:s.tp_order_price??"",trigger_price:s.tp_trigger_price??"",PnL:s.tp_pnl??"",Offset:s.tp_offset??"","Offset%":s.tp_offset_percentage??"",ROI:s.tp_ROI??""}));},[s]),react.useEffect(()=>{u(d=>({...d,enable:s.sl_enable??true,order_type:s.sl_order_type??orderlyTypes.OrderType.MARKET,order_price:s.sl_order_price??"",trigger_price:s.sl_trigger_price??"",PnL:s.sl_pnl??"",Offset:s.sl_offset??"","Offset%":s.sl_offset_percentage??"",ROI:s.sl_ROI??""}));},[s]),jsxRuntime.jsxs("div",{className:"oui-rounded-[16px] oui-py-3 oui-flex oui-flex-col oui-justify-between oui-h-full",children:[jsxRuntime.jsx("div",{className:"oui-px-3",children:jsxRuntime.jsxs(orderlyUi.Flex,{className:"oui-mb-5 oui-cursor-pointer oui-text-base oui-text-base-contrast-80",gap:1,itemAlign:"center",onClick:e.onClose,children:[jsxRuntime.jsx(os,{className:" oui-text-base-contrast-80"}),jsxRuntime.jsx(orderlyUi.Text,{children:t("tpsl.advanced.title")})]})}),jsxRuntime.jsxs(orderlyUi.ScrollArea,{className:"oui-flex-1",children:[jsxRuntime.jsx("div",{className:"oui-px-3",children:jsxRuntime.jsx(H,{order:s,baseDP:n.base_dp,quoteDP:n.quote_dp,symbolLeverage:e.symbolLeverage})}),jsxRuntime.jsx(orderlyUi.Divider,{className:"oui-my-3"}),jsxRuntime.jsxs("div",{className:"oui-px-3",children:[jsxRuntime.jsxs(orderlyUi.Flex,{className:"oui-gap-[6px]",children:[jsxRuntime.jsx(orderlyUi.Button,{onClick:()=>{i("side",orderlyTypes.OrderSide.BUY);},size:"sm",fullWidth:true,"data-type":orderlyTypes.OrderSide.BUY,className:orderlyUi.cn(s.side===orderlyTypes.OrderSide.BUY?"oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80":"oui-bg-base-7 oui-text-base-contrast-36 hover:oui-bg-base-6 active:oui-bg-base-6"),"data-testid":"oui-testid-orderEntry-side-buy-button",children:t("common.buy")}),jsxRuntime.jsx(orderlyUi.Button,{onClick:()=>{i("side",orderlyTypes.OrderSide.SELL);},"data-type":orderlyTypes.OrderSide.SELL,fullWidth:true,size:"sm",className:orderlyUi.cn(s.side===orderlyTypes.OrderSide.SELL?"oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80":"oui-bg-base-7 oui-text-base-contrast-36 hover:oui-bg-base-6 active:oui-bg-base-6"),"data-testid":"oui-testid-orderEntry-side-sell-button",children:t("common.sell")})]}),jsxRuntime.jsxs("div",{className:"oui-py-3",children:[jsxRuntime.jsx(Y,{value:s.position_type??orderlyTypes.PositionType.PARTIAL,onChange:(d,g)=>{if(g===orderlyTypes.PositionType.FULL){a({position_type:orderlyTypes.PositionType.FULL,tp_order_type:orderlyTypes.OrderType.MARKET,tp_order_price:void 0,sl_order_type:orderlyTypes.OrderType.MARKET,sl_order_price:void 0});return}i("position_type",g);}}),s.position_type===orderlyTypes.PositionType.FULL&&jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"start",gap:2,className:"oui-mt-3 oui-w-full",children:[jsxRuntime.jsx("div",{className:"oui-relative oui-top-[7px] oui-size-1 oui-rounded-full oui-bg-[#D25f00]"}),jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-text-[#D25f00]",children:t("tpsl.positionType.full.tips.market")})]})]}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",gap:6,children:[jsxRuntime.jsx($,{rootOrderPrice:s.order_price,symbol:n.symbol,type:"tp",side:s.side,values:l,errors:r?o:null,quote_dp:n.quote_dp,hideOrderPrice:s.position_type===orderlyTypes.PositionType.FULL,onChange:(d,g)=>{i(d,g);},positionType:s.position_type??orderlyTypes.PositionType.PARTIAL,symbolLeverage:e.symbolLeverage}),jsxRuntime.jsx($,{rootOrderPrice:s.order_price,symbol:n.symbol,type:"sl",side:s.side,values:f,hideOrderPrice:s.position_type===orderlyTypes.PositionType.FULL,errors:r?o:null,quote_dp:n.quote_dp,positionType:s.position_type??orderlyTypes.PositionType.PARTIAL,onChange:(d,g)=>{i(d,g);},symbolLeverage:e.symbolLeverage})]}),jsxRuntime.jsx(pe,{tp_pnl:s.tp_pnl,sl_pnl:s.sl_pnl,className:"oui-mt-6"})]})]}),jsxRuntime.jsxs(orderlyUi.Flex,{className:"oui-mt-6 oui-px-3",gap:2,children:[jsxRuntime.jsx(orderlyUi.Button,{size:"md",fullWidth:true,color:"gray",variant:"outlined",className:"oui-text-base-contrast-36",onClick:e.onClose,children:t("common.cancel")}),jsxRuntime.jsx(orderlyUi.Button,{size:"md",fullWidth:true,color:"success",className:orderlyUi.cn(s.side===orderlyTypes.OrderSide.SELL?"oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80":"oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80"),onClick:e.onSubmit,children:t("tpsl.advanced.submit")})]})]})},os=e=>jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",...e,children:jsxRuntime.jsx("path",{d:"M8.03752 2.9294C7.89169 2.95857 7.74527 3.03207 7.65661 3.16624L5.33145 6.66624C5.20137 6.86224 5.20137 7.12648 5.33145 7.32248L7.65661 10.8225C7.83452 11.0902 8.20669 11.1655 8.47385 10.9864C8.74044 10.8079 8.8151 10.434 8.63719 10.1662L6.53019 6.99408L8.63719 3.82249C8.8151 3.55416 8.74044 3.18082 8.47385 3.00232C8.34027 2.91249 8.18335 2.89965 8.03752 2.9294Z"})});var Sr=(e,t)=>{if(e.tp_trigger_price||e.sl_trigger_price){if(t==="tp")return !!e.tp_trigger_price;if(t==="sl")return !!e.sl_trigger_price}return true},Or=e=>{let{order:t,setOrderValue:o,onClose:r}=e,[s,i]=react.useState(null),{formattedOrder:n,setValue:a,setValues:l,helper:m,symbolInfo:f,metaState:u,...d}=orderlyHooks.useOrderEntry(t.symbol,{initialOrder:{symbol:t.symbol,order_type:t.order_type,side:t.side,order_price:t.order_price,order_quantity:t.order_quantity,position_type:t.position_type??orderlyTypes.PositionType.PARTIAL,trigger_price:t.trigger_price,tp_enable:Sr(t,"tp"),sl_enable:Sr(t,"sl"),tp_trigger_price:t.tp_trigger_price,sl_trigger_price:t.sl_trigger_price,tp_order_price:t.tp_order_price,sl_order_price:t.sl_order_price,tp_order_type:t.tp_order_type,sl_order_type:t.sl_order_type,sl_pnl:t.sl_pnl,sl_offset:t.sl_offset,sl_offset_percentage:t.sl_offset_percentage,tp_pnl:t.tp_pnl,tp_offset:t.tp_offset,tp_offset_percentage:t.tp_offset_percentage}});return {order:t,formattedOrder:n,symbolInfo:f,setValue:a,setValues:l,onSubmit:()=>{m.validate().then(()=>{e.onSubmit(n);}).catch(p=>{});},onClose:r,metaState:u,symbolLeverage:e.symbolLeverage}};var Ir=e=>{let t=Or({order:e.order,setOrderValue:e.setOrderValue,onSubmit:e.onSubmit,onClose:e.onClose,symbolLeverage:e.symbolLeverage});return jsxRuntime.jsx(br,{...t})},ds="TPSLAdvancedSheetId",us="TPSLAdvancedDialogId";orderlyUi.registerSimpleSheet(ds,Ir,{title:()=>orderlyI18n.i18n.t("common.settings")});orderlyUi.registerSimpleDialog(us,Ir,{title:()=>orderlyI18n.i18n.t("common.settings")});var Nr=e=>{let{position:t}=e,o=t.symbol,r=orderlyHooks.useSymbolsInfo()[o],{isMobile:s}=orderlyUi.useScreen(),{t:i}=orderlyI18n.useTranslation(),[n,a]=react.useState([]),[l,m]=react.useState([]),[f,{cancelAlgoOrder:u,cancelPostionOrdersByTypes:d,refresh:g}]=orderlyHooks.useOrderStream({symbol:t.symbol,status:orderlyTypes.OrderStatus.INCOMPLETE,includes:[orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL,orderlyTypes.AlgoOrderRootType.TP_SL],size:500},{keeplive:true}),p=async O=>await u(O.algo_order_id,O.symbol),y=async()=>await d(o,[orderlyTypes.AlgoOrderRootType.TP_SL]),c=({order:O,positionType:w,isEditing:oe})=>{let be=s?ze:fe;orderlyUi.modal.show(be,{order:O,symbol:t.symbol,positionType:w,isEditing:oe});},P=(O,w)=>{c({order:O,positionType:w,isEditing:true});},N=O=>{c({positionType:O,isEditing:false});};return react.useEffect(()=>{if(f){let{fullPositionOrder:O,partialPositionOrders:w}=orderlyHooks.findPositionTPSLFromOrders(f,o);a(O?[O]:[]),m(w??[]);}},[f,o]),{symbolInfo:r,position:t,symbol:o,fullPositionOrders:n,partialPositionOrders:l,cancelPostionOrdersByTypes:d,onCancelOrder:p,onCancelAllTPSLOrders:y,editTPSLOrder:P,addTPSLOrder:N}};var hr=react.createContext({}),Cr=e=>{let t=orderlyHooks.useSymbolsInfo()[e.symbol];return jsxRuntime.jsx(hr.Provider,{value:{base_dp:t("base_dp"),quote_dp:t("quote_dp"),position:e.position},children:e.children})},X=()=>react.useContext(hr);var C=e=>jsxRuntime.jsx(orderlyUi.Flex,{direction:"column",justify:"center",itemAlign:"start",className:"oui-text-2xs oui-h-[36px]",children:e.children});var gt=({order:e})=>{let{position:t,base_dp:o,quote_dp:r}=X(),{tp_trigger_price:s,sl_trigger_price:i}=orderlyHooks.findTPSLFromOrder(e),n,a,l=new orderlyUtils.Decimal(e.quantity).eq(0)?t.position_qty:e.quantity,m=t.position_qty>0?orderlyTypes.OrderSide.BUY:orderlyTypes.OrderSide.SELL,f=t?.average_open_price;if(s){let u=orderlyUtils.getTPSLDirection({side:m,type:"tp",closePrice:s,orderPrice:f});n=new orderlyUtils.Decimal(orderlyPerp.positions.unrealizedPnL({qty:l,openPrice:f,markPrice:s})).abs().mul(u).toNumber();}if(i){let u=orderlyUtils.getTPSLDirection({side:m,type:"sl",closePrice:i,orderPrice:f});a=new orderlyUtils.Decimal(orderlyPerp.positions.unrealizedPnL({qty:l,openPrice:f,markPrice:i})).abs().mul(u).toNumber();}return jsxRuntime.jsxs(orderlyUi.Flex,{gap:2,direction:"column",justify:"between",itemAlign:"start",className:"oui-text-2xs",children:[n&&jsxRuntime.jsx(C,{children:jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:2,rm:orderlyUtils.Decimal.ROUND_DOWN,coloring:true,padding:false,children:n})}),a&&jsxRuntime.jsx(C,{children:jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:2,rm:orderlyUtils.Decimal.ROUND_DOWN,coloring:true,padding:false,children:a})})]})};var ft=({order:e})=>{let{quote_dp:t}=X(),{tp_order_price:o,sl_order_price:r}=orderlyHooks.findTPSLOrderPriceFromOrder(e),{t:s}=orderlyI18n.useTranslation();return jsxRuntime.jsxs(orderlyUi.Flex,{gap:2,direction:"column",justify:"between",itemAlign:"start",className:"oui-text-2xs",children:[o&&jsxRuntime.jsx(C,{children:o===orderlyTypes.OrderType.MARKET?jsxRuntime.jsx(orderlyUi.Text,{children:s("common.market")}):jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:t,rm:orderlyUtils.Decimal.ROUND_DOWN,padding:false,children:o})}),r&&jsxRuntime.jsx(C,{children:r===orderlyTypes.OrderType.MARKET?jsxRuntime.jsx(orderlyUi.Text,{children:s("common.market")}):jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:t,rm:orderlyUtils.Decimal.ROUND_DOWN,padding:false,children:r})})]})};var yt=({order:e})=>{let{position:t,base_dp:o}=X(),{tp_trigger_price:r,sl_trigger_price:s}=orderlyHooks.findTPSLFromOrder(e),i=react.useMemo(()=>e.quantity===0?-t.position_qty:t.position_qty>0?-e.quantity:e.quantity,[e.quantity,t.position_qty]);return jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"start",itemAlign:"start",className:"oui-h-full oui-text-2xs",children:[jsxRuntime.jsx(C,{children:jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:o,rm:orderlyUtils.Decimal.ROUND_DOWN,padding:false,children:i})}),r&&s&&jsxRuntime.jsx(C,{children:jsxRuntime.jsx("div",{})})]})};var Tt=({order:e})=>{let{quote_dp:t}=X(),{tp_trigger_price:o,sl_trigger_price:r}=orderlyHooks.findTPSLFromOrder(e),{t:s}=orderlyI18n.useTranslation();return jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,direction:"column",justify:"between",itemAlign:"start",className:"oui-text-2xs",children:[o&&jsxRuntime.jsx(C,{children:jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36",children:s("common.market")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:t,rm:orderlyUtils.Decimal.ROUND_DOWN,padding:false,children:o})]})}),r&&jsxRuntime.jsx(C,{children:jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"start",itemAlign:"start",children:[jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36",children:s("common.market")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{dp:t,rm:orderlyUtils.Decimal.ROUND_DOWN,padding:false,children:r})]})})]})};var xt=({order:e})=>{let{tp_trigger_price:t,sl_trigger_price:o}=orderlyHooks.findTPSLFromOrder(e),{t:r}=orderlyI18n.useTranslation();return jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",justify:"between",itemAlign:"start",className:"oui-text-2xs",children:[t&&jsxRuntime.jsx(C,{children:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-trade-profit",children:r("tpsl.tp")})}),o&&jsxRuntime.jsx(C,{children:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-trade-loss",children:r("tpsl.sl")})})]})};var He=e=>{let{t}=orderlyI18n.useTranslation(),{isMobile:o}=orderlyUi.useScreen(),{onCancelOrder:r}=e;return react.useMemo(()=>{let i=[{title:t("tpsl.tpslDetail.qty"),dataIndex:"quantity",width:70,className:"oui-py-2",render:(a,l)=>jsxRuntime.jsx(yt,{order:l})},{title:t("tpsl.tpslDetail.type"),dataIndex:"type",width:35,className:"oui-pl-1 oui-py-2",render:(a,l)=>jsxRuntime.jsx(xt,{order:l})},{title:t("tpsl.tpslDetail.trigger"),dataIndex:"trigger",width:70,className:"oui-pl-1 oui-py-2",render:(a,l)=>jsxRuntime.jsx(Tt,{order:l})},{title:t("tpsl.tpslDetail.price"),dataIndex:"price",width:70,className:"oui-py-2",render:(a,l)=>jsxRuntime.jsx(ft,{order:l})},{title:jsxRuntime.jsx(orderlyUi.Tooltip,{className:"oui-max-w-[280px] oui-bg-base-8 oui-p-3 oui-text-2xs oui-text-base-contrast",content:t("tpsl.tpslDetail.estPnl.tooltip"),children:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-underline oui-decoration-dashed oui-underline-offset-2",children:t("tpsl.tpslDetail.estPnl")})}),dataIndex:"estpnl",width:70,className:"!oui-pr-0 oui-py-2",render:(a,l)=>jsxRuntime.jsx(gt,{order:l})}],n=[{title:t("tpsl.tpslDetail.qty"),dataIndex:"quantity",width:70,className:orderlyUi.cn(" oui-py-2 !oui-pl-5"),render:(a,l)=>jsxRuntime.jsx(yt,{order:l})},{title:t("tpsl.tpslDetail.type"),dataIndex:"type",width:35,className:"oui-pl-1 oui-py-2",render:(a,l)=>jsxRuntime.jsx(xt,{order:l})},{title:t("tpsl.tpslDetail.trigger"),dataIndex:"trigger",width:70,className:"oui-pl-1 oui-py-2",render:(a,l)=>jsxRuntime.jsx(Tt,{order:l})},{title:t("tpsl.tpslDetail.price"),dataIndex:"price",width:70,className:"oui-pl-1 oui-py-2",render:(a,l)=>jsxRuntime.jsx(ft,{order:l})},{title:jsxRuntime.jsx(orderlyUi.Tooltip,{className:"oui-max-w-[280px] oui-bg-base-8 oui-p-3 oui-text-2xs oui-text-base-contrast",content:t("tpsl.tpslDetail.estPnl.tooltip"),children:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-underline oui-decoration-dashed oui-underline-offset-2",children:t("tpsl.tpslDetail.estPnl")})}),dataIndex:"estpnl",width:70,className:"oui-pl-1 oui-py-2",render:(a,l)=>jsxRuntime.jsx(gt,{order:l})},{title:"",dataIndex:"delete",width:50,className:orderlyUi.cn("oui-py-2 !oui-pr-5"),render:(a,l)=>jsxRuntime.jsx(Xs,{order:l,onCancelOrder:r})}];return o?i:n},[t,o])};var Zs=e=>{let{size:t=18}=e;return jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 18 18",fill:"currentColor",...e,children:jsxRuntime.jsx("path",{d:"M5.48081 15.375C5.10681 15.375 4.78731 15.2426 4.52231 14.9777C4.25744 14.7127 4.125 14.3932 4.125 14.0192V4.50004H3.375V3.37505H6.75V2.71167H11.25V3.37505H14.625V4.50004H13.875V14.0192C13.875 14.3981 13.7438 14.7188 13.4813 14.9813C13.2188 15.2438 12.8981 15.375 12.5192 15.375H5.48081ZM12.75 4.50004H5.25V14.0192C5.25 14.0866 5.27162 14.1419 5.31487 14.1852C5.35812 14.2284 5.41344 14.25 5.48081 14.25H12.5192C12.5769 14.25 12.6298 14.226 12.6778 14.1779C12.7259 14.1299 12.75 14.077 12.75 14.0192V4.50004ZM7.053 12.75H8.17781V6.00004H7.053V12.75ZM9.82219 12.75H10.947V6.00004H9.82219V12.75Z"})})},Xs=e=>{let[t,o]=react.useState(false);return jsxRuntime.jsx(orderlyUi.ThrottledButton,{size:"sm",loading:t,variant:"text",color:"gray",onClick:r=>{r.stopPropagation(),o(true),e.onCancelOrder?.(e.order).then(()=>{},s=>{orderlyUi.toast.error(s.message);}).finally(()=>{o(false);});},children:jsxRuntime.jsx(Zs,{className:"oui-text-base-contrast-54 hover:oui-text-base-contrast oui-cursor-pointer"})})};var St=e=>{let{orders:t}=e,o=He({onCancelOrder:e.onCancelOrder});return jsxRuntime.jsx(orderlyUiConnector.AuthGuardDataTable,{columns:o,dataSource:t,className:"oui-bg-transparent oui-text-2xs",bordered:true,classNames:{root:orderlyUi.cn(e.className),header:"!oui-bg-base-8",scroll:orderlyUi.cn(!t||t.length===0?"!oui-min-h-[170px]":"!oui-min-h-[100px]")},onRow:r=>({className:orderlyUi.cn("oui-h-[53px] oui-cursor-svg-edit !oui-border-none !oui-p-0"),onClick:()=>{e.editTPSLOrder(r);}})})};var Ot=e=>{let{t}=orderlyI18n.useTranslation(),{orders:o}=e,r=He({onCancelOrder:()=>Promise.resolve()}),s=react.useMemo(()=>o.reduce((i,n)=>(i[n.algo_order_id]=true,i),{}),[o]);return jsxRuntime.jsx(orderlyUiConnector.AuthGuardDataTable,{columns:r,dataSource:o,expanded:s,bordered:true,getRowCanExpand:()=>true,expandRowRender:i=>jsxRuntime.jsxs(orderlyUi.Flex,{gap:2,justify:"end",children:[jsxRuntime.jsx(orderlyUi.Button,{variant:"outlined",size:"sm",color:"gray",className:"oui-h-6 oui-text-2xs oui-text-base-contrast-54",onClick:()=>e.editTPSLOrder(i.original),children:t("common.edit")}),jsxRuntime.jsx(dn,{order:i.original,onCancelOrder:e.canCancelOrder})]}),className:"oui-bg-transparent oui-px-2 oui-text-2xs",classNames:{scroll:orderlyUi.cn(!o||o.length===0?"!oui-min-h-[170px]":"!oui-min-h-[100px]")},onRow:()=>({className:orderlyUi.cn("oui-h-[53px] oui-cursor-svg-edit !oui-border-none !oui-p-0")}),generatedRowKey:i=>i.algo_order_id})},dn=e=>{let[t,o]=react.useState(false),{t:r}=orderlyI18n.useTranslation();return jsxRuntime.jsx(orderlyUi.ThrottledButton,{className:"oui-h-6 oui-text-2xs oui-text-base-contrast-54",size:"sm",loading:t,variant:"outlined",color:"gray",onClick:s=>{s.stopPropagation(),o(true),e.onCancelOrder?.(e.order).then(()=>{},i=>{orderlyUi.toast.error(i.message);}).finally(()=>{o(false);});},children:r("common.delete")})};var Kr=e=>{let{isMobile:t}=orderlyUi.useScreen(),{position:o,fullPositionOrders:r,partialPositionOrders:s,onCancelOrder:i,onCancelAllTPSLOrders:n,editTPSLOrder:a,addTPSLOrder:l,symbolInfo:m}=e;return jsxRuntime.jsx(orderlyUi.Box,{children:jsxRuntime.jsxs(orderlyUi.ScrollArea,{className:orderlyUi.cn(t&&"oui-h-[calc(100vh-100px)]"),children:[jsxRuntime.jsx(H,{order:{symbol:o.symbol,order_quantity:o.position_qty.toString(),order_price:o.average_open_price.toString()},symbolLeverage:o.leverage,baseDP:m("base_dp"),quoteDP:m("quote_dp"),classNames:{root:orderlyUi.cn("oui-mb-6 oui-gap-3 oui-px-5"),container:"oui-gap-x-[30px]"}}),jsxRuntime.jsx(yn,{position:o,orders:r,onCancelOrder:i,onCancelAllTPSLOrders:n,editTPSLOrder:a,addTPSLOrder:l}),jsxRuntime.jsx(Pn,{position:o,orders:s,onCancelOrder:i,onCancelAllTPSLOrders:n,editTPSLOrder:a,addTPSLOrder:l})]})})},yn=e=>{let[t,o]=react.useState(true),{orders:r}=e,{isMobile:s}=orderlyUi.useScreen();return jsxRuntime.jsxs(orderlyUi.Box,{className:"oui-mt-6",children:[jsxRuntime.jsxs(orderlyUi.Box,{className:orderlyUi.cn("oui-flex oui-items-center oui-justify-between oui-px-5"),children:[jsxRuntime.jsx(Gr,{positionType:orderlyTypes.PositionType.FULL,open:t,onOpenChange:o}),r&&r.length===0&&jsxRuntime.jsx(orderlyUi.Flex,{gap:2,children:jsxRuntime.jsx($r,{positionType:orderlyTypes.PositionType.FULL,position:e.position,addTPSLOrder:e.addTPSLOrder})})]}),jsxRuntime.jsx(orderlyUi.Box,{className:orderlyUi.cn("oui-overflow-hidden oui-transition-[height] oui-duration-150",t?"oui-h-auto":"oui-h-0 oui-pb-4"),children:s?jsxRuntime.jsx(Ot,{orders:r,editTPSLOrder:i=>e.editTPSLOrder(i,orderlyTypes.PositionType.FULL),canCancelOrder:e.onCancelOrder}):jsxRuntime.jsx(St,{orders:r,editTPSLOrder:i=>{e.editTPSLOrder(i,orderlyTypes.PositionType.FULL);},onCancelOrder:e.onCancelOrder})})]})},Pn=e=>{let[t,o]=react.useState(true),{orders:r}=e,{isMobile:s}=orderlyUi.useScreen();return jsxRuntime.jsxs(orderlyUi.Box,{className:"oui-pt-6",children:[jsxRuntime.jsxs(orderlyUi.Box,{className:orderlyUi.cn("oui-flex oui-items-center oui-justify-between","oui-px-5",s?"oui-flex-col oui-items-start oui-justify-start oui-gap-[11px]":"oui-flex-row oui-items-center oui-justify-between"),children:[jsxRuntime.jsx(Gr,{positionType:orderlyTypes.PositionType.PARTIAL,open:t,onOpenChange:o}),jsxRuntime.jsxs(orderlyUi.Flex,{gap:2,children:[jsxRuntime.jsx($r,{positionType:orderlyTypes.PositionType.PARTIAL,position:e.position,addTPSLOrder:e.addTPSLOrder}),r&&r.length>0&&jsxRuntime.jsx(_n,{canCancelAll:r&&r.length>0,onCancelAllTPSLOrders:e.onCancelAllTPSLOrders})]})]}),jsxRuntime.jsx(orderlyUi.Box,{className:orderlyUi.cn("oui-overflow-hidden oui-transition-[height] oui-duration-150",t?"oui-h-auto":"oui-h-0 oui-pb-4"),children:s?jsxRuntime.jsx(Ot,{orders:r,editTPSLOrder:i=>e.editTPSLOrder(i,orderlyTypes.PositionType.PARTIAL),canCancelOrder:e.onCancelOrder}):jsxRuntime.jsx(St,{className:"oui-h-[300px]",orders:r,editTPSLOrder:i=>{e.editTPSLOrder(i,orderlyTypes.PositionType.PARTIAL);},onCancelOrder:e.onCancelOrder})})]})},Gr=e=>{let{t}=orderlyI18n.useTranslation();return jsxRuntime.jsxs(orderlyUi.Flex,{gap:1,itemAlign:"center",justify:"start",className:"oui-text-2xs",children:[jsxRuntime.jsxs(orderlyUi.Flex,{itemAlign:"center",justify:"start",gap:1,className:"oui-cursor-pointer",onClick:()=>e.onOpenChange(!e.open),children:[jsxRuntime.jsx(orderlyUi.ChevronDownIcon,{size:12,color:"white",className:orderlyUi.cn("oui-cursor-pointer oui-transition-transform",e.open&&"oui-rotate-180")}),e.positionType===orderlyTypes.PositionType.FULL?jsxRuntime.jsx(orderlyUi.Text,{children:t("tpsl.positionType.full")}):jsxRuntime.jsx(orderlyUi.Text,{children:t("tpsl.positionType.partial")})]}),jsxRuntime.jsx(orderlyUi.Tooltip,{className:"oui-w-[280px] oui-p-3",content:e.positionType===orderlyTypes.PositionType.FULL?t("tpsl.positionType.full.tips"):t("tpsl.positionType.partial.tips"),children:jsxRuntime.jsx(orderlyUi.ExclamationFillIcon,{className:"oui-cursor-pointer oui-text-base-contrast-54",size:12})})]})},$r=e=>{let{t}=orderlyI18n.useTranslation();return jsxRuntime.jsx(orderlyUi.ThrottledButton,{variant:"outlined",size:"sm",color:"gray",className:"oui-h-6 oui-w-[94px] oui-text-2xs",onClick:()=>{e.addTPSLOrder(e.positionType);},children:t("tpsl.add")})},_n=e=>{let[t,o]=react.useState(false),{t:r}=orderlyI18n.useTranslation();return jsxRuntime.jsx(orderlyUi.ThrottledButton,{loading:t,variant:"outlined",disabled:!e.canCancelAll,size:"sm",color:"gray",className:"oui-h-6 oui-w-[94px] oui-text-2xs disabled:oui-border-base-contrast-16 disabled:oui-bg-transparent disabled:oui-text-base-contrast-20",onClick:()=>{o(true),e.onCancelAllTPSLOrders().then(()=>{},s=>{orderlyUi.toast.error(s.message);}).finally(()=>{o(false);});},children:r("tpsl.cancelAll")})};var Hr=e=>{let t=Nr(e);return jsxRuntime.jsx(Cr,{symbol:e.position.symbol,position:e.position,children:jsxRuntime.jsx(Kr,{...t})})},bn="TPSLDetailDialogId ",Sn="TPSLDetailSheetId";orderlyUi.registerSimpleDialog(bn,Hr,{classNames:{content:"oui-w-[420px] lg:oui-pt-4 lg:oui-pb-2 !oui-px-0",body:"lg:oui-py-0"}});orderlyUi.registerSimpleSheet(Sn,Hr,{classNames:{content:"!oui-p-0"}});var ht=e=>{let {type:t,triggerPrice:o,symbol:r}=e,s=orderlyHooks.useSymbolsInfo(),[{rows:i},n]=orderlyHooks.usePositionStream(r),a=i?.[0];react.useRef(orderlyTypes.AlgoOrderRootType.TP_SL);let [m]=orderlyHooks.useLocalStorage("orderly_order_confirm",true),{t:f}=orderlyI18n.useTranslation(),[u,{submit:d,deleteOrder:g,setValue:p,setValues:y,validate:c,errors:P,isCreateMutating:N,isUpdateMutating:O}]=orderlyHooks.useTPSLOrder({symbol:r,position_qty:a?.position_qty,average_open_price:a?.average_open_price},{defaultOrder:void 0,positionType:orderlyTypes.PositionType.PARTIAL,tpslEnable:{tp_enable:t==="tp",sl_enable:t==="sl"},isEditing:false}),w=k=>{p("quantity",k);},oe=(k,h)=>{p(k,h);},be=(k,h)=>{p(k,h);},ie=react.useMemo(()=>Math.abs(Number(a.position_qty)),[a.position_qty]);react.useEffect(()=>{ie&&(p("quantity",ie),p(t==="tp"?"tp_trigger_price":"sl_trigger_price",o??""));},[t,o,ie]);let tt=async()=>{try{if(await c())return m?orderlyUi.modal.confirm({title:f("tpsl.confirmOrder"),onOk:async()=>{try{let h=await d({accountId:a.account_id});return h.success?h:(h.message&&orderlyUi.toast.error(h.message),!1)}catch(h){return h?.message&&orderlyUi.toast.error(h.message),!1}},classNames:{body:"!oui-pb-0"},content:jsxRuntime.jsx(Ne,{isPositionTPSL:!1,isEditing:!1,symbol:r,qty:Number(u.quantity),maxQty:ie,tpPrice:Number(u.tp_trigger_price),slPrice:Number(u.sl_trigger_price),side:u.side,orderInfo:u,quoteDP:s[r]("quote_dp"),baseDP:s[r]("base_dp")})}).then(()=>!0,()=>Promise.reject(!1)):d({accountId:a.account_id}).then(()=>!0).catch(h=>{throw h?.message&&orderlyUi.toast.error(h.message),!1})}catch(k){return Promise.reject(k)}};return {symbolInfo:s[r],maxQty:ie,setQuantity:orderlyHooks.useMemoizedFn(w),orderQuantity:u.quantity,isPosition:false,TPSL_OrderEntity:u,setOrderValue:p,setPnL:be,setOrderPrice:oe,onSubmit:tt,errors:P,status:{isCreateMutating:N,isUpdateMutating:O},position:a,setValues:y,type:t,triggerPrice:o}};var Ct=e=>{let{type:t,triggerPrice:o,errors:r,TPSL_OrderEntity:s}=e,{t:i}=orderlyI18n.useTranslation(),{getErrorMsg:n}=orderlyReactApp.useOrderEntryFormErrorMsg(r),a=jsxRuntime.jsxs(orderlyUi.Flex,{width:"100%",itemAlign:"center",gap:3,mt:4,children:[jsxRuntime.jsx(orderlyUi.Button,{color:"gray",onClick:()=>{e.onComplete?.(),e.close?.();},fullWidth:true,className:"oui-text-sm",size:"md",children:i("common.cancel")},"secondary"),jsxRuntime.jsx(orderlyUi.Button,{onClick:()=>{e.onSubmit().then(()=>{e.onComplete?.(),e.close?.();});},fullWidth:true,className:"oui-text-sm",size:"md",children:i("common.confirm")},"primary")]}),l=()=>{let f=n("tp_trigger_price"),u=n("sl_trigger_price"),d="";return f&&t==="tp"&&(d=f),u&&t==="sl"&&(d=u),d?jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"start",gap:2,className:"oui-mt-2 oui-w-full",children:[jsxRuntime.jsx("div",{className:"oui-relative oui-top-[7px] oui-size-1 oui-rounded-full oui-bg-danger"}),jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-danger",children:d})]}):null},m=()=>{let{tp_pnl:f,sl_pnl:u}=s;return t==="sl"?jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:i("tpsl.totalEstSlPnl")}),u?jsxRuntime.jsx(orderlyUi.Text.numeral,{suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-ml-1 oui-text-base-contrast-36",children:"USDC"}),coloring:true,visible:true,size:"2xs",dp:2,children:Number(u)}):jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:"-- USDC"})]}):jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"2xs",children:i("tpsl.totalEstTpPnl")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast-36 oui-ml-1",children:"USDC"}),rule:"price",coloring:true,visible:true,size:"2xs",dp:2,children:f?Number(f):"--"})]})};return jsxRuntime.jsxs(orderlyUi.Box,{className:"oui-w-full oui-px-0.5",children:[jsxRuntime.jsx(Ue,{maxQty:e.maxQty,quantity:Number(e.orderQuantity??e.maxQty),baseTick:e.symbolInfo("base_tick"),base_dp:e.symbolInfo("base_dp"),base:e.symbolInfo("base"),isEditing:false,errorMsg:n("quantity"),onQuantityChange:e.setQuantity}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",itemAlign:"start",className:orderlyUi.cn("oui-mt-4 oui-w-full oui-gap-1 oui-text-xs oui-text-base-contrast-36"),children:[jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"xs",children:i("tpsl.advanced.triggerPrice")}),jsxRuntime.jsx(orderlyUi.Text.numeral,{className:"oui-text-base-contrast",suffix:jsxRuntime.jsx(orderlyUi.Text,{className:"oui-ml-1 oui-text-xs oui-text-base-contrast-36",children:"USDC"}),rule:"price",size:"xs",dp:e.symbolInfo("quote_dp"),children:o?Number(o):"--"})]}),jsxRuntime.jsxs(orderlyUi.Flex,{justify:"between",className:"oui-w-full",children:[jsxRuntime.jsx(orderlyUi.Text,{size:"xs",children:i("tpsl.advanced.orderPrice")}),jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-base-contrast",size:"xs",children:i("tpsl.advanced.market")})]}),m()]}),l(),jsxRuntime.jsx(orderlyUi.Divider,{className:"oui-my-3 oui-w-full"}),jsxRuntime.jsx(orderlyUi.Flex,{itemAlign:"center",onClick:()=>{e.close?.(),e.showAdvancedTPSLDialog?.({qty:Number(s.quantity)});},className:"oui-pb-4",children:jsxRuntime.jsx(orderlyUi.Text,{color:"primary",className:"oui-cursor-pointer oui-text-sm",children:i("tpsl.advancedSetting")})}),a]})};var vt=e=>{let{close:t,onComplete:o,showAdvancedTPSLDialog:r}=e,s=ht(e);return jsxRuntime.jsx(Ct,{...s,close:t,onComplete:o,showAdvancedTPSLDialog:r})},Zr="TPSLSimpleSheetId",Xr="TPSLSimpleDialogId";orderlyUi.registerSimpleSheet(Zr,vt,{classNames:{}});orderlyUi.registerSimpleDialog(Xr,vt,{classNames:{content:"oui-w-[420px]"}});function Yn(e){let t=e.child_orders[0],o=t.algo_type===orderlyTypes.AlgoOrderRootType.TP_SL?orderlyTypes.PositionType.PARTIAL:orderlyTypes.PositionType.FULL,r=t.child_orders.find(n=>n.algo_type===orderlyTypes.AlgoOrderType.TAKE_PROFIT&&n.trigger_price),s=t.child_orders.find(n=>n.algo_type===orderlyTypes.AlgoOrderType.STOP_LOSS&&n.trigger_price),i={};return r&&(i.tp_trigger_price=r.trigger_price?.toString(),i.tp_order_type=typeof r.type=="string"?r.type.replace("_ORDER",""):void 0,i.tp_order_type===orderlyTypes.OrderType.LIMIT&&(i.tp_order_price=r.price?.toString())),s&&(i.sl_trigger_price=s.trigger_price?.toString(),i.sl_order_type=typeof s.type=="string"?s.type.replace("_ORDER",""):void 0,i.sl_order_type===orderlyTypes.OrderType.LIMIT&&(i.sl_order_price=s.price?.toString())),{baseInfo:{symbol:e.symbol,order_type:e.type,side:e.side,order_price:e.price,order_quantity:e.quantity,position_type:o,tp_enable:!!r?.trigger_price,sl_enable:!!s?.trigger_price},tpslPriceInfo:i,tpInfo:{orderId:r?.algo_order_id},slInfo:{orderId:s?.algo_order_id}}}function Xe(e,t){if(t==null)return true;if(isNaN(Number(t)))return false;let o=new orderlyUtils.Decimal(Number(e));return !new orderlyUtils.Decimal(Number(t)).eq(o)}var to=e=>{if(!e.order)throw new orderlyTypes.SDKError("order is required for editBracketOrder");let{baseInfo:t,tpslPriceInfo:o,tpInfo:r,slInfo:s}=Yn(e.order),[i,{isMutating:n}]=orderlyHooks.useMutation("/v1/algo/order","PUT"),{formattedOrder:a,setValue:l,setValues:m,metaState:f,symbolInfo:u,helper:d}=orderlyHooks.useOrderEntry(e.order.symbol,{initialOrder:t}),g=e.order.symbol,p=react.useMemo(()=>{let c=false,{tp_order_price:P,sl_order_price:N,tp_trigger_price:O,sl_trigger_price:w}=a;return o.tp_trigger_price&&(c=c||Xe(o.tp_trigger_price,O??0)),o.tp_order_price&&(c=c||Xe(o.tp_order_price,P??0)),o.sl_trigger_price&&(c=c||Xe(o.sl_trigger_price,w??0)),o.sl_order_price&&(c=c||Xe(o.sl_order_price,N??0)),c},[o,a.tp_order_price,a.sl_order_price,a.tp_trigger_price,a.sl_trigger_price]);return react.useEffect(()=>{m({...o});},[e.order,m]),{symbol:g,symbolInfo:u,formattedOrder:a,setValue:l,setValues:m,metaState:f,onSubmit:async()=>d.validate().then(()=>{let c={order_id:r.orderId,algo_type:orderlyTypes.AlgoOrderType.TAKE_PROFIT,trigger_price:a.tp_trigger_price,reduce_only:true};a.tp_order_type===orderlyTypes.OrderType.LIMIT&&(c.price=a.tp_order_price);let P={order_id:s.orderId,algo_type:orderlyTypes.AlgoOrderType.STOP_LOSS,trigger_price:a.sl_trigger_price,reduce_only:true};a.sl_order_type===orderlyTypes.OrderType.LIMIT&&(P.price=a.sl_order_price);let N=[];return r.orderId&&N.push(c),s.orderId&&N.push(P),i({order_id:e.order.algo_order_id,child_orders:[{order_id:e.order.child_orders[0].algo_order_id,child_orders:N}]})}),isMutating:n,isPriceChanged:p}};var so=e=>{let{t}=orderlyI18n.useTranslation(),{errors:o,validated:r}=e.metaState,{isMobile:s}=orderlyUi.useScreen(),{formattedOrder:i,setValue:n,symbol:a,symbolInfo:l,setValues:m}=e,[f,u]=react.useState({enable:true,order_type:i.tp_order_type??orderlyTypes.OrderType.MARKET,order_price:i.tp_order_price??"",trigger_price:i.tp_trigger_price??"",PnL:i.tp_pnl??"",Offset:i.tp_offset??"","Offset%":i.tp_offset_percentage??"",ROI:i.tp_ROI??""}),[d,g]=react.useState({enable:true,order_type:i.sl_order_type??orderlyTypes.OrderType.MARKET,order_price:i.sl_order_price??"",trigger_price:i.sl_trigger_price??"",PnL:i.sl_pnl??"",Offset:i.sl_offset??"","Offset%":i.sl_offset_percentage??"",ROI:i.sl_ROI??""});return react.useEffect(()=>{u(p=>({...p,enable:i.tp_enable??true,order_type:i.tp_order_type??orderlyTypes.OrderType.MARKET,order_price:i.tp_order_price??"",trigger_price:i.tp_trigger_price??"",PnL:i.tp_pnl??"",Offset:i.tp_offset??"","Offset%":i.tp_offset_percentage??"",ROI:i.tp_ROI??""}));},[i]),react.useEffect(()=>{g(p=>({...p,enable:i.sl_enable??true,order_type:i.sl_order_type??orderlyTypes.OrderType.MARKET,order_price:i.sl_order_price??"",trigger_price:i.sl_trigger_price??"",PnL:i.sl_pnl??"",Offset:i.sl_offset??"","Offset%":i.sl_offset_percentage??"",ROI:i.sl_ROI??""}));},[i]),jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs(orderlyUi.ScrollArea,{className:orderlyUi.cn("oui-flex-1",s&&"oui-h-[calc(100vh-200px)]"),children:[jsxRuntime.jsx("div",{className:"",children:jsxRuntime.jsx(H,{order:{symbol:a,order_quantity:i.order_quantity,order_price:i.order_price},baseDP:l.base_dp,quoteDP:l.quote_dp})}),jsxRuntime.jsx(orderlyUi.Divider,{className:"oui-my-3"}),jsxRuntime.jsxs("div",{className:"",children:[jsxRuntime.jsxs("div",{className:"oui-py-3",children:[jsxRuntime.jsx(Y,{value:i.position_type??orderlyTypes.PositionType.PARTIAL,disableSelector:true,onChange:(p,y)=>{if(y===orderlyTypes.PositionType.FULL){m({position_type:orderlyTypes.PositionType.FULL,tp_order_type:orderlyTypes.OrderType.MARKET,tp_order_price:void 0,sl_order_type:orderlyTypes.OrderType.MARKET,sl_order_price:void 0});return}n("position_type",y);}}),i.position_type===orderlyTypes.PositionType.FULL&&jsxRuntime.jsxs(orderlyUi.Flex,{justify:"start",itemAlign:"start",gap:2,className:"oui-mt-3 oui-w-full",children:[jsxRuntime.jsx("div",{className:"oui-relative oui-top-[7px] oui-size-1 oui-rounded-full oui-bg-[#D25f00]"}),jsxRuntime.jsx(orderlyUi.Text,{className:"oui-text-2xs oui-text-[#D25f00]",children:t("tpsl.positionType.full.tips.market")})]})]}),jsxRuntime.jsxs(orderlyUi.Flex,{direction:"column",gap:6,children:[i.tp_enable&&jsxRuntime.jsx($,{disableEnableCheckbox:true,disableOrderTypeSelector:true,rootOrderPrice:i.order_price,symbol:l.symbol,type:"tp",side:i.side,values:f,errors:r?o:null,quote_dp:l.quote_dp,hideOrderPrice:i.position_type===orderlyTypes.PositionType.FULL,onChange:(p,y)=>{n(p,y);},positionType:i.position_type??orderlyTypes.PositionType.PARTIAL}),i.sl_enable&&i.tp_enable&&jsxRuntime.jsx(orderlyUi.Divider,{className:"oui-w-full"}),i.sl_enable&&jsxRuntime.jsx($,{disableEnableCheckbox:true,disableOrderTypeSelector:true,rootOrderPrice:i.order_price,symbol:l.symbol,type:"sl",side:i.side,values:d,hideOrderPrice:i.position_type===orderlyTypes.PositionType.FULL,errors:r?o:null,quote_dp:l.quote_dp,positionType:i.position_type??orderlyTypes.PositionType.PARTIAL,onChange:(p,y)=>{n(p,y);}})]}),jsxRuntime.jsx(pe,{tp_pnl:i.tp_pnl,sl_pnl:i.sl_pnl,className:"oui-mt-6"})]})]}),jsxRuntime.jsx(orderlyUi.Flex,{itemAlign:"center",gap:3,mt:5,width:"100%",justify:"center",children:jsxRuntime.jsx(orderlyUi.ThrottledButton,{className:"oui-w-[184px]","data-testid":"tpsl-confirm",disabled:!e.isPriceChanged,loading:e.isMutating,onClick:()=>{e.onSubmit().then(()=>{e.onClose?.();}).catch(p=>{});},children:t("common.confirm")})})]})};var no=e=>{let t=to({order:e.order});return jsxRuntime.jsx(so,{...t,onClose:e.close})},sl="EditBracketOrderSheetId",nl="EditBracketOrderDialogId";orderlyUi.registerSimpleSheet(sl,no);orderlyUi.registerSimpleDialog(nl,no,{classNames:{content:"oui-w-[420px]"}});
|
|
704
|
+
// src/components/tpslPostionType/tpslPositionType.script.tsx
|
|
705
|
+
var useTPSLPositionTypeScript = (props) => {
|
|
706
|
+
return {
|
|
707
|
+
value: props.value,
|
|
708
|
+
onChange: props.onChange,
|
|
709
|
+
disableSelector: props.disableSelector
|
|
710
|
+
};
|
|
711
|
+
};
|
|
712
|
+
var positionTypeKey = "position_type";
|
|
713
|
+
var TPSLPositionTypeUI = (props) => {
|
|
714
|
+
const { t } = orderlyI18n.useTranslation();
|
|
715
|
+
const options = [
|
|
716
|
+
{
|
|
717
|
+
label: t("tpsl.partialPosition"),
|
|
718
|
+
value: orderlyTypes.PositionType.PARTIAL
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
label: t("tpsl.fullPosition"),
|
|
722
|
+
value: orderlyTypes.PositionType.FULL
|
|
723
|
+
}
|
|
724
|
+
];
|
|
725
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 1, itemAlign: "center", justify: "start", children: [
|
|
726
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
727
|
+
orderlyUi.Tooltip,
|
|
728
|
+
{
|
|
729
|
+
className: "oui-w-[280px] oui-p-3",
|
|
730
|
+
content: props.value === orderlyTypes.PositionType.FULL ? t("tpsl.positionType.full.tips") : t("tpsl.positionType.partial.tips"),
|
|
731
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
732
|
+
orderlyUi.ExclamationFillIcon,
|
|
733
|
+
{
|
|
734
|
+
className: "oui-cursor-pointer oui-text-base-contrast-54",
|
|
735
|
+
size: 12
|
|
736
|
+
}
|
|
737
|
+
)
|
|
738
|
+
}
|
|
739
|
+
),
|
|
740
|
+
props.disableSelector ? props.value === orderlyTypes.PositionType.FULL ? /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-2xs oui-font-normal oui-text-base-contrast-54", children: t("tpsl.positionType.full") }) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-2xs oui-font-normal oui-text-base-contrast-54", children: t("tpsl.positionType.partial") }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
741
|
+
orderlyUi.Select.options,
|
|
742
|
+
{
|
|
743
|
+
value: props.value,
|
|
744
|
+
options,
|
|
745
|
+
onValueChange: (event) => {
|
|
746
|
+
props.onChange(positionTypeKey, event);
|
|
747
|
+
},
|
|
748
|
+
size: "xs",
|
|
749
|
+
classNames: {
|
|
750
|
+
trigger: " oui-bg-transparent oui-border-0 oui-w-auto oui-px-0 oui-font-normal"
|
|
751
|
+
},
|
|
752
|
+
contentProps: {
|
|
753
|
+
className: " oui-bg-base-8 oui-border-0"
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
)
|
|
757
|
+
] });
|
|
758
|
+
};
|
|
759
|
+
var TPSLPositionTypeWidget = (props) => {
|
|
760
|
+
const state = useTPSLPositionTypeScript(props);
|
|
761
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TPSLPositionTypeUI, { ...state });
|
|
762
|
+
};
|
|
763
|
+
var TPSLQuantity = react.memo((props) => {
|
|
764
|
+
const { maxQty, base_dp, baseTick, quantity } = props;
|
|
765
|
+
const inputRef = react.useRef(null);
|
|
766
|
+
const { t } = orderlyI18n.useTranslation();
|
|
767
|
+
const [sliderValue, setSliderValue] = react.useState(0);
|
|
768
|
+
const formatQuantity = (value) => {
|
|
769
|
+
let _qty = value;
|
|
770
|
+
if (Number(value) > maxQty) {
|
|
771
|
+
_qty = maxQty.toString();
|
|
772
|
+
}
|
|
773
|
+
if (baseTick > 0) {
|
|
774
|
+
props.onQuantityChange?.(orderlyHooks.utils.formatNumber(_qty, baseTick) ?? value);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
const onSliderValueChange = (value) => {
|
|
778
|
+
setSliderValue(value);
|
|
779
|
+
const qty = new orderlyUtils.Decimal(value).div(100).mul(maxQty).toFixed(base_dp, orderlyUtils.Decimal.ROUND_DOWN);
|
|
780
|
+
formatQuantity(qty);
|
|
781
|
+
};
|
|
782
|
+
react.useEffect(() => {
|
|
783
|
+
const qty = Math.min(Number(quantity || 0), maxQty);
|
|
784
|
+
const slider = new orderlyUtils.Decimal(qty).div(maxQty).mul(100).toDecimalPlaces(2, orderlyUtils.Decimal.ROUND_DOWN).toNumber();
|
|
785
|
+
setSliderValue(slider);
|
|
786
|
+
}, [quantity, maxQty]);
|
|
787
|
+
const errorMsg = props.quantity.toString().length > 0 ? props.errorMsg : void 0;
|
|
788
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
789
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Flex, { gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
790
|
+
orderlyUi.Input.tooltip,
|
|
791
|
+
{
|
|
792
|
+
"data-testid": "oui-testid-tpsl-popUp-quantity-input",
|
|
793
|
+
ref: inputRef,
|
|
794
|
+
prefix: t("common.quantity"),
|
|
795
|
+
size: {
|
|
796
|
+
initial: "md",
|
|
797
|
+
lg: "sm"
|
|
798
|
+
},
|
|
799
|
+
align: "right",
|
|
800
|
+
value: props.quantity,
|
|
801
|
+
autoComplete: "off",
|
|
802
|
+
inputMode: "decimal",
|
|
803
|
+
classNames: {
|
|
804
|
+
prefix: "oui-text-base-contrast-54",
|
|
805
|
+
root: orderlyUi.cn(
|
|
806
|
+
"oui-bg-base-5 oui-outline-line-12",
|
|
807
|
+
errorMsg && "oui-outline-danger"
|
|
808
|
+
)
|
|
809
|
+
},
|
|
810
|
+
tooltipProps: {
|
|
811
|
+
content: {
|
|
812
|
+
className: "oui-bg-base-6 oui-text-base-contrast-80"
|
|
813
|
+
},
|
|
814
|
+
arrow: {
|
|
815
|
+
className: "oui-fill-base-6"
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
tooltip: errorMsg,
|
|
819
|
+
color: errorMsg ? "danger" : void 0,
|
|
820
|
+
formatters: [
|
|
821
|
+
orderlyUi.inputFormatter.dpFormatter(props.base_dp),
|
|
822
|
+
orderlyUi.inputFormatter.numberFormatter,
|
|
823
|
+
orderlyUi.inputFormatter.currencyFormatter,
|
|
824
|
+
orderlyUi.inputFormatter.decimalPointFormatter
|
|
825
|
+
],
|
|
826
|
+
onValueChange: (value) => {
|
|
827
|
+
props.onQuantityChange?.(value);
|
|
828
|
+
const qty = Number(value);
|
|
829
|
+
if (qty && qty > props.maxQty) {
|
|
830
|
+
const qty2 = props.maxQty;
|
|
831
|
+
props.onQuantityChange?.(qty2);
|
|
832
|
+
inputRef.current?.blur();
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
onBlur: (e) => formatQuantity(e.target.value),
|
|
836
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "oui-px-3 oui-text-2xs oui-text-base-contrast-54", children: props.base })
|
|
837
|
+
}
|
|
838
|
+
) }) }),
|
|
839
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Flex, { mt: 2, itemAlign: "center", height: "15px", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
840
|
+
orderlyUi.Slider,
|
|
841
|
+
{
|
|
842
|
+
min: 0,
|
|
843
|
+
max: 100,
|
|
844
|
+
markCount: 5,
|
|
845
|
+
showTip: true,
|
|
846
|
+
value: [sliderValue],
|
|
847
|
+
color: "primary",
|
|
848
|
+
onValueChange: (value) => {
|
|
849
|
+
onSliderValueChange(value[0]);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
) }),
|
|
853
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", children: [
|
|
854
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { color: "primary", size: "2xs", suffix: "%", children: sliderValue }),
|
|
855
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { itemAlign: "center", gap: 1, children: [
|
|
856
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
857
|
+
"button",
|
|
858
|
+
{
|
|
859
|
+
className: "oui-leading-none",
|
|
860
|
+
style: { lineHeight: 0 },
|
|
861
|
+
onClick: () => {
|
|
862
|
+
props.onQuantityChange?.(props.maxQty);
|
|
863
|
+
},
|
|
864
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { color: "primary", size: "2xs", children: t("common.max") })
|
|
865
|
+
}
|
|
866
|
+
),
|
|
867
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
868
|
+
orderlyUi.Text.numeral,
|
|
869
|
+
{
|
|
870
|
+
rule: "price",
|
|
871
|
+
size: "2xs",
|
|
872
|
+
intensity: 54,
|
|
873
|
+
tick: props.baseTick,
|
|
874
|
+
children: props.maxQty
|
|
875
|
+
}
|
|
876
|
+
)
|
|
877
|
+
] })
|
|
878
|
+
] })
|
|
879
|
+
] });
|
|
880
|
+
});
|
|
881
|
+
var TPSL = (props) => {
|
|
882
|
+
const {
|
|
883
|
+
TPSL_OrderEntity,
|
|
884
|
+
symbolInfo,
|
|
885
|
+
onCancel,
|
|
886
|
+
onComplete,
|
|
887
|
+
status,
|
|
888
|
+
position,
|
|
889
|
+
setValues,
|
|
890
|
+
isEditing
|
|
891
|
+
} = props;
|
|
892
|
+
const { errors, validated } = props.metaState;
|
|
893
|
+
const { t } = orderlyI18n.useTranslation();
|
|
894
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
895
|
+
const tpErrors = react.useMemo(() => {
|
|
896
|
+
if (!errors)
|
|
897
|
+
return null;
|
|
898
|
+
const { sl_trigger_price, ...rest } = errors;
|
|
899
|
+
return rest;
|
|
900
|
+
}, [errors]);
|
|
901
|
+
const slErrors = react.useMemo(() => {
|
|
902
|
+
if (!errors)
|
|
903
|
+
return null;
|
|
904
|
+
const { tp_trigger_price, ...rest } = errors;
|
|
905
|
+
return rest;
|
|
906
|
+
}, [errors]);
|
|
907
|
+
const { getErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(errors);
|
|
908
|
+
const { getErrorMsg: getSlPriceErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(
|
|
909
|
+
props.slPriceError
|
|
910
|
+
);
|
|
911
|
+
const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
912
|
+
if (!position) {
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
const tpslEnable = TPSL_OrderEntity.tp_trigger_price || TPSL_OrderEntity.sl_trigger_price;
|
|
916
|
+
const renderQtyInput = () => {
|
|
917
|
+
if (TPSL_OrderEntity.position_type === orderlyTypes.PositionType.FULL) {
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Box, { className: "oui-px-0.5", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
921
|
+
TPSLQuantity,
|
|
922
|
+
{
|
|
923
|
+
maxQty: props.maxQty,
|
|
924
|
+
quantity: props.orderQuantity ?? props.maxQty,
|
|
925
|
+
baseTick: symbolInfo("base_tick"),
|
|
926
|
+
base_dp: symbolInfo("base_dp"),
|
|
927
|
+
onQuantityChange: props.setQuantity,
|
|
928
|
+
base: symbolInfo("base"),
|
|
929
|
+
isEditing: props.isEditing,
|
|
930
|
+
errorMsg: validated ? getErrorMsg("quantity") : void 0
|
|
931
|
+
}
|
|
932
|
+
) });
|
|
933
|
+
};
|
|
934
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { id: "orderly-tp_sl-order-edit-content", children: [
|
|
935
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.ScrollArea, { className: orderlyUi.cn(isMobile && "oui-h-[calc(100vh-200px)]"), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-px-2", children: [
|
|
936
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
937
|
+
OrderInfo,
|
|
938
|
+
{
|
|
939
|
+
baseDP: symbolInfo("base_dp"),
|
|
940
|
+
quoteDP: symbolInfo("quote_dp"),
|
|
941
|
+
estLiqPrice: props.estLiqPrice,
|
|
942
|
+
classNames: {
|
|
943
|
+
root: "oui-mb-3",
|
|
944
|
+
container: "oui-gap-x-[30px]"
|
|
945
|
+
},
|
|
946
|
+
order: {
|
|
947
|
+
symbol: position.symbol,
|
|
948
|
+
order_quantity: position.position_qty.toString(),
|
|
949
|
+
order_price: position.average_open_price.toString()
|
|
950
|
+
},
|
|
951
|
+
symbolLeverage: position.leverage
|
|
952
|
+
}
|
|
953
|
+
),
|
|
954
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
955
|
+
orderlyUi.Flex,
|
|
956
|
+
{
|
|
957
|
+
direction: "column",
|
|
958
|
+
justify: "start",
|
|
959
|
+
itemAlign: "start",
|
|
960
|
+
gap: 3,
|
|
961
|
+
className: "oui-mb-3 oui-w-full",
|
|
962
|
+
children: [
|
|
963
|
+
!isEditing && /* @__PURE__ */ jsxRuntime.jsx(
|
|
964
|
+
TPSLPositionTypeWidget,
|
|
965
|
+
{
|
|
966
|
+
disableSelector: true,
|
|
967
|
+
value: TPSL_OrderEntity.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
968
|
+
onChange: (key, value) => {
|
|
969
|
+
props.setOrderValue(key, value);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
),
|
|
973
|
+
TPSL_OrderEntity.position_type === orderlyTypes.PositionType.FULL && /* @__PURE__ */ jsxRuntime.jsx(
|
|
974
|
+
orderlyUi.DotStatus,
|
|
975
|
+
{
|
|
976
|
+
color: "warning",
|
|
977
|
+
size: "xs",
|
|
978
|
+
label: t("tpsl.positionType.full.tips.market")
|
|
979
|
+
}
|
|
980
|
+
)
|
|
981
|
+
]
|
|
982
|
+
}
|
|
983
|
+
),
|
|
984
|
+
renderQtyInput(),
|
|
985
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
986
|
+
orderlyUi.Flex,
|
|
987
|
+
{
|
|
988
|
+
direction: "column",
|
|
989
|
+
itemAlign: "start",
|
|
990
|
+
justify: "start",
|
|
991
|
+
gap: 6,
|
|
992
|
+
className: "oui-mt-3 oui-w-full",
|
|
993
|
+
children: [
|
|
994
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
995
|
+
TPSLInputRowWidget,
|
|
996
|
+
{
|
|
997
|
+
symbol: position.symbol,
|
|
998
|
+
rootOrderPrice: position.average_open_price.toString(),
|
|
999
|
+
type: "tp",
|
|
1000
|
+
side: position.position_qty > 0 ? orderlyTypes.OrderSide.BUY : orderlyTypes.OrderSide.SELL,
|
|
1001
|
+
values: {
|
|
1002
|
+
// enable: TPSL_OrderEntity.tp_enable ?? false,
|
|
1003
|
+
trigger_price: TPSL_OrderEntity.tp_trigger_price?.toString() ?? void 0,
|
|
1004
|
+
PnL: TPSL_OrderEntity.tp_pnl?.toString() ?? void 0,
|
|
1005
|
+
Offset: TPSL_OrderEntity.tp_offset?.toString() ?? void 0,
|
|
1006
|
+
"Offset%": TPSL_OrderEntity.tp_offset_percentage?.toString() ?? void 0,
|
|
1007
|
+
order_price: TPSL_OrderEntity.tp_order_price?.toString() ?? void 0,
|
|
1008
|
+
order_type: TPSL_OrderEntity.tp_order_type ?? orderlyTypes.OrderType.MARKET
|
|
1009
|
+
},
|
|
1010
|
+
hideOrderPrice: TPSL_OrderEntity.position_type === orderlyTypes.PositionType.FULL,
|
|
1011
|
+
errors: validated ? tpErrors : null,
|
|
1012
|
+
disableOrderTypeSelector: isEditing,
|
|
1013
|
+
quote_dp: symbolInfo("quote_dp"),
|
|
1014
|
+
positionType: TPSL_OrderEntity.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
1015
|
+
onChange: (key, value) => {
|
|
1016
|
+
props.setOrderValue(key, value);
|
|
1017
|
+
},
|
|
1018
|
+
symbolLeverage: position.leverage
|
|
1019
|
+
}
|
|
1020
|
+
),
|
|
1021
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1022
|
+
TPSLInputRowWidget,
|
|
1023
|
+
{
|
|
1024
|
+
inputWarnNode: isSlPriceWarning && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1025
|
+
orderlyUi.DotStatus,
|
|
1026
|
+
{
|
|
1027
|
+
color: "warning",
|
|
1028
|
+
label: getSlPriceErrorMsg("sl_trigger_price"),
|
|
1029
|
+
classNames: {
|
|
1030
|
+
root: "oui-mt-1"
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
),
|
|
1034
|
+
symbol: position.symbol,
|
|
1035
|
+
rootOrderPrice: position.average_open_price.toString(),
|
|
1036
|
+
type: "sl",
|
|
1037
|
+
side: position.position_qty > 0 ? orderlyTypes.OrderSide.BUY : orderlyTypes.OrderSide.SELL,
|
|
1038
|
+
values: {
|
|
1039
|
+
// enable: TPSL_OrderEntity.sl_enable ?? false,
|
|
1040
|
+
trigger_price: TPSL_OrderEntity.sl_trigger_price?.toString() ?? void 0,
|
|
1041
|
+
PnL: TPSL_OrderEntity.sl_pnl?.toString() ?? void 0,
|
|
1042
|
+
Offset: TPSL_OrderEntity.sl_offset?.toString() ?? void 0,
|
|
1043
|
+
"Offset%": TPSL_OrderEntity.sl_offset_percentage?.toString() ?? void 0,
|
|
1044
|
+
order_price: TPSL_OrderEntity.sl_order_price?.toString() ?? void 0,
|
|
1045
|
+
order_type: TPSL_OrderEntity.sl_order_type ?? orderlyTypes.OrderType.MARKET
|
|
1046
|
+
},
|
|
1047
|
+
hideOrderPrice: TPSL_OrderEntity.position_type === orderlyTypes.PositionType.FULL,
|
|
1048
|
+
errors: validated ? slErrors : null,
|
|
1049
|
+
quote_dp: symbolInfo("quote_dp"),
|
|
1050
|
+
positionType: TPSL_OrderEntity.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
1051
|
+
disableOrderTypeSelector: isEditing,
|
|
1052
|
+
onChange: (key, value) => {
|
|
1053
|
+
props.setOrderValue(key, value);
|
|
1054
|
+
},
|
|
1055
|
+
symbolLeverage: position.leverage
|
|
1056
|
+
}
|
|
1057
|
+
)
|
|
1058
|
+
]
|
|
1059
|
+
}
|
|
1060
|
+
),
|
|
1061
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1062
|
+
PnlInfo,
|
|
1063
|
+
{
|
|
1064
|
+
tp_pnl: TPSL_OrderEntity.tp_pnl,
|
|
1065
|
+
sl_pnl: TPSL_OrderEntity.sl_pnl,
|
|
1066
|
+
className: "oui-my-3"
|
|
1067
|
+
}
|
|
1068
|
+
)
|
|
1069
|
+
] }) }),
|
|
1070
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Grid, { px: 2, cols: 2, gap: 3, mt: 4, children: [
|
|
1071
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1072
|
+
orderlyUi.Button,
|
|
1073
|
+
{
|
|
1074
|
+
size: "md",
|
|
1075
|
+
color: "secondary",
|
|
1076
|
+
"data-testid": "tpsl-cancel",
|
|
1077
|
+
onClick: () => {
|
|
1078
|
+
props.close?.();
|
|
1079
|
+
onCancel?.();
|
|
1080
|
+
},
|
|
1081
|
+
children: t("common.cancel")
|
|
1082
|
+
}
|
|
1083
|
+
),
|
|
1084
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1085
|
+
orderlyUi.ThrottledButton,
|
|
1086
|
+
{
|
|
1087
|
+
size: "md",
|
|
1088
|
+
"data-testid": "tpsl-confirm",
|
|
1089
|
+
disabled: status.isCreateMutating || !tpslEnable,
|
|
1090
|
+
loading: status.isCreateMutating || status.isUpdateMutating,
|
|
1091
|
+
onClick: () => {
|
|
1092
|
+
props.onSubmit().then(() => {
|
|
1093
|
+
props.close?.();
|
|
1094
|
+
onComplete?.();
|
|
1095
|
+
}).catch((err) => {
|
|
1096
|
+
});
|
|
1097
|
+
},
|
|
1098
|
+
children: t("common.confirm")
|
|
1099
|
+
}
|
|
1100
|
+
)
|
|
1101
|
+
] })
|
|
1102
|
+
] });
|
|
1103
|
+
};
|
|
1104
|
+
var TPSLOrderType = (props) => {
|
|
1105
|
+
const { tpPrice, slPrice } = props;
|
|
1106
|
+
const { t } = orderlyI18n.useTranslation();
|
|
1107
|
+
if (!!tpPrice && !!slPrice) {
|
|
1108
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Badge, { size: "xs", color: "neutral", children: t("common.tpsl") });
|
|
1109
|
+
}
|
|
1110
|
+
if (!!tpPrice) {
|
|
1111
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Badge, { size: "xs", color: "neutral", children: t("tpsl.tp") });
|
|
1112
|
+
}
|
|
1113
|
+
if (!!slPrice) {
|
|
1114
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Badge, { size: "xs", color: "neutral", children: t("tpsl.sl") });
|
|
1115
|
+
}
|
|
1116
|
+
return null;
|
|
1117
|
+
};
|
|
1118
|
+
var PositionTPSLConfirm = (props) => {
|
|
1119
|
+
const {
|
|
1120
|
+
symbol,
|
|
1121
|
+
tpPrice,
|
|
1122
|
+
slPrice,
|
|
1123
|
+
qty,
|
|
1124
|
+
maxQty,
|
|
1125
|
+
side,
|
|
1126
|
+
quoteDP,
|
|
1127
|
+
baseDP,
|
|
1128
|
+
isEditing,
|
|
1129
|
+
isPositionTPSL: _isPositionTPSL,
|
|
1130
|
+
orderInfo: order2
|
|
1131
|
+
} = props;
|
|
1132
|
+
const { t } = orderlyI18n.useTranslation();
|
|
1133
|
+
const [needConfirm, setNeedConfirm] = orderlyHooks.useLocalStorage(
|
|
1134
|
+
"orderly_order_confirm",
|
|
1135
|
+
true
|
|
1136
|
+
);
|
|
1137
|
+
const renderPositionType = () => {
|
|
1138
|
+
if (order2.position_type === orderlyTypes.PositionType.FULL) {
|
|
1139
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.positionType.full") });
|
|
1140
|
+
}
|
|
1141
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.positionType.partial") });
|
|
1142
|
+
};
|
|
1143
|
+
const renderTPSLPrice = ({
|
|
1144
|
+
price,
|
|
1145
|
+
isOrderPrice,
|
|
1146
|
+
isEnable,
|
|
1147
|
+
colorType
|
|
1148
|
+
}) => {
|
|
1149
|
+
if (!isEnable) {
|
|
1150
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36", children: "-- USDC" });
|
|
1151
|
+
}
|
|
1152
|
+
if (!price) {
|
|
1153
|
+
if (isOrderPrice) {
|
|
1154
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36", children: t("common.market") });
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1158
|
+
orderlyUi.Text.numeral,
|
|
1159
|
+
{
|
|
1160
|
+
unit: "USDC",
|
|
1161
|
+
rule: "price",
|
|
1162
|
+
className: orderlyUi.cn(
|
|
1163
|
+
"oui-text-base-contrast",
|
|
1164
|
+
colorType === "TP" ? "oui-text-trade-profit" : "oui-text-trade-loss"
|
|
1165
|
+
),
|
|
1166
|
+
unitClassName: "oui-text-base-contrast-36 oui-ml-1",
|
|
1167
|
+
dp: quoteDP,
|
|
1168
|
+
padding: false,
|
|
1169
|
+
children: price
|
|
1170
|
+
}
|
|
1171
|
+
);
|
|
1172
|
+
};
|
|
1173
|
+
const isPositionTPSL = _isPositionTPSL;
|
|
1174
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1175
|
+
isEditing && /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { as: "div", size: "2xs", intensity: 80, className: "oui-mb-3", children: t("tpsl.agreement", { symbol: orderlyUtils.transSymbolformString(symbol) }) }),
|
|
1176
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { pb: 4, children: [
|
|
1177
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Box, { grow: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1178
|
+
orderlyUi.Text.formatted,
|
|
1179
|
+
{
|
|
1180
|
+
rule: "symbol",
|
|
1181
|
+
formatString: "base-type",
|
|
1182
|
+
size: "base",
|
|
1183
|
+
showIcon: true,
|
|
1184
|
+
as: "div",
|
|
1185
|
+
intensity: 80,
|
|
1186
|
+
children: symbol
|
|
1187
|
+
}
|
|
1188
|
+
) }),
|
|
1189
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 1, children: [
|
|
1190
|
+
isPositionTPSL && /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Badge, { size: "xs", color: "primary", children: t("common.position") }),
|
|
1191
|
+
/* @__PURE__ */ jsxRuntime.jsx(TPSLOrderType, { tpPrice, slPrice }),
|
|
1192
|
+
side === orderlyTypes.OrderSide.SELL ? /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Badge, { size: "xs", color: "success", children: t("common.buy") }) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Badge, { size: "xs", color: "danger", children: t("common.sell") })
|
|
1193
|
+
] })
|
|
1194
|
+
] }),
|
|
1195
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Divider, {}),
|
|
1196
|
+
order2.tp_trigger_price || order2.sl_trigger_price ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1197
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Divider, { className: "oui-my-4" }),
|
|
1198
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1199
|
+
"div",
|
|
1200
|
+
{
|
|
1201
|
+
className: orderlyUi.textVariants({
|
|
1202
|
+
size: "sm",
|
|
1203
|
+
intensity: 54,
|
|
1204
|
+
className: "oui-space-y-1 oui-w-full oui-flex oui-flex-col oui-gap-3"
|
|
1205
|
+
}),
|
|
1206
|
+
children: [
|
|
1207
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast", children: renderPositionType() }),
|
|
1208
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", children: [
|
|
1209
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("common.orderQty") }),
|
|
1210
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1211
|
+
orderlyUi.Text.numeral,
|
|
1212
|
+
{
|
|
1213
|
+
rule: "price",
|
|
1214
|
+
dp: baseDP,
|
|
1215
|
+
padding: false,
|
|
1216
|
+
className: "oui-text-base-contrast",
|
|
1217
|
+
children: order2.quantity ?? "-"
|
|
1218
|
+
}
|
|
1219
|
+
)
|
|
1220
|
+
] }),
|
|
1221
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1222
|
+
orderlyUi.Flex,
|
|
1223
|
+
{
|
|
1224
|
+
direction: "column",
|
|
1225
|
+
justify: "between",
|
|
1226
|
+
itemAlign: "start",
|
|
1227
|
+
gap: 1,
|
|
1228
|
+
className: "oui-w-full",
|
|
1229
|
+
children: [
|
|
1230
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
1231
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.tpTriggerPrice") }),
|
|
1232
|
+
" ",
|
|
1233
|
+
renderTPSLPrice({
|
|
1234
|
+
price: order2.tp_trigger_price ?? "",
|
|
1235
|
+
isOrderPrice: false,
|
|
1236
|
+
isEnable: !!order2.tp_trigger_price,
|
|
1237
|
+
colorType: "TP"
|
|
1238
|
+
})
|
|
1239
|
+
] }),
|
|
1240
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
1241
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.tpOrderPrice") }),
|
|
1242
|
+
renderTPSLPrice({
|
|
1243
|
+
price: order2.tp_order_price ?? "",
|
|
1244
|
+
isOrderPrice: true,
|
|
1245
|
+
isEnable: !!order2.tp_trigger_price,
|
|
1246
|
+
colorType: "TP"
|
|
1247
|
+
})
|
|
1248
|
+
] })
|
|
1249
|
+
]
|
|
1250
|
+
}
|
|
1251
|
+
),
|
|
1252
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1253
|
+
orderlyUi.Flex,
|
|
1254
|
+
{
|
|
1255
|
+
direction: "column",
|
|
1256
|
+
justify: "between",
|
|
1257
|
+
itemAlign: "start",
|
|
1258
|
+
gap: 1,
|
|
1259
|
+
className: "oui-w-full",
|
|
1260
|
+
children: [
|
|
1261
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
1262
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.slTriggerPrice") }),
|
|
1263
|
+
renderTPSLPrice({
|
|
1264
|
+
price: order2.sl_trigger_price ?? "",
|
|
1265
|
+
isOrderPrice: false,
|
|
1266
|
+
isEnable: !!order2.sl_trigger_price,
|
|
1267
|
+
colorType: "SL"
|
|
1268
|
+
})
|
|
1269
|
+
] }),
|
|
1270
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
1271
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.slOrderPrice") }),
|
|
1272
|
+
renderTPSLPrice({
|
|
1273
|
+
price: order2.sl_order_price ?? "",
|
|
1274
|
+
isOrderPrice: true,
|
|
1275
|
+
isEnable: !!order2.sl_trigger_price,
|
|
1276
|
+
colorType: "SL"
|
|
1277
|
+
})
|
|
1278
|
+
] })
|
|
1279
|
+
]
|
|
1280
|
+
}
|
|
1281
|
+
)
|
|
1282
|
+
]
|
|
1283
|
+
}
|
|
1284
|
+
)
|
|
1285
|
+
] }) : null,
|
|
1286
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Box, { pt: 2, children: /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 1, children: [
|
|
1287
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1288
|
+
orderlyUi.Checkbox,
|
|
1289
|
+
{
|
|
1290
|
+
id: "disabledConfirm",
|
|
1291
|
+
color: "white",
|
|
1292
|
+
checked: !needConfirm,
|
|
1293
|
+
onCheckedChange: (check) => {
|
|
1294
|
+
setNeedConfirm(!check);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
),
|
|
1298
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1299
|
+
"label",
|
|
1300
|
+
{
|
|
1301
|
+
htmlFor: "disabledConfirm",
|
|
1302
|
+
className: orderlyUi.textVariants({
|
|
1303
|
+
size: "xs",
|
|
1304
|
+
intensity: 54,
|
|
1305
|
+
className: "oui-ml-1"
|
|
1306
|
+
}),
|
|
1307
|
+
children: t("orderEntry.disableOrderConfirm")
|
|
1308
|
+
}
|
|
1309
|
+
)
|
|
1310
|
+
] }) })
|
|
1311
|
+
] });
|
|
1312
|
+
};
|
|
1313
|
+
var useTPSLBuilder = (options) => {
|
|
1314
|
+
const {
|
|
1315
|
+
symbol,
|
|
1316
|
+
order: order2,
|
|
1317
|
+
isEditing,
|
|
1318
|
+
positionType,
|
|
1319
|
+
triggerPrice,
|
|
1320
|
+
type,
|
|
1321
|
+
withTriggerPrice
|
|
1322
|
+
} = options;
|
|
1323
|
+
const { t } = orderlyI18n.useTranslation();
|
|
1324
|
+
if (isEditing && !order2) {
|
|
1325
|
+
throw new orderlyTypes.SDKError("order is required when isEditing is true");
|
|
1326
|
+
}
|
|
1327
|
+
const symbolInfo = orderlyHooks.useSymbolsInfo();
|
|
1328
|
+
react.useRef(orderlyTypes.AlgoOrderRootType.TP_SL);
|
|
1329
|
+
const [{ rows: positions }] = orderlyHooks.usePositionStream();
|
|
1330
|
+
const [needConfirm] = orderlyHooks.useLocalStorage("orderly_order_confirm", true);
|
|
1331
|
+
const position = positions.find((item) => item.symbol === symbol);
|
|
1332
|
+
const estLiqPrice = orderlyHooks.useEstLiqPriceBySymbol(symbol);
|
|
1333
|
+
react.useEffect(() => {
|
|
1334
|
+
if (!position) {
|
|
1335
|
+
options.close?.();
|
|
1336
|
+
}
|
|
1337
|
+
}, [position]);
|
|
1338
|
+
const [
|
|
1339
|
+
tpslOrder,
|
|
1340
|
+
{
|
|
1341
|
+
submit,
|
|
1342
|
+
deleteOrder,
|
|
1343
|
+
setValue,
|
|
1344
|
+
setValues,
|
|
1345
|
+
validate,
|
|
1346
|
+
metaState,
|
|
1347
|
+
errors,
|
|
1348
|
+
isCreateMutating,
|
|
1349
|
+
isUpdateMutating
|
|
1350
|
+
}
|
|
1351
|
+
] = orderlyHooks.useTPSLOrder(
|
|
1352
|
+
{
|
|
1353
|
+
symbol,
|
|
1354
|
+
position_qty: position?.position_qty ?? 0,
|
|
1355
|
+
average_open_price: position?.average_open_price ?? 0
|
|
1356
|
+
},
|
|
1357
|
+
{
|
|
1358
|
+
defaultOrder: order2,
|
|
1359
|
+
positionType: triggerPrice ? orderlyTypes.PositionType.PARTIAL : positionType,
|
|
1360
|
+
// tpslEnable: {
|
|
1361
|
+
// tp_enable: !withTriggerPrice ? true : type === "tp",
|
|
1362
|
+
// sl_enable: !withTriggerPrice ? true : type === "sl",
|
|
1363
|
+
// },
|
|
1364
|
+
isEditing
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
const slPriceError = orderlyHooks.useTpslPriceChecker({
|
|
1368
|
+
slPrice: tpslOrder.sl_trigger_price?.toString() ?? void 0,
|
|
1369
|
+
liqPrice: estLiqPrice ?? null,
|
|
1370
|
+
side: tpslOrder.side
|
|
1371
|
+
});
|
|
1372
|
+
const isSlPriceWarning = slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
1373
|
+
const setQuantity = (value) => {
|
|
1374
|
+
setValue("quantity", value);
|
|
1375
|
+
};
|
|
1376
|
+
const setOrderPrice = (name, value) => {
|
|
1377
|
+
setValue(name, value);
|
|
1378
|
+
};
|
|
1379
|
+
const setPnL = (type2, value) => {
|
|
1380
|
+
setValue(type2, value);
|
|
1381
|
+
};
|
|
1382
|
+
const maxQty = react.useMemo(
|
|
1383
|
+
() => Math.abs(Number(position?.position_qty)),
|
|
1384
|
+
[position?.position_qty]
|
|
1385
|
+
);
|
|
1386
|
+
react.useMemo(() => {
|
|
1387
|
+
const quantity = order2?.algo_type === orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL ? maxQty : order2?.quantity;
|
|
1388
|
+
let diff = 0;
|
|
1389
|
+
if (Number(tpslOrder.quantity) !== quantity) {
|
|
1390
|
+
diff = 1;
|
|
1391
|
+
} else if (!isEditing && !!tpslOrder.quantity) {
|
|
1392
|
+
diff = 1;
|
|
1393
|
+
}
|
|
1394
|
+
if (order2 && isEditing) {
|
|
1395
|
+
const { tp_trigger_price, sl_trigger_price } = orderlyHooks.utils.findTPSLFromOrder(order2);
|
|
1396
|
+
const { tp_order_price, sl_order_price } = orderlyHooks.utils.findTPSLOrderPriceFromOrder(order2);
|
|
1397
|
+
if (tp_trigger_price !== Number(tpslOrder.tp_trigger_price) && typeof typeof tpslOrder.tp_trigger_price !== "undefined") {
|
|
1398
|
+
diff = 2;
|
|
1399
|
+
}
|
|
1400
|
+
if (sl_trigger_price !== Number(tpslOrder.sl_trigger_price) && typeof tpslOrder.sl_trigger_price !== "undefined") {
|
|
1401
|
+
diff = 3;
|
|
1402
|
+
}
|
|
1403
|
+
if (typeof tpslOrder.tp_order_price !== "undefined" && tp_order_price !== orderlyTypes.OrderType.MARKET && tp_order_price !== Number(tpslOrder.tp_order_price)) {
|
|
1404
|
+
diff = 4;
|
|
1405
|
+
}
|
|
1406
|
+
if (typeof tpslOrder.sl_order_price !== "undefined" && sl_order_price !== orderlyTypes.OrderType.MARKET && sl_order_price !== Number(tpslOrder.sl_order_price)) {
|
|
1407
|
+
diff = 5;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (diff === 1 && !tpslOrder.tp_trigger_price && !tpslOrder.sl_trigger_price) {
|
|
1411
|
+
diff = -1;
|
|
1412
|
+
}
|
|
1413
|
+
return diff;
|
|
1414
|
+
}, [
|
|
1415
|
+
tpslOrder.tp_trigger_price,
|
|
1416
|
+
tpslOrder.tp_order_price,
|
|
1417
|
+
tpslOrder.sl_trigger_price,
|
|
1418
|
+
tpslOrder.sl_order_price,
|
|
1419
|
+
tpslOrder.quantity,
|
|
1420
|
+
order2,
|
|
1421
|
+
isEditing
|
|
1422
|
+
]);
|
|
1423
|
+
react.useEffect(() => {
|
|
1424
|
+
if (!withTriggerPrice) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
if (!triggerPrice) {
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
if (type === "tp") {
|
|
1431
|
+
setValue("tp_trigger_price", triggerPrice);
|
|
1432
|
+
} else {
|
|
1433
|
+
setValue("sl_trigger_price", triggerPrice);
|
|
1434
|
+
}
|
|
1435
|
+
if (options.qty) {
|
|
1436
|
+
setValue("quantity", options.qty);
|
|
1437
|
+
}
|
|
1438
|
+
}, [type, triggerPrice, options.qty]);
|
|
1439
|
+
const cancel = () => {
|
|
1440
|
+
if (order2?.algo_order_id && order2?.symbol) {
|
|
1441
|
+
return deleteOrder(order2?.algo_order_id, order2?.symbol);
|
|
1442
|
+
}
|
|
1443
|
+
return Promise.reject("order id or symbol is invalid");
|
|
1444
|
+
};
|
|
1445
|
+
const onConfirm = (order3, options2) => {
|
|
1446
|
+
if (!needConfirm) {
|
|
1447
|
+
return Promise.resolve(true);
|
|
1448
|
+
}
|
|
1449
|
+
const maxQty2 = Math.abs(Number(position?.position_qty));
|
|
1450
|
+
if (`${order3.tp_trigger_price ?? ""}`.length === 0 && `${order3.sl_trigger_price ?? ""}`.length === 0) {
|
|
1451
|
+
return orderlyUi.modal.confirm({
|
|
1452
|
+
title: t("orders.cancelOrder"),
|
|
1453
|
+
content: t("tpsl.cancelOrder.description"),
|
|
1454
|
+
onOk: () => {
|
|
1455
|
+
return options2.cancel();
|
|
1456
|
+
}
|
|
1457
|
+
}).then(
|
|
1458
|
+
() => {
|
|
1459
|
+
return true;
|
|
1460
|
+
},
|
|
1461
|
+
() => {
|
|
1462
|
+
return Promise.reject(false);
|
|
1463
|
+
}
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
return orderlyUi.modal.confirm({
|
|
1467
|
+
title: t("tpsl.confirmOrder"),
|
|
1468
|
+
// bodyClassName: "lg:oui-py-0",
|
|
1469
|
+
onOk: async () => {
|
|
1470
|
+
try {
|
|
1471
|
+
const res = await options2.submit({
|
|
1472
|
+
accountId: position?.account_id
|
|
1473
|
+
});
|
|
1474
|
+
if (res.success) {
|
|
1475
|
+
return res;
|
|
1476
|
+
}
|
|
1477
|
+
if (res.message) {
|
|
1478
|
+
orderlyUi.toast.error(res.message);
|
|
1479
|
+
}
|
|
1480
|
+
return false;
|
|
1481
|
+
} catch (err) {
|
|
1482
|
+
if (err?.message) {
|
|
1483
|
+
orderlyUi.toast.error(err.message);
|
|
1484
|
+
}
|
|
1485
|
+
return false;
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
classNames: {
|
|
1489
|
+
body: "!oui-pb-0"
|
|
1490
|
+
},
|
|
1491
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1492
|
+
PositionTPSLConfirm,
|
|
1493
|
+
{
|
|
1494
|
+
isPositionTPSL: positionType === orderlyTypes.PositionType.FULL,
|
|
1495
|
+
isEditing,
|
|
1496
|
+
symbol: order3.symbol,
|
|
1497
|
+
qty: Number(order3.quantity),
|
|
1498
|
+
maxQty: maxQty2,
|
|
1499
|
+
tpPrice: Number(order3.tp_trigger_price),
|
|
1500
|
+
slPrice: Number(order3.sl_trigger_price),
|
|
1501
|
+
side: order3.side,
|
|
1502
|
+
orderInfo: order3,
|
|
1503
|
+
quoteDP: symbolInfo[symbol]("quote_dp") ?? 2,
|
|
1504
|
+
baseDP: symbolInfo[symbol]("base_dp") ?? 2
|
|
1505
|
+
}
|
|
1506
|
+
)
|
|
1507
|
+
}).then(
|
|
1508
|
+
() => {
|
|
1509
|
+
return true;
|
|
1510
|
+
},
|
|
1511
|
+
() => {
|
|
1512
|
+
return Promise.reject(false);
|
|
1513
|
+
}
|
|
1514
|
+
);
|
|
1515
|
+
};
|
|
1516
|
+
const onSubmit = async () => {
|
|
1517
|
+
try {
|
|
1518
|
+
const validOrder = await validate(
|
|
1519
|
+
isSlPriceWarning ? void 0 : slPriceError
|
|
1520
|
+
);
|
|
1521
|
+
if (validOrder) {
|
|
1522
|
+
if (!needConfirm) {
|
|
1523
|
+
return submit({ accountId: position?.account_id }).then(() => true).catch((err) => {
|
|
1524
|
+
if (err?.message) {
|
|
1525
|
+
orderlyUi.toast.error(err.message);
|
|
1526
|
+
}
|
|
1527
|
+
throw false;
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
return onConfirm(tpslOrder, {
|
|
1531
|
+
position,
|
|
1532
|
+
submit,
|
|
1533
|
+
cancel
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
return Promise.reject(error);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
return {
|
|
1541
|
+
isEditing,
|
|
1542
|
+
symbolInfo: symbolInfo[symbol],
|
|
1543
|
+
maxQty,
|
|
1544
|
+
setQuantity: orderlyHooks.useMemoizedFn(setQuantity),
|
|
1545
|
+
orderQuantity: tpslOrder.quantity,
|
|
1546
|
+
// isPosition: isPositionTPSL,
|
|
1547
|
+
TPSL_OrderEntity: tpslOrder,
|
|
1548
|
+
setOrderValue: setValue,
|
|
1549
|
+
setPnL,
|
|
1550
|
+
setOrderPrice,
|
|
1551
|
+
// needConfirm,
|
|
1552
|
+
onSubmit,
|
|
1553
|
+
slPriceError,
|
|
1554
|
+
estLiqPrice,
|
|
1555
|
+
metaState,
|
|
1556
|
+
errors,
|
|
1557
|
+
status: {
|
|
1558
|
+
isCreateMutating,
|
|
1559
|
+
isUpdateMutating
|
|
1560
|
+
},
|
|
1561
|
+
position,
|
|
1562
|
+
setValues
|
|
1563
|
+
};
|
|
1564
|
+
};
|
|
1565
|
+
var TPSLWidget = (props) => {
|
|
1566
|
+
const { onCancel, onComplete, ...rest } = props;
|
|
1567
|
+
const state = useTPSLBuilder(rest);
|
|
1568
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1569
|
+
TPSL,
|
|
1570
|
+
{
|
|
1571
|
+
...state,
|
|
1572
|
+
onCancel,
|
|
1573
|
+
onComplete,
|
|
1574
|
+
close: rest.close
|
|
1575
|
+
}
|
|
1576
|
+
);
|
|
1577
|
+
};
|
|
1578
|
+
var TPSLSheetId = "TPSLSheetId";
|
|
1579
|
+
var TPSLDialogId = "TPSLDialogId";
|
|
1580
|
+
orderlyUi.registerSimpleSheet(TPSLSheetId, TPSLWidget);
|
|
1581
|
+
orderlyUi.registerSimpleDialog(TPSLDialogId, TPSLWidget, {
|
|
1582
|
+
classNames: {
|
|
1583
|
+
content: "oui-w-[420px]"
|
|
1584
|
+
}
|
|
1585
|
+
});
|
|
1586
|
+
var PositionTPSLPopover = (props) => {
|
|
1587
|
+
const { position, order: order2, baseDP, quoteDP, buttonProps, isEditing } = props;
|
|
1588
|
+
const [needConfirm] = orderlyHooks.useLocalStorage("orderly_order_confirm", true);
|
|
1589
|
+
const { t } = orderlyI18n.useTranslation();
|
|
1590
|
+
const isPositionTPSL = isEditing ? order2?.algo_type === orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL : void 0;
|
|
1591
|
+
const onEdit = () => {
|
|
1592
|
+
orderlyUi.modal.show(TPSLDialogId, {
|
|
1593
|
+
order: order2,
|
|
1594
|
+
symbol: position.symbol,
|
|
1595
|
+
baseDP,
|
|
1596
|
+
quoteDP,
|
|
1597
|
+
positionType: isPositionTPSL ? orderlyTypes.PositionType.FULL : orderlyTypes.PositionType.PARTIAL,
|
|
1598
|
+
isEditing
|
|
1599
|
+
});
|
|
1600
|
+
};
|
|
1601
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Box, { onClick: onEdit, className: "oui-cursor-pointer", children: props.children || /* @__PURE__ */ jsxRuntime.jsx(
|
|
1602
|
+
orderlyUi.Button,
|
|
1603
|
+
{
|
|
1604
|
+
variant: "outlined",
|
|
1605
|
+
size: "sm",
|
|
1606
|
+
color: "secondary",
|
|
1607
|
+
...buttonProps,
|
|
1608
|
+
children: props.label
|
|
1609
|
+
}
|
|
1610
|
+
) });
|
|
1611
|
+
};
|
|
1612
|
+
var PositionTPSLSheet = (props) => {
|
|
1613
|
+
const { position, order: order2, symbolInfo, isEditing } = props;
|
|
1614
|
+
const { resolve, hide, updateArgs } = orderlyUi.useModal();
|
|
1615
|
+
const isPositionTPSL = isEditing ? order2?.algo_type === orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL : void 0;
|
|
1616
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1617
|
+
TPSLWidget,
|
|
1618
|
+
{
|
|
1619
|
+
...props,
|
|
1620
|
+
positionType: props.positionType ?? (isPositionTPSL ? orderlyTypes.PositionType.FULL : orderlyTypes.PositionType.PARTIAL),
|
|
1621
|
+
onCancel: () => {
|
|
1622
|
+
hide();
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
) });
|
|
1626
|
+
};
|
|
1627
|
+
var TPSLAdvancedUI = (props) => {
|
|
1628
|
+
const { t } = orderlyI18n.useTranslation();
|
|
1629
|
+
const { errors, validated } = props.metaState;
|
|
1630
|
+
const { getErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(props.slPriceError);
|
|
1631
|
+
const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
1632
|
+
const {
|
|
1633
|
+
formattedOrder,
|
|
1634
|
+
setValue: setOrderValue,
|
|
1635
|
+
symbolInfo,
|
|
1636
|
+
setValues
|
|
1637
|
+
} = props;
|
|
1638
|
+
const [tpValues, setTpValuse] = react.useState({
|
|
1639
|
+
enable: false,
|
|
1640
|
+
order_type: formattedOrder.tp_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
1641
|
+
order_price: formattedOrder.tp_order_price ?? "",
|
|
1642
|
+
trigger_price: formattedOrder.tp_trigger_price ?? "",
|
|
1643
|
+
PnL: formattedOrder.tp_pnl ?? "",
|
|
1644
|
+
Offset: formattedOrder.tp_offset ?? "",
|
|
1645
|
+
"Offset%": formattedOrder.tp_offset_percentage ?? "",
|
|
1646
|
+
ROI: formattedOrder.tp_ROI ?? ""
|
|
1647
|
+
});
|
|
1648
|
+
const [slValues, setSlValues] = react.useState({
|
|
1649
|
+
enable: false,
|
|
1650
|
+
order_type: formattedOrder.sl_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
1651
|
+
order_price: formattedOrder.sl_order_price ?? "",
|
|
1652
|
+
trigger_price: formattedOrder.sl_trigger_price ?? "",
|
|
1653
|
+
PnL: formattedOrder.sl_pnl ?? "",
|
|
1654
|
+
Offset: formattedOrder.sl_offset ?? "",
|
|
1655
|
+
"Offset%": formattedOrder.sl_offset_percentage ?? "",
|
|
1656
|
+
ROI: formattedOrder.sl_ROI ?? ""
|
|
1657
|
+
});
|
|
1658
|
+
react.useEffect(() => {
|
|
1659
|
+
setTpValuse((prev) => ({
|
|
1660
|
+
...prev,
|
|
1661
|
+
// enable: formattedOrder.tp_enable ?? false,
|
|
1662
|
+
order_type: formattedOrder.tp_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
1663
|
+
order_price: formattedOrder.tp_order_price ?? "",
|
|
1664
|
+
trigger_price: formattedOrder.tp_trigger_price ?? "",
|
|
1665
|
+
PnL: formattedOrder.tp_pnl ?? "",
|
|
1666
|
+
Offset: formattedOrder.tp_offset ?? "",
|
|
1667
|
+
"Offset%": formattedOrder.tp_offset_percentage ?? "",
|
|
1668
|
+
ROI: formattedOrder.tp_ROI ?? ""
|
|
1669
|
+
}));
|
|
1670
|
+
}, [formattedOrder]);
|
|
1671
|
+
react.useEffect(() => {
|
|
1672
|
+
setSlValues((prev) => ({
|
|
1673
|
+
...prev,
|
|
1674
|
+
// enable: formattedOrder.sl_enable ?? false,
|
|
1675
|
+
order_type: formattedOrder.sl_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
1676
|
+
order_price: formattedOrder.sl_order_price ?? "",
|
|
1677
|
+
trigger_price: formattedOrder.sl_trigger_price ?? "",
|
|
1678
|
+
PnL: formattedOrder.sl_pnl ?? "",
|
|
1679
|
+
Offset: formattedOrder.sl_offset ?? "",
|
|
1680
|
+
"Offset%": formattedOrder.sl_offset_percentage ?? "",
|
|
1681
|
+
ROI: formattedOrder.sl_ROI ?? ""
|
|
1682
|
+
}));
|
|
1683
|
+
}, [formattedOrder]);
|
|
1684
|
+
const tpslEnable = formattedOrder.tp_trigger_price || formattedOrder.sl_trigger_price;
|
|
1685
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-flex oui-h-full oui-flex-col oui-justify-between oui-rounded-[16px] oui-py-3", children: [
|
|
1686
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-px-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1687
|
+
orderlyUi.Flex,
|
|
1688
|
+
{
|
|
1689
|
+
className: "oui-mb-5 oui-cursor-pointer oui-text-base oui-text-base-contrast-80",
|
|
1690
|
+
gap: 1,
|
|
1691
|
+
itemAlign: "center",
|
|
1692
|
+
onClick: props.onClose,
|
|
1693
|
+
children: [
|
|
1694
|
+
/* @__PURE__ */ jsxRuntime.jsx(ArrowRightIcon, { className: " oui-text-base-contrast-80" }),
|
|
1695
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("common.tpsl") })
|
|
1696
|
+
]
|
|
1697
|
+
}
|
|
1698
|
+
) }),
|
|
1699
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.ScrollArea, { className: "oui-flex-1", children: [
|
|
1700
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-px-3", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1701
|
+
OrderInfo,
|
|
1702
|
+
{
|
|
1703
|
+
order: formattedOrder,
|
|
1704
|
+
baseDP: symbolInfo.base_dp,
|
|
1705
|
+
quoteDP: symbolInfo.quote_dp,
|
|
1706
|
+
estLiqPrice: props.estLiqPrice ?? void 0,
|
|
1707
|
+
symbolLeverage: props.symbolLeverage
|
|
1708
|
+
}
|
|
1709
|
+
) }),
|
|
1710
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Divider, { className: "oui-my-3" }),
|
|
1711
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-px-3", children: [
|
|
1712
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { className: "oui-gap-[6px]", children: [
|
|
1713
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1714
|
+
orderlyUi.Button,
|
|
1715
|
+
{
|
|
1716
|
+
onClick: () => {
|
|
1717
|
+
setOrderValue("side", orderlyTypes.OrderSide.BUY);
|
|
1718
|
+
},
|
|
1719
|
+
size: "sm",
|
|
1720
|
+
fullWidth: true,
|
|
1721
|
+
"data-type": orderlyTypes.OrderSide.BUY,
|
|
1722
|
+
className: orderlyUi.cn(
|
|
1723
|
+
formattedOrder.side === orderlyTypes.OrderSide.BUY ? "oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80" : "oui-bg-base-7 oui-text-base-contrast-36 hover:oui-bg-base-6 active:oui-bg-base-6"
|
|
1724
|
+
),
|
|
1725
|
+
"data-testid": "oui-testid-orderEntry-side-buy-button",
|
|
1726
|
+
children: t("common.buy")
|
|
1727
|
+
}
|
|
1728
|
+
),
|
|
1729
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1730
|
+
orderlyUi.Button,
|
|
1731
|
+
{
|
|
1732
|
+
onClick: () => {
|
|
1733
|
+
setOrderValue("side", orderlyTypes.OrderSide.SELL);
|
|
1734
|
+
},
|
|
1735
|
+
"data-type": orderlyTypes.OrderSide.SELL,
|
|
1736
|
+
fullWidth: true,
|
|
1737
|
+
size: "sm",
|
|
1738
|
+
className: orderlyUi.cn(
|
|
1739
|
+
formattedOrder.side === orderlyTypes.OrderSide.SELL ? "oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80" : "oui-bg-base-7 oui-text-base-contrast-36 hover:oui-bg-base-6 active:oui-bg-base-6"
|
|
1740
|
+
),
|
|
1741
|
+
"data-testid": "oui-testid-orderEntry-side-sell-button",
|
|
1742
|
+
children: t("common.sell")
|
|
1743
|
+
}
|
|
1744
|
+
)
|
|
1745
|
+
] }),
|
|
1746
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-py-3", children: [
|
|
1747
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1748
|
+
TPSLPositionTypeWidget,
|
|
1749
|
+
{
|
|
1750
|
+
value: formattedOrder.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
1751
|
+
onChange: (key, value) => {
|
|
1752
|
+
if (value === orderlyTypes.PositionType.FULL) {
|
|
1753
|
+
setValues({
|
|
1754
|
+
position_type: orderlyTypes.PositionType.FULL,
|
|
1755
|
+
tp_order_type: orderlyTypes.OrderType.MARKET,
|
|
1756
|
+
tp_order_price: void 0,
|
|
1757
|
+
sl_order_type: orderlyTypes.OrderType.MARKET,
|
|
1758
|
+
sl_order_price: void 0
|
|
1759
|
+
});
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
setOrderValue("position_type", value);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
),
|
|
1766
|
+
formattedOrder.position_type === orderlyTypes.PositionType.FULL && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1767
|
+
orderlyUi.Flex,
|
|
1768
|
+
{
|
|
1769
|
+
justify: "start",
|
|
1770
|
+
itemAlign: "start",
|
|
1771
|
+
gap: 2,
|
|
1772
|
+
className: "oui-mt-3 oui-w-full",
|
|
1773
|
+
children: [
|
|
1774
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-relative oui-top-[7px] oui-size-1 oui-rounded-full oui-bg-[#D25f00]" }),
|
|
1775
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-2xs oui-text-[#D25f00]", children: t("tpsl.positionType.full.tips.market") })
|
|
1776
|
+
]
|
|
1777
|
+
}
|
|
1778
|
+
)
|
|
1779
|
+
] }),
|
|
1780
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { direction: "column", gap: 6, children: [
|
|
1781
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1782
|
+
TPSLInputRowWidget,
|
|
1783
|
+
{
|
|
1784
|
+
rootOrderPrice: formattedOrder.order_price,
|
|
1785
|
+
symbol: symbolInfo.symbol,
|
|
1786
|
+
type: "tp",
|
|
1787
|
+
side: formattedOrder.side,
|
|
1788
|
+
values: tpValues,
|
|
1789
|
+
errors: validated ? errors : null,
|
|
1790
|
+
quote_dp: symbolInfo.quote_dp,
|
|
1791
|
+
hideOrderPrice: formattedOrder.position_type === orderlyTypes.PositionType.FULL,
|
|
1792
|
+
onChange: (key, value) => {
|
|
1793
|
+
setOrderValue(key, value);
|
|
1794
|
+
},
|
|
1795
|
+
positionType: formattedOrder.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
1796
|
+
symbolLeverage: props.symbolLeverage
|
|
1797
|
+
}
|
|
1798
|
+
),
|
|
1799
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1800
|
+
TPSLInputRowWidget,
|
|
1801
|
+
{
|
|
1802
|
+
rootOrderPrice: formattedOrder.order_price,
|
|
1803
|
+
symbol: symbolInfo.symbol,
|
|
1804
|
+
type: "sl",
|
|
1805
|
+
side: formattedOrder.side,
|
|
1806
|
+
values: slValues,
|
|
1807
|
+
hideOrderPrice: formattedOrder.position_type === orderlyTypes.PositionType.FULL,
|
|
1808
|
+
errors: validated ? errors : null,
|
|
1809
|
+
inputWarnNode: isSlPriceWarning && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1810
|
+
orderlyUi.DotStatus,
|
|
1811
|
+
{
|
|
1812
|
+
color: "warning",
|
|
1813
|
+
size: "xs",
|
|
1814
|
+
label: getErrorMsg("sl_trigger_price")
|
|
1815
|
+
}
|
|
1816
|
+
),
|
|
1817
|
+
quote_dp: symbolInfo.quote_dp,
|
|
1818
|
+
positionType: formattedOrder.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
1819
|
+
onChange: (key, value) => {
|
|
1820
|
+
setOrderValue(key, value);
|
|
1821
|
+
},
|
|
1822
|
+
symbolLeverage: props.symbolLeverage
|
|
1823
|
+
}
|
|
1824
|
+
)
|
|
1825
|
+
] }),
|
|
1826
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1827
|
+
PnlInfo,
|
|
1828
|
+
{
|
|
1829
|
+
tp_pnl: formattedOrder.tp_pnl,
|
|
1830
|
+
sl_pnl: formattedOrder.sl_pnl,
|
|
1831
|
+
className: "oui-mt-6"
|
|
1832
|
+
}
|
|
1833
|
+
)
|
|
1834
|
+
] })
|
|
1835
|
+
] }),
|
|
1836
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { className: "oui-mt-6 oui-px-3", gap: 2, children: [
|
|
1837
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1838
|
+
orderlyUi.Button,
|
|
1839
|
+
{
|
|
1840
|
+
size: "md",
|
|
1841
|
+
fullWidth: true,
|
|
1842
|
+
color: "gray",
|
|
1843
|
+
variant: "outlined",
|
|
1844
|
+
className: "oui-text-base-contrast-36",
|
|
1845
|
+
onClick: props.onClose,
|
|
1846
|
+
children: t("common.cancel")
|
|
1847
|
+
}
|
|
1848
|
+
),
|
|
1849
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1850
|
+
orderlyUi.Button,
|
|
1851
|
+
{
|
|
1852
|
+
size: "md",
|
|
1853
|
+
fullWidth: true,
|
|
1854
|
+
color: "success",
|
|
1855
|
+
className: orderlyUi.cn(
|
|
1856
|
+
formattedOrder.side === orderlyTypes.OrderSide.SELL ? "oui-bg-danger-darken hover:oui-bg-danger-darken/80 active:oui-bg-danger-darken/80" : "oui-bg-success-darken hover:oui-bg-success-darken/80 active:oui-bg-success-darken/80"
|
|
1857
|
+
),
|
|
1858
|
+
onClick: props.onSubmit,
|
|
1859
|
+
disabled: !tpslEnable,
|
|
1860
|
+
children: t("tpsl.advanced.submit")
|
|
1861
|
+
}
|
|
1862
|
+
)
|
|
1863
|
+
] })
|
|
1864
|
+
] });
|
|
1865
|
+
};
|
|
1866
|
+
var ArrowRightIcon = (props) => {
|
|
1867
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1868
|
+
"svg",
|
|
1869
|
+
{
|
|
1870
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1871
|
+
width: "14",
|
|
1872
|
+
height: "14",
|
|
1873
|
+
viewBox: "0 0 14 14",
|
|
1874
|
+
fill: "currentColor",
|
|
1875
|
+
...props,
|
|
1876
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M8.03752 2.9294C7.89169 2.95857 7.74527 3.03207 7.65661 3.16624L5.33145 6.66624C5.20137 6.86224 5.20137 7.12648 5.33145 7.32248L7.65661 10.8225C7.83452 11.0902 8.20669 11.1655 8.47385 10.9864C8.74044 10.8079 8.8151 10.434 8.63719 10.1662L6.53019 6.99408L8.63719 3.82249C8.8151 3.55416 8.74044 3.18082 8.47385 3.00232C8.34027 2.91249 8.18335 2.89965 8.03752 2.9294Z" })
|
|
1877
|
+
}
|
|
1878
|
+
);
|
|
1879
|
+
};
|
|
1880
|
+
var useTPSLAdvanced = (props) => {
|
|
1881
|
+
const { order: order2, setOrderValue, onClose } = props;
|
|
1882
|
+
const [innerMetaState, setInnerMetaState] = react.useState(null);
|
|
1883
|
+
const {
|
|
1884
|
+
formattedOrder,
|
|
1885
|
+
setValue,
|
|
1886
|
+
setValues,
|
|
1887
|
+
helper,
|
|
1888
|
+
symbolInfo,
|
|
1889
|
+
metaState,
|
|
1890
|
+
...state
|
|
1891
|
+
} = orderlyHooks.useOrderEntry(order2.symbol, {
|
|
1892
|
+
initialOrder: {
|
|
1893
|
+
symbol: order2.symbol,
|
|
1894
|
+
order_type: order2.order_type,
|
|
1895
|
+
side: order2.side,
|
|
1896
|
+
order_price: order2.order_price,
|
|
1897
|
+
order_quantity: order2.order_quantity,
|
|
1898
|
+
position_type: order2.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
1899
|
+
trigger_price: order2.trigger_price,
|
|
1900
|
+
// tp_enable: isTPSLEnable(order, "tp"),
|
|
1901
|
+
// sl_enable: isTPSLEnable(order, "sl"),
|
|
1902
|
+
tp_trigger_price: order2.tp_trigger_price,
|
|
1903
|
+
sl_trigger_price: order2.sl_trigger_price,
|
|
1904
|
+
tp_order_price: order2.tp_order_price,
|
|
1905
|
+
sl_order_price: order2.sl_order_price,
|
|
1906
|
+
tp_order_type: order2.tp_order_type,
|
|
1907
|
+
sl_order_type: order2.sl_order_type,
|
|
1908
|
+
sl_pnl: order2.sl_pnl,
|
|
1909
|
+
sl_offset: order2.sl_offset,
|
|
1910
|
+
sl_offset_percentage: order2.sl_offset_percentage,
|
|
1911
|
+
tp_pnl: order2.tp_pnl,
|
|
1912
|
+
tp_offset: order2.tp_offset,
|
|
1913
|
+
tp_offset_percentage: order2.tp_offset_percentage
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
const slPriceError = orderlyHooks.useTpslPriceChecker({
|
|
1917
|
+
slPrice: formattedOrder.sl_trigger_price,
|
|
1918
|
+
liqPrice: state.estLiqPrice,
|
|
1919
|
+
side: formattedOrder.side
|
|
1920
|
+
});
|
|
1921
|
+
const onSubmit = () => {
|
|
1922
|
+
const isSlPriceError = slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_ERROR;
|
|
1923
|
+
helper.validate(isSlPriceError ? slPriceError : void 0).then(() => {
|
|
1924
|
+
props.onSubmit(formattedOrder);
|
|
1925
|
+
}).catch((err) => {
|
|
1926
|
+
});
|
|
1927
|
+
};
|
|
1928
|
+
return {
|
|
1929
|
+
order: order2,
|
|
1930
|
+
formattedOrder,
|
|
1931
|
+
symbolInfo,
|
|
1932
|
+
slPriceError,
|
|
1933
|
+
estLiqPrice: state.estLiqPrice,
|
|
1934
|
+
setValue,
|
|
1935
|
+
setValues,
|
|
1936
|
+
onSubmit,
|
|
1937
|
+
onClose,
|
|
1938
|
+
metaState,
|
|
1939
|
+
symbolLeverage: props.symbolLeverage
|
|
1940
|
+
};
|
|
1941
|
+
};
|
|
1942
|
+
var TPSLAdvancedWidget = (props) => {
|
|
1943
|
+
const state = useTPSLAdvanced({
|
|
1944
|
+
order: props.order,
|
|
1945
|
+
setOrderValue: props.setOrderValue,
|
|
1946
|
+
onSubmit: props.onSubmit,
|
|
1947
|
+
onClose: props.onClose,
|
|
1948
|
+
symbolLeverage: props.symbolLeverage
|
|
1949
|
+
});
|
|
1950
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TPSLAdvancedUI, { ...state });
|
|
1951
|
+
};
|
|
1952
|
+
var TPSLAdvancedSheetId = "TPSLAdvancedSheetId";
|
|
1953
|
+
var TPSLAdvancedDialogId = "TPSLAdvancedDialogId";
|
|
1954
|
+
orderlyUi.registerSimpleSheet(TPSLAdvancedSheetId, TPSLAdvancedWidget, {
|
|
1955
|
+
title: () => orderlyI18n.i18n.t("common.settings")
|
|
1956
|
+
});
|
|
1957
|
+
orderlyUi.registerSimpleDialog(TPSLAdvancedDialogId, TPSLAdvancedWidget, {
|
|
1958
|
+
title: () => orderlyI18n.i18n.t("common.settings")
|
|
1959
|
+
});
|
|
1960
|
+
var useTPSLDetail = (props) => {
|
|
1961
|
+
const { position } = props;
|
|
1962
|
+
const symbol = position.symbol;
|
|
1963
|
+
const symbolInfo = orderlyHooks.useSymbolsInfo()[symbol];
|
|
1964
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
1965
|
+
const { t } = orderlyI18n.useTranslation();
|
|
1966
|
+
const [fullPositionOrders, setFullPositionOrders] = react.useState(
|
|
1967
|
+
[]
|
|
1968
|
+
);
|
|
1969
|
+
const [partialPositionOrders, setPartialPositionOrders] = react.useState([]);
|
|
1970
|
+
const [tpslOrders, { cancelAlgoOrder, cancelPostionOrdersByTypes, refresh }] = orderlyHooks.useOrderStream(
|
|
1971
|
+
{
|
|
1972
|
+
symbol: position.symbol,
|
|
1973
|
+
status: orderlyTypes.OrderStatus.INCOMPLETE,
|
|
1974
|
+
includes: [orderlyTypes.AlgoOrderRootType.POSITIONAL_TP_SL, orderlyTypes.AlgoOrderRootType.TP_SL],
|
|
1975
|
+
size: 500
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
keeplive: true
|
|
1979
|
+
}
|
|
1980
|
+
);
|
|
1981
|
+
const onCancelOrder = async (order2) => {
|
|
1982
|
+
return await cancelAlgoOrder(order2.algo_order_id, order2.symbol);
|
|
1983
|
+
};
|
|
1984
|
+
const onCancelAllTPSLOrders = async () => {
|
|
1985
|
+
return await cancelPostionOrdersByTypes(symbol, [orderlyTypes.AlgoOrderRootType.TP_SL]);
|
|
1986
|
+
};
|
|
1987
|
+
const showTPSLDialog = ({
|
|
1988
|
+
order: order2,
|
|
1989
|
+
positionType,
|
|
1990
|
+
isEditing
|
|
1991
|
+
}) => {
|
|
1992
|
+
const dialogId = isMobile ? TPSLSheetId : TPSLDialogId;
|
|
1993
|
+
orderlyUi.modal.show(dialogId, {
|
|
1994
|
+
order: order2,
|
|
1995
|
+
symbol: position.symbol,
|
|
1996
|
+
positionType,
|
|
1997
|
+
isEditing
|
|
1998
|
+
});
|
|
1999
|
+
};
|
|
2000
|
+
const editTPSLOrder = (order2, positionType) => {
|
|
2001
|
+
showTPSLDialog({ order: order2, positionType, isEditing: true });
|
|
2002
|
+
};
|
|
2003
|
+
const addTPSLOrder = (positionType) => {
|
|
2004
|
+
showTPSLDialog({ positionType, isEditing: false });
|
|
2005
|
+
};
|
|
2006
|
+
react.useEffect(() => {
|
|
2007
|
+
if (tpslOrders) {
|
|
2008
|
+
const { fullPositionOrder, partialPositionOrders: partialPositionOrders2 } = orderlyHooks.findPositionTPSLFromOrders(tpslOrders, symbol);
|
|
2009
|
+
setFullPositionOrders(fullPositionOrder ? [fullPositionOrder] : []);
|
|
2010
|
+
setPartialPositionOrders(partialPositionOrders2 ?? []);
|
|
2011
|
+
}
|
|
2012
|
+
}, [tpslOrders, symbol]);
|
|
2013
|
+
return {
|
|
2014
|
+
symbolInfo,
|
|
2015
|
+
position,
|
|
2016
|
+
symbol,
|
|
2017
|
+
fullPositionOrders,
|
|
2018
|
+
partialPositionOrders,
|
|
2019
|
+
cancelPostionOrdersByTypes,
|
|
2020
|
+
onCancelOrder,
|
|
2021
|
+
onCancelAllTPSLOrders,
|
|
2022
|
+
editTPSLOrder,
|
|
2023
|
+
addTPSLOrder
|
|
2024
|
+
};
|
|
2025
|
+
};
|
|
2026
|
+
var TPSLDetailContext = react.createContext({});
|
|
2027
|
+
var TPSLDetailProvider = (props) => {
|
|
2028
|
+
const symbolInfo = orderlyHooks.useSymbolsInfo()[props.symbol];
|
|
2029
|
+
const estLiqPrice = orderlyHooks.useEstLiqPriceBySymbol(props.symbol);
|
|
2030
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2031
|
+
TPSLDetailContext.Provider,
|
|
2032
|
+
{
|
|
2033
|
+
value: {
|
|
2034
|
+
base_dp: symbolInfo("base_dp"),
|
|
2035
|
+
quote_dp: symbolInfo("quote_dp"),
|
|
2036
|
+
side: props.position.position_qty > 0 ? orderlyTypes.OrderSide.BUY : orderlyTypes.OrderSide.SELL,
|
|
2037
|
+
position: props.position,
|
|
2038
|
+
estLiqPrice
|
|
2039
|
+
},
|
|
2040
|
+
children: props.children
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
2043
|
+
};
|
|
2044
|
+
var useTPSLDetailContext = () => {
|
|
2045
|
+
return react.useContext(TPSLDetailContext);
|
|
2046
|
+
};
|
|
2047
|
+
var FlexCell = (props) => {
|
|
2048
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2049
|
+
orderlyUi.Flex,
|
|
2050
|
+
{
|
|
2051
|
+
direction: "column",
|
|
2052
|
+
justify: "center",
|
|
2053
|
+
itemAlign: "start",
|
|
2054
|
+
className: orderlyUi.cn("oui-text-2xs oui-h-[36px]", props.className),
|
|
2055
|
+
children: props.children
|
|
2056
|
+
}
|
|
2057
|
+
);
|
|
2058
|
+
};
|
|
2059
|
+
var EstPnlRender = ({ order: order2 }) => {
|
|
2060
|
+
const { position, base_dp, quote_dp } = useTPSLDetailContext();
|
|
2061
|
+
const { tp_trigger_price, sl_trigger_price } = orderlyHooks.findTPSLFromOrder(order2);
|
|
2062
|
+
let tp_unrealPnl = void 0;
|
|
2063
|
+
let sl_unrealPnl = void 0;
|
|
2064
|
+
const qty = new orderlyUtils.Decimal(order2.quantity).eq(0) ? position.position_qty : order2.quantity;
|
|
2065
|
+
const side = position.position_qty > 0 ? orderlyTypes.OrderSide.BUY : orderlyTypes.OrderSide.SELL;
|
|
2066
|
+
const openPrice = position?.average_open_price;
|
|
2067
|
+
if (tp_trigger_price) {
|
|
2068
|
+
const direction = orderlyUtils.getTPSLDirection({
|
|
2069
|
+
side,
|
|
2070
|
+
type: "tp",
|
|
2071
|
+
closePrice: tp_trigger_price,
|
|
2072
|
+
orderPrice: openPrice
|
|
2073
|
+
});
|
|
2074
|
+
tp_unrealPnl = orderlyUtils.formatNum.pnl(
|
|
2075
|
+
orderlyPerp.positions.unrealizedPnL({
|
|
2076
|
+
qty,
|
|
2077
|
+
openPrice,
|
|
2078
|
+
// markPrice: unRealizedPrice,
|
|
2079
|
+
markPrice: tp_trigger_price
|
|
2080
|
+
})
|
|
2081
|
+
)?.abs().mul(direction).toNumber();
|
|
2082
|
+
}
|
|
2083
|
+
if (sl_trigger_price) {
|
|
2084
|
+
const direction = orderlyUtils.getTPSLDirection({
|
|
2085
|
+
side,
|
|
2086
|
+
type: "sl",
|
|
2087
|
+
closePrice: sl_trigger_price,
|
|
2088
|
+
orderPrice: openPrice
|
|
2089
|
+
});
|
|
2090
|
+
sl_unrealPnl = orderlyUtils.formatNum.pnl(
|
|
2091
|
+
orderlyPerp.positions.unrealizedPnL({
|
|
2092
|
+
qty,
|
|
2093
|
+
openPrice,
|
|
2094
|
+
// markPrice: unRealizedPrice,
|
|
2095
|
+
markPrice: sl_trigger_price
|
|
2096
|
+
})
|
|
2097
|
+
)?.abs().mul(direction).toNumber();
|
|
2098
|
+
}
|
|
2099
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2100
|
+
orderlyUi.Flex,
|
|
2101
|
+
{
|
|
2102
|
+
gap: 2,
|
|
2103
|
+
direction: "column",
|
|
2104
|
+
justify: "between",
|
|
2105
|
+
itemAlign: "start",
|
|
2106
|
+
className: "oui-text-2xs",
|
|
2107
|
+
children: [
|
|
2108
|
+
tp_unrealPnl && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: 2, rm: orderlyUtils.Decimal.ROUND_DOWN, coloring: true, padding: false, children: tp_unrealPnl }) }),
|
|
2109
|
+
sl_unrealPnl && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: 2, rm: orderlyUtils.Decimal.ROUND_DOWN, coloring: true, padding: false, children: sl_unrealPnl }) })
|
|
2110
|
+
]
|
|
2111
|
+
}
|
|
2112
|
+
);
|
|
2113
|
+
};
|
|
2114
|
+
var OrderPriceRender = ({ order: order2 }) => {
|
|
2115
|
+
const { quote_dp } = useTPSLDetailContext();
|
|
2116
|
+
const { tp_order_price, sl_order_price } = orderlyHooks.findTPSLOrderPriceFromOrder(order2);
|
|
2117
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2118
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2119
|
+
orderlyUi.Flex,
|
|
2120
|
+
{
|
|
2121
|
+
gap: 2,
|
|
2122
|
+
direction: "column",
|
|
2123
|
+
justify: "between",
|
|
2124
|
+
itemAlign: "start",
|
|
2125
|
+
className: "oui-text-2xs",
|
|
2126
|
+
children: [
|
|
2127
|
+
tp_order_price && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: tp_order_price === orderlyTypes.OrderType.MARKET ? /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("common.market") }) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: quote_dp, rm: orderlyUtils.Decimal.ROUND_DOWN, padding: false, children: tp_order_price }) }),
|
|
2128
|
+
sl_order_price && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: sl_order_price === orderlyTypes.OrderType.MARKET ? /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("common.market") }) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: quote_dp, rm: orderlyUtils.Decimal.ROUND_DOWN, padding: false, children: sl_order_price }) })
|
|
2129
|
+
]
|
|
2130
|
+
}
|
|
2131
|
+
);
|
|
2132
|
+
};
|
|
2133
|
+
var QtyRender = ({ order: order2 }) => {
|
|
2134
|
+
const { position, base_dp } = useTPSLDetailContext();
|
|
2135
|
+
const { tp_trigger_price, sl_trigger_price } = orderlyHooks.findTPSLFromOrder(order2);
|
|
2136
|
+
const quantity = react.useMemo(() => {
|
|
2137
|
+
if (order2.quantity === 0) {
|
|
2138
|
+
return -position.position_qty;
|
|
2139
|
+
}
|
|
2140
|
+
return position.position_qty > 0 ? -order2.quantity : order2.quantity;
|
|
2141
|
+
}, [order2.quantity, position.position_qty]);
|
|
2142
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2143
|
+
orderlyUi.Flex,
|
|
2144
|
+
{
|
|
2145
|
+
direction: "column",
|
|
2146
|
+
justify: "start",
|
|
2147
|
+
itemAlign: "start",
|
|
2148
|
+
className: "oui-h-full oui-text-2xs",
|
|
2149
|
+
children: [
|
|
2150
|
+
/* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: base_dp, rm: orderlyUtils.Decimal.ROUND_DOWN, padding: false, children: quantity }) }),
|
|
2151
|
+
tp_trigger_price && sl_trigger_price && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsx("div", {}) })
|
|
2152
|
+
]
|
|
2153
|
+
}
|
|
2154
|
+
);
|
|
2155
|
+
};
|
|
2156
|
+
var TriggerPrice = ({ order: order2 }) => {
|
|
2157
|
+
const { quote_dp } = useTPSLDetailContext();
|
|
2158
|
+
const { tp_trigger_price, sl_trigger_price } = orderlyHooks.findTPSLFromOrder(order2);
|
|
2159
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2160
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2161
|
+
orderlyUi.Flex,
|
|
2162
|
+
{
|
|
2163
|
+
gap: 1,
|
|
2164
|
+
direction: "column",
|
|
2165
|
+
justify: "between",
|
|
2166
|
+
itemAlign: "start",
|
|
2167
|
+
className: "oui-text-2xs",
|
|
2168
|
+
children: [
|
|
2169
|
+
tp_trigger_price && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { direction: "column", justify: "start", itemAlign: "start", children: [
|
|
2170
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36", children: t("common.market") }),
|
|
2171
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: quote_dp, rm: orderlyUtils.Decimal.ROUND_DOWN, padding: false, children: tp_trigger_price })
|
|
2172
|
+
] }) }),
|
|
2173
|
+
sl_trigger_price && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { direction: "column", justify: "start", itemAlign: "start", children: [
|
|
2174
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36", children: t("common.market") }),
|
|
2175
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text.numeral, { dp: quote_dp, rm: orderlyUtils.Decimal.ROUND_DOWN, padding: false, children: sl_trigger_price })
|
|
2176
|
+
] }) })
|
|
2177
|
+
]
|
|
2178
|
+
}
|
|
2179
|
+
);
|
|
2180
|
+
};
|
|
2181
|
+
var CloseToLiqPriceIcon = ({
|
|
2182
|
+
slPriceError,
|
|
2183
|
+
className
|
|
2184
|
+
}) => {
|
|
2185
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2186
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
2187
|
+
const { getErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(slPriceError);
|
|
2188
|
+
const isSlPriceWarning = slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
2189
|
+
const icon = /* @__PURE__ */ jsxRuntime.jsx(
|
|
2190
|
+
orderlyUi.ExclamationFillIcon,
|
|
2191
|
+
{
|
|
2192
|
+
onMouseEnter: (e) => e.stopPropagation(),
|
|
2193
|
+
onMouseLeave: (e) => e.stopPropagation(),
|
|
2194
|
+
onPointerEnter: (e) => e.stopPropagation(),
|
|
2195
|
+
onPointerLeave: (e) => e.stopPropagation(),
|
|
2196
|
+
size: 14,
|
|
2197
|
+
className: orderlyUi.cn(
|
|
2198
|
+
"oui-text-warning-darken hover:oui-cursor-pointer",
|
|
2199
|
+
className
|
|
2200
|
+
)
|
|
2201
|
+
}
|
|
2202
|
+
);
|
|
2203
|
+
if (!isSlPriceWarning || !slPriceError)
|
|
2204
|
+
return null;
|
|
2205
|
+
if (isMobile) {
|
|
2206
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2207
|
+
"button",
|
|
2208
|
+
{
|
|
2209
|
+
onClick: (e) => {
|
|
2210
|
+
orderlyUi.modal.alert({
|
|
2211
|
+
title: t("common.tips"),
|
|
2212
|
+
message: getErrorMsg("sl_trigger_price")
|
|
2213
|
+
});
|
|
2214
|
+
},
|
|
2215
|
+
className: "oui-px-1",
|
|
2216
|
+
children: icon
|
|
2217
|
+
}
|
|
2218
|
+
);
|
|
2219
|
+
}
|
|
2220
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2221
|
+
orderlyUi.Tooltip,
|
|
2222
|
+
{
|
|
2223
|
+
content: getErrorMsg("sl_trigger_price"),
|
|
2224
|
+
className: "oui-max-w-[240px] oui-text-base-contrast-80",
|
|
2225
|
+
children: icon
|
|
2226
|
+
}
|
|
2227
|
+
);
|
|
2228
|
+
};
|
|
2229
|
+
CloseToLiqPriceIcon.displayName = "CloseToLiqPriceIcon";
|
|
2230
|
+
var TypeRender = ({ order: order2 }) => {
|
|
2231
|
+
const { side, estLiqPrice } = useTPSLDetailContext();
|
|
2232
|
+
const { tp_trigger_price, sl_trigger_price } = orderlyHooks.findTPSLFromOrder(order2);
|
|
2233
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2234
|
+
const slPriceError = orderlyHooks.useTpslPriceChecker({
|
|
2235
|
+
slPrice: sl_trigger_price?.toString() ?? void 0,
|
|
2236
|
+
liqPrice: estLiqPrice ?? null,
|
|
2237
|
+
side
|
|
2238
|
+
});
|
|
2239
|
+
const isSlPriceWarning = slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
2240
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2241
|
+
orderlyUi.Flex,
|
|
2242
|
+
{
|
|
2243
|
+
direction: "column",
|
|
2244
|
+
justify: "between",
|
|
2245
|
+
itemAlign: "start",
|
|
2246
|
+
className: "oui-text-2xs",
|
|
2247
|
+
children: [
|
|
2248
|
+
tp_trigger_price && /* @__PURE__ */ jsxRuntime.jsx(FlexCell, { children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-trade-profit", children: t("tpsl.tp") }) }),
|
|
2249
|
+
sl_trigger_price && /* @__PURE__ */ jsxRuntime.jsxs(FlexCell, { className: "oui-flex-row oui-items-center oui-gap-1", children: [
|
|
2250
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-trade-loss", children: t("tpsl.sl") }),
|
|
2251
|
+
isSlPriceWarning && /* @__PURE__ */ jsxRuntime.jsx(CloseToLiqPriceIcon, { slPriceError })
|
|
2252
|
+
] })
|
|
2253
|
+
]
|
|
2254
|
+
}
|
|
2255
|
+
);
|
|
2256
|
+
};
|
|
2257
|
+
var useColumn = (props) => {
|
|
2258
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2259
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
2260
|
+
const { onCancelOrder } = props;
|
|
2261
|
+
const columns = react.useMemo(() => {
|
|
2262
|
+
const moblieColumns = [
|
|
2263
|
+
{
|
|
2264
|
+
title: t("tpsl.tpslDetail.qty"),
|
|
2265
|
+
dataIndex: "quantity",
|
|
2266
|
+
width: 70,
|
|
2267
|
+
className: "oui-py-2",
|
|
2268
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(QtyRender, { order: record })
|
|
2269
|
+
},
|
|
2270
|
+
{
|
|
2271
|
+
title: t("common.type"),
|
|
2272
|
+
dataIndex: "type",
|
|
2273
|
+
width: 35,
|
|
2274
|
+
className: "oui-pl-1 oui-py-2",
|
|
2275
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(TypeRender, { order: record })
|
|
2276
|
+
},
|
|
2277
|
+
{
|
|
2278
|
+
title: t("common.trigger"),
|
|
2279
|
+
dataIndex: "trigger",
|
|
2280
|
+
width: 70,
|
|
2281
|
+
className: "oui-pl-1 oui-py-2",
|
|
2282
|
+
render: (_, record) => {
|
|
2283
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TriggerPrice, { order: record });
|
|
2284
|
+
}
|
|
2285
|
+
},
|
|
2286
|
+
{
|
|
2287
|
+
title: t("common.price"),
|
|
2288
|
+
dataIndex: "price",
|
|
2289
|
+
width: 70,
|
|
2290
|
+
className: "oui-py-2",
|
|
2291
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(OrderPriceRender, { order: record })
|
|
2292
|
+
},
|
|
2293
|
+
{
|
|
2294
|
+
title: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2295
|
+
orderlyUi.Tooltip,
|
|
2296
|
+
{
|
|
2297
|
+
className: "oui-max-w-[280px] oui-bg-base-8 oui-p-3 oui-text-2xs oui-text-base-contrast",
|
|
2298
|
+
content: t("tpsl.tpslDetail.estPnl.tooltip"),
|
|
2299
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-underline oui-decoration-dashed oui-underline-offset-2", children: t("tpsl.tpslDetail.estPnl") })
|
|
2300
|
+
}
|
|
2301
|
+
),
|
|
2302
|
+
dataIndex: "estpnl",
|
|
2303
|
+
width: 70,
|
|
2304
|
+
className: "!oui-pr-0 oui-py-2",
|
|
2305
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(EstPnlRender, { order: record })
|
|
2306
|
+
}
|
|
2307
|
+
];
|
|
2308
|
+
const desktopColums = [
|
|
2309
|
+
{
|
|
2310
|
+
title: t("tpsl.tpslDetail.qty"),
|
|
2311
|
+
dataIndex: "quantity",
|
|
2312
|
+
width: 70,
|
|
2313
|
+
className: orderlyUi.cn(" oui-py-2 !oui-pl-5"),
|
|
2314
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(QtyRender, { order: record })
|
|
2315
|
+
},
|
|
2316
|
+
{
|
|
2317
|
+
title: t("common.type"),
|
|
2318
|
+
dataIndex: "type",
|
|
2319
|
+
width: 35,
|
|
2320
|
+
className: "oui-pl-1 oui-py-2",
|
|
2321
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(TypeRender, { order: record })
|
|
2322
|
+
},
|
|
2323
|
+
{
|
|
2324
|
+
title: t("common.trigger"),
|
|
2325
|
+
dataIndex: "trigger",
|
|
2326
|
+
width: 70,
|
|
2327
|
+
className: "oui-pl-1 oui-py-2",
|
|
2328
|
+
render: (_, record) => {
|
|
2329
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TriggerPrice, { order: record });
|
|
2330
|
+
}
|
|
2331
|
+
},
|
|
2332
|
+
{
|
|
2333
|
+
title: t("common.price"),
|
|
2334
|
+
dataIndex: "price",
|
|
2335
|
+
width: 70,
|
|
2336
|
+
className: "oui-pl-1 oui-py-2",
|
|
2337
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(OrderPriceRender, { order: record })
|
|
2338
|
+
},
|
|
2339
|
+
{
|
|
2340
|
+
title: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2341
|
+
orderlyUi.Tooltip,
|
|
2342
|
+
{
|
|
2343
|
+
className: "oui-max-w-[280px] oui-bg-base-8 oui-p-3 oui-text-2xs oui-text-base-contrast",
|
|
2344
|
+
content: t("tpsl.tpslDetail.estPnl.tooltip"),
|
|
2345
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-underline oui-decoration-dashed oui-underline-offset-2", children: t("tpsl.tpslDetail.estPnl") })
|
|
2346
|
+
}
|
|
2347
|
+
),
|
|
2348
|
+
dataIndex: "estpnl",
|
|
2349
|
+
width: 70,
|
|
2350
|
+
className: "oui-pl-1 oui-py-2",
|
|
2351
|
+
render: (_, record) => /* @__PURE__ */ jsxRuntime.jsx(EstPnlRender, { order: record })
|
|
2352
|
+
},
|
|
2353
|
+
{
|
|
2354
|
+
title: "",
|
|
2355
|
+
dataIndex: "delete",
|
|
2356
|
+
width: 50,
|
|
2357
|
+
className: orderlyUi.cn("oui-py-2 !oui-pr-5"),
|
|
2358
|
+
render: (_, record) => {
|
|
2359
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CancelAllBtn, { order: record, onCancelOrder });
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
];
|
|
2363
|
+
if (isMobile) {
|
|
2364
|
+
return moblieColumns;
|
|
2365
|
+
}
|
|
2366
|
+
return desktopColums;
|
|
2367
|
+
}, [t, isMobile]);
|
|
2368
|
+
return columns;
|
|
2369
|
+
};
|
|
2370
|
+
var DeleteIcon = (props) => {
|
|
2371
|
+
const { size = 18 } = props;
|
|
2372
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2373
|
+
"svg",
|
|
2374
|
+
{
|
|
2375
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2376
|
+
width: size,
|
|
2377
|
+
height: size,
|
|
2378
|
+
viewBox: "0 0 18 18",
|
|
2379
|
+
fill: "currentColor",
|
|
2380
|
+
...props,
|
|
2381
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5.48081 15.375C5.10681 15.375 4.78731 15.2426 4.52231 14.9777C4.25744 14.7127 4.125 14.3932 4.125 14.0192V4.50004H3.375V3.37505H6.75V2.71167H11.25V3.37505H14.625V4.50004H13.875V14.0192C13.875 14.3981 13.7438 14.7188 13.4813 14.9813C13.2188 15.2438 12.8981 15.375 12.5192 15.375H5.48081ZM12.75 4.50004H5.25V14.0192C5.25 14.0866 5.27162 14.1419 5.31487 14.1852C5.35812 14.2284 5.41344 14.25 5.48081 14.25H12.5192C12.5769 14.25 12.6298 14.226 12.6778 14.1779C12.7259 14.1299 12.75 14.077 12.75 14.0192V4.50004ZM7.053 12.75H8.17781V6.00004H7.053V12.75ZM9.82219 12.75H10.947V6.00004H9.82219V12.75Z" })
|
|
2382
|
+
}
|
|
2383
|
+
);
|
|
2384
|
+
};
|
|
2385
|
+
var CancelAllBtn = (props) => {
|
|
2386
|
+
const [loading, setLoading] = react.useState(false);
|
|
2387
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2388
|
+
orderlyUi.ThrottledButton,
|
|
2389
|
+
{
|
|
2390
|
+
size: "sm",
|
|
2391
|
+
loading,
|
|
2392
|
+
variant: "text",
|
|
2393
|
+
color: "gray",
|
|
2394
|
+
onClick: (e) => {
|
|
2395
|
+
e.stopPropagation();
|
|
2396
|
+
setLoading(true);
|
|
2397
|
+
props.onCancelOrder?.(props.order).then(
|
|
2398
|
+
() => {
|
|
2399
|
+
},
|
|
2400
|
+
(error) => {
|
|
2401
|
+
orderlyUi.toast.error(error.message);
|
|
2402
|
+
}
|
|
2403
|
+
).finally(() => {
|
|
2404
|
+
setLoading(false);
|
|
2405
|
+
});
|
|
2406
|
+
},
|
|
2407
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(DeleteIcon, { className: "oui-text-base-contrast-54 hover:oui-text-base-contrast oui-cursor-pointer" })
|
|
2408
|
+
}
|
|
2409
|
+
);
|
|
2410
|
+
};
|
|
2411
|
+
var OrdersTable = (props) => {
|
|
2412
|
+
const { orders } = props;
|
|
2413
|
+
const columns = useColumn({ onCancelOrder: props.onCancelOrder });
|
|
2414
|
+
return (
|
|
2415
|
+
// <ScrollArea className={cn( props.className)}>
|
|
2416
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2417
|
+
orderlyUiConnector.AuthGuardDataTable,
|
|
2418
|
+
{
|
|
2419
|
+
columns,
|
|
2420
|
+
dataSource: orders,
|
|
2421
|
+
className: "oui-bg-transparent oui-text-2xs",
|
|
2422
|
+
bordered: true,
|
|
2423
|
+
classNames: {
|
|
2424
|
+
root: orderlyUi.cn(props.className),
|
|
2425
|
+
header: "!oui-bg-base-8",
|
|
2426
|
+
scroll: orderlyUi.cn(
|
|
2427
|
+
!orders || orders.length === 0 ? "!oui-min-h-[170px]" : "!oui-min-h-[100px]"
|
|
2428
|
+
)
|
|
2429
|
+
},
|
|
2430
|
+
onRow: (record) => {
|
|
2431
|
+
return {
|
|
2432
|
+
className: orderlyUi.cn(
|
|
2433
|
+
"oui-h-[53px] oui-cursor-svg-edit !oui-border-none !oui-p-0"
|
|
2434
|
+
),
|
|
2435
|
+
onClick: () => {
|
|
2436
|
+
props.editTPSLOrder(record);
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
)
|
|
2442
|
+
);
|
|
2443
|
+
};
|
|
2444
|
+
var OrdersTableMobile = (props) => {
|
|
2445
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2446
|
+
const { orders } = props;
|
|
2447
|
+
const columns = useColumn({ onCancelOrder: () => Promise.resolve() });
|
|
2448
|
+
const orderIds = react.useMemo(() => {
|
|
2449
|
+
return orders.reduce(
|
|
2450
|
+
(acc, curr) => {
|
|
2451
|
+
acc[curr.algo_order_id] = true;
|
|
2452
|
+
return acc;
|
|
2453
|
+
},
|
|
2454
|
+
{}
|
|
2455
|
+
);
|
|
2456
|
+
}, [orders]);
|
|
2457
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2458
|
+
orderlyUiConnector.AuthGuardDataTable,
|
|
2459
|
+
{
|
|
2460
|
+
columns,
|
|
2461
|
+
dataSource: orders,
|
|
2462
|
+
expanded: orderIds,
|
|
2463
|
+
bordered: true,
|
|
2464
|
+
getRowCanExpand: () => true,
|
|
2465
|
+
expandRowRender: (row) => {
|
|
2466
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 2, justify: "end", children: [
|
|
2467
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2468
|
+
orderlyUi.Button,
|
|
2469
|
+
{
|
|
2470
|
+
variant: "outlined",
|
|
2471
|
+
size: "sm",
|
|
2472
|
+
color: "gray",
|
|
2473
|
+
className: "oui-h-6 oui-text-2xs oui-text-base-contrast-54",
|
|
2474
|
+
onClick: () => props.editTPSLOrder(row.original),
|
|
2475
|
+
children: t("common.edit")
|
|
2476
|
+
}
|
|
2477
|
+
),
|
|
2478
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2479
|
+
DeleteBtn,
|
|
2480
|
+
{
|
|
2481
|
+
order: row.original,
|
|
2482
|
+
onCancelOrder: props.canCancelOrder
|
|
2483
|
+
}
|
|
2484
|
+
)
|
|
2485
|
+
] });
|
|
2486
|
+
},
|
|
2487
|
+
className: "oui-bg-transparent oui-px-2 oui-text-2xs",
|
|
2488
|
+
classNames: {
|
|
2489
|
+
scroll: orderlyUi.cn(
|
|
2490
|
+
!orders || orders.length === 0 ? "!oui-min-h-[170px]" : "!oui-min-h-[100px]"
|
|
2491
|
+
)
|
|
2492
|
+
},
|
|
2493
|
+
onRow: () => {
|
|
2494
|
+
return {
|
|
2495
|
+
className: orderlyUi.cn(
|
|
2496
|
+
"oui-h-[53px] oui-cursor-svg-edit !oui-border-none !oui-p-0"
|
|
2497
|
+
)
|
|
2498
|
+
};
|
|
2499
|
+
},
|
|
2500
|
+
generatedRowKey: (record) => record.algo_order_id
|
|
2501
|
+
}
|
|
2502
|
+
);
|
|
2503
|
+
};
|
|
2504
|
+
var DeleteBtn = (props) => {
|
|
2505
|
+
const [loading, setLoading] = react.useState(false);
|
|
2506
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2507
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2508
|
+
orderlyUi.ThrottledButton,
|
|
2509
|
+
{
|
|
2510
|
+
className: "oui-h-6 oui-text-2xs oui-text-base-contrast-54",
|
|
2511
|
+
size: "sm",
|
|
2512
|
+
loading,
|
|
2513
|
+
variant: "outlined",
|
|
2514
|
+
color: "gray",
|
|
2515
|
+
onClick: (e) => {
|
|
2516
|
+
e.stopPropagation();
|
|
2517
|
+
setLoading(true);
|
|
2518
|
+
props.onCancelOrder?.(props.order).then(
|
|
2519
|
+
() => {
|
|
2520
|
+
},
|
|
2521
|
+
(error) => {
|
|
2522
|
+
orderlyUi.toast.error(error.message);
|
|
2523
|
+
}
|
|
2524
|
+
).finally(() => {
|
|
2525
|
+
setLoading(false);
|
|
2526
|
+
});
|
|
2527
|
+
},
|
|
2528
|
+
children: t("common.delete")
|
|
2529
|
+
}
|
|
2530
|
+
);
|
|
2531
|
+
};
|
|
2532
|
+
var TPSLDetailUI = (props) => {
|
|
2533
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
2534
|
+
const {
|
|
2535
|
+
position,
|
|
2536
|
+
fullPositionOrders,
|
|
2537
|
+
partialPositionOrders,
|
|
2538
|
+
onCancelOrder,
|
|
2539
|
+
onCancelAllTPSLOrders,
|
|
2540
|
+
editTPSLOrder,
|
|
2541
|
+
addTPSLOrder,
|
|
2542
|
+
symbolInfo
|
|
2543
|
+
} = props;
|
|
2544
|
+
const { estLiqPrice } = useTPSLDetailContext();
|
|
2545
|
+
return /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Box, { children: /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.ScrollArea, { className: orderlyUi.cn(isMobile && "oui-h-[calc(100vh-100px)]"), children: [
|
|
2546
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2547
|
+
OrderInfo,
|
|
2548
|
+
{
|
|
2549
|
+
order: {
|
|
2550
|
+
symbol: position.symbol,
|
|
2551
|
+
order_quantity: position.position_qty.toString(),
|
|
2552
|
+
order_price: position.average_open_price.toString()
|
|
2553
|
+
},
|
|
2554
|
+
estLiqPrice,
|
|
2555
|
+
symbolLeverage: position.leverage,
|
|
2556
|
+
baseDP: symbolInfo("base_dp"),
|
|
2557
|
+
quoteDP: symbolInfo("quote_dp"),
|
|
2558
|
+
classNames: {
|
|
2559
|
+
root: orderlyUi.cn("oui-mb-6 oui-gap-3 oui-px-5"),
|
|
2560
|
+
container: "oui-gap-x-[30px]"
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
),
|
|
2564
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2565
|
+
FullPositionPart,
|
|
2566
|
+
{
|
|
2567
|
+
position,
|
|
2568
|
+
orders: fullPositionOrders,
|
|
2569
|
+
onCancelOrder,
|
|
2570
|
+
onCancelAllTPSLOrders,
|
|
2571
|
+
editTPSLOrder,
|
|
2572
|
+
addTPSLOrder
|
|
2573
|
+
}
|
|
2574
|
+
),
|
|
2575
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2576
|
+
PartialPositionPart,
|
|
2577
|
+
{
|
|
2578
|
+
position,
|
|
2579
|
+
orders: partialPositionOrders,
|
|
2580
|
+
onCancelOrder,
|
|
2581
|
+
onCancelAllTPSLOrders,
|
|
2582
|
+
editTPSLOrder,
|
|
2583
|
+
addTPSLOrder
|
|
2584
|
+
}
|
|
2585
|
+
)
|
|
2586
|
+
] }) });
|
|
2587
|
+
};
|
|
2588
|
+
var FullPositionPart = (props) => {
|
|
2589
|
+
const [open, setOpen] = react.useState(true);
|
|
2590
|
+
const { orders } = props;
|
|
2591
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
2592
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Box, { className: "oui-mt-6", children: [
|
|
2593
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2594
|
+
orderlyUi.Box,
|
|
2595
|
+
{
|
|
2596
|
+
className: orderlyUi.cn("oui-flex oui-items-center oui-justify-between oui-px-5"),
|
|
2597
|
+
children: [
|
|
2598
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2599
|
+
PositionTypeDescription,
|
|
2600
|
+
{
|
|
2601
|
+
positionType: orderlyTypes.PositionType.FULL,
|
|
2602
|
+
open,
|
|
2603
|
+
onOpenChange: setOpen
|
|
2604
|
+
}
|
|
2605
|
+
),
|
|
2606
|
+
orders && orders.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Flex, { gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2607
|
+
AddButton,
|
|
2608
|
+
{
|
|
2609
|
+
positionType: orderlyTypes.PositionType.FULL,
|
|
2610
|
+
position: props.position,
|
|
2611
|
+
addTPSLOrder: props.addTPSLOrder
|
|
2612
|
+
}
|
|
2613
|
+
) })
|
|
2614
|
+
]
|
|
2615
|
+
}
|
|
2616
|
+
),
|
|
2617
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2618
|
+
orderlyUi.Box,
|
|
2619
|
+
{
|
|
2620
|
+
className: orderlyUi.cn(
|
|
2621
|
+
"oui-overflow-hidden oui-transition-[height] oui-duration-150",
|
|
2622
|
+
open ? "oui-h-auto" : "oui-h-0 oui-pb-4"
|
|
2623
|
+
),
|
|
2624
|
+
children: isMobile ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2625
|
+
OrdersTableMobile,
|
|
2626
|
+
{
|
|
2627
|
+
orders,
|
|
2628
|
+
editTPSLOrder: (order2) => props.editTPSLOrder(order2, orderlyTypes.PositionType.FULL),
|
|
2629
|
+
canCancelOrder: props.onCancelOrder
|
|
2630
|
+
}
|
|
2631
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2632
|
+
OrdersTable,
|
|
2633
|
+
{
|
|
2634
|
+
orders,
|
|
2635
|
+
editTPSLOrder: (order2) => {
|
|
2636
|
+
props.editTPSLOrder(order2, orderlyTypes.PositionType.FULL);
|
|
2637
|
+
},
|
|
2638
|
+
onCancelOrder: props.onCancelOrder
|
|
2639
|
+
}
|
|
2640
|
+
)
|
|
2641
|
+
}
|
|
2642
|
+
)
|
|
2643
|
+
] });
|
|
2644
|
+
};
|
|
2645
|
+
var PartialPositionPart = (props) => {
|
|
2646
|
+
const [open, setOpen] = react.useState(true);
|
|
2647
|
+
const { orders } = props;
|
|
2648
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
2649
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Box, { className: "oui-pt-6", children: [
|
|
2650
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2651
|
+
orderlyUi.Box,
|
|
2652
|
+
{
|
|
2653
|
+
className: orderlyUi.cn(
|
|
2654
|
+
"oui-flex oui-items-center oui-justify-between",
|
|
2655
|
+
"oui-px-5",
|
|
2656
|
+
isMobile ? "oui-flex-col oui-items-start oui-justify-start oui-gap-[11px]" : "oui-flex-row oui-items-center oui-justify-between"
|
|
2657
|
+
),
|
|
2658
|
+
children: [
|
|
2659
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2660
|
+
PositionTypeDescription,
|
|
2661
|
+
{
|
|
2662
|
+
positionType: orderlyTypes.PositionType.PARTIAL,
|
|
2663
|
+
open,
|
|
2664
|
+
onOpenChange: setOpen
|
|
2665
|
+
}
|
|
2666
|
+
),
|
|
2667
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { gap: 2, children: [
|
|
2668
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2669
|
+
AddButton,
|
|
2670
|
+
{
|
|
2671
|
+
positionType: orderlyTypes.PositionType.PARTIAL,
|
|
2672
|
+
position: props.position,
|
|
2673
|
+
addTPSLOrder: props.addTPSLOrder
|
|
2674
|
+
}
|
|
2675
|
+
),
|
|
2676
|
+
orders && orders.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2677
|
+
CancelAllBtn2,
|
|
2678
|
+
{
|
|
2679
|
+
canCancelAll: orders && orders.length > 0,
|
|
2680
|
+
onCancelAllTPSLOrders: props.onCancelAllTPSLOrders
|
|
2681
|
+
}
|
|
2682
|
+
)
|
|
2683
|
+
] })
|
|
2684
|
+
]
|
|
2685
|
+
}
|
|
2686
|
+
),
|
|
2687
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2688
|
+
orderlyUi.Box,
|
|
2689
|
+
{
|
|
2690
|
+
className: orderlyUi.cn(
|
|
2691
|
+
"oui-overflow-hidden oui-transition-[height] oui-duration-150",
|
|
2692
|
+
open ? "oui-h-auto" : "oui-h-0 oui-pb-4"
|
|
2693
|
+
),
|
|
2694
|
+
children: isMobile ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2695
|
+
OrdersTableMobile,
|
|
2696
|
+
{
|
|
2697
|
+
orders,
|
|
2698
|
+
editTPSLOrder: (order2) => props.editTPSLOrder(order2, orderlyTypes.PositionType.PARTIAL),
|
|
2699
|
+
canCancelOrder: props.onCancelOrder
|
|
2700
|
+
}
|
|
2701
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2702
|
+
OrdersTable,
|
|
2703
|
+
{
|
|
2704
|
+
className: "oui-h-[300px]",
|
|
2705
|
+
orders,
|
|
2706
|
+
editTPSLOrder: (order2) => {
|
|
2707
|
+
props.editTPSLOrder(order2, orderlyTypes.PositionType.PARTIAL);
|
|
2708
|
+
},
|
|
2709
|
+
onCancelOrder: props.onCancelOrder
|
|
2710
|
+
}
|
|
2711
|
+
)
|
|
2712
|
+
}
|
|
2713
|
+
)
|
|
2714
|
+
] });
|
|
2715
|
+
};
|
|
2716
|
+
var PositionTypeDescription = (props) => {
|
|
2717
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2718
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2719
|
+
orderlyUi.Flex,
|
|
2720
|
+
{
|
|
2721
|
+
gap: 1,
|
|
2722
|
+
itemAlign: "center",
|
|
2723
|
+
justify: "start",
|
|
2724
|
+
className: "oui-text-2xs",
|
|
2725
|
+
children: [
|
|
2726
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2727
|
+
orderlyUi.Flex,
|
|
2728
|
+
{
|
|
2729
|
+
itemAlign: "center",
|
|
2730
|
+
justify: "start",
|
|
2731
|
+
gap: 1,
|
|
2732
|
+
className: "oui-cursor-pointer",
|
|
2733
|
+
onClick: () => props.onOpenChange(!props.open),
|
|
2734
|
+
children: [
|
|
2735
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2736
|
+
orderlyUi.ChevronDownIcon,
|
|
2737
|
+
{
|
|
2738
|
+
size: 12,
|
|
2739
|
+
color: "white",
|
|
2740
|
+
className: orderlyUi.cn(
|
|
2741
|
+
"oui-cursor-pointer oui-transition-transform",
|
|
2742
|
+
props.open && "oui-rotate-180"
|
|
2743
|
+
)
|
|
2744
|
+
}
|
|
2745
|
+
),
|
|
2746
|
+
props.positionType === orderlyTypes.PositionType.FULL ? /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.positionType.full") }) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { children: t("tpsl.positionType.partial") })
|
|
2747
|
+
]
|
|
2748
|
+
}
|
|
2749
|
+
),
|
|
2750
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2751
|
+
orderlyUi.Tooltip,
|
|
2752
|
+
{
|
|
2753
|
+
className: "oui-w-[280px] oui-p-3",
|
|
2754
|
+
content: props.positionType === orderlyTypes.PositionType.FULL ? t("tpsl.positionType.full.tips") : t("tpsl.positionType.partial.tips"),
|
|
2755
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2756
|
+
orderlyUi.ExclamationFillIcon,
|
|
2757
|
+
{
|
|
2758
|
+
className: "oui-cursor-pointer oui-text-base-contrast-54",
|
|
2759
|
+
size: 12
|
|
2760
|
+
}
|
|
2761
|
+
)
|
|
2762
|
+
}
|
|
2763
|
+
)
|
|
2764
|
+
]
|
|
2765
|
+
}
|
|
2766
|
+
);
|
|
2767
|
+
};
|
|
2768
|
+
var AddButton = (props) => {
|
|
2769
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2770
|
+
const onAdd = () => {
|
|
2771
|
+
props.addTPSLOrder(props.positionType);
|
|
2772
|
+
};
|
|
2773
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2774
|
+
orderlyUi.ThrottledButton,
|
|
2775
|
+
{
|
|
2776
|
+
variant: "outlined",
|
|
2777
|
+
size: "sm",
|
|
2778
|
+
color: "gray",
|
|
2779
|
+
className: "oui-h-6 oui-w-[94px] oui-text-2xs",
|
|
2780
|
+
onClick: onAdd,
|
|
2781
|
+
children: t("tpsl.add")
|
|
2782
|
+
}
|
|
2783
|
+
);
|
|
2784
|
+
};
|
|
2785
|
+
var CancelAllBtn2 = (props) => {
|
|
2786
|
+
const [loading, setLoading] = react.useState(false);
|
|
2787
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2788
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2789
|
+
orderlyUi.ThrottledButton,
|
|
2790
|
+
{
|
|
2791
|
+
loading,
|
|
2792
|
+
variant: "outlined",
|
|
2793
|
+
disabled: !props.canCancelAll,
|
|
2794
|
+
size: "sm",
|
|
2795
|
+
color: "gray",
|
|
2796
|
+
className: "oui-h-6 oui-w-[94px] oui-text-2xs disabled:oui-border-base-contrast-16 disabled:oui-bg-transparent disabled:oui-text-base-contrast-20",
|
|
2797
|
+
onClick: () => {
|
|
2798
|
+
setLoading(true);
|
|
2799
|
+
props.onCancelAllTPSLOrders().then(
|
|
2800
|
+
() => {
|
|
2801
|
+
},
|
|
2802
|
+
(error) => {
|
|
2803
|
+
orderlyUi.toast.error(error.message);
|
|
2804
|
+
}
|
|
2805
|
+
).finally(() => {
|
|
2806
|
+
setLoading(false);
|
|
2807
|
+
});
|
|
2808
|
+
},
|
|
2809
|
+
children: t("tpsl.cancelAll")
|
|
2810
|
+
}
|
|
2811
|
+
);
|
|
2812
|
+
};
|
|
2813
|
+
var TPSLDetailWidget = (props) => {
|
|
2814
|
+
const state = useTPSLDetail(props);
|
|
2815
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2816
|
+
TPSLDetailProvider,
|
|
2817
|
+
{
|
|
2818
|
+
symbol: props.position.symbol,
|
|
2819
|
+
position: props.position,
|
|
2820
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(TPSLDetailUI, { ...state })
|
|
2821
|
+
}
|
|
2822
|
+
);
|
|
2823
|
+
};
|
|
2824
|
+
var TPSLDetailDialogId = "TPSLDetailDialogId ";
|
|
2825
|
+
var TPSLDetailSheetId = "TPSLDetailSheetId";
|
|
2826
|
+
orderlyUi.registerSimpleDialog(TPSLDetailDialogId, TPSLDetailWidget, {
|
|
2827
|
+
classNames: {
|
|
2828
|
+
content: "oui-w-[420px] lg:oui-pt-4 lg:oui-pb-2 !oui-px-0",
|
|
2829
|
+
body: "lg:oui-py-0"
|
|
2830
|
+
}
|
|
2831
|
+
});
|
|
2832
|
+
orderlyUi.registerSimpleSheet(TPSLDetailSheetId, TPSLDetailWidget, {
|
|
2833
|
+
classNames: {
|
|
2834
|
+
content: "!oui-p-0"
|
|
2835
|
+
}
|
|
2836
|
+
});
|
|
2837
|
+
var useTPSLSimpleDialog = (options) => {
|
|
2838
|
+
const { type, triggerPrice, symbol } = options;
|
|
2839
|
+
const symbolInfo = orderlyHooks.useSymbolsInfo();
|
|
2840
|
+
const [{ rows: positions }, positionsInfo] = orderlyHooks.usePositionStream(symbol);
|
|
2841
|
+
const position = positions?.[0];
|
|
2842
|
+
react.useRef(orderlyTypes.AlgoOrderRootType.TP_SL);
|
|
2843
|
+
const [needConfirm] = orderlyHooks.useLocalStorage("orderly_order_confirm", true);
|
|
2844
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2845
|
+
const [
|
|
2846
|
+
tpslOrder,
|
|
2847
|
+
{
|
|
2848
|
+
submit,
|
|
2849
|
+
deleteOrder,
|
|
2850
|
+
setValue,
|
|
2851
|
+
setValues,
|
|
2852
|
+
validate,
|
|
2853
|
+
errors,
|
|
2854
|
+
isCreateMutating,
|
|
2855
|
+
isUpdateMutating
|
|
2856
|
+
}
|
|
2857
|
+
] = orderlyHooks.useTPSLOrder(
|
|
2858
|
+
{
|
|
2859
|
+
symbol,
|
|
2860
|
+
position_qty: position?.position_qty,
|
|
2861
|
+
average_open_price: position?.average_open_price
|
|
2862
|
+
},
|
|
2863
|
+
{
|
|
2864
|
+
defaultOrder: void 0,
|
|
2865
|
+
positionType: orderlyTypes.PositionType.PARTIAL,
|
|
2866
|
+
// tpslEnable: { tp_enable: type === "tp", sl_enable: type === "sl" },
|
|
2867
|
+
isEditing: false
|
|
2868
|
+
}
|
|
2869
|
+
);
|
|
2870
|
+
const setQuantity = (value) => {
|
|
2871
|
+
setValue("quantity", value);
|
|
2872
|
+
};
|
|
2873
|
+
const setOrderPrice = (name, value) => {
|
|
2874
|
+
setValue(name, value);
|
|
2875
|
+
};
|
|
2876
|
+
const setPnL = (type2, value) => {
|
|
2877
|
+
setValue(type2, value);
|
|
2878
|
+
};
|
|
2879
|
+
const maxQty = react.useMemo(
|
|
2880
|
+
() => Math.abs(Number(position.position_qty)),
|
|
2881
|
+
[position.position_qty]
|
|
2882
|
+
);
|
|
2883
|
+
react.useEffect(() => {
|
|
2884
|
+
if (!maxQty) {
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
setValue("quantity", maxQty);
|
|
2888
|
+
if (type === "tp") {
|
|
2889
|
+
setValue("tp_trigger_price", triggerPrice ?? "");
|
|
2890
|
+
} else {
|
|
2891
|
+
setValue("sl_trigger_price", triggerPrice ?? "");
|
|
2892
|
+
}
|
|
2893
|
+
}, [type, triggerPrice, maxQty]);
|
|
2894
|
+
const onSubmit = async () => {
|
|
2895
|
+
try {
|
|
2896
|
+
const validOrder = await validate();
|
|
2897
|
+
if (validOrder) {
|
|
2898
|
+
if (!needConfirm) {
|
|
2899
|
+
return submit({ accountId: position.account_id }).then(() => true).catch((err) => {
|
|
2900
|
+
if (err?.message) {
|
|
2901
|
+
orderlyUi.toast.error(err.message);
|
|
2902
|
+
}
|
|
2903
|
+
throw false;
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2906
|
+
return orderlyUi.modal.confirm({
|
|
2907
|
+
title: t("tpsl.confirmOrder"),
|
|
2908
|
+
// bodyClassName: "lg:oui-py-0",
|
|
2909
|
+
onOk: async () => {
|
|
2910
|
+
try {
|
|
2911
|
+
const res = await submit({
|
|
2912
|
+
accountId: position.account_id
|
|
2913
|
+
});
|
|
2914
|
+
if (res.success) {
|
|
2915
|
+
return res;
|
|
2916
|
+
}
|
|
2917
|
+
if (res.message) {
|
|
2918
|
+
orderlyUi.toast.error(res.message);
|
|
2919
|
+
}
|
|
2920
|
+
return false;
|
|
2921
|
+
} catch (err) {
|
|
2922
|
+
if (err?.message) {
|
|
2923
|
+
orderlyUi.toast.error(err.message);
|
|
2924
|
+
}
|
|
2925
|
+
return false;
|
|
2926
|
+
}
|
|
2927
|
+
},
|
|
2928
|
+
classNames: {
|
|
2929
|
+
body: "!oui-pb-0"
|
|
2930
|
+
},
|
|
2931
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2932
|
+
PositionTPSLConfirm,
|
|
2933
|
+
{
|
|
2934
|
+
isPositionTPSL: false,
|
|
2935
|
+
isEditing: false,
|
|
2936
|
+
symbol,
|
|
2937
|
+
qty: Number(tpslOrder.quantity),
|
|
2938
|
+
maxQty,
|
|
2939
|
+
tpPrice: Number(tpslOrder.tp_trigger_price),
|
|
2940
|
+
slPrice: Number(tpslOrder.sl_trigger_price),
|
|
2941
|
+
side: tpslOrder.side,
|
|
2942
|
+
orderInfo: tpslOrder,
|
|
2943
|
+
quoteDP: symbolInfo[symbol]("quote_dp"),
|
|
2944
|
+
baseDP: symbolInfo[symbol]("base_dp")
|
|
2945
|
+
}
|
|
2946
|
+
)
|
|
2947
|
+
}).then(
|
|
2948
|
+
() => {
|
|
2949
|
+
return true;
|
|
2950
|
+
},
|
|
2951
|
+
() => {
|
|
2952
|
+
return Promise.reject(false);
|
|
2953
|
+
}
|
|
2954
|
+
);
|
|
2955
|
+
}
|
|
2956
|
+
} catch (error) {
|
|
2957
|
+
return Promise.reject(error);
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
return {
|
|
2961
|
+
symbolInfo: symbolInfo[symbol],
|
|
2962
|
+
maxQty,
|
|
2963
|
+
setQuantity: orderlyHooks.useMemoizedFn(setQuantity),
|
|
2964
|
+
orderQuantity: tpslOrder.quantity,
|
|
2965
|
+
isPosition: false,
|
|
2966
|
+
TPSL_OrderEntity: tpslOrder,
|
|
2967
|
+
setOrderValue: setValue,
|
|
2968
|
+
setPnL,
|
|
2969
|
+
setOrderPrice,
|
|
2970
|
+
onSubmit,
|
|
2971
|
+
errors,
|
|
2972
|
+
status: {
|
|
2973
|
+
isCreateMutating,
|
|
2974
|
+
isUpdateMutating
|
|
2975
|
+
},
|
|
2976
|
+
position,
|
|
2977
|
+
setValues,
|
|
2978
|
+
type,
|
|
2979
|
+
triggerPrice
|
|
2980
|
+
};
|
|
2981
|
+
};
|
|
2982
|
+
var TPSLSimpleDialogUI = (props) => {
|
|
2983
|
+
const { type, triggerPrice, errors, TPSL_OrderEntity } = props;
|
|
2984
|
+
const { t } = orderlyI18n.useTranslation();
|
|
2985
|
+
const { getErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(errors);
|
|
2986
|
+
const footer = /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { width: "100%", itemAlign: "center", gap: 3, mt: 4, children: [
|
|
2987
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2988
|
+
orderlyUi.Button,
|
|
2989
|
+
{
|
|
2990
|
+
color: "gray",
|
|
2991
|
+
onClick: () => {
|
|
2992
|
+
props.onComplete?.();
|
|
2993
|
+
props.close?.();
|
|
2994
|
+
},
|
|
2995
|
+
fullWidth: true,
|
|
2996
|
+
className: "oui-text-sm",
|
|
2997
|
+
size: "md",
|
|
2998
|
+
children: t("common.cancel")
|
|
2999
|
+
},
|
|
3000
|
+
"secondary"
|
|
3001
|
+
),
|
|
3002
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3003
|
+
orderlyUi.Button,
|
|
3004
|
+
{
|
|
3005
|
+
onClick: () => {
|
|
3006
|
+
props.onSubmit().then(() => {
|
|
3007
|
+
props.onComplete?.();
|
|
3008
|
+
props.close?.();
|
|
3009
|
+
});
|
|
3010
|
+
},
|
|
3011
|
+
fullWidth: true,
|
|
3012
|
+
className: "oui-text-sm",
|
|
3013
|
+
size: "md",
|
|
3014
|
+
children: t("common.confirm")
|
|
3015
|
+
},
|
|
3016
|
+
"primary"
|
|
3017
|
+
)
|
|
3018
|
+
] });
|
|
3019
|
+
const errorMessage = () => {
|
|
3020
|
+
const tpError = getErrorMsg("tp_trigger_price");
|
|
3021
|
+
const slError = getErrorMsg("sl_trigger_price");
|
|
3022
|
+
let text = "";
|
|
3023
|
+
if (tpError && type === "tp") {
|
|
3024
|
+
text = tpError;
|
|
3025
|
+
}
|
|
3026
|
+
if (slError && type === "sl") {
|
|
3027
|
+
text = slError;
|
|
3028
|
+
}
|
|
3029
|
+
if (!text) {
|
|
3030
|
+
return null;
|
|
3031
|
+
}
|
|
3032
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3033
|
+
orderlyUi.Flex,
|
|
3034
|
+
{
|
|
3035
|
+
justify: "start",
|
|
3036
|
+
itemAlign: "start",
|
|
3037
|
+
gap: 2,
|
|
3038
|
+
className: "oui-mt-2 oui-w-full",
|
|
3039
|
+
children: [
|
|
3040
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-relative oui-top-[7px] oui-size-1 oui-rounded-full oui-bg-danger" }),
|
|
3041
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-danger", children: text })
|
|
3042
|
+
]
|
|
3043
|
+
}
|
|
3044
|
+
);
|
|
3045
|
+
};
|
|
3046
|
+
const renderPnl = () => {
|
|
3047
|
+
const { tp_pnl, sl_pnl } = TPSL_OrderEntity;
|
|
3048
|
+
if (type === "sl") {
|
|
3049
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
3050
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("tpsl.totalEstSlPnl") }),
|
|
3051
|
+
sl_pnl ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3052
|
+
orderlyUi.Text.numeral,
|
|
3053
|
+
{
|
|
3054
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-ml-1 oui-text-base-contrast-36", children: "USDC" }),
|
|
3055
|
+
coloring: true,
|
|
3056
|
+
visible: true,
|
|
3057
|
+
size: "2xs",
|
|
3058
|
+
dp: 2,
|
|
3059
|
+
children: Number(sl_pnl)
|
|
3060
|
+
}
|
|
3061
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: "-- USDC" })
|
|
3062
|
+
] });
|
|
3063
|
+
}
|
|
3064
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
3065
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "2xs", children: t("tpsl.totalEstTpPnl") }),
|
|
3066
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3067
|
+
orderlyUi.Text.numeral,
|
|
3068
|
+
{
|
|
3069
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast-36 oui-ml-1", children: "USDC" }),
|
|
3070
|
+
rule: "price",
|
|
3071
|
+
coloring: true,
|
|
3072
|
+
visible: true,
|
|
3073
|
+
size: "2xs",
|
|
3074
|
+
dp: 2,
|
|
3075
|
+
children: tp_pnl ? Number(tp_pnl) : "--"
|
|
3076
|
+
}
|
|
3077
|
+
)
|
|
3078
|
+
] });
|
|
3079
|
+
};
|
|
3080
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Box, { className: "oui-w-full oui-px-0.5", children: [
|
|
3081
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3082
|
+
TPSLQuantity,
|
|
3083
|
+
{
|
|
3084
|
+
maxQty: props.maxQty,
|
|
3085
|
+
quantity: Number(props.orderQuantity ?? props.maxQty),
|
|
3086
|
+
baseTick: props.symbolInfo("base_tick"),
|
|
3087
|
+
base_dp: props.symbolInfo("base_dp"),
|
|
3088
|
+
base: props.symbolInfo("base"),
|
|
3089
|
+
isEditing: false,
|
|
3090
|
+
errorMsg: getErrorMsg("quantity"),
|
|
3091
|
+
onQuantityChange: props.setQuantity
|
|
3092
|
+
}
|
|
3093
|
+
),
|
|
3094
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3095
|
+
orderlyUi.Flex,
|
|
3096
|
+
{
|
|
3097
|
+
direction: "column",
|
|
3098
|
+
itemAlign: "start",
|
|
3099
|
+
className: orderlyUi.cn(
|
|
3100
|
+
"oui-mt-4 oui-w-full oui-gap-1 oui-text-xs oui-text-base-contrast-36"
|
|
3101
|
+
),
|
|
3102
|
+
children: [
|
|
3103
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
3104
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "xs", children: t("common.triggerPrice") }),
|
|
3105
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3106
|
+
orderlyUi.Text.numeral,
|
|
3107
|
+
{
|
|
3108
|
+
className: "oui-text-base-contrast",
|
|
3109
|
+
suffix: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-ml-1 oui-text-xs oui-text-base-contrast-36", children: "USDC" }),
|
|
3110
|
+
rule: "price",
|
|
3111
|
+
size: "xs",
|
|
3112
|
+
dp: props.symbolInfo("quote_dp"),
|
|
3113
|
+
children: triggerPrice ? Number(triggerPrice) : "--"
|
|
3114
|
+
}
|
|
3115
|
+
)
|
|
3116
|
+
] }),
|
|
3117
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { justify: "between", className: "oui-w-full", children: [
|
|
3118
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { size: "xs", children: t("common.orderPrice") }),
|
|
3119
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-base-contrast", size: "xs", children: t("common.market") })
|
|
3120
|
+
] }),
|
|
3121
|
+
renderPnl()
|
|
3122
|
+
]
|
|
3123
|
+
}
|
|
3124
|
+
),
|
|
3125
|
+
errorMessage(),
|
|
3126
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Divider, { className: "oui-my-3 oui-w-full" }),
|
|
3127
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3128
|
+
orderlyUi.Flex,
|
|
3129
|
+
{
|
|
3130
|
+
itemAlign: "center",
|
|
3131
|
+
onClick: () => {
|
|
3132
|
+
props.close?.();
|
|
3133
|
+
props.showAdvancedTPSLDialog?.({
|
|
3134
|
+
qty: Number(TPSL_OrderEntity.quantity)
|
|
3135
|
+
});
|
|
3136
|
+
},
|
|
3137
|
+
className: "oui-pb-4",
|
|
3138
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { color: "primary", className: "oui-cursor-pointer oui-text-sm", children: t("tpsl.advancedSetting") })
|
|
3139
|
+
}
|
|
3140
|
+
),
|
|
3141
|
+
footer
|
|
3142
|
+
] });
|
|
3143
|
+
};
|
|
3144
|
+
var TPSLSimpleDialogWidget = (props) => {
|
|
3145
|
+
const { close, onComplete, showAdvancedTPSLDialog } = props;
|
|
3146
|
+
const state = useTPSLSimpleDialog(props);
|
|
3147
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3148
|
+
TPSLSimpleDialogUI,
|
|
3149
|
+
{
|
|
3150
|
+
...state,
|
|
3151
|
+
close,
|
|
3152
|
+
onComplete,
|
|
3153
|
+
showAdvancedTPSLDialog
|
|
3154
|
+
}
|
|
3155
|
+
);
|
|
3156
|
+
};
|
|
3157
|
+
var TPSLSimpleSheetId = "TPSLSimpleSheetId";
|
|
3158
|
+
var TPSLSimpleDialogId = "TPSLSimpleDialogId";
|
|
3159
|
+
orderlyUi.registerSimpleSheet(TPSLSimpleSheetId, TPSLSimpleDialogWidget, {
|
|
3160
|
+
classNames: {}
|
|
3161
|
+
});
|
|
3162
|
+
orderlyUi.registerSimpleDialog(TPSLSimpleDialogId, TPSLSimpleDialogWidget, {
|
|
3163
|
+
classNames: {
|
|
3164
|
+
content: "oui-w-[420px]"
|
|
3165
|
+
}
|
|
3166
|
+
});
|
|
3167
|
+
function getInitialOrder(order2) {
|
|
3168
|
+
const childOrder = order2.child_orders[0];
|
|
3169
|
+
const positionType = childOrder.algo_type === orderlyTypes.AlgoOrderRootType.TP_SL ? orderlyTypes.PositionType.PARTIAL : orderlyTypes.PositionType.FULL;
|
|
3170
|
+
const tpOrder = childOrder.child_orders.find(
|
|
3171
|
+
(item) => item.algo_type === orderlyTypes.AlgoOrderType.TAKE_PROFIT && item.trigger_price
|
|
3172
|
+
);
|
|
3173
|
+
const slOrder = childOrder.child_orders.find(
|
|
3174
|
+
(item) => item.algo_type === orderlyTypes.AlgoOrderType.STOP_LOSS && item.trigger_price
|
|
3175
|
+
);
|
|
3176
|
+
const tpslPriceInfo = {};
|
|
3177
|
+
if (tpOrder) {
|
|
3178
|
+
tpslPriceInfo.tp_trigger_price = tpOrder.trigger_price?.toString();
|
|
3179
|
+
tpslPriceInfo.tp_order_type = typeof tpOrder.type === "string" ? tpOrder.type.replace("_ORDER", "") : void 0;
|
|
3180
|
+
if (tpslPriceInfo.tp_order_type === orderlyTypes.OrderType.LIMIT) {
|
|
3181
|
+
tpslPriceInfo.tp_order_price = tpOrder.price?.toString();
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
if (slOrder) {
|
|
3185
|
+
tpslPriceInfo.sl_trigger_price = slOrder.trigger_price?.toString();
|
|
3186
|
+
tpslPriceInfo.sl_order_type = typeof slOrder.type === "string" ? slOrder.type.replace("_ORDER", "") : void 0;
|
|
3187
|
+
if (tpslPriceInfo.sl_order_type === orderlyTypes.OrderType.LIMIT) {
|
|
3188
|
+
tpslPriceInfo.sl_order_price = slOrder.price?.toString();
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
return {
|
|
3192
|
+
baseInfo: {
|
|
3193
|
+
symbol: order2.symbol,
|
|
3194
|
+
order_type: order2.type,
|
|
3195
|
+
side: order2.side,
|
|
3196
|
+
order_price: order2.price,
|
|
3197
|
+
order_quantity: order2.quantity,
|
|
3198
|
+
position_type: positionType
|
|
3199
|
+
// tp_enable: !!tpOrder?.trigger_price,
|
|
3200
|
+
// sl_enable: !!slOrder?.trigger_price,
|
|
3201
|
+
},
|
|
3202
|
+
tpslPriceInfo,
|
|
3203
|
+
tpInfo: {
|
|
3204
|
+
orderId: tpOrder?.algo_order_id
|
|
3205
|
+
},
|
|
3206
|
+
slInfo: {
|
|
3207
|
+
orderId: slOrder?.algo_order_id
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
}
|
|
3211
|
+
function isTPSLPriceChanged(originPrice, newPrice) {
|
|
3212
|
+
if (newPrice === void 0 || newPrice === null) {
|
|
3213
|
+
return true;
|
|
3214
|
+
}
|
|
3215
|
+
if (isNaN(Number(newPrice))) {
|
|
3216
|
+
return false;
|
|
3217
|
+
}
|
|
3218
|
+
const originDeci = new orderlyUtils.Decimal(Number(originPrice));
|
|
3219
|
+
const newDeci = new orderlyUtils.Decimal(Number(newPrice));
|
|
3220
|
+
return !newDeci.eq(originDeci);
|
|
3221
|
+
}
|
|
3222
|
+
var useEditBracketOrder = (props) => {
|
|
3223
|
+
if (!props.order) {
|
|
3224
|
+
throw new orderlyTypes.SDKError("order is required for editBracketOrder");
|
|
3225
|
+
}
|
|
3226
|
+
const { baseInfo, tpslPriceInfo, tpInfo, slInfo } = getInitialOrder(
|
|
3227
|
+
props.order
|
|
3228
|
+
);
|
|
3229
|
+
const [doUpdateOrder, { isMutating }] = orderlyHooks.useMutation("/v1/algo/order", "PUT");
|
|
3230
|
+
const maxQty = useEditOrderMaxQty(props.order, props.order.quantity);
|
|
3231
|
+
const {
|
|
3232
|
+
formattedOrder,
|
|
3233
|
+
setValue,
|
|
3234
|
+
setValues,
|
|
3235
|
+
estLiqPrice,
|
|
3236
|
+
metaState,
|
|
3237
|
+
symbolInfo,
|
|
3238
|
+
helper,
|
|
3239
|
+
...state
|
|
3240
|
+
} = orderlyHooks.useOrderEntry(props.order.symbol, {
|
|
3241
|
+
initialOrder: baseInfo,
|
|
3242
|
+
maxQty
|
|
3243
|
+
});
|
|
3244
|
+
const symbol = props.order.symbol;
|
|
3245
|
+
const isPriceChanged = react.useMemo(() => {
|
|
3246
|
+
let dirty = false;
|
|
3247
|
+
const {
|
|
3248
|
+
tp_order_price,
|
|
3249
|
+
sl_order_price,
|
|
3250
|
+
tp_trigger_price,
|
|
3251
|
+
sl_trigger_price
|
|
3252
|
+
} = formattedOrder;
|
|
3253
|
+
if (tpslPriceInfo.tp_trigger_price) {
|
|
3254
|
+
dirty = dirty || isTPSLPriceChanged(
|
|
3255
|
+
tpslPriceInfo.tp_trigger_price,
|
|
3256
|
+
tp_trigger_price ?? 0
|
|
3257
|
+
);
|
|
3258
|
+
}
|
|
3259
|
+
if (tpslPriceInfo.tp_order_price) {
|
|
3260
|
+
dirty = dirty || isTPSLPriceChanged(tpslPriceInfo.tp_order_price, tp_order_price ?? 0);
|
|
3261
|
+
}
|
|
3262
|
+
if (tpslPriceInfo.sl_trigger_price) {
|
|
3263
|
+
dirty = dirty || isTPSLPriceChanged(
|
|
3264
|
+
tpslPriceInfo.sl_trigger_price,
|
|
3265
|
+
sl_trigger_price ?? 0
|
|
3266
|
+
);
|
|
3267
|
+
}
|
|
3268
|
+
if (tpslPriceInfo.sl_order_price) {
|
|
3269
|
+
dirty = dirty || isTPSLPriceChanged(tpslPriceInfo.sl_order_price, sl_order_price ?? 0);
|
|
3270
|
+
}
|
|
3271
|
+
return dirty;
|
|
3272
|
+
}, [
|
|
3273
|
+
tpslPriceInfo,
|
|
3274
|
+
formattedOrder.tp_order_price,
|
|
3275
|
+
formattedOrder.sl_order_price,
|
|
3276
|
+
formattedOrder.tp_trigger_price,
|
|
3277
|
+
formattedOrder.sl_trigger_price
|
|
3278
|
+
]);
|
|
3279
|
+
react.useEffect(() => {
|
|
3280
|
+
setValues({
|
|
3281
|
+
...tpslPriceInfo
|
|
3282
|
+
});
|
|
3283
|
+
}, [props.order, setValues]);
|
|
3284
|
+
const slPriceError = orderlyHooks.useTpslPriceChecker({
|
|
3285
|
+
slPrice: formattedOrder.sl_trigger_price,
|
|
3286
|
+
liqPrice: estLiqPrice,
|
|
3287
|
+
side: formattedOrder.side
|
|
3288
|
+
});
|
|
3289
|
+
const isSlPriceError = slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_ERROR;
|
|
3290
|
+
const onSubmit = async () => {
|
|
3291
|
+
return helper.validate(isSlPriceError ? slPriceError : void 0).then(() => {
|
|
3292
|
+
const tpOrder = {
|
|
3293
|
+
order_id: tpInfo.orderId,
|
|
3294
|
+
algo_type: orderlyTypes.AlgoOrderType.TAKE_PROFIT,
|
|
3295
|
+
trigger_price: formattedOrder.tp_trigger_price,
|
|
3296
|
+
reduce_only: true
|
|
3297
|
+
};
|
|
3298
|
+
if (formattedOrder.tp_order_type === orderlyTypes.OrderType.LIMIT) {
|
|
3299
|
+
tpOrder.price = formattedOrder.tp_order_price;
|
|
3300
|
+
}
|
|
3301
|
+
const slOrder = {
|
|
3302
|
+
order_id: slInfo.orderId,
|
|
3303
|
+
algo_type: orderlyTypes.AlgoOrderType.STOP_LOSS,
|
|
3304
|
+
trigger_price: formattedOrder.sl_trigger_price,
|
|
3305
|
+
reduce_only: true
|
|
3306
|
+
};
|
|
3307
|
+
if (formattedOrder.sl_order_type === orderlyTypes.OrderType.LIMIT) {
|
|
3308
|
+
slOrder.price = formattedOrder.sl_order_price;
|
|
3309
|
+
}
|
|
3310
|
+
const childOrders = [];
|
|
3311
|
+
if (tpInfo.orderId) {
|
|
3312
|
+
childOrders.push(tpOrder);
|
|
3313
|
+
}
|
|
3314
|
+
if (slInfo.orderId) {
|
|
3315
|
+
childOrders.push(slOrder);
|
|
3316
|
+
}
|
|
3317
|
+
return doUpdateOrder({
|
|
3318
|
+
order_id: props.order.algo_order_id,
|
|
3319
|
+
child_orders: [
|
|
3320
|
+
{
|
|
3321
|
+
order_id: props.order.child_orders[0].algo_order_id,
|
|
3322
|
+
child_orders: childOrders
|
|
3323
|
+
}
|
|
3324
|
+
]
|
|
3325
|
+
});
|
|
3326
|
+
});
|
|
3327
|
+
};
|
|
3328
|
+
return {
|
|
3329
|
+
symbol,
|
|
3330
|
+
symbolInfo,
|
|
3331
|
+
slPriceError,
|
|
3332
|
+
estLiqPrice,
|
|
3333
|
+
side: formattedOrder.side,
|
|
3334
|
+
formattedOrder,
|
|
3335
|
+
setValue,
|
|
3336
|
+
setValues,
|
|
3337
|
+
metaState,
|
|
3338
|
+
onSubmit,
|
|
3339
|
+
isMutating,
|
|
3340
|
+
isPriceChanged
|
|
3341
|
+
};
|
|
3342
|
+
};
|
|
3343
|
+
function useEditOrderMaxQty(order2, positionQty) {
|
|
3344
|
+
const { reduce_only } = order2;
|
|
3345
|
+
const maxQty = orderlyHooks.useMaxQty(order2.symbol, order2.side, reduce_only);
|
|
3346
|
+
return react.useMemo(() => {
|
|
3347
|
+
if (reduce_only) {
|
|
3348
|
+
return Math.abs(positionQty ?? 0);
|
|
3349
|
+
}
|
|
3350
|
+
return order2.quantity + Math.abs(maxQty);
|
|
3351
|
+
}, [order2.quantity, maxQty, reduce_only, positionQty]);
|
|
3352
|
+
}
|
|
3353
|
+
var EditBracketOrderUI = (props) => {
|
|
3354
|
+
const { t } = orderlyI18n.useTranslation();
|
|
3355
|
+
const { errors, validated } = props.metaState;
|
|
3356
|
+
const { isMobile } = orderlyUi.useScreen();
|
|
3357
|
+
const isSlPriceWarning = props.slPriceError?.sl_trigger_price?.type === orderlyHooks.ERROR_MSG_CODES.SL_PRICE_WARNING;
|
|
3358
|
+
const { getErrorMsg } = orderlyReactApp.useOrderEntryFormErrorMsg(props.slPriceError);
|
|
3359
|
+
const {
|
|
3360
|
+
formattedOrder,
|
|
3361
|
+
setValue: setOrderValue,
|
|
3362
|
+
symbol,
|
|
3363
|
+
symbolInfo,
|
|
3364
|
+
setValues
|
|
3365
|
+
} = props;
|
|
3366
|
+
const [tpValues, setTpValuse] = react.useState({
|
|
3367
|
+
// enable: false,
|
|
3368
|
+
order_type: formattedOrder.tp_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
3369
|
+
order_price: formattedOrder.tp_order_price ?? "",
|
|
3370
|
+
trigger_price: formattedOrder.tp_trigger_price ?? "",
|
|
3371
|
+
PnL: formattedOrder.tp_pnl ?? "",
|
|
3372
|
+
Offset: formattedOrder.tp_offset ?? "",
|
|
3373
|
+
"Offset%": formattedOrder.tp_offset_percentage ?? "",
|
|
3374
|
+
ROI: formattedOrder.tp_ROI ?? ""
|
|
3375
|
+
});
|
|
3376
|
+
const [slValues, setSlValues] = react.useState({
|
|
3377
|
+
// enable: false,
|
|
3378
|
+
order_type: formattedOrder.sl_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
3379
|
+
order_price: formattedOrder.sl_order_price ?? "",
|
|
3380
|
+
trigger_price: formattedOrder.sl_trigger_price ?? "",
|
|
3381
|
+
PnL: formattedOrder.sl_pnl ?? "",
|
|
3382
|
+
Offset: formattedOrder.sl_offset ?? "",
|
|
3383
|
+
"Offset%": formattedOrder.sl_offset_percentage ?? "",
|
|
3384
|
+
ROI: formattedOrder.sl_ROI ?? ""
|
|
3385
|
+
});
|
|
3386
|
+
react.useEffect(() => {
|
|
3387
|
+
setTpValuse((prev) => ({
|
|
3388
|
+
...prev,
|
|
3389
|
+
// enable: formattedOrder.tp_enable ?? false,
|
|
3390
|
+
order_type: formattedOrder.tp_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
3391
|
+
order_price: formattedOrder.tp_order_price ?? "",
|
|
3392
|
+
trigger_price: formattedOrder.tp_trigger_price ?? "",
|
|
3393
|
+
PnL: formattedOrder.tp_pnl ?? "",
|
|
3394
|
+
Offset: formattedOrder.tp_offset ?? "",
|
|
3395
|
+
"Offset%": formattedOrder.tp_offset_percentage ?? "",
|
|
3396
|
+
ROI: formattedOrder.tp_ROI ?? ""
|
|
3397
|
+
}));
|
|
3398
|
+
}, [formattedOrder]);
|
|
3399
|
+
react.useEffect(() => {
|
|
3400
|
+
setSlValues((prev) => ({
|
|
3401
|
+
...prev,
|
|
3402
|
+
// enable: formattedOrder.sl_enable ?? false,
|
|
3403
|
+
order_type: formattedOrder.sl_order_type ?? orderlyTypes.OrderType.MARKET,
|
|
3404
|
+
order_price: formattedOrder.sl_order_price ?? "",
|
|
3405
|
+
trigger_price: formattedOrder.sl_trigger_price ?? "",
|
|
3406
|
+
PnL: formattedOrder.sl_pnl ?? "",
|
|
3407
|
+
Offset: formattedOrder.sl_offset ?? "",
|
|
3408
|
+
"Offset%": formattedOrder.sl_offset_percentage ?? "",
|
|
3409
|
+
ROI: formattedOrder.sl_ROI ?? ""
|
|
3410
|
+
}));
|
|
3411
|
+
}, [formattedOrder]);
|
|
3412
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3413
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3414
|
+
orderlyUi.ScrollArea,
|
|
3415
|
+
{
|
|
3416
|
+
className: orderlyUi.cn("oui-flex-1", isMobile && "oui-h-[calc(100vh-200px)]"),
|
|
3417
|
+
children: [
|
|
3418
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3419
|
+
OrderInfo,
|
|
3420
|
+
{
|
|
3421
|
+
order: {
|
|
3422
|
+
symbol,
|
|
3423
|
+
order_quantity: formattedOrder.order_quantity,
|
|
3424
|
+
order_price: formattedOrder.order_price
|
|
3425
|
+
},
|
|
3426
|
+
estLiqPrice: props.estLiqPrice ?? void 0,
|
|
3427
|
+
baseDP: symbolInfo.base_dp,
|
|
3428
|
+
quoteDP: symbolInfo.quote_dp
|
|
3429
|
+
}
|
|
3430
|
+
) }),
|
|
3431
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Divider, { className: "oui-my-3" }),
|
|
3432
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "", children: [
|
|
3433
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "oui-py-3", children: [
|
|
3434
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3435
|
+
TPSLPositionTypeWidget,
|
|
3436
|
+
{
|
|
3437
|
+
value: formattedOrder.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
3438
|
+
disableSelector: true,
|
|
3439
|
+
onChange: (key, value) => {
|
|
3440
|
+
if (value === orderlyTypes.PositionType.FULL) {
|
|
3441
|
+
setValues({
|
|
3442
|
+
position_type: orderlyTypes.PositionType.FULL,
|
|
3443
|
+
tp_order_type: orderlyTypes.OrderType.MARKET,
|
|
3444
|
+
tp_order_price: void 0,
|
|
3445
|
+
sl_order_type: orderlyTypes.OrderType.MARKET,
|
|
3446
|
+
sl_order_price: void 0
|
|
3447
|
+
});
|
|
3448
|
+
return;
|
|
3449
|
+
}
|
|
3450
|
+
setOrderValue("position_type", value);
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
),
|
|
3454
|
+
formattedOrder.position_type === orderlyTypes.PositionType.FULL && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3455
|
+
orderlyUi.Flex,
|
|
3456
|
+
{
|
|
3457
|
+
justify: "start",
|
|
3458
|
+
itemAlign: "start",
|
|
3459
|
+
gap: 2,
|
|
3460
|
+
className: "oui-mt-3 oui-w-full",
|
|
3461
|
+
children: [
|
|
3462
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "oui-relative oui-top-[7px] oui-size-1 oui-rounded-full oui-bg-[#D25f00]" }),
|
|
3463
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Text, { className: "oui-text-2xs oui-text-[#D25f00]", children: t("tpsl.positionType.full.tips.market") })
|
|
3464
|
+
]
|
|
3465
|
+
}
|
|
3466
|
+
)
|
|
3467
|
+
] }),
|
|
3468
|
+
/* @__PURE__ */ jsxRuntime.jsxs(orderlyUi.Flex, { direction: "column", gap: 6, children: [
|
|
3469
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3470
|
+
TPSLInputRowWidget,
|
|
3471
|
+
{
|
|
3472
|
+
disableEnableCheckbox: true,
|
|
3473
|
+
disableOrderTypeSelector: true,
|
|
3474
|
+
rootOrderPrice: formattedOrder.order_price,
|
|
3475
|
+
symbol: symbolInfo.symbol,
|
|
3476
|
+
type: "tp",
|
|
3477
|
+
side: formattedOrder.side,
|
|
3478
|
+
values: tpValues,
|
|
3479
|
+
errors: validated ? errors : null,
|
|
3480
|
+
quote_dp: symbolInfo.quote_dp,
|
|
3481
|
+
hideOrderPrice: formattedOrder.position_type === orderlyTypes.PositionType.FULL,
|
|
3482
|
+
onChange: (key, value) => {
|
|
3483
|
+
setOrderValue(key, value);
|
|
3484
|
+
},
|
|
3485
|
+
positionType: formattedOrder.position_type ?? orderlyTypes.PositionType.PARTIAL
|
|
3486
|
+
}
|
|
3487
|
+
),
|
|
3488
|
+
/* @__PURE__ */ jsxRuntime.jsx(orderlyUi.Divider, { className: "oui-w-full" }),
|
|
3489
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3490
|
+
TPSLInputRowWidget,
|
|
3491
|
+
{
|
|
3492
|
+
disableEnableCheckbox: true,
|
|
3493
|
+
disableOrderTypeSelector: true,
|
|
3494
|
+
rootOrderPrice: formattedOrder.order_price,
|
|
3495
|
+
symbol: symbolInfo.symbol,
|
|
3496
|
+
type: "sl",
|
|
3497
|
+
side: formattedOrder.side,
|
|
3498
|
+
values: slValues,
|
|
3499
|
+
hideOrderPrice: formattedOrder.position_type === orderlyTypes.PositionType.FULL,
|
|
3500
|
+
inputWarnNode: isSlPriceWarning && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3501
|
+
orderlyUi.DotStatus,
|
|
3502
|
+
{
|
|
3503
|
+
color: "warning",
|
|
3504
|
+
size: "xs",
|
|
3505
|
+
label: getErrorMsg("sl_trigger_price")
|
|
3506
|
+
}
|
|
3507
|
+
),
|
|
3508
|
+
errors: validated ? errors : null,
|
|
3509
|
+
quote_dp: symbolInfo.quote_dp,
|
|
3510
|
+
positionType: formattedOrder.position_type ?? orderlyTypes.PositionType.PARTIAL,
|
|
3511
|
+
onChange: (key, value) => {
|
|
3512
|
+
setOrderValue(key, value);
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
)
|
|
3516
|
+
] }),
|
|
3517
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3518
|
+
PnlInfo,
|
|
3519
|
+
{
|
|
3520
|
+
tp_pnl: formattedOrder.tp_pnl,
|
|
3521
|
+
sl_pnl: formattedOrder.sl_pnl,
|
|
3522
|
+
className: "oui-mt-6"
|
|
3523
|
+
}
|
|
3524
|
+
)
|
|
3525
|
+
] })
|
|
3526
|
+
]
|
|
3527
|
+
}
|
|
3528
|
+
),
|
|
3529
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3530
|
+
orderlyUi.Flex,
|
|
3531
|
+
{
|
|
3532
|
+
itemAlign: "center",
|
|
3533
|
+
gap: 3,
|
|
3534
|
+
mt: 5,
|
|
3535
|
+
width: "100%",
|
|
3536
|
+
justify: "center",
|
|
3537
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3538
|
+
orderlyUi.ThrottledButton,
|
|
3539
|
+
{
|
|
3540
|
+
className: "oui-w-[184px]",
|
|
3541
|
+
"data-testid": "tpsl-confirm",
|
|
3542
|
+
disabled: !props.isPriceChanged,
|
|
3543
|
+
loading: props.isMutating,
|
|
3544
|
+
onClick: () => {
|
|
3545
|
+
props.onSubmit().then(() => {
|
|
3546
|
+
props.onClose?.();
|
|
3547
|
+
}).catch((err) => {
|
|
3548
|
+
});
|
|
3549
|
+
},
|
|
3550
|
+
children: t("common.confirm")
|
|
3551
|
+
}
|
|
3552
|
+
)
|
|
3553
|
+
}
|
|
3554
|
+
)
|
|
3555
|
+
] });
|
|
3556
|
+
};
|
|
3557
|
+
var EditBracketOrderWidget = (props) => {
|
|
3558
|
+
const state = useEditBracketOrder({ order: props.order });
|
|
3559
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EditBracketOrderUI, { ...state, onClose: props.close });
|
|
3560
|
+
};
|
|
3561
|
+
var EditBracketOrderSheetId = "EditBracketOrderSheetId";
|
|
3562
|
+
var EditBracketOrderDialogId = "EditBracketOrderDialogId";
|
|
3563
|
+
orderlyUi.registerSimpleSheet(EditBracketOrderSheetId, EditBracketOrderWidget);
|
|
3564
|
+
orderlyUi.registerSimpleDialog(EditBracketOrderDialogId, EditBracketOrderWidget, {
|
|
3565
|
+
classNames: {
|
|
3566
|
+
content: "oui-w-[420px]"
|
|
3567
|
+
}
|
|
3568
|
+
});
|
|
15
3569
|
|
|
16
|
-
exports.ArrowRightIcon =
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.
|
|
35
|
-
exports.
|
|
36
|
-
exports.
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
39
|
-
exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.
|
|
3570
|
+
exports.ArrowRightIcon = ArrowRightIcon;
|
|
3571
|
+
exports.CloseToLiqPriceIcon = CloseToLiqPriceIcon;
|
|
3572
|
+
exports.EditBracketOrderDialogId = EditBracketOrderDialogId;
|
|
3573
|
+
exports.EditBracketOrderSheetId = EditBracketOrderSheetId;
|
|
3574
|
+
exports.EditBracketOrderWidget = EditBracketOrderWidget;
|
|
3575
|
+
exports.PositionTPSLConfirm = PositionTPSLConfirm;
|
|
3576
|
+
exports.PositionTPSLPopover = PositionTPSLPopover;
|
|
3577
|
+
exports.PositionTPSLSheet = PositionTPSLSheet;
|
|
3578
|
+
exports.TPSL = TPSL;
|
|
3579
|
+
exports.TPSLAdvancedDialogId = TPSLAdvancedDialogId;
|
|
3580
|
+
exports.TPSLAdvancedSheetId = TPSLAdvancedSheetId;
|
|
3581
|
+
exports.TPSLAdvancedUI = TPSLAdvancedUI;
|
|
3582
|
+
exports.TPSLAdvancedWidget = TPSLAdvancedWidget;
|
|
3583
|
+
exports.TPSLDetailDialogId = TPSLDetailDialogId;
|
|
3584
|
+
exports.TPSLDetailSheetId = TPSLDetailSheetId;
|
|
3585
|
+
exports.TPSLDetailWidget = TPSLDetailWidget;
|
|
3586
|
+
exports.TPSLDialogId = TPSLDialogId;
|
|
3587
|
+
exports.TPSLPositionTypeWidget = TPSLPositionTypeWidget;
|
|
3588
|
+
exports.TPSLSheetId = TPSLSheetId;
|
|
3589
|
+
exports.TPSLSimpleDialogId = TPSLSimpleDialogId;
|
|
3590
|
+
exports.TPSLSimpleDialogUI = TPSLSimpleDialogUI;
|
|
3591
|
+
exports.TPSLSimpleDialogWidget = TPSLSimpleDialogWidget;
|
|
3592
|
+
exports.TPSLSimpleSheetId = TPSLSimpleSheetId;
|
|
3593
|
+
exports.TPSLWidget = TPSLWidget;
|
|
3594
|
+
exports.useTPSLAdvanced = useTPSLAdvanced;
|
|
3595
|
+
exports.useTPSLBuilder = useTPSLBuilder;
|
|
3596
|
+
exports.useTPSLSimpleDialog = useTPSLSimpleDialog;
|
|
42
3597
|
//# sourceMappingURL=out.js.map
|
|
43
3598
|
//# sourceMappingURL=index.js.map
|