@orderly.network/ui-tradingview 2.12.0 → 2.12.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +39 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import React3, { forwardRef, useRef, useState, useMemo, useEffect, useCallback }
|
|
|
3
3
|
import { useTranslation, Trans, useLocaleCode, i18n } from '@orderly.network/i18n';
|
|
4
4
|
import { cn, Flex, Divider, Box, useScreen, useOrderlyTheme, useThemeAttribute, toast, modal, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuContent, Text, Switch } from '@orderly.network/ui';
|
|
5
5
|
import { useMediaQuery, useConfig, useAccount, useSymbolsInfo, useLocalStorage, useOrderEntry_deprecated, useMarginModeBySymbol, useWS, usePositionStream, useOrderStream, useEventEmitter } from '@orderly.network/hooks';
|
|
6
|
-
import { MEDIA_TABLET, OrderSide, TradingviewFullscreenKey, OrderType, AccountStatusEnum, OrderStatus, ORDER_ENTRY_EST_LIQ_PRICE_CHANGE } from '@orderly.network/types';
|
|
6
|
+
import { MEDIA_TABLET, OrderSide, TradingviewFullscreenKey, OrderType, AccountStatusEnum, OrderStatus, ORDER_ENTRY_EST_LIQ_PRICE_CHANGE, MarginMode } from '@orderly.network/types';
|
|
7
7
|
import { Decimal, commify, getTrailingStopPrice, getPrecisionByNumber } from '@orderly.network/utils';
|
|
8
8
|
import { startOfSecond, startOfMinute, startOfHour, startOfDay, startOfMonth, startOfYear, startOfWeek } from 'date-fns';
|
|
9
9
|
|
|
@@ -2388,13 +2388,22 @@ var getTpslEstPnl = (tpslOrder, position) => {
|
|
|
2388
2388
|
tpslOrder.type === "CLOSE_POSITION" /* CLOSE_POSITION */ ? position.balance : tpslOrder.quantity
|
|
2389
2389
|
);
|
|
2390
2390
|
const sideFlag = tpslOrder.side === "SELL" /* SELL */ ? 1 : -1;
|
|
2391
|
-
const
|
|
2392
|
-
const estPnl = new Decimal(tpslOrder.trigger_price).minus(
|
|
2393
|
-
return { estPnl, quantity, openPrice };
|
|
2391
|
+
const priceRef = position.open;
|
|
2392
|
+
const estPnl = new Decimal(tpslOrder.trigger_price).minus(priceRef).times(quantity).times(sideFlag).toString();
|
|
2393
|
+
return { estPnl, quantity, openPrice: priceRef };
|
|
2394
2394
|
};
|
|
2395
2395
|
var formatPnl = (pnl) => {
|
|
2396
2396
|
return pnl !== void 0 && pnl !== "" ? new Decimal(pnl).todp(EST_TPSL_PNL_DECIMAL, Decimal.ROUND_FLOOR) : textDash;
|
|
2397
2397
|
};
|
|
2398
|
+
var getPositionSide = (balance) => {
|
|
2399
|
+
return balance >= 0 ? "LONG" /* LONG */ : "SHORT" /* SHORT */;
|
|
2400
|
+
};
|
|
2401
|
+
var determineTpslType = (targetPrice, markPrice, positionSide) => {
|
|
2402
|
+
if (positionSide === "LONG" /* LONG */) {
|
|
2403
|
+
return targetPrice > markPrice ? "tp" : "sl";
|
|
2404
|
+
}
|
|
2405
|
+
return targetPrice < markPrice ? "tp" : "sl";
|
|
2406
|
+
};
|
|
2398
2407
|
function useCancelOrder() {
|
|
2399
2408
|
const [
|
|
2400
2409
|
pendingOrders,
|
|
@@ -3365,11 +3374,15 @@ var TPSLService = class {
|
|
|
3365
3374
|
}
|
|
3366
3375
|
}
|
|
3367
3376
|
showTPSLDialog(params) {
|
|
3368
|
-
const
|
|
3377
|
+
const markPrice = this.currentPosition?.markPrice ?? this.currentPosition.open;
|
|
3378
|
+
const positionSide = getPositionSide(this.currentPosition.balance ?? 0);
|
|
3379
|
+
const type = determineTpslType(params.price, markPrice, positionSide);
|
|
3380
|
+
const marginMode = this.currentPosition?.marginMode ?? MarginMode.CROSS;
|
|
3369
3381
|
modal.show("TPSLSimpleDialogId", {
|
|
3370
|
-
title:
|
|
3382
|
+
title: type === "tp" ? i18n.t("tpsl.TPOrderConfirm") : i18n.t("tpsl.SLOrderConfirm"),
|
|
3371
3383
|
triggerPrice: params.price,
|
|
3372
|
-
type
|
|
3384
|
+
type,
|
|
3385
|
+
marginMode,
|
|
3373
3386
|
symbol: this.currentPosition.symbol,
|
|
3374
3387
|
onComplete: () => {
|
|
3375
3388
|
this.clearTPSLElements();
|
|
@@ -3379,7 +3392,7 @@ var TPSLService = class {
|
|
|
3379
3392
|
},
|
|
3380
3393
|
showAdvancedTPSLDialog: (options) => {
|
|
3381
3394
|
this.showAdvancedTPSLDialog({
|
|
3382
|
-
type
|
|
3395
|
+
type,
|
|
3383
3396
|
triggerPrice: params.price,
|
|
3384
3397
|
qty: options.qty
|
|
3385
3398
|
});
|
|
@@ -3401,29 +3414,27 @@ var TPSLService = class {
|
|
|
3401
3414
|
triggerPrice,
|
|
3402
3415
|
qty
|
|
3403
3416
|
}) {
|
|
3417
|
+
const onCloseHandler = () => {
|
|
3418
|
+
this.clearTPSLElements();
|
|
3419
|
+
this.chart.setScrollEnabled(true);
|
|
3420
|
+
this.chart.setZoomEnabled(true);
|
|
3421
|
+
this.interactiveMode = 0 /* NONE */;
|
|
3422
|
+
};
|
|
3404
3423
|
modal.show("TPSLDialogId", {
|
|
3405
3424
|
withTriggerPrice: true,
|
|
3406
3425
|
type,
|
|
3407
3426
|
triggerPrice,
|
|
3408
3427
|
symbol: this.currentPosition?.symbol,
|
|
3409
3428
|
qty,
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
this.chart.setZoomEnabled(true);
|
|
3414
|
-
this.interactiveMode = 0 /* NONE */;
|
|
3415
|
-
}
|
|
3429
|
+
position: this.currentPosition,
|
|
3430
|
+
onComplete: onCloseHandler,
|
|
3431
|
+
onCancel: onCloseHandler
|
|
3416
3432
|
}).then(
|
|
3417
3433
|
() => {
|
|
3418
3434
|
},
|
|
3419
3435
|
(err) => {
|
|
3420
3436
|
}
|
|
3421
|
-
).finally(
|
|
3422
|
-
this.clearTPSLElements();
|
|
3423
|
-
this.chart.setScrollEnabled(true);
|
|
3424
|
-
this.chart.setZoomEnabled(true);
|
|
3425
|
-
this.interactiveMode = 0 /* NONE */;
|
|
3426
|
-
});
|
|
3437
|
+
).finally(onCloseHandler);
|
|
3427
3438
|
}
|
|
3428
3439
|
updatePositions(positions) {
|
|
3429
3440
|
this.lastPositions = positions;
|
|
@@ -3456,13 +3467,16 @@ var TPSLService = class {
|
|
|
3456
3467
|
}
|
|
3457
3468
|
drawTPSL(params) {
|
|
3458
3469
|
const { price } = params;
|
|
3459
|
-
const
|
|
3470
|
+
const markPrice = this.currentPosition?.markPrice ?? this.currentPosition.open;
|
|
3471
|
+
const positionSide = getPositionSide(this.currentPosition.balance ?? 0);
|
|
3472
|
+
const type = determineTpslType(price, markPrice, positionSide);
|
|
3473
|
+
const pnl = new Decimal(price).minus(markPrice).mul(this.currentPosition?.balance ?? 0);
|
|
3460
3474
|
const { tpslOrderLine, verticalLine } = this.ensureTPSLElements({
|
|
3461
3475
|
price,
|
|
3462
3476
|
pnl
|
|
3463
3477
|
});
|
|
3464
|
-
const direction =
|
|
3465
|
-
const color =
|
|
3478
|
+
const direction = type === "tp" ? i18n.t("tpsl.tp") : i18n.t("tpsl.sl");
|
|
3479
|
+
const color = type === "tp" ? this.broker.colorConfig.upColor : this.broker.colorConfig.downColor;
|
|
3466
3480
|
tpslOrderLine?.setText(`${direction} ${pnl.toDecimalPlaces(2).toNumber()}`).setBodyTextColor(color).setBodyBorderColor(color).setLineColor(color);
|
|
3467
3481
|
if (this.tpslVerticalLineTime) {
|
|
3468
3482
|
verticalLine?.setPoints([
|
|
@@ -3724,7 +3738,9 @@ function useCreateRenderer(symbol, displayControlSetting, marginMode) {
|
|
|
3724
3738
|
interest: 0,
|
|
3725
3739
|
unrealPnlDecimal: 2,
|
|
3726
3740
|
basePriceDecimal: 4,
|
|
3727
|
-
marginMode: item.margin_mode
|
|
3741
|
+
marginMode: item.margin_mode,
|
|
3742
|
+
margin_mode: item.margin_mode,
|
|
3743
|
+
markPrice: item.mark_price
|
|
3728
3744
|
};
|
|
3729
3745
|
});
|
|
3730
3746
|
renderer?.renderPositions(positionList);
|