@forgecharts/sdk 1.5.23 → 1.5.24

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
@@ -7763,6 +7763,9 @@ function orderRoleLabel(role) {
7763
7763
  function isDraggableRole(role) {
7764
7764
  return role === "stop_loss" || role === "take_profit" || role === "limit" || role === "stop";
7765
7765
  }
7766
+ function isTerminal(status) {
7767
+ return status === "cancelled" || status === "rejected" || status === "expired" || status === "filled";
7768
+ }
7766
7769
  var LINE_H = 15;
7767
7770
  var LABEL_GAP = 6;
7768
7771
  var LABEL_PAD = 6;
@@ -8027,33 +8030,37 @@ var PixiTradingRenderer = class {
8027
8030
  labelIdx = this._drawLabel(String(pos.entryPrice), plotWidth + 4, y, labelIdx, labelStyle);
8028
8031
  this._positionHitZones.push({ id: pos.id, x: pillX, y: boxY, w: pillW, h: LINE_H });
8029
8032
  const linked = pos.linkedOrderIds ?? [];
8030
- const hasTp = linked.some((id) => id.endsWith("-tp"));
8031
- const hasSl = linked.some((id) => id.endsWith("-sl"));
8033
+ const hasTp = linked.some((id) => id.endsWith("-tp")) || orders.some((o) => (o.role === "take_profit" || o.role === "limit") && !isTerminal(o.status));
8034
+ const hasSl = linked.some((id) => id.endsWith("-sl")) || orders.some((o) => (o.role === "stop_loss" || o.role === "stop") && !isTerminal(o.status));
8032
8035
  const entrySide = pos.side === "long" ? "buy" : "sell";
8033
- if (!hasTp) {
8034
- const tpY = y - PILL_H / 2;
8035
- this._boxGfx.roundRect(PILL_TP_X, tpY, PILL_W, PILL_H, PILL_R).fill({ color: TP_PILL_COLOR, alpha: 0.85 });
8036
- labelIdx = this._drawLabel("TP", PILL_TP_X + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8036
+ let pillCursor = pillX - 4;
8037
+ if (!hasSl) {
8038
+ const slX = pillCursor - PILL_W;
8039
+ const slY = y - PILL_H / 2;
8040
+ this._boxGfx.roundRect(slX, slY, PILL_W, PILL_H, PILL_R).fill({ color: SL_PILL_COLOR, alpha: 0.85 });
8041
+ labelIdx = this._drawLabel("SL", slX + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8037
8042
  this._pillHitZones.push({
8038
- kind: "tp",
8043
+ kind: "sl",
8039
8044
  entryOrderId: pos.id,
8040
8045
  entrySide,
8041
- x: PILL_TP_X,
8042
- y: tpY,
8046
+ x: slX,
8047
+ y: slY,
8043
8048
  w: PILL_W,
8044
8049
  h: PILL_H
8045
8050
  });
8051
+ pillCursor = slX - 4;
8046
8052
  }
8047
- if (!hasSl) {
8048
- const slY = y - PILL_H / 2;
8049
- this._boxGfx.roundRect(PILL_SL_X, slY, PILL_W, PILL_H, PILL_R).fill({ color: SL_PILL_COLOR, alpha: 0.85 });
8050
- labelIdx = this._drawLabel("SL", PILL_SL_X + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8053
+ if (!hasTp) {
8054
+ const tpX = pillCursor - PILL_W;
8055
+ const tpY = y - PILL_H / 2;
8056
+ this._boxGfx.roundRect(tpX, tpY, PILL_W, PILL_H, PILL_R).fill({ color: TP_PILL_COLOR, alpha: 0.85 });
8057
+ labelIdx = this._drawLabel("TP", tpX + PILL_W / 2, y, labelIdx, pillLabelStyle, true);
8051
8058
  this._pillHitZones.push({
8052
- kind: "sl",
8059
+ kind: "tp",
8053
8060
  entryOrderId: pos.id,
8054
8061
  entrySide,
8055
- x: PILL_SL_X,
8056
- y: slY,
8062
+ x: tpX,
8063
+ y: tpY,
8057
8064
  w: PILL_W,
8058
8065
  h: PILL_H
8059
8066
  });
@@ -9346,30 +9353,40 @@ var PixiChart = class {
9346
9353
  setTradingOrders(orders) {
9347
9354
  this._tradingOrders = orders;
9348
9355
  this._layers.dirty.mark(4 /* TradingOverlay */);
9349
- const hasDraggable = orders.some(
9350
- (o) => (o.role === "stop_loss" || o.role === "take_profit") && o.status !== "cancelled" && o.status !== "filled"
9351
- );
9352
- if (hasDraggable) {
9353
- this._interaction.setOrderLineHitTest(
9354
- (x, y) => this._tradingRenderer.hitTestDraggableOrder(x, y)
9355
- );
9356
- } else {
9357
- this._interaction.setOrderLineHitTest(null);
9358
- }
9359
- const hasEntryWithoutBracket = orders.some(
9360
- (o) => o.role === "entry" && !o.groupId && o.status !== "cancelled" && o.status !== "filled" && o.status !== "rejected"
9361
- );
9362
- if (hasEntryWithoutBracket) {
9363
- this._interaction.setPillHitTest(
9364
- (x, y) => this._tradingRenderer.hitTestPill(x, y)
9365
- );
9366
- } else {
9367
- this._interaction.setPillHitTest(null);
9368
- }
9356
+ this._refreshTradingHitTests();
9369
9357
  }
9370
9358
  setTradingPositions(positions) {
9371
9359
  this._tradingPositions = positions;
9372
9360
  this._layers.dirty.mark(4 /* TradingOverlay */);
9361
+ this._refreshTradingHitTests();
9362
+ }
9363
+ /**
9364
+ * (Re)register the trading hit tests against current orders AND positions.
9365
+ *
9366
+ * Was inline in setTradingOrders and keyed on hardcoded roles, which left
9367
+ * both interactions half-wired:
9368
+ *
9369
+ * - the drag hit test required a 'stop_loss'/'take_profit' order, so
9370
+ * working limit and stop lines rendered a drag handle they could not
9371
+ * actually be grabbed by
9372
+ * - the pill hit test required an ORDER with role 'entry' and no groupId,
9373
+ * but the pills are drawn on POSITIONS, so they were never grabbable
9374
+ *
9375
+ * Both now derive from the same predicates the renderer draws with.
9376
+ */
9377
+ _refreshTradingHitTests() {
9378
+ const hasDraggable = this._tradingOrders.some(
9379
+ (o) => isDraggableRole(o.role) && o.status !== "cancelled" && o.status !== "filled"
9380
+ );
9381
+ this._interaction.setOrderLineHitTest(
9382
+ hasDraggable ? (x, y) => this._tradingRenderer.hitTestDraggableOrder(x, y) : null
9383
+ );
9384
+ const hasPillSource = this._tradingPositions.some((p) => p.status === "open") || this._tradingOrders.some(
9385
+ (o) => o.role === "entry" && !o.groupId && o.status !== "cancelled" && o.status !== "filled" && o.status !== "rejected"
9386
+ );
9387
+ this._interaction.setPillHitTest(
9388
+ hasPillSource ? (x, y) => this._tradingRenderer.hitTestPill(x, y) : null
9389
+ );
9373
9390
  }
9374
9391
  setContractSwitches(switches) {
9375
9392
  this._timeScale.contractSwitches = switches;