oakscriptjs 0.20.0 → 0.22.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/dist/cjs/check/harness.d.ts.map +1 -1
- package/dist/cjs/check/harness.js +35 -1
- package/dist/cjs/check/harness.js.map +2 -2
- package/dist/cjs/check/spec.d.ts +1 -1
- package/dist/cjs/check/spec.d.ts.map +1 -1
- package/dist/cjs/check/spec.js +1 -1
- package/dist/cjs/check/spec.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +9 -4
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/globals.d.ts +4 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/index.d.ts +237 -11
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +354 -32
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/security/events.d.ts +16 -0
- package/dist/cjs/security/events.d.ts.map +1 -0
- package/dist/cjs/security/events.js +84 -0
- package/dist/cjs/security/events.js.map +7 -0
- package/dist/esm/check/harness.d.ts.map +1 -1
- package/dist/esm/check/harness.js +25 -0
- package/dist/esm/check/harness.js.map +1 -1
- package/dist/esm/check/spec.d.ts +1 -1
- package/dist/esm/check/spec.d.ts.map +1 -1
- package/dist/esm/check/spec.js +1 -1
- package/dist/esm/check/spec.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +9 -4
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/globals.d.ts +4 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/index.d.ts +237 -11
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +381 -38
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/security/events.d.ts +16 -0
- package/dist/esm/security/events.d.ts.map +1 -0
- package/dist/esm/security/events.js +78 -0
- package/dist/esm/security/events.js.map +1 -0
- package/package.json +1 -1
- package/skills/oakscript/reference/script-structure.md +12 -2
- package/skills/oakscript/reference/timeframes-symbols.md +27 -0
- package/skills/oakscript/spec.schema.json +2 -1
- package/src/check/harness.ts +27 -0
- package/src/check/spec.ts +1 -1
- package/src/runtime/types.ts +9 -4
- package/src/script/globals.ts +4 -0
- package/src/script/index.ts +581 -46
- package/src/security/events.ts +85 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/check/harness.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../src/check/harness.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,aAAa,EAElB,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,iGAAiG;AACjG,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAE3C,CAAC;AAEF,mHAAmH;AACnH,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD,oHAAoH;AACpH,wBAAgB,eAAe,IAAI,OAAO,EAAE,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,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KxB,UAAU,IAAI,IAAI;IAKlB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE,CAAM;IAExC,IAAI,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAIlC,GAAG,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS;IAmB5D,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAInD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;CAGtD;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,eAAe,CAAC;IACrB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,6FAA6F;IAC7F,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,IAAI,CAAC;CAC1C;AAED,uGAAuG;AACvG,wBAAgB,SAAS,CACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,OAAO,GAAE,gBAAqB,GAC7B,SAAS,CAOX;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,IAAI,CAQf"}
|
|
@@ -144,9 +144,43 @@ function testChart(bars, options = {}) {
|
|
|
144
144
|
time: first + (b.time - START)
|
|
145
145
|
}));
|
|
146
146
|
},
|
|
147
|
-
symbolInfo: () => ({ timezone, session, mintick: 0.01, currency: "USD" })
|
|
147
|
+
symbolInfo: () => ({ timezone, session, mintick: 0.01, currency: "USD" }),
|
|
148
|
+
// the other symbol fields: none (na), so that a script reading them runs
|
|
149
|
+
symbolType: "stock",
|
|
150
|
+
description: "Synthetic test symbol",
|
|
151
|
+
...NO_SYMBOL_FIELDS,
|
|
152
|
+
events: () => testEvents(bars)
|
|
148
153
|
};
|
|
149
154
|
}
|
|
155
|
+
const NO_SYMBOL_FIELDS = {
|
|
156
|
+
basecurrency: null,
|
|
157
|
+
country: null,
|
|
158
|
+
currentContract: null,
|
|
159
|
+
expirationDate: null,
|
|
160
|
+
sector: null,
|
|
161
|
+
industry: null,
|
|
162
|
+
isin: null,
|
|
163
|
+
volumetype: null,
|
|
164
|
+
employees: null,
|
|
165
|
+
shareholders: null,
|
|
166
|
+
sharesOutstandingTotal: null,
|
|
167
|
+
sharesOutstandingFloat: null,
|
|
168
|
+
recommendations: null,
|
|
169
|
+
targetPrice: null
|
|
170
|
+
};
|
|
171
|
+
function testEvents(bars) {
|
|
172
|
+
if (!bars.length) return {};
|
|
173
|
+
const first = bars[0].time * 1e3;
|
|
174
|
+
const last = bars[bars.length - 1].time * 1e3;
|
|
175
|
+
const QUARTER = 90 * 864e5;
|
|
176
|
+
const dividends = [];
|
|
177
|
+
const earnings = [];
|
|
178
|
+
for (let t = first, k = 1; t <= last; t += QUARTER, k++) {
|
|
179
|
+
dividends.push({ time: t, net: 0.2 + 0.01 * k });
|
|
180
|
+
earnings.push({ time: t + 30 * 864e5, actual: 1 + 0.1 * k, estimate: 1 + 0.09 * k, standardized: 1 + 0.1 * k });
|
|
181
|
+
}
|
|
182
|
+
return { dividends, earnings, splits: [{ time: Math.round((first + last) / 2), numerator: 2, denominator: 1 }] };
|
|
183
|
+
}
|
|
150
184
|
class TestEngine {
|
|
151
185
|
constructor(setup) {
|
|
152
186
|
this.setup = setup;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/check/harness.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Runs a script source the way a host app runs a script written in its editor: the source is the body\n * of the script, with every value export of `oakscriptjs/script` but `executeScript` as an implicit global, on\n * deterministic synthetic bars (or given bars), with a chart context and, for a strategy, a small order engine.\n * Used by {@link checkScript}, the `oakscript check` command and the tests of the agent guide.\n *\n * @module check/harness\n */\nimport * as lib from '../index.js';\nimport * as api from '../script/index.js';\nimport {\n createScriptRun,\n executeScript,\n type ChartContext,\n type ScriptRunResult,\n type StrategyCloseOptions,\n type StrategyDirection,\n type StrategyEngine,\n type StrategyEntryOptions,\n type StrategyExitOptions,\n type StrategyRiskRule,\n type StrategySetup,\n type StrategyTrade,\n type StrategyVariable,\n} from '../script/index.js';\nimport type { Bar } from '../types/index.js';\n\n/** The implicit globals of a script: every value export of the script API but the host entry. */\nexport const SCRIPT_GLOBALS: readonly string[] = Object.keys(api).filter(\n (k) => k !== 'default' && k !== 'executeScript' && /^[A-Za-z_$][\\w$]*$/.test(k)\n);\n\n/** Name of the parameter that receives the `oakscriptjs` module in a compiled script (its `import` statements). */\nexport const LIBRARY_PARAMETER = '__oakscriptjs';\n\n/** The values of {@link SCRIPT_GLOBALS}, then the `oakscriptjs` module, in the order of the compiled parameters. */\nexport function scriptArguments(): unknown[] {\n return [...SCRIPT_GLOBALS.map((k) => (api as Record<string, unknown>)[k]), lib];\n}\n\n/**\n * Rewrites the `import { a, b as c } from \"oakscriptjs\"` statements of a script into `const { a, b: c } = ...` on the\n * same lines (the line numbers of the source do not change). Throws on an import of another module: a script runs\n * self-contained.\n */\nexport function rewriteImports(source: string): string {\n return source.replace(/^([ \\t]*)import\\s*(\\{[^}]*\\}|\\*\\s+as\\s+[A-Za-z_$][\\w$]*)\\s*from\\s*(['\"])([^'\"]+)\\3\\s*;?/gm, (all, indent, what, _q, from) => {\n if (from !== 'oakscriptjs' && from !== 'oakscriptjs/script') {\n throw new SyntaxError(`A script can only import from \"oakscriptjs\" (found \"${from}\").`);\n }\n const lines = all.split('\\n').length - 1;\n const binding = what.startsWith('*')\n ? what.replace(/^\\*\\s+as\\s+/, '')\n : what.replace(/\\s+as\\s+/g, ': ').replace(/\\s+/g, ' ');\n return `${indent}const ${binding} = ${LIBRARY_PARAMETER};${'\\n'.repeat(lines)}`;\n });\n}\n\n/**\n * Start and end of the function the script source is wrapped in. The globals are the parameters of an outer function\n * and the source is the body of an inner one, so a script can declare a name of a global (`const size = 2`), as in an\n * app that imports the globals at the top of a module. The start goes on the first line of the source.\n */\nexport const SCRIPT_PREFIX = '\"use strict\"; return (function () { ';\nexport const SCRIPT_SUFFIX = '\\n})();';\n\n/** The source of the function body of a compiled script (imports rewritten, lines kept). */\nexport function wrapSource(source: string): string {\n return SCRIPT_PREFIX + rewriteImports(source) + SCRIPT_SUFFIX;\n}\n\n/** Compiles a script source into a body for executeScript(); throws a SyntaxError on invalid code. */\nexport function compileScript(source: string): () => void {\n const fn = new Function(...SCRIPT_GLOBALS, LIBRARY_PARAMETER, wrapSource(source)) as (...args: unknown[]) => void;\n const values = scriptArguments();\n return () => fn(...values);\n}\n\nconst HOUR = 3600;\n/** 2024-01-01 00:00 UTC, in seconds. */\nconst START = 1704067200;\n\n/** Deterministic synthetic bars: two waves, a slow trend and seeded noise. `step`: seconds between bars. */\nexport function syntheticBars(count: number, step = HOUR, seed = 1): Bar[] {\n let s = seed >>> 0 || 1;\n const rand = (): number => {\n s = (Math.imul(s, 1664525) + 1013904223) >>> 0;\n return s / 2 ** 32;\n };\n const scale = Math.sqrt(step / HOUR);\n const bars: Bar[] = [];\n let prev = 100;\n for (let i = 0; i < count; i++) {\n const t = (i * step) / HOUR;\n const close = 100 + 12 * Math.sin(t / 60) + 4 * Math.sin(t / 11) + t * 0.004 + (rand() - 0.5) * 1.5 * scale;\n const open = prev;\n const high = Math.max(open, close) + rand() * 0.8 * scale;\n const low = Math.min(open, close) - rand() * 0.8 * scale;\n bars.push({ time: START + i * step, open, high, low, close, volume: Math.round(1000 + rand() * 4000) });\n prev = close;\n }\n return bars;\n}\n\n/** Seconds of a timeframe string (\"1\", \"60\", \"240\", \"D\", \"1D\", \"W\", \"M\"); NaN when it is not one. */\nexport function timeframeSeconds(timeframe: string): number {\n const m = /^(\\d*)([SDWM]?)$/.exec(timeframe.trim().toUpperCase());\n if (!m) return NaN;\n const n = m[1] ? Number(m[1]) : 1;\n const unit = { '': 60, S: 1, D: 86400, W: 7 * 86400, M: 30 * 86400 }[m[2] as '' | 'S' | 'D' | 'W' | 'M'];\n return n * unit;\n}\n\n/** The timeframe of bars from the most common spacing of their times (\"60\", \"D\", \"W\"...); \"60\" for fewer than 2 bars. */\nexport function inferTimeframe(bars: readonly Bar[]): string {\n const counts = new Map<number, number>();\n for (let i = 1; i < bars.length; i++) {\n const d = bars[i]!.time - bars[i - 1]!.time;\n if (d > 0) counts.set(d, (counts.get(d) ?? 0) + 1);\n }\n let step = 0;\n let best = 0;\n for (const [d, c] of counts) if (c > best) [step, best] = [d, c];\n if (!step) return '60';\n if (step >= 28 * 86400) return 'M';\n if (step >= 7 * 86400) return 'W';\n if (step >= 86400) return 'D';\n if (step < 60) return `${step}S`;\n return String(Math.round(step / 60));\n}\n\nexport interface TestChartOptions {\n /** Chart timeframe (default \"60\"). */\n timeframe?: string;\n /** Chart ticker id (default \"TEST:SYN\"). */\n tickerid?: string;\n /** Time zone of the chart and of the other symbols (default \"Etc/UTC\"). */\n timezone?: string;\n /** Session of the chart and of the other symbols (default \"24x7\"). */\n session?: string;\n}\n\n/**\n * Chart context of the test runs: a 24x7 symbol in UTC. Higher timeframes of the chart symbol are resampled from the\n * chart bars by the library; other symbols get synthetic bars of their own (seeded by the symbol name).\n */\nexport function testChart(bars: Bar[], options: TestChartOptions = {}): ChartContext {\n const timezone = options.timezone ?? 'Etc/UTC';\n const session = options.session ?? '24x7';\n const chartStep = timeframeSeconds(options.timeframe ?? '60') || HOUR;\n const span = bars.length ? bars[bars.length - 1]!.time - bars[0]!.time + chartStep : 0;\n return {\n tickerid: options.tickerid ?? 'TEST:SYN',\n timeframe: options.timeframe ?? '60',\n timezone,\n session,\n mintick: 0.01,\n pointvalue: 1,\n mincontract: 1,\n currency: 'USD',\n bars: (symbol, timeframe) => {\n const step = timeframeSeconds(timeframe);\n if (!step) return [];\n // a run on zero bars (the declaration run of a host) gets one empty bar: no bars at all is an invalid symbol\n if (!bars.length) return [{ time: 0, open: 0, high: 0, low: 0, close: 0, volume: 0 }];\n const first = bars[0]!.time;\n return syntheticBars(Math.ceil(span / step), step, symbol.length + 7).map((b) => ({\n ...b,\n time: first + (b.time - START),\n }));\n },\n symbolInfo: () => ({ timezone, session, mintick: 0.01, currency: 'USD' }),\n };\n}\n\n/**\n * A small order engine for checks and tests (the library does not fill orders). Market entries and closes fill at the\n * next bar open; `strategy.exit` stop / limit levels are checked inside each bar (stop first when both are hit).\n * Entry limit / stop prices, pyramiding and process_orders_on_close are not simulated.\n */\n/** A saved state of {@link TestEngine} */\ninterface TestEngineState {\n closed: StrategyTrade[];\n open: StrategyTrade | null;\n pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null;\n pendingClose: boolean;\n exits: Map<string, StrategyExitOptions>;\n net: number;\n bar: number;\n}\n\nexport class TestEngine implements StrategyEngine {\n readonly closed: StrategyTrade[] = [];\n private open: StrategyTrade | null = null;\n private pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null = null;\n private pendingClose = false;\n private exits = new Map<string, StrategyExitOptions>();\n private net = 0;\n private bar = 0;\n\n constructor(readonly setup: StrategySetup) {}\n\n /** The engine state at the end of a bar, for incremental runs (#196) */\n save(): TestEngineState {\n return {\n closed: this.closed.map((t) => ({ ...t })),\n open: this.open ? { ...this.open } : null,\n pendingEntry: this.pendingEntry ? { ...this.pendingEntry } : null,\n pendingClose: this.pendingClose,\n exits: new Map([...this.exits].map(([k, v]) => [k, { ...v }])),\n net: this.net,\n bar: this.bar,\n };\n }\n\n restore(state: unknown): void {\n const s = state as TestEngineState;\n this.closed.length = 0;\n for (const t of s.closed) this.closed.push({ ...t });\n this.open = s.open ? { ...s.open } : null;\n this.pendingEntry = s.pendingEntry ? { ...s.pendingEntry } : null;\n this.pendingClose = s.pendingClose;\n this.exits = new Map([...s.exits].map(([k, v]) => [k, { ...v }]));\n this.net = s.net;\n this.bar = s.bar;\n }\n\n private get bars(): readonly Bar[] {\n return this.setup.bars;\n }\n\n private equity(price: number): number {\n return this.setup.properties.initial_capital + this.net + this.openProfit(price);\n }\n\n private openProfit(price: number): number {\n return this.open ? (price - this.open.entry_price) * this.open.size : 0;\n }\n\n private commission(value: number): number {\n const p = this.setup.properties;\n return p.commission_type === 'percent' ? (Math.abs(value) * p.commission_value) / 100 : 0;\n }\n\n private closeAt(price: number, exitId: string): void {\n const t = this.open;\n if (!t) return;\n const commission = t.commission + this.commission(price * t.size);\n const profit = (price - t.entry_price) * t.size - commission;\n this.net += profit;\n this.closed.push({\n ...t,\n commission,\n profit,\n profit_percent: (profit / Math.abs(t.entry_price * t.size)) * 100,\n exit_id: exitId,\n exit_price: price,\n exit_bar_index: this.bar,\n exit_time: this.bars[this.bar]!.time * 1000,\n });\n this.open = null;\n this.exits.clear();\n }\n\n /** The open trade, if any. */\n get openTradeNow(): StrategyTrade | null {\n return this.open;\n }\n\n processBar(bar: number): void {\n this.bar = bar;\n const b = this.bars[bar]!;\n if (this.pendingClose) this.closeAt(b.open, 'Close');\n this.pendingClose = false;\n const e = this.pendingEntry;\n this.pendingEntry = null;\n if (e && !(this.open && Math.sign(this.open.size) === (e.direction === 'long' ? 1 : -1))) {\n if (this.open) this.closeAt(b.open, e.id);\n const p = this.setup.properties;\n const equity = this.equity(b.open);\n const qty =\n e.qty ??\n (p.default_qty_type === 'fixed'\n ? p.default_qty_value\n : p.default_qty_type === 'cash'\n ? p.default_qty_value / b.open\n : (equity * p.default_qty_value) / 100 / b.open);\n const size = e.direction === 'long' ? qty : -qty;\n this.open = {\n entry_id: e.id,\n entry_price: b.open,\n entry_bar_index: bar,\n entry_time: b.time * 1000,\n size,\n profit: 0,\n profit_percent: 0,\n commission: this.commission(b.open * size),\n max_runup: 0,\n max_runup_percent: 0,\n max_drawdown: 0,\n max_drawdown_percent: 0,\n };\n }\n const t = this.open;\n if (!t) return;\n for (const [id, x] of this.exits) {\n if (x.from_entry !== undefined && x.from_entry !== t.entry_id) continue;\n const long = t.size > 0;\n if (x.stop !== undefined && (long ? b.low <= x.stop : b.high >= x.stop)) {\n this.closeAt(long ? Math.min(b.open, x.stop) : Math.max(b.open, x.stop), id);\n return;\n }\n if (x.limit !== undefined && (long ? b.high >= x.limit : b.low <= x.limit)) {\n this.closeAt(long ? Math.max(b.open, x.limit) : Math.min(b.open, x.limit), id);\n return;\n }\n }\n }\n\n processClose(): void {}\n\n entry(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.pendingEntry = { id, direction, qty: options.qty };\n }\n\n order(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.entry(id, direction, options);\n }\n\n exit(id: string, options: StrategyExitOptions): void {\n this.exits.set(id, options);\n }\n\n close(id: string, _options: StrategyCloseOptions): void {\n if (this.open?.entry_id === id) this.pendingClose = true;\n }\n\n close_all(): void {\n if (this.open) this.pendingClose = true;\n }\n\n cancel(id: string): void {\n this.exits.delete(id);\n if (this.pendingEntry?.id === id) this.pendingEntry = null;\n }\n\n cancel_all(): void {\n this.exits.clear();\n this.pendingEntry = null;\n }\n\n readonly rules: StrategyRiskRule[] = [];\n\n risk(rule: StrategyRiskRule): void {\n this.rules.push(rule);\n }\n\n get(variable: StrategyVariable): number | string | undefined {\n const price = this.bars[this.bar]?.close ?? NaN;\n const wins = this.closed.filter((t) => t.profit > 0).length;\n const values: Partial<Record<StrategyVariable, number | string>> = {\n position_size: this.open?.size ?? 0,\n position_avg_price: this.open?.entry_price ?? NaN,\n initial_capital: this.setup.properties.initial_capital,\n equity: this.equity(price),\n netprofit: this.net,\n openprofit: this.openProfit(price),\n opentrades: this.open ? 1 : 0,\n closedtrades: this.closed.length,\n wintrades: wins,\n losstrades: this.closed.length - wins,\n account_currency: 'USD',\n };\n return values[variable];\n }\n\n openTrade(index: number): StrategyTrade | undefined {\n return index === 0 && this.open ? this.open : undefined;\n }\n\n closedTrade(index: number): StrategyTrade | undefined {\n return this.closed[index];\n }\n}\n\nexport interface ScriptRun {\n run: ScriptRunResult;\n engine?: TestEngine;\n}\n\nexport interface RunScriptOptions extends TestChartOptions {\n /** Compiles the source (default {@link compileScript}); the CLI compiles with file lines. */\n compile?: (source: string) => () => void;\n}\n\n/** Runs a script source on `bars` with the test chart context and, for a strategy, the test engine. */\nexport function runScript(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): ScriptRun {\n let engine: TestEngine | undefined;\n const body = (options.compile ?? compileScript)(source);\n const run = executeScript(body, bars, inputs, testChart(bars, options), {\n strategyEngine: (setup) => (engine = new TestEngine(setup)),\n });\n return { run, engine };\n}\n\n/**\n * Why a live chart would calculate the script in full on every update (#196), or null when its updates are resumed:\n * the script runs as on a live chart, on the bars but the last one, then once more with the last bar (a resumed update,\n * compared with a full run).\n */\nexport function incrementalReason(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): string | null {\n if (bars.length < 2) return null;\n const body = (options.compile ?? compileScript)(source);\n const chart = testChart(bars, options);\n const run = createScriptRun(body, inputs, chart, { strategyEngine: (setup) => new TestEngine(setup), verify: 1 });\n run.update(bars.slice(0, -1), chart);\n run.update(bars, chart);\n return run.fullRunReason;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,UAAqB;AACrB,UAAqB;AACrB,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Runs a script source the way a host app runs a script written in its editor: the source is the body\n * of the script, with every value export of `oakscriptjs/script` but `executeScript` as an implicit global, on\n * deterministic synthetic bars (or given bars), with a chart context and, for a strategy, a small order engine.\n * Used by {@link checkScript}, the `oakscript check` command and the tests of the agent guide.\n *\n * @module check/harness\n */\nimport * as lib from '../index.js';\nimport * as api from '../script/index.js';\nimport {\n createScriptRun,\n executeScript,\n type ChartContext,\n type ScriptRunResult,\n type StrategyCloseOptions,\n type StrategyDirection,\n type StrategyEngine,\n type StrategyEntryOptions,\n type StrategyExitOptions,\n type StrategyRiskRule,\n type StrategySetup,\n type StrategyTrade,\n type SymbolEvents,\n type StrategyVariable,\n} from '../script/index.js';\nimport type { Bar } from '../types/index.js';\n\n/** The implicit globals of a script: every value export of the script API but the host entry. */\nexport const SCRIPT_GLOBALS: readonly string[] = Object.keys(api).filter(\n (k) => k !== 'default' && k !== 'executeScript' && /^[A-Za-z_$][\\w$]*$/.test(k)\n);\n\n/** Name of the parameter that receives the `oakscriptjs` module in a compiled script (its `import` statements). */\nexport const LIBRARY_PARAMETER = '__oakscriptjs';\n\n/** The values of {@link SCRIPT_GLOBALS}, then the `oakscriptjs` module, in the order of the compiled parameters. */\nexport function scriptArguments(): unknown[] {\n return [...SCRIPT_GLOBALS.map((k) => (api as Record<string, unknown>)[k]), lib];\n}\n\n/**\n * Rewrites the `import { a, b as c } from \"oakscriptjs\"` statements of a script into `const { a, b: c } = ...` on the\n * same lines (the line numbers of the source do not change). Throws on an import of another module: a script runs\n * self-contained.\n */\nexport function rewriteImports(source: string): string {\n return source.replace(/^([ \\t]*)import\\s*(\\{[^}]*\\}|\\*\\s+as\\s+[A-Za-z_$][\\w$]*)\\s*from\\s*(['\"])([^'\"]+)\\3\\s*;?/gm, (all, indent, what, _q, from) => {\n if (from !== 'oakscriptjs' && from !== 'oakscriptjs/script') {\n throw new SyntaxError(`A script can only import from \"oakscriptjs\" (found \"${from}\").`);\n }\n const lines = all.split('\\n').length - 1;\n const binding = what.startsWith('*')\n ? what.replace(/^\\*\\s+as\\s+/, '')\n : what.replace(/\\s+as\\s+/g, ': ').replace(/\\s+/g, ' ');\n return `${indent}const ${binding} = ${LIBRARY_PARAMETER};${'\\n'.repeat(lines)}`;\n });\n}\n\n/**\n * Start and end of the function the script source is wrapped in. The globals are the parameters of an outer function\n * and the source is the body of an inner one, so a script can declare a name of a global (`const size = 2`), as in an\n * app that imports the globals at the top of a module. The start goes on the first line of the source.\n */\nexport const SCRIPT_PREFIX = '\"use strict\"; return (function () { ';\nexport const SCRIPT_SUFFIX = '\\n})();';\n\n/** The source of the function body of a compiled script (imports rewritten, lines kept). */\nexport function wrapSource(source: string): string {\n return SCRIPT_PREFIX + rewriteImports(source) + SCRIPT_SUFFIX;\n}\n\n/** Compiles a script source into a body for executeScript(); throws a SyntaxError on invalid code. */\nexport function compileScript(source: string): () => void {\n const fn = new Function(...SCRIPT_GLOBALS, LIBRARY_PARAMETER, wrapSource(source)) as (...args: unknown[]) => void;\n const values = scriptArguments();\n return () => fn(...values);\n}\n\nconst HOUR = 3600;\n/** 2024-01-01 00:00 UTC, in seconds. */\nconst START = 1704067200;\n\n/** Deterministic synthetic bars: two waves, a slow trend and seeded noise. `step`: seconds between bars. */\nexport function syntheticBars(count: number, step = HOUR, seed = 1): Bar[] {\n let s = seed >>> 0 || 1;\n const rand = (): number => {\n s = (Math.imul(s, 1664525) + 1013904223) >>> 0;\n return s / 2 ** 32;\n };\n const scale = Math.sqrt(step / HOUR);\n const bars: Bar[] = [];\n let prev = 100;\n for (let i = 0; i < count; i++) {\n const t = (i * step) / HOUR;\n const close = 100 + 12 * Math.sin(t / 60) + 4 * Math.sin(t / 11) + t * 0.004 + (rand() - 0.5) * 1.5 * scale;\n const open = prev;\n const high = Math.max(open, close) + rand() * 0.8 * scale;\n const low = Math.min(open, close) - rand() * 0.8 * scale;\n bars.push({ time: START + i * step, open, high, low, close, volume: Math.round(1000 + rand() * 4000) });\n prev = close;\n }\n return bars;\n}\n\n/** Seconds of a timeframe string (\"1\", \"60\", \"240\", \"D\", \"1D\", \"W\", \"M\"); NaN when it is not one. */\nexport function timeframeSeconds(timeframe: string): number {\n const m = /^(\\d*)([SDWM]?)$/.exec(timeframe.trim().toUpperCase());\n if (!m) return NaN;\n const n = m[1] ? Number(m[1]) : 1;\n const unit = { '': 60, S: 1, D: 86400, W: 7 * 86400, M: 30 * 86400 }[m[2] as '' | 'S' | 'D' | 'W' | 'M'];\n return n * unit;\n}\n\n/** The timeframe of bars from the most common spacing of their times (\"60\", \"D\", \"W\"...); \"60\" for fewer than 2 bars. */\nexport function inferTimeframe(bars: readonly Bar[]): string {\n const counts = new Map<number, number>();\n for (let i = 1; i < bars.length; i++) {\n const d = bars[i]!.time - bars[i - 1]!.time;\n if (d > 0) counts.set(d, (counts.get(d) ?? 0) + 1);\n }\n let step = 0;\n let best = 0;\n for (const [d, c] of counts) if (c > best) [step, best] = [d, c];\n if (!step) return '60';\n if (step >= 28 * 86400) return 'M';\n if (step >= 7 * 86400) return 'W';\n if (step >= 86400) return 'D';\n if (step < 60) return `${step}S`;\n return String(Math.round(step / 60));\n}\n\nexport interface TestChartOptions {\n /** Chart timeframe (default \"60\"). */\n timeframe?: string;\n /** Chart ticker id (default \"TEST:SYN\"). */\n tickerid?: string;\n /** Time zone of the chart and of the other symbols (default \"Etc/UTC\"). */\n timezone?: string;\n /** Session of the chart and of the other symbols (default \"24x7\"). */\n session?: string;\n}\n\n/**\n * Chart context of the test runs: a 24x7 symbol in UTC. Higher timeframes of the chart symbol are resampled from the\n * chart bars by the library; other symbols get synthetic bars of their own (seeded by the symbol name).\n */\nexport function testChart(bars: Bar[], options: TestChartOptions = {}): ChartContext {\n const timezone = options.timezone ?? 'Etc/UTC';\n const session = options.session ?? '24x7';\n const chartStep = timeframeSeconds(options.timeframe ?? '60') || HOUR;\n const span = bars.length ? bars[bars.length - 1]!.time - bars[0]!.time + chartStep : 0;\n return {\n tickerid: options.tickerid ?? 'TEST:SYN',\n timeframe: options.timeframe ?? '60',\n timezone,\n session,\n mintick: 0.01,\n pointvalue: 1,\n mincontract: 1,\n currency: 'USD',\n bars: (symbol, timeframe) => {\n const step = timeframeSeconds(timeframe);\n if (!step) return [];\n // a run on zero bars (the declaration run of a host) gets one empty bar: no bars at all is an invalid symbol\n if (!bars.length) return [{ time: 0, open: 0, high: 0, low: 0, close: 0, volume: 0 }];\n const first = bars[0]!.time;\n return syntheticBars(Math.ceil(span / step), step, symbol.length + 7).map((b) => ({\n ...b,\n time: first + (b.time - START),\n }));\n },\n symbolInfo: () => ({ timezone, session, mintick: 0.01, currency: 'USD' }),\n // the other symbol fields: none (na), so that a script reading them runs\n symbolType: 'stock',\n description: 'Synthetic test symbol',\n ...NO_SYMBOL_FIELDS,\n events: () => testEvents(bars),\n };\n}\n\nconst NO_SYMBOL_FIELDS = {\n basecurrency: null, country: null, currentContract: null, expirationDate: null, sector: null, industry: null,\n isin: null, volumetype: null, employees: null, shareholders: null, sharesOutstandingTotal: null,\n sharesOutstandingFloat: null, recommendations: null, targetPrice: null,\n} satisfies Partial<ChartContext>;\n\n/** Events of the test symbol: a dividend and an earnings release every 90 days of its bars, a 2-for-1 split half-way. */\nfunction testEvents(bars: Bar[]): SymbolEvents {\n if (!bars.length) return {};\n const first = bars[0]!.time * 1000;\n const last = bars[bars.length - 1]!.time * 1000;\n const QUARTER = 90 * 86_400_000;\n const dividends: SymbolEvents['dividends'] = [];\n const earnings: SymbolEvents['earnings'] = [];\n for (let t = first, k = 1; t <= last; t += QUARTER, k++) {\n dividends.push({ time: t, net: 0.2 + 0.01 * k });\n earnings.push({ time: t + 30 * 86_400_000, actual: 1 + 0.1 * k, estimate: 1 + 0.09 * k, standardized: 1 + 0.1 * k });\n }\n return { dividends, earnings, splits: [{ time: Math.round((first + last) / 2), numerator: 2, denominator: 1 }] };\n}\n\n/**\n * A small order engine for checks and tests (the library does not fill orders). Market entries and closes fill at the\n * next bar open; `strategy.exit` stop / limit levels are checked inside each bar (stop first when both are hit).\n * Entry limit / stop prices, pyramiding and process_orders_on_close are not simulated.\n */\n/** A saved state of {@link TestEngine} */\ninterface TestEngineState {\n closed: StrategyTrade[];\n open: StrategyTrade | null;\n pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null;\n pendingClose: boolean;\n exits: Map<string, StrategyExitOptions>;\n net: number;\n bar: number;\n}\n\nexport class TestEngine implements StrategyEngine {\n readonly closed: StrategyTrade[] = [];\n private open: StrategyTrade | null = null;\n private pendingEntry: { id: string; direction: StrategyDirection; qty?: number } | null = null;\n private pendingClose = false;\n private exits = new Map<string, StrategyExitOptions>();\n private net = 0;\n private bar = 0;\n\n constructor(readonly setup: StrategySetup) {}\n\n /** The engine state at the end of a bar, for incremental runs (#196) */\n save(): TestEngineState {\n return {\n closed: this.closed.map((t) => ({ ...t })),\n open: this.open ? { ...this.open } : null,\n pendingEntry: this.pendingEntry ? { ...this.pendingEntry } : null,\n pendingClose: this.pendingClose,\n exits: new Map([...this.exits].map(([k, v]) => [k, { ...v }])),\n net: this.net,\n bar: this.bar,\n };\n }\n\n restore(state: unknown): void {\n const s = state as TestEngineState;\n this.closed.length = 0;\n for (const t of s.closed) this.closed.push({ ...t });\n this.open = s.open ? { ...s.open } : null;\n this.pendingEntry = s.pendingEntry ? { ...s.pendingEntry } : null;\n this.pendingClose = s.pendingClose;\n this.exits = new Map([...s.exits].map(([k, v]) => [k, { ...v }]));\n this.net = s.net;\n this.bar = s.bar;\n }\n\n private get bars(): readonly Bar[] {\n return this.setup.bars;\n }\n\n private equity(price: number): number {\n return this.setup.properties.initial_capital + this.net + this.openProfit(price);\n }\n\n private openProfit(price: number): number {\n return this.open ? (price - this.open.entry_price) * this.open.size : 0;\n }\n\n private commission(value: number): number {\n const p = this.setup.properties;\n return p.commission_type === 'percent' ? (Math.abs(value) * p.commission_value) / 100 : 0;\n }\n\n private closeAt(price: number, exitId: string): void {\n const t = this.open;\n if (!t) return;\n const commission = t.commission + this.commission(price * t.size);\n const profit = (price - t.entry_price) * t.size - commission;\n this.net += profit;\n this.closed.push({\n ...t,\n commission,\n profit,\n profit_percent: (profit / Math.abs(t.entry_price * t.size)) * 100,\n exit_id: exitId,\n exit_price: price,\n exit_bar_index: this.bar,\n exit_time: this.bars[this.bar]!.time * 1000,\n });\n this.open = null;\n this.exits.clear();\n }\n\n /** The open trade, if any. */\n get openTradeNow(): StrategyTrade | null {\n return this.open;\n }\n\n processBar(bar: number): void {\n this.bar = bar;\n const b = this.bars[bar]!;\n if (this.pendingClose) this.closeAt(b.open, 'Close');\n this.pendingClose = false;\n const e = this.pendingEntry;\n this.pendingEntry = null;\n if (e && !(this.open && Math.sign(this.open.size) === (e.direction === 'long' ? 1 : -1))) {\n if (this.open) this.closeAt(b.open, e.id);\n const p = this.setup.properties;\n const equity = this.equity(b.open);\n const qty =\n e.qty ??\n (p.default_qty_type === 'fixed'\n ? p.default_qty_value\n : p.default_qty_type === 'cash'\n ? p.default_qty_value / b.open\n : (equity * p.default_qty_value) / 100 / b.open);\n const size = e.direction === 'long' ? qty : -qty;\n this.open = {\n entry_id: e.id,\n entry_price: b.open,\n entry_bar_index: bar,\n entry_time: b.time * 1000,\n size,\n profit: 0,\n profit_percent: 0,\n commission: this.commission(b.open * size),\n max_runup: 0,\n max_runup_percent: 0,\n max_drawdown: 0,\n max_drawdown_percent: 0,\n };\n }\n const t = this.open;\n if (!t) return;\n for (const [id, x] of this.exits) {\n if (x.from_entry !== undefined && x.from_entry !== t.entry_id) continue;\n const long = t.size > 0;\n if (x.stop !== undefined && (long ? b.low <= x.stop : b.high >= x.stop)) {\n this.closeAt(long ? Math.min(b.open, x.stop) : Math.max(b.open, x.stop), id);\n return;\n }\n if (x.limit !== undefined && (long ? b.high >= x.limit : b.low <= x.limit)) {\n this.closeAt(long ? Math.max(b.open, x.limit) : Math.min(b.open, x.limit), id);\n return;\n }\n }\n }\n\n processClose(): void {}\n\n entry(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.pendingEntry = { id, direction, qty: options.qty };\n }\n\n order(id: string, direction: StrategyDirection, options: StrategyEntryOptions): void {\n this.entry(id, direction, options);\n }\n\n exit(id: string, options: StrategyExitOptions): void {\n this.exits.set(id, options);\n }\n\n close(id: string, _options: StrategyCloseOptions): void {\n if (this.open?.entry_id === id) this.pendingClose = true;\n }\n\n close_all(): void {\n if (this.open) this.pendingClose = true;\n }\n\n cancel(id: string): void {\n this.exits.delete(id);\n if (this.pendingEntry?.id === id) this.pendingEntry = null;\n }\n\n cancel_all(): void {\n this.exits.clear();\n this.pendingEntry = null;\n }\n\n readonly rules: StrategyRiskRule[] = [];\n\n risk(rule: StrategyRiskRule): void {\n this.rules.push(rule);\n }\n\n get(variable: StrategyVariable): number | string | undefined {\n const price = this.bars[this.bar]?.close ?? NaN;\n const wins = this.closed.filter((t) => t.profit > 0).length;\n const values: Partial<Record<StrategyVariable, number | string>> = {\n position_size: this.open?.size ?? 0,\n position_avg_price: this.open?.entry_price ?? NaN,\n initial_capital: this.setup.properties.initial_capital,\n equity: this.equity(price),\n netprofit: this.net,\n openprofit: this.openProfit(price),\n opentrades: this.open ? 1 : 0,\n closedtrades: this.closed.length,\n wintrades: wins,\n losstrades: this.closed.length - wins,\n account_currency: 'USD',\n };\n return values[variable];\n }\n\n openTrade(index: number): StrategyTrade | undefined {\n return index === 0 && this.open ? this.open : undefined;\n }\n\n closedTrade(index: number): StrategyTrade | undefined {\n return this.closed[index];\n }\n}\n\nexport interface ScriptRun {\n run: ScriptRunResult;\n engine?: TestEngine;\n}\n\nexport interface RunScriptOptions extends TestChartOptions {\n /** Compiles the source (default {@link compileScript}); the CLI compiles with file lines. */\n compile?: (source: string) => () => void;\n}\n\n/** Runs a script source on `bars` with the test chart context and, for a strategy, the test engine. */\nexport function runScript(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): ScriptRun {\n let engine: TestEngine | undefined;\n const body = (options.compile ?? compileScript)(source);\n const run = executeScript(body, bars, inputs, testChart(bars, options), {\n strategyEngine: (setup) => (engine = new TestEngine(setup)),\n });\n return { run, engine };\n}\n\n/**\n * Why a live chart would calculate the script in full on every update (#196), or null when its updates are resumed:\n * the script runs as on a live chart, on the bars but the last one, then once more with the last bar (a resumed update,\n * compared with a full run).\n */\nexport function incrementalReason(\n source: string,\n bars: Bar[],\n inputs: Record<string, unknown> = {},\n options: RunScriptOptions = {}\n): string | null {\n if (bars.length < 2) return null;\n const body = (options.compile ?? compileScript)(source);\n const chart = testChart(bars, options);\n const run = createScriptRun(body, inputs, chart, { strategyEngine: (setup) => new TestEngine(setup), verify: 1 });\n run.update(bars.slice(0, -1), chart);\n run.update(bars, chart);\n return run.fullRunReason;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,UAAqB;AACrB,UAAqB;AACrB,oBAeO;AAIA,MAAM,iBAAoC,OAAO,KAAK,GAAG,EAAE;AAAA,EAChE,CAAC,MAAM,MAAM,aAAa,MAAM,mBAAmB,qBAAqB,KAAK,CAAC;AAChF;AAGO,MAAM,oBAAoB;AAG1B,SAAS,kBAA6B;AAC3C,SAAO,CAAC,GAAG,eAAe,IAAI,CAAC,MAAO,IAAgC,CAAC,CAAC,GAAG,GAAG;AAChF;AAOO,SAAS,eAAe,QAAwB;AACrD,SAAO,OAAO,QAAQ,6FAA6F,CAAC,KAAK,QAAQ,MAAM,IAAI,SAAS;AAClJ,QAAI,SAAS,iBAAiB,SAAS,sBAAsB;AAC3D,YAAM,IAAI,YAAY,uDAAuD,IAAI,KAAK;AAAA,IACxF;AACA,UAAM,QAAQ,IAAI,MAAM,IAAI,EAAE,SAAS;AACvC,UAAM,UAAU,KAAK,WAAW,GAAG,IAC/B,KAAK,QAAQ,eAAe,EAAE,IAC9B,KAAK,QAAQ,aAAa,IAAI,EAAE,QAAQ,QAAQ,GAAG;AACvD,WAAO,GAAG,MAAM,SAAS,OAAO,MAAM,iBAAiB,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,EAC/E,CAAC;AACH;AAOO,MAAM,gBAAg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E,gBAAgB,CAAC,UAAU,IAAI,WAAW,KAAK,GAAG,QAAQ,EAAE,CAAC;AAChH,MAAI,OAAO,KAAK,MAAM,GAAG,EAAE,GAAG,KAAK;AACnC,MAAI,OAAO,MAAM,KAAK;AACtB,SAAO,IAAI;AACb;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/check/spec.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ type Field = {
|
|
|
25
25
|
kind: 'outputs';
|
|
26
26
|
doc: string;
|
|
27
27
|
};
|
|
28
|
-
export declare const INPUT_TYPES: readonly ["int", "float", "bool", "string", "text_area", "source", "color", "timeframe", "session", "time", "symbol"];
|
|
28
|
+
export declare const INPUT_TYPES: readonly ["int", "float", "bool", "string", "text_area", "source", "color", "timeframe", "session", "time", "symbol", "enum"];
|
|
29
29
|
export declare const OUTPUT_KINDS: readonly ["plot", "shape", "char", "arrow", "candle", "bar", "hline", "bgcolor", "barcolor", "alertcondition"];
|
|
30
30
|
/** The keys of a spec checked by checkScript. */
|
|
31
31
|
export declare const SPEC_FIELDS: Record<string, Field>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.d.ts","sourceRoot":"","sources":["../../../src/check/spec.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,KAAK,KAAK,GACN;IAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CA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AI,EAAE,OAAO,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,EAAE,CAKtF;AAuCD,uEAAuE;AACvE,wBAAgB,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOxD"}
|
package/dist/cjs/check/spec.js
CHANGED
|
@@ -27,7 +27,7 @@ __export(spec_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(spec_exports);
|
|
29
29
|
const num = (doc) => ({ kind: "number", doc });
|
|
30
|
-
const INPUT_TYPES = ["int", "float", "bool", "string", "text_area", "source", "color", "timeframe", "session", "time", "symbol"];
|
|
30
|
+
const INPUT_TYPES = ["int", "float", "bool", "string", "text_area", "source", "color", "timeframe", "session", "time", "symbol", "enum"];
|
|
31
31
|
const OUTPUT_KINDS = ["plot", "shape", "char", "arrow", "candle", "bar", "hline", "bgcolor", "barcolor", "alertcondition"];
|
|
32
32
|
const SPEC_FIELDS = {
|
|
33
33
|
kind: { kind: "enum", values: ["indicator", "strategy"], doc: "indicator() or strategy()" },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/check/spec.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview The spec of a check (what the user asked for), described once: {@link validateSpec} rejects unknown\n * keys and wrong values (a misspelt key would otherwise be skipped and the check would pass without checking it), and\n * {@link specJsonSchema} gives the JSON Schema of a spec file (`skills/oakscript/spec.schema.json`).\n *\n * @module check/spec\n */\n\ntype Field =\n | { kind: 'string' | 'number' | 'boolean' | 'any' | 'string[]'; doc: string }\n | { kind: 'enum'; values: readonly string[]; doc: string }\n | { kind: 'object'; fields: Record<string, Field>; doc: string; required?: readonly string[] }\n | { kind: 'map'; of: Field; doc: string }\n | { kind: 'outputs'; doc: string };\n\nconst num = (doc: string): Field => ({ kind: 'number', doc });\n\nexport const INPUT_TYPES = ['int', 'float', 'bool', 'string', 'text_area', 'source', 'color', 'timeframe', 'session', 'time', 'symbol'] as const;\nexport const OUTPUT_KINDS = ['plot', 'shape', 'char', 'arrow', 'candle', 'bar', 'hline', 'bgcolor', 'barcolor', 'alertcondition'] as const;\n\n/** The keys of a spec checked by checkScript. */\nexport const SPEC_FIELDS: Record<string, Field> = {\n kind: { kind: 'enum', values: ['indicator', 'strategy'], doc: 'indicator() or strategy()' },\n title: { kind: 'string', doc: 'the title of the declaration' },\n overlay: { kind: 'boolean', doc: 'true: price pane, false: own pane' },\n inputs: {\n kind: 'map',\n doc: 'inputs that must exist, by id or title',\n of: {\n kind: 'object',\n doc: 'the expected input',\n fields: {\n type: { kind: 'enum', values: INPUT_TYPES, doc: 'input type' },\n defval: { kind: 'any', doc: 'default value' },\n title: { kind: 'string', doc: 'title' },\n min: num('minval'),\n max: num('maxval'),\n options: { kind: 'string[]', doc: 'the choices of a string input' },\n },\n },\n },\n outputs: { kind: 'outputs', doc: 'outputs that must exist: a title, or { title, kind }' },\n plots: {\n kind: 'map',\n doc: 'value checks per plot, by id or title',\n of: {\n kind: 'object',\n doc: 'the expected values',\n fields: { min: num('every value is at least this'), max: num('every value is at most this'), warmup: num('the first value comes at this bar index or before') },\n },\n },\n signals: {\n kind: 'map',\n doc: 'count checks per signal (shape, char, arrow, alertcondition, bgcolor, barcolor), by id or title',\n of: {\n kind: 'object',\n doc: 'the expected count',\n fields: {\n min: num('at least this many bars'),\n max: num('at most this many bars'),\n minShare: num('at least this share of the bars (0 to 1)'),\n maxShare: num('at most this share of the bars (0 to 1)'),\n },\n },\n },\n trades: { kind: 'object', doc: 'closed trades of a strategy', fields: { min: num('at least'), max: num('at most') } },\n};\n\n/** The keys of a spec file read by the `oakscript check` command (paths relative to the spec file). */\nexport const SPEC_FILE_FIELDS: Record<string, Field> = {\n $schema: { kind: 'string', doc: 'the JSON Schema of the spec (oakscriptjs/skills/oakscript/spec.schema.json)' },\n reference: { kind: 'string', doc: 'CSV of expected values per bar (a time column, one column per plot)' },\n export: { kind: 'string', doc: 'chart export CSV: the bars (time, open, high, low, close, volume) and the expected plot values' },\n tolerance: num('relative tolerance of the reference values (default 1e-10)'),\n checks: { kind: 'string', doc: 'JavaScript file of behaviour checks (the body of a function of `t`)' },\n scenarios: { kind: 'boolean', doc: 'also run on the built-in edge-case bars' },\n};\n\nfunction closest(name: string, names: string[]): string | undefined {\n const dist = (a: string, b: string): number => {\n const row = Array.from({ length: b.length + 1 }, (_, j) => j);\n for (let i = 1; i <= a.length; i++) {\n let diag = row[0]!;\n row[0] = i;\n for (let j = 1; j <= b.length; j++) {\n const up = row[j]!;\n row[j] = Math.min(up + 1, row[j - 1]! + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));\n diag = up;\n }\n }\n return row[b.length]!;\n };\n const n = name.toLowerCase();\n const best = names.map((k) => ({ k, d: dist(n, k.toLowerCase()) })).sort((a, b) => a.d - b.d)[0];\n if (!best) return undefined;\n return best.d <= Math.max(2, Math.floor(name.length / 2)) || best.k.toLowerCase().startsWith(n.slice(0, 3)) ? best.k : undefined;\n}\n\nfunction check(value: unknown, field: Field, path: string, errors: string[]): void {\n const fail = (what: string): void => {\n errors.push(`${path}: ${what}`);\n };\n switch (field.kind) {\n case 'any':\n return;\n case 'string':\n case 'number':\n case 'boolean':\n if (typeof value !== field.kind || (field.kind === 'number' && !Number.isFinite(value))) fail(`expected a ${field.kind}, got ${JSON.stringify(value)}`);\n return;\n case 'string[]':\n if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) fail(`expected an array of strings, got ${JSON.stringify(value)}`);\n return;\n case 'enum':\n if (typeof value !== 'string' || !field.values.includes(value)) fail(`expected one of ${field.values.join(', ')}, got ${JSON.stringify(value)}`);\n return;\n case 'outputs':\n if (!Array.isArray(value)) return fail('expected an array of titles or { title, kind }');\n value.forEach((o, k) => {\n if (typeof o === 'string') return;\n check(o, { kind: 'object', doc: '', required: ['title'], fields: { title: { kind: 'string', doc: '' }, kind: { kind: 'enum', values: OUTPUT_KINDS, doc: '' } } }, `${path}[${k}]`, errors);\n });\n return;\n case 'map':\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return fail('expected an object (name -> checks)');\n for (const [k, v] of Object.entries(value)) check(v, field.of, `${path}.${k}`, errors);\n return;\n case 'object': {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return fail('expected an object');\n const keys = Object.keys(field.fields);\n for (const [k, v] of Object.entries(value)) {\n const f = field.fields[k];\n if (!f) {\n const near = closest(k, keys);\n fail(`unknown key \"${k}\"${near ? ` (did you mean \"${near}\"?)` : ''}; the keys are ${keys.join(', ')}`);\n } else check(v, f, `${path}.${k}`, errors);\n }\n for (const r of field.required ?? []) if (!(r in (value as object))) fail(`\"${r}\" is required`);\n return;\n }\n }\n}\n\n/**\n * The problems of a spec: unknown keys (with the closest key) and wrong values, one message per problem; empty when the\n * spec is valid. `file`: also accept the keys of a spec file (reference, export, tolerance, checks, scenarios).\n */\nexport function validateSpec(spec: unknown, options: { file?: boolean } = {}): string[] {\n const errors: string[] = [];\n const fields = options.file ? { ...SPEC_FIELDS, ...SPEC_FILE_FIELDS } : SPEC_FIELDS;\n check(spec, { kind: 'object', doc: '', fields }, 'spec', errors);\n return errors;\n}\n\nfunction schemaOf(field: Field): Record<string, unknown> {\n const description = field.doc ? { description: field.doc } : {};\n switch (field.kind) {\n case 'any':\n return { ...description };\n case 'string':\n case 'number':\n case 'boolean':\n return { type: field.kind, ...description };\n case 'string[]':\n return { type: 'array', items: { type: 'string' }, ...description };\n case 'enum':\n return { enum: [...field.values], ...description };\n case 'outputs':\n return {\n type: 'array',\n ...description,\n items: {\n oneOf: [\n { type: 'string' },\n { type: 'object', additionalProperties: false, required: ['title'], properties: { title: { type: 'string' }, kind: { enum: [...OUTPUT_KINDS] } } },\n ],\n },\n };\n case 'map':\n return { type: 'object', ...description, additionalProperties: schemaOf(field.of) };\n case 'object':\n return {\n type: 'object',\n ...description,\n additionalProperties: false,\n ...(field.required ? { required: [...field.required] } : {}),\n properties: Object.fromEntries(Object.entries(field.fields).map(([k, f]) => [k, schemaOf(f)])),\n };\n }\n}\n\n/** JSON Schema (draft 2020-12) of a spec file of `oakscript check`. */\nexport function specJsonSchema(): Record<string, unknown> {\n return {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n title: 'oakscript check spec',\n description: 'What the user asked for, checked by `oakscript check --spec`: every given entry is checked, an unknown key is an error.',\n ...schemaOf({ kind: 'object', doc: '', fields: { ...SPEC_FIELDS, ...SPEC_FILE_FIELDS } }),\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,MAAM,MAAM,CAAC,SAAwB,EAAE,MAAM,UAAU,IAAI;AAEpD,MAAM,cAAc,CAAC,OAAO,SAAS,QAAQ,UAAU,aAAa,UAAU,SAAS,aAAa,WAAW,QAAQ,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview The spec of a check (what the user asked for), described once: {@link validateSpec} rejects unknown\n * keys and wrong values (a misspelt key would otherwise be skipped and the check would pass without checking it), and\n * {@link specJsonSchema} gives the JSON Schema of a spec file (`skills/oakscript/spec.schema.json`).\n *\n * @module check/spec\n */\n\ntype Field =\n | { kind: 'string' | 'number' | 'boolean' | 'any' | 'string[]'; doc: string }\n | { kind: 'enum'; values: readonly string[]; doc: string }\n | { kind: 'object'; fields: Record<string, Field>; doc: string; required?: readonly string[] }\n | { kind: 'map'; of: Field; doc: string }\n | { kind: 'outputs'; doc: string };\n\nconst num = (doc: string): Field => ({ kind: 'number', doc });\n\nexport const INPUT_TYPES = ['int', 'float', 'bool', 'string', 'text_area', 'source', 'color', 'timeframe', 'session', 'time', 'symbol', 'enum'] as const;\nexport const OUTPUT_KINDS = ['plot', 'shape', 'char', 'arrow', 'candle', 'bar', 'hline', 'bgcolor', 'barcolor', 'alertcondition'] as const;\n\n/** The keys of a spec checked by checkScript. */\nexport const SPEC_FIELDS: Record<string, Field> = {\n kind: { kind: 'enum', values: ['indicator', 'strategy'], doc: 'indicator() or strategy()' },\n title: { kind: 'string', doc: 'the title of the declaration' },\n overlay: { kind: 'boolean', doc: 'true: price pane, false: own pane' },\n inputs: {\n kind: 'map',\n doc: 'inputs that must exist, by id or title',\n of: {\n kind: 'object',\n doc: 'the expected input',\n fields: {\n type: { kind: 'enum', values: INPUT_TYPES, doc: 'input type' },\n defval: { kind: 'any', doc: 'default value' },\n title: { kind: 'string', doc: 'title' },\n min: num('minval'),\n max: num('maxval'),\n options: { kind: 'string[]', doc: 'the choices of a string input' },\n },\n },\n },\n outputs: { kind: 'outputs', doc: 'outputs that must exist: a title, or { title, kind }' },\n plots: {\n kind: 'map',\n doc: 'value checks per plot, by id or title',\n of: {\n kind: 'object',\n doc: 'the expected values',\n fields: { min: num('every value is at least this'), max: num('every value is at most this'), warmup: num('the first value comes at this bar index or before') },\n },\n },\n signals: {\n kind: 'map',\n doc: 'count checks per signal (shape, char, arrow, alertcondition, bgcolor, barcolor), by id or title',\n of: {\n kind: 'object',\n doc: 'the expected count',\n fields: {\n min: num('at least this many bars'),\n max: num('at most this many bars'),\n minShare: num('at least this share of the bars (0 to 1)'),\n maxShare: num('at most this share of the bars (0 to 1)'),\n },\n },\n },\n trades: { kind: 'object', doc: 'closed trades of a strategy', fields: { min: num('at least'), max: num('at most') } },\n};\n\n/** The keys of a spec file read by the `oakscript check` command (paths relative to the spec file). */\nexport const SPEC_FILE_FIELDS: Record<string, Field> = {\n $schema: { kind: 'string', doc: 'the JSON Schema of the spec (oakscriptjs/skills/oakscript/spec.schema.json)' },\n reference: { kind: 'string', doc: 'CSV of expected values per bar (a time column, one column per plot)' },\n export: { kind: 'string', doc: 'chart export CSV: the bars (time, open, high, low, close, volume) and the expected plot values' },\n tolerance: num('relative tolerance of the reference values (default 1e-10)'),\n checks: { kind: 'string', doc: 'JavaScript file of behaviour checks (the body of a function of `t`)' },\n scenarios: { kind: 'boolean', doc: 'also run on the built-in edge-case bars' },\n};\n\nfunction closest(name: string, names: string[]): string | undefined {\n const dist = (a: string, b: string): number => {\n const row = Array.from({ length: b.length + 1 }, (_, j) => j);\n for (let i = 1; i <= a.length; i++) {\n let diag = row[0]!;\n row[0] = i;\n for (let j = 1; j <= b.length; j++) {\n const up = row[j]!;\n row[j] = Math.min(up + 1, row[j - 1]! + 1, diag + (a[i - 1] === b[j - 1] ? 0 : 1));\n diag = up;\n }\n }\n return row[b.length]!;\n };\n const n = name.toLowerCase();\n const best = names.map((k) => ({ k, d: dist(n, k.toLowerCase()) })).sort((a, b) => a.d - b.d)[0];\n if (!best) return undefined;\n return best.d <= Math.max(2, Math.floor(name.length / 2)) || best.k.toLowerCase().startsWith(n.slice(0, 3)) ? best.k : undefined;\n}\n\nfunction check(value: unknown, field: Field, path: string, errors: string[]): void {\n const fail = (what: string): void => {\n errors.push(`${path}: ${what}`);\n };\n switch (field.kind) {\n case 'any':\n return;\n case 'string':\n case 'number':\n case 'boolean':\n if (typeof value !== field.kind || (field.kind === 'number' && !Number.isFinite(value))) fail(`expected a ${field.kind}, got ${JSON.stringify(value)}`);\n return;\n case 'string[]':\n if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) fail(`expected an array of strings, got ${JSON.stringify(value)}`);\n return;\n case 'enum':\n if (typeof value !== 'string' || !field.values.includes(value)) fail(`expected one of ${field.values.join(', ')}, got ${JSON.stringify(value)}`);\n return;\n case 'outputs':\n if (!Array.isArray(value)) return fail('expected an array of titles or { title, kind }');\n value.forEach((o, k) => {\n if (typeof o === 'string') return;\n check(o, { kind: 'object', doc: '', required: ['title'], fields: { title: { kind: 'string', doc: '' }, kind: { kind: 'enum', values: OUTPUT_KINDS, doc: '' } } }, `${path}[${k}]`, errors);\n });\n return;\n case 'map':\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return fail('expected an object (name -> checks)');\n for (const [k, v] of Object.entries(value)) check(v, field.of, `${path}.${k}`, errors);\n return;\n case 'object': {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return fail('expected an object');\n const keys = Object.keys(field.fields);\n for (const [k, v] of Object.entries(value)) {\n const f = field.fields[k];\n if (!f) {\n const near = closest(k, keys);\n fail(`unknown key \"${k}\"${near ? ` (did you mean \"${near}\"?)` : ''}; the keys are ${keys.join(', ')}`);\n } else check(v, f, `${path}.${k}`, errors);\n }\n for (const r of field.required ?? []) if (!(r in (value as object))) fail(`\"${r}\" is required`);\n return;\n }\n }\n}\n\n/**\n * The problems of a spec: unknown keys (with the closest key) and wrong values, one message per problem; empty when the\n * spec is valid. `file`: also accept the keys of a spec file (reference, export, tolerance, checks, scenarios).\n */\nexport function validateSpec(spec: unknown, options: { file?: boolean } = {}): string[] {\n const errors: string[] = [];\n const fields = options.file ? { ...SPEC_FIELDS, ...SPEC_FILE_FIELDS } : SPEC_FIELDS;\n check(spec, { kind: 'object', doc: '', fields }, 'spec', errors);\n return errors;\n}\n\nfunction schemaOf(field: Field): Record<string, unknown> {\n const description = field.doc ? { description: field.doc } : {};\n switch (field.kind) {\n case 'any':\n return { ...description };\n case 'string':\n case 'number':\n case 'boolean':\n return { type: field.kind, ...description };\n case 'string[]':\n return { type: 'array', items: { type: 'string' }, ...description };\n case 'enum':\n return { enum: [...field.values], ...description };\n case 'outputs':\n return {\n type: 'array',\n ...description,\n items: {\n oneOf: [\n { type: 'string' },\n { type: 'object', additionalProperties: false, required: ['title'], properties: { title: { type: 'string' }, kind: { enum: [...OUTPUT_KINDS] } } },\n ],\n },\n };\n case 'map':\n return { type: 'object', ...description, additionalProperties: schemaOf(field.of) };\n case 'object':\n return {\n type: 'object',\n ...description,\n additionalProperties: false,\n ...(field.required ? { required: [...field.required] } : {}),\n properties: Object.fromEntries(Object.entries(field.fields).map(([k, f]) => [k, schemaOf(f)])),\n };\n }\n}\n\n/** JSON Schema (draft 2020-12) of a spec file of `oakscript check`. */\nexport function specJsonSchema(): Record<string, unknown> {\n return {\n $schema: 'https://json-schema.org/draft/2020-12/schema',\n title: 'oakscript check spec',\n description: 'What the user asked for, checked by `oakscript check --spec`: every given entry is checked, an unknown key is an error.',\n ...schemaOf({ kind: 'object', doc: '', fields: { ...SPEC_FIELDS, ...SPEC_FILE_FIELDS } }),\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,MAAM,MAAM,CAAC,SAAwB,EAAE,MAAM,UAAU,IAAI;AAEpD,MAAM,cAAc,CAAC,OAAO,SAAS,QAAQ,UAAU,aAAa,UAAU,SAAS,aAAa,WAAW,QAAQ,UAAU,MAAM;AACvI,MAAM,eAAe,CAAC,QAAQ,SAAS,QAAQ,SAAS,UAAU,OAAO,SAAS,WAAW,YAAY,gBAAgB;AAGzH,MAAM,cAAqC;AAAA,EAChD,MAAM,EAAE,MAAM,QAAQ,QAAQ,CAAC,aAAa,UAAU,GAAG,KAAK,4BAA4B;AAAA,EAC1F,OAAO,EAAE,MAAM,UAAU,KAAK,+BAA+B;AAAA,EAC7D,SAAS,EAAE,MAAM,WAAW,KAAK,oCAAoC;AAAA,EACrE,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,IAAI;AAAA,MACF,MAAM;AAAA,MACN,KAAK;AAAA,MACL,QAAQ;AAAA,QACN,MAAM,EAAE,MAAM,QAAQ,QAAQ,aAAa,KAAK,aAAa;AAAA,QAC7D,QAAQ,EAAE,MAAM,OAAO,KAAK,gBAAgB;AAAA,QAC5C,OAAO,EAAE,MAAM,UAAU,KAAK,QAAQ;AAAA,QACtC,KAAK,IAAI,QAAQ;AAAA,QACjB,KAAK,IAAI,QAAQ;AAAA,QACjB,SAAS,EAAE,MAAM,YAAY,KAAK,gCAAgC;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AAAA,EACA,SAAS,EAAE,MAAM,WAAW,KAAK,uDAAuD;AAAA,EACxF,OAAO;AAAA,IACL,MAAM;AAAA,IACN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AE,EAAE;AAAA,IACpF,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,GAAG;AAAA,QACH,sBAAsB;AAAA,QACtB,GAAI,MAAM,WAAW,EAAE,UAAU,CAAC,GAAG,MAAM,QAAQ,EAAE,IAAI,CAAC;AAAA,QAC1D,YAAY,OAAO,YAAY,OAAO,QAAQ,MAAM,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAAA,MAC/F;AAAA,EACJ;AACF;AAGO,SAAS,iBAA0C;AACxD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,IACP,aAAa;AAAA,IACb,GAAG,SAAS,EAAE,MAAM,UAAU,KAAK,IAAI,QAAQ,EAAE,GAAG,aAAa,GAAG,iBAAiB,EAAE,CAAC;AAAA,EAC1F;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -74,9 +74,9 @@ export interface InputConfig {
|
|
|
74
74
|
/**
|
|
75
75
|
* Type of input. `timeframe` and `session` values are strings ("60", "1D", "0930-1600:23456";
|
|
76
76
|
* an empty timeframe means the chart timeframe), `time` values are UNIX times in milliseconds. A `text_area`
|
|
77
|
-
* value is a string that can hold several lines.
|
|
77
|
+
* value is a string that can hold several lines. An `enum` value is the field name of one of its `options`.
|
|
78
78
|
*/
|
|
79
|
-
type: 'int' | 'float' | 'bool' | 'string' | 'text_area' | 'source' | 'color' | 'timeframe' | 'session' | 'time' | 'symbol';
|
|
79
|
+
type: 'int' | 'float' | 'bool' | 'string' | 'text_area' | 'source' | 'color' | 'timeframe' | 'session' | 'time' | 'symbol' | 'enum';
|
|
80
80
|
/** Default value */
|
|
81
81
|
defval: unknown;
|
|
82
82
|
/** Display title */
|
|
@@ -87,8 +87,13 @@ export interface InputConfig {
|
|
|
87
87
|
max?: number;
|
|
88
88
|
/** Step size (for numeric inputs) */
|
|
89
89
|
step?: number;
|
|
90
|
-
/**
|
|
91
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Options for dropdown selection: strings (string, timeframe, session and symbol inputs), numbers (int and float
|
|
92
|
+
* inputs) or the field names of an enum input
|
|
93
|
+
*/
|
|
94
|
+
options?: (string | number)[];
|
|
95
|
+
/** Titles of the options of an enum input, by field name */
|
|
96
|
+
optionsTitles?: Record<string, string>;
|
|
92
97
|
/** Settings group header (PineScript `group`) */
|
|
93
98
|
group?: string;
|
|
94
99
|
/** Inputs with the same `inline` id are shown on one line (PineScript `inline`) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/runtime/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CAC7E;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC;IAC/D,qCAAqC;IACrC,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC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GAAG,EAAE,MAAM,EAAE,CAAC;IACd,mBAAmB;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,kBAAkB;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,KAAK,EAAE,YAAY,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,YAAY,CAAC;IACrB,kDAAkD;IAClD,KAAK,EAAE,SAAS,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Type definitions for OakScriptJS runtime\n * These types define the adapter interfaces and context structure for the runtime system\n * @module runtime/types\n */\n\nimport type { FillGradient } from '../types/metadata.js';\n\n/**\n * Handle returned by ChartAdapter.addSeries\n * Represents a series on the chart with ability to update data\n */\nexport interface SeriesHandle {\n /** Set the data for this series */\n setData(data: Array<{ time: number; value: number; color?: string }>): void;\n}\n\n/**\n * Options for creating a series on the chart\n */\nexport interface SeriesOptions {\n /** Series color */\n color?: string;\n /** Line width */\n lineWidth?: number;\n /** Line style (0 = solid, 1 = dotted, 2 = dashed, etc.) */\n lineStyle?: number;\n /** Price scale ID */\n priceScaleId?: string;\n /** Pane index */\n pane?: number;\n}\n\n/**\n * Chart adapter interface\n * Implementations translate library calls into chart library operations\n */\nexport interface ChartAdapter {\n /** Add a new series to the chart */\n addSeries(type: string, options?: SeriesOptions): SeriesHandle;\n /** Remove a series from the chart */\n removeSeries(series: SeriesHandle): void;\n /** Get the main price series (optional, may return undefined) */\n getMainSeries?(): SeriesHandle | undefined;\n /** Create a new pane and return its index (optional) */\n createPane?(): number;\n}\n\n/**\n * Condition on other inputs, as plain data (PineScript `active = <expression>`):\n * - `'showMa'`: the bool input `showMa` is true\n * - `{ input: 'maType', eq: 'SMA' }` / `{ input: 'maType', ne: 'None' }`: the value of an input is / is not a value\n * (strict equality; without `eq` and `ne`: the input is true)\n * - `{ not: c }`, `{ any: [c1, c2] }` (or), `{ all: [c1, c2] }` (and)\n *\n * Evaluated by `isInputActive()`.\n */\nexport type InputCondition =\n | string\n | { input: string; eq?: unknown; ne?: unknown }\n | { not: InputCondition }\n | { any: InputCondition[] }\n | { all: InputCondition[] };\n\n/**\n * Configuration for registering an input\n */\nexport interface InputConfig {\n /** Unique identifier for the input */\n id: string;\n /**\n * Type of input. `timeframe` and `session` values are strings (\"60\", \"1D\", \"0930-1600:23456\";\n * an empty timeframe means the chart timeframe), `time` values are UNIX times in milliseconds. A `text_area`\n * value is a string that can hold several lines.\n */\n type: 'int' | 'float' | 'bool' | 'string' | 'text_area' | 'source' | 'color' | 'timeframe' | 'session' | 'time' | 'symbol';\n /** Default value */\n defval: unknown;\n /** Display title */\n title?: string;\n /** Minimum value (for numeric inputs) */\n min?: number;\n /** Maximum value (for numeric inputs) */\n max?: number;\n /** Step size (for numeric inputs) */\n step?: number;\n /** Options for dropdown selection (for string, timeframe and session inputs) */\n options?: string[];\n /** Settings group header (PineScript `group`) */\n group?: string;\n /** Inputs with the same `inline` id are shown on one line (PineScript `inline`) */\n inline?: string;\n /** Info tooltip of the input (PineScript `tooltip`) */\n tooltip?: string;\n /** Ask for the value when the script is added to a chart (PineScript `confirm`) */\n confirm?: boolean;\n /**\n * Where the input value is shown (PineScript `display`); not set means the PineScript default: 'none' for\n * bool, color, time and text_area inputs, 'all' for the others\n */\n display?: 'all' | 'none' | 'data_window' | 'status_line';\n /**\n * Whether the input can be edited (PineScript `active`): an inactive input is shown greyed out in the settings.\n * UI only: an inactive input still gives its value to the script. Not set means always active. A boolean is the\n * value for the current inputs; an `InputCondition` names the inputs it depends on, so a host can apply it\n * without running the script (see `isInputActive()`)\n */\n active?: boolean | InputCondition;\n}\n\n/**\n * Configuration for plot outputs in generated indicators\n */\nexport interface PlotConfig {\n /** Unique identifier for the plot */\n id: string;\n /** Display title */\n title: string;\n /** Plot color */\n color: string;\n /** Line width in pixels */\n lineWidth?: number;\n /** Plot style */\n style?: 'line' | 'stepline' | 'histogram' | 'area' | 'circles' | 'columns' | 'cross' | 'areabr' | 'steplinebr' | 'linebr' | 'stepline_diamond';\n /** Whether the plot is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n /** Display mode: 'all', 'none', 'data_window', 'status_line', 'pane' */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Offset in bars (positive = future, negative = past) */\n offset?: number;\n /** Histogram base value */\n histbase?: number;\n /** Line style (PineScript `linestyle`); default solid. A constant or an input value, not per bar */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the plot chooses from per bar when they are a fixed set (PineScript palette of a plot coloured by a\n * condition): a user can change each of them, the points drawn with one take the new colour. Unset: `color` (one\n * colour) or colours computed per bar\n */\n palette?: string[];\n}\n\n/**\n * Configuration of a PineScript `plotarrow()` declaration: an up arrow (below the bar) for a positive value, a down\n * arrow (above the bar) for a negative value, nothing for 0 / na. The arrow height scales with the absolute value\n * between `minheight` and `maxheight` pixels (drawn by the renderer).\n */\nexport interface ArrowConfig {\n /** Unique identifier (key of the arrow data in the result) */\n id: string;\n /** Display title */\n title?: string;\n /** Color of the up arrows (PineScript default #00FF00) */\n colorup: string;\n /** Color of the down arrows (PineScript default #FF0000) */\n colordown: string;\n /** Minimal arrow height in pixels (PineScript default 5) */\n minheight: number;\n /** Maximal arrow height in pixels (PineScript default 100) */\n maxheight: number;\n /** Offset in bars (applied to the emitted arrow times) */\n offset?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n}\n\n/**\n * Configuration of a PineScript `plotcandle()` (kind 'candle') or `plotbar()` (kind 'bar') declaration. The candles\n * are in `result.plotCandles[id]`, the bars in `result.plotBars[id]`.\n */\nexport interface CandleConfig {\n /** Unique identifier (key of the data in the result) */\n id: string;\n /** 'candle' for plotcandle, 'bar' for plotbar */\n kind: 'candle' | 'bar';\n /** Display title */\n title?: string;\n /** Static body colour (plotcandle) or bar colour (plotbar) */\n color?: string;\n /** Static wick colour (plotcandle only) */\n wickColor?: string;\n /** Static border colour (plotcandle only) */\n borderColor?: string;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the study chooses from per bar (the PineScript palette of the body / wick / border colour), when they\n * are a fixed set: a user can change each of them. Unset: a single colour (`color` / `wickColor` / `borderColor`)\n * or colours computed per bar\n */\n palettes?: { color?: string[]; wickColor?: string[]; borderColor?: string[] };\n}\n\n/**\n * Configuration for horizontal line outputs in generated indicators\n * Matches PineScript hline() function parameters\n */\nexport interface HLineConfig {\n /** Unique identifier for the hline */\n id: string;\n /** Price level for the horizontal line */\n price: number;\n /** Display title */\n title?: string;\n /** Line color */\n color?: string;\n /** Line style: solid, dashed, or dotted (PineScript default: dashed) */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Line width in pixels */\n linewidth?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n}\n\n/**\n * Configuration for fill between plots or hlines in generated indicators\n * Matches PineScript fill() function parameters\n */\nexport interface FillConfig {\n /** Unique identifier for the fill */\n id: string;\n /** ID of the first plot or hline */\n plot1: string;\n /** ID of the second plot or hline */\n plot2: string;\n /** Fill color */\n color?: string;\n /** Per-bar fill colors (overrides static color) */\n colors?: string[];\n /** Gradient fill (PineScript `fill(hline1, hline2, top_value, bottom_value, top_color, bottom_color)`) */\n gradient?: FillGradient;\n /** Display title */\n title?: string;\n /** Whether the fill is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /** Gradient fill: its colour at the top value when it is the same on every bar */\n topColor?: string;\n /** Gradient fill: its colour at the bottom value when it is the same on every bar */\n bottomColor?: string;\n /**\n * The colours the fill chooses from per bar when they are a fixed set (PineScript palette): a user can change each\n * of them. Unset: `color` (one colour) or colours computed per bar\n */\n palette?: string[];\n}\n\n/**\n * Configuration for plotshape/plotchar outputs in generated indicators\n * Matches PineScript plotshape()/plotchar() declarative parameters\n */\nexport interface ShapeConfig {\n /** Unique identifier for the shape declaration */\n id: string;\n /** 'shape' for plotshape, 'char' for plotchar */\n kind: 'shape' | 'char';\n /** Display title */\n title?: string;\n /** Shape style (plotshape only) */\n style?: 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' | 'arrowup' | 'arrowdown' | 'labelup' | 'labeldown' | 'square' | 'diamond';\n /** Character (plotchar only) */\n char?: string;\n /** Marker location relative to the bar */\n location: 'abovebar' | 'belowbar' | 'top' | 'bottom' | 'absolute';\n /** Marker color */\n color?: string;\n /** Text shown near the marker */\n text?: string;\n /** Text color */\n textcolor?: string;\n /** Marker size */\n size?: 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';\n /** Offset in bars (applied to the emitted marker times) */\n offset?: number;\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the output chooses from per bar when they are a fixed set (PineScript palette): a user can change\n * each of them. Unset: `color` (one colour) or colours computed per bar\n */\n palette?: string[];\n}\n\n/**\n * Configuration for bgcolor/barcolor outputs in generated indicators\n */\nexport interface BarColorConfig {\n /** Unique identifier */\n id: string;\n /** 'bgcolor' or 'barcolor' */\n kind: 'bgcolor' | 'barcolor';\n /** Display title */\n title?: string;\n /** Offset in bars (bgcolor only, already baked into emitted data) */\n offset?: number;\n /** bgcolor only: drawn on the main chart pane even when the script is not an overlay (PineScript\n * `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the output chooses from per bar (PineScript palette): a user can change each of them. A colour given\n * as a constant is a palette of one colour. Unset: colours computed per bar\n */\n palette?: string[];\n /**\n * Where the output comes among the plot / shape / character / arrow / candle outputs (`outputs` of the script): it\n * was declared after the first `outputIndex` of them. The Style settings list it there. Unset: after all of them\n */\n outputIndex?: number;\n}\n\n/**\n * Options for numeric inputs\n */\nexport interface InputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n}\n\n/**\n * Input adapter interface\n * Implementations handle input registration and value management\n */\nexport interface InputAdapter {\n /** Register an input, returns current value (possibly user-updated) */\n registerInput(config: InputConfig): unknown;\n /** Get current value of an input */\n getValue(id: string): unknown;\n /** Set value of an input */\n setValue(id: string, value: unknown): void;\n /** Register callback for input changes */\n onInputChange(callback: (id: string, value: unknown) => void): void;\n}\n\n/**\n * OHLCV data structure\n * Provides access to price and volume time series\n */\nexport interface OhlcvData {\n /** Timestamps for each bar */\n time: number[];\n /** Open prices */\n open: number[];\n /** High prices */\n high: number[];\n /** Low prices */\n low: number[];\n /** Close prices */\n close: number[];\n /** Volume data */\n volume: number[];\n}\n\n/**\n * Global context object for OakScriptJS runtime\n * Must be set by host application before calling any indicator calculate function\n */\nexport interface OakScriptContext {\n /** Chart adapter for plot operations */\n chart: ChartAdapter;\n /** Input adapter for managing indicator inputs */\n inputs: InputAdapter;\n /** OHLCV data for the current symbol/timeframe */\n ohlcv: OhlcvData;\n /** Current bar index (typically the last bar) */\n bar_index: number;\n}\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Type definitions for OakScriptJS runtime\n * These types define the adapter interfaces and context structure for the runtime system\n * @module runtime/types\n */\n\nimport type { FillGradient } from '../types/metadata.js';\n\n/**\n * Handle returned by ChartAdapter.addSeries\n * Represents a series on the chart with ability to update data\n */\nexport interface SeriesHandle {\n /** Set the data for this series */\n setData(data: Array<{ time: number; value: number; color?: string }>): void;\n}\n\n/**\n * Options for creating a series on the chart\n */\nexport interface SeriesOptions {\n /** Series color */\n color?: string;\n /** Line width */\n lineWidth?: number;\n /** Line style (0 = solid, 1 = dotted, 2 = dashed, etc.) */\n lineStyle?: number;\n /** Price scale ID */\n priceScaleId?: string;\n /** Pane index */\n pane?: number;\n}\n\n/**\n * Chart adapter interface\n * Implementations translate library calls into chart library operations\n */\nexport interface ChartAdapter {\n /** Add a new series to the chart */\n addSeries(type: string, options?: SeriesOptions): SeriesHandle;\n /** Remove a series from the chart */\n removeSeries(series: SeriesHandle): void;\n /** Get the main price series (optional, may return undefined) */\n getMainSeries?(): SeriesHandle | undefined;\n /** Create a new pane and return its index (optional) */\n createPane?(): number;\n}\n\n/**\n * Condition on other inputs, as plain data (PineScript `active = <expression>`):\n * - `'showMa'`: the bool input `showMa` is true\n * - `{ input: 'maType', eq: 'SMA' }` / `{ input: 'maType', ne: 'None' }`: the value of an input is / is not a value\n * (strict equality; without `eq` and `ne`: the input is true)\n * - `{ not: c }`, `{ any: [c1, c2] }` (or), `{ all: [c1, c2] }` (and)\n *\n * Evaluated by `isInputActive()`.\n */\nexport type InputCondition =\n | string\n | { input: string; eq?: unknown; ne?: unknown }\n | { not: InputCondition }\n | { any: InputCondition[] }\n | { all: InputCondition[] };\n\n/**\n * Configuration for registering an input\n */\nexport interface InputConfig {\n /** Unique identifier for the input */\n id: string;\n /**\n * Type of input. `timeframe` and `session` values are strings (\"60\", \"1D\", \"0930-1600:23456\";\n * an empty timeframe means the chart timeframe), `time` values are UNIX times in milliseconds. A `text_area`\n * value is a string that can hold several lines. An `enum` value is the field name of one of its `options`.\n */\n type: 'int' | 'float' | 'bool' | 'string' | 'text_area' | 'source' | 'color' | 'timeframe' | 'session' | 'time' | 'symbol' | 'enum';\n /** Default value */\n defval: unknown;\n /** Display title */\n title?: string;\n /** Minimum value (for numeric inputs) */\n min?: number;\n /** Maximum value (for numeric inputs) */\n max?: number;\n /** Step size (for numeric inputs) */\n step?: number;\n /**\n * Options for dropdown selection: strings (string, timeframe, session and symbol inputs), numbers (int and float\n * inputs) or the field names of an enum input\n */\n options?: (string | number)[];\n /** Titles of the options of an enum input, by field name */\n optionsTitles?: Record<string, string>;\n /** Settings group header (PineScript `group`) */\n group?: string;\n /** Inputs with the same `inline` id are shown on one line (PineScript `inline`) */\n inline?: string;\n /** Info tooltip of the input (PineScript `tooltip`) */\n tooltip?: string;\n /** Ask for the value when the script is added to a chart (PineScript `confirm`) */\n confirm?: boolean;\n /**\n * Where the input value is shown (PineScript `display`); not set means the PineScript default: 'none' for\n * bool, color, time and text_area inputs, 'all' for the others\n */\n display?: 'all' | 'none' | 'data_window' | 'status_line';\n /**\n * Whether the input can be edited (PineScript `active`): an inactive input is shown greyed out in the settings.\n * UI only: an inactive input still gives its value to the script. Not set means always active. A boolean is the\n * value for the current inputs; an `InputCondition` names the inputs it depends on, so a host can apply it\n * without running the script (see `isInputActive()`)\n */\n active?: boolean | InputCondition;\n}\n\n/**\n * Configuration for plot outputs in generated indicators\n */\nexport interface PlotConfig {\n /** Unique identifier for the plot */\n id: string;\n /** Display title */\n title: string;\n /** Plot color */\n color: string;\n /** Line width in pixels */\n lineWidth?: number;\n /** Plot style */\n style?: 'line' | 'stepline' | 'histogram' | 'area' | 'circles' | 'columns' | 'cross' | 'areabr' | 'steplinebr' | 'linebr' | 'stepline_diamond';\n /** Whether the plot is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n /** Display mode: 'all', 'none', 'data_window', 'status_line', 'pane' */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Offset in bars (positive = future, negative = past) */\n offset?: number;\n /** Histogram base value */\n histbase?: number;\n /** Line style (PineScript `linestyle`); default solid. A constant or an input value, not per bar */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the plot chooses from per bar when they are a fixed set (PineScript palette of a plot coloured by a\n * condition): a user can change each of them, the points drawn with one take the new colour. Unset: `color` (one\n * colour) or colours computed per bar\n */\n palette?: string[];\n}\n\n/**\n * Configuration of a PineScript `plotarrow()` declaration: an up arrow (below the bar) for a positive value, a down\n * arrow (above the bar) for a negative value, nothing for 0 / na. The arrow height scales with the absolute value\n * between `minheight` and `maxheight` pixels (drawn by the renderer).\n */\nexport interface ArrowConfig {\n /** Unique identifier (key of the arrow data in the result) */\n id: string;\n /** Display title */\n title?: string;\n /** Color of the up arrows (PineScript default #00FF00) */\n colorup: string;\n /** Color of the down arrows (PineScript default #FF0000) */\n colordown: string;\n /** Minimal arrow height in pixels (PineScript default 5) */\n minheight: number;\n /** Maximal arrow height in pixels (PineScript default 100) */\n maxheight: number;\n /** Offset in bars (applied to the emitted arrow times) */\n offset?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n}\n\n/**\n * Configuration of a PineScript `plotcandle()` (kind 'candle') or `plotbar()` (kind 'bar') declaration. The candles\n * are in `result.plotCandles[id]`, the bars in `result.plotBars[id]`.\n */\nexport interface CandleConfig {\n /** Unique identifier (key of the data in the result) */\n id: string;\n /** 'candle' for plotcandle, 'bar' for plotbar */\n kind: 'candle' | 'bar';\n /** Display title */\n title?: string;\n /** Static body colour (plotcandle) or bar colour (plotbar) */\n color?: string;\n /** Static wick colour (plotcandle only) */\n wickColor?: string;\n /** Static border colour (plotcandle only) */\n borderColor?: string;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the study chooses from per bar (the PineScript palette of the body / wick / border colour), when they\n * are a fixed set: a user can change each of them. Unset: a single colour (`color` / `wickColor` / `borderColor`)\n * or colours computed per bar\n */\n palettes?: { color?: string[]; wickColor?: string[]; borderColor?: string[] };\n}\n\n/**\n * Configuration for horizontal line outputs in generated indicators\n * Matches PineScript hline() function parameters\n */\nexport interface HLineConfig {\n /** Unique identifier for the hline */\n id: string;\n /** Price level for the horizontal line */\n price: number;\n /** Display title */\n title?: string;\n /** Line color */\n color?: string;\n /** Line style: solid, dashed, or dotted (PineScript default: dashed) */\n linestyle?: 'solid' | 'dashed' | 'dotted';\n /** Line width in pixels */\n linewidth?: number;\n /** Display mode */\n display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n}\n\n/**\n * Configuration for fill between plots or hlines in generated indicators\n * Matches PineScript fill() function parameters\n */\nexport interface FillConfig {\n /** Unique identifier for the fill */\n id: string;\n /** ID of the first plot or hline */\n plot1: string;\n /** ID of the second plot or hline */\n plot2: string;\n /** Fill color */\n color?: string;\n /** Per-bar fill colors (overrides static color) */\n colors?: string[];\n /** Gradient fill (PineScript `fill(hline1, hline2, top_value, bottom_value, top_color, bottom_color)`) */\n gradient?: FillGradient;\n /** Display title */\n title?: string;\n /** Whether the fill is visible (can be boolean or expression string for dynamic visibility) */\n visible?: boolean | string;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /** Gradient fill: its colour at the top value when it is the same on every bar */\n topColor?: string;\n /** Gradient fill: its colour at the bottom value when it is the same on every bar */\n bottomColor?: string;\n /**\n * The colours the fill chooses from per bar when they are a fixed set (PineScript palette): a user can change each\n * of them. Unset: `color` (one colour) or colours computed per bar\n */\n palette?: string[];\n}\n\n/**\n * Configuration for plotshape/plotchar outputs in generated indicators\n * Matches PineScript plotshape()/plotchar() declarative parameters\n */\nexport interface ShapeConfig {\n /** Unique identifier for the shape declaration */\n id: string;\n /** 'shape' for plotshape, 'char' for plotchar */\n kind: 'shape' | 'char';\n /** Display title */\n title?: string;\n /** Shape style (plotshape only) */\n style?: 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' | 'arrowup' | 'arrowdown' | 'labelup' | 'labeldown' | 'square' | 'diamond';\n /** Character (plotchar only) */\n char?: string;\n /** Marker location relative to the bar */\n location: 'abovebar' | 'belowbar' | 'top' | 'bottom' | 'absolute';\n /** Marker color */\n color?: string;\n /** Text shown near the marker */\n text?: string;\n /** Text color */\n textcolor?: string;\n /** Marker size */\n size?: 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';\n /** Offset in bars (applied to the emitted marker times) */\n offset?: number;\n /** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the output chooses from per bar when they are a fixed set (PineScript palette): a user can change\n * each of them. Unset: `color` (one colour) or colours computed per bar\n */\n palette?: string[];\n}\n\n/**\n * Configuration for bgcolor/barcolor outputs in generated indicators\n */\nexport interface BarColorConfig {\n /** Unique identifier */\n id: string;\n /** 'bgcolor' or 'barcolor' */\n kind: 'bgcolor' | 'barcolor';\n /** Display title */\n title?: string;\n /** Offset in bars (bgcolor only, already baked into emitted data) */\n offset?: number;\n /** bgcolor only: drawn on the main chart pane even when the script is not an overlay (PineScript\n * `force_overlay`); default false */\n forceOverlay?: boolean;\n /**\n * False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still\n * drawn. Default true\n */\n editable?: boolean;\n /**\n * The colours the output chooses from per bar (PineScript palette): a user can change each of them. A colour given\n * as a constant is a palette of one colour. Unset: colours computed per bar\n */\n palette?: string[];\n /**\n * Where the output comes among the plot / shape / character / arrow / candle outputs (`outputs` of the script): it\n * was declared after the first `outputIndex` of them. The Style settings list it there. Unset: after all of them\n */\n outputIndex?: number;\n}\n\n/**\n * Options for numeric inputs\n */\nexport interface InputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n}\n\n/**\n * Input adapter interface\n * Implementations handle input registration and value management\n */\nexport interface InputAdapter {\n /** Register an input, returns current value (possibly user-updated) */\n registerInput(config: InputConfig): unknown;\n /** Get current value of an input */\n getValue(id: string): unknown;\n /** Set value of an input */\n setValue(id: string, value: unknown): void;\n /** Register callback for input changes */\n onInputChange(callback: (id: string, value: unknown) => void): void;\n}\n\n/**\n * OHLCV data structure\n * Provides access to price and volume time series\n */\nexport interface OhlcvData {\n /** Timestamps for each bar */\n time: number[];\n /** Open prices */\n open: number[];\n /** High prices */\n high: number[];\n /** Low prices */\n low: number[];\n /** Close prices */\n close: number[];\n /** Volume data */\n volume: number[];\n}\n\n/**\n * Global context object for OakScriptJS runtime\n * Must be set by host application before calling any indicator calculate function\n */\nexport interface OakScriptContext {\n /** Chart adapter for plot operations */\n chart: ChartAdapter;\n /** Input adapter for managing indicator inputs */\n inputs: InputAdapter;\n /** OHLCV data for the current symbol/timeframe */\n ohlcv: OhlcvData;\n /** Current bar index (typically the last bar) */\n bar_index: number;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -48,6 +48,7 @@ declare global {
|
|
|
48
48
|
const holdDrawing: typeof S.holdDrawing;
|
|
49
49
|
const releaseDrawing: typeof S.releaseDrawing;
|
|
50
50
|
const varDrawing: typeof S.varDrawing;
|
|
51
|
+
const defineEnum: typeof S.defineEnum;
|
|
51
52
|
const StrategyRecorder: typeof S.StrategyRecorder;
|
|
52
53
|
const input: typeof S.input;
|
|
53
54
|
const open: typeof S.open;
|
|
@@ -85,6 +86,9 @@ declare global {
|
|
|
85
86
|
const barstate: typeof S.barstate;
|
|
86
87
|
const session: typeof S.session;
|
|
87
88
|
const barmerge: typeof S.barmerge;
|
|
89
|
+
const dividends: typeof S.dividends;
|
|
90
|
+
const splits: typeof S.splits;
|
|
91
|
+
const earnings: typeof S.earnings;
|
|
88
92
|
const ticker: typeof S.ticker;
|
|
89
93
|
const request: typeof S.request;
|
|
90
94
|
const line: typeof S.line;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../../src/script/globals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAErC,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,eAAe,EAAE,OAAO,CAAC,CAAC,eAAe,CAAC;IAChD,MAAM,eAAe,EAAE,OAAO,CAAC,CAAC,eAAe,CAAC;IAChD,MAAM,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC;IAC5B,MAAM,OAAO,EAAE,OAAO,CAAC,CAAC,OAAO,CA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,oGAAoG;IACpG,KAAK,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACvB,kEAAkE;IAClE,KAAK,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;CAChC;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/script/globals.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Type declarations of the script globals, for type-checking a script source (plain JavaScript)\n * before it runs. A script body uses every value export of `oakscriptjs/script` but `executeScript` (the host\n * entry) as a global; these declarations give each global its type, so the TypeScript checker reports the\n * mistakes of a script with their line: `close - open` (operators on a Series), a misspelt name (`ta.smaa`), a\n * wrong argument or option, a bad shape or style string.\n *\n * In a project that runs scripts, a `tsconfig.json` next to the scripts, then `npx tsc -p .`:\n *\n * ```json\n * {\n * \"compilerOptions\": {\n * \"allowJs\": true, \"checkJs\": true, \"noEmit\": true, \"strict\": true, \"noImplicitAny\": false,\n * \"target\": \"ES2022\", \"module\": \"ESNext\", \"moduleResolution\": \"bundler\", \"moduleDetection\": \"force\",\n * \"lib\": [\"ES2022\"], \"types\": [\"oakscriptjs/script/globals\"]\n * },\n * \"include\": [\"*.js\"]\n * }\n * ```\n *\n * - `lib` leaves out `DOM`: its `open`, `close` and `alert` are other globals.\n * - `moduleDetection: \"force\"`: each script has its own top-level names (a script has no import or export).\n * - `noImplicitAny: false`: the parameters of a script's own functions have no types (plain JavaScript).\n *\n * @module script/globals\n */\n\nimport type * as S from './index.js';\n\ndeclare global {\n const executeIntrabar: typeof S.executeIntrabar;\n const createScriptRun: typeof S.createScriptRun;\n const varip: typeof S.varip;\n const persist: typeof S.persist;\n const indicator: typeof S.indicator;\n const fixnan: typeof S.fixnan;\n const fill: typeof S.fill;\n const plotshape: typeof S.plotshape;\n const plotchar: typeof S.plotchar;\n const plotarrow: typeof S.plotarrow;\n const bgcolor: typeof S.bgcolor;\n const barcolor: typeof S.barcolor;\n const plotcandle: typeof S.plotcandle;\n const plotbar: typeof S.plotbar;\n const eachBar: typeof S.eachBar;\n const timestamp: typeof S.timestamp;\n const inSession: typeof S.inSession;\n const seriesOf: typeof S.seriesOf;\n const alertcondition: typeof S.alertcondition;\n const holdDrawing: typeof S.holdDrawing;\n const releaseDrawing: typeof S.releaseDrawing;\n const varDrawing: typeof S.varDrawing;\n const StrategyRecorder: typeof S.StrategyRecorder;\n const input: typeof S.input;\n const open: typeof S.open;\n const high: typeof S.high;\n const low: typeof S.low;\n const close: typeof S.close;\n const volume: typeof S.volume;\n const hl2: typeof S.hl2;\n const hlc3: typeof S.hlc3;\n const ohlc4: typeof S.ohlc4;\n const hlcc4: typeof S.hlcc4;\n const ta: typeof S.ta;\n const color: typeof S.color;\n const DEFAULT_OUTPUT_TITLES: typeof S.DEFAULT_OUTPUT_TITLES;\n const plot: typeof S.plot;\n const hline: typeof S.hline;\n const DEFAULT_CANDLE_COLORS: typeof S.DEFAULT_CANDLE_COLORS;\n const strategy: typeof S.strategy;\n const MissingSymbolDataError: typeof S.MissingSymbolDataError;\n const timeframe: typeof S.timeframe;\n const syminfo: typeof S.syminfo;\n const year: typeof S.year;\n const month: typeof S.month;\n const weekofyear: typeof S.weekofyear;\n const dayofmonth: typeof S.dayofmonth;\n const dayofweek: typeof S.dayofweek;\n const hour: typeof S.hour;\n const minute: typeof S.minute;\n const second: typeof S.second;\n const str: typeof S.str;\n const timenow: typeof S.timenow;\n const time: typeof S.time;\n const time_close: typeof S.time_close;\n const time_tradingday: typeof S.time_tradingday;\n const barstate: typeof S.barstate;\n const session: typeof S.session;\n const barmerge: typeof S.barmerge;\n const ticker: typeof S.ticker;\n const request: typeof S.request;\n const line: typeof S.line;\n const label: typeof S.label;\n const box: typeof S.box;\n const linefill: typeof S.linefill;\n const polyline: typeof S.polyline;\n const table: typeof S.table;\n const position: typeof S.position;\n const text: typeof S.text;\n const chart: typeof S.chart;\n const alert: typeof S.alert;\n const log: typeof S.log;\n const MAX_LOG_ENTRIES: typeof S.MAX_LOG_ENTRIES;\n const setLogLineResolver: typeof S.setLogLineResolver;\n const Series: typeof S.Series;\n const BarData: typeof S.BarData;\n const na: typeof S.na;\n const nz: typeof S.nz;\n const STRATEGY_DEFAULTS: typeof S.STRATEGY_DEFAULTS;\n const math: typeof S.math;\n const bar_index: typeof S.bar_index;\n const last_bar_index: typeof S.last_bar_index;\n const shape: typeof S.shape;\n const location: typeof S.location;\n const size: typeof S.size;\n const xloc: typeof S.xloc;\n const yloc: typeof S.yloc;\n const extend: typeof S.extend;\n const display: typeof S.display;\n const format: typeof S.format;\n const font: typeof S.font;\n const scale: typeof S.scale;\n const order: typeof S.order;\n const currency: typeof S.currency;\n const adjustment: typeof S.adjustment;\n const compare: typeof S.compare;\n const isInputActive: typeof S.isInputActive;\n /** A Series of the script (`close`, the result of `ta.*`...), for JSDoc types: `@type {Series}`. */\n type Series = S.Series;\n /** The bar handed to an `eachBar()` callback, for JSDoc types. */\n type BarContext = S.BarContext;\n}\n\nexport {};\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Type declarations of the script globals, for type-checking a script source (plain JavaScript)\n * before it runs. A script body uses every value export of `oakscriptjs/script` but `executeScript` (the host\n * entry) as a global; these declarations give each global its type, so the TypeScript checker reports the\n * mistakes of a script with their line: `close - open` (operators on a Series), a misspelt name (`ta.smaa`), a\n * wrong argument or option, a bad shape or style string.\n *\n * In a project that runs scripts, a `tsconfig.json` next to the scripts, then `npx tsc -p .`:\n *\n * ```json\n * {\n * \"compilerOptions\": {\n * \"allowJs\": true, \"checkJs\": true, \"noEmit\": true, \"strict\": true, \"noImplicitAny\": false,\n * \"target\": \"ES2022\", \"module\": \"ESNext\", \"moduleResolution\": \"bundler\", \"moduleDetection\": \"force\",\n * \"lib\": [\"ES2022\"], \"types\": [\"oakscriptjs/script/globals\"]\n * },\n * \"include\": [\"*.js\"]\n * }\n * ```\n *\n * - `lib` leaves out `DOM`: its `open`, `close` and `alert` are other globals.\n * - `moduleDetection: \"force\"`: each script has its own top-level names (a script has no import or export).\n * - `noImplicitAny: false`: the parameters of a script's own functions have no types (plain JavaScript).\n *\n * @module script/globals\n */\n\nimport type * as S from './index.js';\n\ndeclare global {\n const executeIntrabar: typeof S.executeIntrabar;\n const createScriptRun: typeof S.createScriptRun;\n const varip: typeof S.varip;\n const persist: typeof S.persist;\n const indicator: typeof S.indicator;\n const fixnan: typeof S.fixnan;\n const fill: typeof S.fill;\n const plotshape: typeof S.plotshape;\n const plotchar: typeof S.plotchar;\n const plotarrow: typeof S.plotarrow;\n const bgcolor: typeof S.bgcolor;\n const barcolor: typeof S.barcolor;\n const plotcandle: typeof S.plotcandle;\n const plotbar: typeof S.plotbar;\n const eachBar: typeof S.eachBar;\n const timestamp: typeof S.timestamp;\n const inSession: typeof S.inSession;\n const seriesOf: typeof S.seriesOf;\n const alertcondition: typeof S.alertcondition;\n const holdDrawing: typeof S.holdDrawing;\n const releaseDrawing: typeof S.releaseDrawing;\n const varDrawing: typeof S.varDrawing;\n const defineEnum: typeof S.defineEnum;\n const StrategyRecorder: typeof S.StrategyRecorder;\n const input: typeof S.input;\n const open: typeof S.open;\n const high: typeof S.high;\n const low: typeof S.low;\n const close: typeof S.close;\n const volume: typeof S.volume;\n const hl2: typeof S.hl2;\n const hlc3: typeof S.hlc3;\n const ohlc4: typeof S.ohlc4;\n const hlcc4: typeof S.hlcc4;\n const ta: typeof S.ta;\n const color: typeof S.color;\n const DEFAULT_OUTPUT_TITLES: typeof S.DEFAULT_OUTPUT_TITLES;\n const plot: typeof S.plot;\n const hline: typeof S.hline;\n const DEFAULT_CANDLE_COLORS: typeof S.DEFAULT_CANDLE_COLORS;\n const strategy: typeof S.strategy;\n const MissingSymbolDataError: typeof S.MissingSymbolDataError;\n const timeframe: typeof S.timeframe;\n const syminfo: typeof S.syminfo;\n const year: typeof S.year;\n const month: typeof S.month;\n const weekofyear: typeof S.weekofyear;\n const dayofmonth: typeof S.dayofmonth;\n const dayofweek: typeof S.dayofweek;\n const hour: typeof S.hour;\n const minute: typeof S.minute;\n const second: typeof S.second;\n const str: typeof S.str;\n const timenow: typeof S.timenow;\n const time: typeof S.time;\n const time_close: typeof S.time_close;\n const time_tradingday: typeof S.time_tradingday;\n const barstate: typeof S.barstate;\n const session: typeof S.session;\n const barmerge: typeof S.barmerge;\n const dividends: typeof S.dividends;\n const splits: typeof S.splits;\n const earnings: typeof S.earnings;\n const ticker: typeof S.ticker;\n const request: typeof S.request;\n const line: typeof S.line;\n const label: typeof S.label;\n const box: typeof S.box;\n const linefill: typeof S.linefill;\n const polyline: typeof S.polyline;\n const table: typeof S.table;\n const position: typeof S.position;\n const text: typeof S.text;\n const chart: typeof S.chart;\n const alert: typeof S.alert;\n const log: typeof S.log;\n const MAX_LOG_ENTRIES: typeof S.MAX_LOG_ENTRIES;\n const setLogLineResolver: typeof S.setLogLineResolver;\n const Series: typeof S.Series;\n const BarData: typeof S.BarData;\n const na: typeof S.na;\n const nz: typeof S.nz;\n const STRATEGY_DEFAULTS: typeof S.STRATEGY_DEFAULTS;\n const math: typeof S.math;\n const bar_index: typeof S.bar_index;\n const last_bar_index: typeof S.last_bar_index;\n const shape: typeof S.shape;\n const location: typeof S.location;\n const size: typeof S.size;\n const xloc: typeof S.xloc;\n const yloc: typeof S.yloc;\n const extend: typeof S.extend;\n const display: typeof S.display;\n const format: typeof S.format;\n const font: typeof S.font;\n const scale: typeof S.scale;\n const order: typeof S.order;\n const currency: typeof S.currency;\n const adjustment: typeof S.adjustment;\n const compare: typeof S.compare;\n const isInputActive: typeof S.isInputActive;\n /** A Series of the script (`close`, the result of `ta.*`...), for JSDoc types: `@type {Series}`. */\n type Series = S.Series;\n /** The bar handed to an `eachBar()` callback, for JSDoc types. */\n type BarContext = S.BarContext;\n}\n\nexport {};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|