Files
etf/config/settings.py
aszerW 0a8d0d9212 fix: 删除未使用的空目录data_cache
删除内容:
1. data_cache 目录(空目录,无文件)
2. config/settings.py 中的 DATA_CACHE_DIR 定义(第22-25行)

说明:
- 该目录原设计用于CSV文件缓存,但实际未使用
- 当前项目使用 data/etf_cache/daily 作为数据缓存目录
2026-05-12 22:07:54 +08:00

104 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
ETF策略项目 - 通用配置
敏感信息通过环境变量读取,非敏感配置直接定义
"""
import os
from pathlib import Path
# 加载 .env 文件
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
pass # python-dotenv 未安装时跳过
# 项目根目录
PROJECT_ROOT = Path(__file__).parent.parent
# 数据目录
DATA_DIR = PROJECT_ROOT / "data"
# ==================== 钉钉配置 ====================
def get_dingtalk_config() -> dict:
"""从环境变量获取钉钉配置默认群1"""
return {
"webhook": os.getenv("DINGTALK_WEBHOOK", ""),
"secret": os.getenv("DINGTALK_SECRET", ""),
}
def get_all_dingtalk_configs() -> list[dict]:
"""获取所有已配置的钉钉群配置列表"""
configs = []
# 群1主群
cfg1 = get_dingtalk_config()
if cfg1["webhook"]:
configs.append(cfg1)
# 群2 及后续扩展DINGTALK_WEBHOOK_2, _3, ...
for i in range(2, 10):
webhook = os.getenv(f"DINGTALK_WEBHOOK_{i}", "")
secret = os.getenv(f"DINGTALK_SECRET_{i}", "")
if webhook:
configs.append({"webhook": webhook, "secret": secret})
return configs
# ==================== 数据库配置 ====================
def get_db_config() -> dict:
"""从环境变量获取数据库配置"""
return {
"host": os.getenv("DB_HOST", "192.168.0.115"),
"port": int(os.getenv("DB_PORT", "5432")),
"database": os.getenv("DB_NAME", "etf_db"),
"username": os.getenv("DB_USER", "admin"),
"password": os.getenv("DB_PASS", "admin"),
}
# ==================== 代码映射(默认,可被策略配置覆盖)====================
DEFAULT_CODE_NAME_MAP = {
# 宽基
"000300.SH": "沪深300",
"000905.SH": "中证500",
"000852.SH": "中证1000",
"399006.SZ": "创业板指",
"000015.SH": "上证红利",
# 金融
"399986.SZ": "中证银行",
"399975.SZ": "证券公司",
"000934.SH": "中证金融",
# 消费
"000932.SH": "中证消费",
"399997.SZ": "中证白酒",
# 医药
"000933.SH": "中证医药",
"399989.SZ": "中证医疗",
# 科技
"000935.SH": "中证信息",
"399971.SZ": "中证传媒",
# 新能源
"399808.SZ": "中证新能源",
"399976.SZ": "新能源车",
# 周期
"399395.SZ": "国证有色",
"399440.SZ": "中证钢铁",
"399998.SZ": "中证煤炭",
"399813.SZ": "细分化工",
"000937.SH": "中证能源",
"000938.SH": "中证材料",
# 其他
"399967.SZ": "中证军工",
"399393.SZ": "国证地产",
"000827.SH": "中证环保",
"399995.SZ": "中证基建",
"000949.SH": "中证农业",
"399702.SZ": "中证国债指数",
}
# 基准指数(默认,可被策略配置覆盖)
DEFAULT_BENCHMARK_CODE = "000300.SH"
DEFAULT_BENCHMARK_NAME = "沪深300指数"