feat: complete BTC ML trading strategy optimizer

Multi-machine optimization loop:
- VPS orchestrator coordinates training and LLM analysis
- Windows PC (RTX 4070 Ti) runs XGBoost/LightGBM/CatBoost with GPU
- Mac Mini runs qwen3.5:27b via Ollama for strategy analysis

Includes 60+ technical features, walk-forward validation,
confidence-scaled position sizing, and automated convergence detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
BizzleBot
2026-03-19 21:25:44 +00:00
co-authored by Claude Opus 4.6
parent 7b9a4bfde7
commit 8ff35c1a86
13 changed files with 1420 additions and 2 deletions
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
"""Fetch BTC/USDT OHLCV data from Binance using ccxt."""
import os
import sys
import time
import ccxt
import pandas as pd
from datetime import datetime, timezone
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data")
SYMBOL = "BTC/USDT"
EXCHANGE_ID = "binance"
YEARS_HISTORY = 2
LIMIT_PER_REQUEST = 1000 # Binance max
def fetch_ohlcv(timeframe: str) -> pd.DataFrame:
"""Fetch OHLCV data for a given timeframe."""
exchange = ccxt.binance({"enableRateLimit": True})
# Calculate start time
now_ms = int(time.time() * 1000)
if timeframe == "1h":
ms_per_candle = 3600 * 1000
elif timeframe == "4h":
ms_per_candle = 4 * 3600 * 1000
else:
raise ValueError(f"Unsupported timeframe: {timeframe}")
since = now_ms - (YEARS_HISTORY * 365 * 24 * 3600 * 1000)
all_candles = []
print(f" Fetching {SYMBOL} {timeframe} from {datetime.fromtimestamp(since / 1000, tz=timezone.utc).strftime('%Y-%m-%d')}...")
while since < now_ms:
try:
candles = exchange.fetch_ohlcv(SYMBOL, timeframe, since=since, limit=LIMIT_PER_REQUEST)
except Exception as e:
print(f" Warning: fetch error, retrying in 5s — {e}")
time.sleep(5)
continue
if not candles:
break
all_candles.extend(candles)
since = candles[-1][0] + ms_per_candle
sys.stdout.write(f"\r Downloaded {len(all_candles)} candles...")
sys.stdout.flush()
time.sleep(exchange.rateLimit / 1000)
print(f"\r Downloaded {len(all_candles)} candles total.")
df = pd.DataFrame(all_candles, columns=["timestamp", "open", "high", "low", "close", "volume"])
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms", utc=True)
df = df.drop_duplicates(subset=["timestamp"]).sort_values("timestamp").reset_index(drop=True)
return df
def main():
os.makedirs(DATA_DIR, exist_ok=True)
for tf in ["1h", "4h"]:
print(f"\n[*] Fetching {tf} data...")
df = fetch_ohlcv(tf)
out_path = os.path.join(DATA_DIR, f"btc_{tf}.csv")
df.to_csv(out_path, index=False)
print(f" Saved {len(df)} rows to {out_path}")
print(f" Range: {df['timestamp'].iloc[0]}{df['timestamp'].iloc[-1]}")
print("\nData fetch complete!")
if __name__ == "__main__":
main()
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Setup Windows PC (100.76.218.38) with ML dependencies for BTC optimizer
set -euo pipefail
WINDOWS_HOST="bizzle@100.76.218.38"
REMOTE_DIR="~/btc-ml-optimizer"
echo "=== BTC ML Optimizer — Windows PC Setup ==="
echo "Target: $WINDOWS_HOST"
echo ""
# Create project directory on Windows
echo "[1/3] Creating project directory..."
ssh "$WINDOWS_HOST" "mkdir -p $REMOTE_DIR"
# Install PyTorch with CUDA support + ML libraries
echo "[2/3] Installing Python dependencies (this may take a while)..."
ssh "$WINDOWS_HOST" "pip install --upgrade pip && \
pip install torch --index-url https://download.pytorch.org/whl/cu128 && \
pip install xgboost lightgbm catboost optuna && \
pip install pandas numpy scikit-learn ta"
# Verify installations
echo "[3/3] Verifying installations..."
ssh "$WINDOWS_HOST" "python -c \"
import torch
print(f'PyTorch {torch.__version__}, CUDA available: {torch.cuda.is_available()}')
if torch.cuda.is_available():
print(f' GPU: {torch.cuda.get_device_name(0)}')
import xgboost; print(f'XGBoost {xgboost.__version__}')
import lightgbm; print(f'LightGBM {lightgbm.__version__}')
import catboost; print(f'CatBoost {catboost.__version__}')
import optuna; print(f'Optuna {optuna.__version__}')
import pandas; print(f'Pandas {pandas.__version__}')
import numpy; print(f'NumPy {numpy.__version__}')
import ta; print('ta library OK')
import sklearn; print(f'scikit-learn {sklearn.__version__}')
print('All dependencies verified!')
\""
echo ""
echo "=== Setup complete! ==="