@orderly.network/ui-tradingview 2.12.0 → 2.12.1
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.js
CHANGED
|
@@ -2394,13 +2394,22 @@ var getTpslEstPnl = (tpslOrder, position) => {
|
|
|
2394
2394
|
tpslOrder.type === "CLOSE_POSITION" /* CLOSE_POSITION */ ? position.balance : tpslOrder.quantity
|
|
2395
2395
|
);
|
|
2396
2396
|
const sideFlag = tpslOrder.side === "SELL" /* SELL */ ? 1 : -1;
|
|
2397
|
-
const
|
|
2398
|
-
const estPnl = new utils.Decimal(tpslOrder.trigger_price).minus(
|
|
2399
|
-
return { estPnl, quantity, openPrice };
|
|
2397
|
+
const priceRef = position.open;
|
|
2398
|
+
const estPnl = new utils.Decimal(tpslOrder.trigger_price).minus(priceRef).times(quantity).times(sideFlag).toString();
|
|
2399
|
+
return { estPnl, quantity, openPrice: priceRef };
|
|
2400
2400
|
};
|
|
2401
2401
|
var formatPnl = (pnl) => {
|
|
2402
2402
|
return pnl !== void 0 && pnl !== "" ? new utils.Decimal(pnl).todp(EST_TPSL_PNL_DECIMAL, utils.Decimal.ROUND_FLOOR) : textDash;
|
|
2403
2403
|
};
|
|
2404
|
+
var getPositionSide = (balance) => {
|
|
2405
|
+
return balance >= 0 ? "LONG" /* LONG */ : "SHORT" /* SHORT */;
|
|
2406
|
+
};
|
|
2407
|
+
var determineTpslType = (targetPrice, markPrice, positionSide) => {
|
|
2408
|
+
if (positionSide === "LONG" /* LONG */) {
|
|
2409
|
+
return targetPrice > markPrice ? "tp" : "sl";
|
|
2410
|
+
}
|
|
2411
|
+
return targetPrice < markPrice ? "tp" : "sl";
|
|
2412
|
+
};
|
|
2404
2413
|
function useCancelOrder() {
|
|
2405
2414
|
const [
|
|
2406
2415
|
pendingOrders,
|
|
@@ -3371,11 +3380,15 @@ var TPSLService = class {
|
|
|
3371
3380
|
}
|
|
3372
3381
|
}
|
|
3373
3382
|
showTPSLDialog(params) {
|
|
3374
|
-
const
|
|
3383
|
+
const markPrice = this.currentPosition?.markPrice ?? this.currentPosition.open;
|
|
3384
|
+
const positionSide = getPositionSide(this.currentPosition.balance ?? 0);
|
|
3385
|
+
const type = determineTpslType(params.price, markPrice, positionSide);
|
|
3386
|
+
const marginMode = this.currentPosition?.marginMode ?? types.MarginMode.CROSS;
|
|
3375
3387
|
ui.modal.show("TPSLSimpleDialogId", {
|
|
3376
|
-
title:
|
|
3388
|
+
title: type === "tp" ? i18n.i18n.t("tpsl.TPOrderConfirm") : i18n.i18n.t("tpsl.SLOrderConfirm"),
|
|
3377
3389
|
triggerPrice: params.price,
|
|
3378
|
-
type
|
|
3390
|
+
type,
|
|
3391
|
+
marginMode,
|
|
3379
3392
|
symbol: this.currentPosition.symbol,
|
|
3380
3393
|
onComplete: () => {
|
|
3381
3394
|
this.clearTPSLElements();
|
|
@@ -3385,7 +3398,7 @@ var TPSLService = class {
|
|
|
3385
3398
|
},
|
|
3386
3399
|
showAdvancedTPSLDialog: (options) => {
|
|
3387
3400
|
this.showAdvancedTPSLDialog({
|
|
3388
|
-
type
|
|
3401
|
+
type,
|
|
3389
3402
|
triggerPrice: params.price,
|
|
3390
3403
|
qty: options.qty
|
|
3391
3404
|
});
|
|
@@ -3407,29 +3420,27 @@ var TPSLService = class {
|
|
|
3407
3420
|
triggerPrice,
|
|
3408
3421
|
qty
|
|
3409
3422
|
}) {
|
|
3423
|
+
const onCloseHandler = () => {
|
|
3424
|
+
this.clearTPSLElements();
|
|
3425
|
+
this.chart.setScrollEnabled(true);
|
|
3426
|
+
this.chart.setZoomEnabled(true);
|
|
3427
|
+
this.interactiveMode = 0 /* NONE */;
|
|
3428
|
+
};
|
|
3410
3429
|
ui.modal.show("TPSLDialogId", {
|
|
3411
3430
|
withTriggerPrice: true,
|
|
3412
3431
|
type,
|
|
3413
3432
|
triggerPrice,
|
|
3414
3433
|
symbol: this.currentPosition?.symbol,
|
|
3415
3434
|
qty,
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
this.chart.setZoomEnabled(true);
|
|
3420
|
-
this.interactiveMode = 0 /* NONE */;
|
|
3421
|
-
}
|
|
3435
|
+
position: this.currentPosition,
|
|
3436
|
+
onComplete: onCloseHandler,
|
|
3437
|
+
onCancel: onCloseHandler
|
|
3422
3438
|
}).then(
|
|
3423
3439
|
() => {
|
|
3424
3440
|
},
|
|
3425
3441
|
(err) => {
|
|
3426
3442
|
}
|
|
3427
|
-
).finally(
|
|
3428
|
-
this.clearTPSLElements();
|
|
3429
|
-
this.chart.setScrollEnabled(true);
|
|
3430
|
-
this.chart.setZoomEnabled(true);
|
|
3431
|
-
this.interactiveMode = 0 /* NONE */;
|
|
3432
|
-
});
|
|
3443
|
+
).finally(onCloseHandler);
|
|
3433
3444
|
}
|
|
3434
3445
|
updatePositions(positions) {
|
|
3435
3446
|
this.lastPositions = positions;
|
|
@@ -3462,13 +3473,16 @@ var TPSLService = class {
|
|
|
3462
3473
|
}
|
|
3463
3474
|
drawTPSL(params) {
|
|
3464
3475
|
const { price } = params;
|
|
3465
|
-
const
|
|
3476
|
+
const markPrice = this.currentPosition?.markPrice ?? this.currentPosition.open;
|
|
3477
|
+
const positionSide = getPositionSide(this.currentPosition.balance ?? 0);
|
|
3478
|
+
const type = determineTpslType(price, markPrice, positionSide);
|
|
3479
|
+
const pnl = new utils.Decimal(price).minus(markPrice).mul(this.currentPosition?.balance ?? 0);
|
|
3466
3480
|
const { tpslOrderLine, verticalLine } = this.ensureTPSLElements({
|
|
3467
3481
|
price,
|
|
3468
3482
|
pnl
|
|
3469
3483
|
});
|
|
3470
|
-
const direction =
|
|
3471
|
-
const color =
|
|
3484
|
+
const direction = type === "tp" ? i18n.i18n.t("tpsl.tp") : i18n.i18n.t("tpsl.sl");
|
|
3485
|
+
const color = type === "tp" ? this.broker.colorConfig.upColor : this.broker.colorConfig.downColor;
|
|
3472
3486
|
tpslOrderLine?.setText(`${direction} ${pnl.toDecimalPlaces(2).toNumber()}`).setBodyTextColor(color).setBodyBorderColor(color).setLineColor(color);
|
|
3473
3487
|
if (this.tpslVerticalLineTime) {
|
|
3474
3488
|
verticalLine?.setPoints([
|
|
@@ -3730,7 +3744,9 @@ function useCreateRenderer(symbol, displayControlSetting, marginMode) {
|
|
|
3730
3744
|
interest: 0,
|
|
3731
3745
|
unrealPnlDecimal: 2,
|
|
3732
3746
|
basePriceDecimal: 4,
|
|
3733
|
-
marginMode: item.margin_mode
|
|
3747
|
+
marginMode: item.margin_mode,
|
|
3748
|
+
margin_mode: item.margin_mode,
|
|
3749
|
+
markPrice: item.mark_price
|
|
3734
3750
|
};
|
|
3735
3751
|
});
|
|
3736
3752
|
renderer?.renderPositions(positionList);
|