@orangecharts/wrun-chart-host 0.1.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/README.md +72 -0
- package/dist/constants/governed-exchanges.constants.d.ts +11 -0
- package/dist/constants/governed-exchanges.constants.js +11 -0
- package/dist/constants/indicator-sets.constants.d.ts +8 -0
- package/dist/constants/indicator-sets.constants.js +8 -0
- package/dist/constants/interval.constants.d.ts +34 -0
- package/dist/constants/interval.constants.js +121 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +28 -0
- package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +65 -0
- package/dist/constants/tpo-color-schemes.constants.d.ts +30 -0
- package/dist/constants/tpo-color-schemes.constants.js +32 -0
- package/dist/host-env.d.ts +102 -0
- package/dist/host-env.js +26 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +96 -0
- package/dist/indicators/controls/tpo-letter.util.d.ts +2 -0
- package/dist/indicators/controls/tpo-letter.util.js +13 -0
- package/dist/indicators/controls/tpo-session.util.d.ts +99 -0
- package/dist/indicators/controls/tpo-session.util.js +389 -0
- package/dist/interfaces/kscript-diagnostics.interface.d.ts +64 -0
- package/dist/interfaces/kscript-diagnostics.interface.js +1 -0
- package/dist/interfaces/om-panel-data.interface.d.ts +103 -0
- package/dist/interfaces/om-panel-data.interface.js +7 -0
- package/dist/interfaces/wrun-runtime.interface.d.ts +2659 -0
- package/dist/interfaces/wrun-runtime.interface.js +55 -0
- package/dist/utility/chart/calendar-interval.util.d.ts +24 -0
- package/dist/utility/chart/calendar-interval.util.js +81 -0
- package/dist/utility/chart/candle-bar-end.util.d.ts +15 -0
- package/dist/utility/chart/candle-bar-end.util.js +23 -0
- package/dist/utility/chart/cme-realtime.util.d.ts +24 -0
- package/dist/utility/chart/cme-realtime.util.js +53 -0
- package/dist/utility/chart/interval-ladder.util.d.ts +27 -0
- package/dist/utility/chart/interval-ladder.util.js +92 -0
- package/dist/utility/chart/kscript-drawing-prep.util.d.ts +40 -0
- package/dist/utility/chart/kscript-drawing-prep.util.js +184 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +95 -0
- package/dist/utility/chart/kscript-drawing-safe-area.util.js +805 -0
- package/dist/utility/chart/kscript-legend-entries.util.d.ts +166 -0
- package/dist/utility/chart/kscript-legend-entries.util.js +538 -0
- package/dist/utility/chart/kscript-output-role.util.d.ts +32 -0
- package/dist/utility/chart/kscript-output-role.util.js +215 -0
- package/dist/utility/chart/kscript-provenance-keys.util.d.ts +22 -0
- package/dist/utility/chart/kscript-provenance-keys.util.js +56 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.d.ts +53 -0
- package/dist/utility/chart/kscript-run-result-normalize.util.js +476 -0
- package/dist/utility/chart/kscript-run-result-shape.util.d.ts +14 -0
- package/dist/utility/chart/kscript-run-result-shape.util.js +66 -0
- package/dist/utility/chart/kscript-titancharts-container.util.d.ts +29 -0
- package/dist/utility/chart/kscript-titancharts-container.util.js +151 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.d.ts +83 -0
- package/dist/utility/chart/kscript-viewport-overlays.util.js +443 -0
- package/dist/utility/chart/om-panel-push-style.util.d.ts +78 -0
- package/dist/utility/chart/om-panel-push-style.util.js +301 -0
- package/dist/utility/chart/om-panel.util.d.ts +166 -0
- package/dist/utility/chart/om-panel.util.js +815 -0
- package/dist/utility/chart/om-series.util.d.ts +42 -0
- package/dist/utility/chart/om-series.util.js +330 -0
- package/dist/utility/chart/om-target.util.d.ts +11 -0
- package/dist/utility/chart/om-target.util.js +24 -0
- package/dist/utility/chart/om-widget.util.d.ts +148 -0
- package/dist/utility/chart/om-widget.util.js +413 -0
- package/dist/utility/chart/overlay-output-budget.util.d.ts +16 -0
- package/dist/utility/chart/overlay-output-budget.util.js +109 -0
- package/dist/utility/chart/overlay-paint-flags.util.d.ts +24 -0
- package/dist/utility/chart/overlay-paint-flags.util.js +55 -0
- package/dist/utility/chart/profile-row-height.util.d.ts +21 -0
- package/dist/utility/chart/profile-row-height.util.js +110 -0
- package/dist/utility/chart/session-interval.util.d.ts +1 -0
- package/dist/utility/chart/session-interval.util.js +35 -0
- package/dist/utility/chart/technical-script-legend-value.util.d.ts +18 -0
- package/dist/utility/chart/technical-script-legend-value.util.js +53 -0
- package/dist/utility/chart/trading-day.util.d.ts +70 -0
- package/dist/utility/chart/trading-day.util.js +238 -0
- package/dist/utility/chart/wrun-legend-name.util.d.ts +25 -0
- package/dist/utility/chart/wrun-legend-name.util.js +87 -0
- package/dist/utility/chart/wrun-run-result.util.d.ts +977 -0
- package/dist/utility/chart/wrun-run-result.util.js +5179 -0
- package/dist/utility/chart/wrun-visibility-chart.util.d.ts +25 -0
- package/dist/utility/chart/wrun-visibility-chart.util.js +22 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.d.ts +62 -0
- package/dist/utility/indicators/heatmap-sensitivity.util.js +82 -0
- package/dist/utility/number-format.util.d.ts +68 -0
- package/dist/utility/number-format.util.js +188 -0
- package/dist/utility/v2/opra-governed.util.d.ts +1 -0
- package/dist/utility/v2/opra-governed.util.js +13 -0
- package/dist/utility/wrun/wrun-auto-row.util.d.ts +54 -0
- package/dist/utility/wrun/wrun-auto-row.util.js +96 -0
- package/dist/utility/wrun/wrun-batched-marks.util.d.ts +341 -0
- package/dist/utility/wrun/wrun-batched-marks.util.js +938 -0
- package/dist/utility/wrun/wrun-batched-readout.util.d.ts +75 -0
- package/dist/utility/wrun/wrun-batched-readout.util.js +171 -0
- package/dist/utility/wrun/wrun-box-segment.util.d.ts +185 -0
- package/dist/utility/wrun/wrun-box-segment.util.js +570 -0
- package/dist/utility/wrun/wrun-build-memo.util.d.ts +133 -0
- package/dist/utility/wrun/wrun-build-memo.util.js +301 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.d.ts +25 -0
- package/dist/utility/wrun/wrun-builtin-twin-ports.util.js +75 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +9 -0
- package/dist/utility/wrun/wrun-builtin-twin.util.js +40 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.d.ts +28 -0
- package/dist/utility/wrun/wrun-canvas-cache.util.js +56 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-canvas-readout.util.js +53 -0
- package/dist/utility/wrun/wrun-canvases.util.d.ts +295 -0
- package/dist/utility/wrun/wrun-canvases.util.js +1432 -0
- package/dist/utility/wrun/wrun-cap-notice.util.d.ts +77 -0
- package/dist/utility/wrun/wrun-cap-notice.util.js +296 -0
- package/dist/utility/wrun/wrun-card-style.util.d.ts +154 -0
- package/dist/utility/wrun/wrun-card-style.util.js +539 -0
- package/dist/utility/wrun/wrun-chart-context.util.d.ts +89 -0
- package/dist/utility/wrun/wrun-chart-context.util.js +213 -0
- package/dist/utility/wrun/wrun-chart-names.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-chart-names.util.js +33 -0
- package/dist/utility/wrun/wrun-chart-time.util.d.ts +12 -0
- package/dist/utility/wrun/wrun-chart-time.util.js +23 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.d.ts +13 -0
- package/dist/utility/wrun/wrun-child-overlay-id.util.js +44 -0
- package/dist/utility/wrun/wrun-color-facts.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-color-facts.util.js +88 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.d.ts +26 -0
- package/dist/utility/wrun/wrun-color-settings.lazy.js +9 -0
- package/dist/utility/wrun/wrun-color-settings.util.d.ts +351 -0
- package/dist/utility/wrun/wrun-color-settings.util.js +1363 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.d.ts +23 -0
- package/dist/utility/wrun/wrun-footprint-modes.util.js +24 -0
- package/dist/utility/wrun/wrun-frames.d.ts +217 -0
- package/dist/utility/wrun/wrun-frames.js +1021 -0
- package/dist/utility/wrun/wrun-handles.util.d.ts +792 -0
- package/dist/utility/wrun/wrun-handles.util.js +2050 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.d.ts +156 -0
- package/dist/utility/wrun/wrun-heatmap-cell-budget.util.js +342 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +218 -0
- package/dist/utility/wrun/wrun-hosted-wire-caps.js +667 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +40 -0
- package/dist/utility/wrun/wrun-hosted-wire.util.js +27 -0
- package/dist/utility/wrun/wrun-hover.util.d.ts +182 -0
- package/dist/utility/wrun/wrun-hover.util.js +534 -0
- package/dist/utility/wrun/wrun-hud-looks.util.d.ts +246 -0
- package/dist/utility/wrun/wrun-hud-looks.util.js +587 -0
- package/dist/utility/wrun/wrun-integration-budget.util.d.ts +47 -0
- package/dist/utility/wrun/wrun-integration-budget.util.js +122 -0
- package/dist/utility/wrun/wrun-latest-snapshot.d.ts +19 -0
- package/dist/utility/wrun/wrun-latest-snapshot.js +7 -0
- package/dist/utility/wrun/wrun-levels-child.util.d.ts +131 -0
- package/dist/utility/wrun/wrun-levels-child.util.js +514 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +75 -0
- package/dist/utility/wrun/wrun-lifecycle.contract.js +9 -0
- package/dist/utility/wrun/wrun-market-facts.util.d.ts +116 -0
- package/dist/utility/wrun/wrun-market-facts.util.js +238 -0
- package/dist/utility/wrun/wrun-output-style.util.d.ts +344 -0
- package/dist/utility/wrun/wrun-output-style.util.js +1239 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +84 -0
- package/dist/utility/wrun/wrun-overlay-identity.util.js +142 -0
- package/dist/utility/wrun/wrun-overlay-result.util.d.ts +120 -0
- package/dist/utility/wrun/wrun-overlay-result.util.js +219 -0
- package/dist/utility/wrun/wrun-pack.util.d.ts +70 -0
- package/dist/utility/wrun/wrun-pack.util.js +301 -0
- package/dist/utility/wrun/wrun-pane-format.util.d.ts +180 -0
- package/dist/utility/wrun/wrun-pane-format.util.js +299 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.d.ts +25 -0
- package/dist/utility/wrun/wrun-panel-style.lazy.js +15 -0
- package/dist/utility/wrun/wrun-panel-style.util.d.ts +174 -0
- package/dist/utility/wrun/wrun-panel-style.util.js +726 -0
- package/dist/utility/wrun/wrun-param-values.util.d.ts +69 -0
- package/dist/utility/wrun/wrun-param-values.util.js +230 -0
- package/dist/utility/wrun/wrun-refusal.util.d.ts +263 -0
- package/dist/utility/wrun/wrun-refusal.util.js +1259 -0
- package/dist/utility/wrun/wrun-registry-errors.util.d.ts +199 -0
- package/dist/utility/wrun/wrun-registry-errors.util.js +257 -0
- package/dist/utility/wrun/wrun-render-select.util.d.ts +336 -0
- package/dist/utility/wrun/wrun-render-select.util.js +1157 -0
- package/dist/utility/wrun/wrun-script-inputs.util.d.ts +434 -0
- package/dist/utility/wrun/wrun-script-inputs.util.js +1971 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.d.ts +20 -0
- package/dist/utility/wrun/wrun-setting-words.lazy.js +9 -0
- package/dist/utility/wrun/wrun-setting-words.util.d.ts +79 -0
- package/dist/utility/wrun/wrun-setting-words.util.js +176 -0
- package/dist/utility/wrun/wrun-socket-row-store.d.ts +98 -0
- package/dist/utility/wrun/wrun-socket-row-store.js +417 -0
- package/dist/utility/wrun/wrun-style-flags.util.d.ts +18 -0
- package/dist/utility/wrun/wrun-style-flags.util.js +21 -0
- package/dist/utility/wrun/wrun-style-words.util.d.ts +148 -0
- package/dist/utility/wrun/wrun-style-words.util.js +439 -0
- package/dist/utility/wrun/wrun-table-look.util.d.ts +125 -0
- package/dist/utility/wrun/wrun-table-look.util.js +225 -0
- package/dist/utility/wrun/wrun-text-look.util.d.ts +51 -0
- package/dist/utility/wrun/wrun-text-look.util.js +227 -0
- package/dist/utility/wrun/wrun-text-params.util.d.ts +106 -0
- package/dist/utility/wrun/wrun-text-params.util.js +171 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.d.ts +71 -0
- package/dist/utility/wrun/wrun-tpo-rows.util.js +438 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.d.ts +14 -0
- package/dist/utility/wrun/wrun-twin-compute-inputs.util.js +58 -0
- package/dist/utility/wrun/wrun-visibility-table.d.ts +437 -0
- package/dist/utility/wrun/wrun-visibility-table.js +237 -0
- package/dist/utility/wrun/wrun-volume-profile.util.d.ts +37 -0
- package/dist/utility/wrun/wrun-volume-profile.util.js +278 -0
- package/package.json +38 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The batched records' readout (WRUN-BATCHED-MARKS): a `marks`, `spans` or `rays` record's meta
|
|
3
|
+
* decode, the number formats a template (and a marks caption) prints with, and the tooltip text.
|
|
4
|
+
* The batched mount registers the text as its readout's `text` (wrun-batched-marks.util
|
|
5
|
+
* `wrunBatchedChildConfig`), so the boot-path hover inspector prints a record through the thin
|
|
6
|
+
* registry (wrun-canvas-readout.util) and never loads this module itself. A timed spans or rays
|
|
7
|
+
* record (stride 5, WRUN-MARKS-CONTRACT F2) answers `{{start}}` and `{{end}}`, printed as the
|
|
8
|
+
* chart prints a time (wrun-chart-time.util), its meta read from its fifth field.
|
|
9
|
+
*/
|
|
10
|
+
import { type WrunBatchedHoverRecord, type WrunCanvasReadout } from './wrun-canvas-readout.util.js';
|
|
11
|
+
/** A marks record's meta, `side + 4 * fills + 262144 * offset_ms`, read apart. */
|
|
12
|
+
export interface WrunMarkMeta {
|
|
13
|
+
/** 0..3: 0 sell, 1 buy (the record's colour index). */
|
|
14
|
+
side: number;
|
|
15
|
+
/** 0..65535. */
|
|
16
|
+
fills: number;
|
|
17
|
+
/** 0..2^30: the record's time inside its bar. */
|
|
18
|
+
offsetMs: number;
|
|
19
|
+
}
|
|
20
|
+
/** The largest `offset_ms` a marks meta packs (2^30 ms, 12.4 days). */
|
|
21
|
+
export declare const WRUN_MARK_META_MAX_OFFSET_MS: number;
|
|
22
|
+
/**
|
|
23
|
+
* A marks meta read apart by integer arithmetic (decode by division and modulo, exact below 2^53:
|
|
24
|
+
* the largest meta is 2^30 * 262144 + 262143 < 2^49). Null for a value that is no packed meta: not
|
|
25
|
+
* a finite whole number, negative, or past the largest offset.
|
|
26
|
+
*/
|
|
27
|
+
export declare function decodeWrunMarkMeta(meta: number): WrunMarkMeta | null;
|
|
28
|
+
/** A spans or rays record's meta, `style + 8 * word + 256 * extend`, read apart. */
|
|
29
|
+
export interface WrunSpanMeta {
|
|
30
|
+
/** 0..7: the record's colour index. */
|
|
31
|
+
style: number;
|
|
32
|
+
/** 0..31: the word index (`words[word]`). */
|
|
33
|
+
word: number;
|
|
34
|
+
/** The extend bit: the record runs on to the right edge (a span to it, a ray along its slope). */
|
|
35
|
+
extend: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** A spans or rays meta read apart, extend as the bit it is (`floor(meta / 256) % 2`, the engine's
|
|
38
|
+
* read); null for a value that is no packed meta (not a whole number from 0 to 511: a meta past
|
|
39
|
+
* the extend bit packs a field this chart does not read). */
|
|
40
|
+
export declare function decodeWrunSpanMeta(meta: number): WrunSpanMeta | null;
|
|
41
|
+
/** The `{{token}}` words a timed (stride-5) section's tooltip takes, by kind (the kit's
|
|
42
|
+
* WRUN_BATCHED_TIMED_TOOLTIP_TOKENS): `{{start}}` and `{{end}}` in place of `{{length}}`. Any other
|
|
43
|
+
* token stays as written on a timed record. */
|
|
44
|
+
export declare const WRUN_BATCHED_TIMED_TOOLTIP_TOKENS: Readonly<{
|
|
45
|
+
spans: readonly ['top', 'bottom', 'start', 'end', 'word'];
|
|
46
|
+
rays: readonly ['y1', 'y2', 'start', 'end', 'word'];
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* A timed record's start and end (epoch ms, the engine's rule): the start, or the record's own bar
|
|
50
|
+
* time when it is not a number; the end, or the start when it is not after it (a zero-length record
|
|
51
|
+
* at the start).
|
|
52
|
+
*/
|
|
53
|
+
export declare function wrunTimedRecordSpan(record: Pick<WrunBatchedHoverRecord, 'ts' | 'fields'>): [number, number];
|
|
54
|
+
/** The number formats a batched template (and a marks caption) prints with. */
|
|
55
|
+
export type WrunBatchedNumberFormat = 'compact' | 'price' | 'int';
|
|
56
|
+
/** A number in a batched format: `compact` is Big Trades 0.3.2's caption ("1.2M", "1.2K", a whole
|
|
57
|
+
* number from 100, one decimal from 1, two below 1), `int` the rounded whole number, `price` the
|
|
58
|
+
* pane's price; a negative value keeps its sign. Not finite: '-'. */
|
|
59
|
+
export declare function formatWrunBatchedNumber(value: number, format: WrunBatchedNumberFormat | 'amount', formatPrice: (value: number) => string): string;
|
|
60
|
+
/**
|
|
61
|
+
* A batched record's tooltip (WRUN-BATCHED-MARKS): `{{name}}` or `{{name:<compact|price|int>}}`.
|
|
62
|
+
* Marks read `{{side}}`, `{{qty}}` (default the full amount), `{{price}}` (default price) and
|
|
63
|
+
* `{{fills}}` (default int); spans `{{top}}` and `{{bottom}}`, rays `{{y1}}` and `{{y2}}` (default
|
|
64
|
+
* price), both `{{length}}` (the length in bars, default int) and `{{word}}` (the section's word the meta
|
|
65
|
+
* names, '' when none); a timed record (stride 5) `{{start}}` and `{{end}}` in place of `{{length}}`,
|
|
66
|
+
* each the time as the chart prints it (`formatters.formatTime`, else wrun-chart-time.util shifted by
|
|
67
|
+
* the display offset the mount door stamped on the readout), its meta its fifth field; `{{label}}` is
|
|
68
|
+
* the readout's title. A placeholder
|
|
69
|
+
* the record does not read, or a format word outside the three, stays as written; a hole (a
|
|
70
|
+
* non-finite field) prints '-'.
|
|
71
|
+
*/
|
|
72
|
+
export declare function wrunBatchedReadoutText(readout: WrunCanvasReadout, record: WrunBatchedHoverRecord, formatters: {
|
|
73
|
+
formatPrice: (value: number) => string;
|
|
74
|
+
formatTime?: (ms: number) => string;
|
|
75
|
+
}): string;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The batched records' readout (WRUN-BATCHED-MARKS): a `marks`, `spans` or `rays` record's meta
|
|
3
|
+
* decode, the number formats a template (and a marks caption) prints with, and the tooltip text.
|
|
4
|
+
* The batched mount registers the text as its readout's `text` (wrun-batched-marks.util
|
|
5
|
+
* `wrunBatchedChildConfig`), so the boot-path hover inspector prints a record through the thin
|
|
6
|
+
* registry (wrun-canvas-readout.util) and never loads this module itself. A timed spans or rays
|
|
7
|
+
* record (stride 5, WRUN-MARKS-CONTRACT F2) answers `{{start}}` and `{{end}}`, printed as the
|
|
8
|
+
* chart prints a time (wrun-chart-time.util), its meta read from its fifth field.
|
|
9
|
+
*/
|
|
10
|
+
import { CANVAS_PLACEHOLDER } from './wrun-canvas-readout.util.js';
|
|
11
|
+
import { wrunChartTimeText } from './wrun-chart-time.util.js';
|
|
12
|
+
/** The largest `offset_ms` a marks meta packs (2^30 ms, 12.4 days). */
|
|
13
|
+
export const WRUN_MARK_META_MAX_OFFSET_MS = 2 ** 30;
|
|
14
|
+
/**
|
|
15
|
+
* A marks meta read apart by integer arithmetic (decode by division and modulo, exact below 2^53:
|
|
16
|
+
* the largest meta is 2^30 * 262144 + 262143 < 2^49). Null for a value that is no packed meta: not
|
|
17
|
+
* a finite whole number, negative, or past the largest offset.
|
|
18
|
+
*/
|
|
19
|
+
export function decodeWrunMarkMeta(meta) {
|
|
20
|
+
if (!Number.isInteger(meta) || meta < 0)
|
|
21
|
+
return null;
|
|
22
|
+
const offsetMs = Math.floor(meta / 262144);
|
|
23
|
+
if (offsetMs > WRUN_MARK_META_MAX_OFFSET_MS)
|
|
24
|
+
return null;
|
|
25
|
+
return { side: meta % 4, fills: Math.floor(meta / 4) % 65536, offsetMs };
|
|
26
|
+
}
|
|
27
|
+
/** A spans or rays meta read apart, extend as the bit it is (`floor(meta / 256) % 2`, the engine's
|
|
28
|
+
* read); null for a value that is no packed meta (not a whole number from 0 to 511: a meta past
|
|
29
|
+
* the extend bit packs a field this chart does not read). */
|
|
30
|
+
export function decodeWrunSpanMeta(meta) {
|
|
31
|
+
if (!Number.isInteger(meta) || meta < 0 || meta > 511)
|
|
32
|
+
return null;
|
|
33
|
+
return { style: meta % 8, word: Math.floor(meta / 8) % 32, extend: Math.floor(meta / 256) % 2 === 1 };
|
|
34
|
+
}
|
|
35
|
+
/** The `{{token}}` words a timed (stride-5) section's tooltip takes, by kind (the kit's
|
|
36
|
+
* WRUN_BATCHED_TIMED_TOOLTIP_TOKENS): `{{start}}` and `{{end}}` in place of `{{length}}`. Any other
|
|
37
|
+
* token stays as written on a timed record. */
|
|
38
|
+
export const WRUN_BATCHED_TIMED_TOOLTIP_TOKENS = Object.freeze({
|
|
39
|
+
spans: Object.freeze(['top', 'bottom', 'start', 'end', 'word']),
|
|
40
|
+
rays: Object.freeze(['y1', 'y2', 'start', 'end', 'word']),
|
|
41
|
+
});
|
|
42
|
+
/** A timed record's field positions: `[top|y1, bottom|y2, startTs, endTs, meta]`. */
|
|
43
|
+
const TIMED_START = 2;
|
|
44
|
+
const TIMED_END = 3;
|
|
45
|
+
const TIMED_META = 4;
|
|
46
|
+
/**
|
|
47
|
+
* A timed record's start and end (epoch ms, the engine's rule): the start, or the record's own bar
|
|
48
|
+
* time when it is not a number; the end, or the start when it is not after it (a zero-length record
|
|
49
|
+
* at the start).
|
|
50
|
+
*/
|
|
51
|
+
export function wrunTimedRecordSpan(record) {
|
|
52
|
+
const at = (index) => {
|
|
53
|
+
const value = record.fields[index];
|
|
54
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : Number.NaN;
|
|
55
|
+
};
|
|
56
|
+
const written = at(TIMED_START);
|
|
57
|
+
const start = Number.isFinite(written) ? written : record.ts;
|
|
58
|
+
const end = at(TIMED_END);
|
|
59
|
+
return [start, Number.isFinite(end) && end > start ? end : start];
|
|
60
|
+
}
|
|
61
|
+
const BATCHED_FORMATS = new Set(['compact', 'price', 'int']);
|
|
62
|
+
/** `tenths` (a whole count of tenths) as "1.5" or "2" (never "2.0"). */
|
|
63
|
+
function tenthsText(tenths) {
|
|
64
|
+
const whole = Math.trunc(tenths / 10);
|
|
65
|
+
const rest = Math.abs(tenths % 10);
|
|
66
|
+
return rest === 0 ? String(whole) : `${whole}.${rest}`;
|
|
67
|
+
}
|
|
68
|
+
/** The full amount (Big Trades 0.3.2's hover size): >= 100 whole, >= 1 one decimal (a trailing
|
|
69
|
+
* ".0" dropped), below 1 two decimals ("0.50"). */
|
|
70
|
+
function amountText(value) {
|
|
71
|
+
if (value >= 100)
|
|
72
|
+
return String(Math.round(value));
|
|
73
|
+
if (value >= 1)
|
|
74
|
+
return tenthsText(Math.round(value * 10));
|
|
75
|
+
return (Math.round(value * 100) / 100).toFixed(2);
|
|
76
|
+
}
|
|
77
|
+
/** A number in a batched format: `compact` is Big Trades 0.3.2's caption ("1.2M", "1.2K", a whole
|
|
78
|
+
* number from 100, one decimal from 1, two below 1), `int` the rounded whole number, `price` the
|
|
79
|
+
* pane's price; a negative value keeps its sign. Not finite: '-'. */
|
|
80
|
+
export function formatWrunBatchedNumber(value, format, formatPrice) {
|
|
81
|
+
if (!Number.isFinite(value))
|
|
82
|
+
return '-';
|
|
83
|
+
if (format === 'price')
|
|
84
|
+
return formatPrice(value);
|
|
85
|
+
if (format === 'int')
|
|
86
|
+
return String(Math.round(value));
|
|
87
|
+
const sign = value < 0 ? '-' : '';
|
|
88
|
+
const size = Math.abs(value);
|
|
89
|
+
if (format === 'amount')
|
|
90
|
+
return `${sign}${amountText(size)}`;
|
|
91
|
+
if (size >= 1_000_000)
|
|
92
|
+
return `${sign}${tenthsText(Math.round(size / 100_000))}M`;
|
|
93
|
+
if (size >= 1_000)
|
|
94
|
+
return `${sign}${tenthsText(Math.round(size / 100))}K`;
|
|
95
|
+
return `${sign}${amountText(size)}`;
|
|
96
|
+
}
|
|
97
|
+
/** The side words `{{side}}` prints, the template's own register (the author writes the template
|
|
98
|
+
* around them, as Big Trades 0.3.2's module wrote "Buy" and "Sell"). Sides 2 and 3 print their
|
|
99
|
+
* number. */
|
|
100
|
+
const SIDE_WORDS = { 0: 'Sell', 1: 'Buy' };
|
|
101
|
+
/**
|
|
102
|
+
* A batched record's tooltip (WRUN-BATCHED-MARKS): `{{name}}` or `{{name:<compact|price|int>}}`.
|
|
103
|
+
* Marks read `{{side}}`, `{{qty}}` (default the full amount), `{{price}}` (default price) and
|
|
104
|
+
* `{{fills}}` (default int); spans `{{top}}` and `{{bottom}}`, rays `{{y1}}` and `{{y2}}` (default
|
|
105
|
+
* price), both `{{length}}` (the length in bars, default int) and `{{word}}` (the section's word the meta
|
|
106
|
+
* names, '' when none); a timed record (stride 5) `{{start}}` and `{{end}}` in place of `{{length}}`,
|
|
107
|
+
* each the time as the chart prints it (`formatters.formatTime`, else wrun-chart-time.util shifted by
|
|
108
|
+
* the display offset the mount door stamped on the readout), its meta its fifth field; `{{label}}` is
|
|
109
|
+
* the readout's title. A placeholder
|
|
110
|
+
* the record does not read, or a format word outside the three, stays as written; a hole (a
|
|
111
|
+
* non-finite field) prints '-'.
|
|
112
|
+
*/
|
|
113
|
+
export function wrunBatchedReadoutText(readout, record, formatters) {
|
|
114
|
+
const field = (at) => {
|
|
115
|
+
const value = record.fields[at];
|
|
116
|
+
return typeof value === 'number' ? value : Number.NaN;
|
|
117
|
+
};
|
|
118
|
+
const timed = readout.timed === true && (readout.kind === 'spans' || readout.kind === 'rays');
|
|
119
|
+
const markMeta = readout.kind === 'marks' ? decodeWrunMarkMeta(field(2)) : null;
|
|
120
|
+
const spanMeta = readout.kind === 'spans' || readout.kind === 'rays' ? decodeWrunSpanMeta(field(timed ? TIMED_META : 3)) : null;
|
|
121
|
+
// A printed time never breaks across the card's lines: its words are joined by no-break spaces.
|
|
122
|
+
const timeText = (ms) => {
|
|
123
|
+
const text = formatters.formatTime !== undefined
|
|
124
|
+
? formatters.formatTime(ms)
|
|
125
|
+
: wrunChartTimeText(ms + (readout.timeOffsetMs ?? 0));
|
|
126
|
+
return text === undefined ? '-' : text.replace(/ /g, '\u00a0');
|
|
127
|
+
};
|
|
128
|
+
const number = (value, written, fallback) => formatWrunBatchedNumber(value, written !== undefined ? written : fallback, formatters.formatPrice);
|
|
129
|
+
return readout.tooltip.replace(CANVAS_PLACEHOLDER, (literal, name, format) => {
|
|
130
|
+
if (format !== undefined && !BATCHED_FORMATS.has(format))
|
|
131
|
+
return literal;
|
|
132
|
+
if (name === 'label')
|
|
133
|
+
return readout.label;
|
|
134
|
+
if (readout.kind === 'marks') {
|
|
135
|
+
switch (name) {
|
|
136
|
+
case 'side':
|
|
137
|
+
return markMeta === null ? '-' : (SIDE_WORDS[markMeta.side] ?? String(markMeta.side));
|
|
138
|
+
case 'qty':
|
|
139
|
+
return number(field(1), format, 'amount');
|
|
140
|
+
case 'price':
|
|
141
|
+
return number(field(0), format, 'price');
|
|
142
|
+
case 'fills':
|
|
143
|
+
return markMeta === null ? '-' : number(markMeta.fills, format, 'int');
|
|
144
|
+
default:
|
|
145
|
+
return literal;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const first = readout.kind === 'spans' ? 'top' : 'y1';
|
|
149
|
+
const second = readout.kind === 'spans' ? 'bottom' : 'y2';
|
|
150
|
+
if (timed &&
|
|
151
|
+
!WRUN_BATCHED_TIMED_TOOLTIP_TOKENS[readout.kind].includes(name)) {
|
|
152
|
+
return literal;
|
|
153
|
+
}
|
|
154
|
+
switch (name) {
|
|
155
|
+
case first:
|
|
156
|
+
return number(field(0), format, 'price');
|
|
157
|
+
case second:
|
|
158
|
+
return number(field(1), format, 'price');
|
|
159
|
+
case 'length':
|
|
160
|
+
return number(field(2), format, 'int');
|
|
161
|
+
case 'start':
|
|
162
|
+
return timed ? timeText(wrunTimedRecordSpan(record)[0]) : literal;
|
|
163
|
+
case 'end':
|
|
164
|
+
return timed ? timeText(wrunTimedRecordSpan(record)[1]) : literal;
|
|
165
|
+
case 'word':
|
|
166
|
+
return spanMeta === null ? '' : (readout.words?.[spanMeta.word] ?? '');
|
|
167
|
+
default:
|
|
168
|
+
return literal;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boxes and segments: per-bar geometry an Indicator package declares on its
|
|
3
|
+
* sheet (`wrun/metadata.json` `boxes` / `segments`) over outputs that already
|
|
4
|
+
* stream, evaluated by the host from the output rows it holds. No wire
|
|
5
|
+
* record carries the geometry: every anchor is a declared numeric output or
|
|
6
|
+
* a literal bar offset, so the sheet additions are legal under wrun-1 and
|
|
7
|
+
* wrun-2 alike and the wasm ABI is untouched.
|
|
8
|
+
*
|
|
9
|
+
* Sheet contract (frozen across hosts):
|
|
10
|
+
* - `boxes[]`: `{ name, top, bottom, x_from, x_to, when, panel, color,
|
|
11
|
+
* border_color, opacity (0..1, default 0.2), border_width (0..10,
|
|
12
|
+
* default 1) }`, at most 16. PT-box-ladder (WRUN-STYLE g2) adds the
|
|
13
|
+
* per-bar colour ladders: `color_by` + `colors` (1..64) or
|
|
14
|
+
* `color_packed_by` for the fill, `border_color_by` + `border_colors`
|
|
15
|
+
* (1..64) or `border_color_packed_by` for the border; a `_by` and its
|
|
16
|
+
* palette come together and never beside the packed form, every name a
|
|
17
|
+
* declared output (data-only ones included).
|
|
18
|
+
* - Every colour key also takes a theme token (`theme.up` ... `theme.accent`,
|
|
19
|
+
* TH-theme-tokens) beside its own grammar; the token rides to the paint
|
|
20
|
+
* pass unresolved.
|
|
21
|
+
* - `segments[]`: `{ name, y_from, y_to, x_from, x_to, when, panel, color,
|
|
22
|
+
* width (0.5..20, default 1), line_style (solid|dashed|dotted, default
|
|
23
|
+
* solid) }`, at most 16.
|
|
24
|
+
* - `x_from` / `x_to` are bar OFFSETS relative to the evaluated bar
|
|
25
|
+
* (negative = past), either a literal in [-500, 500], whole or
|
|
26
|
+
* fractional, or the name of an output whose per-bar value is truncated
|
|
27
|
+
* to an integer; both default 0. `when` optionally gates the bar (drawn
|
|
28
|
+
* only when finite and nonzero). `panel` defaults to the panel of the
|
|
29
|
+
* first y output.
|
|
30
|
+
*
|
|
31
|
+
* Per-bar semantics (`evaluateWrunSpans`): on the run's row grid, bar i
|
|
32
|
+
* draws nothing when the row is not ready, when any referenced output
|
|
33
|
+
* (y anchors, output-valued offsets, `when`) is non-finite there, or when
|
|
34
|
+
* `when` is 0; otherwise the span runs from row i + x_from to row i + x_to
|
|
35
|
+
* (a fractional literal anchors on the row of its whole bars) with anchors
|
|
36
|
+
* clamped to the loaded range's edges, carrying both y values in declared
|
|
37
|
+
* order. An edge's time is om's one placement rule (`wrunSpanEdgeTs`, the
|
|
38
|
+
* vendored wrunShapeEdgeTs): the whole bars on the row grid, a fraction
|
|
39
|
+
* as that share of the run's bar interval, where the kScript engine draws
|
|
40
|
+
* `bars.time[0] - currentInterval * 0.5`. The chart adapter shapes the
|
|
41
|
+
* spans into the kScript engine's own per-bar records (a box = a plotRange
|
|
42
|
+
* record, a segment = a per-bar line drawing), so the forming bar's
|
|
43
|
+
* re-evaluation on every tick REPLACES its record instead of stacking one.
|
|
44
|
+
*
|
|
45
|
+
* The vendored indicator kit types the raw sheet arrays as `WrunBox` /
|
|
46
|
+
* `WrunSegment` (every style field optional). This util reads
|
|
47
|
+
* them as untyped parsed JSON on purpose (a malformed sheet must refuse by
|
|
48
|
+
* name, not typecheck its way past) and hands back the defaults-applied
|
|
49
|
+
* `WrunBoxSpec` / `WrunSegmentSpec` forms the chart adapter consumes.
|
|
50
|
+
*
|
|
51
|
+
* The sheet's `strategy` section (wrun-3, OM-WRUN3-STRATEGIES-CONTRACT
|
|
52
|
+
* section 3) is read here too, in the same style: `readWrunStrategySheet`
|
|
53
|
+
* validates the section with the om validator's wording (every field
|
|
54
|
+
* optional, the engine's own value rules, `{ "param": "<name>" }` links on
|
|
55
|
+
* numeric fields, the four cross-field refusals by name) and hands the
|
|
56
|
+
* validated section to the shared host's resolver
|
|
57
|
+
* (`resolveWrunStrategySheet`, through the seam), which turns it into the
|
|
58
|
+
* engine's declared config at run time. The rows side table at the
|
|
59
|
+
* bottom (`attachWrunStrategy` / `wrunStrategyOf`) carries a run's
|
|
60
|
+
* `StrategyOutput` from the host to the run-result adapter the way the
|
|
61
|
+
* handle set travels.
|
|
62
|
+
*/
|
|
63
|
+
import type { WrunIndicatorMetadata, WrunOutputRow } from '../../interfaces/wrun-runtime.interface.js';
|
|
64
|
+
import type { StrategyOutput, WrunStrategySheet } from '@orangecharts/indicator-kit/host';
|
|
65
|
+
export declare const WRUN_BOX_CAP = 16;
|
|
66
|
+
export declare const WRUN_SEGMENT_CAP = 16;
|
|
67
|
+
/** A box colour ladder (`colors`, `border_colors`) lists 1..64 colours. */
|
|
68
|
+
export declare const WRUN_BOX_LADDER_CAP = 64;
|
|
69
|
+
type WrunBarOffsetRef = string | number;
|
|
70
|
+
export type WrunVisualPanel = 'overlay' | 'lower';
|
|
71
|
+
type WrunSegmentLineStyle = 'solid' | 'dashed' | 'dotted';
|
|
72
|
+
export interface WrunBoxSpec {
|
|
73
|
+
name: string;
|
|
74
|
+
top: string;
|
|
75
|
+
bottom: string;
|
|
76
|
+
x_from: WrunBarOffsetRef;
|
|
77
|
+
x_to: WrunBarOffsetRef;
|
|
78
|
+
when?: string;
|
|
79
|
+
panel?: WrunVisualPanel;
|
|
80
|
+
color?: string;
|
|
81
|
+
border_color?: string;
|
|
82
|
+
/** Fill alpha, 0..1. */
|
|
83
|
+
opacity: number;
|
|
84
|
+
/** Border stroke width, 0..10 (0 = no visible border). */
|
|
85
|
+
border_width: number;
|
|
86
|
+
/** PT-box-ladder: the output whose floor picks the bar's fill colour from
|
|
87
|
+
* `colors` (1..64, hex, rgb(), hsl() or a theme token), or an output of
|
|
88
|
+
* packed rgba; the same pair for the border. */
|
|
89
|
+
color_by?: string;
|
|
90
|
+
colors?: string[];
|
|
91
|
+
color_packed_by?: string;
|
|
92
|
+
border_color_by?: string;
|
|
93
|
+
border_colors?: string[];
|
|
94
|
+
border_color_packed_by?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface WrunSegmentSpec {
|
|
97
|
+
name: string;
|
|
98
|
+
y_from: string;
|
|
99
|
+
y_to: string;
|
|
100
|
+
x_from: WrunBarOffsetRef;
|
|
101
|
+
x_to: WrunBarOffsetRef;
|
|
102
|
+
when?: string;
|
|
103
|
+
panel?: WrunVisualPanel;
|
|
104
|
+
color?: string;
|
|
105
|
+
/** Stroke width, 0.5..20. */
|
|
106
|
+
width: number;
|
|
107
|
+
line_style: WrunSegmentLineStyle;
|
|
108
|
+
}
|
|
109
|
+
/** The sheet fields this util reads; a package metadata object may carry
|
|
110
|
+
* them beside the kit-typed fields. */
|
|
111
|
+
export interface WrunBoxSegmentSheet {
|
|
112
|
+
boxes?: unknown;
|
|
113
|
+
segments?: unknown;
|
|
114
|
+
}
|
|
115
|
+
/** One evaluated bar: the two x anchors as CLAMPED row indexes in declared
|
|
116
|
+
* order (a fractional offset's row is the row of its whole bars) and the
|
|
117
|
+
* two y values in declared order. */
|
|
118
|
+
export interface WrunBarSpan {
|
|
119
|
+
fromRow: number;
|
|
120
|
+
toRow: number;
|
|
121
|
+
a: number;
|
|
122
|
+
b: number;
|
|
123
|
+
}
|
|
124
|
+
export interface WrunSpanRefs {
|
|
125
|
+
/** First y anchor (a box's `top`, a segment's `y_from`). */
|
|
126
|
+
a: string;
|
|
127
|
+
/** Second y anchor (a box's `bottom`, a segment's `y_to`). */
|
|
128
|
+
b: string;
|
|
129
|
+
x_from: WrunBarOffsetRef;
|
|
130
|
+
x_to: WrunBarOffsetRef;
|
|
131
|
+
when?: string;
|
|
132
|
+
}
|
|
133
|
+
export declare function isWrunAlphaColor(color: string): boolean;
|
|
134
|
+
/** The sheet's `boxes`, defaults applied, refused by name on a bad
|
|
135
|
+
* declaration (cap, cross-reference, offset, style range). Absent = []. */
|
|
136
|
+
export declare function readWrunBoxSpecs(metadata: WrunIndicatorMetadata): WrunBoxSpec[];
|
|
137
|
+
/** The sheet's `segments`, defaults applied, refused by name on a bad
|
|
138
|
+
* declaration. Absent = []. */
|
|
139
|
+
export declare function readWrunSegmentSpecs(metadata: WrunIndicatorMetadata): WrunSegmentSpec[];
|
|
140
|
+
/** Evaluate one declaration's spans over the row grid: one entry per row,
|
|
141
|
+
* `null` where the bar draws nothing. `outputIndexByName` maps declared
|
|
142
|
+
* output names to their column; every reference in `refs` must resolve
|
|
143
|
+
* (the readers above guarantee it for sheet declarations). */
|
|
144
|
+
export declare function evaluateWrunSpans(rows: ReadonlyArray<WrunOutputRow>, outputIndexByName: ReadonlyMap<string, number>, refs: WrunSpanRefs): Array<WrunBarSpan | null>;
|
|
145
|
+
/** The time a box or segment edge sits at: `offset` (a literal as written,
|
|
146
|
+
* an output-valued one already truncated) from the bar at `rowAt`, its
|
|
147
|
+
* whole bars through `rowTs` (the run's row grid, with the adapter's reach
|
|
148
|
+
* past the loaded rows) and its fraction as that share of `intervalMs`
|
|
149
|
+
* (the run's bar interval, kScript's currentInterval). om's one placement
|
|
150
|
+
* rule, vendored verbatim: a whole offset is exactly its row's time. */
|
|
151
|
+
export declare function wrunSpanEdgeTs(rowTs: (rowAt: number) => number, rowAt: number, offset: number, intervalMs: number): number;
|
|
152
|
+
/** The sheet field this util reads; a package metadata object carries it
|
|
153
|
+
* beside the kit-typed fields. The kit types it as `WrunStrategy`; this
|
|
154
|
+
* util reads it untyped on purpose, like the boxes and segments above (a
|
|
155
|
+
* malformed sheet must refuse by name, not typecheck its way past). */
|
|
156
|
+
export interface WrunStrategySheetHolder {
|
|
157
|
+
strategy?: unknown;
|
|
158
|
+
}
|
|
159
|
+
/** True when the sheet declares the strategy section (an Indicator that
|
|
160
|
+
* runs the broker), whatever the section holds. */
|
|
161
|
+
export declare function isWrunStrategySheet(metadata: WrunIndicatorMetadata | WrunStrategySheetHolder): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* The sheet's `strategy` section, validated, or undefined when the sheet
|
|
164
|
+
* declares none. Every refusal names the sheet and the field in the om
|
|
165
|
+
* validator's words; the section itself comes back verbatim (literals and
|
|
166
|
+
* `{ "param": ... }` links, no default injected), the form the shared
|
|
167
|
+
* host's `resolveWrunStrategySheet` resolves against the instance's
|
|
168
|
+
* params at run time. Read during a run only (the host loaded first). Cross-field rules, each refusing by name:
|
|
169
|
+
* - a param link names a declared param (`wrun_strategy_*` links resolve at
|
|
170
|
+
* init() from the instance's params);
|
|
171
|
+
* - `slippage_model: "bookEstimate"` needs an order book provider no host
|
|
172
|
+
* supplies in this rung (`wrun_strategy_slippage_model_unsupported`);
|
|
173
|
+
* - the primary input (index 0) is the broker feed, so it reads source
|
|
174
|
+
* class `ohlcv` on the instance's own market (`wrun_strategy_feed_not_ohlcv`);
|
|
175
|
+
* - `strategy.position` and `strategy.equity` are host-published and
|
|
176
|
+
* reserved across the chart-name namespace (`wrun_strategy_reserved_output`).
|
|
177
|
+
*/
|
|
178
|
+
export declare function readWrunStrategySheet(metadata: WrunIndicatorMetadata): WrunStrategySheet | undefined;
|
|
179
|
+
/** The instance's params by declared name from init()'s positional
|
|
180
|
+
* argument block (`buildWrunInitArgs` order), the values a
|
|
181
|
+
* `{ "param": ... }` link resolves from. */
|
|
182
|
+
export declare function wrunStrategyParamsOf(metadata: Pick<WrunIndicatorMetadata, 'params'>, initArgs: readonly number[]): Record<string, number>;
|
|
183
|
+
export declare function attachWrunStrategy(rows: ReadonlyArray<WrunOutputRow>, strategy: StrategyOutput): void;
|
|
184
|
+
export declare function wrunStrategyOf(rows: ReadonlyArray<WrunOutputRow>): StrategyOutput | undefined;
|
|
185
|
+
export {};
|