Spaces:
Sleeping
Sleeping
| """API routes for statistics.""" | |
| from fastapi import APIRouter | |
| from app.services import get_stats_service | |
| from app.models import StatsResponse | |
| router = APIRouter(prefix="/stats", tags=["Statistics"]) | |
| async def get_stats(): | |
| """ | |
| Get comprehensive market statistics. | |
| Includes: | |
| - Total number of trading pairs | |
| - Average funding rate across all pairs | |
| - Highest and lowest funding rate coins | |
| - Count of positive/negative FR coins | |
| - Time until next funding settlement | |
| """ | |
| service = get_stats_service() | |
| return await service.get_stats() | |
| async def get_next_funding_time(): | |
| """ | |
| Get time until next funding settlement. | |
| MEXC funding occurs every 8 hours at 00:00, 08:00, 16:00 UTC. | |
| """ | |
| from app.utils import calculate_next_funding_time | |
| seconds, time_str = calculate_next_funding_time() | |
| # Calculate hours, minutes, seconds | |
| hours = seconds // 3600 | |
| minutes = (seconds % 3600) // 60 | |
| secs = seconds % 60 | |
| return { | |
| "success": True, | |
| "seconds_until_next": seconds, | |
| "next_funding_time": time_str, | |
| "formatted": f"{hours:02d}:{minutes:02d}:{secs:02d}", | |
| } | |