
- Created Alembic migrations for SQLite database - Set up database initialization on app startup - Fixed linting issues with Ruff - Updated README with comprehensive documentation - Configured startup tasks and health checks
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from datetime import datetime
|
|
from typing import Any, Optional
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import desc
|
|
|
|
from app.db.session import get_db
|
|
from app.models.arbitrage import ArbitrageOpportunity
|
|
from app.schemas.arbitrage import OpportunitiesList
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=OpportunitiesList)
|
|
async def get_arbitrage_opportunities(
|
|
viable_only: bool = Query(True, description="Show only viable opportunities that meet profit threshold"),
|
|
token_address: Optional[str] = Query(None, description="Filter by specific token address"),
|
|
min_profit_percent: Optional[float] = Query(None, description="Filter by minimum profit percentage"),
|
|
limit: int = Query(20, ge=1, le=100, description="Number of opportunities to return"),
|
|
offset: int = Query(0, ge=0, description="Pagination offset"),
|
|
db: Session = Depends(get_db)
|
|
) -> Any:
|
|
"""
|
|
Retrieve arbitrage opportunities with optional filtering.
|
|
"""
|
|
query = db.query(ArbitrageOpportunity)
|
|
|
|
# Apply filters
|
|
if viable_only:
|
|
query = query.filter(ArbitrageOpportunity.is_viable.is_(True))
|
|
|
|
if token_address:
|
|
query = query.filter(ArbitrageOpportunity.token_address == token_address)
|
|
|
|
if min_profit_percent is not None:
|
|
query = query.filter(ArbitrageOpportunity.price_difference_percent >= min_profit_percent)
|
|
|
|
# Get total count
|
|
total_count = query.count()
|
|
|
|
# Get paginated results
|
|
opportunities = query.order_by(desc(ArbitrageOpportunity.created_at)).offset(offset).limit(limit).all()
|
|
|
|
return {
|
|
"opportunities": opportunities,
|
|
"count": total_count,
|
|
"timestamp": datetime.utcnow()
|
|
} |