desic-okx-agent 0.2.0 → 0.3.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 (237) hide show
  1. package/README.en.md +353 -0
  2. package/README.md +194 -190
  3. package/dist/account/private-websocket.js +4 -4
  4. package/dist/account/private-websocket.js.map +1 -1
  5. package/dist/account/service.d.ts +12 -1
  6. package/dist/account/service.js +18 -0
  7. package/dist/account/service.js.map +1 -1
  8. package/dist/bars/rate-limiter.d.ts +18 -0
  9. package/dist/bars/rate-limiter.js +84 -0
  10. package/dist/bars/rate-limiter.js.map +1 -0
  11. package/dist/bars/schema.d.ts +36 -0
  12. package/dist/bars/schema.js +134 -0
  13. package/dist/bars/schema.js.map +1 -0
  14. package/dist/bars/service.d.ts +60 -0
  15. package/dist/bars/service.js +120 -0
  16. package/dist/bars/service.js.map +1 -0
  17. package/dist/bars/store.d.ts +105 -0
  18. package/dist/bars/store.js +415 -0
  19. package/dist/bars/store.js.map +1 -0
  20. package/dist/bars/timeframe.d.ts +40 -0
  21. package/dist/bars/timeframe.js +146 -0
  22. package/dist/bars/timeframe.js.map +1 -0
  23. package/dist/bars/types.d.ts +68 -0
  24. package/dist/bars/types.js +13 -0
  25. package/dist/bars/types.js.map +1 -0
  26. package/dist/cli/data-render.d.ts +37 -0
  27. package/dist/cli/data-render.js +143 -0
  28. package/dist/cli/data-render.js.map +1 -0
  29. package/dist/cli/doctor.js +7 -3
  30. package/dist/cli/doctor.js.map +1 -1
  31. package/dist/cli/index.js +758 -27
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/cli/live-render.d.ts +24 -0
  34. package/dist/cli/live-render.js +85 -0
  35. package/dist/cli/live-render.js.map +1 -0
  36. package/dist/cli/range.d.ts +28 -0
  37. package/dist/cli/range.js +63 -0
  38. package/dist/cli/range.js.map +1 -0
  39. package/dist/cli/render.js +3 -0
  40. package/dist/cli/render.js.map +1 -1
  41. package/dist/cli/strategy-render.d.ts +36 -0
  42. package/dist/cli/strategy-render.js +391 -0
  43. package/dist/cli/strategy-render.js.map +1 -0
  44. package/dist/cli/width.d.ts +18 -0
  45. package/dist/cli/width.js +71 -0
  46. package/dist/cli/width.js.map +1 -0
  47. package/dist/config/loader.js +1 -1
  48. package/dist/config/schema.d.ts +7 -0
  49. package/dist/config/schema.js +24 -0
  50. package/dist/config/schema.js.map +1 -1
  51. package/dist/core/okx-client.d.ts +9 -1
  52. package/dist/core/okx-client.js +14 -5
  53. package/dist/core/okx-client.js.map +1 -1
  54. package/dist/i18n/locale.d.ts +24 -0
  55. package/dist/i18n/locale.js +65 -0
  56. package/dist/i18n/locale.js.map +1 -0
  57. package/dist/i18n/messages.d.ts +333 -0
  58. package/dist/i18n/messages.js +660 -0
  59. package/dist/i18n/messages.js.map +1 -0
  60. package/dist/live/account-snapshot.d.ts +30 -0
  61. package/dist/live/account-snapshot.js +130 -0
  62. package/dist/live/account-snapshot.js.map +1 -0
  63. package/dist/live/cutoff-queue.d.ts +42 -0
  64. package/dist/live/cutoff-queue.js +69 -0
  65. package/dist/live/cutoff-queue.js.map +1 -0
  66. package/dist/live/execution-key.d.ts +23 -0
  67. package/dist/live/execution-key.js +31 -0
  68. package/dist/live/execution-key.js.map +1 -0
  69. package/dist/live/failures.d.ts +37 -0
  70. package/dist/live/failures.js +57 -0
  71. package/dist/live/failures.js.map +1 -0
  72. package/dist/live/gates.d.ts +65 -0
  73. package/dist/live/gates.js +136 -0
  74. package/dist/live/gates.js.map +1 -0
  75. package/dist/live/loop.d.ts +56 -0
  76. package/dist/live/loop.js +197 -0
  77. package/dist/live/loop.js.map +1 -0
  78. package/dist/live/preconditions.d.ts +48 -0
  79. package/dist/live/preconditions.js +69 -0
  80. package/dist/live/preconditions.js.map +1 -0
  81. package/dist/live/reconcile.d.ts +46 -0
  82. package/dist/live/reconcile.js +104 -0
  83. package/dist/live/reconcile.js.map +1 -0
  84. package/dist/live/runner.d.ts +57 -0
  85. package/dist/live/runner.js +160 -0
  86. package/dist/live/runner.js.map +1 -0
  87. package/dist/live/schema.d.ts +18 -0
  88. package/dist/live/schema.js +91 -0
  89. package/dist/live/schema.js.map +1 -0
  90. package/dist/live/service.d.ts +144 -0
  91. package/dist/live/service.js +303 -0
  92. package/dist/live/service.js.map +1 -0
  93. package/dist/live/session.d.ts +85 -0
  94. package/dist/live/session.js +234 -0
  95. package/dist/live/session.js.map +1 -0
  96. package/dist/live/sizing.d.ts +62 -0
  97. package/dist/live/sizing.js +79 -0
  98. package/dist/live/sizing.js.map +1 -0
  99. package/dist/live/store.d.ts +123 -0
  100. package/dist/live/store.js +350 -0
  101. package/dist/live/store.js.map +1 -0
  102. package/dist/live/types.d.ts +82 -0
  103. package/dist/live/types.js +2 -0
  104. package/dist/live/types.js.map +1 -0
  105. package/dist/market/websocket.d.ts +16 -1
  106. package/dist/market/websocket.js +60 -5
  107. package/dist/market/websocket.js.map +1 -1
  108. package/dist/mcp/server.d.ts +1 -0
  109. package/dist/mcp/server.js +15 -1
  110. package/dist/mcp/server.js.map +1 -1
  111. package/dist/network/connectivity.d.ts +9 -1
  112. package/dist/network/connectivity.js +28 -1
  113. package/dist/network/connectivity.js.map +1 -1
  114. package/dist/report/chart-script.d.ts +12 -0
  115. package/dist/report/chart-script.js +146 -0
  116. package/dist/report/chart-script.js.map +1 -0
  117. package/dist/report/compare-html.d.ts +8 -0
  118. package/dist/report/compare-html.js +254 -0
  119. package/dist/report/compare-html.js.map +1 -0
  120. package/dist/report/compare-script.d.ts +12 -0
  121. package/dist/report/compare-script.js +109 -0
  122. package/dist/report/compare-script.js.map +1 -0
  123. package/dist/report/compare.d.ts +61 -0
  124. package/dist/report/compare.js +205 -0
  125. package/dist/report/compare.js.map +1 -0
  126. package/dist/report/fetch.d.ts +20 -0
  127. package/dist/report/fetch.js +56 -0
  128. package/dist/report/fetch.js.map +1 -0
  129. package/dist/report/html.d.ts +54 -0
  130. package/dist/report/html.js +641 -0
  131. package/dist/report/html.js.map +1 -0
  132. package/dist/report/open.d.ts +42 -0
  133. package/dist/report/open.js +114 -0
  134. package/dist/report/open.js.map +1 -0
  135. package/dist/runtime/server.d.ts +16 -1
  136. package/dist/runtime/server.js +112 -9
  137. package/dist/runtime/server.js.map +1 -1
  138. package/dist/setup/installer.d.ts +1 -0
  139. package/dist/setup/installer.js +8 -0
  140. package/dist/setup/installer.js.map +1 -1
  141. package/dist/setup/wizard.d.ts +3 -0
  142. package/dist/setup/wizard.js +131 -6
  143. package/dist/setup/wizard.js.map +1 -1
  144. package/dist/strategy/constants.d.ts +23 -0
  145. package/dist/strategy/constants.js +24 -0
  146. package/dist/strategy/constants.js.map +1 -0
  147. package/dist/strategy/environment.d.ts +52 -0
  148. package/dist/strategy/environment.js +187 -0
  149. package/dist/strategy/environment.js.map +1 -0
  150. package/dist/strategy/instrument.d.ts +29 -0
  151. package/dist/strategy/instrument.js +39 -0
  152. package/dist/strategy/instrument.js.map +1 -0
  153. package/dist/strategy/optimize.d.ts +73 -0
  154. package/dist/strategy/optimize.js +113 -0
  155. package/dist/strategy/optimize.js.map +1 -0
  156. package/dist/strategy/parameter-space.d.ts +59 -0
  157. package/dist/strategy/parameter-space.js +221 -0
  158. package/dist/strategy/parameter-space.js.map +1 -0
  159. package/dist/strategy/python-bridge.d.ts +24 -0
  160. package/dist/strategy/python-bridge.js +114 -0
  161. package/dist/strategy/python-bridge.js.map +1 -0
  162. package/dist/strategy/schema.d.ts +9 -0
  163. package/dist/strategy/schema.js +91 -0
  164. package/dist/strategy/schema.js.map +1 -0
  165. package/dist/strategy/service.d.ts +138 -0
  166. package/dist/strategy/service.js +745 -0
  167. package/dist/strategy/service.js.map +1 -0
  168. package/dist/strategy/settings.d.ts +162 -0
  169. package/dist/strategy/settings.js +243 -0
  170. package/dist/strategy/settings.js.map +1 -0
  171. package/dist/strategy/store.d.ts +96 -0
  172. package/dist/strategy/store.js +367 -0
  173. package/dist/strategy/store.js.map +1 -0
  174. package/dist/strategy/templates.d.ts +11 -0
  175. package/dist/strategy/templates.js +134 -0
  176. package/dist/strategy/templates.js.map +1 -0
  177. package/dist/strategy/types.d.ts +111 -0
  178. package/dist/strategy/types.js +2 -0
  179. package/dist/strategy/types.js.map +1 -0
  180. package/dist/tools/catalog.d.ts +16 -0
  181. package/dist/tools/catalog.js +118 -17
  182. package/dist/tools/catalog.js.map +1 -1
  183. package/dist/trade/service.d.ts +12 -0
  184. package/dist/trade/service.js +24 -7
  185. package/dist/trade/service.js.map +1 -1
  186. package/dist/tui/app.d.ts +23 -0
  187. package/dist/tui/app.js +322 -0
  188. package/dist/tui/app.js.map +1 -0
  189. package/dist/tui/commands.d.ts +70 -0
  190. package/dist/tui/commands.js +313 -0
  191. package/dist/tui/commands.js.map +1 -0
  192. package/dist/tui/entries.d.ts +17 -0
  193. package/dist/tui/entries.js +24 -0
  194. package/dist/tui/entries.js.map +1 -0
  195. package/dist/tui/execute.d.ts +26 -0
  196. package/dist/tui/execute.js +664 -0
  197. package/dist/tui/execute.js.map +1 -0
  198. package/dist/tui/history.d.ts +17 -0
  199. package/dist/tui/history.js +48 -0
  200. package/dist/tui/history.js.map +1 -0
  201. package/dist/tui/index.d.ts +8 -0
  202. package/dist/tui/index.js +48 -0
  203. package/dist/tui/index.js.map +1 -0
  204. package/dist/tui/line-editor.d.ts +44 -0
  205. package/dist/tui/line-editor.js +98 -0
  206. package/dist/tui/line-editor.js.map +1 -0
  207. package/dist/tui/progress.d.ts +23 -0
  208. package/dist/tui/progress.js +46 -0
  209. package/dist/tui/progress.js.map +1 -0
  210. package/dist/tui/settings-editor.d.ts +18 -0
  211. package/dist/tui/settings-editor.js +115 -0
  212. package/dist/tui/settings-editor.js.map +1 -0
  213. package/docs/live-trading.md +455 -0
  214. package/docs/strategy-research.md +597 -0
  215. package/package.json +11 -1
  216. package/python/desic_strategy/__init__.py +34 -0
  217. package/python/desic_strategy/actions.py +158 -0
  218. package/python/desic_strategy/context.py +164 -0
  219. package/python/desic_strategy/engine.py +614 -0
  220. package/python/desic_strategy/indicators.py +159 -0
  221. package/python/desic_strategy/live.py +253 -0
  222. package/python/desic_strategy/policy.py +193 -0
  223. package/python/desic_strategy/portfolio.py +152 -0
  224. package/python/desic_strategy/report.py +319 -0
  225. package/python/desic_strategy/runner.py +574 -0
  226. package/python/desic_strategy/timeframe.py +150 -0
  227. package/python/main.py +18 -0
  228. package/skills/okx-live-trading/SKILL.md +117 -0
  229. package/skills/okx-live-trading/agents/openai.yaml +9 -0
  230. package/skills/okx-live-trading/references/lifecycle.md +128 -0
  231. package/skills/okx-strategy-research/SKILL.md +113 -0
  232. package/skills/okx-strategy-research/agents/openai.yaml +9 -0
  233. package/skills/okx-strategy-research/references/execution-semantics.md +107 -0
  234. package/skills/okx-strategy-research/references/field-traps.md +142 -0
  235. package/skills/okx-strategy-research/references/python-api.md +121 -0
  236. package/skills/okx-strategy-research/references/tools-and-data.md +192 -0
  237. package/skills/okx-trading/SKILL.md +11 -10
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/report/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AA2CnC;;;;;;;;;;;GAWG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,KAAsB;IACpD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChD,IAAI,IAAI,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;QACpC,MAAM,IAAI,YAAY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SAAS,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { RuntimeClient } from "../runtime/client.js";
2
+ import type { ReportInput } from "./html.js";
3
+ import type { ComparisonInput } from "./compare.js";
4
+ /**
5
+ * Gathers everything a report needs, following pagination.
6
+ *
7
+ * Requesting a large limit is not enough: the store bounds a single page, so a
8
+ * one-shot read silently returns a prefix. That produced a chart showing a 37%
9
+ * drawdown next to a metric block reporting 79% — the picture contradicting the
10
+ * numbers is worse than no picture.
11
+ */
12
+ export declare function collectReport(client: RuntimeClient, runId: string): Promise<ReportInput>;
13
+ /**
14
+ * Gathers the runs for a comparison.
15
+ *
16
+ * Only the summary and the equity curve are read: a comparison overlays curves and
17
+ * tabulates metrics, and pulling every trade for six runs would cost far more than
18
+ * it shows. Fetched concurrently, since the reads are independent.
19
+ */
20
+ export declare function collectComparison(client: RuntimeClient, runIds: string[]): Promise<ComparisonInput>;
@@ -0,0 +1,56 @@
1
+ import { MAX_PAGE_ROWS } from "../strategy/constants.js";
2
+ /**
3
+ * Ceiling on total points gathered for a report. A year of one-minute bars is
4
+ * ~525k points, which is plotted after downsampling; beyond this the extra
5
+ * detail cannot survive the chart anyway.
6
+ */
7
+ const MAX_POINTS = 600_000;
8
+ /**
9
+ * Gathers everything a report needs, following pagination.
10
+ *
11
+ * Requesting a large limit is not enough: the store bounds a single page, so a
12
+ * one-shot read silently returns a prefix. That produced a chart showing a 37%
13
+ * drawdown next to a metric block reporting 79% — the picture contradicting the
14
+ * numbers is worse than no picture.
15
+ */
16
+ export async function collectReport(client, runId) {
17
+ const run = (await client.call("strategy_get_run", { runId })).data;
18
+ const [equity, trades, actions] = await Promise.all([
19
+ collect(client, "strategy_get_run_equity", runId, MAX_POINTS),
20
+ collect(client, "strategy_get_run_trades", runId, 50_000),
21
+ collect(client, "strategy_get_run_actions", runId, 50_000)
22
+ ]);
23
+ return { run, equity, trades, actions };
24
+ }
25
+ /**
26
+ * Gathers the runs for a comparison.
27
+ *
28
+ * Only the summary and the equity curve are read: a comparison overlays curves and
29
+ * tabulates metrics, and pulling every trade for six runs would cost far more than
30
+ * it shows. Fetched concurrently, since the reads are independent.
31
+ */
32
+ export async function collectComparison(client, runIds) {
33
+ const runs = await Promise.all(runIds.map(async (runId) => {
34
+ const run = (await client.call("strategy_get_run", { runId })).data;
35
+ // A run that never completed has no curve to plot; it is still listed so the
36
+ // comparison can say why it is missing.
37
+ const equity = run.status === "completed" ? await collect(client, "strategy_get_run_equity", runId, MAX_POINTS) : [];
38
+ return { run, equity };
39
+ }));
40
+ return { runs };
41
+ }
42
+ async function collect(client, tool, runId, ceiling) {
43
+ const rows = [];
44
+ let offset = 0;
45
+ for (;;) {
46
+ const page = (await client.call(tool, { runId, offset, limit: MAX_PAGE_ROWS })).data;
47
+ rows.push(...page.rows);
48
+ offset += page.rows.length;
49
+ // Stop on an empty page too, so a store that reports a larger total than it
50
+ // can serve cannot spin here forever.
51
+ if (page.rows.length === 0 || offset >= page.total || rows.length >= ceiling)
52
+ break;
53
+ }
54
+ return rows;
55
+ }
56
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/report/fetch.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD;;;;GAIG;AACH,MAAM,UAAU,GAAG,OAAO,CAAC;AAO3B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAqB,EAAE,KAAa;IACtE,MAAM,GAAG,GAAI,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,CAAC,CAA0B,CAAC,IAAI,CAAC;IAC9F,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAClD,O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AAC,CAAuB,CAAC,IAAI,CAAC;QAC5G,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3B,4EAA4E;QAC5E,sCAAsC;QACtC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,IAAI,OAAO;YAAE,MAAM;IACtF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { EquityPoint, RunSummary } from "../strategy/types.js";
2
+ export interface ReportInput {
3
+ run: RunSummary;
4
+ equity: EquityPoint[];
5
+ trades: Array<Record<string, unknown>>;
6
+ actions: Array<Record<string, unknown>>;
7
+ }
8
+ /**
9
+ * Renders a self-contained HTML report.
10
+ *
11
+ * Everything is inlined — no CDN, no fonts, no scripts fetched at view time — so
12
+ * the file opens offline, keeps working when archived next to its run, and never
13
+ * sends the contents of a strategy anywhere.
14
+ *
15
+ * The chart is drawn as SVG paths computed here rather than by a charting
16
+ * library: a 50,000-point curve as JSON plus a bundled library would be
17
+ * megabytes, and the useful information survives downsampling.
18
+ */
19
+ export declare function renderReportHtml(input: ReportInput): string;
20
+ /**
21
+ * Reduces a curve for plotting while keeping its shape.
22
+ *
23
+ * Each bucket contributes both its highest and lowest point, in the order they
24
+ * occurred. Picking one point per bucket — even alternating high and low — drops
25
+ * a spike whenever it lands in a bucket that happens to be looking for the other
26
+ * extreme, which erases exactly the moves a reader is scanning for.
27
+ */
28
+ export declare function downsample(points: EquityPoint[], target: number): EquityPoint[];
29
+ /** Percentage below the running peak at each point. */
30
+ export declare function drawdownSeries(points: EquityPoint[], initialEquity: number): number[];
31
+ /**
32
+ * Escapes text for HTML.
33
+ *
34
+ * Strategy names and error messages come from user input, so anything
35
+ * interpolated into the document is escaped rather than trusted.
36
+ */
37
+ export declare function escapeHtml(value: string): string;
38
+ /**
39
+ * Escapes a value for a single-quoted HTML attribute.
40
+ *
41
+ * The series JSON is carried in an attribute rather than a script literal, so a
42
+ * quote or an angle bracket inside it cannot terminate the attribute or open a
43
+ * tag. Kept separate from `escapeHtml` because that one escapes double quotes
44
+ * and would mangle the JSON's own syntax.
45
+ */
46
+ export declare function escapeAttribute(value: string): string;
47
+ /**
48
+ * Styles for the comparison document.
49
+ *
50
+ * The single-run sheet plus the few rules a matrix table needs, rather than a
51
+ * second copy: the two documents should not drift apart visually, and a duplicated
52
+ * sheet is exactly how that happens.
53
+ */
54
+ export declare const COMPARE_STYLES = "\n:root{--bg:#0f1116;--panel:#171a21;--line:#242833;--text:#e6e8ee;--dim:#8b90a0;--up:#3fb950;--down:#f2777a;--accent:#4f9cf9}\n@media(prefers-color-scheme:light){:root{--bg:#f7f8fa;--panel:#fff;--line:#e3e6ec;--text:#1a1d24;--dim:#6b7280;--up:#1a7f37;--down:#c9372c}}\n*{box-sizing:border-box}\nbody{margin:0;background:var(--bg);color:var(--text);font:14px/1.55 -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,\"Helvetica Neue\",\"PingFang SC\",\"Microsoft YaHei\",sans-serif}\nmain{max-width:1080px;margin:0 auto;padding:32px 24px 64px}\nheader{display:flex;justify-content:space-between;align-items:flex-end;gap:24px;flex-wrap:wrap;padding-bottom:20px;border-bottom:1px solid var(--line)}\nh1{margin:0;font-size:26px;font-weight:600;letter-spacing:-.01em}\n.sub{margin:4px 0 0;color:var(--dim);font-size:13px}\n.headline{text-align:right}\n.headline .value{display:block;font-size:34px;font-weight:650;letter-spacing:-.02em;font-variant-numeric:tabular-nums}\n.headline .label{color:var(--dim);font-size:12px;text-transform:uppercase;letter-spacing:.08em}\n.up{color:var(--up)}.down{color:var(--down)}.flat{color:var(--dim)}\n.facts{display:flex;gap:28px;flex-wrap:wrap;margin:20px 0 8px;color:var(--dim);font-size:13px}\n.facts span{display:block;text-transform:uppercase;letter-spacing:.06em;font-size:11px}\n.facts strong{color:var(--text);font-weight:550;font-variant-numeric:tabular-nums}\n.warnings{margin:20px 0 0;padding:12px 16px;border-left:3px solid var(--down);background:color-mix(in srgb,var(--down) 8%,transparent);border-radius:0 6px 6px 0}\n.warnings p{margin:4px 0;font-size:13px}\nsection{margin-top:32px}\nh2{margin:0 0 14px;font-size:12px;font-weight:600;text-transform:uppercase;letter-spacing:.1em;color:var(--dim)}\nh2 .count{color:var(--dim);font-weight:400}\ndl{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:1px;margin:0;background:var(--line);border:1px solid var(--line);border-radius:8px;overflow:hidden}\ndl>div{background:var(--panel);padding:12px 14px}\ndt{color:var(--dim);font-size:11px;text-transform:uppercase;letter-spacing:.06em}\ndd{margin:3px 0 0;font-size:16px;font-weight:550;font-variant-numeric:tabular-nums}\n.chart{background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:10px 12px;display:flex;gap:10px;align-items:stretch}\n.chart.drawdown{margin-top:8px;border-radius:8px}\n.chart svg{flex:1;height:240px;width:100%;display:block}\n.chart.drawdown svg{height:80px}\n.axis{display:flex;flex-direction:column;justify-content:space-between;color:var(--dim);font-size:11px;font-variant-numeric:tabular-nums;min-width:62px;text-align:right}\n.range{margin:8px 0 0;color:var(--dim);font-size:12px}\n.chart{position:relative}\n.chart svg{cursor:crosshair}\n.chart:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n.baseline{stroke:var(--dim);stroke-width:1;stroke-dasharray:3 4;opacity:.5;vector-effect:non-scaling-stroke}\n.crosshair{stroke:var(--dim);stroke-width:1;vector-effect:non-scaling-stroke;pointer-events:none}\n.marker{fill:var(--accent);stroke:var(--panel);stroke-width:1.5;pointer-events:none}\n.tooltip{position:absolute;top:10px;pointer-events:none;background:var(--panel);border:1px solid var(--line);border-radius:6px;padding:8px 10px;font-size:12px;min-width:180px;box-shadow:0 4px 16px rgba(0,0,0,.28);z-index:2}\n.tooltip .row{display:flex;justify-content:space-between;gap:14px;padding:1px 0}\n.tooltip .row span{color:var(--dim)}\n.tooltip .row b{font-weight:550;font-variant-numeric:tabular-nums}\n.scroll{overflow-x:auto;border:1px solid var(--line);border-radius:8px}\ntable{width:100%;border-collapse:collapse;font-size:13px}\nth,td{padding:8px 12px;text-align:left;border-bottom:1px solid var(--line);white-space:nowrap}\nth{background:var(--panel);color:var(--dim);font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;position:sticky;top:0}\ntbody tr:last-child td{border-bottom:none}\ntd.n{text-align:right;font-variant-numeric:tabular-nums}\ntr.up td:nth-child(5),tr.up td:nth-child(6){color:var(--up)}\ntr.down td:nth-child(5),tr.down td:nth-child(6){color:var(--down)}\n.mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}\ntd.dim{color:var(--dim)}\n.scroll.tall{max-height:520px;overflow-y:auto}\n.histogram{background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:12px 14px}\n.bin{display:flex;align-items:center;gap:10px;padding:3px 0}\n.bin .range{min-width:132px;color:var(--dim);text-align:right;flex-shrink:0}\n.bin .track{flex:1;height:12px;background:color-mix(in srgb,var(--line) 60%,transparent);border-radius:3px;overflow:hidden}\n.bin .fill{display:block;height:100%;border-radius:3px}\n.bin .fill.up{background:var(--up)}\n.bin .fill.down{background:var(--down)}\n.bin>.count{min-width:44px;text-align:right;color:var(--dim);font-size:12px;font-variant-numeric:tabular-nums;flex-shrink:0}\n.empty{color:var(--dim);font-size:13px}\nfooter{margin-top:40px;padding-top:16px;border-top:1px solid var(--line);color:var(--dim);font-size:12px}\nfooter p{margin:4px 0}\n\n.legend{display:flex;gap:20px;flex-wrap:wrap;margin:20px 0 0;font-size:13px}\n.legend div{display:flex;align-items:center;gap:7px}\n.legend i,th i{display:inline-block;width:10px;height:10px;border-radius:2px;flex-shrink:0}\nth i{margin-right:6px;vertical-align:middle}\ntable.matrix th[scope=row]{background:var(--panel);color:var(--dim);text-transform:none;letter-spacing:0;font-size:12px;font-weight:500;text-align:left;position:sticky;left:0}\ntable.matrix thead th{text-align:right}\ntable.matrix thead th span.dim{display:block;font-weight:400;text-transform:none;letter-spacing:0;font-size:10px}\ntd.best{color:var(--up);font-weight:600}\n.chart .tooltip .swatch{display:inline-block;width:8px;height:8px;border-radius:2px;margin-right:6px}\n.chart .tooltip .row.head{border-bottom:1px solid var(--line);margin-bottom:3px;padding-bottom:3px}\n";