@orderly.network/ui-tradingview 2.10.2 → 2.11.0-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 +44 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import React3, { forwardRef, useRef, useState, useMemo, useEffect, useCallback } from 'react';
|
|
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
|
-
import { useMediaQuery, useConfig, useAccount, useSymbolsInfo, useLocalStorage, useOrderEntry_deprecated, useWS, usePositionStream, useOrderStream, useEventEmitter } from '@orderly.network/hooks';
|
|
5
|
+
import { useMediaQuery, useConfig, useAccount, useSymbolsInfo, useLocalStorage, useOrderEntry_deprecated, useMarginModeBySymbol, useWS, usePositionStream, useOrderStream, useEventEmitter } from '@orderly.network/hooks';
|
|
6
6
|
import { MEDIA_TABLET, OrderSide, TradingviewFullscreenKey, OrderType, AccountStatusEnum, OrderStatus, ORDER_ENTRY_EST_LIQ_PRICE_CHANGE } 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';
|
|
@@ -2489,7 +2489,8 @@ function useEditOrder(onToast) {
|
|
|
2489
2489
|
order_type: order.type,
|
|
2490
2490
|
side: order.side,
|
|
2491
2491
|
visible_quantity: 0,
|
|
2492
|
-
reduce_only: order.reduce_only
|
|
2492
|
+
reduce_only: order.reduce_only,
|
|
2493
|
+
margin_mode: order.margin_mode
|
|
2493
2494
|
};
|
|
2494
2495
|
if (new Decimal(order.visible_quantity ?? order.visible ?? 0).eq(
|
|
2495
2496
|
order.quantity
|
|
@@ -2915,7 +2916,10 @@ var _OrderLineService = class _OrderLineService {
|
|
|
2915
2916
|
this.cleanOldPendingOrders(this.pendingOrders);
|
|
2916
2917
|
this.tpslCalService.prepareTpslPnlMap(this.pendingOrders);
|
|
2917
2918
|
this.tpslCalService.prepareQuantityTpslNoMap(this.pendingOrders);
|
|
2918
|
-
this.pendingOrders.
|
|
2919
|
+
const needDrawMarginMode = this.pendingOrders.length > 1;
|
|
2920
|
+
this.pendingOrders.forEach(
|
|
2921
|
+
(order) => this.renderPendingOrder(order, needDrawMarginMode)
|
|
2922
|
+
);
|
|
2919
2923
|
}
|
|
2920
2924
|
updatePositions(positions) {
|
|
2921
2925
|
const changed = this.tpslCalService.recalculatePnl(
|
|
@@ -2924,12 +2928,12 @@ var _OrderLineService = class _OrderLineService {
|
|
|
2924
2928
|
);
|
|
2925
2929
|
this.pendingOrders.filter((order) => changed.includes(getOrderId(order))).forEach((order) => this.renderPendingOrder(order));
|
|
2926
2930
|
}
|
|
2927
|
-
renderPendingOrder(order) {
|
|
2931
|
+
renderPendingOrder(order, needDrawMarginMode = false) {
|
|
2928
2932
|
const orderId = _OrderLineService.getOrderId(order);
|
|
2929
2933
|
if (!orderId) {
|
|
2930
2934
|
return;
|
|
2931
2935
|
}
|
|
2932
|
-
const orderLine = this.drawOrderLine(orderId, order);
|
|
2936
|
+
const orderLine = this.drawOrderLine(orderId, order, needDrawMarginMode);
|
|
2933
2937
|
if (orderLine) {
|
|
2934
2938
|
this.pendingOrderLineMap.set(orderId, orderLine);
|
|
2935
2939
|
}
|
|
@@ -3067,8 +3071,8 @@ var _OrderLineService = class _OrderLineService {
|
|
|
3067
3071
|
}
|
|
3068
3072
|
return commify(new Decimal(pendingOrder.quantity).toString());
|
|
3069
3073
|
}
|
|
3070
|
-
drawOrderLine(orderId, pendingOrder) {
|
|
3071
|
-
|
|
3074
|
+
drawOrderLine(orderId, pendingOrder, needDrawMarginMode = false) {
|
|
3075
|
+
let text = isTpslOrder(pendingOrder) ? this.getTPSLText(pendingOrder) : _OrderLineService.getText(pendingOrder);
|
|
3072
3076
|
if (text === null) {
|
|
3073
3077
|
return null;
|
|
3074
3078
|
}
|
|
@@ -3093,7 +3097,10 @@ var _OrderLineService = class _OrderLineService {
|
|
|
3093
3097
|
const lineLength = 100;
|
|
3094
3098
|
const quantity = this.getOrderQuantity(pendingOrder);
|
|
3095
3099
|
const textColor = colorConfig.textColor;
|
|
3096
|
-
|
|
3100
|
+
if (needDrawMarginMode) {
|
|
3101
|
+
text += ` (${pendingOrder.margin_mode === "ISOLATED" ? "Isolated" : "Cross"})`;
|
|
3102
|
+
}
|
|
3103
|
+
orderLine.setText(text).setCancelButtonIconColor(colorConfig.closeIcon).setCancelButtonBorderColor(color).setBodyTextColor(textColor).setBodyBorderColor(borderColor).setQuantityBorderColor(borderColor).setQuantityTextColor(color).setLineColor(color).setLineLength(lineLength).setQuantity(quantity).setPrice(price);
|
|
3097
3104
|
if (this.broker.mode !== 3 /* MOBILE */) {
|
|
3098
3105
|
orderLine.onCancel(null, () => this.broker.cancelOrder(pendingOrder));
|
|
3099
3106
|
this.applyEditOnMove(orderLine, pendingOrder);
|
|
@@ -3163,7 +3170,10 @@ var PositionLineService = class _PositionLineService {
|
|
|
3163
3170
|
this.removePositions();
|
|
3164
3171
|
this.currentSymbol = positions[0].symbol;
|
|
3165
3172
|
}
|
|
3166
|
-
|
|
3173
|
+
const needDrawMarginMode = positions.length > 1;
|
|
3174
|
+
positions.forEach(
|
|
3175
|
+
(position, idx) => this.drawPositionLine(position, idx, needDrawMarginMode)
|
|
3176
|
+
);
|
|
3167
3177
|
this.lastPositions = positions;
|
|
3168
3178
|
}
|
|
3169
3179
|
getBasePositionLine() {
|
|
@@ -3203,7 +3213,7 @@ var PositionLineService = class _PositionLineService {
|
|
|
3203
3213
|
delete this.positionLines[Number(lineId)];
|
|
3204
3214
|
});
|
|
3205
3215
|
}
|
|
3206
|
-
drawPositionLine(position, idx) {
|
|
3216
|
+
drawPositionLine(position, idx, needDrawMarginMode = false) {
|
|
3207
3217
|
const colorConfig = this.broker.colorConfig;
|
|
3208
3218
|
const isPositiveBalance = position.balance >= 0;
|
|
3209
3219
|
const pnlDecimal = new Decimal(position.unrealPnl);
|
|
@@ -3218,22 +3228,24 @@ var PositionLineService = class _PositionLineService {
|
|
|
3218
3228
|
const sideColor = isPositiveBalance ? colorConfig.upColor : colorConfig.downColor;
|
|
3219
3229
|
const price = new Decimal(position.open).toNumber();
|
|
3220
3230
|
this.positionLines[idx] = this.positionLines[idx] ?? this.getBasePositionLine();
|
|
3221
|
-
let
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
position.unrealPnlDecimal
|
|
3225
|
-
)
|
|
3231
|
+
let text = _PositionLineService.getPositionPnL(
|
|
3232
|
+
position.unrealPnl,
|
|
3233
|
+
position.unrealPnlDecimal
|
|
3226
3234
|
);
|
|
3235
|
+
const quantity = _PositionLineService.getPositionQuantity(position.balance);
|
|
3236
|
+
if (needDrawMarginMode) {
|
|
3237
|
+
text += ` (${position.marginMode === "ISOLATED" ? "Isolated" : "Cross"})`;
|
|
3238
|
+
}
|
|
3239
|
+
const line = this.positionLines[idx].setQuantity(quantity).setPrice(price).setCloseButtonIconColor(colorConfig.closeIcon).setCloseButtonBorderColor(sideColor).setBodyBackgroundColor(pnlColor).setQuantityTextColor(sideColor).setBodyBorderColor(pnlColor).setLineColor(sideColor).setQuantityBorderColor(sideColor).setText(text);
|
|
3227
3240
|
if (colorConfig.closeIcon) {
|
|
3228
|
-
line
|
|
3241
|
+
line.setCloseButtonIconColor(colorConfig.closeIcon);
|
|
3229
3242
|
}
|
|
3230
3243
|
if (sideColor) {
|
|
3231
|
-
line
|
|
3244
|
+
line.setCloseButtonBorderColor(sideColor).setQuantityTextColor(sideColor).setLineColor(sideColor).setQuantityBorderColor(sideColor);
|
|
3232
3245
|
}
|
|
3233
3246
|
if (pnlColor) {
|
|
3234
|
-
line
|
|
3247
|
+
line.setBodyBackgroundColor(pnlColor).setBodyBorderColor(pnlColor);
|
|
3235
3248
|
}
|
|
3236
|
-
this.positionLines[idx] = line;
|
|
3237
3249
|
if (this.broker.mode !== 3 /* MOBILE */) {
|
|
3238
3250
|
this.positionLines[idx].onClose(null, () => {
|
|
3239
3251
|
this.broker.closePosition(position);
|
|
@@ -3587,14 +3599,20 @@ var Renderer = class {
|
|
|
3587
3599
|
};
|
|
3588
3600
|
|
|
3589
3601
|
// src/tradingviewAdapter/hooks/useCreateRenderer.ts
|
|
3590
|
-
function useCreateRenderer(symbol, displayControlSetting) {
|
|
3602
|
+
function useCreateRenderer(symbol, displayControlSetting, marginMode) {
|
|
3591
3603
|
const [renderer, setRenderer] = useState();
|
|
3592
3604
|
const rendererRef = useRef();
|
|
3593
3605
|
const { state } = useAccount();
|
|
3594
3606
|
const [unPnlPriceBasis] = useLocalStorage("unPnlPriceBasis", "markPrice");
|
|
3595
|
-
const [{ rows
|
|
3607
|
+
const [{ rows }, positionsInfo] = usePositionStream(symbol, {
|
|
3596
3608
|
calcMode: unPnlPriceBasis
|
|
3597
3609
|
});
|
|
3610
|
+
const positions = useMemo(() => {
|
|
3611
|
+
if (!rows?.length) return [];
|
|
3612
|
+
return rows.filter(
|
|
3613
|
+
(item) => item.symbol === symbol && (marginMode == null || item.margin_mode === marginMode)
|
|
3614
|
+
);
|
|
3615
|
+
}, [rows, symbol, marginMode]);
|
|
3598
3616
|
const [pendingOrders] = useOrderStream({
|
|
3599
3617
|
status: OrderStatus.INCOMPLETE,
|
|
3600
3618
|
symbol
|
|
@@ -3633,7 +3651,7 @@ function useCreateRenderer(symbol, displayControlSetting) {
|
|
|
3633
3651
|
renderer?.renderPositions([]);
|
|
3634
3652
|
return;
|
|
3635
3653
|
}
|
|
3636
|
-
const positionList =
|
|
3654
|
+
const positionList = positions.map((item) => {
|
|
3637
3655
|
return {
|
|
3638
3656
|
symbol: item.symbol,
|
|
3639
3657
|
open: item.average_open_price,
|
|
@@ -3644,7 +3662,7 @@ function useCreateRenderer(symbol, displayControlSetting) {
|
|
|
3644
3662
|
interest: 0,
|
|
3645
3663
|
unrealPnlDecimal: 2,
|
|
3646
3664
|
basePriceDecimal: 4,
|
|
3647
|
-
|
|
3665
|
+
marginMode: item.margin_mode
|
|
3648
3666
|
};
|
|
3649
3667
|
});
|
|
3650
3668
|
renderer?.renderPositions(positionList);
|
|
@@ -3699,9 +3717,7 @@ function useCreateRenderer(symbol, displayControlSetting) {
|
|
|
3699
3717
|
renderer?.renderPendingOrders([]);
|
|
3700
3718
|
return;
|
|
3701
3719
|
}
|
|
3702
|
-
const symbolPosition = (
|
|
3703
|
-
(item) => item.symbol === symbol
|
|
3704
|
-
);
|
|
3720
|
+
const symbolPosition = positions.find((item) => item.symbol === symbol);
|
|
3705
3721
|
pendingOrders?.forEach((order) => {
|
|
3706
3722
|
if (symbol !== order.symbol) {
|
|
3707
3723
|
return;
|
|
@@ -4284,6 +4300,7 @@ function useTradingviewScript(props) {
|
|
|
4284
4300
|
watchOrderbook: true
|
|
4285
4301
|
}
|
|
4286
4302
|
);
|
|
4303
|
+
const { marginMode } = useMarginModeBySymbol(symbol ?? "");
|
|
4287
4304
|
const [displayControlState, setDisplayControlState] = useState(() => {
|
|
4288
4305
|
const displaySettingInfo = localStorage.getItem(
|
|
4289
4306
|
TradingViewSDKLocalstorageKey.displayControlSetting
|
|
@@ -4374,7 +4391,8 @@ function useTradingviewScript(props) {
|
|
|
4374
4391
|
});
|
|
4375
4392
|
const [createRenderer, removeRenderer] = useCreateRenderer(
|
|
4376
4393
|
symbol,
|
|
4377
|
-
displayControlState
|
|
4394
|
+
displayControlState,
|
|
4395
|
+
marginMode
|
|
4378
4396
|
);
|
|
4379
4397
|
const onFullScreenChange = () => {
|
|
4380
4398
|
if (fullscreen) {
|