openalgo-script 0.2.0 → 0.5.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 (357) hide show
  1. package/CHANGELOG.md +1198 -0
  2. package/README.md +127 -40
  3. package/dist/adapters/charts/driving.d.ts +50 -0
  4. package/dist/adapters/charts/driving.d.ts.map +1 -0
  5. package/dist/adapters/charts/driving.js +57 -0
  6. package/dist/adapters/charts/driving.js.map +1 -0
  7. package/dist/adapters/charts/run.d.ts +20 -0
  8. package/dist/adapters/charts/run.d.ts.map +1 -1
  9. package/dist/adapters/charts/run.js +83 -16
  10. package/dist/adapters/charts/run.js.map +1 -1
  11. package/dist/adapters/charts/surfaces.d.ts +17 -0
  12. package/dist/adapters/charts/surfaces.d.ts.map +1 -1
  13. package/dist/adapters/charts/tables.js +82 -0
  14. package/dist/adapters/charts/tables.js.map +1 -1
  15. package/dist/adapters/charts/venue.d.ts +73 -0
  16. package/dist/adapters/charts/venue.d.ts.map +1 -0
  17. package/dist/adapters/charts/venue.js +104 -0
  18. package/dist/adapters/charts/venue.js.map +1 -0
  19. package/dist/adapters/codemirror/commands.d.ts +14 -0
  20. package/dist/adapters/codemirror/commands.d.ts.map +1 -0
  21. package/dist/adapters/codemirror/commands.js +52 -0
  22. package/dist/adapters/codemirror/commands.js.map +1 -0
  23. package/dist/adapters/codemirror/completion.d.ts +15 -0
  24. package/dist/adapters/codemirror/completion.d.ts.map +1 -0
  25. package/dist/adapters/codemirror/completion.js +64 -0
  26. package/dist/adapters/codemirror/completion.js.map +1 -0
  27. package/dist/adapters/codemirror/contract.d.ts +156 -0
  28. package/dist/adapters/codemirror/contract.d.ts.map +1 -0
  29. package/dist/adapters/codemirror/contract.js +42 -0
  30. package/dist/adapters/codemirror/contract.js.map +1 -0
  31. package/dist/adapters/codemirror/index.d.ts +43 -0
  32. package/dist/adapters/codemirror/index.d.ts.map +1 -0
  33. package/dist/adapters/codemirror/index.js +8 -0
  34. package/dist/adapters/codemirror/index.js.map +1 -0
  35. package/dist/adapters/codemirror/lint.d.ts +17 -0
  36. package/dist/adapters/codemirror/lint.d.ts.map +1 -0
  37. package/dist/adapters/codemirror/lint.js +62 -0
  38. package/dist/adapters/codemirror/lint.js.map +1 -0
  39. package/dist/adapters/codemirror/positions.d.ts +16 -0
  40. package/dist/adapters/codemirror/positions.d.ts.map +1 -0
  41. package/dist/adapters/codemirror/positions.js +65 -0
  42. package/dist/adapters/codemirror/positions.js.map +1 -0
  43. package/dist/adapters/codemirror/stream.d.ts +23 -0
  44. package/dist/adapters/codemirror/stream.d.ts.map +1 -0
  45. package/dist/adapters/codemirror/stream.js +70 -0
  46. package/dist/adapters/codemirror/stream.js.map +1 -0
  47. package/dist/adapters/codemirror/tokens.d.ts +44 -0
  48. package/dist/adapters/codemirror/tokens.d.ts.map +1 -0
  49. package/dist/adapters/codemirror/tokens.js +34 -0
  50. package/dist/adapters/codemirror/tokens.js.map +1 -0
  51. package/dist/adapters/codemirror/tooltips.d.ts +35 -0
  52. package/dist/adapters/codemirror/tooltips.d.ts.map +1 -0
  53. package/dist/adapters/codemirror/tooltips.js +108 -0
  54. package/dist/adapters/codemirror/tooltips.js.map +1 -0
  55. package/dist/core/accounting/analysis.d.ts +111 -0
  56. package/dist/core/accounting/analysis.d.ts.map +1 -0
  57. package/dist/core/accounting/analysis.js +123 -0
  58. package/dist/core/accounting/analysis.js.map +1 -0
  59. package/dist/core/accounting/charges.d.ts +136 -0
  60. package/dist/core/accounting/charges.d.ts.map +1 -0
  61. package/dist/core/accounting/charges.js +362 -0
  62. package/dist/core/accounting/charges.js.map +1 -0
  63. package/dist/core/accounting/equity.d.ts +191 -0
  64. package/dist/core/accounting/equity.d.ts.map +1 -0
  65. package/dist/core/accounting/equity.js +167 -0
  66. package/dist/core/accounting/equity.js.map +1 -0
  67. package/dist/core/accounting/index.d.ts +46 -0
  68. package/dist/core/accounting/index.d.ts.map +1 -0
  69. package/dist/core/accounting/index.js +37 -0
  70. package/dist/core/accounting/index.js.map +1 -0
  71. package/dist/core/accounting/markers.d.ts +43 -0
  72. package/dist/core/accounting/markers.d.ts.map +1 -0
  73. package/dist/core/accounting/markers.js +64 -0
  74. package/dist/core/accounting/markers.js.map +1 -0
  75. package/dist/core/accounting/monthly.d.ts +52 -0
  76. package/dist/core/accounting/monthly.d.ts.map +1 -0
  77. package/dist/core/accounting/monthly.js +99 -0
  78. package/dist/core/accounting/monthly.js.map +1 -0
  79. package/dist/core/accounting/report.d.ts +41 -0
  80. package/dist/core/accounting/report.d.ts.map +1 -0
  81. package/dist/core/accounting/report.js +65 -0
  82. package/dist/core/accounting/report.js.map +1 -0
  83. package/dist/core/accounting/shapes.d.ts +70 -0
  84. package/dist/core/accounting/shapes.d.ts.map +1 -0
  85. package/dist/core/accounting/shapes.js +21 -0
  86. package/dist/core/accounting/shapes.js.map +1 -0
  87. package/dist/core/accounting/statistics.d.ts +87 -0
  88. package/dist/core/accounting/statistics.d.ts.map +1 -0
  89. package/dist/core/accounting/statistics.js +268 -0
  90. package/dist/core/accounting/statistics.js.map +1 -0
  91. package/dist/core/accounting/trades.d.ts +118 -0
  92. package/dist/core/accounting/trades.d.ts.map +1 -0
  93. package/dist/core/accounting/trades.js +186 -0
  94. package/dist/core/accounting/trades.js.map +1 -0
  95. package/dist/core/backtest/case.d.ts +60 -0
  96. package/dist/core/backtest/case.d.ts.map +1 -0
  97. package/dist/core/backtest/case.js +319 -0
  98. package/dist/core/backtest/case.js.map +1 -0
  99. package/dist/core/backtest/compare.d.ts +38 -0
  100. package/dist/core/backtest/compare.d.ts.map +1 -0
  101. package/dist/core/backtest/compare.js +191 -0
  102. package/dist/core/backtest/compare.js.map +1 -0
  103. package/dist/core/backtest/declaration.d.ts +52 -0
  104. package/dist/core/backtest/declaration.d.ts.map +1 -0
  105. package/dist/core/backtest/declaration.js +48 -0
  106. package/dist/core/backtest/declaration.js.map +1 -0
  107. package/dist/core/backtest/deliver.d.ts +93 -0
  108. package/dist/core/backtest/deliver.d.ts.map +1 -0
  109. package/dist/core/backtest/deliver.js +94 -0
  110. package/dist/core/backtest/deliver.js.map +1 -0
  111. package/dist/core/backtest/drive.d.ts +87 -0
  112. package/dist/core/backtest/drive.d.ts.map +1 -0
  113. package/dist/core/backtest/drive.js +312 -0
  114. package/dist/core/backtest/drive.js.map +1 -0
  115. package/dist/core/backtest/index.d.ts +58 -0
  116. package/dist/core/backtest/index.d.ts.map +1 -0
  117. package/dist/core/backtest/index.js +47 -0
  118. package/dist/core/backtest/index.js.map +1 -0
  119. package/dist/core/backtest/range.d.ts +84 -0
  120. package/dist/core/backtest/range.d.ts.map +1 -0
  121. package/dist/core/backtest/range.js +90 -0
  122. package/dist/core/backtest/range.js.map +1 -0
  123. package/dist/core/backtest/record.d.ts +299 -0
  124. package/dist/core/backtest/record.d.ts.map +1 -0
  125. package/dist/core/backtest/record.js +243 -0
  126. package/dist/core/backtest/record.js.map +1 -0
  127. package/dist/core/backtest/replay.d.ts +48 -0
  128. package/dist/core/backtest/replay.d.ts.map +1 -0
  129. package/dist/core/backtest/replay.js +137 -0
  130. package/dist/core/backtest/replay.js.map +1 -0
  131. package/dist/core/backtest/resting.d.ts +62 -0
  132. package/dist/core/backtest/resting.d.ts.map +1 -0
  133. package/dist/core/backtest/resting.js +59 -0
  134. package/dist/core/backtest/resting.js.map +1 -0
  135. package/dist/core/backtest/settings.d.ts +117 -0
  136. package/dist/core/backtest/settings.d.ts.map +1 -0
  137. package/dist/core/backtest/settings.js +207 -0
  138. package/dist/core/backtest/settings.js.map +1 -0
  139. package/dist/core/backtest/simulate.d.ts +258 -0
  140. package/dist/core/backtest/simulate.d.ts.map +1 -0
  141. package/dist/core/backtest/simulate.js +335 -0
  142. package/dist/core/backtest/simulate.js.map +1 -0
  143. package/dist/core/catalogue/catalogue.generated.d.ts +66 -0
  144. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
  145. package/dist/core/catalogue/catalogue.generated.js +6 -0
  146. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  147. package/dist/core/catalogue/values.generated.d.ts +24 -0
  148. package/dist/core/catalogue/values.generated.d.ts.map +1 -1
  149. package/dist/core/check/index.d.ts +2 -1
  150. package/dist/core/check/index.d.ts.map +1 -1
  151. package/dist/core/check/index.js +1 -1
  152. package/dist/core/check/index.js.map +1 -1
  153. package/dist/core/check/library-orders.js +2 -2
  154. package/dist/core/check/library-orders.js.map +1 -1
  155. package/dist/core/check/library-prose.generated.d.ts +16 -0
  156. package/dist/core/check/library-prose.generated.d.ts.map +1 -0
  157. package/dist/core/check/library-prose.generated.js +353 -0
  158. package/dist/core/check/library-prose.generated.js.map +1 -0
  159. package/dist/core/check/surface.d.ts +24 -0
  160. package/dist/core/check/surface.d.ts.map +1 -1
  161. package/dist/core/check/surface.js +29 -0
  162. package/dist/core/check/surface.js.map +1 -1
  163. package/dist/core/emit/canonical.d.ts +22 -8
  164. package/dist/core/emit/canonical.d.ts.map +1 -1
  165. package/dist/core/emit/canonical.js +67 -6
  166. package/dist/core/emit/canonical.js.map +1 -1
  167. package/dist/core/emit/defaults.d.ts +35 -16
  168. package/dist/core/emit/defaults.d.ts.map +1 -1
  169. package/dist/core/emit/defaults.js +66 -0
  170. package/dist/core/emit/defaults.js.map +1 -1
  171. package/dist/core/emit/index.d.ts +2 -0
  172. package/dist/core/emit/index.d.ts.map +1 -1
  173. package/dist/core/emit/index.js +2 -0
  174. package/dist/core/emit/index.js.map +1 -1
  175. package/dist/core/engine/arithmetic.d.ts +6 -25
  176. package/dist/core/engine/arithmetic.d.ts.map +1 -1
  177. package/dist/core/engine/arithmetic.js +48 -3
  178. package/dist/core/engine/arithmetic.js.map +1 -1
  179. package/dist/core/engine/index.d.ts +2 -2
  180. package/dist/core/engine/index.d.ts.map +1 -1
  181. package/dist/core/engine/index.js +2 -2
  182. package/dist/core/engine/index.js.map +1 -1
  183. package/dist/core/engine/library/arrays.d.ts.map +1 -1
  184. package/dist/core/engine/library/arrays.js +8 -2
  185. package/dist/core/engine/library/arrays.js.map +1 -1
  186. package/dist/core/engine/library/code-points.d.ts +40 -0
  187. package/dist/core/engine/library/code-points.d.ts.map +1 -0
  188. package/dist/core/engine/library/code-points.js +74 -0
  189. package/dist/core/engine/library/code-points.js.map +1 -0
  190. package/dist/core/engine/library/index.d.ts +5 -0
  191. package/dist/core/engine/library/index.d.ts.map +1 -1
  192. package/dist/core/engine/library/index.js +5 -0
  193. package/dist/core/engine/library/index.js.map +1 -1
  194. package/dist/core/engine/library/text.d.ts.map +1 -1
  195. package/dist/core/engine/library/text.js +51 -34
  196. package/dist/core/engine/library/text.js.map +1 -1
  197. package/dist/core/engine/load.d.ts +35 -1
  198. package/dist/core/engine/load.d.ts.map +1 -1
  199. package/dist/core/engine/load.js +63 -0
  200. package/dist/core/engine/load.js.map +1 -1
  201. package/dist/core/engine/verify-tables.d.ts.map +1 -1
  202. package/dist/core/engine/verify-tables.js +41 -0
  203. package/dist/core/engine/verify-tables.js.map +1 -1
  204. package/dist/core/index.d.ts +43 -4
  205. package/dist/core/index.d.ts.map +1 -1
  206. package/dist/core/index.js +23 -2
  207. package/dist/core/index.js.map +1 -1
  208. package/dist/core/stdlib/index.d.ts +1 -1
  209. package/dist/core/stdlib/index.d.ts.map +1 -1
  210. package/dist/core/stdlib/index.js +1 -1
  211. package/dist/core/stdlib/index.js.map +1 -1
  212. package/dist/core/stdlib/maths/index.d.ts +1 -1
  213. package/dist/core/stdlib/maths/index.d.ts.map +1 -1
  214. package/dist/core/stdlib/maths/index.js +1 -1
  215. package/dist/core/stdlib/maths/index.js.map +1 -1
  216. package/dist/core/stdlib/maths/rounding.d.ts +5 -0
  217. package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
  218. package/dist/core/stdlib/maths/rounding.js +19 -1
  219. package/dist/core/stdlib/maths/rounding.js.map +1 -1
  220. package/dist/core/version/version.generated.d.ts +1 -1
  221. package/dist/core/version/version.generated.js +1 -1
  222. package/dist/editor/complete.d.ts +40 -0
  223. package/dist/editor/complete.d.ts.map +1 -0
  224. package/dist/editor/complete.js +206 -0
  225. package/dist/editor/complete.js.map +1 -0
  226. package/dist/editor/diagnose.d.ts +18 -0
  227. package/dist/editor/diagnose.d.ts.map +1 -0
  228. package/dist/editor/diagnose.js +70 -0
  229. package/dist/editor/diagnose.js.map +1 -0
  230. package/dist/editor/format.d.ts +11 -0
  231. package/dist/editor/format.d.ts.map +1 -0
  232. package/dist/editor/format.js +50 -0
  233. package/dist/editor/format.js.map +1 -0
  234. package/dist/editor/highlight.d.ts +28 -0
  235. package/dist/editor/highlight.d.ts.map +1 -0
  236. package/dist/editor/highlight.js +65 -0
  237. package/dist/editor/highlight.js.map +1 -0
  238. package/dist/editor/hover.d.ts +40 -0
  239. package/dist/editor/hover.d.ts.map +1 -0
  240. package/dist/editor/hover.js +147 -0
  241. package/dist/editor/hover.js.map +1 -0
  242. package/dist/editor/index.d.ts +60 -0
  243. package/dist/editor/index.d.ts.map +1 -0
  244. package/dist/editor/index.js +7 -0
  245. package/dist/editor/index.js.map +1 -0
  246. package/dist/editor/kinds.d.ts +27 -0
  247. package/dist/editor/kinds.d.ts.map +1 -0
  248. package/dist/editor/kinds.js +118 -0
  249. package/dist/editor/kinds.js.map +1 -0
  250. package/dist/editor/layout.d.ts +47 -0
  251. package/dist/editor/layout.d.ts.map +1 -0
  252. package/dist/editor/layout.js +135 -0
  253. package/dist/editor/layout.js.map +1 -0
  254. package/dist/editor/manifest.d.ts +47 -0
  255. package/dist/editor/manifest.d.ts.map +1 -0
  256. package/dist/editor/manifest.js +93 -0
  257. package/dist/editor/manifest.js.map +1 -0
  258. package/dist/editor/reading.d.ts +41 -0
  259. package/dist/editor/reading.d.ts.map +1 -0
  260. package/dist/editor/reading.js +51 -0
  261. package/dist/editor/reading.js.map +1 -0
  262. package/dist/editor/scan.d.ts +26 -0
  263. package/dist/editor/scan.d.ts.map +1 -0
  264. package/dist/editor/scan.js +139 -0
  265. package/dist/editor/scan.js.map +1 -0
  266. package/dist/editor/scope.d.ts +19 -0
  267. package/dist/editor/scope.d.ts.map +1 -0
  268. package/dist/editor/scope.js +99 -0
  269. package/dist/editor/scope.js.map +1 -0
  270. package/dist/editor/signature.d.ts +38 -0
  271. package/dist/editor/signature.d.ts.map +1 -0
  272. package/dist/editor/signature.js +112 -0
  273. package/dist/editor/signature.js.map +1 -0
  274. package/dist/editor/site.d.ts +46 -0
  275. package/dist/editor/site.d.ts.map +1 -0
  276. package/dist/editor/site.js +184 -0
  277. package/dist/editor/site.js.map +1 -0
  278. package/dist/editor/spacing.d.ts +29 -0
  279. package/dist/editor/spacing.d.ts.map +1 -0
  280. package/dist/editor/spacing.js +116 -0
  281. package/dist/editor/spacing.js.map +1 -0
  282. package/package.json +42 -3
  283. package/spec/README.md +2 -1
  284. package/spec/errors.json +141 -1
  285. package/src/adapters/charts/driving.ts +109 -0
  286. package/src/adapters/charts/run.ts +120 -28
  287. package/src/adapters/charts/surfaces.ts +17 -0
  288. package/src/adapters/charts/tables.ts +88 -0
  289. package/src/adapters/charts/venue.ts +132 -0
  290. package/src/adapters/codemirror/commands.ts +53 -0
  291. package/src/adapters/codemirror/completion.ts +74 -0
  292. package/src/adapters/codemirror/contract.ts +156 -0
  293. package/src/adapters/codemirror/index.ts +66 -0
  294. package/src/adapters/codemirror/lint.ts +66 -0
  295. package/src/adapters/codemirror/positions.ts +79 -0
  296. package/src/adapters/codemirror/stream.ts +87 -0
  297. package/src/adapters/codemirror/tokens.ts +64 -0
  298. package/src/adapters/codemirror/tooltips.ts +113 -0
  299. package/src/core/accounting/analysis.ts +188 -0
  300. package/src/core/accounting/charges.ts +452 -0
  301. package/src/core/accounting/equity.ts +314 -0
  302. package/src/core/accounting/index.ts +51 -0
  303. package/src/core/accounting/markers.ts +95 -0
  304. package/src/core/accounting/monthly.ts +137 -0
  305. package/src/core/accounting/report.ts +94 -0
  306. package/src/core/accounting/shapes.ts +73 -0
  307. package/src/core/accounting/statistics.ts +387 -0
  308. package/src/core/accounting/trades.ts +313 -0
  309. package/src/core/backtest/case.ts +395 -0
  310. package/src/core/backtest/compare.ts +246 -0
  311. package/src/core/backtest/declaration.ts +97 -0
  312. package/src/core/backtest/deliver.ts +161 -0
  313. package/src/core/backtest/drive.ts +468 -0
  314. package/src/core/backtest/index.ts +64 -0
  315. package/src/core/backtest/range.ts +137 -0
  316. package/src/core/backtest/record.ts +470 -0
  317. package/src/core/backtest/replay.ts +168 -0
  318. package/src/core/backtest/resting.ts +125 -0
  319. package/src/core/backtest/settings.ts +280 -0
  320. package/src/core/backtest/simulate.ts +499 -0
  321. package/src/core/catalogue/catalogue.generated.ts +6 -0
  322. package/src/core/catalogue/values.generated.ts +6 -0
  323. package/src/core/check/index.ts +3 -0
  324. package/src/core/check/library-orders.ts +2 -2
  325. package/src/core/check/library-prose.generated.ts +367 -0
  326. package/src/core/check/surface.ts +34 -0
  327. package/src/core/emit/canonical.ts +67 -9
  328. package/src/core/emit/defaults.ts +70 -0
  329. package/src/core/emit/index.ts +2 -0
  330. package/src/core/engine/arithmetic.ts +23 -3
  331. package/src/core/engine/index.ts +2 -2
  332. package/src/core/engine/library/arrays.ts +8 -2
  333. package/src/core/engine/library/code-points.ts +73 -0
  334. package/src/core/engine/library/index.ts +6 -0
  335. package/src/core/engine/library/text.ts +53 -35
  336. package/src/core/engine/load.ts +84 -2
  337. package/src/core/engine/verify-tables.ts +43 -0
  338. package/src/core/index.ts +100 -2
  339. package/src/core/stdlib/index.ts +1 -0
  340. package/src/core/stdlib/maths/index.ts +1 -0
  341. package/src/core/stdlib/maths/rounding.ts +23 -1
  342. package/src/core/version/version.generated.ts +1 -1
  343. package/src/editor/complete.ts +266 -0
  344. package/src/editor/diagnose.ts +71 -0
  345. package/src/editor/format.ts +85 -0
  346. package/src/editor/highlight.ts +110 -0
  347. package/src/editor/hover.ts +199 -0
  348. package/src/editor/index.ts +65 -0
  349. package/src/editor/kinds.ts +157 -0
  350. package/src/editor/layout.ts +189 -0
  351. package/src/editor/manifest.ts +119 -0
  352. package/src/editor/reading.ts +69 -0
  353. package/src/editor/scan.ts +162 -0
  354. package/src/editor/scope.ts +122 -0
  355. package/src/editor/signature.ts +150 -0
  356. package/src/editor/site.ts +233 -0
  357. package/src/editor/spacing.ts +132 -0
package/README.md CHANGED
@@ -15,31 +15,74 @@ can write their own engine for it.
15
15
 
16
16
  ---
17
17
 
18
+ ## Architecture at a glance
19
+
20
+ [![OpenScript connects a trading idea to charts, backtests and planned live trading, using the platform's editor, market data and broker connection.](https://raw.githubusercontent.com/marketcalls/openscript/main/docs/architecture-overview.png)](https://raw.githubusercontent.com/marketcalls/openscript/main/docs/architecture-overview.png)
21
+
22
+ Write an indicator or a strategy once, then use it on a chart or test it against
23
+ historical data. Your platform supplies the editor, saved scripts, market data
24
+ and connections. The live runner is planned, with sandbox testing before live
25
+ execution; see [Phase 6](./ROADMAP.md#phase-6-the-second-engine-and-live-running).
26
+
18
27
  ## Status
19
28
 
20
- **`0.2.0` runs studies. It does not yet backtest, and it ships no editor.**
29
+ **`0.4.0` runs studies, backtests strategies, and ships the language
30
+ intelligence an editor needs.**
21
31
 
22
- What an install gets you today: the compiler, the engine, and the chart adapter.
23
- A script compiles in milliseconds in a browser tab and computes, bar by bar, the
24
- same numbers everywhere. One hundred and one independently written studies
25
- compile, load and run, and five of them match arithmetic transcribed from the
26
- specification alone, bit for bit, warmups included.
32
+ What an install gets you today: the compiler, the engine, the chart adapter and
33
+ the backtest. A script compiles in milliseconds in a browser tab and computes,
34
+ bar by bar, the same numbers everywhere. One hundred and one independently
35
+ written studies compile, load and run, and five of them match arithmetic
36
+ transcribed from the specification alone, bit for bit, warmups included.
37
+
38
+ A strategy is walked over a range of bars and what comes back is a document
39
+ rather than a number: the program, the bars, the settings, every frame, every
40
+ fill, the ledger and the report. That document replays to the same report and
41
+ reruns to the same bytes, and `npm test` proves it over the shipped strategy
42
+ examples on every run rather than asserting it in a page. Two records can be put
43
+ beside each other, and a pair over different bars is reported incomparable
44
+ instead of being subtracted into a table that reads like a result.
27
45
 
28
46
  What it does **not** do yet, stated plainly because the registry page is the
29
47
  first thing a stranger reads:
30
48
 
31
- - **No backtest and no report.** A strategy can place orders through a host, and
32
- the order ledger refuses what the specification says to refuse, but the
33
- equity curve, the drawdown, the trade list and the run you can reproduce
34
- months later are Phase 5 and are not here.
35
- - **No editor.** The six headless language functions, highlight, complete,
36
- diagnose, hover, signature and format, are Phase 4 and are not built. You get
37
- a compiler, not an authoring experience.
38
- - **No second engine.** The Python engine and the conformance suite that would
39
- prove two engines agree are Phase 6. Until an engine somebody else wrote
40
- passes that suite, the portability claim is a design, not a result.
41
-
42
- The version is `0.2.0` rather than `1.0` because of that list. The studies
49
+ - **The backtest does not model everything, and says which.** A bracket's stop
50
+ cannot fill, because the engine appends no order row for a bracket. A quantity
51
+ stated in cash or in a percentage of equity is refused rather than filled,
52
+ because a backtest works out no running equity to size against. The equity
53
+ curve marks a trade at the size it ended up entering, so a strategy that
54
+ scales in is reported with a drawdown deeper than the account had. A script
55
+ still cannot read its own equity mid-run. The `0.4.0` entry in
56
+ [`CHANGELOG.md`](./CHANGELOG.md) is the full list, and every item on it is
57
+ there because somebody would otherwise find it inside a report they had
58
+ already believed.
59
+ - **No editor on screen, and that is the design.** The six headless functions are
60
+ here and resolve as `openalgo-script/editor`: highlight, complete, diagnose,
61
+ hover, signature and format, text in and data out, with no DOM at any tier. The
62
+ text component, the panel, the apply button, saving and the theme are yours,
63
+ and the drop-in adapter for one editor component wires the six into it without
64
+ drawing anything itself. What each function gives you, and what stays yours, is
65
+ in
66
+ [`docs/integrating/the-editor-half.md`](./docs/integrating/the-editor-half.md).
67
+ The language server that would put the same errors in a desktop editor is the
68
+ rest of Phase 4 and is not written.
69
+ - **No engine anybody else wrote has run the suite, so the portability claim is
70
+ still untested.** The second engine is here: `engine/` holds a complete
71
+ engine in Python with a test suite of its own, and `npm test` runs both on
72
+ every build. A run record carries its own
73
+ source text rather than only a hash of it (`sourceText` in
74
+ [`src/core/backtest/record.ts`](./src/core/backtest/record.ts)), and
75
+ `caseFilesFrom` in [`src/core/backtest/case.ts`](./src/core/backtest/case.ts)
76
+ writes the files a suite runs from straight out of a record, which is where the
77
+ eight cases under [`cases/`](./cases) came from. `npm run suite:agree` reports
78
+ 8 pass of 8 between the two engines. What that run does not prove is the thing
79
+ the suite exists for: both engines were written in this repository, from the
80
+ same specification, by the same hands, so their agreement is evidence about
81
+ this repository rather than about the specification. Until an engine written by
82
+ somebody who had only the specification passes these cases, portability is a
83
+ design with one corroborating implementation, not a result.
84
+
85
+ The version is `0.4.0` rather than `1.0` because of that list. The studies
43
86
  surface is the part that is finished, and it is the part to build on.
44
87
 
45
88
  `ROADMAP.md` says what each phase owes before it is allowed to finish. The
@@ -91,8 +134,8 @@ OpenScript is the opposite of that:
91
134
  timeout, and nothing you drew silently dropped to make room for the next one.
92
135
  - **Honest.** A higher timeframe read has to say whether it repaints. The
93
136
  compiler warns when a script would.
94
- - **Connected.** The same script places real orders through your own broker
95
- connection, on paper by default.
137
+ - **Connected.** Designed to route orders through your own broker connection,
138
+ with sandbox testing before live execution. The live runner is planned.
96
139
  - **Open.** Apache-2.0, a written specification, and a conformance suite anyone
97
140
  can run against their own implementation.
98
141
 
@@ -121,14 +164,49 @@ own, with their fixes taken from the error catalogue. A host supplies the text
121
164
  component and the panel around it, and keeps its own design. The editor is not a
122
165
  second implementation of the language to be kept in step.
123
166
 
124
- ```
125
- source text
126
- -> tokens
127
- -> tree
128
- -> checked tree (errors carry a code, a line and a fix)
129
- -> compiled program (plain data, versioned schema)
130
- -> any engine (browser, server, yours)
131
- ```
167
+ [![OpenScript compiler and runtime: source passes through lexing, parsing, checking and emission into a portable data program, then verification, loading and bar-by-bar interpretation produce outputs for the host.](https://raw.githubusercontent.com/marketcalls/openscript/main/docs/architecture-compiler.png)](https://raw.githubusercontent.com/marketcalls/openscript/main/docs/architecture-compiler.png)
168
+
169
+ ### From source to a compiled program
170
+
171
+ | Stage | What happens | Implementation |
172
+ |---|---|---|
173
+ | Lex | Turns text into tokens with source positions. Newlines, indentation and dedentation become explicit tokens, so later stages do not reinterpret whitespace. | [`src/core/lex`](./src/core/lex/index.ts) |
174
+ | Parse | Builds the abstract syntax tree (AST). It recovers around malformed statements so an editor can still work with a partially typed file. | [`src/core/parse`](./src/core/parse/index.ts) |
175
+ | Check | Resolves names, checks types and calls, determines storage and tracks when a value becomes available. `CheckedScript` keeps those answers beside the original tree. | [`src/core/check`](./src/core/check/index.ts) |
176
+ | Emit | Allocates registers and persistent state, lowers statements into instructions, links calls and requests, and checks stack depths and limits. | [`src/core/emit`](./src/core/emit/emit.ts) |
177
+
178
+ The result is a [`CompiledProgram`](./src/core/emit/program.ts), not executable
179
+ code in the host's language. Alongside its instructions it carries the constants,
180
+ inputs, output declarations, storage layout and source mapping the engine needs.
181
+ Its [canonical encoding](./src/core/emit/canonical.ts) makes the program portable
182
+ and gives it stable bytes for hashing. The language and compiled format have
183
+ separate versions, defined by the [compiled program specification](./spec/compiled-program.md).
184
+
185
+ Every compiler stage reports through the same diagnostic system. Codes, messages
186
+ and fixes come from the [error catalogue](./spec/errors.json); the
187
+ [headless editor](./src/editor/index.ts) reuses the compiler and its language
188
+ tables for highlighting, completion, diagnostics, hover, signatures and formatting.
189
+
190
+ ### From a compiled program to results
191
+
192
+ Before the first bar, [`load`](./src/core/engine/load.ts) verifies the program's
193
+ format, capabilities, tables and instructions, including stack and address
194
+ bounds. It checks the host's limits, resolves inputs and plans requested series.
195
+ A rejected program returns a diagnostic before execution starts.
196
+
197
+ The [engine](./src/core/engine/engine.ts) then advances one bar at a time. Its
198
+ [interpreter](./src/core/engine/machine.ts) walks the instruction list using
199
+ registers, persistent memory and the standard library, with instruction, memory
200
+ and time budgets. Updating the newest bar restores its checkpoint before
201
+ recomputing it; explicitly live state is retained. Drawing values are published
202
+ on updates, while signals, alerts and orders follow the confirmation policy.
203
+
204
+ The [chart adapter](./src/adapters/charts/index.ts) maps study outputs into the
205
+ host's chart. The [backtest driver](./src/core/backtest/drive.ts) supplies a
206
+ simulated order destination and records frames, fills, orders and the report.
207
+ [Replay and rerun](./src/core/backtest/replay.ts) let a stored result be checked
208
+ again. The host owns data access, rendering, persistence and order routing;
209
+ the language core does not reach into those systems itself.
132
210
 
133
211
  ## The pieces, and which way they point
134
212
 
@@ -143,10 +221,11 @@ and the dependencies only ever point one way.
143
221
  | \ /
144
222
  | .../adapters/charts <- knows both. The only place that does
145
223
  |
146
- .../editor <- designed, not built
224
+ .../editor <- the six headless functions. No DOM, no
225
+ | package, nothing on screen
147
226
  |
148
- .../adapters/codemirror <- designed, not built. Would know the
149
- editor component, and nothing else would
227
+ .../adapters/codemirror <- knows both. Takes its markup from the
228
+ host, so it draws nothing either
150
229
  ```
151
230
 
152
231
  The language ships as one package with an entry point per tier, so a consumer who
@@ -154,17 +233,20 @@ wants only the compiler never pays for an adapter. A tier is declared only once
154
233
  exists: an entry point that resolves to nothing fails at a consumer's run time
155
234
  rather than honestly at install.
156
235
 
157
- These two resolve today, from an install holding nothing but the manifest and the
158
- built output:
236
+ These four resolve today, from an install holding nothing but the manifest and the
237
+ built output. That is a check rather than a sentence: `scripts/check-entry-points.mjs`
238
+ builds exactly that install in a temporary directory, with no package of any kind
239
+ beside it, and imports every one of them.
159
240
 
160
241
  | Entry point | Is | Depends on |
161
242
  |---|---|---|
162
243
  | `openalgo-script` | Compiler and engine | Nothing |
244
+ | `openalgo-script/editor` | The six headless language functions an editor needs | The compiler |
163
245
  | `openalgo-script/adapters/charts` | Turns a compiled study into a chart's indicator descriptor | The compiler and a chart |
246
+ | `openalgo-script/adapters/codemirror` | Wires the six into a text component | The editor half and a text component |
164
247
 
165
- The editor half and its drop-in adapter are in the roadmap rather than in the
166
- export map, and so is the server-side engine, which is a separate package in
167
- another language. The roadmap says which phase owes each of them.
248
+ The server-side engine is not among them: it is a separate package in another
249
+ language, and the roadmap says which phase owes it.
168
250
 
169
251
  An adapter is the only thing allowed to know two worlds at once, which is what
170
252
  makes it the piece a platform replaces rather than the piece they patch. A
@@ -173,8 +255,10 @@ else. A platform with its own editor does the same on that side.
173
255
 
174
256
  This is enforced rather than promised. `scripts/check-layering.mjs` runs in
175
257
  continuous integration and fails the build if the compiler imports a chart, if
176
- anything outside an adapter imports a package, or if the compiler or the editor
177
- half so much as mentions a browser global.
258
+ anything outside an adapter imports a package, or if anything under `src` so much
259
+ as mentions a browser global. That last one holds of the adapters too: the editor
260
+ adapter takes a tooltip's markup from the host rather than building an element,
261
+ so every file in the package loads in a worker and on a server.
178
262
 
179
263
  ## Taking it, one step at a time
180
264
 
@@ -184,7 +268,7 @@ Each row is usable on its own. Nobody has to take the next one.
184
268
  |---|---|---|
185
269
  | Scripts that produce numbers | `openalgo-script`, and the six-item host interface | An afternoon |
186
270
  | Those studies on your chart | the charts adapter, plus a chart | Days. Free if the chart is the one this adapter already targets |
187
- | Traders authoring in your app | The editor half, once it is built, and your own text component or the drop-in one | Days |
271
+ | Traders authoring in your app | The editor half, and your own text component or the drop-in adapter | Days |
188
272
  | Traders trading from it | Wire the order half of the host interface to your order API | About a week |
189
273
  | To run it on your own stack | Implement the compiled program format in your language, then pass the conformance suite | Weeks |
190
274
 
@@ -215,8 +299,11 @@ fails the build.
215
299
  | Two engines agree to the last decimal | The conformance suite, run against both. A disagreement blocks a release | Phase 6 gate |
216
300
  | A runaway script stops | Instruction, memory and wall clock budgets, counters in the loop the engine owns. `tests/engine/budget.test.ts` | Enforced |
217
301
  | A failing script does not take anything else down | One script's failure is a diagnostic on that script and reaches nothing else | Enforced |
302
+ | Every entry point in the export map resolves from a real install | `scripts/check-entry-points.mjs`. Each one is imported from a temporary install built from the `files` list alone, with no package beside it, which is also what says both adapters' peer dependencies are optional in fact and not only in the manifest | Enforced |
303
+ | A completion, a tooltip and a default come from the compiler, not from a list | The names are the standard library manifest the checker resolves against; what a call is for is the cell `spec/stdlib.md` prints, read at build time by `scripts/generate-library-prose.mjs`; a default is the one `scripts/check-defaults.mjs` holds the compiler to. `tests/editor/hover.test.ts` fails if the manifest and the specification describe different sets of names | Enforced |
304
+ | Laying a script out again cannot change what it computes | `tests/editor/format.test.ts`. Every example and every gate script is formatted, both texts are compiled, and the compiled programs are compared. Each call also checks itself against the lexer, so a rule that is wrong returns your source untouched rather than a changed program | Enforced |
218
305
  | A saved script never stops working | The language version is declared per file and old front ends are retained | Phase 7, with a test per retained version |
219
- | Performance | Six benchmarks with recorded budgets, run by `npm test` and in continuous integration. A regression past a budget fails the build | Enforced |
306
+ | Performance | Eight benchmarks with recorded budgets, run by `npm test` and in continuous integration. A regression past a budget fails the build | Enforced |
220
307
 
221
308
  The rows marked as gates are not promises we intend to keep. They are conditions a
222
309
  phase does not finish without, and each one is written into the roadmap beside the
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Walking the bars, for a study and for a strategy.
3
+ *
4
+ * Split from `run.ts` because they are two things. That file decides what an
5
+ * engine is loaded with: the host record, the clock, the settings, the venue.
6
+ * This one decides how the bars are then handed over, and the two differ by
7
+ * exactly one thing, whether frames have to reach the engine between them.
8
+ */
9
+ import type { CompiledProgram } from '../../core/emit/index.js';
10
+ import type { Engine } from '../../core/engine/index.js';
11
+ import type { ChartBar, ChartCalcContext, ChartSettings } from './contract.js';
12
+ import type { HeldVenue } from './venue.js';
13
+ /**
14
+ * A run in hand, held between a chart's recomputes.
15
+ *
16
+ * The signature and the bar times are what a tail run is checked against before
17
+ * it is trusted: splicing a tail onto a history that has changed underneath it
18
+ * draws a wrong study that looks entirely plausible.
19
+ */
20
+ export interface Held {
21
+ readonly engine: Engine;
22
+ readonly signature: string;
23
+ count: number;
24
+ firstTime: number;
25
+ lastTime: number;
26
+ /**
27
+ * The destination this run's orders go to, for a strategy.
28
+ *
29
+ * Held with the engine because the two are one run: the venue holds the
30
+ * orders that have not filled yet, and an engine continued onto a new bar
31
+ * against a fresh venue would have its working orders silently forgotten.
32
+ */
33
+ readonly venue: HeldVenue | null;
34
+ }
35
+ /** A study: every bar in one hand-over, which is what `run` is for. */
36
+ export declare function runWhole(engine: Engine, bars: readonly ChartBar[], ctx: ChartCalcContext | undefined, program: CompiledProgram, settings: ChartSettings): Held;
37
+ /**
38
+ * A strategy: one bar at a time, with the venue answering between them.
39
+ *
40
+ * The order is deliver, execute, then ask. A driver that asked the venue before
41
+ * executing would price a fill against a bar the strategy had not seen yet, and
42
+ * one that delivered after executing would let a script read a position its own
43
+ * order on this bar had just created.
44
+ *
45
+ * `supplied` is the whole count rather than the index reached, so `bar.isLast`
46
+ * means the same on this path as on the one above it: a strategy written to act
47
+ * on the final bar acts on the final bar, not on every bar in turn.
48
+ */
49
+ export declare function walkWith(engine: Engine, held: HeldVenue, bars: readonly ChartBar[], ctx: ChartCalcContext | undefined, program: CompiledProgram, settings: ChartSettings): Held;
50
+ //# sourceMappingURL=driving.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driving.d.ts","sourceRoot":"","sources":["../../../src/adapters/charts/driving.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;CAClC;AAED,uEAAuE;AACvE,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,QAAQ,EAAE,EACzB,GAAG,EAAE,gBAAgB,GAAG,SAAS,EACjC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,aAAa,GACtB,IAAI,CAON;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,SAAS,QAAQ,EAAE,EACzB,GAAG,EAAE,gBAAgB,GAAG,SAAS,EACjC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,aAAa,GACtB,IAAI,CAcN"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Walking the bars, for a study and for a strategy.
3
+ *
4
+ * Split from `run.ts` because they are two things. That file decides what an
5
+ * engine is loaded with: the host record, the clock, the settings, the venue.
6
+ * This one decides how the bars are then handed over, and the two differ by
7
+ * exactly one thing, whether frames have to reach the engine between them.
8
+ */
9
+ import { hostBar, stateFor } from './bars.js';
10
+ import { stopped } from './errors.js';
11
+ import { signatureOf } from './settings.js';
12
+ import { answersFor } from './venue.js';
13
+ /** A study: every bar in one hand-over, which is what `run` is for. */
14
+ export function runWhole(engine, bars, ctx, program, settings) {
15
+ const result = engine.run(bars.map(hostBar), bars.map((_, index) => stateFor(index, bars, ctx)));
16
+ if (result.diagnostic !== undefined)
17
+ throw stopped(result.diagnostic);
18
+ return heldFrom(engine, null, bars, program, settings);
19
+ }
20
+ /**
21
+ * A strategy: one bar at a time, with the venue answering between them.
22
+ *
23
+ * The order is deliver, execute, then ask. A driver that asked the venue before
24
+ * executing would price a fill against a bar the strategy had not seen yet, and
25
+ * one that delivered after executing would let a script read a position its own
26
+ * order on this bar had just created.
27
+ *
28
+ * `supplied` is the whole count rather than the index reached, so `bar.isLast`
29
+ * means the same on this path as on the one above it: a strategy written to act
30
+ * on the final bar acts on the final bar, not on every bar in turn.
31
+ */
32
+ export function walkWith(engine, held, bars, ctx, program, settings) {
33
+ for (let index = 0; index < bars.length; index += 1) {
34
+ const bar = bars[index];
35
+ if (bar === undefined)
36
+ continue;
37
+ for (const frame of held.pending)
38
+ engine.deliver(frame);
39
+ held.pending = [];
40
+ const result = engine.append(hostBar(bar), stateFor(index, bars, ctx), bars.length);
41
+ if (result.diagnostic !== undefined)
42
+ throw stopped(result.diagnostic);
43
+ answersFor(held, index);
44
+ }
45
+ return heldFrom(engine, held, bars, program, settings);
46
+ }
47
+ function heldFrom(engine, venue, bars, program, settings) {
48
+ return {
49
+ engine,
50
+ venue,
51
+ signature: signatureOf(program, settings),
52
+ count: bars.length,
53
+ firstTime: bars[0]?.time ?? 0,
54
+ lastTime: bars[bars.length - 1]?.time ?? 0,
55
+ };
56
+ }
57
+ //# sourceMappingURL=driving.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driving.js","sourceRoot":"","sources":["../../../src/adapters/charts/driving.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA0BxC,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CACtB,MAAc,EACd,IAAyB,EACzB,GAAiC,EACjC,OAAwB,EACxB,QAAuB;IAEvB,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CACvB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EACjB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CACnD,CAAC;IACF,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACtE,OAAO,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,I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,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC;KAC3C,CAAC;AACJ,CAAC"}
@@ -98,6 +98,26 @@ export interface ChartAdapterOptions {
98
98
  * (`stdlib.md` 17.1), never handed over by the chart.
99
99
  */
100
100
  readonly orders?: EffectRoute;
101
+ /**
102
+ * Run a strategy against a simulated destination where the host gives none.
103
+ *
104
+ * **Off by default, because the refusal it replaces is useful.** A strategy
105
+ * with nowhere to send an order is refused at load with OS6006 naming the
106
+ * capability, which is exactly what a host that meant to wire a destination
107
+ * and forgot needs to be told. A chart that quietly filled one in for them
108
+ * would draw a convincing strategy that routed nothing.
109
+ *
110
+ * **On, it is the venue a backtest uses.** A chart drawing a strategy then
111
+ * fills the same orders at the same prices as the report of the same script,
112
+ * so the marks on the price and the trades in the report are one answer
113
+ * rather than two. This is what a host turns on to draw a strategy the way it
114
+ * draws a study: the plots, the legend row and the settings all follow from
115
+ * the program running at all.
116
+ *
117
+ * It does not place an order anywhere. A host that wants that supplies
118
+ * `orders`, which wins over this.
119
+ */
120
+ readonly simulateOrders?: boolean;
101
121
  readonly limits?: Partial<EngineLimits>;
102
122
  readonly clock?: Clock;
103
123
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/adapters/charts/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EAGX,YAAY,EACZ,IAAI,EAEJ,UAAU,EACV,OAAO,EAEP,KAAK,EACN,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3F,iF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C,QAAQ,EAAE,mBAAmB,GAC5B,SAAS,GAAG,IAAI,CA6ClB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAG/C"}
@@ -3,21 +3,26 @@ import { hostBar, hostNow, stateFor } from './bars.js';
3
3
  import { refused, stopped } from './errors.js';
4
4
  import { stationIn, stationOf } from './requests.js';
5
5
  import { engineSettings, signatureOf } from './settings.js';
6
+ import { answersFor, needsVenue, routeInto, venueFor } from './venue.js';
7
+ import { runWhole, walkWith } from './driving.js';
8
+ /** The engine one chart instance is holding, between recomputes. */
6
9
  /** The store key. Namespaced, because the store belongs to the host as well. */
7
10
  const HELD = 'openscript';
8
11
  export function fullRun(program, bars, settings, store, ctx, options) {
9
12
  const station = stationIn(store);
10
- const engine = start(program, settings, ctx, options, station.provider(bars));
11
- const result = engine.run(bars.map(hostBar), bars.map((_, index) => stateFor(index, bars, ctx)));
12
- if (result.diagnostic !== undefined)
13
- throw stopped(result.diagnostic);
14
- const held = {
15
- engine,
16
- signature: signatureOf(program, settings),
17
- count: bars.length,
18
- firstTime: bars[0]?.time ?? 0,
19
- lastTime: bars[bars.length - 1]?.time ?? 0,
20
- };
13
+ const started = start(program, settings, ctx, options, station.provider(bars), bars);
14
+ const engine = started.engine;
15
+ // **A strategy is walked bar by bar and a study is handed the lot.** The
16
+ // difference is the venue: its frames reach the engine between bars, which is
17
+ // the only place they can, so a strategy's position is right on the bar after
18
+ // the one it traded on. `run()` has no gap to put them in.
19
+ //
20
+ // It is also the loop the backtest uses, which is the point: a chart drawing a
21
+ // strategy and a report of the same strategy walk the same bars in the same
22
+ // order against the same venue, so they cannot disagree about what filled.
23
+ const held = started.venue === null
24
+ ? runWhole(engine, bars, ctx, program, settings)
25
+ : walkWith(engine, started.venue, bars, ctx, program, settings);
21
26
  store[HELD] = held;
22
27
  station.settle();
23
28
  return outputOf(program, engine);
@@ -51,11 +56,28 @@ _options) {
51
56
  if (bar === undefined)
52
57
  return null;
53
58
  const state = stateFor(index, bars, ctx);
59
+ // The venue's answers about the bar before this one, delivered before this
60
+ // one runs, exactly as the full walk does. A tail that skipped this would
61
+ // draw the first bars of a strategy correctly and then quietly stop folding
62
+ // its fills the moment the chart went live, which is the half of the run
63
+ // nobody re-checks.
64
+ //
65
+ // Only when the bar is new. Re-executing the bar that moved must not
66
+ // deliver again: a frame is cumulative and folding one twice is harmless,
67
+ // but the bar's own orders have been rolled back and answering them a
68
+ // second time would fill an order the engine no longer knows it sent.
69
+ if (held.venue !== null && index !== from) {
70
+ for (const frame of held.venue.pending)
71
+ held.engine.deliver(frame);
72
+ held.venue.pending = [];
73
+ }
54
74
  const result = index === from
55
75
  ? held.engine.update(hostBar(bar), state)
56
76
  : held.engine.append(hostBar(bar), state);
57
77
  if (result.diagnostic !== undefined)
58
78
  throw stopped(result.diagnostic);
79
+ if (held.venue !== null)
80
+ answersFor(held.venue, index);
59
81
  }
60
82
  held.count = bars.length;
61
83
  held.lastTime = bars[bars.length - 1]?.time ?? held.lastTime;
@@ -86,10 +108,38 @@ function outputOf(program, engine) {
86
108
  // `tables.ts`'s own first paragraph.
87
109
  return { columns, tables: engine.tables(), drawings: engine.drawings() };
88
110
  }
89
- function start(program, settings, ctx, options, requests) {
111
+ /**
112
+ * Load the program, and give a strategy somewhere for its orders to go.
113
+ *
114
+ * **The venue is built after the load and reached through a holder, because
115
+ * neither can come first.** The route has to be handed to `load`, since that is
116
+ * what declares the `orders` capability and a program needing one is otherwise
117
+ * refused. The venue has to be built after it, because the declaration it reads
118
+ * may state its fill rule through an `input()`, and inputs are not resolved
119
+ * until `load` has run. The route is only ever called from inside an execution,
120
+ * which is after both, so the holder is always filled by the time anything
121
+ * reaches it.
122
+ *
123
+ * **A host that supplied its own route keeps it.** Somewhere real to send an
124
+ * order is a better destination than a simulated one, and a host that wired one
125
+ * up meant it.
126
+ *
127
+ * **And simulation is asked for rather than assumed.** Without
128
+ * `simulateOrders` a strategy with nowhere to send an order is still refused at
129
+ * load, which is the answer a host that meant to wire a destination and forgot
130
+ * needs to see. Filling in a venue for them would turn that mistake into a
131
+ * chart that draws convincingly and routes nothing, discovered whenever
132
+ * somebody next looked for the orders.
133
+ */
134
+ function start(program, settings, ctx, options, requests, bars) {
135
+ const holder = { current: null };
136
+ const simulate = options.simulateOrders === true && options.orders === undefined && needsVenue(program);
137
+ const withRoute = simulate
138
+ ? { ...options, orders: routeInto(holder) }
139
+ : options;
90
140
  const loaded = load(program, {
91
141
  settings: engineSettings(program, settings),
92
- host: hostFor(ctx, options, requests),
142
+ host: hostFor(ctx, withRoute, requests),
93
143
  time: timeFor(options, ctx?.timezone ?? ''),
94
144
  ...(options.limits === undefined ? {} : { limits: options.limits }),
95
145
  ...(options.source === undefined ? {} : { source: options.source }),
@@ -97,7 +147,13 @@ function start(program, settings, ctx, options, requests) {
97
147
  });
98
148
  if (!loaded.ok)
99
149
  throw refused(loaded.diagnostic);
100
- return loaded.engine;
150
+ if (!simulate)
151
+ return { engine: loaded.engine, venue: null };
152
+ const venue = venueFor(program, bars, loaded.inputs, instrumentFor(ctx, options));
153
+ if (venue === null)
154
+ return { engine: loaded.engine, venue: null };
155
+ holder.current = venue;
156
+ return { engine: loaded.engine, venue: { venue, pending: [] } };
101
157
  }
102
158
  /**
103
159
  * The host the engine reads, which always serves requests.
@@ -109,8 +165,16 @@ function start(program, settings, ctx, options, requests) {
109
165
  * the chart's own sentence in `req.error`, instead of being refused at load
110
166
  * with OS6006 naming a capability the chart does have.
111
167
  */
112
- function hostFor(ctx, options, requests) {
113
- const instrument = {
168
+ /**
169
+ * The instrument record, from what the host stated and what the chart knows.
170
+ *
171
+ * Its own function because two callers need it and they must not each build
172
+ * one: the engine is loaded with this record, and the venue prices fills
173
+ * against the tick size in it. Two spellings of the same record is how a fill
174
+ * gets rounded to a tick the strategy was never told about.
175
+ */
176
+ function instrumentFor(ctx, options) {
177
+ return {
114
178
  ...(options.instrument ?? {}),
115
179
  ...(ctx?.symbol === undefined ? {} : { symbol: ctx.symbol }),
116
180
  ...(ctx?.interval === undefined ? {} : { interval: ctx.interval }),
@@ -121,6 +185,9 @@ function hostFor(ctx, options, requests) {
121
185
  // the chart it was drawn on.
122
186
  ...(ctx === undefined || ctx.timezone === '' ? {} : { timezone: ctx.timezone }),
123
187
  };
188
+ }
189
+ function hostFor(ctx, options, requests) {
190
+ const instrument = instrumentFor(ctx, options);
124
191
  return {
125
192
  instrument,
126
193
  requestBars: requests,
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/adapters/charts/run.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAkG5D,gFAAgF;AAChF,MAAM,IAAI,GAAG,YAAY,CAAC;AAoB1B,MAAM,UAAU,OAAO,CACrB,OAAwB,EACxB,IAAyB,EACzB,QAAuB,EACvB,KAAiB,EACjB,GAAiC,EACjC,OAA4B;IAE5B,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CACvB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EACjB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,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MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,0EAA0E;YAC1E,uEAAuE;YACvE,uEAAuE;YACvE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -75,6 +75,23 @@ export interface ChartTableOptions {
75
75
  readonly borderWidth: number;
76
76
  /** The backdrop behind the whole grid, which is the grid's own `bgColor`. */
77
77
  readonly background?: string;
78
+ /**
79
+ * Column widths in media pixels, one per column.
80
+ *
81
+ * The chart's own default is one flat width for every column, which is a
82
+ * width chosen without seeing the text. A grid whose first column says
83
+ * "Moving averages" and whose second says "RSI: 27.22" has two columns that
84
+ * want different room, and one number cannot give it to both.
85
+ */
86
+ readonly cellWidth?: readonly number[];
87
+ /**
88
+ * `'auto'` to shrink a cell's type until its text fits the cell it is in.
89
+ *
90
+ * The chart measures the text it is about to draw, which nothing upstream of
91
+ * it can do, so this is what makes a column width that is slightly wrong
92
+ * merely slightly loose instead of two cells written over each other.
93
+ */
94
+ readonly fontSize?: number | 'auto';
78
95
  }
79
96
  /** A grid of cells pinned to a corner, and the options it is drawn with. */
80
97
  export interface ChartGrid {