股票均线计算器

一个提供简单移动平均线计算的股票市场分析工具,可作为Web应用程序或AI代理的MCP工具使用。

  • by nishikanta24
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 nishikanta24/SMA_MCP-TOOL

使用说明

SMA计算器

带有简单移动平均线计算的股票市场分析工具。可作为web应用程序和用于AI代理的MCP工具。

🚀 快速开始

选项1:Web应用程序(人类用户)

使用Docker:

docker build -t sma-calculator .
docker run -p 8000:8000 -p 8501:8501 sma-calculator

访问地址:http://localhost:8501

没有Docker:

pip install -r backend/requirements.txt
python -m uvicorn backend.main:app --port 8000 --reload &
streamlit run app.py

选项2:MCP服务器(AI代理)

运行MCP服务器:

pip install -r backend/requirements.txt
python mcp_server.py

使用Docker:

docker build -t sma-calculator .
docker run sma-calculator python mcp_server.py

在Claude Desktop中配置: 添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "sma-calculator": {
      "command": "python",
      "args": ["path/to/demo_indium/mcp_server.py"]
    }
  }
}

🛠️ MCP工具使用

配置后,AI代理可以调用:

工具: calculate_stock_sma

参数:

  • symbol (必填):股票代码(例如“AAPL”、“GOOGL”)
  • interval (可选):“5m”、“15m”或“30m”(默认值:“5m)
  • sma_window (可选):2-100(默认值:20)
  • period (可选):“1d”、“5d”或“1mo”(默认值:“1d)

退货:

{
  "symbol": "AAPL",
  "interval": "5m",
  "sma_window": 20,
  "data_points": 50,
  "data": {
    "timestamp": [...],
    "close": [...],
    "sma": [...]
  },
  "latest": {
    "close": 267.95,
    "sma": 268.12,
    "trend": "bearish"
  }
}

📊 特性

  • 雅虎财经的实时股票数据
  • 多个间隔:5m、15m、30m
  • 交互式图表(网络应用程序)
  • CSV导出(web应用程序)
  • 结构化JSON响应(MCP)
  • 趋势指标

🌐 Web API

端点: GET /analyze

例子:

curl "http://localhost:8000/analyze?symbol=AAPL&interval=5m&sma_window=20"

文档: http://localhost:8000/docs

📁 项目结构

demo_indium/
├── mcp_server.py           # MCP server for AI agents
├── mcp_config.json         # MCP configuration
├── app.py                  # Streamlit frontend
├── Dockerfile              # Container configuration
└── backend/
    ├── main.py             # FastAPI app
    ├── requirements.txt
    └── services/
        ├── data_fetcher.py
        └── sma_calculator.py

🧪 测试

python backend/test_backend.py

🐳 Docker命令

构建:

docker build -t sma-calculator .

运行Web应用程序:

docker run -p 8000:8000 -p 8501:8501 sma-calculator

运行MCP服务器:

docker run sma-calculator python mcp_server.py

📝 技术栈

  • 后端: FastAPI、yfinance、pandas
  • 前端: 流光溢彩
  • MCP: Python MCP SDK
  • 缓存: 5分钟内存缓存

⚠️ 备注

  • 使用雅虎财经免费API
  • 仅支持5m、15m、30m的间隔
  • 数据缓存5分钟
  • 市场时段内可用的日内数据

📄 许可证

教育和示范目的。