hyperprop-charting-library 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -37,6 +37,7 @@ chart.setData(data);
37
37
  - API reference: `docs/API.md`
38
38
  - Event contracts: `docs/EVENTS.md`
39
39
  - Integration recipes: `docs/RECIPES.md`
40
+ - Bracket orders (TP/SL lifecycle): `docs/BRACKETS.md`
40
41
  - AI integration context: `docs/AI_CONTEXT.md`
41
42
 
42
43
  ## Core API Surface
package/dist/index.cjs CHANGED
@@ -24,15 +24,15 @@ __export(index_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(index_exports);
26
26
  var DEFAULT_GRID_OPTIONS = {
27
- color: "#e2e8f0",
28
- opacity: 0.9,
27
+ color: "#2b2f38",
28
+ opacity: 0.38,
29
29
  horizontalLines: true,
30
30
  verticalLines: true,
31
31
  horizontalTickCount: 5
32
32
  };
33
33
  var DEFAULT_AXIS_OPTIONS = {
34
- lineColor: "#94a3b8",
35
- textColor: "#94a3b8",
34
+ lineColor: "#3b3f47",
35
+ textColor: "#a9adb6",
36
36
  fontSize: 12,
37
37
  lineWidth: 1
38
38
  };
@@ -47,8 +47,8 @@ var DEFAULT_CROSSHAIR_OPTIONS = {
47
47
  var DEFAULT_WATERMARK_OPTIONS = {
48
48
  visible: false,
49
49
  text: "",
50
- color: "#94a3b8",
51
- opacity: 0.2,
50
+ color: "#81858d",
51
+ opacity: 0.14,
52
52
  fontSize: 92,
53
53
  fontWeight: 700,
54
54
  thickness: 0
@@ -57,9 +57,9 @@ var DEFAULT_PRICE_LINE_OPTIONS = {
57
57
  visible: true,
58
58
  style: "solid",
59
59
  thickness: 1,
60
- color: "#f59e0b",
61
- labelBackgroundColor: "#f59e0b",
62
- labelTextColor: "#0f172a",
60
+ color: "#38bdf8",
61
+ labelBackgroundColor: "#0b1220",
62
+ labelTextColor: "#60a5fa",
63
63
  labelBorderRadius: 3,
64
64
  showLabel: true
65
65
  };
@@ -68,9 +68,9 @@ var DEFAULT_ORDER_LINE_OPTIONS = {
68
68
  behavior: "static",
69
69
  style: "solid",
70
70
  thickness: 1,
71
- color: "#f59e0b",
72
- labelBackgroundColor: "#f59e0b",
73
- labelTextColor: "#0f172a",
71
+ color: "rgba(59,130,246,0.8)",
72
+ labelBackgroundColor: "#0b1220",
73
+ labelTextColor: "#60a5fa",
74
74
  labelBorderRadius: 3,
75
75
  showCloseButton: true,
76
76
  widgetPosition: "left",
@@ -97,12 +97,12 @@ var DEFAULT_ORDER_LINE_OPTIONS = {
97
97
  var DEFAULT_OPTIONS = {
98
98
  width: 720,
99
99
  height: 360,
100
- backgroundColor: "#ffffff",
101
- axisColor: "#94a3b8",
100
+ backgroundColor: "#101114",
101
+ axisColor: "#7f8289",
102
102
  axis: DEFAULT_AXIS_OPTIONS,
103
- upColor: "#16a34a",
104
- downColor: "#dc2626",
105
- gridColor: "#e2e8f0",
103
+ upColor: "#2fb171",
104
+ downColor: "#d35a5a",
105
+ gridColor: "#252932",
106
106
  fontFamily: "Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif",
107
107
  candleBodyWidthRatio: 0.7,
108
108
  candleMinWidth: 0.5,
@@ -118,12 +118,12 @@ var DEFAULT_OPTIONS = {
118
118
  orderLines: [],
119
119
  tickerLine: {
120
120
  visible: true,
121
- style: "dashed",
121
+ style: "dotted",
122
122
  thickness: 1,
123
- color: "#22c55e",
124
- labelBackgroundColor: "#22c55e",
123
+ color: "#38bdf8",
124
+ labelBackgroundColor: "#38bdf8",
125
125
  labelTextColor: "#0b1220",
126
- labelBorderRadius: 6
126
+ labelBorderRadius: 3
127
127
  }
128
128
  };
129
129
  function createChart(element, options = {}) {
@@ -389,7 +389,7 @@ function createChart(element, options = {}) {
389
389
  return;
390
390
  }
391
391
  const lineY = clamp(yFromPrice(renderPrice), chartTop + 1, chartBottom - 1);
392
- const color = mergedLine.color ?? (mergedLine.side === "buy" ? mergedOptions.upColor : mergedLine.side === "sell" ? mergedOptions.downColor : "#f59e0b");
392
+ const color = line.color ?? (mergedLine.type === "takeProfit" ? "rgba(45,212,191,0.86)" : mergedLine.type === "stop" ? "rgba(245,158,11,0.86)" : "rgba(59,130,246,0.8)");
393
393
  if (Number.isFinite(mergedLine.fillToPrice)) {
394
394
  const fillY = clamp(yFromPrice(mergedLine.fillToPrice), chartTop + 1, chartBottom - 1);
395
395
  const topY = Math.min(lineY, fillY);
@@ -500,7 +500,7 @@ function createChart(element, options = {}) {
500
500
  const borderRadius = Math.max(0, mergedLine.labelBorderRadius);
501
501
  const widgetBackground = mergedOptions.backgroundColor;
502
502
  const widgetBorder = color;
503
- const textColor = mergedLine.labelTextColor;
503
+ const textColor = line.labelTextColor ?? (mergedLine.type === "takeProfit" ? "#5eead4" : mergedLine.type === "stop" ? "#fbbf24" : mergedLine.labelTextColor);
504
504
  const mainWidgetX = leftWidgetX + actionButtonsTotalWidth + actionButtonsGap;
505
505
  ctx.fillStyle = widgetBackground;
506
506
  fillRoundedRect(Math.round(mainWidgetX), Math.round(labelY), mainWidgetWidth, labelHeight, borderRadius);
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  // src/index.ts
2
2
  var DEFAULT_GRID_OPTIONS = {
3
- color: "#e2e8f0",
4
- opacity: 0.9,
3
+ color: "#2b2f38",
4
+ opacity: 0.38,
5
5
  horizontalLines: true,
6
6
  verticalLines: true,
7
7
  horizontalTickCount: 5
8
8
  };
9
9
  var DEFAULT_AXIS_OPTIONS = {
10
- lineColor: "#94a3b8",
11
- textColor: "#94a3b8",
10
+ lineColor: "#3b3f47",
11
+ textColor: "#a9adb6",
12
12
  fontSize: 12,
13
13
  lineWidth: 1
14
14
  };
@@ -23,8 +23,8 @@ var DEFAULT_CROSSHAIR_OPTIONS = {
23
23
  var DEFAULT_WATERMARK_OPTIONS = {
24
24
  visible: false,
25
25
  text: "",
26
- color: "#94a3b8",
27
- opacity: 0.2,
26
+ color: "#81858d",
27
+ opacity: 0.14,
28
28
  fontSize: 92,
29
29
  fontWeight: 700,
30
30
  thickness: 0
@@ -33,9 +33,9 @@ var DEFAULT_PRICE_LINE_OPTIONS = {
33
33
  visible: true,
34
34
  style: "solid",
35
35
  thickness: 1,
36
- color: "#f59e0b",
37
- labelBackgroundColor: "#f59e0b",
38
- labelTextColor: "#0f172a",
36
+ color: "#38bdf8",
37
+ labelBackgroundColor: "#0b1220",
38
+ labelTextColor: "#60a5fa",
39
39
  labelBorderRadius: 3,
40
40
  showLabel: true
41
41
  };
@@ -44,9 +44,9 @@ var DEFAULT_ORDER_LINE_OPTIONS = {
44
44
  behavior: "static",
45
45
  style: "solid",
46
46
  thickness: 1,
47
- color: "#f59e0b",
48
- labelBackgroundColor: "#f59e0b",
49
- labelTextColor: "#0f172a",
47
+ color: "rgba(59,130,246,0.8)",
48
+ labelBackgroundColor: "#0b1220",
49
+ labelTextColor: "#60a5fa",
50
50
  labelBorderRadius: 3,
51
51
  showCloseButton: true,
52
52
  widgetPosition: "left",
@@ -73,12 +73,12 @@ var DEFAULT_ORDER_LINE_OPTIONS = {
73
73
  var DEFAULT_OPTIONS = {
74
74
  width: 720,
75
75
  height: 360,
76
- backgroundColor: "#ffffff",
77
- axisColor: "#94a3b8",
76
+ backgroundColor: "#101114",
77
+ axisColor: "#7f8289",
78
78
  axis: DEFAULT_AXIS_OPTIONS,
79
- upColor: "#16a34a",
80
- downColor: "#dc2626",
81
- gridColor: "#e2e8f0",
79
+ upColor: "#2fb171",
80
+ downColor: "#d35a5a",
81
+ gridColor: "#252932",
82
82
  fontFamily: "Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif",
83
83
  candleBodyWidthRatio: 0.7,
84
84
  candleMinWidth: 0.5,
@@ -94,12 +94,12 @@ var DEFAULT_OPTIONS = {
94
94
  orderLines: [],
95
95
  tickerLine: {
96
96
  visible: true,
97
- style: "dashed",
97
+ style: "dotted",
98
98
  thickness: 1,
99
- color: "#22c55e",
100
- labelBackgroundColor: "#22c55e",
99
+ color: "#38bdf8",
100
+ labelBackgroundColor: "#38bdf8",
101
101
  labelTextColor: "#0b1220",
102
- labelBorderRadius: 6
102
+ labelBorderRadius: 3
103
103
  }
104
104
  };
105
105
  function createChart(element, options = {}) {
@@ -365,7 +365,7 @@ function createChart(element, options = {}) {
365
365
  return;
366
366
  }
367
367
  const lineY = clamp(yFromPrice(renderPrice), chartTop + 1, chartBottom - 1);
368
- const color = mergedLine.color ?? (mergedLine.side === "buy" ? mergedOptions.upColor : mergedLine.side === "sell" ? mergedOptions.downColor : "#f59e0b");
368
+ const color = line.color ?? (mergedLine.type === "takeProfit" ? "rgba(45,212,191,0.86)" : mergedLine.type === "stop" ? "rgba(245,158,11,0.86)" : "rgba(59,130,246,0.8)");
369
369
  if (Number.isFinite(mergedLine.fillToPrice)) {
370
370
  const fillY = clamp(yFromPrice(mergedLine.fillToPrice), chartTop + 1, chartBottom - 1);
371
371
  const topY = Math.min(lineY, fillY);
@@ -476,7 +476,7 @@ function createChart(element, options = {}) {
476
476
  const borderRadius = Math.max(0, mergedLine.labelBorderRadius);
477
477
  const widgetBackground = mergedOptions.backgroundColor;
478
478
  const widgetBorder = color;
479
- const textColor = mergedLine.labelTextColor;
479
+ const textColor = line.labelTextColor ?? (mergedLine.type === "takeProfit" ? "#5eead4" : mergedLine.type === "stop" ? "#fbbf24" : mergedLine.labelTextColor);
480
480
  const mainWidgetX = leftWidgetX + actionButtonsTotalWidth + actionButtonsGap;
481
481
  ctx.fillStyle = widgetBackground;
482
482
  fillRoundedRect(Math.round(mainWidgetX), Math.round(labelY), mainWidgetWidth, labelHeight, borderRadius);
@@ -54,6 +54,7 @@ When using this library in another repo, include:
54
54
 
55
55
  1. `docs/API.md`
56
56
  2. `docs/EVENTS.md`
57
- 3. this file (`AI_CONTEXT.md`)
57
+ 3. `docs/BRACKETS.md` (if trading/order workflows)
58
+ 4. this file (`AI_CONTEXT.md`)
58
59
 
59
60
  That gives enough context for most integration tasks without reading source.
@@ -0,0 +1,132 @@
1
+ # Bracket Orders (TP/SL) Integration
2
+
3
+ This library provides chart primitives and interaction events.
4
+ Bracket behavior (preview, pending, activation, OCO) is implemented in app state.
5
+
6
+ Use this guide as the canonical flow.
7
+
8
+ ---
9
+
10
+ ## Conceptual Model
11
+
12
+ Keep 3 layers in your app:
13
+
14
+ 1. **Preview layer** (before placement)
15
+ - `previewLimitPrice`
16
+ - `previewTpPrice`
17
+ - `previewSlPrice`
18
+ 2. **Pending bracket layer** (entry not filled yet)
19
+ - keyed by `entryOrderId`
20
+ - stores pending TP/SL values
21
+ 3. **Active order layer** (entry filled)
22
+ - active `market` position line
23
+ - active TP/SL exit lines
24
+
25
+ The chart only renders what you feed via `setOrderLines(...)`.
26
+
27
+ ---
28
+
29
+ ## Recommended Flow
30
+
31
+ ### 1) Create preview limit
32
+
33
+ - From click/double-click in plot, set `previewLimitPrice`.
34
+ - Render preview order line with custom buttons:
35
+ - `Buy/Sell` (`action: "execute"`)
36
+ - `TP` (`action: "previewTp"`, `draggable: true`)
37
+ - `SL` (`action: "previewSl"`, `draggable: true`)
38
+
39
+ ### 2) Set preview TP/SL
40
+
41
+ - On `onOrderAction`:
42
+ - `action === "previewTp"` -> set/update `previewTpPrice`
43
+ - `action === "previewSl"` -> set/update `previewSlPrice`
44
+ - Use `event.dragging`:
45
+ - `true`: live drag updates
46
+ - `false`: drag end
47
+
48
+ ### 3) Validate side rules before execute
49
+
50
+ - Buy entry:
51
+ - TP must be `>` limit
52
+ - SL must be `<` limit
53
+ - Sell entry:
54
+ - TP must be `<` limit
55
+ - SL must be `>` limit
56
+
57
+ If invalid, disable execute action in your state/UI.
58
+
59
+ ### 4) Execute preview
60
+
61
+ On `action === "execute"`:
62
+
63
+ - Create entry limit order.
64
+ - If TP/SL exists, store them as **pending brackets** tied to `entryOrderId`.
65
+ - Clear preview state.
66
+
67
+ ### 5) Convert pending to active on fill
68
+
69
+ When your fill logic marks entry as filled:
70
+
71
+ - Transition entry line to active position line (for example `market` + `follow` behavior).
72
+ - Create active TP/SL lines from pending bracket values.
73
+ - Remove pending bracket object.
74
+
75
+ ### 6) OCO behavior
76
+
77
+ If active TP or SL fills:
78
+
79
+ - Close/transition position as needed.
80
+ - Remove the sibling exit leg (OCO cleanup).
81
+
82
+ ### 7) Position close behavior
83
+
84
+ If user closes active position manually:
85
+
86
+ - Remove linked active TP/SL lines too.
87
+ - Remove any pending bracket bound to that entry id.
88
+
89
+ ---
90
+
91
+ ## Useful `OrderLineOptions` for Brackets
92
+
93
+ - `actionButtons` (custom Buy/TP/SL controls)
94
+ - `draggable` (line dragging)
95
+ - `connectorToPrice` + `connectorStyle` + `connectorAnchorPaddingRight`
96
+ - `fillToPrice` + `fillColor` (drag preview zone)
97
+ - `widgetPosition`
98
+ - `label`, `qty`, `pnl`
99
+
100
+ ---
101
+
102
+ ## Event Contract Essentials
103
+
104
+ From `onOrderAction(event)`:
105
+
106
+ - `event.action`: open string for app-defined workflows
107
+ - `event.price`: provided for move/drag contexts
108
+ - `event.dragging`: streaming drag state (`true` while dragging, `false` on release)
109
+ - `event.orderId`: line identity to map back to app state
110
+
111
+ Use ids as your state join key.
112
+
113
+ ---
114
+
115
+ ## Minimal State Skeleton
116
+
117
+ ```ts
118
+ type PreviewState = {
119
+ side: "buy" | "sell";
120
+ limit: number | null;
121
+ tp: number | null;
122
+ sl: number | null;
123
+ };
124
+
125
+ type PendingBracket = {
126
+ entryOrderId: string;
127
+ tpPrice: number | null;
128
+ slPrice: number | null;
129
+ };
130
+ ```
131
+
132
+ Keep this state in your app and regenerate chart lines from it each render/update tick.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",