
- 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
69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
from datetime import datetime, timedelta
|
|
from typing import Any
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.config import settings
|
|
from app.db.session import get_db
|
|
from app.models.arbitrage import ArbitrageOpportunity, Trade
|
|
from app.schemas.arbitrage import StatusResponse
|
|
from app.services.solana import get_wallet_balance
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=StatusResponse)
|
|
async def get_system_status(db: Session = Depends(get_db)) -> Any:
|
|
"""
|
|
Get current system status including:
|
|
- System configuration
|
|
- Wallet balance (if connected)
|
|
- Active opportunities count
|
|
- Recent trade statistics
|
|
"""
|
|
# Get count of active opportunities
|
|
active_opportunities_count = db.query(ArbitrageOpportunity).filter(
|
|
ArbitrageOpportunity.is_viable.is_(True)
|
|
).count()
|
|
|
|
# Get trade stats for last 24 hours
|
|
yesterday = datetime.utcnow() - timedelta(days=1)
|
|
recent_trades = db.query(Trade).filter(
|
|
Trade.created_at >= yesterday,
|
|
Trade.tx_status == "success"
|
|
).all()
|
|
|
|
# Calculate profit
|
|
profit_last_24h_usd = sum(trade.profit_amount_usd for trade in recent_trades)
|
|
|
|
# Get wallet balance
|
|
wallet_balance_sol = None
|
|
wallet_balance_usdc = None
|
|
wallet_connected = False
|
|
|
|
if settings.WALLET_KEYPAIR_PATH:
|
|
wallet_connected = True
|
|
try:
|
|
balances = get_wallet_balance()
|
|
wallet_balance_sol = balances.get("SOL", 0.0)
|
|
wallet_balance_usdc = balances.get("USDC", 0.0)
|
|
except Exception:
|
|
# If there's an error getting balance, we'll just return None
|
|
pass
|
|
|
|
return {
|
|
"status": "running",
|
|
"version": settings.VERSION,
|
|
"network": settings.SOLANA_NETWORK,
|
|
"execution_enabled": settings.EXECUTION_ENABLED,
|
|
"scan_interval_seconds": settings.SCAN_INTERVAL_SECONDS,
|
|
"last_scan_time": None, # Will be populated when the scanner is implemented
|
|
"monitored_tokens_count": len(settings.MONITORED_TOKENS),
|
|
"enabled_dexes": settings.ENABLED_DEXES,
|
|
"wallet_connected": wallet_connected,
|
|
"wallet_balance_sol": wallet_balance_sol,
|
|
"wallet_balance_usdc": wallet_balance_usdc,
|
|
"active_opportunities_count": active_opportunities_count,
|
|
"trades_last_24h": len(recent_trades),
|
|
"profit_last_24h_usd": profit_last_24h_usd
|
|
} |