openalgo-script 0.7.1 → 0.8.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/CHANGELOG.md +89 -0
- package/README.md +22 -9
- package/dist/adapters/charts/capabilities.d.ts +48 -0
- package/dist/adapters/charts/capabilities.d.ts.map +1 -0
- package/dist/adapters/charts/capabilities.js +82 -0
- package/dist/adapters/charts/capabilities.js.map +1 -0
- package/dist/adapters/charts/columns.d.ts +2 -0
- package/dist/adapters/charts/columns.d.ts.map +1 -1
- package/dist/adapters/charts/columns.js +4 -0
- package/dist/adapters/charts/columns.js.map +1 -1
- package/dist/adapters/charts/contract.d.ts +35 -3
- package/dist/adapters/charts/contract.d.ts.map +1 -1
- package/dist/adapters/charts/descriptor.d.ts +1 -1
- package/dist/adapters/charts/descriptor.d.ts.map +1 -1
- package/dist/adapters/charts/descriptor.js +17 -5
- package/dist/adapters/charts/descriptor.js.map +1 -1
- package/dist/adapters/charts/fills.d.ts +26 -5
- package/dist/adapters/charts/fills.d.ts.map +1 -1
- package/dist/adapters/charts/fills.js +55 -7
- package/dist/adapters/charts/fills.js.map +1 -1
- package/dist/adapters/charts/index.d.ts +9 -3
- package/dist/adapters/charts/index.d.ts.map +1 -1
- package/dist/adapters/charts/index.js +7 -1
- package/dist/adapters/charts/index.js.map +1 -1
- package/dist/adapters/charts/produced.d.ts +3 -2
- package/dist/adapters/charts/produced.d.ts.map +1 -1
- package/dist/adapters/charts/produced.js +1 -1
- package/dist/adapters/charts/produced.js.map +1 -1
- package/dist/adapters/charts/run.d.ts +23 -0
- package/dist/adapters/charts/run.d.ts.map +1 -1
- package/dist/adapters/charts/run.js +2 -1
- package/dist/adapters/charts/run.js.map +1 -1
- package/dist/adapters/charts/surfaces.d.ts +11 -0
- package/dist/adapters/charts/surfaces.d.ts.map +1 -1
- package/dist/adapters/charts/tables.d.ts +21 -11
- package/dist/adapters/charts/tables.d.ts.map +1 -1
- package/dist/adapters/charts/tables.js +17 -6
- package/dist/adapters/charts/tables.js.map +1 -1
- package/dist/adapters/charts/undrawable.d.ts +2 -1
- package/dist/adapters/charts/undrawable.d.ts.map +1 -1
- package/dist/adapters/charts/undrawable.js +24 -14
- package/dist/adapters/charts/undrawable.js.map +1 -1
- package/dist/core/stdlib/volume/accumulation.d.ts +14 -0
- package/dist/core/stdlib/volume/accumulation.d.ts.map +1 -1
- package/dist/core/stdlib/volume/accumulation.js +32 -2
- package/dist/core/stdlib/volume/accumulation.js.map +1 -1
- package/dist/core/stdlib/volume/flow.d.ts.map +1 -1
- package/dist/core/stdlib/volume/flow.js +3 -1
- package/dist/core/stdlib/volume/flow.js.map +1 -1
- package/dist/core/stdlib/volume/weighted.d.ts +7 -0
- package/dist/core/stdlib/volume/weighted.d.ts.map +1 -1
- package/dist/core/stdlib/volume/weighted.js +15 -3
- package/dist/core/stdlib/volume/weighted.js.map +1 -1
- package/dist/core/version/version.generated.d.ts +1 -1
- package/dist/core/version/version.generated.js +1 -1
- package/package.json +1 -1
- package/src/adapters/charts/capabilities.ts +103 -0
- package/src/adapters/charts/columns.ts +5 -0
- package/src/adapters/charts/contract.ts +36 -2
- package/src/adapters/charts/descriptor.ts +21 -6
- package/src/adapters/charts/fills.ts +95 -11
- package/src/adapters/charts/index.ts +9 -1
- package/src/adapters/charts/produced.ts +4 -3
- package/src/adapters/charts/run.ts +25 -1
- package/src/adapters/charts/surfaces.ts +12 -0
- package/src/adapters/charts/tables.ts +31 -14
- package/src/adapters/charts/undrawable.ts +24 -14
- package/src/core/stdlib/volume/accumulation.ts +37 -2
- package/src/core/stdlib/volume/flow.ts +3 -1
- package/src/core/stdlib/volume/weighted.ts +14 -3
- package/src/core/version/version.generated.ts +1 -1
|
@@ -7,13 +7,21 @@ import { emaStep } from '../averages/index.js';
|
|
|
7
7
|
* A bar whose high and low are equal has no position inside it to report, and
|
|
8
8
|
* the settled treatment is that such a bar contributes nothing rather than
|
|
9
9
|
* ending the running total.
|
|
10
|
+
*
|
|
11
|
+
* A span that overflows is not that bar. It is absent (`compiled-program.md`
|
|
12
|
+
* section 3.1), and so is the term, because the one later step that could hide
|
|
13
|
+
* it is this division: a finite numerator over an infinite span is an exact
|
|
14
|
+
* zero, a term for a bar whose position was never computed. Every other step
|
|
15
|
+
* that overflows stays non-finite to the end and the last check catches it.
|
|
10
16
|
*/
|
|
11
17
|
export function moneyFlow(bar) {
|
|
12
18
|
if (!isPresent(bar.high) || !isPresent(bar.low))
|
|
13
19
|
return NONE;
|
|
14
20
|
if (!isPresent(bar.close) || !isPresent(bar.volume))
|
|
15
21
|
return NONE;
|
|
16
|
-
const span = bar.high - bar.low;
|
|
22
|
+
const span = result(bar.high - bar.low);
|
|
23
|
+
if (!isPresent(span))
|
|
24
|
+
return NONE;
|
|
17
25
|
if (!(span > 0))
|
|
18
26
|
return 0;
|
|
19
27
|
return result((((bar.close - bar.low) - (bar.high - bar.close)) / span) * bar.volume);
|
|
@@ -89,6 +97,25 @@ export function adOscTail(fast = 3, slow = 10) {
|
|
|
89
97
|
export function adOsc(bars, fast = 3, slow = 10) {
|
|
90
98
|
return fold(adOscTail(fast, slow), bars);
|
|
91
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* The per-bar term `pvt` adds: the change, then the proportion, then the
|
|
102
|
+
* product with the volume, each checked as it is formed.
|
|
103
|
+
*
|
|
104
|
+
* A change can overflow although the true proportion is finite: a close of
|
|
105
|
+
* -1e308 after one of 1e308 is a proportion of -2. Section 3.1 makes that change
|
|
106
|
+
* absent, and so the term. Each step is checked where it rounds because that is
|
|
107
|
+
* how the rule is stated, not because a later step could turn an infinity back
|
|
108
|
+
* into a number here: none of these three can.
|
|
109
|
+
*/
|
|
110
|
+
function trendTerm(close, before, volume) {
|
|
111
|
+
const change = result(close - before);
|
|
112
|
+
if (!isPresent(change))
|
|
113
|
+
return NONE;
|
|
114
|
+
const proportion = result(change / before);
|
|
115
|
+
if (!isPresent(proportion))
|
|
116
|
+
return NONE;
|
|
117
|
+
return result(proportion * volume);
|
|
118
|
+
}
|
|
92
119
|
/**
|
|
93
120
|
* `pvt()`: the running total of volume weighted by percentage change, from bar
|
|
94
121
|
* 1, seeded 0.
|
|
@@ -112,7 +139,10 @@ export function pvtStep(state, key, bar) {
|
|
|
112
139
|
return NONE;
|
|
113
140
|
if (!isPresent(bar.close) || !isPresent(bar.volume))
|
|
114
141
|
return NONE;
|
|
115
|
-
const
|
|
142
|
+
const term = trendTerm(bar.close, before, bar.volume);
|
|
143
|
+
if (!isPresent(term))
|
|
144
|
+
return NONE;
|
|
145
|
+
const total = slot(state, totalKey, 0) + term;
|
|
116
146
|
state[totalKey] = total;
|
|
117
147
|
return result(total);
|
|
118
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accumulation.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/accumulation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"accumulation.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/accumulation.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,GAAQ;IAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,IAA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C,CAAC,GAAG,IAAI,CAAC;IAC9C,KAAK,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;IACxB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,yBAAyB;AACzB,MAAM,UAAU,OAAO;IACrB,OAAO,MAAM,CAAC,CAAC,KAAK,EAAE,GAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,GAAG,CAAC,IAAoB;IACtC,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/flow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOxE,kGAAkG;AAClG,wBAAgB,OAAO,CACrB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,KAAK,
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/flow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAOxE,kGAAkG;AAClG,wBAAgB,OAAO,CACrB,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,KAAK,CAOP;AAED,4BAA4B;AAC5B,wBAAgB,OAAO,CAAC,GAAG,SAAK,GAAG,I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,GAAG,EAAE,EAAE,GAAG,SAAK,GAAG,KAAK,EAAE,CAElE;AAED,gGAAgG;AAChG,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,KAAK,EACb,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,KAAK,CAIP;AAED,uCAAuC;AACvC,wBAAgB,kBAAkB,CAAC,GAAG,SAAK,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAE7D;AAED,gDAAgD;AAChD,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,SAAK,GAAG,KAAK,EAAE,CAEtE"}
|
|
@@ -6,7 +6,9 @@ import { moneyFlow } from './accumulation.js';
|
|
|
6
6
|
export function cmfStep(state, key, bar, len) {
|
|
7
7
|
const flow = sumStep(state, `${key}f`, moneyFlow(bar), len);
|
|
8
8
|
const traded = sumStep(state, `${key}v`, bar.volume, len);
|
|
9
|
-
|
|
9
|
+
// A ratio is absent where its divisor is zero, and only there: a window whose
|
|
10
|
+
// volume sums below zero divides like any other.
|
|
11
|
+
if (!isPresent(flow) || !isPresent(traded) || traded === 0)
|
|
10
12
|
return NONE;
|
|
11
13
|
return result(flow / traded);
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/flow.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,k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AC,IAAoB,EAAE,GAAG,GAAG,EAAE;IAC3D,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -27,6 +27,13 @@ export interface Anchored {
|
|
|
27
27
|
* The bar the condition holds on is the first bar of the new average, not the
|
|
28
28
|
* last bar of the old one. Absent before the condition has ever been true,
|
|
29
29
|
* because there is no anchor to measure from and zero would read as a price.
|
|
30
|
+
*
|
|
31
|
+
* A price times volume that overflows is an absent term (`compiled-program.md`
|
|
32
|
+
* section 3.1): the bar is absent and neither total moves, so the bar costs its
|
|
33
|
+
* own reading and nothing after it. A total that overflows is kept as the
|
|
34
|
+
* arithmetic produced it and is absent, so the average divided by it is absent
|
|
35
|
+
* until the next anchor rather than the exact zero a finite flow over an
|
|
36
|
+
* infinite volume would give.
|
|
30
37
|
*/
|
|
31
38
|
export declare function vwapAnchorStep(state: StateRecord, key: string, input: Anchored): Value;
|
|
32
39
|
/** `vwapAnchor(src, resetWhen)` as a tail. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weighted.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3E,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED
|
|
1
|
+
{"version":3,"file":"weighted.d.ts","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3E,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAqBtF;AAED,8CAA8C;AAC9C,wBAAgB,cAAc,IAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAEtD;AAED,sDAAsD;AACtD,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,OAAO,EAAE,GAC5B,KAAK,EAAE,CAST;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAEhD;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,KAAK,CAEhF;AAED,qCAAqC;AACrC,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,OAAO,EAAE,GAC/B,KAAK,EAAE,CAET"}
|
|
@@ -5,6 +5,13 @@ import { NONE, flag, fold, isPresent, result, slot, tailOf } from '../values/ind
|
|
|
5
5
|
* The bar the condition holds on is the first bar of the new average, not the
|
|
6
6
|
* last bar of the old one. Absent before the condition has ever been true,
|
|
7
7
|
* because there is no anchor to measure from and zero would read as a price.
|
|
8
|
+
*
|
|
9
|
+
* A price times volume that overflows is an absent term (`compiled-program.md`
|
|
10
|
+
* section 3.1): the bar is absent and neither total moves, so the bar costs its
|
|
11
|
+
* own reading and nothing after it. A total that overflows is kept as the
|
|
12
|
+
* arithmetic produced it and is absent, so the average divided by it is absent
|
|
13
|
+
* until the next anchor rather than the exact zero a finite flow over an
|
|
14
|
+
* infinite volume would give.
|
|
8
15
|
*/
|
|
9
16
|
export function vwapAnchorStep(state, key, input) {
|
|
10
17
|
const flowKey = `${key}f`;
|
|
@@ -19,13 +26,18 @@ export function vwapAnchorStep(state, key, input) {
|
|
|
19
26
|
return NONE;
|
|
20
27
|
if (!isPresent(input.src) || !isPresent(input.volume))
|
|
21
28
|
return NONE;
|
|
22
|
-
const
|
|
29
|
+
const term = result(input.src * input.volume);
|
|
30
|
+
if (!isPresent(term))
|
|
31
|
+
return NONE;
|
|
32
|
+
const flow = slot(state, flowKey, 0) + term;
|
|
23
33
|
const traded = slot(state, tradedKey, 0) + input.volume;
|
|
24
34
|
state[flowKey] = flow;
|
|
25
35
|
state[tradedKey] = traded;
|
|
26
|
-
|
|
36
|
+
const numerator = result(flow);
|
|
37
|
+
const divisor = result(traded);
|
|
38
|
+
if (!isPresent(numerator) || !isPresent(divisor) || divisor === 0)
|
|
27
39
|
return NONE;
|
|
28
|
-
return result(
|
|
40
|
+
return result(numerator / divisor);
|
|
29
41
|
}
|
|
30
42
|
/** `vwapAnchor(src, resetWhen)` as a tail. */
|
|
31
43
|
export function vwapAnchorTail() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weighted.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AASvF
|
|
1
|
+
{"version":3,"file":"weighted.js","sourceRoot":"","sources":["../../../../src/core/stdlib/volume/weighted.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,E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ILED_FORMAT_VERSION from
|
|
4
4
|
// spec/compiled-program.md, so neither can drift from the thing it names.
|
|
5
5
|
/** This build's package version. The release refuses to publish unless the tag, the manifest and this agree. */
|
|
6
|
-
export const VERSION = "0.
|
|
6
|
+
export const VERSION = "0.8.0";
|
|
7
7
|
/**
|
|
8
8
|
* The compiled program format this compiler emits.
|
|
9
9
|
*
|
package/package.json
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host's chart can draw, read from the version the host states.
|
|
3
|
+
*
|
|
4
|
+
* The adapter declares the descriptor's shape rather than importing the chart
|
|
5
|
+
* library, for the reason `contract.ts` gives, so it cannot ask the library
|
|
6
|
+
* what it has. Two hooks arrived after the oldest chart the peer range accepts:
|
|
7
|
+
* a band's per-bar colour callback and the list of grids, both in 2.5.4. A
|
|
8
|
+
* chart ignores a hook it does not know, so a descriptor that relied on either
|
|
9
|
+
* would draw, on an older chart, a band in the chart's own default colours or
|
|
10
|
+
* the first grid alone, and say nothing. That is the failure OS6024 exists to
|
|
11
|
+
* end, so where the adapter cannot tell, it refuses (`undrawable.ts`).
|
|
12
|
+
*
|
|
13
|
+
* **The host states the version, and the adapter reads what that version
|
|
14
|
+
* has.** The library exports its own version string, and a host that imports
|
|
15
|
+
* the chart already holds it: `descriptorFor(program, { chartVersion: VERSION })`.
|
|
16
|
+
* A version rather than a switch per hook, because a switch is a fact about the
|
|
17
|
+
* chart that the host has to look up and keep true through every upgrade and
|
|
18
|
+
* downgrade, while the version is the chart it actually installed.
|
|
19
|
+
*
|
|
20
|
+
* **Nothing stated reads as the oldest chart**, which is the descriptor every
|
|
21
|
+
* host got before the option existed: nothing it draws changes, and a program
|
|
22
|
+
* that needs either hook is refused as it was. A string that is not a version
|
|
23
|
+
* reads the same way, and the refusal says the string could not be read rather
|
|
24
|
+
* than guessing at what it meant. A prerelease orders before its release, as
|
|
25
|
+
* version precedence orders it, so `2.5.4-rc.1` reads as a chart without what
|
|
26
|
+
* 2.5.4 added; build metadata after a `+` orders nothing and is ignored.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** What the chart this descriptor is registered with will read. */
|
|
30
|
+
export interface ChartCapabilities {
|
|
31
|
+
/** A band's colour per bar, through the band's own colour callback. */
|
|
32
|
+
readonly bandColours: boolean;
|
|
33
|
+
/** Every declared grid, through the list of grids with an id each. */
|
|
34
|
+
readonly grids: boolean;
|
|
35
|
+
/** What the host stated, for the sentence a refusal carries. */
|
|
36
|
+
readonly stated: string | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The two hooks this reads a version for. */
|
|
40
|
+
export type Capability = 'bandColours' | 'grids';
|
|
41
|
+
|
|
42
|
+
/** The chart version each hook arrived in. */
|
|
43
|
+
const SINCE: Readonly<Record<Capability, string>> = {
|
|
44
|
+
bandColours: '2.5.4',
|
|
45
|
+
grids: '2.5.4',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** `major.minor.patch`, an optional prerelease, optional build metadata. */
|
|
49
|
+
const VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/;
|
|
50
|
+
|
|
51
|
+
interface Read {
|
|
52
|
+
readonly release: readonly [number, number, number];
|
|
53
|
+
readonly prerelease: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function capabilitiesOf(stated: string | undefined): ChartCapabilities {
|
|
57
|
+
const read = stated === undefined ? undefined : readVersion(stated);
|
|
58
|
+
return {
|
|
59
|
+
bandColours: read !== undefined && reaches(read, SINCE.bandColours),
|
|
60
|
+
grids: read !== undefined && reaches(read, SINCE.grids),
|
|
61
|
+
stated,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The sentence a refusal gives for a hook the chart may not have.
|
|
67
|
+
*
|
|
68
|
+
* `older` is what a chart without the hook does, in the words a reader of the
|
|
69
|
+
* refusal needs; the rest says which version has it and what this host stated,
|
|
70
|
+
* because the fix is the host's and it has to know which of the two to change.
|
|
71
|
+
*/
|
|
72
|
+
export function lacking(chart: ChartCapabilities, capability: Capability, older: string): string {
|
|
73
|
+
const since = SINCE[capability];
|
|
74
|
+
const stated = chart.stated;
|
|
75
|
+
const which =
|
|
76
|
+
stated === undefined
|
|
77
|
+
? 'this host stated no chart version'
|
|
78
|
+
: readVersion(stated) === undefined
|
|
79
|
+
? `this host stated ${JSON.stringify(stated)}, which is not a version this adapter can read`
|
|
80
|
+
: `this host stated version ${stated}`;
|
|
81
|
+
return `${older} before chart version ${since}, and ${which}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function readVersion(text: string): Read | undefined {
|
|
85
|
+
const match = VERSION.exec(text);
|
|
86
|
+
if (match === null) return undefined;
|
|
87
|
+
return {
|
|
88
|
+
release: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
89
|
+
prerelease: match[4] !== undefined,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Whether a stated version is at or past the one a hook arrived in. */
|
|
94
|
+
function reaches(read: Read, since: string): boolean {
|
|
95
|
+
const needed = readVersion(since);
|
|
96
|
+
if (needed === undefined) return false;
|
|
97
|
+
for (let part = 0; part < 3; part += 1) {
|
|
98
|
+
const have = read.release[part] ?? 0;
|
|
99
|
+
const need = needed.release[part] ?? 0;
|
|
100
|
+
if (have !== need) return have > need;
|
|
101
|
+
}
|
|
102
|
+
return !read.prerelease;
|
|
103
|
+
}
|
|
@@ -42,6 +42,11 @@ export function levelKey(index: number): string {
|
|
|
42
42
|
return `openscript:level:${index}`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/** The key one side of a band's computed colour travels under. */
|
|
46
|
+
export function bandColourKey(band: number, side: 'up' | 'down'): string {
|
|
47
|
+
return `openscript:fill:${band}:${side}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
/** The two keys a per-bar colour travels under. */
|
|
46
51
|
export function colourKeys(key: string): { readonly rgb: string; readonly alpha: string } {
|
|
47
52
|
return { rgb: `${key}:rgb`, alpha: `${key}:alpha` };
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* What is declared is the whole output surface: the inputs and the settings
|
|
33
33
|
* dialog a chart generates from them, the plots with their styles and scales,
|
|
34
34
|
* the bands between them, the horizontal levels, the pane's fixed range, the
|
|
35
|
-
* markers, the candle and pane painting, the summary
|
|
35
|
+
* markers, the candle and pane painting, the summary grids, the drawing objects,
|
|
36
36
|
* the watched conditions, and the lifecycle a read of another instrument fetches
|
|
37
37
|
* through.
|
|
38
38
|
*
|
|
@@ -56,6 +56,7 @@ import type {
|
|
|
56
56
|
ChartGrid,
|
|
57
57
|
ChartMarker,
|
|
58
58
|
ChartSurfaceContext,
|
|
59
|
+
ChartTableSpec,
|
|
59
60
|
} from './surfaces.js';
|
|
60
61
|
|
|
61
62
|
/** One bar as the chart holds it. Its time is UTC seconds, not milliseconds. */
|
|
@@ -223,6 +224,20 @@ export interface ChartPlot {
|
|
|
223
224
|
colorParts?(ctx: ChartColorContext): ChartBarColor | undefined;
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
/**
|
|
228
|
+
* What a band's per-bar colour callback is handed, for one bar.
|
|
229
|
+
*
|
|
230
|
+
* `a` and `b` are the two columns the band is drawn between, read on that bar,
|
|
231
|
+
* and `null` where either has no value, which is a bar the band is not drawn on.
|
|
232
|
+
*/
|
|
233
|
+
export interface ChartFillContext {
|
|
234
|
+
readonly index: number;
|
|
235
|
+
readonly a: number | null;
|
|
236
|
+
readonly b: number | null;
|
|
237
|
+
readonly values: ChartValues;
|
|
238
|
+
readonly settings: ChartSettings;
|
|
239
|
+
}
|
|
240
|
+
|
|
226
241
|
export interface ChartFill {
|
|
227
242
|
readonly between: readonly [string, string];
|
|
228
243
|
readonly colorUp?: string;
|
|
@@ -231,6 +246,15 @@ export interface ChartFill {
|
|
|
231
246
|
readonly colorDownKey?: string;
|
|
232
247
|
readonly opacity?: number;
|
|
233
248
|
readonly overlay?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* The band's colour on one bar, for a band whose colour the script computes.
|
|
251
|
+
*
|
|
252
|
+
* Present only on such a band, and only where the host states a chart that
|
|
253
|
+
* has the callback (`capabilities.ts`). Nothing where that bar's side is not
|
|
254
|
+
* computed per bar, which leaves the chart drawing the band's own colour for
|
|
255
|
+
* that side.
|
|
256
|
+
*/
|
|
257
|
+
colorBy?(ctx: ChartFillContext): string | undefined;
|
|
234
258
|
}
|
|
235
259
|
|
|
236
260
|
export interface ChartLevel {
|
|
@@ -305,8 +329,18 @@ export interface ChartDescriptor {
|
|
|
305
329
|
background?(ctx: ChartSurfaceContext): readonly (string | null)[];
|
|
306
330
|
/** Every marker the last calculation produced, oldest bar first. */
|
|
307
331
|
markers?(ctx: ChartSurfaceContext): readonly ChartMarker[];
|
|
308
|
-
/** The declared grid as the last executed bar left it, or nothing. */
|
|
332
|
+
/** The first declared grid as the last executed bar left it, or nothing. */
|
|
309
333
|
table?(ctx: ChartSurfaceContext): ChartGrid | null;
|
|
334
|
+
/**
|
|
335
|
+
* Every declared grid as the last executed bar left it, each under its
|
|
336
|
+
* declaration's key.
|
|
337
|
+
*
|
|
338
|
+
* A chart that has this hook reads it in place of `table`, and one that does
|
|
339
|
+
* not reads `table` and draws the first grid. So it is present only where the
|
|
340
|
+
* host states a chart that has it (`capabilities.ts`), and a second grid is
|
|
341
|
+
* refused on a chart that does not.
|
|
342
|
+
*/
|
|
343
|
+
tables?(ctx: ChartSurfaceContext): readonly ChartTableSpec[];
|
|
310
344
|
/** Every drawing object the script currently holds, oldest first. */
|
|
311
345
|
draws?(ctx: ChartSurfaceContext): readonly ChartDrawing[];
|
|
312
346
|
/**
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* second thing to keep in step with the specification.
|
|
15
15
|
*
|
|
16
16
|
* **The hooks that follow a calculation read it and do not repeat it.** Markers,
|
|
17
|
-
* the
|
|
17
|
+
* the grids, the drawing objects and each alert's message channel are taken once,
|
|
18
18
|
* while the engine is in hand, and left in the run record `produced.ts` keeps.
|
|
19
19
|
* The chart calls each hook after every calculation, so asking twice gives one
|
|
20
20
|
* answer and a study with a grid costs the same over a hundred thousand bars as
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
*/
|
|
44
44
|
import type { CompiledProgram } from '../../core/emit/index.js';
|
|
45
45
|
import { alertMessages, buildAlerts } from './alerts.js';
|
|
46
|
+
import { capabilitiesOf } from './capabilities.js';
|
|
46
47
|
import { valuesFrom } from './columns.js';
|
|
47
48
|
import type {
|
|
48
49
|
ChartBar,
|
|
@@ -70,8 +71,9 @@ import type {
|
|
|
70
71
|
ChartGrid,
|
|
71
72
|
ChartMarker,
|
|
72
73
|
ChartSurfaceContext,
|
|
74
|
+
ChartTableSpec,
|
|
73
75
|
} from './surfaces.js';
|
|
74
|
-
import {
|
|
76
|
+
import { buildTables, firstGrid } from './tables.js';
|
|
75
77
|
|
|
76
78
|
/** The grey an unnamed marker is drawn in, where the host names no default. */
|
|
77
79
|
const MARKER_COLOUR = 'rgba(128, 128, 128, 1)';
|
|
@@ -87,11 +89,14 @@ export function descriptorFor(
|
|
|
87
89
|
// afterwards carry a settings key instead of a value, and the two that cannot
|
|
88
90
|
// are read again per call: a level's style and the pane's range.
|
|
89
91
|
const declared = lookupFor(program, options.settings ?? {});
|
|
92
|
+
// Which of the descriptor's newer hooks the host's chart reads. A hook it may
|
|
93
|
+
// not read is left off, and what needs one is refused before a bar runs.
|
|
94
|
+
const chart = capabilitiesOf(options.chartVersion);
|
|
90
95
|
|
|
91
96
|
const overlay = boolField(program.meta.overlay, declared) === true;
|
|
92
97
|
const plots = buildPlots(program, declared, !overlay);
|
|
93
98
|
const levels = buildLevels(program);
|
|
94
|
-
const fills = buildFills(program, declared);
|
|
99
|
+
const fills = buildFills(program, declared, chart);
|
|
95
100
|
const paint = buildPaint(program);
|
|
96
101
|
const alerts = buildAlerts(program, declared);
|
|
97
102
|
const columns = [
|
|
@@ -99,6 +104,7 @@ export function descriptorFor(
|
|
|
99
104
|
...levels.columns,
|
|
100
105
|
...paint.columns,
|
|
101
106
|
...alerts.columns,
|
|
107
|
+
...fills.columns,
|
|
102
108
|
];
|
|
103
109
|
const markerColour = options.markerColor ?? MARKER_COLOUR;
|
|
104
110
|
|
|
@@ -117,7 +123,7 @@ export function descriptorFor(
|
|
|
117
123
|
const lookup = lookupFor(program, settings);
|
|
118
124
|
remember(settings, {
|
|
119
125
|
markers: buildMarkers(program, lookup, bars, ran.columns, markerColour),
|
|
120
|
-
|
|
126
|
+
tables: buildTables(program, lookup, ran.tables),
|
|
121
127
|
drawings: buildDrawings(ran.drawings),
|
|
122
128
|
messages: alertMessages(program, ran.columns),
|
|
123
129
|
});
|
|
@@ -134,7 +140,7 @@ export function descriptorFor(
|
|
|
134
140
|
placement: overlay ? 'onchart' : 'pane',
|
|
135
141
|
inputs: inputRows(program),
|
|
136
142
|
plots: plots.plots,
|
|
137
|
-
...(fills.length === 0 ? {} : { fills }),
|
|
143
|
+
...(fills.fills.length === 0 ? {} : { fills: fills.fills }),
|
|
138
144
|
|
|
139
145
|
...(alerts.alerts.length === 0 ? {} : { alerts: alerts.alerts }),
|
|
140
146
|
|
|
@@ -175,7 +181,16 @@ export function descriptorFor(
|
|
|
175
181
|
}),
|
|
176
182
|
...(program.outputs.tables.length === 0
|
|
177
183
|
? {}
|
|
178
|
-
: {
|
|
184
|
+
: {
|
|
185
|
+
table: (ctx: ChartSurfaceContext): ChartGrid | null =>
|
|
186
|
+
firstGrid(producedFor(ctx.settings).tables),
|
|
187
|
+
}),
|
|
188
|
+
...(program.outputs.tables.length === 0 || !chart.grids
|
|
189
|
+
? {}
|
|
190
|
+
: {
|
|
191
|
+
tables: (ctx: ChartSurfaceContext): readonly ChartTableSpec[] =>
|
|
192
|
+
producedFor(ctx.settings).tables,
|
|
193
|
+
}),
|
|
179
194
|
...(program.requires.includes('objects')
|
|
180
195
|
? {
|
|
181
196
|
draws: (ctx: ChartSurfaceContext): readonly ChartDrawing[] =>
|