Skip to content

Commit 3bcca93

Browse files
committed
fix: docusaurus config, sidebar, and tasks docs improvements
- Fix prism-react-renderer import for Docusaurus 3.x compatibility - Fix sidebar.js: replace missing doc IDs with actual files (data-sources, backtest_data) - tasks.md: add class-level attribute pattern alongside constructor pattern - Add show_docs.sh script for running docs locally (with --build option)
1 parent bb348db commit 3bcca93

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

docusaurus/docs/Getting Started/tasks.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ Tasks are automated functions that run on a fixed schedule, independently of you
2222

2323
### Class-Based Task
2424

25-
Subclass `Task` and implement the `run(self, context)` method:
25+
Subclass `Task` and implement the `run(self, context)` method. You can set the schedule using **class-level attributes** or by passing parameters to `__init__`:
26+
27+
**Class-level attributes (recommended for simple tasks):**
28+
29+
```python
30+
from investing_algorithm_framework import Task, TimeUnit
31+
32+
class LogOpenTrades(Task):
33+
time_unit = TimeUnit.MINUTE
34+
interval = 15
35+
36+
def run(self, context):
37+
for trade in context.get_open_trades():
38+
print(f"[{trade.target_symbol}] net_gain={trade.net_gain}")
39+
```
40+
41+
**Constructor parameters:**
2642

2743
```python
2844
from investing_algorithm_framework import Task, TimeUnit
@@ -41,6 +57,8 @@ class PortfolioLoggerTask(Task):
4157
print(f"Currently {len(open_trades)} open trades")
4258
```
4359

60+
Both approaches are equivalent. Class-level attributes are simpler when the schedule is fixed; constructor parameters are useful when you need dynamic configuration.
61+
4462
### Decorator-Based Task
4563

4664
Use `@app.task()` to turn any function into a task:

docusaurus/docusaurus.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// @ts-check
22
// Note: type annotations allow type checking and IDEs autocompletion
33

4-
const lightCodeTheme = require('prism-react-renderer/themes/github');
5-
const darkCodeTheme = require('prism-react-renderer/themes/dracula');
4+
const {themes} = require('prism-react-renderer');
5+
const lightCodeTheme = themes.github;
6+
const darkCodeTheme = themes.dracula;
67

78
/** @type {import('@docusaurus/types').Config} */
89
const config = {

docusaurus/sidebar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ const sidebars = {
6161
},
6262
{
6363
type: 'doc',
64-
id: 'Data/market-data-sources',
64+
id: 'Data/data-sources',
6565
},
6666
{
6767
type: 'doc',
68-
id: 'Data/multiple-market-data-sources',
68+
id: 'Data/backtest_data',
6969
},
7070
],
7171
},

show_docs.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
cd "$(dirname "$0")/docusaurus"
5+
6+
if [ ! -d "node_modules" ]; then
7+
echo "Installing dependencies..."
8+
npm install
9+
fi
10+
11+
if [ "$1" = "--build" ] || [ "$1" = "-b" ]; then
12+
echo "Building docs..."
13+
npm run build
14+
echo "Serving built docs..."
15+
npm run serve
16+
else
17+
echo "Starting Docusaurus dev server..."
18+
npm start
19+
fi

0 commit comments

Comments
 (0)