Compare commits

..

2 Commits

Author SHA1 Message Date
9e05ce0891 fix: prevent price data overwrite on container restart
Preserve existing merged.jsonl to avoid data loss and API rate limits.
Only fetch new data if merged.jsonl is missing or empty.

Problem:
- Entrypoint always fetched fresh data from Alpha Vantage on every start
- Overwrote existing mounted data directory
- Caused API rate limit issues and data inconsistencies
- Lost historical data needed for backtesting specific date ranges

Solution:
- Check if merged.jsonl exists and has content before fetching
- Display stock count when using existing data
- Provide manual refresh instructions for when updates are needed

Benefits:
- Faster container startup (no API calls if data exists)
- Avoids Alpha Vantage rate limits (5 calls/min, 500/day)
- Preserves user's existing historical datasets
- Enables reliable backtesting with consistent data

To refresh data: rm data/merged.jsonl && docker-compose restart
2025-10-30 23:27:58 -04:00
2f2c1d6ea2 feat: simplify Docker config file selection with convention over configuration
Implement automatic detection of custom_config.json for simpler Docker usage.
No environment variables or command-line arguments needed for most users.

Changes:
- entrypoint.sh: Add smart config detection (custom_config.json > CLI arg > default_config.json)
- docker-compose.yml: Add configs volume mount for editing without rebuilds
- docs/DOCKER.md: Update documentation with simplified workflow
- .gitignore: Add custom_config.json to prevent accidental commits

Usage:
  cp configs/default_config.json configs/custom_config.json
  nano configs/custom_config.json
  docker-compose up  # Automatically uses custom_config.json

Simplifies user experience by following convention over configuration principle.
2025-10-30 22:34:22 -04:00
4 changed files with 89 additions and 16 deletions

1
.gitignore vendored
View File

@@ -57,6 +57,7 @@ delete.py
refresh_data.sh
# Config files (optional - uncomment if needed)
configs/custom_config.json
configs/day_config.json
configs/hour_config.json
configs/test_config.json

View File

@@ -7,6 +7,7 @@ services:
volumes:
- ./data:/app/data
- ./logs:/app/logs
- ./configs:/app/configs
environment:
# AI Model API Configuration
- OPENAI_API_BASE=${OPENAI_API_BASE}

View File

@@ -53,10 +53,30 @@ AGENT_MAX_STEP=30
### Custom Trading Configuration
Pass a custom config file:
**Simple Method (Recommended):**
Create a `configs/custom_config.json` file - it will be automatically used:
```bash
docker-compose run ai-trader configs/my_config.json
# Copy default config as starting point
cp configs/default_config.json configs/custom_config.json
# Edit your custom config
nano configs/custom_config.json
# Run normally - custom_config.json is automatically detected!
docker-compose up
```
**Priority order:**
1. `configs/custom_config.json` (if exists) - **Highest priority**
2. Command-line argument: `docker-compose run ai-trader configs/other.json`
3. `configs/default_config.json` (fallback)
**Advanced: Use a different config file name:**
```bash
docker-compose run ai-trader configs/my_special_config.json
```
## Usage Examples
@@ -92,10 +112,11 @@ docker-compose up
### Volume Mounts
Docker Compose mounts two volumes:
Docker Compose mounts three volumes:
- `./data:/app/data` - Price data and trading records
- `./logs:/app/logs` - MCP service logs
- `./configs:/app/configs` - Configuration files (allows editing configs without rebuilding)
Data persists across container restarts. To reset:
@@ -227,13 +248,45 @@ Services exposed on host:
### Test Different Configurations
```bash
# Create test config
cp configs/default_config.json configs/test_config.json
# Edit test_config.json
**Method 1: Use the standard custom_config.json**
# Run with test config
docker-compose run ai-trader configs/test_config.json
```bash
# Create and edit your config
cp configs/default_config.json configs/custom_config.json
nano configs/custom_config.json
# Run - automatically uses custom_config.json
docker-compose up
```
**Method 2: Test multiple configs with different names**
```bash
# Create multiple test configs
cp configs/default_config.json configs/conservative.json
cp configs/default_config.json configs/aggressive.json
# Edit each config...
# Test conservative strategy
docker-compose run ai-trader configs/conservative.json
# Test aggressive strategy
docker-compose run ai-trader configs/aggressive.json
```
**Method 3: Temporarily switch configs**
```bash
# Temporarily rename your custom config
mv configs/custom_config.json configs/custom_config.json.backup
cp configs/test_strategy.json configs/custom_config.json
# Run with test strategy
docker-compose up
# Restore original
mv configs/custom_config.json.backup configs/custom_config.json
```
## Production Deployment

View File

@@ -38,12 +38,18 @@ fi
echo "✅ Environment variables validated"
# Step 1: Data preparation
echo "📊 Fetching and merging price data..."
# Run scripts from /app/scripts but output to /app/data
cd /app/data
python /app/scripts/get_daily_price.py
python /app/scripts/merge_jsonl.py
cd /app
echo "📊 Checking price data..."
if [ -f "/app/data/merged.jsonl" ] && [ -s "/app/data/merged.jsonl" ]; then
echo "✅ Using existing price data ($(wc -l < /app/data/merged.jsonl) stocks)"
echo " To refresh data, delete /app/data/merged.jsonl and restart"
else
echo "📊 Fetching and merging price data..."
# Run scripts from /app/scripts but output to /app/data
cd /app/data
python /app/scripts/get_daily_price.py
python /app/scripts/merge_jsonl.py
cd /app
fi
# Step 2: Start MCP services in background
echo "🔧 Starting MCP services..."
@@ -57,7 +63,19 @@ sleep 3
# Step 4: Run trading agent with config file
echo "🤖 Starting trading agent..."
CONFIG_FILE="${1:-configs/default_config.json}"
# Smart config selection: custom_config.json takes precedence if it exists
if [ -f "configs/custom_config.json" ]; then
CONFIG_FILE="configs/custom_config.json"
echo "✅ Using custom configuration: configs/custom_config.json"
elif [ -n "$1" ]; then
CONFIG_FILE="$1"
echo "✅ Using specified configuration: $CONFIG_FILE"
else
CONFIG_FILE="configs/default_config.json"
echo "✅ Using default configuration: configs/default_config.json"
fi
python main.py "$CONFIG_FILE"
# Cleanup on exit