feat(data): 脚手架 + YAML 配置加载
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# config/data_platform.yaml
|
||||
data_paths:
|
||||
daily_dir: /volume1/stock/A股数据/日线数据/daily
|
||||
minute_15_dir: /volume1/stock/minute_kline/15min
|
||||
vnpy_db: /volume1/stock/sanguo_vnpy/data/quant_trading.db
|
||||
stock_list: /volume1/stock/A股数据/stock_info/stock_basic_info_raw_20260326_113530.csv
|
||||
|
||||
data_sources:
|
||||
daily:
|
||||
- name: eastmoney
|
||||
enabled: true
|
||||
interval: 4.0
|
||||
- name: baostock
|
||||
enabled: true
|
||||
interval: 0.0
|
||||
timeout: 30
|
||||
- name: tencent
|
||||
enabled: true
|
||||
interval: 0.0
|
||||
minute_15:
|
||||
- name: eastmoney
|
||||
enabled: true
|
||||
interval: 4.0
|
||||
|
||||
validation:
|
||||
price_positive: true
|
||||
ohlc_consistency: true
|
||||
no_future_dates: true
|
||||
|
||||
performance:
|
||||
request_interval: 0.3
|
||||
max_retries: 3
|
||||
fail_window: 100
|
||||
fail_threshold: 0.8
|
||||
@@ -0,0 +1,3 @@
|
||||
# sanguo_data/__init__.py
|
||||
from .config import DataConfig, load_config
|
||||
__all__ = ["DataConfig", "load_config"]
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# sanguo_data/config.py
|
||||
from dataclasses import dataclass
|
||||
import yaml
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DataConfig:
|
||||
data_paths: dict
|
||||
data_sources: dict
|
||||
validation: dict
|
||||
performance: dict
|
||||
|
||||
def load_config(path: str) -> DataConfig:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
raw = yaml.safe_load(f)
|
||||
return DataConfig(
|
||||
data_paths=raw.get("data_paths", {}),
|
||||
data_sources=raw.get("data_sources", {}),
|
||||
validation=raw.get("validation", {}),
|
||||
performance=raw.get("performance", {}),
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
# tests/data/__init__.py
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
# tests/data/test_config.py
|
||||
from sanguo_data.config import load_config, DataConfig
|
||||
|
||||
def test_load_config_returns_dataconfig(tmp_path):
|
||||
yaml_content = """
|
||||
data_paths:
|
||||
daily_dir: /tmp/daily
|
||||
minute_15_dir: /tmp/15min
|
||||
vnpy_db: /tmp/quant.db
|
||||
stock_list: /tmp/stock.csv
|
||||
data_sources:
|
||||
daily:
|
||||
- name: eastmoney
|
||||
enabled: true
|
||||
interval: 4.0
|
||||
validation:
|
||||
price_positive: true
|
||||
performance:
|
||||
max_retries: 3
|
||||
"""
|
||||
p = tmp_path / "config.yaml"
|
||||
p.write_text(yaml_content)
|
||||
cfg = load_config(str(p))
|
||||
assert isinstance(cfg, DataConfig)
|
||||
assert cfg.data_paths["daily_dir"] == "/tmp/daily"
|
||||
assert cfg.data_sources["daily"][0]["name"] == "eastmoney"
|
||||
assert cfg.performance["max_retries"] == 3
|
||||
Reference in New Issue
Block a user