oakscriptjs 0.20.0 → 0.21.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.
Files changed (34) hide show
  1. package/dist/cjs/check/harness.d.ts.map +1 -1
  2. package/dist/cjs/check/harness.js +35 -1
  3. package/dist/cjs/check/harness.js.map +2 -2
  4. package/dist/cjs/script/globals.d.ts +3 -0
  5. package/dist/cjs/script/globals.d.ts.map +1 -1
  6. package/dist/cjs/script/globals.js.map +1 -1
  7. package/dist/cjs/script/index.d.ts +211 -11
  8. package/dist/cjs/script/index.d.ts.map +1 -1
  9. package/dist/cjs/script/index.js +295 -29
  10. package/dist/cjs/script/index.js.map +3 -3
  11. package/dist/cjs/security/events.d.ts +16 -0
  12. package/dist/cjs/security/events.d.ts.map +1 -0
  13. package/dist/cjs/security/events.js +84 -0
  14. package/dist/cjs/security/events.js.map +7 -0
  15. package/dist/esm/check/harness.d.ts.map +1 -1
  16. package/dist/esm/check/harness.js +25 -0
  17. package/dist/esm/check/harness.js.map +1 -1
  18. package/dist/esm/script/globals.d.ts +3 -0
  19. package/dist/esm/script/globals.d.ts.map +1 -1
  20. package/dist/esm/script/globals.js.map +1 -1
  21. package/dist/esm/script/index.d.ts +211 -11
  22. package/dist/esm/script/index.d.ts.map +1 -1
  23. package/dist/esm/script/index.js +314 -35
  24. package/dist/esm/script/index.js.map +1 -1
  25. package/dist/esm/security/events.d.ts +16 -0
  26. package/dist/esm/security/events.d.ts.map +1 -0
  27. package/dist/esm/security/events.js +78 -0
  28. package/dist/esm/security/events.js.map +1 -0
  29. package/package.json +1 -1
  30. package/skills/oakscript/reference/timeframes-symbols.md +27 -0
  31. package/src/check/harness.ts +27 -0
  32. package/src/script/globals.ts +3 -0
  33. package/src/script/index.ts +502 -43
  34. 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,E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ACxB,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,oBAcO;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,gBAAgB;AACtB,MAAM,gBAAgB;AAGtB,SAAS,WAAW,QAAwB;AACjD,SAAO,gBAAgB,eAAe,MAAM,IAAI;AAClD;AAGO,SAAS,cAAc,QAA4B;AACxD,QAAM,KAAK,IAAI,SAAS,GAAG,g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AAgB,MAAM,QAAQ,OAAO,EAAE,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;",
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,SA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M,MAAM,QAAQ,UAAU,MAAM,OAAO,GAAG;AAAA,IACtE,gBAAgB,CAAC,UAAW,SAAS,IAAI,WAAW,KAAK;AAAA,EAC3D,CAAC;AACD,SAAO,EAAE,KAAK,OAAO;AACvB;AAOO,SAAS,kBACd,QACA,MACA,SAAkC,CAAC,GACnC,UAA4B,CAAC,GACd;AACf,MAAI,KAAK,SAAS,EAAG,QAAO;AAC5B,QAAM,QAAQ,QAAQ,WAAW,eAAe,MAAM;AACtD,QAAM,QAAQ,UAAU,MAAM,OAAO;AACrC,QAAM,UAAM,+BAAgB,MAAM,QAAQ,OAAO,EAAE,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
  }
@@ -85,6 +85,9 @@ declare global {
85
85
  const barstate: typeof S.barstate;
86
86
  const session: typeof S.session;
87
87
  const barmerge: typeof S.barmerge;
88
+ const dividends: typeof S.dividends;
89
+ const splits: typeof S.splits;
90
+ const earnings: typeof S.earnings;
88
91
  const ticker: typeof S.ticker;
89
92
  const request: typeof S.request;
90
93
  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,CAAC;IAChC,M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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 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
  }
@@ -569,7 +569,8 @@ export declare const ta: {
569
569
  export declare function fixnan(source: Series): Series;
570
570
  export declare function fixnan(source: Array<string | undefined>): Array<string | undefined>;
571
571
  /** PineScript `na(x)`. On a Series: a Series of 1 / 0, 1 where the value is na (NaN or +/-Infinity, #187). On a
572
- * single value (a number of a bar loop, a colour, a drawing): true when it is na. */
572
+ * single value (a number of a bar loop, a colour, a drawing): true when it is na. An empty text is na, as in
573
+ * PineScript (`na("")`, `na(syminfo.basecurrency)` of a stock). */
573
574
  export declare function na(x: Series): Series;
574
575
  export declare function na(x: unknown): boolean;
575
576
  /** PineScript `nz(source, replacement)`; replacement defaults to 0. On a Series: each na value (NaN or +/-Infinity)
@@ -942,13 +943,54 @@ export interface ChartContext {
942
943
  currency?: string;
943
944
  /**
944
945
  * Base currency of the symbol (PineScript `syminfo.basecurrency`): "BTC" for BITSTAMP:BTCUSD, BINANCE:BTCUSDT.P and
945
- * CME:BTC1!, "EUR" for FX:EURUSD, "" for a stock, an index or CME_MINI:ES1! (#180)
946
+ * CME:BTC1!, "EUR" for FX:EURUSD, "" for a stock, an index or CME_MINI:ES1! (#180).
947
+ *
948
+ * The symbol fields below, like this one: a value; null when the symbol has none (PineScript gives na: "" for a
949
+ * text, which `na()` takes as na, NaN for a number); left out when the host does not know it (reading it throws).
946
950
  */
947
- basecurrency?: string;
948
- /** Root of the symbol (PineScript `syminfo.root`): "BTC" for CME:BTC1!, "ES" for CME_MINI:ES1!, "AAPL" for NASDAQ:AAPL (#180) */
949
- root?: string;
951
+ basecurrency?: string | null;
952
+ /**
953
+ * Root of the symbol (PineScript `syminfo.root`): "BTC" for CME:BTC1!, "ES" for CME_MINI:ES1!, "AAPL" for
954
+ * NASDAQ:AAPL (#180). Default: the ticker, without the "1!" of a continuous future or the month code and year of a
955
+ * contract ("ESZ2026" of a `symbolType` "futures").
956
+ */
957
+ root?: string | null;
950
958
  /** Description of the symbol (PineScript `syminfo.description`): "Apple Inc." for NASDAQ:AAPL, "Bitcoin / U.S. dollar" for BITSTAMP:BTCUSD (#184) */
951
- description?: string;
959
+ description?: string | null;
960
+ /** Prefix of the ticker id (PineScript `syminfo.prefix`), default: the part of `tickerid` before ":" */
961
+ prefix?: string | null;
962
+ /** Ticker without its prefix (PineScript `syminfo.ticker`), default: the part of `tickerid` after ":" */
963
+ ticker?: string;
964
+ /** The chart's own symbol (PineScript `syminfo.main_tickerid`, the same inside `request.security`); default `tickerid` */
965
+ mainTickerid?: string;
966
+ /** Two-letter code of the country the symbol trades in (PineScript `syminfo.country`): "US", "IN" */
967
+ country?: string | null;
968
+ /** Contract a continuous future stands for (PineScript `syminfo.current_contract`): "ESZ2026" for CME_MINI:ES1! */
969
+ currentContract?: string | null;
970
+ /** Last trading day of a future's contract, in ms (PineScript `syminfo.expiration_date`) */
971
+ expirationDate?: number | null;
972
+ /** PineScript `syminfo.sector` and `syminfo.industry` of a company */
973
+ sector?: string | null;
974
+ industry?: string | null;
975
+ /** PineScript `syminfo.isin`: "US0378331005" for NASDAQ:AAPL */
976
+ isin?: string | null;
977
+ /** Unit of the volume (PineScript `syminfo.volumetype`): "base" (crypto: in the base currency), "quote", "tick", "n/a" */
978
+ volumetype?: string | null;
979
+ /** PineScript `syminfo.employees`, `syminfo.shareholders`, `syminfo.shares_outstanding_total` / `_float` */
980
+ employees?: number | null;
981
+ shareholders?: number | null;
982
+ sharesOutstandingTotal?: number | null;
983
+ sharesOutstandingFloat?: number | null;
984
+ /** Analysts' ratings (PineScript `syminfo.recommendations_*`; `date` in ms) */
985
+ recommendations?: SymbolRecommendations | null;
986
+ /** Analysts' price targets (PineScript `syminfo.target_price_*`; `date` in ms) */
987
+ targetPrice?: SymbolTargetPrice | null;
988
+ /**
989
+ * Dividends, splits and earnings of a symbol (PineScript `request.dividends`, `request.splits`, `request.earnings`,
990
+ * `dividends.future_*`, `earnings.future_*`). Return undefined when they are not loaded: the run then ends with a
991
+ * {@link MissingSymbolDataError} whose request has `events: true`. Return {} for a symbol without any.
992
+ */
993
+ events?: (symbol: string) => SymbolEvents | undefined;
952
994
  /** Chart foreground colour (PineScript `chart.fg_color`), e.g. "#DBDBDB" on a dark chart */
953
995
  foregroundColor?: string;
954
996
  /** Chart background colour (PineScript `chart.bg_color`), e.g. "#0F0F0F" on a dark chart */
@@ -992,11 +1034,81 @@ export interface ChartContext {
992
1034
  seedSymbol?: (source: string, symbol: string) => string;
993
1035
  }
994
1036
  /** Calendar and properties of a symbol, as in {@link ChartContext}. */
995
- export type SymbolInfo = Pick<ChartContext, 'timezone' | 'session' | 'regularSession' | 'mintick' | 'minmove' | 'pricescale' | 'pointvalue' | 'mincontract' | 'symbolType' | 'currency' | 'basecurrency' | 'root' | 'description'>;
996
- /** A request of `request.security` for another symbol whose bars the host has not given. */
1037
+ export type SymbolInfo = Pick<ChartContext, 'timezone' | 'session' | 'regularSession' | 'mintick' | 'minmove' | 'pricescale' | 'pointvalue' | 'mincontract' | 'symbolType' | 'currency' | 'basecurrency' | 'root' | 'description' | 'prefix' | 'ticker' | 'country' | 'currentContract' | 'expirationDate' | 'sector' | 'industry' | 'isin' | 'volumetype' | 'employees' | 'shareholders' | 'sharesOutstandingTotal' | 'sharesOutstandingFloat' | 'recommendations' | 'targetPrice'>;
1038
+ /** Analysts' ratings of a symbol: counts of each rating, and the date of the count (ms). */
1039
+ export interface SymbolRecommendations {
1040
+ buy: number;
1041
+ buy_strong: number;
1042
+ hold: number;
1043
+ sell: number;
1044
+ sell_strong: number;
1045
+ total: number;
1046
+ date: number;
1047
+ }
1048
+ /** Analysts' price targets of a symbol, their number and the date of the figures (ms). */
1049
+ export interface SymbolTargetPrice {
1050
+ average: number;
1051
+ high: number;
1052
+ low: number;
1053
+ median: number;
1054
+ estimates: number;
1055
+ date: number;
1056
+ }
1057
+ /**
1058
+ * A dividend: `time` the ex-date (ms; 00:00 UTC of the day, as PineScript's dividends are stamped), the amount per
1059
+ * share as declared (not adjusted for later splits), net and gross of withholding tax (gross defaults to net).
1060
+ */
1061
+ export interface DividendEvent {
1062
+ time: number;
1063
+ net: number;
1064
+ gross?: number;
1065
+ /** Payment date (ms) */
1066
+ payDate?: number | null;
1067
+ }
1068
+ /** A split from `denominator` shares to `numerator` (4 and 1 for a 4-for-1 split); `time` its date (ms, 00:00 UTC). */
1069
+ export interface SplitEvent {
1070
+ time: number;
1071
+ numerator: number;
1072
+ denominator: number;
1073
+ }
1074
+ /**
1075
+ * An earnings release: `time` when it was published (ms; a release after the close is after the session's close). The
1076
+ * values per share are adjusted for later splits, as PineScript gives them. A value the host does not have is left
1077
+ * out; a script that asks for it then stops with an error.
1078
+ */
1079
+ export interface EarningsEvent {
1080
+ time: number;
1081
+ /** Reported earnings per share (`earnings.actual`), the analysts' estimate (`earnings.estimate`), standardized
1082
+ * earnings per share (`earnings.standardized`) */
1083
+ actual?: number | null;
1084
+ estimate?: number | null;
1085
+ standardized?: number | null;
1086
+ /** Estimated revenue (`earnings.future_revenue`) and the end of the fiscal period (ms) */
1087
+ revenueEstimate?: number | null;
1088
+ periodEnd?: number | null;
1089
+ }
1090
+ /** Events of a symbol, oldest first. */
1091
+ export interface SymbolEvents {
1092
+ dividends?: DividendEvent[];
1093
+ splits?: SplitEvent[];
1094
+ earnings?: EarningsEvent[];
1095
+ /**
1096
+ * The lists hold the announced events still to come (`dividends.future_*`, `earnings.future_*` read them): without
1097
+ * it the future values are not known and reading them throws.
1098
+ */
1099
+ future?: {
1100
+ dividends?: boolean;
1101
+ earnings?: boolean;
1102
+ };
1103
+ }
1104
+ /**
1105
+ * A request of `request.security` for another symbol whose bars the host has not given, or (`events`) of
1106
+ * `request.dividends` / `request.splits` / `request.earnings` for a symbol whose events it has not given.
1107
+ */
997
1108
  export interface SymbolDataRequest {
998
1109
  symbol: string;
999
1110
  timeframe: string;
1111
+ events?: boolean;
1000
1112
  }
1001
1113
  /**
1002
1114
  * Thrown by `executeScript` when `request.security` asked for bars of another symbol that `ChartContext.bars` did not
@@ -1030,9 +1142,8 @@ export declare const timeframe: {
1030
1142
  info(timeframe: import("../index.js").simple_string): timeframeCore.TimeframeInfo;
1031
1143
  };
1032
1144
  /**
1033
- * PineScript `syminfo.timezone`, `syminfo.tickerid`, `syminfo.session` (session type), `syminfo.mintick`,
1034
- * `syminfo.minmove`, `syminfo.pricescale`, `syminfo.pointvalue`, `syminfo.mincontract`, `syminfo.type`,
1035
- * `syminfo.currency`, `syminfo.basecurrency`, `syminfo.root` and `syminfo.description`, from the chart context.
1145
+ * PineScript `syminfo.*`, from the chart context (inside `request.security`, the requested symbol's). A field the
1146
+ * symbol has none of is na ("" for a text); a field the host did not give throws.
1036
1147
  */
1037
1148
  export declare const syminfo: {
1038
1149
  readonly mintick: number;
@@ -1042,12 +1153,39 @@ export declare const syminfo: {
1042
1153
  readonly mincontract: number;
1043
1154
  readonly timezone: string;
1044
1155
  readonly tickerid: string;
1156
+ readonly main_tickerid: string;
1157
+ readonly ticker: string;
1158
+ readonly prefix: string;
1045
1159
  readonly session: string;
1046
1160
  readonly type: string;
1047
1161
  readonly currency: string;
1048
1162
  readonly basecurrency: string;
1049
1163
  readonly root: string;
1050
1164
  readonly description: string;
1165
+ readonly country: string;
1166
+ readonly current_contract: string;
1167
+ readonly expiration_date: number;
1168
+ readonly sector: string;
1169
+ readonly industry: string;
1170
+ readonly isin: string;
1171
+ readonly volumetype: string;
1172
+ readonly employees: number;
1173
+ readonly shareholders: number;
1174
+ readonly shares_outstanding_total: number;
1175
+ readonly shares_outstanding_float: number;
1176
+ readonly recommendations_buy: number;
1177
+ readonly recommendations_buy_strong: number;
1178
+ readonly recommendations_hold: number;
1179
+ readonly recommendations_sell: number;
1180
+ readonly recommendations_sell_strong: number;
1181
+ readonly recommendations_total: number;
1182
+ readonly recommendations_date: number;
1183
+ readonly target_price_average: number;
1184
+ readonly target_price_high: number;
1185
+ readonly target_price_low: number;
1186
+ readonly target_price_median: number;
1187
+ readonly target_price_estimates: number;
1188
+ readonly target_price_date: number;
1051
1189
  };
1052
1190
  /** A calendar function: `(time, timezone?)` on a UNIX time or on a Series of times. */
1053
1191
  interface CalendarFunction {
@@ -1217,10 +1355,72 @@ declare function seedCall<T extends SecurityValue>(...args: [source: string, sym
1217
1355
  symbol: string;
1218
1356
  expression: () => T;
1219
1357
  }]): T extends unknown[] ? Series[] : Series;
1358
+ /** PineScript `dividends.*`: the fields of `request.dividends` and the next announced dividend of the chart symbol. */
1359
+ export declare const dividends: {
1360
+ readonly net: "net";
1361
+ readonly gross: "gross";
1362
+ /** Amount of the next dividend (net), na when none is announced */
1363
+ readonly future_amount: number;
1364
+ /** Ex-date of the next dividend (ms) */
1365
+ readonly future_ex_date: number;
1366
+ /** Payment date of the next dividend (ms) */
1367
+ readonly future_pay_date: number;
1368
+ };
1369
+ /** PineScript `splits.*`: the fields of `request.splits`. */
1370
+ export declare const splits: {
1371
+ readonly numerator: "numerator";
1372
+ readonly denominator: "denominator";
1373
+ };
1374
+ /** PineScript `earnings.*`: the fields of `request.earnings` and the next earnings release of the chart symbol. */
1375
+ export declare const earnings: {
1376
+ readonly actual: "actual";
1377
+ readonly estimate: "estimate";
1378
+ readonly standardized: "standardized";
1379
+ /** Estimated earnings per share of the next release */
1380
+ readonly future_eps: number;
1381
+ /** Estimated revenue of the next release */
1382
+ readonly future_revenue: number;
1383
+ /** Time of the next release (ms) */
1384
+ readonly future_time: number;
1385
+ /** End of the fiscal period of the next release (ms) */
1386
+ readonly future_period_end_time: number;
1387
+ };
1388
+ /** Named arguments of `request.dividends` / `request.earnings` (`request.splits` has no `currency`). */
1389
+ export interface EventRequestArgs {
1390
+ ticker?: string;
1391
+ field?: string;
1392
+ gaps?: string;
1393
+ lookahead?: string;
1394
+ ignore_invalid_symbol?: boolean;
1395
+ currency?: string;
1396
+ }
1397
+ type EventRequestCall = [ticker: string, field?: string, gaps?: string, lookahead?: string, ignore_invalid_symbol?: boolean, currency?: string] | [ticker: string, field: string, args: EventRequestArgs] | [ticker: string, args: EventRequestArgs] | [args: EventRequestArgs & {
1398
+ ticker: string;
1399
+ }];
1400
+ /**
1401
+ * PineScript `request.dividends(ticker, field, gaps, lookahead, ignore_invalid_symbol, currency)`: the dividend per
1402
+ * share (`dividends.net`, default, or `dividends.gross`) as declared, from the bar after its ex-date's day (see
1403
+ * `security/events`). na before the first dividend. The events come from `ChartContext.events`.
1404
+ */
1405
+ declare function dividendsCall(...args: EventRequestCall): Series;
1406
+ /**
1407
+ * PineScript `request.splits(ticker, field, gaps, lookahead, ignore_invalid_symbol)`: the numerator
1408
+ * (`splits.numerator`) or the denominator (`splits.denominator`) of the last split, from the bar after its day.
1409
+ */
1410
+ declare function splitsCall(...args: EventRequestCall): Series;
1411
+ /**
1412
+ * PineScript `request.earnings(ticker, field, gaps, lookahead, ignore_invalid_symbol, currency)`: earnings per share of
1413
+ * the last release (`earnings.actual`, default, `earnings.estimate` or `earnings.standardized`), from the bar after the
1414
+ * period of the chart timeframe it was published in (the next day on a daily chart).
1415
+ */
1416
+ declare function earningsCall(...args: EventRequestCall): Series;
1220
1417
  export declare const request: {
1221
1418
  security: typeof securityCall;
1222
1419
  security_lower_tf: typeof securityLowerTfCall;
1223
1420
  seed: typeof seedCall;
1421
+ dividends: typeof dividendsCall;
1422
+ splits: typeof splitsCall;
1423
+ earnings: typeof earningsCall;
1224
1424
  };
1225
1425
  /** PineScript `line.*`; `line.all` lists the live lines in creation order. */
1226
1426
  type Numeric = number | Series;