feat: Add database init on startup and documentation
- Add lifespan handler to main.py for automatic DB table creation - Expand .env.example with detailed variable documentation - Add AUDIT_REPORT.md with comprehensive product/technical review - Add STRATEGY_SCHEMA.md as single source of truth for strategy config - Remove redundant init_db.py script (DB init now handled by app startup)
This commit is contained in:
@@ -1,11 +1,68 @@
|
||||
# Randebu Trading Bot - Environment Variables Template
|
||||
# Copy this file to .env and fill in your values
|
||||
|
||||
# =============================================================================
|
||||
# DATABASE
|
||||
# =============================================================================
|
||||
|
||||
# SQLite database path (relative or absolute)
|
||||
# Example: sqlite:///./data/app.db
|
||||
DATABASE_URL=sqlite:///./data/app.db
|
||||
|
||||
# =============================================================================
|
||||
# AUTHENTICATION
|
||||
# =============================================================================
|
||||
|
||||
# Secret key for JWT token signing
|
||||
# Generate with: python -c "import secrets; print(secrets.token_hex(32))"
|
||||
SECRET_KEY=your-super-secret-key-change-in-production
|
||||
|
||||
# JWT algorithm (HS256 is recommended)
|
||||
JWT_ALGORITHM=HS256
|
||||
|
||||
# Token expiration time in minutes (1440 = 24 hours)
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES=1440
|
||||
|
||||
# =============================================================================
|
||||
# MINIMAX LLM
|
||||
# =============================================================================
|
||||
|
||||
# MiniMax API key (get from https://platform.minimax.chat/)
|
||||
MINIMAX_API_KEY=your-minimax-api-key
|
||||
|
||||
# MiniMax model to use
|
||||
# Common options: MiniMax-Text-01, MiniMax-M2.1
|
||||
MINIMAX_MODEL=MiniMax-Text-01
|
||||
AVE_API_KEY=your-ave-cloud-api-key
|
||||
|
||||
# =============================================================================
|
||||
# AVE CLOUD API
|
||||
# =============================================================================
|
||||
|
||||
# AVE Cloud API key (get from https://cloud.ave.ai/)
|
||||
AVE_API_KEY=your-ave-api-key
|
||||
|
||||
# AVE Cloud plan tier
|
||||
# Options: free, normal, pro
|
||||
# Note: Free tier has 1 TPS limit, Pro required for WebSocket
|
||||
AVE_API_PLAN=free
|
||||
|
||||
# =============================================================================
|
||||
# SERVER CONFIGURATION
|
||||
# =============================================================================
|
||||
|
||||
# Server host (0.0.0.0 for all interfaces)
|
||||
HOST=0.0.0.0
|
||||
|
||||
# Server port
|
||||
PORT=8000
|
||||
|
||||
# Debug mode (set to false in production)
|
||||
DEBUG=false
|
||||
|
||||
# =============================================================================
|
||||
# FRONTEND CONFIGURATION (for reference)
|
||||
# =============================================================================
|
||||
|
||||
# Frontend environment variables (set in frontend .env file):
|
||||
# VITE_API_URL=https://bot.yourdomain.com/api
|
||||
# VITE_WS_URL=wss://bot.yourdomain.com/ws
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from slowapi import Limiter
|
||||
from slowapi.util import get_remote_address
|
||||
from .api import auth, bots, backtest, simulate, config, ave
|
||||
from .core.limiter import limiter
|
||||
from .core.database import engine, Base
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Initialize database on startup."""
|
||||
# Import all models to ensure they're registered
|
||||
from .db.models import User, Bot, BotConversation, Backtest, Simulation, Signal
|
||||
|
||||
# Create tables if they don't exist
|
||||
Base.metadata.create_all(bind=engine)
|
||||
logger.info("Database initialized successfully")
|
||||
|
||||
yield
|
||||
# Cleanup on shutdown if needed
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Randebu Trading Bot API",
|
||||
description="AI-powered trading bot platform API",
|
||||
version="0.1.0",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
app.state.limiter = limiter
|
||||
|
||||
Reference in New Issue
Block a user