@orderly.network/ui-tradingview 2.10.2 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2495,7 +2495,8 @@ function useEditOrder(onToast) {
2495
2495
  order_type: order.type,
2496
2496
  side: order.side,
2497
2497
  visible_quantity: 0,
2498
- reduce_only: order.reduce_only
2498
+ reduce_only: order.reduce_only,
2499
+ margin_mode: order.margin_mode
2499
2500
  };
2500
2501
  if (new utils.Decimal(order.visible_quantity ?? order.visible ?? 0).eq(
2501
2502
  order.quantity
@@ -2921,7 +2922,10 @@ var _OrderLineService = class _OrderLineService {
2921
2922
  this.cleanOldPendingOrders(this.pendingOrders);
2922
2923
  this.tpslCalService.prepareTpslPnlMap(this.pendingOrders);
2923
2924
  this.tpslCalService.prepareQuantityTpslNoMap(this.pendingOrders);
2924
- this.pendingOrders.forEach((order) => this.renderPendingOrder(order));
2925
+ const needDrawMarginMode = this.pendingOrders.length > 1;
2926
+ this.pendingOrders.forEach(
2927
+ (order) => this.renderPendingOrder(order, needDrawMarginMode)
2928
+ );
2925
2929
  }
2926
2930
  updatePositions(positions) {
2927
2931
  const changed = this.tpslCalService.recalculatePnl(
@@ -2930,12 +2934,12 @@ var _OrderLineService = class _OrderLineService {
2930
2934
  );
2931
2935
  this.pendingOrders.filter((order) => changed.includes(getOrderId(order))).forEach((order) => this.renderPendingOrder(order));
2932
2936
  }
2933
- renderPendingOrder(order) {
2937
+ renderPendingOrder(order, needDrawMarginMode = false) {
2934
2938
  const orderId = _OrderLineService.getOrderId(order);
2935
2939
  if (!orderId) {
2936
2940
  return;
2937
2941
  }
2938
- const orderLine = this.drawOrderLine(orderId, order);
2942
+ const orderLine = this.drawOrderLine(orderId, order, needDrawMarginMode);
2939
2943
  if (orderLine) {
2940
2944
  this.pendingOrderLineMap.set(orderId, orderLine);
2941
2945
  }
@@ -3073,8 +3077,8 @@ var _OrderLineService = class _OrderLineService {
3073
3077
  }
3074
3078
  return utils.commify(new utils.Decimal(pendingOrder.quantity).toString());
3075
3079
  }
3076
- drawOrderLine(orderId, pendingOrder) {
3077
- const text = isTpslOrder(pendingOrder) ? this.getTPSLText(pendingOrder) : _OrderLineService.getText(pendingOrder);
3080
+ drawOrderLine(orderId, pendingOrder, needDrawMarginMode = false) {
3081
+ let text = isTpslOrder(pendingOrder) ? this.getTPSLText(pendingOrder) : _OrderLineService.getText(pendingOrder);
3078
3082
  if (text === null) {
3079
3083
  return null;
3080
3084
  }
@@ -3099,7 +3103,10 @@ var _OrderLineService = class _OrderLineService {
3099
3103
  const lineLength = 100;
3100
3104
  const quantity = this.getOrderQuantity(pendingOrder);
3101
3105
  const textColor = colorConfig.textColor;
3102
- orderLine.setText(text).setCancelButtonIconColor(colorConfig.closeIcon).setCancelButtonBorderColor(color).setBodyTextColor(textColor).setBodyBorderColor(borderColor).setQuantityBorderColor(borderColor).setQuantityTextColor(color).setLineColor(color).setLineLength(lineLength).setQuantity(quantity ?? "").setPrice(price);
3106
+ if (needDrawMarginMode) {
3107
+ text += ` (${pendingOrder.margin_mode === "ISOLATED" ? "Isolated" : "Cross"})`;
3108
+ }
3109
+ orderLine.setText(text).setCancelButtonIconColor(colorConfig.closeIcon).setCancelButtonBorderColor(color).setBodyTextColor(textColor).setBodyBorderColor(borderColor).setQuantityBorderColor(borderColor).setQuantityTextColor(color).setLineColor(color).setLineLength(lineLength).setQuantity(quantity).setPrice(price);
3103
3110
  if (this.broker.mode !== 3 /* MOBILE */) {
3104
3111
  orderLine.onCancel(null, () => this.broker.cancelOrder(pendingOrder));
3105
3112
  this.applyEditOnMove(orderLine, pendingOrder);
@@ -3169,7 +3176,10 @@ var PositionLineService = class _PositionLineService {
3169
3176
  this.removePositions();
3170
3177
  this.currentSymbol = positions[0].symbol;
3171
3178
  }
3172
- positions.forEach((position, idx) => this.drawPositionLine(position, idx));
3179
+ const needDrawMarginMode = positions.length > 1;
3180
+ positions.forEach(
3181
+ (position, idx) => this.drawPositionLine(position, idx, needDrawMarginMode)
3182
+ );
3173
3183
  this.lastPositions = positions;
3174
3184
  }
3175
3185
  getBasePositionLine() {
@@ -3209,7 +3219,7 @@ var PositionLineService = class _PositionLineService {
3209
3219
  delete this.positionLines[Number(lineId)];
3210
3220
  });
3211
3221
  }
3212
- drawPositionLine(position, idx) {
3222
+ drawPositionLine(position, idx, needDrawMarginMode = false) {
3213
3223
  const colorConfig = this.broker.colorConfig;
3214
3224
  const isPositiveBalance = position.balance >= 0;
3215
3225
  const pnlDecimal = new utils.Decimal(position.unrealPnl);
@@ -3224,22 +3234,24 @@ var PositionLineService = class _PositionLineService {
3224
3234
  const sideColor = isPositiveBalance ? colorConfig.upColor : colorConfig.downColor;
3225
3235
  const price = new utils.Decimal(position.open).toNumber();
3226
3236
  this.positionLines[idx] = this.positionLines[idx] ?? this.getBasePositionLine();
3227
- let line = this.positionLines[idx].setQuantity(_PositionLineService.getPositionQuantity(position.balance)).setPrice(price).setText(
3228
- _PositionLineService.getPositionPnL(
3229
- position.unrealPnl,
3230
- position.unrealPnlDecimal
3231
- )
3237
+ let text = _PositionLineService.getPositionPnL(
3238
+ position.unrealPnl,
3239
+ position.unrealPnlDecimal
3232
3240
  );
3241
+ const quantity = _PositionLineService.getPositionQuantity(position.balance);
3242
+ if (needDrawMarginMode) {
3243
+ text += ` (${position.marginMode === "ISOLATED" ? "Isolated" : "Cross"})`;
3244
+ }
3245
+ 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);
3233
3246
  if (colorConfig.closeIcon) {
3234
- line = line.setCloseButtonIconColor(colorConfig.closeIcon);
3247
+ line.setCloseButtonIconColor(colorConfig.closeIcon);
3235
3248
  }
3236
3249
  if (sideColor) {
3237
- line = line.setCloseButtonBorderColor(sideColor).setQuantityTextColor(sideColor).setLineColor(sideColor).setQuantityBorderColor(sideColor);
3250
+ line.setCloseButtonBorderColor(sideColor).setQuantityTextColor(sideColor).setLineColor(sideColor).setQuantityBorderColor(sideColor);
3238
3251
  }
3239
3252
  if (pnlColor) {
3240
- line = line.setBodyBackgroundColor(pnlColor).setBodyBorderColor(pnlColor);
3253
+ line.setBodyBackgroundColor(pnlColor).setBodyBorderColor(pnlColor);
3241
3254
  }
3242
- this.positionLines[idx] = line;
3243
3255
  if (this.broker.mode !== 3 /* MOBILE */) {
3244
3256
  this.positionLines[idx].onClose(null, () => {
3245
3257
  this.broker.closePosition(position);
@@ -3593,14 +3605,20 @@ var Renderer = class {
3593
3605
  };
3594
3606
 
3595
3607
  // src/tradingviewAdapter/hooks/useCreateRenderer.ts
3596
- function useCreateRenderer(symbol, displayControlSetting) {
3608
+ function useCreateRenderer(symbol, displayControlSetting, marginMode) {
3597
3609
  const [renderer, setRenderer] = React3.useState();
3598
3610
  const rendererRef = React3.useRef();
3599
3611
  const { state } = hooks.useAccount();
3600
3612
  const [unPnlPriceBasis] = hooks.useLocalStorage("unPnlPriceBasis", "markPrice");
3601
- const [{ rows: positions }, positionsInfo] = hooks.usePositionStream(symbol, {
3613
+ const [{ rows }, positionsInfo] = hooks.usePositionStream(symbol, {
3602
3614
  calcMode: unPnlPriceBasis
3603
3615
  });
3616
+ const positions = React3.useMemo(() => {
3617
+ if (!rows?.length) return [];
3618
+ return rows.filter(
3619
+ (item) => item.symbol === symbol && (marginMode == null || item.margin_mode === marginMode)
3620
+ );
3621
+ }, [rows, symbol, marginMode]);
3604
3622
  const [pendingOrders] = hooks.useOrderStream({
3605
3623
  status: types.OrderStatus.INCOMPLETE,
3606
3624
  symbol
@@ -3639,7 +3657,7 @@ function useCreateRenderer(symbol, displayControlSetting) {
3639
3657
  renderer?.renderPositions([]);
3640
3658
  return;
3641
3659
  }
3642
- const positionList = (positions ?? []).filter((_) => _.symbol === symbol).map((item) => {
3660
+ const positionList = positions.map((item) => {
3643
3661
  return {
3644
3662
  symbol: item.symbol,
3645
3663
  open: item.average_open_price,
@@ -3650,7 +3668,7 @@ function useCreateRenderer(symbol, displayControlSetting) {
3650
3668
  interest: 0,
3651
3669
  unrealPnlDecimal: 2,
3652
3670
  basePriceDecimal: 4,
3653
- est_liq_price: item.est_liq_price ?? null
3671
+ marginMode: item.margin_mode
3654
3672
  };
3655
3673
  });
3656
3674
  renderer?.renderPositions(positionList);
@@ -3705,9 +3723,7 @@ function useCreateRenderer(symbol, displayControlSetting) {
3705
3723
  renderer?.renderPendingOrders([]);
3706
3724
  return;
3707
3725
  }
3708
- const symbolPosition = (positions ?? []).find(
3709
- (item) => item.symbol === symbol
3710
- );
3726
+ const symbolPosition = positions.find((item) => item.symbol === symbol);
3711
3727
  pendingOrders?.forEach((order) => {
3712
3728
  if (symbol !== order.symbol) {
3713
3729
  return;
@@ -4290,6 +4306,7 @@ function useTradingviewScript(props) {
4290
4306
  watchOrderbook: true
4291
4307
  }
4292
4308
  );
4309
+ const { marginMode } = hooks.useMarginModeBySymbol(symbol ?? "");
4293
4310
  const [displayControlState, setDisplayControlState] = React3.useState(() => {
4294
4311
  const displaySettingInfo = localStorage.getItem(
4295
4312
  TradingViewSDKLocalstorageKey.displayControlSetting
@@ -4380,7 +4397,8 @@ function useTradingviewScript(props) {
4380
4397
  });
4381
4398
  const [createRenderer, removeRenderer] = useCreateRenderer(
4382
4399
  symbol,
4383
- displayControlState
4400
+ displayControlState,
4401
+ marginMode
4384
4402
  );
4385
4403
  const onFullScreenChange = () => {
4386
4404
  if (fullscreen) {