Install:
pip install -e .Test:
pytest tests/test_equity_historical.py -v
pytest tests/ -k "equity" -vBuild:
python -m openbb_tdx.openbb buildEntry Points:
openbb_tdx/provider.py- Provider registration (tdxquant), fetcher dictopenbb_tdx/router.py- FastAPI route definitions with@router.command()openbb_tdx/models/*.py- Fetcher classes inheritingFetcher[QueryParams, Data]openbb_tdx/utils/helpers.py- Data fetching (tdx_download,check_cache)
Data Flow: Router → Fetcher.transform_query → Fetcher.extract_data → Fetcher.transform_data → Response
Key Patterns:
- All fetchers must implement:
transform_query(params),extract_data(query, credentials),transform_data(query, data) - Use
__json_schema_extra__formultiple_items_allowedon symbols - Use
__alias_dict__for Chinese→English field mapping (e.g.,"date": "日期")
TdxQuant Client (tqcenter.tq):
- Must have TongDaXin client running and logged in
- SDK only available on Windows;
tq.initialize(__file__)used in extract_data - Mock
tqcenter.tqin tests
Normalization:
- Use
normalize_symbol()frommysharelib.toolsfor all stock codes - Converts various formats to
{code}.{market}(e.g.,600519.SH)
Caching:
TableCache(EQUITY_HISTORY_SCHEMA, project=project_name, table_name=f"{market}{symbol_b}", primary_key="date")check_cache()validates TTL by comparing cache max date withlast_closing_day()
Mock TdxQuant:
from unittest.mock import patch
with patch('tqcenter.tq') as mock_tq:
# test codeTest Structure:
- Tests in
tests/directory, one file per feature - Test fetcher methods:
transform_query(),extract_data(),transform_data() - Verify
EmptyDataErroron empty results
Check .trae/specs/ before implementing:
spec.md- Requirements and designtasks.md- Implementation taskschecklist.md- Validation checklist
- Windows only:
tqcenter.tqSDK requires Windows - Initializes in extract_data:
tq.initialize(__file__)is called per symbol fetch - Period mapping:
"daily"→"1d","weekly"→"1w","monthly"→"1m" - Date format: Input dates passed to TdxQuant must be
YYYYMMDDstring - Standard params: Query params automatically include
start_date,end_dateif not provided