DiTus 0df8547d96 Fix: Signal date tracking and indicator real-time updates
Issue 1: Only update lastSignalDate when signal type changes (BUY→SELL or SELL→BUY)
- Modified clearIndicatorCaches() to accept clearSignalState parameter
- When new candle completes: only clear cachedResults/cachedMeta (not signal state)
- When timeframe changes: clear everything including signal tracking
- This preserves signal change history across multiple candles

Issue 2: Indicator lines not updating when new candles arrive
- Added updateIndicatorCandles() function to update existing series
- Instead of removing and recreating series, now uses .setData() to update
- Called when new candle is detected to update indicator lines
- Chart renders correctly with new data after each candle completion

Both issues now resolved:
1. Shows last crossover date only when signal actually changes
2. Indicator lines update in real-time when new candles complete
2026-03-01 20:07:12 +01:00
2026-02-26 23:47:10 +01:00

BTC Trading Dashboard

A Bitcoin trading dashboard with FastAPI backend, PostgreSQL database, and technical analysis features.

Architecture

  • Backend: FastAPI (Python)
  • Frontend: HTML/JS dashboard with lightweight-charts
  • Database: PostgreSQL (connects to NAS)
  • Features:
    • Real-time candle data
    • Technical indicators (SMA, EMA, RSI, MACD, Bollinger Bands, etc.)
    • Trading strategy simulation
    • Backtesting

Prerequisites

  • Python 3.9+
  • PostgreSQL database (on NAS at 20.20.20.20:5433)

Setup

1. Virtual Environment

python -m venv venv

2. Install Dependencies

venv\Scripts\activate
pip install -r requirements.txt

3. Configure Database

Edit .env file:

DB_HOST=20.20.20.20
DB_PORT=5433
DB_NAME=btc_data
DB_USER=btc_bot
DB_PASSWORD=your_password

4. Test Database Connection

python test_db.py

Running the Server

Quick Start

Windows:

start_dev.cmd

Linux/Mac:

chmod +x start_dev.sh
./start_dev.sh

Manual Start

venv\Scripts\activate
uvicorn src.api.server:app --reload --host 0.0.0.0 --port 8000

Access the Application

Once the server is running:

Project Structure

.
├── config/
│   └── data_config.yaml       # Data collection configuration
├── src/
│   ├── api/
│   │   ├── server.py          # FastAPI application
│   │   └── dashboard/         # Frontend static files
│   ├── data_collector/        # Data collection modules
│   │   ├── main.py            # Data collector service
│   │   ├── database.py        # Database manager
│   │   ├── websocket_client.py # WebSocket client
│   │   ├── indicator_engine.py # Technical indicators
│   │   ├── brain.py           # Trading logic
│   │   └── backtester.py      # Backtesting engine
│   └── strategies/            # Trading strategies
│       ├── base.py           # Base strategy class
│       └── ma_strategy.py    # Moving average strategy
├── .env                       # Environment variables
├── requirements.txt           # Python dependencies
└── test_db.py                # Database connection test

API Endpoints

Endpoint Method Description
/ GET API info
/api/v1/health GET System health check
/api/v1/candles GET Get candle data
/api/v1/strategies GET List available strategies
/api/v1/ta GET Technical analysis
/api/v1/stats GET Trading statistics
/api/v1/backtests POST Trigger backtest

Development Tips

  1. Auto-reload: The server reloads automatically when Python files change
  2. Database changes: Restart server to pick up schema changes
  3. Frontend: Edit HTML/JS in src/api/dashboard/static/
  4. Indicators: Add new indicators in src/api/dashboard/static/js/indicators/
  5. Strategies: Create strategies in src/strategies/

Troubleshooting

Port 8000 already in use

netstat -ano | findstr :8000
taskkill /PID <PID> /F

Database connection failed

  1. Check NAS is reachable: ping 20.20.20.20
  2. Verify PostgreSQL is running on NAS
  3. Check .env credentials
  4. Run python test_db.py for diagnosis

No data in dashboard

  1. Verify data collector is running on NAS
  2. Check database has candles table
  3. Use API docs to query data manually
Description
No description provided
Readme 887 KiB
Languages
JavaScript 54.5%
Python 29.8%
HTML 8.8%
CSS 2.8%
Shell 2.4%
Other 1.7%