Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ ADMIN_AUTH_ENABLED=false
# Data Fetcher Priority Configuration
# ===========================================
# Lower number = higher priority (tried first)
# Negative priority = disable the fetcher entirely
# Default priorities: efinance(0) > akshare(1) > tushare/pytdx(2) > baostock(3) > yfinance(4)
# For US stocks, set YFINANCE_PRIORITY=0 to use Yahoo Finance first

Expand All @@ -505,6 +506,12 @@ ADMIN_AUTH_ENABLED=false
# YFINANCE_PRIORITY=0
# EFINANCE_PRIORITY=99

# Example: Disable a data fetcher (negative priority = disabled)
# EFINANCE_PRIORITY=-1
# TUSHARE_PRIORITY=-1



# ===========================================
# 实时行情数据源优先级配置
# ===========================================
Expand Down
22 changes: 13 additions & 9 deletions data_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,11 @@ def _init_default_fetchers(self) -> None:
"""
初始化默认数据源列表

优先级动态调整逻辑:
- 如果配置了 TUSHARE_TOKEN:Tushare 优先级提升为 0(最高)
- 优先级数字越小越优先,负优先级表示禁用该数据源
- 如果配置了 TUSHARE_TOKEN:Tushare 优先级提升为 0(与 efinance 同级,
靠 stable sort 顺序保证 Tushare 优先于 efinance)
- 否则按默认优先级:
0. EfinanceFetcher (Priority 0) - 最高优先级
0. EfinanceFetcher (Priority 0)
1. AkshareFetcher (Priority 1)
2. PytdxFetcher (Priority 2) - 通达信
2. TushareFetcher (Priority 2)
Expand All @@ -872,21 +873,24 @@ def _init_default_fetchers(self) -> None:
yfinance = YfinanceFetcher()
longbridge = LongbridgeFetcher() # 长桥(美股/港股兜底,懒加载)

# 初始化数据源列表
# 初始化数据源列表(负优先级 = 禁用)
self._ensure_concurrency_guards()
with self._fetchers_lock:
self._fetchers = [
all_fetchers = [
# Tushare 放在列表首位,当其优先级与 efinance 相同时(均为 0),
# stable sort 会保持此顺序,使 Tushare 优先于 efinance
tushare,
efinance,
akshare,
tushare,
pytdx,
baostock,
yfinance,
longbridge,
]

# 按优先级排序(Tushare 如果配置了 Token 且初始化成功,优先级为 0)
self._fetchers.sort(key=lambda f: f.priority)
# 按优先级排序(优先级数字越小越优先;负优先级 = 禁用)
self._fetchers = sorted(all_fetchers, key=lambda f: f.priority)
# 过滤掉优先级为负的数据源(表示用户显式禁用)
self._fetchers = [f for f in self._fetchers if f.priority >= 0]

# 构建优先级说明
priority_info = ", ".join([f"{f.name}(P{f.priority})" for f in self._get_fetchers_snapshot()])
Expand Down
7 changes: 4 additions & 3 deletions data_provider/tushare_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ def _determine_priority(self) -> int:
config = get_config()

if config.tushare_token and self._api is not None:
# Token 配置且 API 初始化成功,提升为最高优先级
logger.info("✅ 检测到 TUSHARE_TOKEN 且 API 初始化成功,Tushare 数据源优先级提升为最高 (Priority -1)")
return -1
# Token 配置且 API 初始化成功,提升为最高优先级(与 efinance 同级,
# 通过 stable sort 顺序保证 Tushare 在前)
logger.info("✅ 检测到 TUSHARE_TOKEN 且 API 初始化成功,Tushare 数据源优先级提升为最高 (Priority 0)")
return 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Respect explicit TUSHARE_PRIORITY disable setting

When TUSHARE_TOKEN is present, _determine_priority() now unconditionally returns 0, so an explicit TUSHARE_PRIORITY=-1 is ignored and the fetcher remains active. This breaks the new contract introduced in this change (negative priority = disabled) and means users cannot actually disable Tushare in token-enabled environments, even though .env.example now documents that they can.

Useful? React with 👍 / 👎.


# Token 未配置或 API 初始化失败,保持默认优先级
return 2
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- [修复] Agent 模式未生成有效决策仪表盘时保留本地趋势分析的评分、趋势和操作建议,并将强买/强卖 fallback 归一到兼容的 `buy`/`sell` 决策类型,避免首页结果被 `50 / 观望 / 未知` 缺省值覆盖。
- [修复] 持仓快照现价缺失时不再静默回退为持仓成本;当天快照优先使用历史收盘价,仅在缺失时使用实时价 fallback,缺价持仓不再污染市值与未实现盈亏汇总,并为持仓明细返回价格来源、日期、stale 与缺价状态。
- [测试] 补齐 `task_queue` 轻量导入 stub 的股票代码规范化函数,恢复 `tests/test_task_queue_config_sync.py` 收集与运行。
- [新功能] 数据源优先级设为负值时视为禁用:设置 `EFINANCE_PRIORITY=-1` 等即可关闭对应 fetcher;Tushare 内部动态提权改为 Priority 0(与 efinance 同级,靠 stable sort 顺序保证优先)。

## [3.14.1] - 2026-04-26
- [测试] 修正大盘复盘 prompt 测试对“明日交易计划”标题的断言,并同步桌面端版本号,恢复发布 gate。
Expand Down