backtest-kit-docs / documents /begin_02_getting_started_configuration.html
tripolskypetr's picture
patch
615c2b5
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>begin/02_getting_started_configuration | 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="begin_02_getting_started_configuration.html">begin/02_getting_started_configuration</a></li></ul></div><div class="tsd-panel tsd-typography"><a id="getting-started--configuration" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Getting Started &amp; Configuration<a href="#getting-started--configuration" 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><p>This page provides a comprehensive guide for setting up the <strong>news-sentiment-ai-trader</strong> codebase. It covers the installation of system requirements, environment configuration, and the initial execution of the trading system using the integrated CLI.</p>
<a id="system-requirements" class="tsd-anchor"></a><h2 class="tsd-anchor-link">System Requirements<a href="#system-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></h2><p>The system relies on a modern JavaScript runtime and specific AI/search providers.</p>
<table>
<thead>
<tr>
<th>Requirement</th>
<th>Version</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Node.js</strong></td>
<td>≥15.0.0</td>
<td>Core runtime for <code>backtest-kit</code> and <code>ccxt</code>.</td>
</tr>
<tr>
<td><strong>TypeScript</strong></td>
<td>^5.0.0</td>
<td>Static typing and compilation.</td>
</tr>
<tr>
<td><strong>Ollama</strong></td>
<td>≥0.6.3</td>
<td>Local LLM server for sentiment inference.</td>
</tr>
<tr>
<td><strong>Tavily API</strong></td>
<td>-</td>
<td>Web search for real-time news retrieval.</td>
</tr>
</tbody>
</table>
<hr>
<a id="installation--setup" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Installation &amp; Setup<a href="#installation--setup" 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="1-clone-and-install-dependencies" class="tsd-anchor"></a><h3 class="tsd-anchor-link">1. Clone and Install Dependencies<a href="#1-clone-and-install-dependencies" 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 project uses <code>npm</code> to manage its dependencies, which include the <code>backtest-kit</code> framework and the <code>agent-swarm-kit</code> for LLM orchestration.</p>
<pre><code class="bash"><span class="hl-0">git</span><span class="hl-1"> </span><span class="hl-2">clone</span><span class="hl-1"> </span><span class="hl-2">https://github.com/tripolskypetr/backtest-kit.git</span><span class="hl-1"> </span><span class="hl-2">backtest-kit-main</span><br/><span class="hl-0">cd</span><span class="hl-1"> </span><span class="hl-2">backtest-kit-main/example</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span>
</code><button type="button">Copy</button></pre>
<p>The core logic depends on several specialized packages defined in the manifest:</p>
<ul>
<li><code>@backtest-kit/cli</code>: Provides the command-line interface.</li>
<li><code>agent-swarm-kit</code>: Manages the multi-agent LLM forecasting logic.</li>
<li><code>ollama</code>: Interface for the local LLM.</li>
<li><code>ccxt</code>: Handles exchange connectivity for market data.</li>
</ul>
<a id="2-environment-configuration" class="tsd-anchor"></a><h3 class="tsd-anchor-link">2. Environment Configuration<a href="#2-environment-configuration" 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 system requires two primary API tokens to function. Copy the example environment file and populate it with your credentials:</p>
<pre><code class="bash"><span class="hl-0">cp</span><span class="hl-1"> </span><span class="hl-2">.env.example</span><span class="hl-1"> </span><span class="hl-2">.env</span>
</code><button type="button">Copy</button></pre>
<p><strong>Required Variables:</strong></p>
<ul>
<li><code>OLLAMA_TOKEN</code>: Token for authenticating with your Ollama instance (if required by your setup).</li>
<li><code>TAVILY_TOKEN</code>: API key from <a href="https://tavily.com/">Tavily</a> for news search capabilities.</li>
</ul>
<a id="3-typescript-configuration" class="tsd-anchor"></a><h3 class="tsd-anchor-link">3. TypeScript Configuration<a href="#3-typescript-configuration" 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 project is configured to use <code>ESNext</code> modules with path mapping for the <code>logic/</code> and <code>utils/</code> directories to simplify imports.</p>
<hr>
<a id="data-flow-initialization-to-execution" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Data Flow: Initialization to Execution<a href="#data-flow-initialization-to-execution" 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 following diagram illustrates the transition from environment configuration to the internal code entities that manage the system startup.</p>
<a id="configuration-to-code-entity-mapping" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Configuration to Code Entity Mapping<a href="#configuration-to-code-entity-mapping" 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>&quot;The diagram below bridges the environment variables and configuration files to the internal <code>backtest-kit</code> initialization sequence.&quot;</p>
<p><img src="../media/02-getting-started-configuration_0.svg" alt="Mermaid Diagram"></p>
<hr>
<a id="running-the-system" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Running the System<a href="#running-the-system" 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="cli-execution" class="tsd-anchor"></a><h3 class="tsd-anchor-link">CLI Execution<a href="#cli-execution" 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 system is started via the <code>@backtest-kit/cli</code> package, which is mapped to the <code>start</code> script in <code>package.json</code>.</p>
<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="framework-initialization-sequence" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Framework Initialization Sequence<a href="#framework-initialization-sequence" 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 system starts, it performs several critical steps via the <code>backtest-kit</code> framework:</p>
<ol>
<li><strong>Logger Setup</strong>: The framework requires a logger implementation to be set via <code>setLogger</code> to output operational data.</li>
<li><strong>Global Configuration</strong>: Parameters such as <code>CC_PERCENT_FEE</code> and <code>CC_SCHEDULE_AWAIT_MINUTES</code> are applied to the <code>GLOBAL_CONFIG</code>.</li>
<li><strong>Dependency Injection</strong>: Over 75 services are wired together using <code>di-kit</code> and <code>di-scoped</code>, managing the lifecycle of news fetchers, LLM clients, and backtesting engines.</li>
</ol>
<a id="component-interaction-diagram" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Component Interaction Diagram<a href="#component-interaction-diagram" 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>&quot;This diagram maps the system's runtime components to their respective code modules during a typical execution cycle.&quot;</p>
<p><img src="../media/02-getting-started-configuration_1.svg" alt="Mermaid Diagram"></p>
<hr>
<a id="verification" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Verification<a href="#verification" 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>To ensure the environment is correctly configured, you can verify the framework initialization with a minimal script:</p>
<pre><code class="typescript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-4">getDefaultConfig</span><span class="hl-1">, </span><span class="hl-4">setLogger</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-2">&#39;backtest-kit&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-6">// Verify Logger</span><br/><span class="hl-0">setLogger</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-0">log</span><span class="hl-4">:</span><span class="hl-1"> (</span><span class="hl-4">topic</span><span class="hl-1">, ...</span><span class="hl-4">args</span><span class="hl-1">) </span><span class="hl-3">=&gt;</span><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-4">topic</span><span class="hl-1">, </span><span class="hl-4">args</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-0">debug</span><span class="hl-4">:</span><span class="hl-1"> () </span><span class="hl-3">=&gt;</span><span class="hl-1"> {},</span><br/><span class="hl-1"> </span><span class="hl-0">info</span><span class="hl-4">:</span><span class="hl-1"> () </span><span class="hl-3">=&gt;</span><span class="hl-1"> {},</span><br/><span class="hl-1"> </span><span class="hl-0">warn</span><span class="hl-4">:</span><span class="hl-1"> () </span><span class="hl-3">=&gt;</span><span class="hl-1"> {},</span><br/><span class="hl-1">});</span><br/><br/><span class="hl-6">// Verify Configuration</span><br/><span class="hl-3">const</span><span class="hl-1"> </span><span class="hl-8">config</span><span class="hl-1"> = </span><span class="hl-0">getDefaultConfig</span><span class="hl-1">();</span><br/><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">&#39;Parameters loaded:&#39;</span><span class="hl-1">, </span><span class="hl-4">Object</span><span class="hl-1">.</span><span class="hl-0">keys</span><span class="hl-1">(</span><span class="hl-4">config</span><span class="hl-1">).</span><span class="hl-4">length</span><span class="hl-1">);</span>
</code><button type="button">Copy</button></pre>
<p><strong>Expected Result:</strong> The console should indicate that 14 default parameters have been loaded.</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="#getting-started--configuration"><span>Getting <wbr/>Started &amp; <wbr/>Configuration</span></a><ul><li><a href="#system-requirements"><span>System <wbr/>Requirements</span></a></li><li><a href="#installation--setup"><span>Installation &amp; <wbr/>Setup</span></a></li><li><ul><li><a href="#1-clone-and-install-dependencies"><span>1. <wbr/>Clone and <wbr/>Install <wbr/>Dependencies</span></a></li><li><a href="#2-environment-configuration"><span>2. <wbr/>Environment <wbr/>Configuration</span></a></li><li><a href="#3-typescript-configuration"><span>3. <wbr/>Type<wbr/>Script <wbr/>Configuration</span></a></li></ul></li><li><a href="#data-flow-initialization-to-execution"><span>Data <wbr/>Flow: <wbr/>Initialization to <wbr/>Execution</span></a></li><li><ul><li><a href="#configuration-to-code-entity-mapping"><span>Configuration to <wbr/>Code <wbr/>Entity <wbr/>Mapping</span></a></li></ul></li><li><a href="#running-the-system"><span>Running the <wbr/>System</span></a></li><li><ul><li><a href="#cli-execution"><span>CLI <wbr/>Execution</span></a></li><li><a href="#framework-initialization-sequence"><span>Framework <wbr/>Initialization <wbr/>Sequence</span></a></li><li><a href="#component-interaction-diagram"><span>Component <wbr/>Interaction <wbr/>Diagram</span></a></li></ul></li><li><a href="#verification"><span>Verification</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>