Parquet + DuckDB storage with REST/WebSocket APIs for Chinese A-share market data. Supports 9 K-line frequencies with dual backend (East Money / Sina) and auto-fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
987 B
Python
40 lines
987 B
Python
"""Serve CLI subcommand: start the API server."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
import typer
|
|
import uvicorn
|
|
from loguru import logger
|
|
|
|
from ashare_dp.config import Settings
|
|
|
|
settings = Settings()
|
|
serve_app = typer.Typer()
|
|
|
|
|
|
@serve_app.command("start")
|
|
def serve(
|
|
host: str = typer.Option(None, help="Bind address"),
|
|
port: int = typer.Option(None, help="Bind port"),
|
|
reload: bool = typer.Option(False, help="Enable auto-reload (dev mode)"),
|
|
):
|
|
"""Start the API server with scheduler."""
|
|
h = host or settings.api_host
|
|
p = port or settings.api_port
|
|
|
|
logger.info(f"Starting API server on {h}:{p}")
|
|
|
|
# Start the realtime poller in a background thread via the app lifespan
|
|
# The FastAPI lifespan handles DB init, scheduler start, and poller start
|
|
|
|
uvicorn.run(
|
|
"ashare_dp.api.app:create_app",
|
|
host=h,
|
|
port=p,
|
|
reload=reload,
|
|
factory=True,
|
|
log_level=settings.log_level.lower(),
|
|
)
|