Skip to main content
Glama
BAI2007-Dev

dragon-trading-agent

by BAI2007-Dev

龙头交易Agent · Dragon Trading Agent

A complete system that turns personal trading rules into code: scheduled decision reports + rule engine + MCP Server + desktop conversation Agent.

Python 3.12 · FastAPI · MCP 协议 · LLM Tool-Use · SQLite · PyInstaller

⚠️ Disclaimer

Chinese: This project is for personal programming learning and technical research. It does not constitute any investment advice. Live trading or commercial use is strictly prohibited. All consequences are borne by the user.

English: This project is for personal programming learning and technical research only. It does NOT constitute investment advice. Any use for live trading or commercial purposes is strictly prohibited. All consequences are borne by the user.

Related MCP server: AI-Kline MCP Server

Project Highlights

  • Complete closed loop, not a demo: from scheduled tasks (APScheduler), real market-data collection, and rule-engine decisions to exposing the system to LLMs through MCP Server and desktop chat interaction — a fully runnable system.

  • 21 rule-engine modules: market environment grading, leading-stock consecutive limit-up node theory, swing pullback stock selection, strategy backtesting, risk guardrails, trading memory (lightweight RAG), and performance review — all independently callable.

  • Anti-hallucination design: key market data is cross-validated across two sources; mismatches are flagged as “data questionable”; LLM tool results exist only in the current in-memory turn and are never written back to history, which stores plain text only.

  • Multi-agent decision-making: decision-type questions (should we do it / buy / sell) converge through multiple rounds of debate among 3 analysts + 1 moderator, outputting an action and confidence level.

  • Productized delivery: pywebview desktop client packaged into an exe with a custom icon, and a config panel with key validation; it is also a standard MCP Server that any LLM can call.

System Architecture

                      ┌─────────────────────────────────────────────┐
   行情源              │             规则引擎 (src/, 21 模块)          │
 ┌──────────┐         │                                             │
 │ 东方财富  │──┐      │  scheduler ──► market_env ──► node_engine   │
 │ 同花顺    │──┤ 真实  │      │            │            │            │
 │ 腾讯行情  │──┼─行情─►│  market_review  stock_picker   │            │
 │ 新浪行情  │──┘      │      │            │            │            │
 └──────────┘         │  data_check ◄── risk_guard ◄── agent_core    │
                      └───────┬─────────────┬─────────────┬──────────┘
                              │             │             │
                     ┌────────▼──┐   ┌──────▼─────┐  ┌────▼─────────┐
                     │ 每日决策报告 │   │ MCP Server │  │ 桌面对话 Agent│
                     │ (Markdown, │   │ (32 工具)  │  │ (pywebview +  │
                     │  可同步    │   │ 供 LLM 调用│  │  DeepSeek +   │
                     │  Obsidian) │   │            │  │  妙想数据源)  │
                     └───────────┘   └────────────┘  └──────────────┘

Tech Stack

Layer

Technology

Backend

Python 3.12 · FastAPI · APScheduler scheduled tasks

Protocol

MCP (Model Context Protocol) Server, 32 @mcp.tool tools

AI

DeepSeek streaming tool-use · 妙想金融数据 MCP · multi-agent debate convergence

Data

东方财富 / 同花顺 / 腾讯 qt.gtimg.cn / 新浪 —— two-source cross-validation, trusting only real market data

Storage

SQLite (session persistence) · JSON ledger

Desktop

pywebview · PyInstaller packaging (custom dragon-head theme icon)

Feature Overview

Entry

Description

docs/功能说明.md

What each module does, tool inventory, desktop capabilities

docs/交易策略.md

Complete trading rules made public (excerpted from the source code, for learning reference)

docs/samples/每日决策报告_示例.md

A sample of the report the system produces every day

The core output is the Daily Decision Report: data validation → market environment → market review → node tracking → limit-up board → swing pullback candidates → position check → decision conclusion, 10 sections in total, each with a mermaid flowchart.

Quick Start

1. Install dependencies

# 规则引擎 + 定时报告(src/)
pip install -r requirements.txt

# 桌面对话版(chat_agent/)
pip install -r chat_agent/requirements.txt

2. Configure keys (desktop version only)

The desktop version 龙头交易Agent requires two keys, stored locally in config/chat_agent.json (gitignored, not committed to the repository):

cp config/chat_agent.example.json config/chat_agent.json
cp config/agent_config.example.json config/agent_config.json
  • api_key: DeepSeek (sk-...), for calling DeepSeek models

  • mx_api_key: 东方财富妙想 MCP (em_...), for market quotes / financials / news

You can also use environment variables instead (higher priority): DEEPSEEK_API_KEY, MX_EM_API_KEY.

Keys are stored only locally; the repository contains only placeholder templates, and placeholders are rejected by validation.

3. Generate a report

py src/scheduler.py once

The report is output to data/交易报告_YYYY-MM-DD.md. To sync to Obsidian, set obsidian_dir in config/agent_config.json.

4. Launch the desktop chat version

py chat_agent/main.py

4.1 Package into exe (with custom icon)

pyinstaller chat_agent/dragon_agent.spec

Output: dist/龙头交易Agent.exe. The icon is a generated dragon-head theme (red circular background + golden “龙” character + rising candlestick lines). The source script is at tools/make_icon.py; to change the icon, edit it, regenerate, and repackage. Packaging details and pitfalls are in the spec file comments.

5. Windows startup scheduled report

Place start_scheduler.vbs in the “Startup” folder (Win+R → shell:startup). Adjust the paths in the file to your own environment.

Directory Structure

src/            规则引擎 + MCP Server(核心,21 模块)
chat_agent/     桌面对话版「龙头交易Agent」
config/         配置(示例模板 + 本地真实配置,后者 gitignore)
data/           运行数据(报告/持仓/日志,gitignore 不进仓库)
docs/           功能说明 / 交易策略 / 示例报告
tests/          测试(80+ 用例)
tools/          工具脚本(图标生成等)

Data Sources

Data Source

Purpose

东方财富

Daily K-line, limit-up pool, advancing/declining counts, capital flows (with throttling and ban protection)

同花顺

Limit-up pool cross-validation

腾讯行情

Indices / real-time quotes (does not block IPs)

新浪行情

Indices / real-time quotes

妙想 MCP

Desktop natural-language queries for A-shares / HK stocks / US stocks / funds / bonds / macro / news

License

MIT


⚠️ Disclaimer

Chinese: This project is for personal programming learning and technical research. It does not constitute any investment advice. Live trading or commercial use is strictly prohibited. All consequences are borne by the user.

English: This project is for personal programming learning and technical research only. It does NOT constitute investment advice. Any use for live trading or commercial purposes is strictly prohibited. All consequences are borne by the user.

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    C
    quality
    D
    maintenance
    The MCP provides comprehensive financial data and analytical tool support for AI large language models, specifically including the following five core data capabilities: Stock Analysis/ETF Analysis/Public Funds/News & Information/General Tools More Info: https://github.com/shenqingtech/deepq-finan
    44
    40
    7
    ISC
  • A
    license
    A
    quality
    D
    maintenance
    Provides professional financial data access for LLMs via MCP, supporting providers like Tushare, Wind, and DataYes.
    14
    58
    Apache 2.0
  • A
    license
    B
    quality
    C
    maintenance
    MCP server that wraps AKShare's 1000+ financial data functions, enabling LLMs to query Chinese stock, macro, futures, fund, bond, option, forex, and alternative data through standardized tools.
    14
    3
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

  • Read-only China A-share data for AI agents: market, limit-up, capital flow and disclosures.

  • Real SEC, 13F, insider, congress & macro data your AI agent can cite. Hosted MCP, 24 tools.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BAI2007-Dev/dragon-trading-agent'

If you have feedback or need assistance with the MCP directory API, please join our Discord server