openalgo-script 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +269 -0
- package/README.md +65 -31
- package/dist/adapters/charts/surfaces.d.ts +17 -0
- package/dist/adapters/charts/surfaces.d.ts.map +1 -1
- package/dist/adapters/charts/tables.js +82 -0
- package/dist/adapters/charts/tables.js.map +1 -1
- package/dist/adapters/codemirror/commands.d.ts +14 -0
- package/dist/adapters/codemirror/commands.d.ts.map +1 -0
- package/dist/adapters/codemirror/commands.js +52 -0
- package/dist/adapters/codemirror/commands.js.map +1 -0
- package/dist/adapters/codemirror/completion.d.ts +15 -0
- package/dist/adapters/codemirror/completion.d.ts.map +1 -0
- package/dist/adapters/codemirror/completion.js +64 -0
- package/dist/adapters/codemirror/completion.js.map +1 -0
- package/dist/adapters/codemirror/contract.d.ts +156 -0
- package/dist/adapters/codemirror/contract.d.ts.map +1 -0
- package/dist/adapters/codemirror/contract.js +42 -0
- package/dist/adapters/codemirror/contract.js.map +1 -0
- package/dist/adapters/codemirror/index.d.ts +43 -0
- package/dist/adapters/codemirror/index.d.ts.map +1 -0
- package/dist/adapters/codemirror/index.js +8 -0
- package/dist/adapters/codemirror/index.js.map +1 -0
- package/dist/adapters/codemirror/lint.d.ts +17 -0
- package/dist/adapters/codemirror/lint.d.ts.map +1 -0
- package/dist/adapters/codemirror/lint.js +62 -0
- package/dist/adapters/codemirror/lint.js.map +1 -0
- package/dist/adapters/codemirror/positions.d.ts +16 -0
- package/dist/adapters/codemirror/positions.d.ts.map +1 -0
- package/dist/adapters/codemirror/positions.js +65 -0
- package/dist/adapters/codemirror/positions.js.map +1 -0
- package/dist/adapters/codemirror/stream.d.ts +23 -0
- package/dist/adapters/codemirror/stream.d.ts.map +1 -0
- package/dist/adapters/codemirror/stream.js +70 -0
- package/dist/adapters/codemirror/stream.js.map +1 -0
- package/dist/adapters/codemirror/tokens.d.ts +44 -0
- package/dist/adapters/codemirror/tokens.d.ts.map +1 -0
- package/dist/adapters/codemirror/tokens.js +34 -0
- package/dist/adapters/codemirror/tokens.js.map +1 -0
- package/dist/adapters/codemirror/tooltips.d.ts +35 -0
- package/dist/adapters/codemirror/tooltips.d.ts.map +1 -0
- package/dist/adapters/codemirror/tooltips.js +108 -0
- package/dist/adapters/codemirror/tooltips.js.map +1 -0
- package/dist/core/accounting/charges.d.ts +136 -0
- package/dist/core/accounting/charges.d.ts.map +1 -0
- package/dist/core/accounting/charges.js +362 -0
- package/dist/core/accounting/charges.js.map +1 -0
- package/dist/core/accounting/equity.d.ts +158 -0
- package/dist/core/accounting/equity.d.ts.map +1 -0
- package/dist/core/accounting/equity.js +155 -0
- package/dist/core/accounting/equity.js.map +1 -0
- package/dist/core/accounting/index.d.ts +44 -0
- package/dist/core/accounting/index.d.ts.map +1 -0
- package/dist/core/accounting/index.js +36 -0
- package/dist/core/accounting/index.js.map +1 -0
- package/dist/core/accounting/markers.d.ts +43 -0
- package/dist/core/accounting/markers.d.ts.map +1 -0
- package/dist/core/accounting/markers.js +64 -0
- package/dist/core/accounting/markers.js.map +1 -0
- package/dist/core/accounting/monthly.d.ts +52 -0
- package/dist/core/accounting/monthly.d.ts.map +1 -0
- package/dist/core/accounting/monthly.js +99 -0
- package/dist/core/accounting/monthly.js.map +1 -0
- package/dist/core/accounting/report.d.ts +38 -0
- package/dist/core/accounting/report.d.ts.map +1 -0
- package/dist/core/accounting/report.js +63 -0
- package/dist/core/accounting/report.js.map +1 -0
- package/dist/core/accounting/shapes.d.ts +70 -0
- package/dist/core/accounting/shapes.d.ts.map +1 -0
- package/dist/core/accounting/shapes.js +21 -0
- package/dist/core/accounting/shapes.js.map +1 -0
- package/dist/core/accounting/statistics.d.ts +75 -0
- package/dist/core/accounting/statistics.d.ts.map +1 -0
- package/dist/core/accounting/statistics.js +246 -0
- package/dist/core/accounting/statistics.js.map +1 -0
- package/dist/core/accounting/trades.d.ts +118 -0
- package/dist/core/accounting/trades.d.ts.map +1 -0
- package/dist/core/accounting/trades.js +186 -0
- package/dist/core/accounting/trades.js.map +1 -0
- package/dist/core/backtest/compare.d.ts +38 -0
- package/dist/core/backtest/compare.d.ts.map +1 -0
- package/dist/core/backtest/compare.js +189 -0
- package/dist/core/backtest/compare.js.map +1 -0
- package/dist/core/backtest/declaration.d.ts +52 -0
- package/dist/core/backtest/declaration.d.ts.map +1 -0
- package/dist/core/backtest/declaration.js +48 -0
- package/dist/core/backtest/declaration.js.map +1 -0
- package/dist/core/backtest/drive.d.ts +29 -0
- package/dist/core/backtest/drive.d.ts.map +1 -0
- package/dist/core/backtest/drive.js +262 -0
- package/dist/core/backtest/drive.js.map +1 -0
- package/dist/core/backtest/index.d.ts +46 -0
- package/dist/core/backtest/index.d.ts.map +1 -0
- package/dist/core/backtest/index.js +36 -0
- package/dist/core/backtest/index.js.map +1 -0
- package/dist/core/backtest/range.d.ts +84 -0
- package/dist/core/backtest/range.d.ts.map +1 -0
- package/dist/core/backtest/range.js +90 -0
- package/dist/core/backtest/range.js.map +1 -0
- package/dist/core/backtest/record.d.ts +238 -0
- package/dist/core/backtest/record.d.ts.map +1 -0
- package/dist/core/backtest/record.js +176 -0
- package/dist/core/backtest/record.js.map +1 -0
- package/dist/core/backtest/replay.d.ts +48 -0
- package/dist/core/backtest/replay.d.ts.map +1 -0
- package/dist/core/backtest/replay.js +127 -0
- package/dist/core/backtest/replay.js.map +1 -0
- package/dist/core/backtest/resting.d.ts +62 -0
- package/dist/core/backtest/resting.d.ts.map +1 -0
- package/dist/core/backtest/resting.js +59 -0
- package/dist/core/backtest/resting.js.map +1 -0
- package/dist/core/backtest/settings.d.ts +117 -0
- package/dist/core/backtest/settings.d.ts.map +1 -0
- package/dist/core/backtest/settings.js +207 -0
- package/dist/core/backtest/settings.js.map +1 -0
- package/dist/core/backtest/simulate.d.ts +146 -0
- package/dist/core/backtest/simulate.d.ts.map +1 -0
- package/dist/core/backtest/simulate.js +217 -0
- package/dist/core/backtest/simulate.js.map +1 -0
- package/dist/core/catalogue/catalogue.generated.d.ts +66 -0
- package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
- package/dist/core/catalogue/catalogue.generated.js +6 -0
- package/dist/core/catalogue/catalogue.generated.js.map +1 -1
- package/dist/core/catalogue/values.generated.d.ts +24 -0
- package/dist/core/catalogue/values.generated.d.ts.map +1 -1
- package/dist/core/check/index.d.ts +2 -1
- package/dist/core/check/index.d.ts.map +1 -1
- package/dist/core/check/index.js +1 -1
- package/dist/core/check/index.js.map +1 -1
- package/dist/core/check/library-prose.generated.d.ts +16 -0
- package/dist/core/check/library-prose.generated.d.ts.map +1 -0
- package/dist/core/check/library-prose.generated.js +353 -0
- package/dist/core/check/library-prose.generated.js.map +1 -0
- package/dist/core/check/surface.d.ts +24 -0
- package/dist/core/check/surface.d.ts.map +1 -1
- package/dist/core/check/surface.js +29 -0
- package/dist/core/check/surface.js.map +1 -1
- package/dist/core/emit/defaults.d.ts +35 -16
- package/dist/core/emit/defaults.d.ts.map +1 -1
- package/dist/core/emit/defaults.js +66 -0
- package/dist/core/emit/defaults.js.map +1 -1
- package/dist/core/emit/index.d.ts +2 -0
- package/dist/core/emit/index.d.ts.map +1 -1
- package/dist/core/emit/index.js +2 -0
- package/dist/core/emit/index.js.map +1 -1
- package/dist/core/engine/index.d.ts +1 -1
- package/dist/core/engine/index.d.ts.map +1 -1
- package/dist/core/engine/index.js +1 -1
- package/dist/core/engine/index.js.map +1 -1
- package/dist/core/engine/load.d.ts +15 -1
- package/dist/core/engine/load.d.ts.map +1 -1
- package/dist/core/engine/load.js +1 -0
- package/dist/core/engine/load.js.map +1 -1
- package/dist/core/index.d.ts +37 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +17 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/version/version.generated.d.ts +1 -1
- package/dist/core/version/version.generated.js +1 -1
- package/dist/editor/complete.d.ts +40 -0
- package/dist/editor/complete.d.ts.map +1 -0
- package/dist/editor/complete.js +206 -0
- package/dist/editor/complete.js.map +1 -0
- package/dist/editor/diagnose.d.ts +18 -0
- package/dist/editor/diagnose.d.ts.map +1 -0
- package/dist/editor/diagnose.js +70 -0
- package/dist/editor/diagnose.js.map +1 -0
- package/dist/editor/format.d.ts +11 -0
- package/dist/editor/format.d.ts.map +1 -0
- package/dist/editor/format.js +50 -0
- package/dist/editor/format.js.map +1 -0
- package/dist/editor/highlight.d.ts +28 -0
- package/dist/editor/highlight.d.ts.map +1 -0
- package/dist/editor/highlight.js +65 -0
- package/dist/editor/highlight.js.map +1 -0
- package/dist/editor/hover.d.ts +40 -0
- package/dist/editor/hover.d.ts.map +1 -0
- package/dist/editor/hover.js +147 -0
- package/dist/editor/hover.js.map +1 -0
- package/dist/editor/index.d.ts +60 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +7 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/kinds.d.ts +27 -0
- package/dist/editor/kinds.d.ts.map +1 -0
- package/dist/editor/kinds.js +118 -0
- package/dist/editor/kinds.js.map +1 -0
- package/dist/editor/layout.d.ts +47 -0
- package/dist/editor/layout.d.ts.map +1 -0
- package/dist/editor/layout.js +135 -0
- package/dist/editor/layout.js.map +1 -0
- package/dist/editor/manifest.d.ts +47 -0
- package/dist/editor/manifest.d.ts.map +1 -0
- package/dist/editor/manifest.js +93 -0
- package/dist/editor/manifest.js.map +1 -0
- package/dist/editor/reading.d.ts +41 -0
- package/dist/editor/reading.d.ts.map +1 -0
- package/dist/editor/reading.js +51 -0
- package/dist/editor/reading.js.map +1 -0
- package/dist/editor/scan.d.ts +26 -0
- package/dist/editor/scan.d.ts.map +1 -0
- package/dist/editor/scan.js +139 -0
- package/dist/editor/scan.js.map +1 -0
- package/dist/editor/scope.d.ts +19 -0
- package/dist/editor/scope.d.ts.map +1 -0
- package/dist/editor/scope.js +99 -0
- package/dist/editor/scope.js.map +1 -0
- package/dist/editor/signature.d.ts +38 -0
- package/dist/editor/signature.d.ts.map +1 -0
- package/dist/editor/signature.js +112 -0
- package/dist/editor/signature.js.map +1 -0
- package/dist/editor/site.d.ts +46 -0
- package/dist/editor/site.d.ts.map +1 -0
- package/dist/editor/site.js +184 -0
- package/dist/editor/site.js.map +1 -0
- package/dist/editor/spacing.d.ts +29 -0
- package/dist/editor/spacing.d.ts.map +1 -0
- package/dist/editor/spacing.js +116 -0
- package/dist/editor/spacing.js.map +1 -0
- package/package.json +30 -3
- package/spec/errors.json +140 -0
- package/src/adapters/charts/surfaces.ts +17 -0
- package/src/adapters/charts/tables.ts +88 -0
- package/src/adapters/codemirror/commands.ts +53 -0
- package/src/adapters/codemirror/completion.ts +74 -0
- package/src/adapters/codemirror/contract.ts +156 -0
- package/src/adapters/codemirror/index.ts +66 -0
- package/src/adapters/codemirror/lint.ts +66 -0
- package/src/adapters/codemirror/positions.ts +79 -0
- package/src/adapters/codemirror/stream.ts +87 -0
- package/src/adapters/codemirror/tokens.ts +64 -0
- package/src/adapters/codemirror/tooltips.ts +113 -0
- package/src/core/accounting/charges.ts +452 -0
- package/src/core/accounting/equity.ts +276 -0
- package/src/core/accounting/index.ts +49 -0
- package/src/core/accounting/markers.ts +95 -0
- package/src/core/accounting/monthly.ts +137 -0
- package/src/core/accounting/report.ts +89 -0
- package/src/core/accounting/shapes.ts +73 -0
- package/src/core/accounting/statistics.ts +350 -0
- package/src/core/accounting/trades.ts +313 -0
- package/src/core/backtest/compare.ts +244 -0
- package/src/core/backtest/declaration.ts +97 -0
- package/src/core/backtest/drive.ts +364 -0
- package/src/core/backtest/index.ts +52 -0
- package/src/core/backtest/range.ts +137 -0
- package/src/core/backtest/record.ts +341 -0
- package/src/core/backtest/replay.ts +158 -0
- package/src/core/backtest/resting.ts +125 -0
- package/src/core/backtest/settings.ts +280 -0
- package/src/core/backtest/simulate.ts +304 -0
- package/src/core/catalogue/catalogue.generated.ts +6 -0
- package/src/core/catalogue/values.generated.ts +6 -0
- package/src/core/check/index.ts +3 -0
- package/src/core/check/library-prose.generated.ts +367 -0
- package/src/core/check/surface.ts +34 -0
- package/src/core/emit/defaults.ts +70 -0
- package/src/core/emit/index.ts +2 -0
- package/src/core/engine/index.ts +1 -1
- package/src/core/engine/load.ts +16 -2
- package/src/core/index.ts +85 -1
- package/src/core/version/version.generated.ts +1 -1
- package/src/editor/complete.ts +266 -0
- package/src/editor/diagnose.ts +71 -0
- package/src/editor/format.ts +85 -0
- package/src/editor/highlight.ts +110 -0
- package/src/editor/hover.ts +199 -0
- package/src/editor/index.ts +65 -0
- package/src/editor/kinds.ts +157 -0
- package/src/editor/layout.ts +189 -0
- package/src/editor/manifest.ts +119 -0
- package/src/editor/reading.ts +69 -0
- package/src/editor/scan.ts +162 -0
- package/src/editor/scope.ts +122 -0
- package/src/editor/signature.ts +150 -0
- package/src/editor/site.ts +233 -0
- package/src/editor/spacing.ts +132 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highlighting, as the editor's line at a time tokenizer.
|
|
3
|
+
*
|
|
4
|
+
* The editor asks for one line's tokens at a time and remembers nothing between
|
|
5
|
+
* lines except the state this file hands back. The tier's `highlight` takes a
|
|
6
|
+
* whole file. So the line is what is lexed here, by the real lexer, through the
|
|
7
|
+
* same `highlight` a host would call itself.
|
|
8
|
+
*
|
|
9
|
+
* **That is an equivalence rather than an approximation, and it is measured.**
|
|
10
|
+
* `tests/adapters/codemirror/stream.test.ts` puts every script in the repository
|
|
11
|
+
* and the malformed corpus through both routes and compares them piece for
|
|
12
|
+
* piece: 4279 lines of real scripts, and not one of them differs. It holds
|
|
13
|
+
* because nothing in this language crosses a line ending: a string literal is
|
|
14
|
+
* refused at the end of its line, there is no block comment, and the layout
|
|
15
|
+
* tokens that do depend on the lines above are painted as whitespace either way.
|
|
16
|
+
* If the language ever grows something that does cross one, that test fails on
|
|
17
|
+
* the day it is added rather than on the day somebody notices a half painted
|
|
18
|
+
* line, and this becomes a line the narrowings file has to carry.
|
|
19
|
+
*
|
|
20
|
+
* A line is lexed once, not once per token: the pieces are computed when the
|
|
21
|
+
* editor arrives at the start of a line and walked from there. Without that, a
|
|
22
|
+
* line of twenty tokens would be lexed twenty times, which is the shape that
|
|
23
|
+
* makes a tokenizer show up in a frame budget.
|
|
24
|
+
*/
|
|
25
|
+
import { highlight } from '../../editor/index.js';
|
|
26
|
+
import { HIGHLIGHT_TOKENS } from './tokens.js';
|
|
27
|
+
/** The pieces of one line, computed once and kept until the line changes. */
|
|
28
|
+
function piecesFor(state, line) {
|
|
29
|
+
if (state.line !== line || state.pieces.length === 0) {
|
|
30
|
+
state.line = line;
|
|
31
|
+
state.pieces = highlight(line);
|
|
32
|
+
}
|
|
33
|
+
return state.pieces;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The tokenizer, which a host turns into a language with one call.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* const openscript = StreamLanguage.define(openscriptStream);
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* `token` moves the stream to the end of the piece that starts where it is and
|
|
43
|
+
* returns that piece's style. A stream that has somehow been left inside a piece,
|
|
44
|
+
* which the editor does when it re-tokenizes from a column rather than from the
|
|
45
|
+
* start of a line, is moved to the end of the piece containing it, so the
|
|
46
|
+
* tokenizer always advances and the editor cannot be made to loop.
|
|
47
|
+
*/
|
|
48
|
+
export const openscriptStream = {
|
|
49
|
+
name: 'openscript',
|
|
50
|
+
startState: () => ({ line: '', pieces: [] }),
|
|
51
|
+
copyState: (state) => ({ line: state.line, pieces: state.pieces }),
|
|
52
|
+
token(stream, state) {
|
|
53
|
+
if (stream.eol())
|
|
54
|
+
return null;
|
|
55
|
+
const pieces = piecesFor(state, stream.string);
|
|
56
|
+
const at = stream.pos;
|
|
57
|
+
const piece = pieces.find((one) => at >= one.span.offset && at < one.span.offset + one.span.length);
|
|
58
|
+
if (piece === undefined) {
|
|
59
|
+
// No piece covers the position, which cannot happen for a line the tier
|
|
60
|
+
// has covered and is still answered rather than trusted: the pieces tile
|
|
61
|
+
// the line, so this is a position outside it. Moving to the end leaves the
|
|
62
|
+
// editor with an unstyled remainder instead of an infinite loop.
|
|
63
|
+
stream.pos = stream.string.length;
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
stream.pos = piece.span.offset + piece.span.length;
|
|
67
|
+
return HIGHLIGHT_TOKENS[piece.kind];
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C,6EAA6E;AAC7E,SAAS,SAAS,CAAC,KAAkB,EAAE,IAAY;IACjD,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoC;IAC/D,IAAI,EAAE,YAAY;IAElB,UAAU,EAAE,GAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAEzD,SAAS,EAAE,CAAC,KAAkB,EAAe,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IAE5F,KAAK,CAAC,MAA0B,EAAE,KAAkB;QAClD,IAAI,MAAM,CAAC,GAAG,EAAE;YAAE,OAAO,IAAI,CAAC;QAE9B,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CACvB,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CACzE,CAAC;QAEF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,wEAAwE;YACxE,yEAAyE;YACzE,2EAA2E;YAC3E,iEAAiE;YACjE,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;QACnD,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The eleven kinds, as the editor's own highlighting tags.
|
|
3
|
+
*
|
|
4
|
+
* This is the translation an adapter exists to do: the language has eleven
|
|
5
|
+
* kinds, closed, and the editor has a vocabulary of tags its themes are written
|
|
6
|
+
* against. Neither knows about the other, and this file is the only place that
|
|
7
|
+
* knows both.
|
|
8
|
+
*
|
|
9
|
+
* **It is one record rather than a switch on purpose.** A style name is the one
|
|
10
|
+
* thing in this adapter that no type can hold: the editor looks a name up in its
|
|
11
|
+
* own tag table at run time and warns on a console about one it does not know,
|
|
12
|
+
* so a name that is wrong here is invisible to every check in this repository
|
|
13
|
+
* and shows up as an unpainted keyword in somebody's product. A host that
|
|
14
|
+
* disagrees with any of these, or whose theme is written against different
|
|
15
|
+
* names, replaces the row in one line:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const tokens = { ...HIGHLIGHT_TOKENS, unknown: "invalid" };
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Two of the eleven are deliberately unstyled. `whitespace` has nothing to
|
|
22
|
+
* paint. `unknown` is the honest name for source the lexer took no token from,
|
|
23
|
+
* which is a character the language does not have, a region somebody wrote as a
|
|
24
|
+
* block comment, or a line continuation backslash: the first is a mistake and
|
|
25
|
+
* the last is not, so painting all three as invalid would paint a correct line
|
|
26
|
+
* red. `diagnose` is what says which of them is wrong, and the linter below is
|
|
27
|
+
* how a host shows that.
|
|
28
|
+
*/
|
|
29
|
+
import type { HighlightKind } from '../../editor/index.js';
|
|
30
|
+
/**
|
|
31
|
+
* A style name per kind, or null for one the editor should leave alone.
|
|
32
|
+
*
|
|
33
|
+
* `builtin` uses the editor's modifier syntax for a name the environment
|
|
34
|
+
* supplies rather than the file, which is what a library name is.
|
|
35
|
+
*/
|
|
36
|
+
export declare const HIGHLIGHT_TOKENS: Readonly<Record<HighlightKind, string | null>>;
|
|
37
|
+
/**
|
|
38
|
+
* The editor's name for the icon beside a completion row, per kind.
|
|
39
|
+
*
|
|
40
|
+
* The editor ships icons for a fixed set of names and shows none for a name it
|
|
41
|
+
* does not know, which is a missing icon rather than a missing row.
|
|
42
|
+
*/
|
|
43
|
+
export declare const COMPLETION_TYPES: Readonly<Record<string, string>>;
|
|
44
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC,CAY3E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO7D,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A style name per kind, or null for one the editor should leave alone.
|
|
3
|
+
*
|
|
4
|
+
* `builtin` uses the editor's modifier syntax for a name the environment
|
|
5
|
+
* supplies rather than the file, which is what a library name is.
|
|
6
|
+
*/
|
|
7
|
+
export const HIGHLIGHT_TOKENS = {
|
|
8
|
+
keyword: 'keyword',
|
|
9
|
+
builtin: 'variableName.standard',
|
|
10
|
+
name: 'variableName',
|
|
11
|
+
number: 'number',
|
|
12
|
+
string: 'string',
|
|
13
|
+
color: 'color',
|
|
14
|
+
comment: 'comment',
|
|
15
|
+
operator: 'operator',
|
|
16
|
+
punctuation: 'punctuation',
|
|
17
|
+
whitespace: null,
|
|
18
|
+
unknown: null,
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The editor's name for the icon beside a completion row, per kind.
|
|
22
|
+
*
|
|
23
|
+
* The editor ships icons for a fixed set of names and shows none for a name it
|
|
24
|
+
* does not know, which is a missing icon rather than a missing row.
|
|
25
|
+
*/
|
|
26
|
+
export const COMPLETION_TYPES = {
|
|
27
|
+
function: 'function',
|
|
28
|
+
value: 'constant',
|
|
29
|
+
namespace: 'namespace',
|
|
30
|
+
member: 'property',
|
|
31
|
+
variable: 'variable',
|
|
32
|
+
argument: 'property',
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/tokens.ts"],"names":[],"mappings":"AA8BA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAmD;IAC9E,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,uBAAuB;IAChC,IAAI,EAAE,cAAc;IACpB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,IAAI;CACd,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqC;IAChE,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,UAAU;IACjB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,UAAU;IAClB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;CACrB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Hover, SignatureHelp } from '../../editor/index.js';
|
|
2
|
+
import type { EditorState, EditorTooltip, EditorTooltipView, EditorView } from './contract.js';
|
|
3
|
+
/** What a host supplies to draw a tooltip, which is the whole of the markup. */
|
|
4
|
+
export interface Renderer<Held> {
|
|
5
|
+
(held: Held): EditorTooltipView;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The lines a hover shows, in the order it shows them.
|
|
9
|
+
*
|
|
10
|
+
* Every one of them came from the compiler: the signatures from the library
|
|
11
|
+
* manifest, the sentence and the warmup from the specification's own tables, the
|
|
12
|
+
* type from the checker, and the refusal from the error catalogue. Nothing is
|
|
13
|
+
* written here, which is why this function is a join rather than a template.
|
|
14
|
+
*/
|
|
15
|
+
export declare function hoverLines(held: Hover): readonly string[];
|
|
16
|
+
/** The lines a signature tooltip shows, with the active parameter named. */
|
|
17
|
+
export declare function signatureLines(held: SignatureHelp): readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* A hover tooltip source, which a host wires in one line.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* hoverTooltip(openscriptHoverTooltip(render))
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function openscriptHoverTooltip(render: Renderer<Hover>): (view: EditorView, pos: number) => EditorTooltip | null;
|
|
26
|
+
/**
|
|
27
|
+
* A signature tooltip for wherever the cursor is, or nothing where it is in no
|
|
28
|
+
* call.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* showTooltip.compute(["doc", "selection"], openscriptSignatureTooltip(render))
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function openscriptSignatureTooltip(render: Renderer<SignatureHelp>): (state: EditorState) => EditorTooltip | null;
|
|
35
|
+
//# sourceMappingURL=tooltips.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltips.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/tooltips.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG/F,gFAAgF;AAChF,MAAM,WAAW,QAAQ,CAAC,IAAI;IAC5B,CAAC,IAAI,EAAE,IAAI,GAAG,iBAAiB,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,MAAM,EAAE,CAOzD;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,MAAM,EAAE,CAYrE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,GACtB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,KAAK,aAAa,GAAG,IAAI,CAWzD;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,GAC9B,CAAC,KAAK,EAAE,WAAW,KAAK,aAAa,GAAG,IAAI,CAY9C"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hover and signature, as the editor's tooltips.
|
|
3
|
+
*
|
|
4
|
+
* This is the one part of the adapter that would put something on screen, and it
|
|
5
|
+
* is the one part that does not: the markup is a parameter, and there is no
|
|
6
|
+
* default for it. So nothing in this package, at any tier, names a browser
|
|
7
|
+
* global, and `scripts/check-layering.mjs` fails the build if anything under
|
|
8
|
+
* `src` does. The same files load in a worker, on a server and inside somebody
|
|
9
|
+
* else's application.
|
|
10
|
+
*
|
|
11
|
+
* It costs a host four lines and it is the whole point of the split. Every
|
|
12
|
+
* platform has a design system and none of them wants to fight a styled panel
|
|
13
|
+
* that arrived with a language package; a default renderer here would be that
|
|
14
|
+
* panel, and it would be the one thing in this adapter a host could not replace
|
|
15
|
+
* without replacing the adapter.
|
|
16
|
+
*
|
|
17
|
+
* What is not a parameter is the content. `hoverLines` and `signatureLines`
|
|
18
|
+
* below are what a tooltip says, in order, and every line of it came from the
|
|
19
|
+
* compiler: the signatures from the library manifest, the sentence and the
|
|
20
|
+
* warmup from the specification's own tables, the type from the checker, and the
|
|
21
|
+
* refusal from the error catalogue.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* hoverTooltip(openscriptHoverTooltip((held) => ({ dom: yourPanel(hoverLines(held)) })))
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { hover, signature } from '../../editor/index.js';
|
|
28
|
+
import { documentOf, normalisedOffset } from './positions.js';
|
|
29
|
+
/**
|
|
30
|
+
* The lines a hover shows, in the order it shows them.
|
|
31
|
+
*
|
|
32
|
+
* Every one of them came from the compiler: the signatures from the library
|
|
33
|
+
* manifest, the sentence and the warmup from the specification's own tables, the
|
|
34
|
+
* type from the checker, and the refusal from the error catalogue. Nothing is
|
|
35
|
+
* written here, which is why this function is a join rather than a template.
|
|
36
|
+
*/
|
|
37
|
+
export function hoverLines(held) {
|
|
38
|
+
const lines = [...held.signatures];
|
|
39
|
+
if (held.summary !== undefined)
|
|
40
|
+
lines.push(held.summary);
|
|
41
|
+
if (held.warmup !== undefined)
|
|
42
|
+
lines.push(`First value: ${held.warmup}`);
|
|
43
|
+
if (held.refusal !== undefined)
|
|
44
|
+
lines.push(held.refusal);
|
|
45
|
+
if (held.kind === 'keyword')
|
|
46
|
+
lines.push('A reserved word of the language.');
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
/** The lines a signature tooltip shows, with the active parameter named. */
|
|
50
|
+
export function signatureLines(held) {
|
|
51
|
+
const lines = [held.signature];
|
|
52
|
+
const active = held.parameters[held.active];
|
|
53
|
+
if (active !== undefined) {
|
|
54
|
+
const value = active.defaultText === undefined ? '' : ` = ${active.defaultText}`;
|
|
55
|
+
const need = active.required ? 'required' : 'optional';
|
|
56
|
+
lines.push(`${active.name}: ${active.type}${value} (${need})`);
|
|
57
|
+
if (active.values.length > 0)
|
|
58
|
+
lines.push(`One of: ${active.values.join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
if (held.summary !== undefined)
|
|
61
|
+
lines.push(held.summary);
|
|
62
|
+
if (held.refusal !== undefined)
|
|
63
|
+
lines.push(held.refusal);
|
|
64
|
+
return lines;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A hover tooltip source, which a host wires in one line.
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* hoverTooltip(openscriptHoverTooltip(render))
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function openscriptHoverTooltip(render) {
|
|
74
|
+
return (view, pos) => {
|
|
75
|
+
const held = documentOf(view.state.doc.toString());
|
|
76
|
+
const found = hover(held.text, normalisedOffset(held, pos));
|
|
77
|
+
if (found === undefined)
|
|
78
|
+
return null;
|
|
79
|
+
return {
|
|
80
|
+
pos: held.at(found.span.offset),
|
|
81
|
+
end: held.at(found.span.offset + found.span.length),
|
|
82
|
+
create: () => render(found),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A signature tooltip for wherever the cursor is, or nothing where it is in no
|
|
88
|
+
* call.
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* showTooltip.compute(["doc", "selection"], openscriptSignatureTooltip(render))
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function openscriptSignatureTooltip(render) {
|
|
95
|
+
return (state) => {
|
|
96
|
+
const held = documentOf(state.doc.toString());
|
|
97
|
+
const at = normalisedOffset(held, state.selection.main.head);
|
|
98
|
+
const found = signature(held.text, at);
|
|
99
|
+
if (found === undefined)
|
|
100
|
+
return null;
|
|
101
|
+
return {
|
|
102
|
+
pos: state.selection.main.head,
|
|
103
|
+
above: true,
|
|
104
|
+
create: () => render(found),
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=tooltips.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltips.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/tooltips.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAO9D;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAW;IACpC,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,IAAI,CAAC,MAAM,K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AC,IAAI;YAC9B,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;SAC5B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Diagnostic } from '../diagnostics/index.js';
|
|
2
|
+
import type { Contract, Money, RecordedFill } from './shapes.js';
|
|
3
|
+
/**
|
|
4
|
+
* What a line's rate is measured against.
|
|
5
|
+
*
|
|
6
|
+
* Four bases cover every stack the documentation describes without naming a
|
|
7
|
+
* market: a fraction of turnover, money per unit, money per fill, and a
|
|
8
|
+
* fraction of the lines named before this one, which is the charge on a charge.
|
|
9
|
+
*/
|
|
10
|
+
export type ChargeBase = 'turnover' | 'units' | 'order' | 'charges';
|
|
11
|
+
/**
|
|
12
|
+
* Which side of the trade a line applies to.
|
|
13
|
+
*
|
|
14
|
+
* A transaction tax levied on one side is expressed exactly rather than smeared
|
|
15
|
+
* across both fills at half the rate, which is what a reader doing it by hand
|
|
16
|
+
* has to do and what makes their figure disagree with their broker's.
|
|
17
|
+
*/
|
|
18
|
+
export type ChargeSide = 'buy' | 'sell' | 'both';
|
|
19
|
+
/** One line of a schedule, applied to one fill. */
|
|
20
|
+
export interface ChargeLine {
|
|
21
|
+
/** The platform's own word. */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly base: ChargeBase;
|
|
24
|
+
readonly side: ChargeSide;
|
|
25
|
+
/**
|
|
26
|
+
* Fraction for turnover and charges, money per unit for units, money for
|
|
27
|
+
* order.
|
|
28
|
+
*/
|
|
29
|
+
readonly rate: number;
|
|
30
|
+
/** Floor per application. */
|
|
31
|
+
readonly min: Money | null;
|
|
32
|
+
/** Cap per application. */
|
|
33
|
+
readonly max: Money | null;
|
|
34
|
+
/** Base 'charges' only: names of lines declared before this one. */
|
|
35
|
+
readonly of: readonly string[];
|
|
36
|
+
}
|
|
37
|
+
/** The whole cost model a run was carried out under. */
|
|
38
|
+
export interface ChargeSchedule {
|
|
39
|
+
readonly currency: string;
|
|
40
|
+
readonly digits: number;
|
|
41
|
+
readonly slippageTicks: number;
|
|
42
|
+
/** Applied in order, and order is part of the result. */
|
|
43
|
+
readonly lines: readonly ChargeLine[];
|
|
44
|
+
/**
|
|
45
|
+
* Where the schedule came from.
|
|
46
|
+
*
|
|
47
|
+
* A schedule derived from the declaration is derived again on replay rather
|
|
48
|
+
* than stored, because what the program states is stored once, as the
|
|
49
|
+
* program. A supplied one is the host's choice and travels with the record.
|
|
50
|
+
*/
|
|
51
|
+
readonly source: 'declaration' | 'supplied';
|
|
52
|
+
}
|
|
53
|
+
/** What one fill was charged, line by line and in total. */
|
|
54
|
+
export interface ChargeBreakdown {
|
|
55
|
+
readonly lines: readonly {
|
|
56
|
+
readonly name: string;
|
|
57
|
+
readonly amount: Money;
|
|
58
|
+
}[];
|
|
59
|
+
readonly total: Money;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What one fill cost, line by line and in total.
|
|
63
|
+
*
|
|
64
|
+
* **The lines are the arithmetic and the total is the money.** Each line's
|
|
65
|
+
* amount is computed in binary64 and left unrounded, and the per-fill total is
|
|
66
|
+
* rounded once, half to even, to the contract's digits. Rounding each line
|
|
67
|
+
* would round once per line, and two engines rounding in two places disagree in
|
|
68
|
+
* the last bit, which is a failed conformance comparison months later on
|
|
69
|
+
* somebody else's engine. So a reader adding the lines up by hand may land a
|
|
70
|
+
* fraction of the last digit away from the total, and that is the honest way
|
|
71
|
+
* round: the total is the figure the report accumulates.
|
|
72
|
+
*
|
|
73
|
+
* **Half to even, and not the language's own rounding.** `round()` in the
|
|
74
|
+
* language is halves away from zero, because a price a trader reads should
|
|
75
|
+
* agree with what they would write down (`stdlib.md` 8.1). Money folded over
|
|
76
|
+
* thousands of fills is a different question: away from zero biases every exact
|
|
77
|
+
* half upward, and half a unit of the last digit per fill is a bias that grows
|
|
78
|
+
* with the length of the backtest. Two rules, two reasons, both written down.
|
|
79
|
+
*
|
|
80
|
+
* **A line that does not apply to this side is not in the breakdown at all.** A
|
|
81
|
+
* name beside a zero reads as a charge that was levied and came to nothing,
|
|
82
|
+
* which is not what happened, and a later line levied on that name is levied on
|
|
83
|
+
* nothing, which is exactly what a tax on one side of the trade does.
|
|
84
|
+
*/
|
|
85
|
+
export declare function chargeFor(schedule: ChargeSchedule, fill: RecordedFill, contract: Contract): ChargeBreakdown;
|
|
86
|
+
/**
|
|
87
|
+
* The declaration's own cost model, as the one schedule this module evaluates.
|
|
88
|
+
*
|
|
89
|
+
* **The declaration is not a second cost engine.** Its three commission
|
|
90
|
+
* spellings are a schedule of one line: a flat fee is a line charged per fill,
|
|
91
|
+
* a per unit fee is a line charged per unit, and a percentage is a line charged
|
|
92
|
+
* on turnover. A second evaluator for the declaration would be the same money
|
|
93
|
+
* computed two ways, and the day the two disagreed the report and the
|
|
94
|
+
* platform's own cost panel would both be defensible.
|
|
95
|
+
*
|
|
96
|
+
* **A commission of zero is no line at all**, rather than a line charging
|
|
97
|
+
* nothing. A zero line would put a name in every breakdown, and it would make a
|
|
98
|
+
* declaration that states no commission indistinguishable from one that states
|
|
99
|
+
* a commission, which is the distinction a run has to make before it accepts a
|
|
100
|
+
* schedule from the host as well.
|
|
101
|
+
*
|
|
102
|
+
* **A flat fee is charged per fill**, which is the one place `language.md` 13.3
|
|
103
|
+
* lets a reasonable person read the words two ways: per order, or per completed
|
|
104
|
+
* round trip. A charge is attributed to the fill that incurred it everywhere in
|
|
105
|
+
* this module, because that is what attributes it to a trade, so a round trip of
|
|
106
|
+
* two fills is charged twice.
|
|
107
|
+
*
|
|
108
|
+
* The currency and the digit count are parameters because neither is the
|
|
109
|
+
* declaration's to state: the declaration's currency is a label and is often
|
|
110
|
+
* left blank, and money rounding is a fact about the contract. A default here
|
|
111
|
+
* would be this module inventing a rounding rule for somebody else's market.
|
|
112
|
+
*
|
|
113
|
+
* `commissionType`'s value set is declared once, in `check/declaration.ts`, and
|
|
114
|
+
* is not restated here: what is below is a mapping from each spelling to the
|
|
115
|
+
* line it means. A program reaching this has been checked, so a fourth spelling
|
|
116
|
+
* cannot arrive, and the spelling that falls through is the declaration's own
|
|
117
|
+
* default rather than a shape this module made up.
|
|
118
|
+
*/
|
|
119
|
+
export declare function scheduleFromDeclaration(commission: number, commissionType: string, slippage: number, currency: string, digits: number): ChargeSchedule;
|
|
120
|
+
/**
|
|
121
|
+
* Why this schedule cannot be carried out, or null.
|
|
122
|
+
*
|
|
123
|
+
* **Asked before the first bar, and answered once.** Everything here is a fact
|
|
124
|
+
* about the schedule rather than about any fill, so a run that would produce a
|
|
125
|
+
* number nobody can explain is refused while nothing has been computed and the
|
|
126
|
+
* cost of correcting it is one run. The contract is optional because a schedule
|
|
127
|
+
* is checkable on its own: what it adds is the three questions that need both,
|
|
128
|
+
* which are the currency the money is in, the digits it is rounded to, and the
|
|
129
|
+
* tick a slippage in ticks is measured in.
|
|
130
|
+
*
|
|
131
|
+
* The first problem found is the one reported. A list of everything wrong with
|
|
132
|
+
* a schedule reads as a worse schedule than it is, and it is corrected one line
|
|
133
|
+
* at a time regardless.
|
|
134
|
+
*/
|
|
135
|
+
export declare function scheduleProblem(schedule: ChargeSchedule, contract?: Contract | null): Diagnostic | null;
|
|
136
|
+
//# sourceMappingURL=charges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charges.d.ts","sourceRoot":"","sources":["../../../src/core/accounting/charges.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;A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