mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 19:14:16 +08:00
- Board analysis: list/members/belong/summary/ranking/change-ranking (6) - Capital flow, symbol info, server info (3) - Quote list, auction, unusual (3) - Extended market: bars/quote/minute/transaction (4) - Technical indicators: list + compute (2) - Multi-client DI: AsyncMacClient + AsyncExTdxClient lifecycle - 6 MAC enum converters, DictResponse, ComputeIndicatorsRequest schemas - Web API endpoints: 22 → 40 Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""技术指标路由:指标列表、指标计算。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import pandas as pd
|
|
from fastapi import APIRouter
|
|
|
|
from easy_tdx.web.schemas import ComputeIndicatorsRequest, DataFrameResponse
|
|
|
|
router = APIRouter(tags=["indicator"])
|
|
|
|
|
|
def _df_resp(df: Any) -> DataFrameResponse:
|
|
return DataFrameResponse.from_dataframe(df)
|
|
|
|
|
|
@router.get("/indicator/list")
|
|
async def indicator_list() -> list[dict[str, Any]]:
|
|
"""获取所有可用技术指标列表。"""
|
|
from easy_tdx.indicator import list_indicators
|
|
|
|
return list_indicators()
|
|
|
|
|
|
@router.post("/indicator/compute", response_model=DataFrameResponse)
|
|
async def indicator_compute(
|
|
req: ComputeIndicatorsRequest,
|
|
) -> DataFrameResponse:
|
|
"""在 OHLCV 数据上计算技术指标。
|
|
|
|
请求体包含 K 线 records 和指标名称列表,返回计算后的 DataFrame。
|
|
"""
|
|
from easy_tdx.indicator import compute_indicators
|
|
|
|
df = pd.DataFrame(req.data)
|
|
result = compute_indicators(
|
|
df,
|
|
indicators=req.indicators,
|
|
params=req.params,
|
|
keep_ohlcv=req.keep_ohlcv,
|
|
tail=req.tail,
|
|
)
|
|
return _df_resp(result)
|