@tradecanvas/script 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +120 -3
- package/dist/Column.d.ts +21 -0
- package/dist/Column.d.ts.map +1 -0
- package/dist/Ring.d.ts +28 -0
- package/dist/Ring.d.ts.map +1 -0
- package/dist/ScriptRun.d.ts +75 -0
- package/dist/ScriptRun.d.ts.map +1 -0
- package/dist/defineScript.d.ts +203 -0
- package/dist/defineScript.d.ts.map +1 -0
- package/dist/drawings.d.ts +46 -0
- package/dist/drawings.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1522 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +30 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/outputs.d.ts +129 -0
- package/dist/outputs.d.ts.map +1 -0
- package/dist/points.d.ts +13 -0
- package/dist/points.d.ts.map +1 -0
- package/dist/scope.d.ts +33 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scriptIndicator.d.ts +25 -0
- package/dist/scriptIndicator.d.ts.map +1 -0
- package/dist/security.d.ts +52 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/state.d.ts +52 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/ta/averages.d.ts +19 -0
- package/dist/ta/averages.d.ts.map +1 -0
- package/dist/ta/common.d.ts +24 -0
- package/dist/ta/common.d.ts.map +1 -0
- package/dist/ta/events.d.ts +16 -0
- package/dist/ta/events.d.ts.map +1 -0
- package/dist/ta/index.d.ts +65 -0
- package/dist/ta/index.d.ts.map +1 -0
- package/dist/ta/moves.d.ts +26 -0
- package/dist/ta/moves.d.ts.map +1 -0
- package/dist/ta/oscillators.d.ts +29 -0
- package/dist/ta/oscillators.d.ts.map +1 -0
- package/dist/ta/ranges.d.ts +18 -0
- package/dist/ta/ranges.d.ts.map +1 -0
- package/dist/ta/statistics.d.ts +26 -0
- package/dist/ta/statistics.d.ts.map +1 -0
- package/dist/worker/messages.d.ts +49 -0
- package/dist/worker/messages.d.ts.map +1 -0
- package/dist/worker/scriptWorkerIndicator.d.ts +40 -0
- package/dist/worker/scriptWorkerIndicator.d.ts.map +1 -0
- package/dist/worker/serveScripts.d.ts +28 -0
- package/dist/worker/serveScripts.d.ts.map +1 -0
- package/package.json +39 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IndicatorDrawing, IndicatorValue, OHLCBar } from '@tradecanvas/commons';
|
|
2
|
+
import { ScriptError } from '../outputs.js';
|
|
3
|
+
import { ScriptRunOptions } from '../ScriptRun.js';
|
|
4
|
+
/** Run a script over all of `bars`, as a run of its own (`run`); one with that number before is dropped. */
|
|
5
|
+
export interface LoadRequest {
|
|
6
|
+
type: 'load';
|
|
7
|
+
run: number;
|
|
8
|
+
seq: number;
|
|
9
|
+
/** The script's id, as `serveScripts` was given it. */
|
|
10
|
+
script: string;
|
|
11
|
+
params: Record<string, unknown>;
|
|
12
|
+
options: ScriptRunOptions;
|
|
13
|
+
bars: OHLCBar[];
|
|
14
|
+
}
|
|
15
|
+
/** The live bar again (`tick`), or a new bar (`next`), in a run loaded before. */
|
|
16
|
+
export interface BarRequest {
|
|
17
|
+
type: 'tick' | 'next';
|
|
18
|
+
run: number;
|
|
19
|
+
seq: number;
|
|
20
|
+
bar: OHLCBar;
|
|
21
|
+
}
|
|
22
|
+
/** Forget a run. */
|
|
23
|
+
export interface DropRequest {
|
|
24
|
+
type: 'drop';
|
|
25
|
+
run: number;
|
|
26
|
+
}
|
|
27
|
+
export type ScriptWorkerRequest = LoadRequest | BarRequest | DropRequest;
|
|
28
|
+
/** What a request changed: the bars from `from` on, as the chart reads them, and what the run holds now. */
|
|
29
|
+
export interface PatchResponse {
|
|
30
|
+
type: 'patch';
|
|
31
|
+
run: number;
|
|
32
|
+
seq: number;
|
|
33
|
+
/** The first bar whose point is in `points`; the bars before are as they were. */
|
|
34
|
+
from: number;
|
|
35
|
+
/** A point a bar, from `from` to the run's last bar. */
|
|
36
|
+
points: (IndicatorValue | null)[];
|
|
37
|
+
palette: string[];
|
|
38
|
+
drawings: IndicatorDrawing[];
|
|
39
|
+
errors: ScriptError[];
|
|
40
|
+
}
|
|
41
|
+
/** A request the worker could not run at all: no such script, a setup that threw, a run it does not hold. */
|
|
42
|
+
export interface FailedResponse {
|
|
43
|
+
type: 'failed';
|
|
44
|
+
run: number;
|
|
45
|
+
seq: number;
|
|
46
|
+
message: string;
|
|
47
|
+
}
|
|
48
|
+
export type ScriptWorkerResponse = PatchResponse | FailedResponse;
|
|
49
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/worker/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,4GAA4G;AAC5G,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB;AAED,kFAAkF;AAClF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,OAAO,CAAC;CACd;AAED,oBAAoB;AACpB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEzE,4GAA4G;AAC5G,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,MAAM,EAAE,CAAC,cAAc,GAAG,IAAI,CAAC,EAAE,CAAC;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,cAAc,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IndicatorPlugin } from '@tradecanvas/commons';
|
|
2
|
+
import { Script, ScriptInputs } from '../defineScript.js';
|
|
3
|
+
import { ScriptLimits } from '../limits.js';
|
|
4
|
+
/** What the page's side needs of a worker: `Worker` is one. */
|
|
5
|
+
export interface ScriptWorkerLike {
|
|
6
|
+
postMessage(message: unknown): void;
|
|
7
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
8
|
+
terminate(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface ScriptWorkerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Start the worker that serves the script (its module calls
|
|
13
|
+
* `serveScripts`). Called when first needed, and again after a worker
|
|
14
|
+
* was stopped.
|
|
15
|
+
*/
|
|
16
|
+
spawn: () => ScriptWorkerLike;
|
|
17
|
+
/**
|
|
18
|
+
* How long one request may go unanswered, in ms, the first load of the
|
|
19
|
+
* bars among them, before the worker is stopped and the script it hung
|
|
20
|
+
* on with it: a bar that never returns is stopped this way. Default 5000.
|
|
21
|
+
*/
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
/** How far each run may go in the worker: loop steps a bar, numbers a list, ms a run. */
|
|
24
|
+
limits?: ScriptLimits;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A script as an indicator run in a worker: the page sends it the bars,
|
|
28
|
+
* one bar each on a tick, and draws what it answers. A worker that does
|
|
29
|
+
* not answer within `timeoutMs` is stopped, so a script that never returns
|
|
30
|
+
* cannot hang the page. The worker's module serves the same script
|
|
31
|
+
* (`serveScripts`); the setup runs here too, once, to know what it draws.
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* chart.registerIndicator(scriptWorkerIndicator(emaCross, {
|
|
35
|
+
* spawn: () => new Worker(new URL('./scripts.worker.ts', import.meta.url), { type: 'module' }),
|
|
36
|
+
* }))
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function scriptWorkerIndicator(script: Script<ScriptInputs>, options: ScriptWorkerOptions): IndicatorPlugin;
|
|
40
|
+
//# sourceMappingURL=scriptWorkerIndicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scriptWorkerIndicator.d.ts","sourceRoot":"","sources":["../../src/worker/scriptWorkerIndicator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,eAAe,EAGhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ3D,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,SAAS,IAAI,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,KAAK,EAAE,MAAM,gBAAgB,CAAC;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yFAAyF;IACzF,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AA+PD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,mBAAmB,GAAG,eAAe,CAKjH"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Script, ScriptInputs } from '../defineScript.js';
|
|
2
|
+
import { ScriptWorkerRequest, ScriptWorkerResponse } from './messages.js';
|
|
3
|
+
/** How the worker answers. */
|
|
4
|
+
export type ScriptWorkerPost = (message: ScriptWorkerResponse) => void;
|
|
5
|
+
/** What a worker's global scope gives `serveScripts`: its messages in, and a way to answer. */
|
|
6
|
+
export interface ScriptWorkerScope {
|
|
7
|
+
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
|
8
|
+
postMessage(message: unknown): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The worker's side, apart from the worker so a test can run it on its own
|
|
12
|
+
* thread: each run the page loads is kept here, so a tick sends one bar
|
|
13
|
+
* and gets back the points from that bar on.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createScriptHandler(scripts: readonly Script<ScriptInputs>[], post: ScriptWorkerPost): (request: ScriptWorkerRequest) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Serve `scripts` from a worker: call it in the worker's module, with the
|
|
18
|
+
* scripts the page runs through `scriptWorkerIndicator`.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* // scripts.worker.ts
|
|
22
|
+
* import { serveScripts } from '@tradecanvas/script'
|
|
23
|
+
* import { emaCross } from './emaCross'
|
|
24
|
+
* serveScripts([emaCross])
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function serveScripts(scripts: readonly Script<ScriptInputs>[], scope?: ScriptWorkerScope): void;
|
|
28
|
+
//# sourceMappingURL=serveScripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveScripts.d.ts","sourceRoot":"","sources":["../../src/worker/serveScripts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG/D,OAAO,KAAK,EAAiB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE9F,8BAA8B;AAC9B,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAEvE,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,IAAI,CAAC;IACjF,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACrC;AAuBD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,SAAS,MAAM,CAAC,YAAY,CAAC,EAAE,EACxC,IAAI,EAAE,gBAAgB,GACrB,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAqCxC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,CAAC,YAAY,CAAC,EAAE,EAAE,KAAK,GAAE,iBAAwD,GAAG,IAAI,CAG5I"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradecanvas/script",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Indicators written bar by bar for TradeCanvas: state kept across bars, history read back, ta sums that run one bar at a time, and a live bar run again on each tick.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/bonguynvan/tradecanvas.git",
|
|
10
|
+
"directory": "packages/script"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"homepage": "https://tradecanvas.dev/",
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@tradecanvas/commons": "3.1.0",
|
|
30
|
+
"@tradecanvas/core": "3.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"vitest": "^2.1.8"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "vite build",
|
|
37
|
+
"dev": "vite build --watch",
|
|
38
|
+
"clean": "rm -rf dist",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest"
|
|
41
|
+
}
|
|
6
42
|
}
|