Merge origin/dev: resolve conflicts in data_provider main.py
This commit is contained in:
+24
-13
@@ -499,7 +499,7 @@ class DataProvider:
|
||||
return results
|
||||
|
||||
def initialize(self) -> None:
|
||||
"""快速启动:仅加载本地 CSV 到内存,立即设 _ready 让服务可用。后台再补拉交易所数据。"""
|
||||
"""快速启动:仅加载本地磁盘已有数据到内存,立即设 _ready 让服务可用。后台再补拉交易所数据。"""
|
||||
logger.info("开始初始化数据提供商(仅加载本地数据)")
|
||||
for symbol in self.symbols:
|
||||
for timeframe in self.timeframes:
|
||||
@@ -922,8 +922,15 @@ def create_app(provider: DataProvider) -> FastAPI:
|
||||
loop = asyncio.get_running_loop()
|
||||
ws_manager.set_loop(loop)
|
||||
provider.on_update(_on_data_update)
|
||||
# 快速加载本地数据后立即就绪,不阻塞服务启动
|
||||
await loop.run_in_executor(None, provider.initialize)
|
||||
provider.start_background_workers()
|
||||
# 后台拉取历史数据补齐(不阻塞 HTTP/WS 服务)
|
||||
threading.Thread(
|
||||
target=provider.run_initial_history_fetch,
|
||||
name="initial-history-fetch",
|
||||
daemon=True,
|
||||
).start()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
@@ -974,18 +981,15 @@ def create_app(provider: DataProvider) -> FastAPI:
|
||||
data = provider.get_klines(symbol=symbol, timeframe=tf, start_time=start, end_time=end, limit=limit)
|
||||
return data
|
||||
|
||||
@app.get("/")
|
||||
async def root() -> Dict[str, object]:
|
||||
"""根路径:服务名、交易所、交易对与可用周期(含 ready 标志)。"""
|
||||
return {
|
||||
"service": "Data Provider",
|
||||
"exchange": provider.exchange_name,
|
||||
"symbols": provider.symbols,
|
||||
"base_timeframes": provider.timeframes,
|
||||
"derived_timeframes": provider.get_derived_timeframes(),
|
||||
"timeframes": provider.get_available_timeframes(),
|
||||
"ready": provider.is_ready(),
|
||||
}
|
||||
homepage_path = Path(__file__).resolve().parent / "homepage.html"
|
||||
docs_path = Path(__file__).resolve().parent / "api_docs.html"
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def root():
|
||||
"""服务主页。"""
|
||||
if homepage_path.exists():
|
||||
return HTMLResponse(content=homepage_path.read_text(encoding="utf-8"))
|
||||
return HTMLResponse(content="<h1>主页页面未找到</h1>", status_code=404)
|
||||
|
||||
@app.get("/api-manual", response_class=HTMLResponse)
|
||||
async def api_manual():
|
||||
@@ -1581,6 +1585,13 @@ document.querySelectorAll('#manualTabs .nav-link').forEach(btn => {{
|
||||
finally:
|
||||
await ws_manager.disconnect(ws)
|
||||
|
||||
@app.get("/api/docs", response_class=HTMLResponse, include_in_schema=False)
|
||||
async def api_docs():
|
||||
"""返回自定义 API 文档页面。"""
|
||||
if docs_path.exists():
|
||||
return HTMLResponse(content=docs_path.read_text(encoding="utf-8"))
|
||||
return HTMLResponse(content="<h1>API 文档页面未找到</h1>", status_code=404)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user