Spaces:
Running
Running
File size: 232,292 Bytes
8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 615c2b5 8b8fb92 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 | <!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>cli/readme | backtest-kit</title><meta name="description" content="Documentation for backtest-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script><script async src="../assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">backtest-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">backtest-kit</a></li><li><a href="cli_readme.html">cli/readme</a></li></ul></div><div class="tsd-panel tsd-typography"><img src="https://github.com/tripolskypetr/backtest-kit/raw/refs/heads/master/assets/square_compasses.svg" height="45px" align="right">
<a id="π-backtest-kitcli" class="tsd-anchor"></a><h1 class="tsd-anchor-link">π @backtest-kit/cli<a href="#π-backtest-kitcli" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h1><blockquote>
<p>Zero-boilerplate CLI for launching backtests, paper trading, and live trading. Run any backtest-kit strategy from the command line β no setup code required.</p>
</blockquote>
<p><img src="https://raw.githubusercontent.com/tripolskypetr/backtest-kit/HEAD/assets/screenshots/screenshot16.png" alt="screenshot"></p>
<p><a href="https://deepwiki.com/tripolskypetr/backtest-kit"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
<a href="https://npmjs.org/package/@backtest-kit/cli"><img src="https://img.shields.io/npm/v/@backtest-kit/cli.svg?style=flat-square" alt="npm"></a>
<a href=""><img src="https://img.shields.io/badge/TypeScript-5.0+-blue" alt="TypeScript"></a></p>
<p>Point the CLI at your strategy file, choose a mode, and it handles exchange connectivity, candle caching, UI dashboard, and Telegram notifications for you.</p>
<p>π <strong><a href="https://backtest-kit.github.io/documents/article_07_ai_news_trading_signals.html">Backtest Kit Docs</a></strong> | π <strong><a href="https://github.com/tripolskypetr/backtest-kit">GitHub</a></strong></p>
<blockquote>
<p><strong>New to backtest-kit?</strong> The fastest way to get a real, production-ready setup is to clone the <a href="https://github.com/tripolskypetr/backtest-kit/tree/master/example">reference implementation</a> β a fully working news-sentiment AI trading system with LLM forecasting, multi-timeframe data, and a documented February 2026 backtest. Start there instead of from scratch.</p>
</blockquote>
<a id="ποΈ-cli-init" class="tsd-anchor"></a><h2 class="tsd-anchor-link">ποΈ CLI Init<a href="#ποΈ-cli-init" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Minimal scaffold β all boilerplate stays inside @backtest-kit/cli:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--init</span><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">backtest-kit-project</span><br/><span class="hl-0">cd</span><span class="hl-1"> </span><span class="hl-2">backtest-kit-project</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">start</span><span class="hl-1"> </span><span class="hl-3">--</span><span class="hl-1"> </span><span class="hl-3">--help</span>
</code><button type="button">Copy</button></pre>
<a id="π€-philosophy" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π€ Philosophy<a href="#π€-philosophy" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> is designed to do <strong>two things well</strong> β and the same tool covers both.</p>
<p><strong>1. The lightest possible runner for a solo quant on day one.</strong></p>
<p>You write a strategy file, point the CLI at it, and you're trading. No DI container to learn, no project scaffold to fight, no infrastructure code to copy-paste. One developer, one strategy, one command:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--init</span><br/><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--backtest</span><span class="hl-1"> </span><span class="hl-2">./content/feb_2026.strategy/index.ts</span>
</code><button type="button">Copy</button></pre>
<p>That's the whole onboarding. The first day you have an idea, you can backtest it. The first week you have an edge, you can paper-trade it. The first month you have a P&L, you can run it live β same CLI, different flag.</p>
<p><strong>2. Built-in monorepo tooling for when the business takes off.</strong></p>
<p>The moment you start making money is the worst possible moment to rewrite your stack in another language. So the CLI is also a monorepo-grade runner from day one β even if you don't use it that way at first.</p>
<pre><code><span class="hl-4">monorepo</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">content</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">strategy</span><span class="hl-1">/ </span><br/><span class="hl-1">β βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">strategy</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> # </span><span class="hl-4">strategy</span><span class="hl-1"> </span><span class="hl-4">production</span><span class="hl-1"> </span><span class="hl-4">code</span><br/><span class="hl-1">β βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">test</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> # </span><span class="hl-4">developer</span><span class="hl-1"> </span><span class="hl-4">playground</span><br/><span class="hl-1">βββ </span><span class="hl-4">packages</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">shared</span><span class="hl-1">-</span><span class="hl-4">broker</span><span class="hl-1">/ # </span><span class="hl-4">shared</span><span class="hl-1"> </span><span class="hl-4">broker</span><span class="hl-1"> </span><span class="hl-4">code</span><br/><span class="hl-1">β βββ </span><span class="hl-4">shared</span><span class="hl-1">-</span><span class="hl-4">signals</span><span class="hl-1">/ # </span><span class="hl-4">common</span><span class="hl-1"> </span><span class="hl-0">indicators</span><span class="hl-1"> (</span><span class="hl-8">RSI</span><span class="hl-1">, </span><span class="hl-8">MACD</span><span class="hl-1">)</span>
</code><button>Copy</button></pre>
<p>As a result: you used to backtest your first idea is the same tool you use to run a desk of strategies in production. No rewrite, no language switch, no framework migration when the business scales β only more files in the monorepo.</p>
<a id="β¨-features" class="tsd-anchor"></a><h2 class="tsd-anchor-link">β¨ Features<a href="#β¨-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
<li>π <strong>Zero Config</strong>: Run <code>npx @backtest-kit/cli --backtest ./strategy.mjs</code> β no boilerplate needed</li>
<li>π <strong>Four Modes</strong>: Backtest on historical data, walker A/B comparison, paper trade on live prices, or deploy live bots</li>
<li>πΎ <strong>Auto Candle Cache</strong>: Warms OHLCV cache for all required intervals before backtest starts</li>
<li>π <strong>Web Dashboard</strong>: Launch <code>@backtest-kit/ui</code> with a single <code>--ui</code> flag</li>
<li>π¬ <strong>Telegram Alerts</strong>: Send formatted trade notifications with charts via <code>--telegram</code></li>
<li>π <strong>Default Binance</strong>: CCXT Binance exchange schema registered automatically when none is provided</li>
<li>π§© <strong>Module Hooks</strong>: Drop a <code>live.module.mjs</code>, <code>paper.module.mjs</code>, or <code>backtest.module.mjs</code> to register a <code>Broker</code> adapter. No manual wiring needed.</li>
<li>ποΈ <strong>Transactional Live Orders</strong>: Broker adapter intercepts every trade mutation before internal state changes β exchange rejection rolls back the operation atomically.</li>
<li>π <strong>Pluggable Logger</strong>: Override the built-in logger with <code>setLogger()</code> from your strategy module</li>
<li>π <strong>Graceful Shutdown</strong>: SIGINT stops the active run and cleans up all subscriptions safely</li>
</ul>
<a id="π-what-it-does" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π What It Does<a href="#π-what-it-does" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> wraps the <code>backtest-kit</code> engine and resolves all scaffolding automatically:</p>
<table>
<thead>
<tr>
<th>Mode</th>
<th>Command Line Args</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Backtest</strong></td>
<td><code>--backtest</code></td>
<td>Run strategy on historical candle data</td>
</tr>
<tr>
<td><strong>Walker</strong></td>
<td><code>--walker</code></td>
<td>A/B compare multiple strategies on the same historical data</td>
</tr>
<tr>
<td><strong>Paper</strong></td>
<td><code>--paper</code></td>
<td>Live prices, no real orders</td>
</tr>
<tr>
<td><strong>Live</strong></td>
<td><code>--live</code></td>
<td>Real trades via exchange API</td>
</tr>
<tr>
<td><strong>UI Dashboard</strong></td>
<td><code>--ui</code></td>
<td>Web dashboard at <code>http://localhost:60050</code></td>
</tr>
<tr>
<td><strong>Telegram</strong></td>
<td><code>--telegram</code></td>
<td>Trade notifications with price charts</td>
</tr>
<tr>
<td><strong>PineScript</strong></td>
<td><code>--pine</code></td>
<td>Run a local <code>.pine</code> indicator against exchange data</td>
</tr>
<tr>
<td><strong>Pine Editor</strong></td>
<td><code>--editor</code></td>
<td>Open the visual Pine Script editor in the browser</td>
</tr>
<tr>
<td><strong>Candle Dump</strong></td>
<td><code>--dump</code></td>
<td>Fetch and save raw OHLCV candles to a file</td>
</tr>
<tr>
<td><strong>PnL Debug</strong></td>
<td><code>--pnldebug</code></td>
<td>Simulate per-minute PnL for a given entry price and direction</td>
</tr>
<tr>
<td><strong>Broker Debug</strong></td>
<td><code>--brokerdebug</code></td>
<td>Fire a single broker commit against the live broker adapter</td>
</tr>
<tr>
<td><strong>Flush</strong></td>
<td><code>--flush</code></td>
<td>Delete report/log/markdown/agent folders from strategy dump dir</td>
</tr>
<tr>
<td><strong>Init Project</strong></td>
<td><code>--init</code></td>
<td>Scaffold a new backtest-kit project</td>
</tr>
</tbody>
</table>
<a id="π-installation" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Installation<a href="#π-installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Add <code>@backtest-kit/cli</code> to your project and wire it up in <code>package.json</code> scripts:</p>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span>
</code><button type="button">Copy</button></pre>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./src/index.mjs"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"paper"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --paper ./src/index.mjs"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"start"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --live ./src/index.mjs"</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-16">"dependencies"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"@backtest-kit/cli"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest-kit"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"ccxt"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<p>Or run once without installing:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--backtest</span><span class="hl-1"> </span><span class="hl-2">./src/index.mjs</span>
</code><button type="button">Copy</button></pre>
<a id="π-quick-start" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Quick Start<a href="#π-quick-start" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Create your strategy entry point (<code>src/index.mjs</code>). The file registers schemas via <code>backtest-kit</code> β <code>@backtest-kit/cli</code> is only the runner:</p>
<pre><code class="javascript"><span class="hl-6">// src/index.mjs</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">addStrategySchema</span><span class="hl-1">, </span><span class="hl-4">addExchangeSchema</span><span class="hl-1">, </span><span class="hl-4">addFrameSchema</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'backtest-kit'</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'ccxt'</span><span class="hl-1">;</span><br/><br/><span class="hl-6">// Register exchange</span><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">'binance'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">binance</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ohlcv</span><span class="hl-1"> = </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">.</span><span class="hl-0">fetchOHLCV</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">.</span><span class="hl-0">getTime</span><span class="hl-1">(), </span><span class="hl-4">limit</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-4">ohlcv</span><span class="hl-1">.</span><span class="hl-0">map</span><span class="hl-1">(([</span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">]) </span><span class="hl-3">=></span><span class="hl-1"> ({</span><br/><span class="hl-1"> </span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">,</span><br/><span class="hl-1"> }));</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-0">formatPrice</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">price</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">2</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">formatQuantity</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">quantity</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">quantity</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">8</span><span class="hl-1">),</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-6">// Register frame (backtest only)</span><br/><span class="hl-0">addFrameSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">frameName:</span><span class="hl-1"> </span><span class="hl-2">'feb-2024'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">interval:</span><span class="hl-1"> </span><span class="hl-2">'1m'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">startDate:</span><span class="hl-1"> </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Date</span><span class="hl-1">(</span><span class="hl-2">'2024-02-01'</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-4">endDate:</span><span class="hl-1"> </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Date</span><span class="hl-1">(</span><span class="hl-2">'2024-02-29'</span><span class="hl-1">),</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-6">// Register strategy</span><br/><span class="hl-0">addStrategySchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">strategyName:</span><span class="hl-1"> </span><span class="hl-2">'my-strategy'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">interval:</span><span class="hl-1"> </span><span class="hl-2">'15m'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getSignal</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">// return signal or null</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-3">null</span><span class="hl-1">;</span><br/><span class="hl-1"> },</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>Run a backtest:</p>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">backtest</span><span class="hl-1"> </span><span class="hl-3">--</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span>
</code><button type="button">Copy</button></pre>
<p>Run with UI dashboard and Telegram:</p>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">backtest</span><span class="hl-1"> </span><span class="hl-3">--</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--ui</span><span class="hl-1"> </span><span class="hl-3">--telegram</span>
</code><button type="button">Copy</button></pre>
<p>Run live trading:</p>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">start</span><span class="hl-1"> </span><span class="hl-3">--</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--ui</span>
</code><button type="button">Copy</button></pre>
<a id="ποΈ-cli-flags" class="tsd-anchor"></a><h2 class="tsd-anchor-link">ποΈ CLI Flags<a href="#ποΈ-cli-flags" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><table>
<thead>
<tr>
<th>Command Line Args</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--backtest</code></td>
<td>boolean</td>
<td>Run historical backtest (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--walker</code></td>
<td>boolean</td>
<td>Run Walker A/B strategy comparison (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--paper</code></td>
<td>boolean</td>
<td>Paper trading (live prices, no orders) (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--live</code></td>
<td>boolean</td>
<td>Run live trading (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--ui</code></td>
<td>boolean</td>
<td>Start web UI dashboard (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--telegram</code></td>
<td>boolean</td>
<td>Enable Telegram notifications (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--verbose</code></td>
<td>boolean</td>
<td>Log each candle fetch (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--noCache</code></td>
<td>boolean</td>
<td>Skip candle cache warming before backtest (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--noFlush</code></td>
<td>boolean</td>
<td>Skip removing report/log/markdown/agent folders before backtest run (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--symbol</code></td>
<td>string</td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>--strategy</code></td>
<td>string</td>
<td>Strategy name (default: first registered)</td>
</tr>
<tr>
<td><code>--exchange</code></td>
<td>string</td>
<td>Exchange name (default: first registered)</td>
</tr>
<tr>
<td><code>--frame</code></td>
<td>string</td>
<td>Backtest frame name (default: first registered)</td>
</tr>
<tr>
<td><code>--cacheInterval</code></td>
<td>string</td>
<td>Intervals to pre-cache before backtest (default: <code>"1m, 15m, 30m, 4h"</code>)</td>
</tr>
<tr>
<td><code>--brokerdebug</code></td>
<td>boolean</td>
<td>Fire a single broker commit against the live broker adapter (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--commit</code></td>
<td>string</td>
<td>Commit type for <code>--brokerdebug</code> (default: <code>"signal-open"</code>)</td>
</tr>
</tbody>
</table>
<p><strong>Positional argument (required):</strong> path to your strategy entry point file (set once in <code>package.json</code> scripts).</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./src/index.mjs"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<a id="π-execution-modes" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Execution Modes<a href="#π-execution-modes" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="backtest" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Backtest<a href="#backtest" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Runs the strategy against historical candle data using a registered <code>FrameSchema</code>.</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest --symbol ETHUSDT --strategy my-strategy --exchange binance --frame feb-2024 --cacheInterval </span><span class="hl-13">\"</span><span class="hl-2">1m, 15m, 1h, 4h</span><span class="hl-13">\"</span><span class="hl-2"> ./src/index.mjs"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">backtest</span>
</code><button type="button">Copy</button></pre>
<p>Before running, the CLI removes the <code>report</code>, <code>log</code>, <code>markdown</code>, and <code>agent</code> folders from the strategy's <code>dump/</code> directory, then warms the candle cache for every interval in <code>--cacheInterval</code>. On the next run, cached data is used directly β no API calls needed. Pass <code>--noCache</code> to skip cache warming, <code>--noFlush</code> to keep existing output folders.</p>
<a id="paper-trading" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Paper Trading<a href="#paper-trading" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Connects to the live exchange but does not place real orders. Identical code path to live β safe for strategy validation.</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"paper"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --paper --symbol BTCUSDT ./src/index.mjs"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">paper</span>
</code><button type="button">Copy</button></pre>
<a id="live-trading" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Live Trading<a href="#live-trading" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Deploys a real trading bot. Requires exchange API keys configured in your <code>.env</code> or environment.</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"start"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --live --ui --telegram --symbol BTCUSDT ./src/index.mjs"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">start</span>
</code><button type="button">Copy</button></pre>
<a id="walker--ab-strategy-comparison" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Walker β A/B Strategy Comparison<a href="#walker--ab-strategy-comparison" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Runs the same historical period against multiple strategy files and prints a ranked comparison report. Use it to pick the best variant before deploying to backtest or live.</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"walker"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --walker --symbol BTCUSDT --noCache ./content/feb_2026_v1.strategy.ts ./content/feb_2026_v2.strategy.ts ./content/feb_2026_v3.strategy.ts"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">walker</span>
</code><button type="button">Copy</button></pre>
<p>Each positional argument is a separate strategy entry point. Before loading them, the CLI removes the <code>report</code>, <code>log</code>, <code>markdown</code>, and <code>agent</code> folders from each entry point's <code>dump/</code> directory. Pass <code>--noFlush</code> to keep existing output. All files are loaded without changing <code>process.cwd()</code> β <code>.env</code> is read from the working directory only. After loading, <code>addWalkerSchema</code> is called automatically using the exchange and frame registered by the strategy files.</p>
<p>If no frame is registered, the CLI falls back to the last 31 days from <code>Date.now()</code> with a console warning.</p>
<p><strong>Walker-specific flags:</strong></p>
<table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--walker</code></td>
<td>boolean</td>
<td>Enable Walker comparison mode</td>
</tr>
<tr>
<td><code>--symbol</code></td>
<td>string</td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>--cacheInterval</code></td>
<td>string</td>
<td>Intervals to pre-cache (default: <code>"1m, 15m, 30m, 4h"</code>)</td>
</tr>
<tr>
<td><code>--noCache</code></td>
<td>boolean</td>
<td>Skip candle cache warming (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--noFlush</code></td>
<td>boolean</td>
<td>Skip removing report/log/markdown/agent folders before walker run (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--verbose</code></td>
<td>boolean</td>
<td>Log each candle fetch and strategy progress (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>--output</code></td>
<td>string</td>
<td>Output file base name (default: <code>walker_{SYMBOL}_{TIMESTAMP}</code>)</td>
</tr>
<tr>
<td><code>--json</code></td>
<td>boolean</td>
<td>Save results as JSON to <code>./dump/<output>.json</code></td>
</tr>
<tr>
<td><code>--markdown</code></td>
<td>boolean</td>
<td>Save report as Markdown to <code>./dump/<output>.md</code></td>
</tr>
</tbody>
</table>
<p><strong>Output modes:</strong></p>
<ul>
<li>No flag β print Markdown report to stdout</li>
<li><code>--json</code> β save <code>Walker.getData()</code> result as JSON and exit</li>
<li><code>--markdown</code> β save <code>Walker.getReport()</code> as <code>.md</code> file and exit</li>
</ul>
<p><strong>Module hook:</strong> <code>./modules/walker.module</code> is loaded automatically before the comparison starts (same rules as other modes β <code>.ts</code>, <code>.mjs</code>, <code>.cjs</code> tried in order).</p>
<p><strong>Example β compare three variants and save the report:</strong></p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--walker</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--noCache</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--markdown</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">feb_2026_comparison</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-2">./content/feb_2026_v1.strategy.ts</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-2">./content/feb_2026_v2.strategy.ts</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-2">./content/feb_2026_v3.strategy.ts</span><br/><span class="hl-6"># β ./dump/feb_2026_comparison.md</span>
</code><button type="button">Copy</button></pre>
<a id="π-multiple-symbol-parallel" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Multiple Symbol Parallel<a href="#π-multiple-symbol-parallel" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><blockquote>
<p><strong>For Poweruser β skip unless needed.</strong> The standard flow runs one symbol from <code>--symbol</code>. Use <code>--entry</code> only to fan out one strategy across many symbols at once, or to drive <code>*.background()</code> from a UI / DB / API.</p>
</blockquote>
<p>With <code>--entry</code>, the CLI does only the boilerplate β <code>Setup</code>, providers (<code>--ui</code> / <code>--telegram</code>), the matching <code>./modules/<mode>.module</code>, SIGINT that stops every active run via <code>*.list()</code>, and <code>shutdown()</code> once <code>listenDone*</code> reports all your runs complete. Picking the symbol set, warming cache, and calling <code>*.background()</code> is on you.</p>
<p>The <code>--entry</code> flag is a modifier β combine it with exactly one of <code>--backtest</code> / <code>--live</code> / <code>--paper</code> / <code>--walker</code>. One positional: the path to your entry file.</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--backtest</span><span class="hl-1"> </span><span class="hl-3">--entry</span><span class="hl-1"> </span><span class="hl-2">./src/multi-symbol.mjs</span>
</code><button type="button">Copy</button></pre>
<a id="example-backtest-a-strategy-on-five-symbols-at-once" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Example: backtest a strategy on five symbols at once<a href="#example-backtest-a-strategy-on-five-symbols-at-once" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-6">// src/multi-symbol.mjs</span><br/><span class="hl-5">import</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">addExchangeSchema</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">addFrameSchema</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">addStrategySchema</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">Backtest</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">warmCandles</span><span class="hl-1">,</span><br/><span class="hl-1">} </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"backtest-kit"</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"ccxt"</span><span class="hl-1">;</span><br/><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"binance"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">binance</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ohlcv</span><span class="hl-1"> = </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">.</span><span class="hl-0">fetchOHLCV</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">.</span><span class="hl-0">getTime</span><span class="hl-1">(), </span><span class="hl-4">limit</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-4">ohlcv</span><span class="hl-1">.</span><span class="hl-0">map</span><span class="hl-1">(([</span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">]) </span><span class="hl-3">=></span><span class="hl-1"> ({</span><br/><span class="hl-1"> </span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">,</span><br/><span class="hl-1"> }));</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-0">formatPrice</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">price</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">2</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">formatQuantity</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">quantity</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">quantity</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">8</span><span class="hl-1">),</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-0">addFrameSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">frameName:</span><span class="hl-1"> </span><span class="hl-2">"feb-2026"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">interval:</span><span class="hl-1"> </span><span class="hl-2">"1m"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">startDate:</span><span class="hl-1"> </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Date</span><span class="hl-1">(</span><span class="hl-2">"2026-02-01"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-4">endDate:</span><span class="hl-1"> </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Date</span><span class="hl-1">(</span><span class="hl-2">"2026-02-28"</span><span class="hl-1">),</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-0">addStrategySchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">strategyName:</span><span class="hl-1"> </span><span class="hl-2">"my-strategy"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">interval:</span><span class="hl-1"> </span><span class="hl-2">"15m"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getSignal</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-3">null</span><span class="hl-1">,</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-6">// Decide the symbol set yourself β from a UI, database, API, or just a list.</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">symbols</span><span class="hl-1"> = [</span><span class="hl-2">"BTCUSDT"</span><span class="hl-1">, </span><span class="hl-2">"ETHUSDT"</span><span class="hl-1">, </span><span class="hl-2">"SOLUSDT"</span><span class="hl-1">, </span><span class="hl-2">"BNBUSDT"</span><span class="hl-1">, </span><span class="hl-2">"XRPUSDT"</span><span class="hl-1">];</span><br/><br/><span class="hl-5">for</span><span class="hl-1"> (</span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">symbol</span><span class="hl-1"> </span><span class="hl-3">of</span><span class="hl-1"> </span><span class="hl-4">symbols</span><span class="hl-1">) {</span><br/><br/><span class="hl-1"> </span><span class="hl-6">// </span><br/><span class="hl-1"> </span><span class="hl-6">// Optional</span><br/><span class="hl-1"> </span><span class="hl-6">// </span><br/><span class="hl-1"> </span><span class="hl-6">// await warmCandles({</span><br/><span class="hl-1"> </span><span class="hl-6">// exchangeName: "binance,</span><br/><span class="hl-1"> </span><span class="hl-6">// from: new Date("2026-01-01T00:00:00Z"),</span><br/><span class="hl-1"> </span><span class="hl-6">// to: new Date("2026-01-31T23:59:59Z"),</span><br/><span class="hl-1"> </span><span class="hl-6">// interval: "1m",</span><br/><span class="hl-1"> </span><span class="hl-6">// symbol,</span><br/><span class="hl-1"> </span><span class="hl-6">// })</span><br/><br/><br/><span class="hl-1"> </span><span class="hl-4">Backtest</span><span class="hl-1">.</span><span class="hl-0">background</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-4">strategyName:</span><span class="hl-1"> </span><span class="hl-2">"my-strategy"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"binance"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">frameName:</span><span class="hl-1"> </span><span class="hl-2">"feb-2026"</span><span class="hl-1">,</span><br/><span class="hl-1"> });</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<p>The same shape works for <code>--live --entry</code> / <code>--paper --entry</code> (call <code>Live.background()</code> per symbol with your broker adapter)</p>
<a id="ποΈ-monorepo-usage" class="tsd-anchor"></a><h2 class="tsd-anchor-link">ποΈ Monorepo Usage<a href="#ποΈ-monorepo-usage" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> works out of the box in a monorepo where each strategy lives in its own subdirectory. When the CLI loads your entry point file, it automatically changes the working directory to the file's location β so all relative paths (<code>dump/</code>, <code>modules/</code>, <code>template/</code>) resolve inside that strategy's folder, not the project root.</p>
<a id="how-it-works" class="tsd-anchor"></a><h3 class="tsd-anchor-link">How It Works<a href="#how-it-works" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Internally, <code>ResolveService</code> does the following before executing your entry point:</p>
<pre><code><span class="hl-4">process</span><span class="hl-1">.</span><span class="hl-0">chdir</span><span class="hl-1">(</span><span class="hl-4">path</span><span class="hl-1">.</span><span class="hl-0">dirname</span><span class="hl-1">(</span><span class="hl-4">entryPoint</span><span class="hl-1">)) </span><span class="hl-6">// cwd β strategy directory</span><br/><span class="hl-4">dotenv</span><span class="hl-1">.</span><span class="hl-0">config</span><span class="hl-1">({ </span><span class="hl-4">path:</span><span class="hl-1"> </span><span class="hl-4">rootDir</span><span class="hl-1"> + </span><span class="hl-2">'/.env'</span><span class="hl-1"> }) </span><span class="hl-6">// load root .env first</span><br/><span class="hl-4">dotenv</span><span class="hl-1">.</span><span class="hl-0">config</span><span class="hl-1">({ </span><span class="hl-4">path:</span><span class="hl-1"> </span><span class="hl-4">strategyDir</span><span class="hl-1"> + </span><span class="hl-2">'/.env'</span><span class="hl-1">, </span><span class="hl-4">override:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1"> }) </span><span class="hl-6">// strategy .env overrides</span>
</code><button>Copy</button></pre>
<p>Everything that follows β candle cache warming, report generation, module loading, template resolution β uses the new cwd automatically.</p>
<a id="project-structure" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Project Structure<a href="#project-structure" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code><span class="hl-4">monorepo</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">package</span><span class="hl-1">.</span><span class="hl-4">json</span><span class="hl-1"> # </span><span class="hl-4">root</span><span class="hl-1"> </span><span class="hl-0">scripts</span><span class="hl-1"> (</span><span class="hl-4">one</span><span class="hl-1"> </span><span class="hl-4">per</span><span class="hl-1"> </span><span class="hl-4">strategy</span><span class="hl-1">)</span><br/><span class="hl-1">βββ .</span><span class="hl-4">env</span><span class="hl-1"> # </span><span class="hl-4">shared</span><span class="hl-1"> </span><span class="hl-8">API</span><span class="hl-1"> </span><span class="hl-0">keys</span><span class="hl-1"> (</span><span class="hl-4">exchange</span><span class="hl-1">, </span><span class="hl-4">Telegram</span><span class="hl-1">, </span><span class="hl-4">etc</span><span class="hl-1">.)</span><br/><span class="hl-1">βββ </span><span class="hl-4">strategies</span><span class="hl-1">/</span><br/><span class="hl-1"> βββ </span><span class="hl-4">oct_2025</span><span class="hl-1">/</span><br/><span class="hl-1"> β βββ </span><span class="hl-4">index</span><span class="hl-1">.</span><span class="hl-4">mjs</span><span class="hl-1"> # </span><span class="hl-4">entry</span><span class="hl-1"> </span><span class="hl-4">point</span><span class="hl-1"> β </span><span class="hl-4">registers</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">/</span><span class="hl-4">frame</span><span class="hl-1">/</span><span class="hl-4">strategy</span><span class="hl-1"> </span><span class="hl-4">schemas</span><br/><span class="hl-1"> β βββ .</span><span class="hl-4">env</span><span class="hl-1"> # </span><span class="hl-4">overrides</span><span class="hl-1"> </span><span class="hl-4">root</span><span class="hl-1"> .</span><span class="hl-4">env</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-3">this</span><span class="hl-1"> </span><span class="hl-4">strategy</span><span class="hl-1"> </span><br/><span class="hl-1"> β βββ </span><span class="hl-0">modules</span><span class="hl-1"> (</span><span class="hl-4">optional</span><span class="hl-1">)</span><br/><span class="hl-1"> β | βββ </span><span class="hl-4">live</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">mjs</span><span class="hl-1"> # </span><span class="hl-4">broker</span><span class="hl-1"> </span><span class="hl-4">adapter</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> --</span><span class="hl-4">live</span><span class="hl-1"> </span><span class="hl-0">mode</span><span class="hl-1"> (</span><span class="hl-4">optional</span><span class="hl-1">)</span><br/><span class="hl-1"> β | βββ </span><span class="hl-4">paper</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">mjs</span><span class="hl-1"> # </span><span class="hl-4">broker</span><span class="hl-1"> </span><span class="hl-4">adapter</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> --</span><span class="hl-4">paper</span><span class="hl-1"> </span><span class="hl-0">mode</span><span class="hl-1"> (</span><span class="hl-4">optional</span><span class="hl-1">)</span><br/><span class="hl-1"> β | βββ </span><span class="hl-4">backtest</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">mjs</span><span class="hl-1"> # </span><span class="hl-4">broker</span><span class="hl-1"> </span><span class="hl-4">adapter</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> --</span><span class="hl-4">backtest</span><span class="hl-1"> </span><span class="hl-0">mode</span><span class="hl-1"> (</span><span class="hl-4">optional</span><span class="hl-1">)</span><br/><span class="hl-1"> β βββ </span><span class="hl-4">template</span><span class="hl-1">/ # </span><span class="hl-4">custom</span><span class="hl-1"> </span><span class="hl-4">Mustache</span><span class="hl-1"> </span><span class="hl-0">templates</span><span class="hl-1"> (</span><span class="hl-4">optional</span><span class="hl-1">)</span><br/><span class="hl-1"> β βββ </span><span class="hl-4">dump</span><span class="hl-1">/ # </span><span class="hl-4">auto</span><span class="hl-1">-</span><span class="hl-10">created</span><span class="hl-1">: </span><span class="hl-4">candle</span><span class="hl-1"> </span><span class="hl-4">cache</span><span class="hl-1"> + </span><span class="hl-4">backtest</span><span class="hl-1"> </span><span class="hl-4">reports</span><br/><span class="hl-1"> βββ </span><span class="hl-4">dec_2025</span><span class="hl-1">/</span><br/><span class="hl-1"> βββ </span><span class="hl-4">index</span><span class="hl-1">.</span><span class="hl-4">mjs</span><br/><span class="hl-1"> βββ .</span><span class="hl-4">env</span><br/><span class="hl-1"> βββ </span><span class="hl-4">dump</span><span class="hl-1">/</span>
</code><button>Copy</button></pre>
<a id="root-packagejson" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Root <code>package.json</code><a href="#root-packagejson" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest:oct"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./strategies/oct_2025/index.mjs"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest:dec"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./strategies/dec_2025/index.mjs"</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-16">"dependencies"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"@backtest-kit/cli"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest-kit"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"ccxt"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">backtest:oct</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">backtest:dec</span>
</code><button type="button">Copy</button></pre>
<a id="isolated-resources-per-strategy" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Isolated Resources Per Strategy<a href="#isolated-resources-per-strategy" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Resource</th>
<th>Path (relative to strategy dir)</th>
<th>Isolated</th>
</tr>
</thead>
<tbody>
<tr>
<td>Candle cache</td>
<td><code>./dump/data/candle/</code></td>
<td>β
per-strategy</td>
</tr>
<tr>
<td>Backtest reports</td>
<td><code>./dump/</code></td>
<td>β
per-strategy</td>
</tr>
<tr>
<td>Broker module (live)</td>
<td><code>./modules/live.module.mjs</code></td>
<td>β
per-strategy</td>
</tr>
<tr>
<td>Broker module (paper)</td>
<td><code>./modules/paper.module.mjs</code></td>
<td>β
per-strategy</td>
</tr>
<tr>
<td>Broker module (backtest)</td>
<td><code>./modules/backtest.module.mjs</code></td>
<td>β
per-strategy</td>
</tr>
<tr>
<td>Config module (walker)</td>
<td><code>./modules/walker.module.mjs</code></td>
<td>β
loaded once</td>
</tr>
<tr>
<td>Telegram templates</td>
<td><code>./template/*.mustache</code></td>
<td>β
per-strategy</td>
</tr>
<tr>
<td>Environment variables</td>
<td><code>./.env</code> (overrides root)</td>
<td>β
per-strategy</td>
</tr>
</tbody>
</table>
<p>Each strategy run produces its own <code>dump/</code> directory, making it straightforward to compare results across time periods β both by inspection and by pointing an AI agent at a specific strategy folder.</p>
<a id="π-shared-import-aliases" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Shared Import Aliases<a href="#π-shared-import-aliases" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> automatically turns every <strong>top-level folder</strong> in <code>process.cwd()</code> into a bare import alias available inside any strategy file. No configuration needed β just create the folder.</p>
<a id="how-it-works-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link">How It Works<a href="#how-it-works-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>When the CLI loads a strategy file, it scans the current working directory for subdirectories and registers each one as an import alias. The alias name is the folder name. Both barrel imports and deep subpath imports are supported:</p>
<table>
<thead>
<tr>
<th>Import</th>
<th>Resolves to</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>import { fn } from "utils"</code></td>
<td><code><cwd>/utils/index.ts</code> (or <code>.js</code>, <code>.mjs</code>, <code>.cjs</code>)</td>
</tr>
<tr>
<td><code>import { calcRSI } from "math/rsi"</code></td>
<td><code><cwd>/math/rsi.ts</code></td>
</tr>
<tr>
<td><code>import { research } from "logic"</code></td>
<td><code><cwd>/logic/index.ts</code></td>
</tr>
<tr>
<td><code>import { ResearchResponseContract } from "logic/contract/ResearchResponse.contract"</code></td>
<td><code><cwd>/logic/contract/ResearchResponse.contract.ts</code></td>
</tr>
</tbody>
</table>
<a id="project-structure-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Project Structure<a href="#project-structure-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code><span class="hl-4">my</span><span class="hl-1">-</span><span class="hl-4">project</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">utils</span><span class="hl-1">/ β </span><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">formatDate</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"utils"</span><br/><span class="hl-1">β βββ </span><span class="hl-4">index</span><span class="hl-1">.</span><span class="hl-4">ts</span><br/><span class="hl-1">βββ </span><span class="hl-4">math</span><span class="hl-1">/ β </span><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">calcRSI</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"math/rsi"</span><br/><span class="hl-1">β βββ </span><span class="hl-4">rsi</span><span class="hl-1">.</span><span class="hl-4">ts</span><br/><span class="hl-1">βββ </span><span class="hl-4">logic</span><span class="hl-1">/ β </span><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">research</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"logic"</span><br/><span class="hl-1">β βββ </span><span class="hl-4">index</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-4">barrel</span><br/><span class="hl-1">β βββ </span><span class="hl-4">contract</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">ResearchResponse</span><span class="hl-1">.</span><span class="hl-4">contract</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-5">import</span><span class="hl-1"> { ... } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"logic/contract/ResearchResponse.contract"</span><br/><span class="hl-1">βββ </span><span class="hl-4">content</span><span class="hl-1">/</span><br/><span class="hl-1"> βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">strategy</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-4">uses</span><span class="hl-1"> </span><span class="hl-4">all</span><span class="hl-1"> </span><span class="hl-4">three</span><span class="hl-1"> </span><span class="hl-4">aliases</span><span class="hl-1"> </span><span class="hl-4">freely</span><br/><span class="hl-1"> βββ </span><span class="hl-4">mar_2026</span><span class="hl-1">.</span><span class="hl-4">strategy</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-4">same</span><span class="hl-1"> </span><span class="hl-4">aliases</span><span class="hl-1">, </span><span class="hl-4">no</span><span class="hl-1"> </span><span class="hl-4">duplication</span>
</code><button>Copy</button></pre>
<p>This lets you extract shared utilities, math helpers, or AI agent logic (e.g. <code>agent-swarm-kit</code> workflows) into named folders and reuse them across every strategy in the project without relative path hell.</p>
<a id="typescript-support" class="tsd-anchor"></a><h3 class="tsd-anchor-link">TypeScript Support<a href="#typescript-support" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Add a matching <code>paths</code> entry to your <code>tsconfig.json</code> so the editor resolves the aliases:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"compilerOptions"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"moduleResolution"</span><span class="hl-1">: </span><span class="hl-2">"bundler"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"paths"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"logic"</span><span class="hl-1">: [</span><span class="hl-2">"./logic/index.ts"</span><span class="hl-1">],</span><br/><span class="hl-1"> </span><span class="hl-16">"logic/*"</span><span class="hl-1">: [</span><span class="hl-2">"./logic/*"</span><span class="hl-1">],</span><br/><span class="hl-1"> </span><span class="hl-16">"math"</span><span class="hl-1">: [</span><span class="hl-2">"./math/index.ts"</span><span class="hl-1">],</span><br/><span class="hl-1"> </span><span class="hl-16">"math/*"</span><span class="hl-1">: [</span><span class="hl-2">"./math/*"</span><span class="hl-1">],</span><br/><span class="hl-1"> </span><span class="hl-16">"utils"</span><span class="hl-1">: [</span><span class="hl-2">"./utils/index.ts"</span><span class="hl-1">],</span><br/><span class="hl-1"> </span><span class="hl-16">"utils/*"</span><span class="hl-1">: [</span><span class="hl-2">"./utils/*"</span><span class="hl-1">]</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-16">"include"</span><span class="hl-1">: [</span><br/><span class="hl-1"> </span><span class="hl-2">"./logic"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"./math"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"./utils"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"./content"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"./modules"</span><span class="hl-1">,</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<a id="π-integrations" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Integrations<a href="#π-integrations" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="web-dashboard---ui" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Web Dashboard (<code>--ui</code>)<a href="#web-dashboard---ui" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Starts <code>@backtest-kit/ui</code> server. Access the interactive dashboard at:</p>
<pre><code><span class="hl-10">http</span><span class="hl-1">:</span><span class="hl-6">//localhost:60050</span>
</code><button>Copy</button></pre>
<p>Customize host/port via environment variables <code>CC_WWWROOT_HOST</code> and <code>CC_WWWROOT_PORT</code>.</p>
<a id="symbol-list-symbolconfig" class="tsd-anchor"></a><h4 class="tsd-anchor-link">Symbol List (<code>symbol.config</code>)<a href="#symbol-list-symbolconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>By default the UI shows all symbols from the exchange. To restrict or reorder the list, create a <code>config/symbol.config</code> file in your strategy directory (next to the entry point).</p>
<p><strong>Resolution order β first match wins:</strong></p>
<table>
<thead>
<tr>
<th>Priority</th>
<th>Path</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><code>{strategyDir}/config/symbol.config</code></td>
<td>per-strategy override (cwd after <code>chdir</code>)</td>
</tr>
<tr>
<td>2</td>
<td><code>{projectRoot}/config/symbol.config</code></td>
<td>project-root override (cwd where <code>npx</code> was invoked)</td>
</tr>
<tr>
<td>3</td>
<td><code>@backtest-kit/cli/config/symbol.config</code></td>
<td>built-in default shipped with the package</td>
</tr>
</tbody>
</table>
<p>Supported file formats (<code>.ts</code>, <code>.cjs</code>, <code>.mjs</code>, <code>.js</code> tried automatically):</p>
<pre><code class="ts"><span class="hl-6">// config/symbol.config.ts</span><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">symbol_list</span><span class="hl-1"> = [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">icon:</span><span class="hl-1"> </span><span class="hl-2">"/icon/btc.png"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">logo:</span><span class="hl-1"> </span><span class="hl-2">"/icon/128/btc.png"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">symbol:</span><span class="hl-1"> </span><span class="hl-2">"BTCUSDT"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">displayName:</span><span class="hl-1"> </span><span class="hl-2">"Bitcoin"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">color:</span><span class="hl-1"> </span><span class="hl-2">"#F7931A"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">priority:</span><span class="hl-1"> </span><span class="hl-7">50</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">description:</span><span class="hl-1"> </span><span class="hl-2">"Bitcoin - the first and most popular cryptocurrency"</span><span class="hl-1">,</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">icon:</span><span class="hl-1"> </span><span class="hl-2">"/icon/eth.png"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">logo:</span><span class="hl-1"> </span><span class="hl-2">"/icon/128/eth.png"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">symbol:</span><span class="hl-1"> </span><span class="hl-2">"ETHUSDT"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">displayName:</span><span class="hl-1"> </span><span class="hl-2">"Ethereum"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">color:</span><span class="hl-1"> </span><span class="hl-2">"#6F42C1"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">priority:</span><span class="hl-1"> </span><span class="hl-7">50</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">description:</span><span class="hl-1"> </span><span class="hl-2">"Ethereum - a blockchain platform for smart contracts"</span><span class="hl-1">,</span><br/><span class="hl-1"> },</span><br/><span class="hl-1">];</span>
</code><button type="button">Copy</button></pre>
<a id="notification-filter-notificationconfig" class="tsd-anchor"></a><h4 class="tsd-anchor-link">Notification Filter (<code>notification.config</code>)<a href="#notification-filter-notificationconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>Controls which notification categories are shown in the UI dashboard. Create a <code>config/notification.config</code> file in your strategy directory to override the defaults.</p>
<p><strong>Resolution order β first match wins:</strong></p>
<table>
<thead>
<tr>
<th>Priority</th>
<th>Path</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><code>{strategyDir}/config/notification.config</code></td>
<td>per-strategy override (cwd after <code>chdir</code>)</td>
</tr>
<tr>
<td>2</td>
<td><code>{projectRoot}/config/notification.config</code></td>
<td>project-root override (cwd where <code>npx</code> was invoked)</td>
</tr>
<tr>
<td>3</td>
<td><code>@backtest-kit/cli/config/notification.config</code></td>
<td>built-in default shipped with the package</td>
</tr>
</tbody>
</table>
<p><strong>Default values (built-in):</strong></p>
<table>
<thead>
<tr>
<th>Key</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>signal</code></td>
<td><code>true</code></td>
<td>Signal lifecycle: opened, scheduled, closed, cancelled</td>
</tr>
<tr>
<td><code>risk</code></td>
<td><code>true</code></td>
<td>Risk manager rejection notifications</td>
</tr>
<tr>
<td><code>info</code></td>
<td><code>true</code></td>
<td>Informational messages attached to an active signal</td>
</tr>
<tr>
<td><code>breakeven</code></td>
<td><code>true</code></td>
<td>Breakeven level reached</td>
</tr>
<tr>
<td><code>common_error</code></td>
<td><code>true</code></td>
<td>Non-fatal runtime errors</td>
</tr>
<tr>
<td><code>critical_error</code></td>
<td><code>true</code></td>
<td>Fatal errors that terminate the session</td>
</tr>
<tr>
<td><code>validation_error</code></td>
<td><code>true</code></td>
<td>Strategy config / input validation errors</td>
</tr>
<tr>
<td><code>strategy_commit</code></td>
<td><code>true</code></td>
<td>All committed actions (partial close, DCA, trailing, etc.)</td>
</tr>
<tr>
<td><code>partial_loss</code></td>
<td><code>false</code></td>
<td>Partial loss level reached (before commit)</td>
</tr>
<tr>
<td><code>partial_profit</code></td>
<td><code>false</code></td>
<td>Partial profit level reached (before commit)</td>
</tr>
<tr>
<td><code>signal_sync</code></td>
<td><code>false</code></td>
<td>Live order fill / exit confirmations from exchange sync</td>
</tr>
</tbody>
</table>
<pre><code class="js"><span class="hl-6">// config/notification.config.ts</span><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-5">default</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">signal:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">risk:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">info:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">breakeven:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">common_error:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">critical_error:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">validation_error:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">strategy_commit:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">partial_loss:</span><span class="hl-1"> </span><span class="hl-3">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">partial_profit:</span><span class="hl-1"> </span><span class="hl-3">false</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">signal_sync:</span><span class="hl-1"> </span><span class="hl-3">false</span><span class="hl-1">,</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<a id="telegram-notifications---telegram" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Telegram Notifications (<code>--telegram</code>)<a href="#telegram-notifications---telegram" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Sends formatted HTML messages with 1m / 15m / 1h price charts to your Telegram channel for every position event: opened, closed, scheduled, cancelled, risk rejection, partial profit/loss, trailing stop/take, and breakeven.</p>
<p>Requires <code>CC_TELEGRAM_TOKEN</code> and <code>CC_TELEGRAM_CHANNEL</code> in your environment.</p>
<a id="telegram-message-adapter-telegramconfig" class="tsd-anchor"></a><h4 class="tsd-anchor-link">Telegram Message Adapter (<code>telegram.config</code>)<a href="#telegram-message-adapter-telegramconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>By default messages are rendered from Mustache templates (<code>template/*.mustache</code>). To override rendering programmatically, create a <code>config/telegram.config</code> file and export an object with any subset of <code>get*Markdown</code> methods. Each method receives the event payload and must return a <code>Promise<string></code> with the Markdown message body.</p>
<p>Resolution order is the same as other configs (strategy dir β project root β package default).</p>
<pre><code class="ts"><span class="hl-6">// config/telegram.config.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">IStrategyTickResultOpened</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">IStrategyTickResultClosed</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">RiskContract</span><span class="hl-1">,</span><br/><span class="hl-1">} </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"backtest-kit"</span><span class="hl-1">;</span><br/><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-5">default</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">getOpenedMarkdown</span><span class="hl-1">(</span><span class="hl-4">event</span><span class="hl-1">: </span><span class="hl-11">IStrategyTickResultOpened</span><span class="hl-1">): </span><span class="hl-11">Promise</span><span class="hl-1"><</span><span class="hl-11">string</span><span class="hl-1">> {</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-2">`**Opened** </span><span class="hl-3">${</span><span class="hl-4">event</span><span class="hl-9">.</span><span class="hl-4">symbol</span><span class="hl-3">}</span><span class="hl-2"> at </span><span class="hl-3">${</span><span class="hl-4">event</span><span class="hl-9">.</span><span class="hl-4">priceOpen</span><span class="hl-3">}</span><span class="hl-2">`</span><span class="hl-1">;</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">getClosedMarkdown</span><span class="hl-1">(</span><span class="hl-4">event</span><span class="hl-1">: </span><span class="hl-11">IStrategyTickResultClosed</span><span class="hl-1">): </span><span class="hl-11">Promise</span><span class="hl-1"><</span><span class="hl-11">string</span><span class="hl-1">> {</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-2">`**Closed** </span><span class="hl-3">${</span><span class="hl-4">event</span><span class="hl-9">.</span><span class="hl-4">symbol</span><span class="hl-3">}</span><span class="hl-2"> at </span><span class="hl-3">${</span><span class="hl-4">event</span><span class="hl-9">.</span><span class="hl-4">priceClosed</span><span class="hl-3">}</span><span class="hl-2">`</span><span class="hl-1">;</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">getRiskMarkdown</span><span class="hl-1">(</span><span class="hl-4">event</span><span class="hl-1">: </span><span class="hl-11">RiskContract</span><span class="hl-1">): </span><span class="hl-11">Promise</span><span class="hl-1"><</span><span class="hl-11">string</span><span class="hl-1">> {</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-2">`**Risk rejected** </span><span class="hl-3">${</span><span class="hl-4">event</span><span class="hl-9">.</span><span class="hl-4">symbol</span><span class="hl-3">}</span><span class="hl-2">`</span><span class="hl-1">;</span><br/><span class="hl-1"> },</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<p>All methods are optional β unimplemented ones fall back to the Mustache template.</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Event type</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>getOpenedMarkdown</code></td>
<td><code>IStrategyTickResultOpened</code></td>
</tr>
<tr>
<td><code>getClosedMarkdown</code></td>
<td><code>IStrategyTickResultClosed</code></td>
</tr>
<tr>
<td><code>getScheduledMarkdown</code></td>
<td><code>IStrategyTickResultScheduled</code></td>
</tr>
<tr>
<td><code>getCancelledMarkdown</code></td>
<td><code>IStrategyTickResultCancelled</code></td>
</tr>
<tr>
<td><code>getRiskMarkdown</code></td>
<td><code>RiskContract</code></td>
</tr>
<tr>
<td><code>getPartialProfitMarkdown</code></td>
<td><code>PartialProfitCommit</code></td>
</tr>
<tr>
<td><code>getPartialLossMarkdown</code></td>
<td><code>PartialLossCommit</code></td>
</tr>
<tr>
<td><code>getBreakevenMarkdown</code></td>
<td><code>BreakevenCommit</code></td>
</tr>
<tr>
<td><code>getTrailingTakeMarkdown</code></td>
<td><code>TrailingTakeCommit</code></td>
</tr>
<tr>
<td><code>getTrailingStopMarkdown</code></td>
<td><code>TrailingStopCommit</code></td>
</tr>
<tr>
<td><code>getAverageBuyMarkdown</code></td>
<td><code>AverageBuyCommit</code></td>
</tr>
<tr>
<td><code>getSignalOpenMarkdown</code></td>
<td><code>SignalOpenContract</code></td>
</tr>
<tr>
<td><code>getSignalCloseMarkdown</code></td>
<td><code>SignalCloseContract</code></td>
</tr>
<tr>
<td><code>getCancelScheduledMarkdown</code></td>
<td><code>CancelScheduledCommit</code></td>
</tr>
<tr>
<td><code>getClosePendingMarkdown</code></td>
<td><code>ClosePendingCommit</code></td>
</tr>
<tr>
<td><code>getSignalInfoMarkdown</code></td>
<td><code>SignalInfoContract</code></td>
</tr>
</tbody>
</table>
<a id="π§©-module-hooks-broker-adapter" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π§© Module Hooks (Broker Adapter)<a href="#π§©-module-hooks-broker-adapter" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The CLI supports <strong>mode-specific module files</strong> that are loaded as side-effect imports before the strategy starts. Each file is expected to call <code>Broker.useBrokerAdapter()</code> from <code>backtest-kit</code> to register a broker adapter.</p>
<table>
<thead>
<tr>
<th>Command Line Args</th>
<th>Module file</th>
<th>Loaded before</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--live</code></td>
<td><code>./modules/live.module.mjs</code></td>
<td><code>Live.background()</code></td>
</tr>
<tr>
<td><code>--paper</code></td>
<td><code>./modules/paper.module.mjs</code></td>
<td><code>Live.background()</code> (paper)</td>
</tr>
<tr>
<td><code>--backtest</code></td>
<td><code>./modules/backtest.module.mjs</code></td>
<td><code>Backtest.background()</code></td>
</tr>
<tr>
<td><code>--walker</code></td>
<td><code>./modules/walker.module.mjs</code></td>
<td><code>Walker.background()</code></td>
</tr>
<tr>
<td><code>--brokerdebug</code></td>
<td><code>./modules/brokerdebug.module.mjs</code></td>
<td>broker commit test</td>
</tr>
</tbody>
</table>
<blockquote>
<p>File is resolved relative to <code>cwd</code> (the strategy directory). All of <code>.mjs</code>, <code>.cjs</code>, <code>.ts</code> extensions are tried automatically. Missing module is a soft warning β not an error.</p>
</blockquote>
<a id="how-it-works-2" class="tsd-anchor"></a><h3 class="tsd-anchor-link">How It Works<a href="#how-it-works-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The module file is a side-effect import. When the CLI loads it, your code runs and registers the adapter. From that point on, <code>backtest-kit</code> intercepts every trade-mutating call through the adapter <strong>before</strong> updating internal state β if the adapter throws, the position state is never changed.</p>
<pre><code class="javascript"><span class="hl-6">// live.module.mjs</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">Broker</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'backtest-kit'</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">myExchange</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'./exchange.mjs'</span><span class="hl-1">;</span><br/><br/><span class="hl-3">class</span><span class="hl-1"> </span><span class="hl-11">MyBroker</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onSignalOpenCommit</span><span class="hl-1">({ </span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">priceOpen</span><span class="hl-1">, </span><span class="hl-4">direction</span><span class="hl-1"> }) {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">myExchange</span><span class="hl-1">.</span><span class="hl-0">openPosition</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">direction</span><span class="hl-1">, </span><span class="hl-4">priceOpen</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onSignalCloseCommit</span><span class="hl-1">({ </span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">priceClosed</span><span class="hl-1"> }) {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">myExchange</span><span class="hl-1">.</span><span class="hl-0">closePosition</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">priceClosed</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onPartialProfitCommit</span><span class="hl-1">({ </span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">cost</span><span class="hl-1">, </span><span class="hl-4">currentPrice</span><span class="hl-1"> }) {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">myExchange</span><span class="hl-1">.</span><span class="hl-0">createOrder</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">symbol</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">side:</span><span class="hl-1"> </span><span class="hl-2">'sell'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">quantity:</span><span class="hl-1"> </span><span class="hl-4">cost</span><span class="hl-1"> / </span><span class="hl-4">currentPrice</span><span class="hl-1">,</span><br/><span class="hl-1"> });</span><br/><span class="hl-1"> }</span><br/><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onAverageBuyCommit</span><span class="hl-1">({ </span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">cost</span><span class="hl-1">, </span><span class="hl-4">currentPrice</span><span class="hl-1"> }) {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">myExchange</span><span class="hl-1">.</span><span class="hl-0">createOrder</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">symbol</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">side:</span><span class="hl-1"> </span><span class="hl-2">'buy'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">quantity:</span><span class="hl-1"> </span><span class="hl-4">cost</span><span class="hl-1"> / </span><span class="hl-4">currentPrice</span><span class="hl-1">,</span><br/><span class="hl-1"> });</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-4">Broker</span><span class="hl-1">.</span><span class="hl-0">useBrokerAdapter</span><span class="hl-1">(</span><span class="hl-4">MyBroker</span><span class="hl-1">);</span><br/><br/><span class="hl-4">Broker</span><span class="hl-1">.</span><span class="hl-0">enable</span><span class="hl-1">();</span>
</code><button type="button">Copy</button></pre>
<a id="available-broker-hooks" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Available Broker Hooks<a href="#available-broker-hooks" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Method</th>
<th>Payload type</th>
<th>Triggered on</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>onSignalOpenCommit</code></td>
<td><code>BrokerSignalOpenPayload</code></td>
<td>Position activation</td>
</tr>
<tr>
<td><code>onSignalCloseCommit</code></td>
<td><code>BrokerSignalClosePayload</code></td>
<td>SL / TP / manual close</td>
</tr>
<tr>
<td><code>onPartialProfitCommit</code></td>
<td><code>BrokerPartialProfitPayload</code></td>
<td>PP</td>
</tr>
<tr>
<td><code>onPartialLossCommit</code></td>
<td><code>BrokerPartialLossPayload</code></td>
<td>PL</td>
</tr>
<tr>
<td><code>onTrailingStopCommit</code></td>
<td><code>BrokerTrailingStopPayload</code></td>
<td>SL adjustment</td>
</tr>
<tr>
<td><code>onTrailingTakeCommit</code></td>
<td><code>BrokerTrailingTakePayload</code></td>
<td>TP adjustment</td>
</tr>
<tr>
<td><code>onBreakevenCommit</code></td>
<td><code>BrokerBreakevenPayload</code></td>
<td>SL moved to entry</td>
</tr>
<tr>
<td><code>onAverageBuyCommit</code></td>
<td><code>BrokerAverageBuyPayload</code></td>
<td>DCA entry</td>
</tr>
</tbody>
</table>
<p>All methods are optional. Unimplemented hooks are silently skipped. In backtest mode all broker calls are skipped automatically β no adapter code runs during backtests.</p>
<a id="typescript" class="tsd-anchor"></a><h3 class="tsd-anchor-link">TypeScript<a href="#typescript" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">Broker</span><span class="hl-1">, </span><span class="hl-4">IBroker</span><span class="hl-1">, </span><span class="hl-4">BrokerSignalOpenPayload</span><span class="hl-1">, </span><span class="hl-4">BrokerSignalClosePayload</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'backtest-kit'</span><span class="hl-1">;</span><br/><br/><span class="hl-3">class</span><span class="hl-1"> </span><span class="hl-11">MyBroker</span><span class="hl-1"> </span><span class="hl-3">implements</span><span class="hl-1"> </span><span class="hl-11">Partial</span><span class="hl-1"><</span><span class="hl-11">IBroker</span><span class="hl-1">> {</span><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onSignalOpenCommit</span><span class="hl-1">(</span><span class="hl-4">payload</span><span class="hl-1">: </span><span class="hl-11">BrokerSignalOpenPayload</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-6">// place open order on exchange</span><br/><span class="hl-1"> }</span><br/><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onSignalCloseCommit</span><span class="hl-1">(</span><span class="hl-4">payload</span><span class="hl-1">: </span><span class="hl-11">BrokerSignalClosePayload</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-6">// place close order on exchange</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-4">Broker</span><span class="hl-1">.</span><span class="hl-0">useBrokerAdapter</span><span class="hl-1">(</span><span class="hl-4">MyBroker</span><span class="hl-1">);</span><br/><br/><span class="hl-4">Broker</span><span class="hl-1">.</span><span class="hl-0">enable</span><span class="hl-1">();</span>
</code><button type="button">Copy</button></pre>
<a id="βοΈ-setup-hook-configsetupconfig" class="tsd-anchor"></a><h2 class="tsd-anchor-link">βοΈ Setup Hook (<code>config/setup.config</code>)<a href="#βοΈ-setup-hook-configsetupconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> loads a <code>{projectRoot}/config/setup.config</code> file once before any module hooks or strategy code run. Use it to perform one-time initialization that must happen before the first persistence call β registering a custom storage backend, configuring a logger, seeding global state, or anything else the process needs before <code>backtest-kit</code> starts.</p>
<p><strong>Important:</strong> When <code>setup.config</code> is present, the CLI skips its own default adapter registration β it does <strong>not</strong> call <code>usePersist()</code> / <code>useLocal()</code> / <code>useMemory()</code> for any of the persistence slots. This means your config takes full ownership of the persistence layer: whatever adapters you register in <code>{projectRoot}/config/setup.config</code> are the ones <code>backtest-kit</code> uses, with no interference from the CLI defaults.</p>
<a id="example-mongodb--redis-persistence-via-backtest-kitmongo" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Example: MongoDB + Redis persistence via <code>@backtest-kit/mongo</code><a href="#example-mongodb--redis-persistence-via-backtest-kitmongo" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The most common use-case is swapping the default file-based persistence for a production-grade backend. Install <code>@backtest-kit/mongo</code> and call <code>setup()</code> β it registers all 15 persistence adapters in one call and reads connection parameters from environment variables:</p>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/mongo</span>
</code><button type="button">Copy</button></pre>
<pre><code class="ts"><span class="hl-6">// config/setup.config.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">setup</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/mongo'</span><span class="hl-1">;</span><br/><br/><span class="hl-0">setup</span><span class="hl-1">();</span>
</code><button type="button">Copy</button></pre>
<pre><code class="env"># .env
CC_MONGO_CONNECTION_STRING=mongodb://localhost:27017/backtest-kit
CC_REDIS_HOST=127.0.0.1
CC_REDIS_PORT=6379
</code><button type="button">Copy</button></pre>
<p>Or pass connection parameters explicitly:</p>
<pre><code class="ts"><span class="hl-6">// config/setup.config.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">setup</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/mongo'</span><span class="hl-1">;</span><br/><br/><span class="hl-0">setup</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">CC_MONGO_CONNECTION_STRING:</span><span class="hl-1"> </span><span class="hl-2">'mongodb://mongo:27017/mydb'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">CC_REDIS_HOST:</span><span class="hl-1"> </span><span class="hl-2">'redis'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">CC_REDIS_PORT:</span><span class="hl-1"> </span><span class="hl-7">6379</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">CC_REDIS_PASSWORD:</span><span class="hl-1"> </span><span class="hl-2">'secret'</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>No changes to strategy code are needed β <code>setup()</code> wires up the adapters transparently before <code>backtest-kit</code> makes its first persistence call.</p>
<a id="π§©-module-loader-configloaderconfig" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π§© Module Loader (<code>config/loader.config</code>)<a href="#π§©-module-loader-configloaderconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> loads a <code>{projectRoot}/config/loader.config</code> file <strong>after</strong> <code>setup.config</code> but <strong>before</strong> any strategy or module code runs. Unlike <code>setup.config</code> (which is loaded for its side effects), <code>loader.config</code> exports a function that the CLI explicitly <code>await</code>s. Use it whenever you need to <strong>wait for an async dependency</strong> to be ready before the backtest starts.</p>
<pre><code class="bash"><span class="hl-0">monorepo/</span><br/><span class="hl-0">βββ</span><span class="hl-1"> </span><span class="hl-2">packages/</span><br/><span class="hl-0">β</span><span class="hl-1"> </span><span class="hl-2">βββ</span><span class="hl-1"> </span><span class="hl-2">shared-broker/</span><span class="hl-1"> </span><span class="hl-6"># shared broker code</span><br/><span class="hl-0">β</span><span class="hl-1"> </span><span class="hl-2">βββ</span><span class="hl-1"> </span><span class="hl-2">shared-signals/</span><span class="hl-1"> </span><span class="hl-6"># common indicators (RSI, MACD)</span><br/><span class="hl-0">β</span><span class="hl-1"> </span><span class="hl-2">βββ</span><span class="hl-1"> </span><span class="hl-2">shared-db/</span><span class="hl-1"> </span><span class="hl-6"># mongodb wiring</span><br/><span class="hl-0">β</span><span class="hl-1"> </span><span class="hl-2">βββ</span><span class="hl-1"> </span><span class="hl-2">strategy-momentum/</span><span class="hl-1"> </span><span class="hl-6"># strategy code</span><br/><span class="hl-0">β</span><span class="hl-1"> </span><span class="hl-2">βββ</span><span class="hl-1"> </span><span class="hl-2">strategy-mean-reversion/</span>
</code><button type="button">Copy</button></pre>
<p><strong>When to use it:</strong></p>
<ul>
<li><strong>Wire microfrontends in a monorepo</strong> β resolve and pre-load sibling packages, register cross-package services, or hydrate a shared DI container before strategies import from neighboring workspaces.</li>
<li><strong>Wait for a database connection</strong> β open a Mongo/Postgres/Redis connection and verify it's reachable before the first persistence call, so the backtest fails fast instead of mid-run.</li>
<li><strong>Warm up caches or external APIs</strong> β pre-fetch reference data (instruments list, calendar, fee tables) so the strategy's first tick doesn't pay the round-trip cost.</li>
<li><strong>Run schema migrations</strong> β apply any pending migrations to the persistence backend before signals start flowing.</li>
</ul>
<p><code>loader.config</code> supports exactly one of two export styles β <strong>never both at once</strong>. If both are present, the <code>default</code> export wins and the named <code>loader</code> is ignored.</p>
<pre><code class="ts"><span class="hl-6">// config/loader.config.ts β default export (preferred, ESM style)</span><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-5">default</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> () </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">mongoose</span><span class="hl-1">.</span><span class="hl-0">connect</span><span class="hl-1">(</span><span class="hl-4">process</span><span class="hl-1">.</span><span class="hl-4">env</span><span class="hl-1">.</span><span class="hl-8">CC_MONGO_CONNECTION_STRING</span><span class="hl-1">!);</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">redis</span><span class="hl-1">.</span><span class="hl-0">ping</span><span class="hl-1">();</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<pre><code class="ts"><span class="hl-6">// config/loader.config.ts β named export</span><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-0">loader</span><span class="hl-1"> = </span><span class="hl-3">async</span><span class="hl-1"> () </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">mongoose</span><span class="hl-1">.</span><span class="hl-0">connect</span><span class="hl-1">(</span><span class="hl-4">process</span><span class="hl-1">.</span><span class="hl-4">env</span><span class="hl-1">.</span><span class="hl-8">CC_MONGO_CONNECTION_STRING</span><span class="hl-1">!);</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">redis</span><span class="hl-1">.</span><span class="hl-0">ping</span><span class="hl-1">();</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<a id="example-wait-for-mongodb-before-running-a-backtest" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Example: wait for MongoDB before running a backtest<a href="#example-wait-for-mongodb-before-running-a-backtest" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p><code>@backtest-kit/mongo</code>'s <code>setup()</code> registers the adapters synchronously but doesn't block until the connection is established. If your backtest depends on data that must be present in Mongo before the first signal fires, use <code>loader.config</code> to gate the run on a real connection:</p>
<pre><code class="ts"><span class="hl-6">// config/setup.config.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">setup</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/mongo'</span><span class="hl-1">;</span><br/><br/><span class="hl-0">setup</span><span class="hl-1">();</span>
</code><button type="button">Copy</button></pre>
<pre><code class="ts"><span class="hl-6">// config/loader.config.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">mongoose</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'mongoose'</span><span class="hl-1">;</span><br/><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-5">default</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> () </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">mongoose</span><span class="hl-1">.</span><span class="hl-0">connect</span><span class="hl-1">(</span><span class="hl-4">process</span><span class="hl-1">.</span><span class="hl-4">env</span><span class="hl-1">.</span><span class="hl-8">CC_MONGO_CONNECTION_STRING</span><span class="hl-1">!);</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">'mongo connection verified, starting backtest'</span><span class="hl-1">);</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<a id="example-stitch-microfrontends-in-a-monorepo" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Example: stitch microfrontends in a monorepo<a href="#example-stitch-microfrontends-in-a-monorepo" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>When <code>backtest-kit</code> strategies live in one workspace and shared services (broker adapters, signal feeds, dashboards) live in sibling workspaces, <code>loader.config</code> is the place to wire them together before the runner starts:</p>
<pre><code class="ts"><span class="hl-6">// config/loader.config.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-2">"@my-org/brokers"</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-2">"@my-org/signals"</span><span class="hl-1">;</span>
</code><button type="button">Copy</button></pre>
<p>The <code>@my-org</code> alias should be declared in <code>config/alias.config</code>.</p>
<a id="π-import-aliases-configaliasconfig" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Import Aliases (<code>config/alias.config</code>)<a href="#π-import-aliases-configaliasconfig" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> lets you override any nodejs module import β without touching the strategy code. Drop a <code>config/alias.config</code> file in your project root and export a mapping from module name to replacement module.</p>
<p>The alias table is loaded once (on the first <code>import</code> call) from <code>{projectRoot}/config/alias.config</code> and applied globally to every subsequent module load via <code>require</code>/ <code>import</code>.</p>
<p><strong>Use cases:</strong></p>
<ul>
<li>Replace a heavy dependency with a lighter stub for backtesting</li>
<li>Swap any external api for a mock during CI runs</li>
</ul>
<pre><code class="ts"><span class="hl-6">// config/alias.config.ts β named export</span><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ccxt</span><span class="hl-1"> = </span><span class="hl-0">require</span><span class="hl-1">(</span><span class="hl-2">"./stubs/ccxt.stub.cjs"</span><span class="hl-1">);</span>
</code><button type="button">Copy</button></pre>
<pre><code class="js"><span class="hl-6">// config/alias.config.cjs β default export</span><br/><span class="hl-11">module</span><span class="hl-1">.</span><span class="hl-11">exports</span><span class="hl-1"> = {</span><br/><span class="hl-1"> </span><span class="hl-4">ccxt:</span><span class="hl-1"> </span><span class="hl-0">require</span><span class="hl-1">(</span><span class="hl-2">"./stubs/ccxt.stub.cjs"</span><span class="hl-1">),</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<pre><code class="js"><span class="hl-6">// config/alias.config.mjs β default export</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxtStub</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"./stubs/ccxt.stub.mjs"</span><span class="hl-1">;</span><br/><br/><span class="hl-5">export</span><span class="hl-1"> </span><span class="hl-5">default</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">ccxt:</span><span class="hl-1"> </span><span class="hl-4">ccxtStub</span><span class="hl-1">,</span><br/><span class="hl-1">};</span>
</code><button type="button">Copy</button></pre>
<p><strong>How it works:</strong> when strategy code calls <code>require("ccxt")</code>, the loader checks <code>IMPORT_ALIAS</code> first. If a key matches, the mapped value is returned instead of the real module β no monkey-patching of <code>node_modules</code> needed.</p>
<p><strong>Important:</strong> It is <strong>not</strong> per-strategy β it applies to all modules loaded in the current process.</p>
<a id="π¦-supported-entry-point-formats" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π¦ Supported Entry Point Formats<a href="#π¦-supported-entry-point-formats" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> automatically detects the format of your strategy file and loads it with the appropriate runtime β no flags or configuration required.</p>
<table>
<thead>
<tr>
<th>Format</th>
<th>Extension</th>
<th>Runtime</th>
<th>Use Case</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>TypeScript</strong></td>
<td><code>.ts</code></td>
<td><a href="https://tsx.is/"><code>tsx</code></a> via <code>tsImport()</code></td>
<td>TypeScript strategies with cross-imports (ESM β CJS)</td>
</tr>
<tr>
<td><strong>ES Module</strong></td>
<td><code>.mjs</code></td>
<td>Native <code>import()</code></td>
<td>Modern JavaScript with top-level <code>await</code> and ESM syntax</td>
</tr>
<tr>
<td><strong>CommonJS</strong></td>
<td><code>.cjs</code></td>
<td>Native <code>require()</code></td>
<td>Legacy or dual-package strategies</td>
</tr>
</tbody>
</table>
<a id="typescript-ts" class="tsd-anchor"></a><h3 class="tsd-anchor-link">TypeScript (<code>.ts</code>)<a href="#typescript-ts" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Run TypeScript strategy files directly β no <code>tsc</code> compilation step needed. Powered by <code>tsx</code>, which handles cross-format imports transparently:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./src/index.ts"</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-16">"dependencies"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"@backtest-kit/cli"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest-kit"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-16">"tsx"</span><span class="hl-1">: </span><span class="hl-2">"latest"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<a id="es-module-mjs" class="tsd-anchor"></a><h3 class="tsd-anchor-link">ES Module (<code>.mjs</code>)<a href="#es-module-mjs" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Standard ESM format. Supports top-level <code>await</code>, named exports, and <code>import</code> syntax:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./src/index.mjs"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<a id="commonjs-cjs" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CommonJS (<code>.cjs</code>)<a href="#commonjs-cjs" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>For projects that compile to or use CommonJS. Loaded via <code>require()</code>:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest ./dist/index.cjs"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<a id="π²-running-local-pinescript-indicators" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π² Running Local PineScript Indicators<a href="#π²-running-local-pinescript-indicators" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> can execute any local <code>.pine</code> file against a real exchange and print the results as a Markdown table β no TradingView account required.</p>
<a id="cli-flags" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--pine</code></td>
<td>boolean</td>
<td>Enable PineScript execution mode</td>
</tr>
<tr>
<td><code>--symbol</code></td>
<td>string</td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>--timeframe</code></td>
<td>string</td>
<td>Candle interval (default: <code>"15m"</code>)</td>
</tr>
<tr>
<td><code>--limit</code></td>
<td>string</td>
<td>Number of candles to fetch (default: <code>250</code>)</td>
</tr>
<tr>
<td><code>--when</code></td>
<td>string</td>
<td>End date for candle window β ISO 8601 or Unix ms (default: now)</td>
</tr>
<tr>
<td><code>--exchange</code></td>
<td>string</td>
<td>Exchange name (default: first registered, falls back to CCXT Binance)</td>
</tr>
<tr>
<td><code>--output</code></td>
<td>string</td>
<td>Output file base name without extension (default: <code>.pine</code> file name)</td>
</tr>
<tr>
<td><code>--json</code></td>
<td>boolean</td>
<td>Write plots as a JSON array to <code><pine-dir>/dump/{output}.json</code></td>
</tr>
<tr>
<td><code>--jsonl</code></td>
<td>boolean</td>
<td>Write plots as JSONL (one row per line) to <code><pine-dir>/dump/{output}.jsonl</code></td>
</tr>
<tr>
<td><code>--markdown</code></td>
<td>boolean</td>
<td>Write Markdown table to <code><pine-dir>/dump/{output}.md</code></td>
</tr>
</tbody>
</table>
<p><strong>Important:</strong> <code>limit</code> must cover indicator warmup bars β rows before warmup completes will show <code>N/A</code></p>
<p><strong>Positional argument:</strong> path to the <code>.pine</code> file.</p>
<a id="exchange-via-pinemodule" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Exchange via <code>pine.module</code><a href="#exchange-via-pinemodule" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>By default the CLI registers CCXT Binance automatically. To use a different exchange β or to configure API keys, custom rate limits, or a non-spot market β create a <code>modules/pine.module.ts</code> file. The CLI loads it automatically before running the script.</p>
<p>The CLI looks for <code>modules/pine.module</code> in two locations (first match wins):</p>
<ol>
<li><strong>Next to the <code>.pine</code> file</strong> β <code><pine-file-dir>/modules/pine.module.ts</code></li>
<li><strong>Project root</strong> β <code><cwd>/modules/pine.module.ts</code></li>
</ol>
<pre><code><span class="hl-4">my</span><span class="hl-1">-</span><span class="hl-4">project</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">math</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">impulse_trend_15m</span><span class="hl-1">.</span><span class="hl-4">pine</span><span class="hl-1"> β </span><span class="hl-4">indicator</span><br/><span class="hl-1">β βββ </span><span class="hl-4">modules</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">pine</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-4">loaded</span><span class="hl-1"> </span><span class="hl-0">first</span><span class="hl-1"> (</span><span class="hl-4">next</span><span class="hl-1"> </span><span class="hl-4">to</span><span class="hl-1"> .</span><span class="hl-4">pine</span><span class="hl-1"> </span><span class="hl-4">file</span><span class="hl-1">)</span><br/><span class="hl-1">βββ </span><span class="hl-4">modules</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">pine</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-0">fallback</span><span class="hl-1"> (</span><span class="hl-4">project</span><span class="hl-1"> </span><span class="hl-4">root</span><span class="hl-1">)</span><br/><span class="hl-1">βββ </span><span class="hl-4">package</span><span class="hl-1">.</span><span class="hl-4">json</span>
</code><button>Copy</button></pre>
<p>Inside <code>pine.module.ts</code> call <code>addExchangeSchema</code> from <code>backtest-kit</code> and give the exchange a name:</p>
<pre><code class="typescript"><span class="hl-6">// modules/pine.module.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">addExchangeSchema</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"backtest-kit"</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"ccxt"</span><span class="hl-1">;</span><br/><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"my-exchange"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">bybit</span><span class="hl-1">({ </span><span class="hl-4">enableRateLimit:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ohlcv</span><span class="hl-1"> = </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">.</span><span class="hl-0">fetchOHLCV</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">.</span><span class="hl-0">getTime</span><span class="hl-1">(), </span><span class="hl-4">limit</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-4">ohlcv</span><span class="hl-1">.</span><span class="hl-0">map</span><span class="hl-1">(([</span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">]) </span><span class="hl-3">=></span><span class="hl-1"> ({</span><br/><span class="hl-1"> </span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">,</span><br/><span class="hl-1"> }));</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-0">formatPrice</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">price</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">2</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">formatQuantity</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">quantity</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">quantity</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">8</span><span class="hl-1">),</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<a id="environment-variables-env" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Environment variables (<code>.env</code>)<a href="#environment-variables-env" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Before loading <code>pine.module</code>, the CLI loads <code>.env</code> files in the same order as for strategy modules β project root first, then the <code>.pine</code> file directory (overrides root):</p>
<pre><code><span class="hl-4">my</span><span class="hl-1">-</span><span class="hl-4">project</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">math</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ .</span><span class="hl-4">env</span><span class="hl-1"> β </span><span class="hl-4">loaded</span><span class="hl-1"> </span><span class="hl-0">second</span><span class="hl-1"> (</span><span class="hl-4">overrides</span><span class="hl-1"> </span><span class="hl-4">root</span><span class="hl-1">)</span><br/><span class="hl-1">β βββ </span><span class="hl-4">impulse_trend_15m</span><span class="hl-1">.</span><span class="hl-4">pine</span><br/><span class="hl-1">βββ .</span><span class="hl-4">env</span><span class="hl-1"> β </span><span class="hl-4">loaded</span><span class="hl-1"> </span><span class="hl-4">first</span><br/><span class="hl-1">βββ </span><span class="hl-4">package</span><span class="hl-1">.</span><span class="hl-4">json</span>
</code><button>Copy</button></pre>
<p>Use this to store API keys without hardcoding them:</p>
<pre><code class="env"># .env
BYBIT_API_KEY=xxx
BYBIT_API_SECRET=yyy
</code><button type="button">Copy</button></pre>
<pre><code class="typescript"><span class="hl-6">// modules/pine.module.ts</span><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"my-exchange"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">bybit</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">apiKey:</span><span class="hl-1"> </span><span class="hl-4">process</span><span class="hl-1">.</span><span class="hl-4">env</span><span class="hl-1">.</span><span class="hl-8">BYBIT_API_KEY</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">secret:</span><span class="hl-1"> </span><span class="hl-4">process</span><span class="hl-1">.</span><span class="hl-4">env</span><span class="hl-1">.</span><span class="hl-8">BYBIT_API_SECRET</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">enableRateLimit:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-6">// ...</span><br/><span class="hl-1"> },</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>Then run:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pine</span><span class="hl-1"> </span><span class="hl-2">./math/impulse_trend_15m.pine</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--exchange</span><span class="hl-1"> </span><span class="hl-2">my-exchange</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--timeframe</span><span class="hl-1"> </span><span class="hl-2">15m</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--limit</span><span class="hl-1"> </span><span class="hl-7">180</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--when</span><span class="hl-1"> </span><span class="hl-2">"2025-09-24T12:00:00.000Z"</span>
</code><button type="button">Copy</button></pre>
<p>Or add it to <code>package.json</code>:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"pine"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --pine ./math/impulse_trend_15m.pine --symbol BTCUSDT --timeframe 15m --limit 180"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">pine</span>
</code><button type="button">Copy</button></pre>
<a id="pinescript-requirements" class="tsd-anchor"></a><h3 class="tsd-anchor-link">PineScript Requirements<a href="#pinescript-requirements" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The CLI reads all <code>plot()</code> calls that use <code>display=display.data_window</code> as output columns. Every other <code>plot()</code> is ignored. Name each output plot explicitly:</p>
<pre><code class="pine">//@version=5
indicator("MyIndicator", overlay=true)
// ... computation ...
plot(close, "Close", display=display.data_window)
plot(position, "Position", display=display.data_window)
</code><button type="button">Copy</button></pre>
<p>The column names in the output Markdown table are taken directly from those plot names β no manual schema definition needed.</p>
<a id="output" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Output<a href="#output" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The CLI prints a Markdown table to stdout:</p>
<pre><code><span class="hl-1"># </span><span class="hl-4">PineScript</span><span class="hl-1"> </span><span class="hl-4">Technical</span><span class="hl-1"> </span><span class="hl-4">Analysis</span><span class="hl-1"> </span><span class="hl-4">Dump</span><br/><br/><span class="hl-1">**</span><span class="hl-4">Signal</span><span class="hl-1"> </span><span class="hl-8">ID</span><span class="hl-1">**: </span><span class="hl-8">CLI</span><span class="hl-1"> </span><span class="hl-4">execution</span><span class="hl-1"> </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">09</span><span class="hl-1">-24</span><span class="hl-10">T12</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><br/><br/><span class="hl-1">| </span><span class="hl-4">Close</span><span class="hl-1"> | </span><span class="hl-4">Position</span><span class="hl-1"> | </span><span class="hl-4">timestamp</span><span class="hl-1"> |</span><br/><span class="hl-1">| --- | --- | --- |</span><br/><span class="hl-1">| </span><span class="hl-7">112871.28</span><span class="hl-1"> | -</span><span class="hl-7">1.0000</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">09</span><span class="hl-1">-22</span><span class="hl-10">T15</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> |</span><br/><span class="hl-1">| </span><span class="hl-7">112666.69</span><span class="hl-1"> | -</span><span class="hl-7">1.0000</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">09</span><span class="hl-1">-22</span><span class="hl-10">T15</span><span class="hl-1">:</span><span class="hl-7">15</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> |</span><br/><span class="hl-1">| </span><span class="hl-7">112736.00</span><span class="hl-1"> | </span><span class="hl-7">0.0000</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">09</span><span class="hl-1">-22</span><span class="hl-10">T18</span><span class="hl-1">:</span><span class="hl-7">30</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> |</span><br/><span class="hl-1">| </span><span class="hl-7">112653.90</span><span class="hl-1"> | </span><span class="hl-7">1.0000</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">09</span><span class="hl-1">-22</span><span class="hl-10">T22</span><span class="hl-1">:</span><span class="hl-7">15</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> |</span>
</code><button>Copy</button></pre>
<p>Save to <code>./math/dump/impulse_trend_15m.md</code> (uses <code>.pine</code> file name automatically, dump is created next to the <code>.pine</code> file):</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pine</span><span class="hl-1"> </span><span class="hl-2">./math/impulse_trend_15m.pine</span><span class="hl-1"> </span><span class="hl-3">--markdown</span>
</code><button type="button">Copy</button></pre>
<p>Override the output name with <code>--output</code>:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pine</span><span class="hl-1"> </span><span class="hl-2">./math/impulse_trend_15m.pine</span><span class="hl-1"> </span><span class="hl-3">--jsonl</span><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">feb2026_bb</span><br/><span class="hl-6"># β ./math/dump/feb2026_bb.jsonl</span>
</code><button type="button">Copy</button></pre>
<p>Print to stdout (no flag):</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pine</span><span class="hl-1"> </span><span class="hl-2">./math/impulse_trend_15m.pine</span>
</code><button type="button">Copy</button></pre>
<a id="π¨-visual-pine-script-editor" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π¨ Visual Pine Script Editor<a href="#π¨-visual-pine-script-editor" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><img src="https://raw.githubusercontent.com/tripolskypetr/backtest-kit/HEAD/assets/screenshots/screenshot32.png" alt="pine"></p>
<p><code>@backtest-kit/cli</code> ships a browser-based Pine Script editor powered by <code>@backtest-kit/ui</code>. It lets you write, run, and iterate on indicators interactively β with a live chart that updates as you hit <strong>βΆ Run</strong></p>
<a id="usage" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Usage<a href="#usage" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--editor</span>
</code><button type="button">Copy</button></pre>
<p>The CLI will:</p>
<ol>
<li>Load <code>./modules/editor.module</code> (if it exists) β use it to register your exchange schema, identical to <code>pine.module</code></li>
<li>Start the <code>@backtest-kit/ui</code> server on <code>http://localhost:60050</code> (or <code>CC_WWWROOT_PORT</code>)</li>
<li>Open <code>http://localhost:{CC_WWWROOT_PORT}?pine=1</code> automatically in your default browser</li>
</ol>
<p>Press <strong>Ctrl+C</strong> to stop the server.</p>
<a id="exchange-via-editormodule" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Exchange via <code>editor.module</code><a href="#exchange-via-editormodule" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Drop a <code>modules/editor.module.ts</code> next to your project to register the exchange that the editor's candle provider will use:</p>
<pre><code class="typescript"><span class="hl-6">// modules/editor.module.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">addExchangeSchema</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"backtest-kit"</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"ccxt"</span><span class="hl-1">;</span><br/><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"my-exchange"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">bybit</span><span class="hl-1">({ </span><span class="hl-4">enableRateLimit:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ohlcv</span><span class="hl-1"> = </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">.</span><span class="hl-0">fetchOHLCV</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">.</span><span class="hl-0">getTime</span><span class="hl-1">(), </span><span class="hl-4">limit</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-4">ohlcv</span><span class="hl-1">.</span><span class="hl-0">map</span><span class="hl-1">(([</span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">]) </span><span class="hl-3">=></span><span class="hl-1"> ({</span><br/><span class="hl-1"> </span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">,</span><br/><span class="hl-1"> }));</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-0">formatPrice</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">price</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">2</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">formatQuantity</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">quantity</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">quantity</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">8</span><span class="hl-1">),</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<a id="environment-variables" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Environment Variables<a href="#environment-variables" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Variable</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>CC_WWWROOT_HOST</code></td>
<td><code>0.0.0.0</code></td>
<td>UI server bind address</td>
</tr>
<tr>
<td><code>CC_WWWROOT_PORT</code></td>
<td><code>60050</code></td>
<td>UI server port</td>
</tr>
</tbody>
</table>
<a id="packagejson-script" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>package.json</code> script<a href="#packagejson-script" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"editor"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --editor"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">editor</span>
</code><button type="button">Copy</button></pre>
<a id="πΎ-dumping-raw-candles" class="tsd-anchor"></a><h2 class="tsd-anchor-link">πΎ Dumping Raw Candles<a href="#πΎ-dumping-raw-candles" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> can fetch raw OHLCV candles from any registered exchange and save them to a file β no strategy file required.</p>
<a id="cli-flags-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--dump</code></td>
<td>boolean</td>
<td>Enable candle dump mode</td>
</tr>
<tr>
<td><code>--symbol</code></td>
<td>string</td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>--timeframe</code></td>
<td>string</td>
<td>Candle interval (default: <code>"15m"</code>)</td>
</tr>
<tr>
<td><code>--limit</code></td>
<td>string</td>
<td>Number of candles to fetch (default: <code>250</code>)</td>
</tr>
<tr>
<td><code>--when</code></td>
<td>string</td>
<td>End date for candle window β ISO 8601 or Unix ms (default: now)</td>
</tr>
<tr>
<td><code>--exchange</code></td>
<td>string</td>
<td>Exchange name (default: first registered, falls back to CCXT Binance)</td>
</tr>
<tr>
<td><code>--output</code></td>
<td>string</td>
<td>Output file base name without extension (default: <code>{SYMBOL}_{LIMIT}_{TIMEFRAME}_{TIMESTAMP}</code>)</td>
</tr>
<tr>
<td><code>--json</code></td>
<td>boolean</td>
<td>Write candles as a JSON array to <code>./dump/{output}.json</code></td>
</tr>
<tr>
<td><code>--jsonl</code></td>
<td>boolean</td>
<td>Write candles as JSONL (one row per line) to <code>./dump/{output}.jsonl</code></td>
</tr>
</tbody>
</table>
<p>The <code>dump/</code> directory is created in the current working directory (where the CLI is invoked from).</p>
<a id="exchange-via-dumpmodule" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Exchange via <code>dump.module</code><a href="#exchange-via-dumpmodule" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>By default the CLI registers CCXT Binance automatically. To use a different exchange β or to configure API keys, custom rate limits, or a non-spot market β create a <code>modules/dump.module.ts</code> file. The CLI loads it automatically before fetching candles.</p>
<p>The CLI looks for <code>modules/dump.module</code> in the current working directory</p>
<pre><code><span class="hl-4">my</span><span class="hl-1">-</span><span class="hl-4">project</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">modules</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">dump</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> β </span><span class="hl-4">exchange</span><span class="hl-1"> </span><span class="hl-4">registration</span><br/><span class="hl-1">βββ </span><span class="hl-4">dump</span><span class="hl-1">/ β </span><span class="hl-4">auto</span><span class="hl-1">-</span><span class="hl-10">created</span><span class="hl-1">: </span><span class="hl-4">candle</span><span class="hl-1"> </span><span class="hl-4">output</span><span class="hl-1"> </span><span class="hl-4">files</span><br/><span class="hl-1">βββ </span><span class="hl-4">package</span><span class="hl-1">.</span><span class="hl-4">json</span>
</code><button>Copy</button></pre>
<p>Inside <code>dump.module.ts</code> call <code>addExchangeSchema</code> from <code>backtest-kit</code>:</p>
<pre><code class="typescript"><span class="hl-6">// modules/dump.module.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">addExchangeSchema</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"backtest-kit"</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"ccxt"</span><span class="hl-1">;</span><br/><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"my-exchange"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">bybit</span><span class="hl-1">({ </span><span class="hl-4">enableRateLimit:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ohlcv</span><span class="hl-1"> = </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">.</span><span class="hl-0">fetchOHLCV</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">.</span><span class="hl-0">getTime</span><span class="hl-1">(), </span><span class="hl-4">limit</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-4">ohlcv</span><span class="hl-1">.</span><span class="hl-0">map</span><span class="hl-1">(([</span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">]) </span><span class="hl-3">=></span><span class="hl-1"> ({</span><br/><span class="hl-1"> </span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">,</span><br/><span class="hl-1"> }));</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-0">formatPrice</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">price</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">2</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">formatQuantity</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">quantity</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">quantity</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">8</span><span class="hl-1">),</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<a id="output-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Output<a href="#output-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Each candle row contains OHLCV fields. Print to stdout:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--dump</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--timeframe</span><span class="hl-1"> </span><span class="hl-2">15m</span><span class="hl-1"> </span><span class="hl-3">--limit</span><span class="hl-1"> </span><span class="hl-7">100</span>
</code><button type="button">Copy</button></pre>
<p>Save to <code>./dump/BTCUSDT_100_15m_{timestamp}.jsonl</code>:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--dump</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--timeframe</span><span class="hl-1"> </span><span class="hl-2">15m</span><span class="hl-1"> </span><span class="hl-3">--limit</span><span class="hl-1"> </span><span class="hl-7">100</span><span class="hl-1"> </span><span class="hl-3">--jsonl</span>
</code><button type="button">Copy</button></pre>
<p>Fetch candles up to a specific date with <code>--when</code> and override the file name with <code>--output</code>:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--dump</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--timeframe</span><span class="hl-1"> </span><span class="hl-2">15m</span><span class="hl-1"> </span><span class="hl-3">--limit</span><span class="hl-1"> </span><span class="hl-7">500</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--when</span><span class="hl-1"> </span><span class="hl-2">"2026-02-28T00:00:00.000Z"</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--jsonl</span><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">feb2026_btc</span><br/><span class="hl-6"># β ./dump/feb2026_btc.jsonl</span>
</code><button type="button">Copy</button></pre>
<p>Or add it to <code>package.json</code>:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"dump"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --dump --symbol BTCUSDT --timeframe 15m --limit 500 --jsonl"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--dump</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--timeframe</span><span class="hl-1"> </span><span class="hl-2">15m</span><span class="hl-1"> </span><span class="hl-3">--limit</span><span class="hl-1"> </span><span class="hl-7">500</span><span class="hl-1"> </span><span class="hl-3">--jsonl</span>
</code><button type="button">Copy</button></pre>
<a id="π-pnl-debug---pnldebug" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π PnL Debug (<code>--pnldebug</code>)<a href="#π-pnl-debug---pnldebug" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> can simulate a hypothetical position minute by minute and print running PnL, peak profit, and maximum drawdown for each candle β without placing any trades or loading a strategy file.</p>
<a id="cli-flags-2" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--pnldebug</code></td>
<td>boolean</td>
<td>Enable PnL debug mode</td>
</tr>
<tr>
<td><code>--priceopen</code></td>
<td>number</td>
<td>Entry price (required)</td>
</tr>
<tr>
<td><code>--direction</code></td>
<td>string</td>
<td><code>long</code> or <code>short</code> (default: <code>long</code>)</td>
</tr>
<tr>
<td><code>--when</code></td>
<td>string</td>
<td>Start timestamp β ISO 8601 or Unix ms (default: now)</td>
</tr>
<tr>
<td><code>--minutes</code></td>
<td>string</td>
<td>Number of 1m candles to simulate (default: <code>60</code>)</td>
</tr>
<tr>
<td><code>--symbol</code></td>
<td>string</td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>--exchange</code></td>
<td>string</td>
<td>Exchange name (default: first registered, falls back to CCXT Binance)</td>
</tr>
<tr>
<td><code>--output</code></td>
<td>string</td>
<td>Output file base name (default: <code>{SYMBOL}_{DIRECTION}_{PRICEOPEN}_{TIMESTAMP}</code>)</td>
</tr>
<tr>
<td><code>--json</code></td>
<td>boolean</td>
<td>Save results as JSON array to <code>./dump/<output>.json</code></td>
</tr>
<tr>
<td><code>--jsonl</code></td>
<td>boolean</td>
<td>Save results as JSONL to <code>./dump/<output>.jsonl</code></td>
</tr>
<tr>
<td><code>--markdown</code></td>
<td>boolean</td>
<td>Save results as Markdown table to <code>./dump/<output>.md</code></td>
</tr>
</tbody>
</table>
<a id="output-columns" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Output columns<a href="#output-columns" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Column</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>min</code></td>
<td>Minute offset from start (1-based)</td>
</tr>
<tr>
<td><code>timestamp</code></td>
<td>Candle timestamp (ISO 8601)</td>
</tr>
<tr>
<td><code>close</code></td>
<td>Candle close price</td>
</tr>
<tr>
<td><code>pnl%</code></td>
<td>Running PnL vs entry price (signed %)</td>
</tr>
<tr>
<td><code>peak%</code></td>
<td>Highest PnL reached so far (always β₯ 0)</td>
</tr>
<tr>
<td><code>drawdown%</code></td>
<td>Lowest PnL reached so far (always β€ 0)</td>
</tr>
</tbody>
</table>
<a id="exchange-via-pnldebugmodule" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Exchange via <code>pnldebug.module</code><a href="#exchange-via-pnldebugmodule" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>By default the CLI registers CCXT Binance automatically. To use a different exchange, create a <code>modules/pnldebug.module.ts</code> file in the current working directory β the CLI loads it automatically before fetching candles.</p>
<pre><code class="typescript"><span class="hl-6">// modules/pnldebug.module.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">addExchangeSchema</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"backtest-kit"</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">"ccxt"</span><span class="hl-1">;</span><br/><br/><span class="hl-0">addExchangeSchema</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">exchangeName:</span><span class="hl-1"> </span><span class="hl-2">"my-exchange"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getCandles</span><span class="hl-4">:</span><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">, </span><span class="hl-4">limit</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">exchange</span><span class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-4">ccxt</span><span class="hl-1">.</span><span class="hl-0">bybit</span><span class="hl-1">({ </span><span class="hl-4">enableRateLimit:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">ohlcv</span><span class="hl-1"> = </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">exchange</span><span class="hl-1">.</span><span class="hl-0">fetchOHLCV</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">interval</span><span class="hl-1">, </span><span class="hl-4">since</span><span class="hl-1">.</span><span class="hl-0">getTime</span><span class="hl-1">(), </span><span class="hl-4">limit</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-5">return</span><span class="hl-1"> </span><span class="hl-4">ohlcv</span><span class="hl-1">.</span><span class="hl-0">map</span><span class="hl-1">(([</span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">]) </span><span class="hl-3">=></span><span class="hl-1"> ({</span><br/><span class="hl-1"> </span><span class="hl-4">timestamp</span><span class="hl-1">, </span><span class="hl-4">open</span><span class="hl-1">, </span><span class="hl-4">high</span><span class="hl-1">, </span><span class="hl-4">low</span><span class="hl-1">, </span><span class="hl-4">close</span><span class="hl-1">, </span><span class="hl-4">volume</span><span class="hl-1">,</span><br/><span class="hl-1"> }));</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> </span><span class="hl-0">formatPrice</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">price</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">2</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">formatQuantity</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">quantity</span><span class="hl-1">) </span><span class="hl-3">=></span><span class="hl-1"> </span><span class="hl-4">quantity</span><span class="hl-1">.</span><span class="hl-0">toFixed</span><span class="hl-1">(</span><span class="hl-7">8</span><span class="hl-1">),</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<a id="usage-1" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Usage<a href="#usage-1" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Print to stdout (default table format):</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pnldebug</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><span class="hl-1"> </span><span class="hl-3">--priceopen</span><span class="hl-1"> </span><span class="hl-7">64069.50</span><span class="hl-1"> </span><span class="hl-3">--direction</span><span class="hl-1"> </span><span class="hl-2">short</span><span class="hl-1"> </span><span class="hl-3">--when</span><span class="hl-1"> </span><span class="hl-2">"2025-02-25"</span><span class="hl-1"> </span><span class="hl-3">--minutes</span><span class="hl-1"> </span><span class="hl-7">120</span>
</code><button type="button">Copy</button></pre>
<p>Save as Markdown:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pnldebug</span><span class="hl-1"> </span><span class="hl-3">--priceopen</span><span class="hl-1"> </span><span class="hl-7">67956.73</span><span class="hl-1"> </span><span class="hl-3">--direction</span><span class="hl-1"> </span><span class="hl-2">long</span><span class="hl-1"> </span><span class="hl-3">--when</span><span class="hl-1"> </span><span class="hl-7">1772064000000</span><span class="hl-1"> </span><span class="hl-3">--minutes</span><span class="hl-1"> </span><span class="hl-7">60</span><span class="hl-1"> </span><span class="hl-3">--markdown</span><br/><span class="hl-6"># β ./dump/BTCUSDT_long_67956.73_{timestamp}.md</span>
</code><button type="button">Copy</button></pre>
<p>Override the output file name with <code>--output</code>:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--pnldebug</span><span class="hl-1"> </span><span class="hl-3">--priceopen</span><span class="hl-1"> </span><span class="hl-7">64069.50</span><span class="hl-1"> </span><span class="hl-3">--direction</span><span class="hl-1"> </span><span class="hl-2">short</span><span class="hl-1"> </span><span class="hl-3">--when</span><span class="hl-1"> </span><span class="hl-2">"2025-02-25"</span><span class="hl-1"> </span><span class="hl-3">--minutes</span><span class="hl-1"> </span><span class="hl-7">120</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-3">--jsonl</span><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">feb25_short_debug</span><br/><span class="hl-6"># β ./dump/feb25_short_debug.jsonl</span>
</code><button type="button">Copy</button></pre>
<p>Or add it to <code>package.json</code>:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"pnldebug"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --pnldebug --symbol BTCUSDT --priceopen 64069.50 --direction short --when </span><span class="hl-13">\"</span><span class="hl-2">2025-02-25</span><span class="hl-13">\"</span><span class="hl-2"> --minutes 120"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">pnldebug</span>
</code><button type="button">Copy</button></pre>
<a id="example-stdout-output" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Example stdout output<a href="#example-stdout-output" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code><span class="hl-10">Symbol</span><span class="hl-1">: </span><span class="hl-8">BTCUSDT</span><span class="hl-1"> | </span><span class="hl-10">Direction</span><span class="hl-1">: </span><span class="hl-4">short</span><span class="hl-1"> | </span><span class="hl-10">PriceOpen</span><span class="hl-1">: </span><span class="hl-7">64069.50</span><span class="hl-1"> | </span><span class="hl-10">From</span><span class="hl-1">: </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">02</span><span class="hl-1">-25</span><span class="hl-10">T00</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> | </span><span class="hl-10">Minutes</span><span class="hl-1">: </span><span class="hl-7">120</span><br/><br/><span class="hl-1"> </span><span class="hl-4">min</span><span class="hl-1"> | </span><span class="hl-4">timestamp</span><span class="hl-1"> | </span><span class="hl-4">close</span><span class="hl-1"> | </span><span class="hl-4">pnl</span><span class="hl-1">% | </span><span class="hl-4">peak</span><span class="hl-1">% | </span><span class="hl-4">drawdown</span><span class="hl-1">%</span><br/><span class="hl-1">-----------------------------------------------------------------------------------</span><br/><span class="hl-1"> </span><span class="hl-7">1</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">02</span><span class="hl-1">-25</span><span class="hl-10">T00</span><span class="hl-1">:</span><span class="hl-7">01</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> | </span><span class="hl-7">64020.10</span><span class="hl-1"> | +</span><span class="hl-7">0.08</span><span class="hl-1">% | +</span><span class="hl-7">0.08</span><span class="hl-1">% | </span><span class="hl-7">0.00</span><span class="hl-1">%</span><br/><span class="hl-1"> </span><span class="hl-7">2</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">02</span><span class="hl-1">-25</span><span class="hl-10">T00</span><span class="hl-1">:</span><span class="hl-7">02</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> | </span><span class="hl-7">64105.30</span><span class="hl-1"> | -</span><span class="hl-7">0.06</span><span class="hl-1">% | +</span><span class="hl-7">0.08</span><span class="hl-1">% | -</span><span class="hl-7">0.06</span><span class="hl-1">%</span><br/><span class="hl-1"> ...</span><br/><span class="hl-1"> </span><span class="hl-7">120</span><span class="hl-1"> | </span><span class="hl-7">2025</span><span class="hl-1">-</span><span class="hl-7">02</span><span class="hl-1">-25</span><span class="hl-10">T02</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">:</span><span class="hl-7">00</span><span class="hl-1">.000</span><span class="hl-8">Z</span><span class="hl-1"> | </span><span class="hl-7">63200.00</span><span class="hl-1"> | +</span><span class="hl-7">1.36</span><span class="hl-1">% | +</span><span class="hl-7">1.36</span><span class="hl-1">% | -</span><span class="hl-7">0.06</span><span class="hl-1">%</span>
</code><button>Copy</button></pre>
<a id="π-broker-debug---brokerdebug" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Broker Debug (<code>--brokerdebug</code>)<a href="#π-broker-debug---brokerdebug" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> can fire a single broker commit against your live broker adapter without running a full strategy β useful for verifying that your <code>brokerdebug.module</code> correctly wires up exchange calls.</p>
<a id="cli-flags-3" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--brokerdebug</code></td>
<td>boolean</td>
<td>Enable broker debug mode</td>
</tr>
<tr>
<td><code>--commit</code></td>
<td>string</td>
<td>Commit type to fire (default: <code>"signal-open"</code>)</td>
</tr>
<tr>
<td><code>--symbol</code></td>
<td>string</td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>--exchange</code></td>
<td>string</td>
<td>Exchange name (default: first registered)</td>
</tr>
</tbody>
</table>
<p><strong>Available <code>--commit</code> values:</strong></p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Broker hook</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>signal-open</code></td>
<td><code>onSignalOpenCommit</code></td>
</tr>
<tr>
<td><code>signal-close</code></td>
<td><code>onSignalCloseCommit</code></td>
</tr>
<tr>
<td><code>partial-profit</code></td>
<td><code>onPartialProfitCommit</code></td>
</tr>
<tr>
<td><code>partial-loss</code></td>
<td><code>onPartialLossCommit</code></td>
</tr>
<tr>
<td><code>average-buy</code></td>
<td><code>onAverageBuyCommit</code></td>
</tr>
<tr>
<td><code>trailing-stop</code></td>
<td><code>onTrailingStopCommit</code></td>
</tr>
<tr>
<td><code>trailing-take</code></td>
<td><code>onTrailingTakeCommit</code></td>
</tr>
<tr>
<td><code>breakeven</code></td>
<td><code>onBreakevenCommit</code></td>
</tr>
</tbody>
</table>
<a id="how-it-works-3" class="tsd-anchor"></a><h3 class="tsd-anchor-link">How It Works<a href="#how-it-works-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The CLI loads <code>./modules/brokerdebug.module</code>, fetches the last candle for <code>--symbol</code> / <code>--timeframe</code>, derives synthetic payload values from <code>currentPrice</code> (TP = +2%, SL = -2%), and calls the selected broker hook once. Exits with code <code>0</code> on success.</p>
<a id="broker-via-brokerdebugmodule" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Broker via <code>brokerdebug.module</code><a href="#broker-via-brokerdebugmodule" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Create a <code>modules/brokerdebug.module.ts</code> file and register your broker adapter:</p>
<pre><code class="typescript"><span class="hl-6">// modules/brokerdebug.module.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">Broker</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'backtest-kit'</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">myExchange</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'./exchange.mjs'</span><span class="hl-1">;</span><br/><br/><span class="hl-3">class</span><span class="hl-1"> </span><span class="hl-11">MyBroker</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">async</span><span class="hl-1"> </span><span class="hl-0">onSignalOpenCommit</span><span class="hl-1">({ </span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">priceOpen</span><span class="hl-1">, </span><span class="hl-4">position</span><span class="hl-1"> }) {</span><br/><span class="hl-1"> </span><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-4">myExchange</span><span class="hl-1">.</span><span class="hl-0">openPosition</span><span class="hl-1">(</span><span class="hl-4">symbol</span><span class="hl-1">, </span><span class="hl-4">position</span><span class="hl-1">, </span><span class="hl-4">priceOpen</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-6">// ... other hooks</span><br/><span class="hl-1">}</span><br/><br/><span class="hl-4">Broker</span><span class="hl-1">.</span><span class="hl-0">useBrokerAdapter</span><span class="hl-1">(</span><span class="hl-4">MyBroker</span><span class="hl-1">);</span><br/><span class="hl-4">Broker</span><span class="hl-1">.</span><span class="hl-0">enable</span><span class="hl-1">();</span>
</code><button type="button">Copy</button></pre>
<a id="usage-2" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Usage<a href="#usage-2" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--brokerdebug</span><span class="hl-1"> </span><span class="hl-3">--commit</span><span class="hl-1"> </span><span class="hl-2">signal-open</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">BTCUSDT</span><br/><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--brokerdebug</span><span class="hl-1"> </span><span class="hl-3">--commit</span><span class="hl-1"> </span><span class="hl-2">partial-profit</span><span class="hl-1"> </span><span class="hl-3">--symbol</span><span class="hl-1"> </span><span class="hl-2">ETHUSDT</span><span class="hl-1"> </span><span class="hl-3">--timeframe</span><span class="hl-1"> </span><span class="hl-2">1h</span>
</code><button type="button">Copy</button></pre>
<a id="ποΈ-flushing-strategy-output---flush" class="tsd-anchor"></a><h2 class="tsd-anchor-link">ποΈ Flushing Strategy Output (<code>--flush</code>)<a href="#ποΈ-flushing-strategy-output---flush" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> can delete generated output folders from one or more strategy dump directories without touching cached candle data.</p>
<a id="cli-flags-4" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags-4" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--flush</code></td>
<td>boolean</td>
<td>Enable flush mode</td>
</tr>
</tbody>
</table>
<p><strong>Positional arguments (required):</strong> one or more strategy entry point files. For each entry point the CLI resolves its directory and removes the following subdirectories from <code><entry-dir>/dump/</code>:</p>
<table>
<thead>
<tr>
<th>Folder</th>
<th>Contents</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>report</code></td>
<td>Backtest report files (<code>.jsonl</code>)</td>
</tr>
<tr>
<td><code>log</code></td>
<td>Run logs (<code>log.jsonl</code>)</td>
</tr>
<tr>
<td><code>markdown</code></td>
<td>Exported Markdown reports</td>
</tr>
<tr>
<td><code>agent</code></td>
<td>Agent outline files</td>
</tr>
</tbody>
</table>
<p>Candle cache (<code>dump/data/</code>) and AI forecast outlines (<code>dump/outline/</code>) are <strong>not</strong> removed.</p>
<a id="usage-3" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Usage<a href="#usage-3" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Flush a single strategy:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--flush</span><span class="hl-1"> </span><span class="hl-2">./content/feb_2026.strategy/modules/backtest.module.ts</span>
</code><button type="button">Copy</button></pre>
<p>Flush multiple strategies at once:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--flush</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-2">./content/feb_2026.strategy/modules/backtest.module.ts</span><span class="hl-1"> </span><span class="hl-13">\</span><br/><span class="hl-1"> </span><span class="hl-2">./content/mar_2026.strategy/modules/backtest.module.ts</span>
</code><button type="button">Copy</button></pre>
<p>Or add it to <code>package.json</code>:</p>
<pre><code class="json"><span class="hl-1">{</span><br/><span class="hl-1"> </span><span class="hl-16">"scripts"</span><span class="hl-1">: {</span><br/><span class="hl-1"> </span><span class="hl-16">"flush"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --flush ./content/feb_2026.strategy/modules/backtest.module.ts"</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">flush</span>
</code><button type="button">Copy</button></pre>
<a id="ποΈ-scaffolding-a-new-project---init" class="tsd-anchor"></a><h2 class="tsd-anchor-link">ποΈ Scaffolding a New Project (<code>--init</code>)<a href="#ποΈ-scaffolding-a-new-project---init" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p><code>@backtest-kit/cli</code> can bootstrap a ready-to-use project directory with a pre-configured layout, example strategy files, and all documentation fetched automatically.</p>
<a id="cli-flags-5" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags-5" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--init</code></td>
<td>boolean</td>
<td>Scaffold a new project</td>
</tr>
<tr>
<td><code>--output</code></td>
<td>string</td>
<td>Target directory name (default: <code>backtest-kit-project</code>)</td>
</tr>
</tbody>
</table>
<a id="usage-4" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Usage<a href="#usage-4" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--init</span>
</code><button type="button">Copy</button></pre>
<p>Creates <code>./backtest-kit-project/</code> in the current working directory.</p>
<p>Override the directory name with <code>--output</code>:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--init</span><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">my-trading-bot</span>
</code><button type="button">Copy</button></pre>
<p>Creates <code>./my-trading-bot/</code>.</p>
<p>The target directory must not exist or must be empty β the command aborts if it contains any files.</p>
<a id="generated-project-structure" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Generated Project Structure<a href="#generated-project-structure" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code><span class="hl-4">backtest</span><span class="hl-1">-</span><span class="hl-4">kit</span><span class="hl-1">-</span><span class="hl-4">project</span><span class="hl-1">/</span><br/><span class="hl-1">βββ </span><span class="hl-4">package</span><span class="hl-1">.</span><span class="hl-4">json</span><span class="hl-1"> # </span><span class="hl-4">pre</span><span class="hl-1">-</span><span class="hl-4">configured</span><span class="hl-1"> </span><span class="hl-5">with</span><span class="hl-1"> </span><span class="hl-4">all</span><span class="hl-1"> </span><span class="hl-4">backtest</span><span class="hl-1">-</span><span class="hl-4">kit</span><span class="hl-1"> </span><span class="hl-4">dependencies</span><br/><span class="hl-1">βββ .</span><span class="hl-4">gitignore</span><br/><span class="hl-1">βββ </span><span class="hl-8">CLAUDE</span><span class="hl-1">.</span><span class="hl-4">md</span><span class="hl-1"> # </span><span class="hl-8">AI</span><span class="hl-1">-</span><span class="hl-4">agent</span><span class="hl-1"> </span><span class="hl-4">guide</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> </span><span class="hl-4">writing</span><span class="hl-1"> </span><span class="hl-4">strategies</span><br/><span class="hl-1">βββ </span><span class="hl-4">content</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">strategy</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> # </span><span class="hl-4">example</span><span class="hl-1"> </span><span class="hl-4">strategy</span><span class="hl-1"> </span><span class="hl-4">entry</span><span class="hl-1"> </span><span class="hl-4">point</span><br/><span class="hl-1">βββ </span><span class="hl-4">docs</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">lib</span><span class="hl-1">/ # </span><span class="hl-4">fetched</span><span class="hl-1"> </span><span class="hl-0">automatically</span><span class="hl-1"> (</span><span class="hl-4">see</span><span class="hl-1"> </span><span class="hl-4">below</span><span class="hl-1">)</span><br/><span class="hl-1">β βββ </span><span class="hl-4">backtest_actions</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">backtest_graph_pattern</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">backtest_logging_jsonl</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">backtest_pinets_usage</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">backtest_risk_async</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">backtest_strategy_structure</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">pine_debug</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">β βββ </span><span class="hl-4">pine_indicator_warmup</span><span class="hl-1">.</span><span class="hl-4">md</span><br/><span class="hl-1">βββ </span><span class="hl-4">math</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">pine</span><span class="hl-1"> # </span><span class="hl-4">example</span><span class="hl-1"> </span><span class="hl-4">PineScript</span><span class="hl-1"> </span><span class="hl-4">indicator</span><br/><span class="hl-1">βββ </span><span class="hl-4">modules</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">dump</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> # </span><span class="hl-4">exchange</span><span class="hl-1"> </span><span class="hl-4">schema</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> --</span><span class="hl-4">dump</span><span class="hl-1"> </span><span class="hl-4">mode</span><br/><span class="hl-1">β βββ </span><span class="hl-4">pine</span><span class="hl-1">.</span><span class="hl-4">module</span><span class="hl-1">.</span><span class="hl-4">ts</span><span class="hl-1"> # </span><span class="hl-4">exchange</span><span class="hl-1"> </span><span class="hl-4">schema</span><span class="hl-1"> </span><span class="hl-4">for</span><span class="hl-1"> --</span><span class="hl-4">pine</span><span class="hl-1"> </span><span class="hl-4">mode</span><br/><span class="hl-1">βββ </span><span class="hl-4">report</span><span class="hl-1">/</span><br/><span class="hl-1">β βββ </span><span class="hl-4">feb_2026</span><span class="hl-1">.</span><span class="hl-4">md</span><span class="hl-1"> # </span><span class="hl-4">example</span><span class="hl-1"> </span><span class="hl-4">strategy</span><span class="hl-1"> </span><span class="hl-4">research</span><span class="hl-1"> </span><span class="hl-4">report</span><br/><span class="hl-1">βββ </span><span class="hl-4">scripts</span><span class="hl-1">/</span><br/><span class="hl-1"> βββ </span><span class="hl-4">fetch_docs</span><span class="hl-1">.</span><span class="hl-4">mjs</span><span class="hl-1"> # </span><span class="hl-10">utility</span><span class="hl-1">: </span><span class="hl-4">downloads</span><span class="hl-1"> </span><span class="hl-4">library</span><span class="hl-1"> </span><span class="hl-4">READMEs</span><span class="hl-1"> </span><span class="hl-4">into</span><span class="hl-1"> </span><span class="hl-4">docs</span><span class="hl-1">/</span><span class="hl-4">lib</span><span class="hl-1">/</span>
</code><button>Copy</button></pre>
<a id="automatic-documentation-fetch" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Automatic Documentation Fetch<a href="#automatic-documentation-fetch" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>After scaffolding, the CLI immediately runs <code>scripts/fetch_docs.mjs</code> inside the new project, which downloads the latest README files for all bundled libraries into <code>docs/lib/</code>:</p>
<table>
<thead>
<tr>
<th>File</th>
<th>Source</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>backtest-kit.md</code></td>
<td><code>backtest-kit</code> README</td>
</tr>
<tr>
<td><code>backtest-kit__graph.md</code></td>
<td><code>@backtest-kit/graph</code> README</td>
</tr>
<tr>
<td><code>backtest-kit__pinets.md</code></td>
<td><code>@backtest-kit/pinets</code> README</td>
</tr>
<tr>
<td><code>backtest-kit__cli.md</code></td>
<td><code>@backtest-kit/cli</code> README</td>
</tr>
<tr>
<td><code>garch.md</code></td>
<td><code>garch</code> README</td>
</tr>
<tr>
<td><code>volume-anomaly.md</code></td>
<td><code>volume-anomaly</code> README</td>
</tr>
<tr>
<td><code>agent-swarm-kit.md</code></td>
<td><code>agent-swarm-kit</code> README</td>
</tr>
<tr>
<td><code>functools-kit.md</code></td>
<td><code>functools-kit</code> README</td>
</tr>
</tbody>
</table>
<p>You can re-run this script at any time to refresh the docs:</p>
<pre><code class="bash"><span class="hl-0">cd</span><span class="hl-1"> </span><span class="hl-2">backtest-kit-project</span><br/><span class="hl-0">node</span><span class="hl-1"> </span><span class="hl-2">./scripts/fetch_docs.mjs</span>
</code><button type="button">Copy</button></pre>
<p>Or via the pre-configured npm script:</p>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">sync:lib</span>
</code><button type="button">Copy</button></pre>
<a id="π³-running-in-docker---docker" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π³ Running in Docker (<code>--docker</code>)<a href="#π³-running-in-docker---docker" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>CLI can create a ready-to-use Docker workspace: self-contained directory with <code>docker-compose.yaml</code> and a strategy entry point.</p>
<a id="cli-flags-6" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Flags<a href="#cli-flags-6" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><table>
<thead>
<tr>
<th>Flag</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--docker</code></td>
<td>boolean</td>
<td>Scaffold a Docker workspace</td>
</tr>
<tr>
<td><code>--output</code></td>
<td>string</td>
<td>Target directory name (default: <code>backtest-kit-docker</code>)</td>
</tr>
</tbody>
</table>
<a id="usage-5" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Usage<a href="#usage-5" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--docker</span>
</code><button type="button">Copy</button></pre>
<p>Creates <code>./backtest-kit-docker/</code> in the current working directory.</p>
<p>Override the directory name with <code>--output</code>:</p>
<pre><code class="bash"><span class="hl-0">npx</span><span class="hl-1"> </span><span class="hl-2">@backtest-kit/cli</span><span class="hl-1"> </span><span class="hl-3">--docker</span><span class="hl-1"> </span><span class="hl-3">--output</span><span class="hl-1"> </span><span class="hl-2">my-docker-workspace</span>
</code><button type="button">Copy</button></pre>
<p>The target directory must not exist or must be empty β the command aborts if it contains any files.</p>
<a id="two-launch-modes" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Two Launch Modes<a href="#two-launch-modes" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The Docker image entrypoint supports two ways to run a strategy:</p>
<a id="1-command-in-docker-composeyaml" class="tsd-anchor"></a><h4 class="tsd-anchor-link">1. <code>command:</code> in <code>docker-compose.yaml</code><a href="#1-command-in-docker-composeyaml" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>Pin mode and flags directly in the compose file. The entrypoint forwards all arguments to the CLI unchanged:</p>
<pre><code class="yaml"><span class="hl-14">command</span><span class="hl-1">:</span><br/><span class="hl-1"> - </span><span class="hl-15">--live</span><br/><span class="hl-1"> - </span><span class="hl-15">--symbol</span><br/><span class="hl-1"> - </span><span class="hl-15">TRXUSDT</span><br/><span class="hl-1"> - </span><span class="hl-15">--strategy</span><br/><span class="hl-1"> - </span><span class="hl-15">feb_2026_strategy</span><br/><span class="hl-1"> - </span><span class="hl-15">--exchange</span><br/><span class="hl-1"> - </span><span class="hl-15">ccxt-exchange</span><br/><span class="hl-1"> - </span><span class="hl-15">./content/feb_2026/feb_2026.strategy.ts</span><br/><span class="hl-1"> - </span><span class="hl-15">--ui</span>
</code><button type="button">Copy</button></pre>
<a id="2-inline-environment-variables" class="tsd-anchor"></a><h4 class="tsd-anchor-link">2. Inline environment variables<a href="#2-inline-environment-variables" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h4><p>Pass <code>MODE</code> and <code>STRATEGY_FILE</code> on the command line β no file edits needed:</p>
<pre><code class="bash"><span class="hl-4">MODE</span><span class="hl-1">=</span><span class="hl-2">live</span><span class="hl-1"> </span><span class="hl-4">SYMBOL</span><span class="hl-1">=</span><span class="hl-2">TRXUSDT</span><span class="hl-1"> </span><span class="hl-4">STRATEGY_FILE</span><span class="hl-1">=</span><span class="hl-2">./content/feb_2026/feb_2026.strategy.ts</span><span class="hl-1"> </span><span class="hl-0">docker-compose</span><span class="hl-1"> </span><span class="hl-2">up</span><span class="hl-1"> </span><span class="hl-3">-d</span>
</code><button type="button">Copy</button></pre>
<table>
<thead>
<tr>
<th>Variable</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>MODE</code></td>
<td>yes</td>
<td>β</td>
<td><code>backtest</code> | <code>live</code> | <code>paper</code> | <code>walker</code></td>
</tr>
<tr>
<td><code>STRATEGY_FILE</code></td>
<td>yes</td>
<td>β</td>
<td>Path to strategy entry point (relative to <code>working_dir</code>)</td>
</tr>
<tr>
<td><code>SYMBOL</code></td>
<td>no</td>
<td><code>BTCUSDT</code></td>
<td>Trading pair</td>
</tr>
<tr>
<td><code>STRATEGY</code></td>
<td>no</td>
<td>first registered</td>
<td>Strategy name</td>
</tr>
<tr>
<td><code>EXCHANGE</code></td>
<td>no</td>
<td>first registered</td>
<td>Exchange name</td>
</tr>
<tr>
<td><code>FRAME</code></td>
<td>no</td>
<td>first registered</td>
<td>Frame name (backtest only)</td>
</tr>
<tr>
<td><code>UI</code></td>
<td>no</td>
<td>β</td>
<td>Any non-empty value enables <code>--ui</code></td>
</tr>
<tr>
<td><code>TELEGRAM</code></td>
<td>no</td>
<td>β</td>
<td>Any non-empty value enables <code>--telegram</code></td>
</tr>
<tr>
<td><code>VERBOSE</code></td>
<td>no</td>
<td>β</td>
<td>Any non-empty value enables <code>--verbose</code></td>
</tr>
<tr>
<td><code>NO_CACHE</code></td>
<td>no</td>
<td>β</td>
<td>Any non-empty value enables <code>--noCache</code></td>
</tr>
<tr>
<td><code>NO_FLUSH</code></td>
<td>no</td>
<td>β</td>
<td>Any non-empty value enables <code>--noFlush</code></td>
</tr>
<tr>
<td><code>ENTRY</code></td>
<td>no</td>
<td>β</td>
<td>Any non-empty value enables multiple symbols from userspace</td>
</tr>
</tbody>
</table>
<a id="π-environment-variables" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π Environment Variables<a href="#π-environment-variables" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Create a <code>.env</code> file in your project root:</p>
<pre><code class="env"># Telegram notifications (required for --telegram)
CC_TELEGRAM_TOKEN=your_bot_token_here
CC_TELEGRAM_CHANNEL=-100123456789
# Web UI server (optional, defaults shown)
CC_WWWROOT_HOST=0.0.0.0
CC_WWWROOT_PORT=60050
# Custom QuickChart service URL (optional)
CC_QUICKCHART_HOST=
</code><button type="button">Copy</button></pre>
<table>
<thead>
<tr>
<th>Variable</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>CC_TELEGRAM_TOKEN</code></td>
<td>β</td>
<td>Telegram bot token (from @BotFather)</td>
</tr>
<tr>
<td><code>CC_TELEGRAM_CHANNEL</code></td>
<td>β</td>
<td>Telegram channel or chat ID</td>
</tr>
<tr>
<td><code>CC_WWWROOT_HOST</code></td>
<td><code>0.0.0.0</code></td>
<td>UI server bind address</td>
</tr>
<tr>
<td><code>CC_WWWROOT_PORT</code></td>
<td><code>60050</code></td>
<td>UI server port</td>
</tr>
<tr>
<td><code>CC_QUICKCHART_HOST</code></td>
<td>β</td>
<td>Self-hosted QuickChart instance URL</td>
</tr>
</tbody>
</table>
<a id="βοΈ-default-behaviors" class="tsd-anchor"></a><h2 class="tsd-anchor-link">βοΈ Default Behaviors<a href="#βοΈ-default-behaviors" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>When your strategy module does not register an exchange, frame, or strategy name, the CLI falls back to built-in defaults and prints a console warning:</p>
<table>
<thead>
<tr>
<th>Component</th>
<th>Default</th>
<th>Warning</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Exchange</strong></td>
<td>CCXT Binance (<code>default_exchange</code>)</td>
<td><code>Warning: The default exchange schema is set to CCXT Binance...</code></td>
</tr>
<tr>
<td><strong>Frame</strong></td>
<td>February 2024 (<code>default_frame</code>)</td>
<td><code>Warning: The default frame schema is set to February 2024...</code></td>
</tr>
<tr>
<td><strong>Symbol</strong></td>
<td><code>BTCUSDT</code></td>
<td>β</td>
</tr>
<tr>
<td><strong>Cache intervals</strong></td>
<td><code>1m, 15m, 30m, 4h</code></td>
<td>Used if <code>--cacheInterval</code> not provided; skip entirely with <code>--noCache</code></td>
</tr>
</tbody>
</table>
<blockquote>
<p><strong>Note:</strong> The default exchange schema <strong>does not support order book fetching in backtest mode</strong>. If your strategy calls <code>getOrderBook()</code> during backtest, you must register a custom exchange schema with your own snapshot storage.</p>
</blockquote>
<a id="π§-programmatic-api" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π§ Programmatic API<a href="#π§-programmatic-api" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>In addition to the CLI, <code>@backtest-kit/cli</code> can be used as a library β call <code>run()</code> directly from your own script without spawning a child process or parsing CLI flags.</p>
<a id="runmode-args" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code>run(mode, args)</code><a href="#runmode-args" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">run</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/cli'</span><span class="hl-1">;</span><br/><br/><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-0">run</span><span class="hl-1">(</span><span class="hl-4">mode</span><span class="hl-1">, </span><span class="hl-4">args</span><span class="hl-1">);</span>
</code><button type="button">Copy</button></pre>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>mode</code></td>
<td><code>"backtest" | "paper" | "live"</code> β Execution mode</td>
</tr>
<tr>
<td><code>args</code></td>
<td>Mode-specific options (all optional β same defaults as CLI)</td>
</tr>
</tbody>
</table>
<p><code>run()</code> can be called <strong>only once per process</strong>. A second call throws <code>"Should be called only once"</code>.</p>
<a id="payload-fields" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Payload fields<a href="#payload-fields" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p><strong>Backtest</strong> (<code>mode: "backtest"</code>):</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>entryPoint</code></td>
<td><code>string</code></td>
<td>Path to strategy entry point file</td>
</tr>
<tr>
<td><code>symbol</code></td>
<td><code>string</code></td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>strategy</code></td>
<td><code>string</code></td>
<td>Strategy name (default: first registered)</td>
</tr>
<tr>
<td><code>exchange</code></td>
<td><code>string</code></td>
<td>Exchange name (default: first registered)</td>
</tr>
<tr>
<td><code>frame</code></td>
<td><code>string</code></td>
<td>Frame name (default: first registered)</td>
</tr>
<tr>
<td><code>cacheInterval</code></td>
<td><code>CandleInterval[]</code></td>
<td>Intervals to pre-cache (default: <code>["1m","15m","30m","1h","4h"]</code>)</td>
</tr>
<tr>
<td><code>noCache</code></td>
<td><code>boolean</code></td>
<td>Skip candle cache warming (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>noFlush</code></td>
<td><code>boolean</code></td>
<td>Skip removing report/log/markdown/agent folders before the run (default: <code>false</code>)</td>
</tr>
<tr>
<td><code>verbose</code></td>
<td><code>boolean</code></td>
<td>Log each candle fetch (default: <code>false</code>)</td>
</tr>
</tbody>
</table>
<p><strong>Paper</strong> and <strong>Live</strong> (<code>mode: "paper"</code> / <code>mode: "live"</code>):</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>entryPoint</code></td>
<td><code>string</code></td>
<td>Path to strategy entry point file</td>
</tr>
<tr>
<td><code>symbol</code></td>
<td><code>string</code></td>
<td>Trading pair (default: <code>"BTCUSDT"</code>)</td>
</tr>
<tr>
<td><code>strategy</code></td>
<td><code>string</code></td>
<td>Strategy name (default: first registered)</td>
</tr>
<tr>
<td><code>exchange</code></td>
<td><code>string</code></td>
<td>Exchange name (default: first registered)</td>
</tr>
<tr>
<td><code>verbose</code></td>
<td><code>boolean</code></td>
<td>Log each candle fetch (default: <code>false</code>)</td>
</tr>
</tbody>
</table>
<a id="examples" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Examples<a href="#examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><p><strong>Backtest:</strong></p>
<pre><code class="typescript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">run</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/cli'</span><span class="hl-1">;</span><br/><br/><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-0">run</span><span class="hl-1">(</span><span class="hl-2">'backtest'</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-4">entryPoint:</span><span class="hl-1"> </span><span class="hl-2">'./src/index.mjs'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">symbol:</span><span class="hl-1"> </span><span class="hl-2">'ETHUSDT'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">frame:</span><span class="hl-1"> </span><span class="hl-2">'feb-2024'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">cacheInterval:</span><span class="hl-1"> [</span><span class="hl-2">'1m'</span><span class="hl-1">, </span><span class="hl-2">'15m'</span><span class="hl-1">, </span><span class="hl-2">'1h'</span><span class="hl-1">],</span><br/><span class="hl-1"> </span><span class="hl-4">verbose:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p><strong>Paper trading:</strong></p>
<pre><code class="typescript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">run</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/cli'</span><span class="hl-1">;</span><br/><br/><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-0">run</span><span class="hl-1">(</span><span class="hl-2">'paper'</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-4">entryPoint:</span><span class="hl-1"> </span><span class="hl-2">'./src/index.mjs'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">symbol:</span><span class="hl-1"> </span><span class="hl-2">'BTCUSDT'</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p><strong>Live trading:</strong></p>
<pre><code class="typescript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">run</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/cli'</span><span class="hl-1">;</span><br/><br/><span class="hl-5">await</span><span class="hl-1"> </span><span class="hl-0">run</span><span class="hl-1">(</span><span class="hl-2">'live'</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-4">entryPoint:</span><span class="hl-1"> </span><span class="hl-2">'./src/index.mjs'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">symbol:</span><span class="hl-1"> </span><span class="hl-2">'BTCUSDT'</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">verbose:</span><span class="hl-1"> </span><span class="hl-3">true</span><span class="hl-1">,</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<a id="π‘-why-use-backtest-kitcli" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π‘ Why Use @backtest-kit/cli?<a href="#π‘-why-use-backtest-kitcli" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Instead of writing infrastructure code for every project:</p>
<p><strong>β Without @backtest-kit/cli (manual setup)</strong></p>
<pre><code class="typescript"><span class="hl-6">// index.ts</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">setLogger</span><span class="hl-1">, </span><span class="hl-4">setConfig</span><span class="hl-1">, </span><span class="hl-4">Storage</span><span class="hl-1">, </span><span class="hl-4">Notification</span><span class="hl-1">, </span><span class="hl-4">Report</span><span class="hl-1">, </span><span class="hl-4">Markdown</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'backtest-kit'</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">serve</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">'@backtest-kit/ui'</span><span class="hl-1">;</span><br/><br/><span class="hl-0">setLogger</span><span class="hl-1">({ </span><span class="hl-4">log:</span><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">, ... });</span><br/><span class="hl-4">Storage</span><span class="hl-1">.</span><span class="hl-0">enable</span><span class="hl-1">();</span><br/><span class="hl-4">Notification</span><span class="hl-1">.</span><span class="hl-0">enable</span><span class="hl-1">();</span><br/><span class="hl-4">Report</span><span class="hl-1">.</span><span class="hl-0">enable</span><span class="hl-1">();</span><br/><span class="hl-4">Markdown</span><span class="hl-1">.</span><span class="hl-0">disable</span><span class="hl-1">();</span><br/><br/><span class="hl-6">// ... parse CLI args manually</span><br/><span class="hl-6">// ... register exchange schema</span><br/><span class="hl-6">// ... warm candle cache</span><br/><span class="hl-6">// ... set up Telegram bot</span><br/><span class="hl-6">// ... handle SIGINT gracefully</span><br/><span class="hl-6">// ... load and run backtest</span>
</code><button type="button">Copy</button></pre>
<p><strong>β
With @backtest-kit/cli (one script)</strong></p>
<pre><code class="json"><span class="hl-1">{ </span><span class="hl-16">"scripts"</span><span class="hl-1">: { </span><span class="hl-16">"backtest"</span><span class="hl-1">: </span><span class="hl-2">"npx @backtest-kit/cli --backtest --ui --telegram ./src/index.mjs"</span><span class="hl-1"> } }</span>
</code><button type="button">Copy</button></pre>
<pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">run</span><span class="hl-1"> </span><span class="hl-2">backtest</span>
</code><button type="button">Copy</button></pre>
<p><strong>Benefits:</strong></p>
<ul>
<li>π From zero to running backtest in seconds</li>
<li>πΎ Automatic candle cache warming with retry logic</li>
<li>π Production-ready web dashboard out of the box</li>
<li>π¬ Telegram notifications with price charts β no chart code needed</li>
<li>π Graceful shutdown on SIGINT β no hanging processes</li>
<li>π Works with any <code>backtest-kit</code> strategy file as-is</li>
<li>π§© Broker adapter hooks via side-effect module files β no CLI internals to touch</li>
</ul>
<a id="π€-contribute" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π€ Contribute<a href="#π€-contribute" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Fork/PR on <a href="https://github.com/tripolskypetr/backtest-kit">GitHub</a>.</p>
<a id="π-license" class="tsd-anchor"></a><h2 class="tsd-anchor-link">π License<a href="#π-license" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h2><p>MIT Β© <a href="https://github.com/tripolskypetr">tripolskypetr</a></p>
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#π-backtest-kitcli"><span>π @backtest-<wbr/>kit/cli</span></a><ul><li><a href="#ποΈ-cli-init"><span>ποΈ CLI <wbr/>Init</span></a></li><li><a href="#π€-philosophy"><span>π€ <wbr/>Philosophy</span></a></li><li><a href="#β¨-features"><span>β¨ <wbr/>Features</span></a></li><li><a href="#π-what-it-does"><span>π <wbr/>What <wbr/>It <wbr/>Does</span></a></li><li><a href="#π-installation"><span>π <wbr/>Installation</span></a></li><li><a href="#π-quick-start"><span>π <wbr/>Quick <wbr/>Start</span></a></li><li><a href="#ποΈ-cli-flags"><span>ποΈ CLI <wbr/>Flags</span></a></li><li><a href="#π-execution-modes"><span>π <wbr/>Execution <wbr/>Modes</span></a></li><li><ul><li><a href="#backtest"><span>Backtest</span></a></li><li><a href="#paper-trading"><span>Paper <wbr/>Trading</span></a></li><li><a href="#live-trading"><span>Live <wbr/>Trading</span></a></li><li><a href="#walker--ab-strategy-comparison"><span>Walker β <wbr/>A/<wbr/>B <wbr/>Strategy <wbr/>Comparison</span></a></li></ul></li><li><a href="#π-multiple-symbol-parallel"><span>π <wbr/>Multiple <wbr/>Symbol <wbr/>Parallel</span></a></li><li><ul><li><a href="#example-backtest-a-strategy-on-five-symbols-at-once"><span>Example: backtest a strategy on five symbols at once</span></a></li></ul></li><li><a href="#ποΈ-monorepo-usage"><span>ποΈ <wbr/>Monorepo <wbr/>Usage</span></a></li><li><ul><li><a href="#how-it-works"><span>How <wbr/>It <wbr/>Works</span></a></li><li><a href="#project-structure"><span>Project <wbr/>Structure</span></a></li><li><a href="#root-packagejson"><span>Root package.json</span></a></li><li><a href="#isolated-resources-per-strategy"><span>Isolated <wbr/>Resources <wbr/>Per <wbr/>Strategy</span></a></li></ul></li><li><a href="#π-shared-import-aliases"><span>π <wbr/>Shared <wbr/>Import <wbr/>Aliases</span></a></li><li><ul><li><a href="#how-it-works-1"><span>How <wbr/>It <wbr/>Works</span></a></li><li><a href="#project-structure-1"><span>Project <wbr/>Structure</span></a></li><li><a href="#typescript-support"><span>Type<wbr/>Script <wbr/>Support</span></a></li></ul></li><li><a href="#π-integrations"><span>π <wbr/>Integrations</span></a></li><li><ul><li><a href="#web-dashboard---ui"><span>Web <wbr/>Dashboard (--ui)</span></a></li><li><ul><li><a href="#symbol-list-symbolconfig"><span>Symbol <wbr/>List (symbol.config)</span></a></li><li><a href="#notification-filter-notificationconfig"><span>Notification <wbr/>Filter (notification.config)</span></a></li></ul></li><li><a href="#telegram-notifications---telegram"><span>Telegram <wbr/>Notifications (--telegram)</span></a></li><li><ul><li><a href="#telegram-message-adapter-telegramconfig"><span>Telegram <wbr/>Message <wbr/>Adapter (telegram.config)</span></a></li></ul></li></ul></li><li><a href="#π§©-module-hooks-broker-adapter"><span>π§© <wbr/>Module <wbr/>Hooks (<wbr/>Broker <wbr/>Adapter)</span></a></li><li><ul><li><a href="#how-it-works-2"><span>How <wbr/>It <wbr/>Works</span></a></li><li><a href="#available-broker-hooks"><span>Available <wbr/>Broker <wbr/>Hooks</span></a></li><li><a href="#typescript"><span>Type<wbr/>Script</span></a></li></ul></li><li><a href="#βοΈ-setup-hook-configsetupconfig"><span>βοΈ <wbr/>Setup <wbr/>Hook (config/setup.config)</span></a></li><li><ul><li><a href="#example-mongodb--redis-persistence-via-backtest-kitmongo"><span>Example: <wbr/>MongoDB + <wbr/>Redis persistence via @backtest-<wbr/>kit/mongo</span></a></li></ul></li><li><a href="#π§©-module-loader-configloaderconfig"><span>π§© <wbr/>Module <wbr/>Loader (config/loader.config)</span></a></li><li><ul><li><a href="#example-wait-for-mongodb-before-running-a-backtest"><span>Example: wait for <wbr/>MongoDB before running a backtest</span></a></li><li><a href="#example-stitch-microfrontends-in-a-monorepo"><span>Example: stitch microfrontends in a monorepo</span></a></li></ul></li><li><a href="#π-import-aliases-configaliasconfig"><span>π <wbr/>Import <wbr/>Aliases (config/alias.config)</span></a></li><li><a href="#π¦-supported-entry-point-formats"><span>π¦ <wbr/>Supported <wbr/>Entry <wbr/>Point <wbr/>Formats</span></a></li><li><ul><li><a href="#typescript-ts"><span>Type<wbr/>Script (.ts)</span></a></li><li><a href="#es-module-mjs"><span>ES <wbr/>Module (.mjs)</span></a></li><li><a href="#commonjs-cjs"><span>CommonJS (.cjs)</span></a></li></ul></li><li><a href="#π²-running-local-pinescript-indicators"><span>π² <wbr/>Running <wbr/>Local <wbr/>Pine<wbr/>Script <wbr/>Indicators</span></a></li><li><ul><li><a href="#cli-flags"><span>CLI <wbr/>Flags</span></a></li><li><a href="#exchange-via-pinemodule"><span>Exchange via pine.module</span></a></li><li><a href="#environment-variables-env"><span>Environment variables (.env)</span></a></li><li><a href="#pinescript-requirements"><span>Pine<wbr/>Script <wbr/>Requirements</span></a></li><li><a href="#output"><span>Output</span></a></li></ul></li><li><a href="#π¨-visual-pine-script-editor"><span>π¨ <wbr/>Visual <wbr/>Pine <wbr/>Script <wbr/>Editor</span></a></li><li><ul><li><a href="#usage"><span>Usage</span></a></li><li><a href="#exchange-via-editormodule"><span>Exchange via editor.module</span></a></li><li><a href="#environment-variables"><span>Environment <wbr/>Variables</span></a></li><li><a href="#packagejson-script"><span>package.json script</span></a></li></ul></li><li><a href="#πΎ-dumping-raw-candles"><span>πΎ <wbr/>Dumping <wbr/>Raw <wbr/>Candles</span></a></li><li><ul><li><a href="#cli-flags-1"><span>CLI <wbr/>Flags</span></a></li><li><a href="#exchange-via-dumpmodule"><span>Exchange via dump.module</span></a></li><li><a href="#output-1"><span>Output</span></a></li></ul></li><li><a href="#π-pnl-debug---pnldebug"><span>π <wbr/>Pn<wbr/>L <wbr/>Debug (--pnldebug)</span></a></li><li><ul><li><a href="#cli-flags-2"><span>CLI <wbr/>Flags</span></a></li><li><a href="#output-columns"><span>Output columns</span></a></li><li><a href="#exchange-via-pnldebugmodule"><span>Exchange via pnldebug.module</span></a></li><li><a href="#usage-1"><span>Usage</span></a></li><li><a href="#example-stdout-output"><span>Example stdout output</span></a></li></ul></li><li><a href="#π-broker-debug---brokerdebug"><span>π <wbr/>Broker <wbr/>Debug (--brokerdebug)</span></a></li><li><ul><li><a href="#cli-flags-3"><span>CLI <wbr/>Flags</span></a></li><li><a href="#how-it-works-3"><span>How <wbr/>It <wbr/>Works</span></a></li><li><a href="#broker-via-brokerdebugmodule"><span>Broker via brokerdebug.module</span></a></li><li><a href="#usage-2"><span>Usage</span></a></li></ul></li><li><a href="#ποΈ-flushing-strategy-output---flush"><span>ποΈ <wbr/>Flushing <wbr/>Strategy <wbr/>Output (--flush)</span></a></li><li><ul><li><a href="#cli-flags-4"><span>CLI <wbr/>Flags</span></a></li><li><a href="#usage-3"><span>Usage</span></a></li></ul></li><li><a href="#ποΈ-scaffolding-a-new-project---init"><span>ποΈ <wbr/>Scaffolding a <wbr/>New <wbr/>Project (--init)</span></a></li><li><ul><li><a href="#cli-flags-5"><span>CLI <wbr/>Flags</span></a></li><li><a href="#usage-4"><span>Usage</span></a></li><li><a href="#generated-project-structure"><span>Generated <wbr/>Project <wbr/>Structure</span></a></li><li><a href="#automatic-documentation-fetch"><span>Automatic <wbr/>Documentation <wbr/>Fetch</span></a></li></ul></li><li><a href="#π³-running-in-docker---docker"><span>π³ <wbr/>Running in <wbr/>Docker (--docker)</span></a></li><li><ul><li><a href="#cli-flags-6"><span>CLI <wbr/>Flags</span></a></li><li><a href="#usage-5"><span>Usage</span></a></li><li><a href="#two-launch-modes"><span>Two <wbr/>Launch <wbr/>Modes</span></a></li><li><ul><li><a href="#1-command-in-docker-composeyaml"><span>1. command: in docker-<wbr/>compose.yaml</span></a></li><li><a href="#2-inline-environment-variables"><span>2. <wbr/>Inline environment variables</span></a></li></ul></li></ul></li><li><a href="#π-environment-variables"><span>π <wbr/>Environment <wbr/>Variables</span></a></li><li><a href="#βοΈ-default-behaviors"><span>βοΈ <wbr/>Default <wbr/>Behaviors</span></a></li><li><a href="#π§-programmatic-api"><span>π§ <wbr/>Programmatic API</span></a></li><li><ul><li><a href="#runmode-args"><span>run(mode, args)</span></a></li><li><a href="#payload-fields"><span>Payload fields</span></a></li><li><a href="#examples"><span>Examples</span></a></li></ul></li><li><a href="#π‘-why-use-backtest-kitcli"><span>π‘ <wbr/>Why <wbr/>Use @backtest-<wbr/>kit/cli?</span></a></li><li><a href="#π€-contribute"><span>π€ <wbr/>Contribute</span></a></li><li><a href="#π-license"><span>π <wbr/>License</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">backtest-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
<!-- Yandex.Metrika counter -->
<script type="text/javascript">
(function(m,e,t,r,i,k,a){
m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
})(window, document,'script','https://mc.yandex.ru/metrika/tag.js?id=105455585', 'ym');
ym(105455585, 'init', {ssr:true, webvisor:true, clickmap:true, ecommerce:"dataLayer", accurateTrackBounce:true, trackLinks:true});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/105455585" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-3MQZEBBDDR"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-3MQZEBBDDR');
</script>
|