- Complete MVP for tracking Fidelity brokerage account performance - Transaction import from CSV with deduplication - Automatic FIFO position tracking with options support - Real-time P&L calculations with market data caching - Dashboard with timeframe filtering (30/90/180 days, 1 year, YTD, all time) - Docker-based deployment with PostgreSQL backend - React/TypeScript frontend with TailwindCSS - FastAPI backend with SQLAlchemy ORM Features: - Multi-account support - Import via CSV upload or filesystem - Open and closed position tracking - Balance history charting - Performance analytics and metrics - Top trades analysis - Responsive UI design Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
39 lines
910 B
Python
39 lines
910 B
Python
"""
|
|
Database configuration and session management.
|
|
Provides SQLAlchemy engine and session factory.
|
|
"""
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from app.config import settings
|
|
|
|
# Create SQLAlchemy engine
|
|
engine = create_engine(
|
|
settings.database_url,
|
|
pool_pre_ping=True, # Enable connection health checks
|
|
pool_size=10,
|
|
max_overflow=20
|
|
)
|
|
|
|
# Create session factory
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# Base class for SQLAlchemy models
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
"""
|
|
Dependency function that provides a database session.
|
|
Automatically closes the session after the request is completed.
|
|
|
|
Yields:
|
|
Session: SQLAlchemy database session
|
|
"""
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|