Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
|------|------|
| AI 模型 | [Anspire](https://open.anspire.cn/dsa?share_code=QFBC0FYC)、[AIHubMix](https://inferera.com/?aff=CfMq)、Gemini、OpenAI 兼容、DeepSeek、通义千问、Claude、Ollama 本地模型等 |
| 行情数据 | [TickFlow](https://tickflow.org/auth/register?ref=WDSGSPS5XC)、AkShare、Tushare、Pytdx、Baostock、YFinance、Longbridge |
| 新闻搜索 | [Anspire](https://open.anspire.cn/dsa/?share_code=QFBC0FYC)、[SerpAPI](https://serpapi.com/github-daily-stock-analysis)、[Tavily](https://tavily.com/)、[Bocha](https://open.bocha.cn/)、[Brave](https://brave.com/search/api/)、[MiniMax](https://platform.minimaxi.com/)、SearXNG |
| 新闻搜索 | [Anspire](https://open.anspire.cn/dsa?share_code=QFBC0FYC)、[SerpAPI](https://serpapi.com/github-daily-stock-analysis)、[Tavily](https://tavily.com/)、[Bocha](https://open.bocha.cn/)、[Brave](https://brave.com/search/api/)、[MiniMax](https://platform.minimaxi.com/)、SearXNG |
| 社交舆情 | [Stock Sentiment API](https://api.adanos.org/docs)(Reddit / X / Polymarket,仅美股,可选) |

> 项目默认内置 AkShare、Baostock、YFinance 等免费行情源,可零配置运行;免费源受上游限流、接口变动和网络波动影响,稳定性不保证。长期定时、批量分析或更稳定行情建议配置 TickFlow、Tushare、Longbridge 等 token 型数据源,适用市场、Actions 映射和 fallback 规则见 [数据源配置](docs/full-guide.md#数据源配置)。
Expand Down
31 changes: 31 additions & 0 deletions api/v1/endpoints/decision_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
DecisionSignalReassessRequest,
DecisionSignalReassessErrorResponse,
DecisionSignalReassessResponse,
DecisionSignalReviewMemory,
DecisionSignalStatusUpdateRequest,
)
from src.auth import COOKIE_NAME
Expand Down Expand Up @@ -323,6 +324,36 @@ def get_outcome_stats(
raise _internal_error("Get decision signal outcome stats failed", exc)


@router.get(
"/stocks/{stock_code}/review",
response_model=DecisionSignalReviewMemory,
responses={
**AUTH_RESPONSE,
400: {"model": ErrorResponse, "description": "查询参数非法"},
422: {"model": ErrorResponse, "description": "路径或查询参数校验失败"},
500: {"model": ErrorResponse, "description": "查询失败"},
},
summary="查询单票决策信号复盘摘要",
description=(
"聚合指定股票在当前 engine_version 下的 signal-level outcome/feedback,"
"返回只读低敏 ReviewMemory 摘要;样本不足、unable 率高或数据质量弱时 "
"confidence_adjustment 固定为 observe,仅供观察,不构成交易信号。"
),
operation_id="getDecisionSignalStockReview",
)
def get_stock_review(
stock_code: str,
horizon: Optional[str] = Query(None, description="Optional outcome horizon filter: 1d/3d/5d/10d"),
) -> DecisionSignalReviewMemory:
service = DecisionSignalOutcomeService()
try:
return DecisionSignalReviewMemory(**service.get_stock_review(stock_code, horizon=horizon))
except ValueError as exc:
raise _bad_request(exc)
except Exception as exc:
raise _internal_error("Get decision signal stock review failed", exc)


@router.post(
"/reassess",
response_model=DecisionSignalReassessResponse,
Expand Down
22 changes: 22 additions & 0 deletions api/v1/schemas/decision_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
DecisionSignalOutcomeValue = Literal["hit", "miss", "neutral"]
DecisionSignalFeedbackValue = Literal["useful", "not_useful"]
DecisionSignalFeedbackSource = Literal["web", "api"]
DecisionSignalReviewScope = Literal["stock"]
DecisionSignalConfidenceAdjustment = Literal["upgrade", "downgrade", "neutral", "observe"]


class DecisionSignalCreateRequest(BaseModel):
Expand Down Expand Up @@ -233,6 +235,26 @@ class DecisionSignalOutcomeStatsResponse(BaseModel):
profile_calibration: DecisionSignalProfileCalibration


class DecisionSignalReviewMemory(BaseModel):
"""Read-only, low-sensitivity review summary of DecisionSignal outcomes for one stock.

Aggregated server-side from signal-level outcomes/feedback. Raw evidence,
prompt text, diagnostics, and holdings are intentionally excluded; the
payload is observational context only and must not be used as a trading
signal.
"""

stock_code: str
scope: DecisionSignalReviewScope = "stock"
sample_size: int = Field(0, ge=0)
completed: int = Field(0, ge=0)
hit_rate_pct: Optional[float] = None
avg_return_pct: Optional[float] = None
common_miss_reasons: List[str] = Field(default_factory=list)
confidence_adjustment: DecisionSignalConfidenceAdjustment = "observe"
notes: str = ""


class DecisionSignalFeedbackRequest(BaseModel):
feedback_value: DecisionSignalFeedbackValue
reason_code: Optional[str] = Field(None, json_schema_extra={"maxLength": 64})
Expand Down
5 changes: 4 additions & 1 deletion apps/dsa-desktop/tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ test('renderDesktopShareImage captures the complete local poster and closes its
}
FakeRenderWindow.getAllWindows = () => [];

const mainModule = loadMainModule(t, { browserWindow: FakeRenderWindow });
const mainModule = loadMainModule(t, {
browserWindow: FakeRenderWindow,
platform: 'win32',
});
const sourceWindow = {
isDestroyed: () => false,
webContents: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,16 @@ describe('AlertRuleForm', () => {
expect(screen.queryByText('组合回撤')).not.toBeInTheDocument();
});

it('shows JP/KR options for market region in Chinese UI mode', () => {
it('keeps JP/KR out of market light options in Chinese UI mode', () => {
render(<AlertRuleForm onSubmit={onSubmit} />);

fireEvent.change(screen.getByLabelText('目标范围'), { target: { value: 'market' } });

expect(screen.getByRole('option', { name: 'A 股(cn)' })).toBeInTheDocument();
expect(screen.getByRole('option', { name: '港股(hk)' })).toBeInTheDocument();
expect(screen.getByRole('option', { name: '美股(us)' })).toBeInTheDocument();
expect(screen.getByRole('option', { name: '日股(jp)' })).toBeInTheDocument();
expect(screen.getByRole('option', { name: '韩股(kr)' })).toBeInTheDocument();
expect(screen.queryByRole('option', { name: '日股(jp)' })).not.toBeInTheDocument();
expect(screen.queryByRole('option', { name: '韩股(kr)' })).not.toBeInTheDocument();
});

it('submits a market light status rule payload', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('SettingsField', () => {
);

expect(screen.getByLabelText('TickFlow 日 K 优先级')).toBeInTheDocument();
expect(screen.getByText(/控制 TickFlow 在 A 股日 K 数据源回退链中的尝试顺序/)).toBeInTheDocument();
expect(screen.getByText(/控制 TickFlow 在普通 A 股日 K 回退链中的尝试顺序/)).toBeInTheDocument();
expect(screen.queryByText(/Priority for TickFlow daily K-line fetcher/)).not.toBeInTheDocument();
});
it('uses schema key for TickFlow localization when the runtime item key differs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const LLM_PROVIDER_TEMPLATES: LLMProviderTemplate[] = [
configHint:
'同一 ANSPIRE_API_KEYS 可复用到搜索与 LLM 渠道。以下模型与网关为配置示例,实际可用性请以账号权限和控制台为准;建议先点“测试连接”确认。',
officialSources: [
{ label: 'Anspire Open', url: 'https://open.anspire.cn/?share_code=QFBC0FYC' },
{ label: 'Anspire Open', url: 'https://open.anspire.cn/dsa?share_code=QFBC0FYC' },
{
label: 'LiteLLM OpenAI-compatible',
url: 'https://docs.litellm.ai/docs/providers/openai_compatible',
Expand Down
25 changes: 22 additions & 3 deletions data_provider/tencent_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,30 @@ def _format_tencent_date(date_text: str) -> Optional[str]:
return None


def _lots_to_shares(volume: Any) -> Any:
def _is_star_market(symbol: str) -> bool:
"""Return True for STAR Market codes (688xxx, and 689xxx CDRs).

Accepts Tencent symbols (``sh688111``), bare codes (``688111``) and
suffixed codes (``688111.SH``).
"""
code = (symbol or "").strip().lower()
if code[:2] in ("sh", "sz", "bj"):
code = code[2:]
return code.startswith(("688", "689"))


def _lots_to_shares(volume: Any, symbol: str = "") -> Any:
"""Convert Tencent daily K-line volume to shares.

Tencent reports volume in lots (手, 100 shares) for most A-shares, but in
shares (股) for STAR Market stocks (688/689). Multiplying STAR Market volume
by 100 inflates it 100x (Refs #2350).
"""
try:
return float(volume) * 100
value = float(volume)
except (TypeError, ValueError):
return volume
return value if _is_star_market(symbol) else value * 100


def _extract_kline_rows(payload: dict[str, Any], *, symbol: str) -> list[dict[str, Any]]:
Expand All @@ -253,7 +272,7 @@ def _extract_kline_rows(payload: dict[str, Any], *, symbol: str) -> list[dict[st
"close": row[2],
"high": row[3],
"low": row[4],
"volume": _lots_to_shares(row[5]),
"volume": _lots_to_shares(row[5], symbol),
"amount": amount,
}
)
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- [新功能] 支持 Multi-Agent 分阶段轨迹评估:保留既有扁平工具指标并增加阶段快照、局部/累计步数、完成/失败/跳过状态与可选期望阶段命中率,单 Agent 输出保持兼容(Refs #2347)。
- [修复] Multi-Agent 各阶段的 `tool_metrics` 仅统计阶段本地调用,不再将样例级工具期望和步数预算错误应用到每个阶段。
- [修复] Multi-Agent 顶层轨迹步数改由阶段快照累计,避免将 orchestrator 阶段数误判为 agent-loop 步数并漏报全局预算超限。
- [修复] 腾讯日线对科创板(688/689)返回的成交量单位是「股」而非「手」,此前统一乘以 100 导致科创板 `volume` 偏大 100 倍;现按号段区分换算。已入库的历史数据需限定 `data_source = 'TencentFetcher'` 迁移修正(Fixes #2350)。
- [新功能] Web/API runtime scheduler 硬超时后扫描已落库分析历史,**默认发送**部分完成通知(`DSA_TIMEOUT_PARTIAL_NOTIFY` 未设置或为 true;此前超时不推送已落库个股),并在 `last_error` 中记录 `completed/pending` 摘要;可用 `DSA_TIMEOUT_PARTIAL_NOTIFY=false` 关闭推送(Refs #2328)。
- [测试] 修复股票名称解析冷启动超时并发测试的同步竞态:在放行后台抓取前确认两个等待者均已结束并返回空结果,避免 Docker 发布门禁偶发失败。
- [文档] 将仓库内所有 SerpApi 链接统一更新为新的赞助转化追踪地址。
Expand Down Expand Up @@ -42,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- [测试] 新增 Bot 指数入口 transport-independent 在线 E2E smoke(`scripts/smoke_bot_index_entry.py`):worker 子进程经真实 `CommandDispatcher.dispatch_async` 提交并在同进程轮询 `TaskService` 贯穿到 `StockAnalysisPipeline`,父进程只负责 deadline、进程树清理(Windows `taskkill /T /F`、POSIX 杀进程组)与退出码(0=成功/1=失败/124=超时),输出单行 `E2E_EVENT {json}` 事件(`phase=submitted|completed|failed|timeout`);smoke 覆盖 `SH.000016`/`上证50`/`930955.CSI` 矩阵,期望 code/name 取脚本内置权威映射(不信任响应/结果自报身份,提交 code mismatch 输出含期望值与实际值的显式错误并携带结构化实际 `stock_code`,dispatcher 路由错误也失败),矩阵外 target 与非正 `--timeout` 在提交与 spawn 之前即被拒绝(退出码 2),completed 须 exact canonical code、exact 注册名称且 `analysis_summary`/`operation_advice`/`trend_prediction` 非空(仅空白视为空),失败或结果不完整即非零退出;超时清理进程树(Windows `taskkill /T /F`、POSIX 杀进程组),清理成功输出 `timeout` 事件并退出 124、清理失败输出含清理错误的 `failed` 事件并退出 1,不回滚 DB/报告/通知副作用;用户 Ctrl-C 中止时父进程同样先清理进程树,清理成功透传中断、清理失败输出含清理错误的 `failed` 事件并退出 1,绝不静默吞掉清理失败;worker 意外异常输出 `failed` 事件并退出 1(stderr 保留异常证据,`KeyboardInterrupt` 不按普通失败处理),父进程将 worker 任意其他退出码归一化为 1(运行时契约只暴露 0/1/124);父进程以内部 `--worker` flag 显式拉起子进程(不依赖环境变量,防外部预置绕过硬超时);不 mock 在线依赖、不 dry-run、不修 transport,不加入离线 gate。
- [新功能] Bot `/analyze` 支持已登记指数入口:显式代码(`sh000016`)、CSI alias(`930955.CSI` 收敛为 `csi930955`)与注册中文名(`上证50`)均可提交,指数以结构化 `AnalysisTarget` 经 `TaskService` 贯穿到 Pipeline `process_single_stock`(`sh000016` 不再被改写为 `SH000016`);注册名称查询独立于 parser identity alias(中文名不进入 `find_by_explicit_key`/`parse_analysis_target`),同名歧义返回明确错误并要求显式代码,未登记 CSI 与未知名称返回明确错误且不提交任务;个股代码(A/HK/US)保持既有 legacy code 路径不变,股票名称输入(如 `贵州茅台`)由本次 Bot 入口新暴露——复用既有名称解析器(`resolve_name_to_code`)解析后提交 legacy code,不携带结构化 target;提交成功响应在 `BotResponse.extra` 暴露内部任务 identity(`task_id`/`stock_code`)供在线验收等内部流程使用,文本与错误路径不变、平台适配器可忽略 `extra`。
- [新功能] 新增最小 Agent 轨迹评估入口 `evals/agent_trajectory/`(Refs #1956):纯函数指标层只消费真实 `tool_calls_log + AgentResult`,冻结最小指标契约(工具命中、冗余/缓存、失败/重试、总步数/max_steps),`run_eval.py` 经 `build_agent_executor` 真实执行并输出文本摘要 + 结构化 JSON 报告;评估为 reporter 非 gate,零 `src/` 改动
- [新功能] 新增单票决策信号复盘摘要:只读接口 `GET /api/v1/decision-signals/stocks/{stock_code}/review` 返回低敏 ReviewMemory 契约(样本量、命中率、常见 miss 原因、置信度调整方向),样本不足、unable 率高或数据质量弱时固定为 observe 仅观察;`AGENT_MEMORY_ENABLED=true` 时 Agent 记忆以独立 section 注入该复盘摘要,flag 关闭时行为不变(#1903)

- [修复] 将 litellm 依赖窗口上界收敛到 `<1.99.0`:1.99.0 起把 `prompt_cache_key` 透传给 OpenAI provider,破坏 provider 缓存测试对不透传行为的既有断言(CI backend-tests 3/3 与 backend-gate 失败);保留历史最低版本与 `!=1.82.7`/`!=1.82.8` 事故排除,同时同步更新各 LLM 兼容文档中写死的依赖约束表述,避免文档与 requirements.txt 漂移

Expand Down
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ OPENAI_MODEL=deepseek-v4-flash
- 若 Ollama 和程序不在同一主机,需将 `OLLAMA_API_BASE` 改为实际 IP,如 `http://192.168.1.100:11434`。
- 确认防火墙已放行 11434 端口,且 Ollama 启动时绑定了正确地址(`OLLAMA_HOST=0.0.0.0:11434`)。

> 完整配置示例见 [LLM 配置指南 → 示例 4(Ollama)](LLM_CONFIG_GUIDE.md#example-4-ollama)。
> 完整配置示例见 [LLM 配置指南 → 示例 4(Ollama)](LLM_CONFIG_GUIDE.md#示例-4使用-ollama-本地模型)。

---

Expand Down
2 changes: 1 addition & 1 deletion docs/FAQ_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Work through the following 5 checkpoints in order:
- If Ollama runs on a different host, set `OLLAMA_API_BASE` to its actual IP, e.g. `http://192.168.1.100:11434`.
- Make sure port 11434 is open and Ollama binds the right address (`OLLAMA_HOST=0.0.0.0:11434`).

> See [LLM Config Guide → Example 4 (Ollama)](LLM_CONFIG_GUIDE_EN.md#example-4-ollama) for a complete configuration example.
> See [LLM Config Guide → Example 4 (Ollama)](LLM_CONFIG_GUIDE_EN.md#example-4-using-ollama-local-models) for a complete configuration example.

---

Expand Down
10 changes: 5 additions & 5 deletions docs/LLM_CONFIG_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

1. **【新手小白】** "我只想赶紧把系统跑起来,越简单越好!" -> [指路【方式一:极简单模型配置】](#方式一极简单模型配置适合新手)
2. **【进阶用户】** "我有好几个 Key,想配置备用模型,还要改自定义网址(Base URL)。" -> [指路【方式二:渠道(Channels)模式配置】](#方式二渠道channels模式配置适合进阶多模型)
3. **【高玩老手】** "我要做复杂的负载均衡、请求路由、甚至多异构平台高可用!" -> [指路【方式三:YAML 高级配置】](#方式三yaml高级配置适合老手自定义)
3. **【高玩老手】** "我要做复杂的负载均衡、请求路由、甚至多异构平台高可用!" -> [指路【方式三:YAML 高级配置】](#方式三yaml-高级配置适合老手自定义)
4. **【本地模型】** "我想用 Ollama 本地模型!" -> [指路【示例 4:使用 Ollama 本地模型】](#示例-4使用-ollama-本地模型)
5. **【视觉模型】** "我想用图片识别股票代码!" -> [指路【扩展功能:看图模型(Vision)配置】](#扩展功能看图模型vision配置)
5. **【视觉模型】** "我想用图片识别股票代码!" -> [指路【扩展功能:看图模型(Vision)配置】](#扩展功能看图模型-vision-配置)

---

Expand Down Expand Up @@ -107,13 +107,13 @@ Web 启用步骤:打开「设置 → Agent 设置 → 问股生成方式」,

### Anspire Open 示例:

> 💡 **推荐 [Anspire Open](https://open.anspire.cn/?share_code=QFBC0FYC)**:支持中文优化的联网搜索与 OpenAI-compatible 路径一体化体验,适合只准备一个 Key 的用户。
> 💡 **推荐 [Anspire Open](https://open.anspire.cn/dsa?share_code=QFBC0FYC)**:支持中文优化的联网搜索与 OpenAI-compatible 路径一体化体验,适合只准备一个 Key 的用户。
> - 以下为配置示例,模型与网关可用性以账号权限和 Anspire 控制台为准;文档示例不替代实际连通性验证。
> - 建议在 Web 设置页点击“测试连接”进行实际鉴权与模型可用性检查,避免以文档默认值直接当作可用性承诺。

```env
# Anspire Open API Keys(支持多个,逗号分隔)
# 获取: https://open.anspire.cn/?share_code=QFBC0FYC
# 获取: https://open.anspire.cn/dsa?share_code=QFBC0FYC
# 满足默认优先级条件时,系统会复用该 Key 处理搜索与 LLM(仅限示例兜底路径)。
# 示例模型:Doubao-Seed-2.0-lite;示例网关:https://open-gateway.anspire.cn/v6
ANSPIRE_API_KEYS=sk-xxxxxxxxxxxxxxxx
Expand Down Expand Up @@ -203,7 +203,7 @@ LITELLM_MODEL=ollama/qwen3:8b
- OpenAI Compatible 规范(LiteLLM):<https://docs.litellm.ai/docs/providers/openai_compatible>
- OpenAI 官方:<https://platform.openai.com/docs/api-reference/chat>
- DeepSeek 官方:<https://api-docs.deepseek.com/>
- Anspire Open:<https://open.anspire.cn/?share_code=QFBC0FYC>
- Anspire Open:<https://open.anspire.cn/dsa?share_code=QFBC0FYC>
- 阿里百炼 DashScope 兼容模式:<https://help.aliyun.com/zh/model-studio/compatibility-of-openai-with-dashscope>
- Moonshot / Kimi 官方:<https://platform.moonshot.ai/docs/guide/compatibility>
- Anthropic 官方:<https://docs.anthropic.com/en/api/messages>
Expand Down
Loading
Loading