Skill: jfstylejf/finance-reporter (version 1.0.1)

--- name: finance-reporter description: 实时财经数据推送工具。使用Yahoo Finance API获取全球股市、外汇、大宗商品、加密货币实时行情，支持定时推送到钉钉/微信。包含股票代码、货币单位、实时价格、24h前/昨收价格、涨跌幅。支持标的：纳指、道指、美元指数、黄金、比特币、沪指、恒生、日经、人民币/美元汇率、原油。 homepage: https://github.com/openclaw/finance-reporter version: 1.0.0 author: A哥 license: MIT metadata: { "openclaw": { "emoji": "📈", "requires": { "bins": ["python3", "curl"] }, "triggers": { "scheduled": "generate_finance_report" }, "install": [ { "id": "python", "kind": "system", "bins": ["python3"], "label": "Python 3.8+", }, ], }, } --- # Finance Reporter - 实时财经数据推送 📈 专业的财经数据获取与推送工具，支持全球主要金融市场实时行情。 ## ✨ 功能特性 - **全球覆盖**：美股、A股、港股、日股、外汇、大宗商品、加密货币 - **实时数据**：Yahoo Finance API，数据准确及时 - **智能计算**：自动计算涨跌幅，股票显示"昨收"，加密货币显示"24h前" - **定时推送**：支持 cron 定时任务，自动推送到钉钉/微信 - **重试机制**：网络失败自动重试3次 - **货币单位**：自动显示 USD/CNY/HKD/JPY 等货币符号 ## 📊 支持标的 | 类别 | 标的 | 代码 | 货币 | 市场类型 | |------|------|------|------|----------| | 🇺🇸 美股指数 | 纳指 | ^IXIC | USD | 股票 | | 🇺🇸 美股指数 | 道指 | ^DJI | USD | 股票 | | 💵 外汇 | 美元指数 | DX-Y.NYB | - | 外汇 | | 💵 外汇 | 人民币/美元 | CNY=X | - | 外汇 | | 🪙 加密货币 | 比特币 | BTC-USD | USD | 加密(24h) | | 🏆 大宗商品 | 黄金 | GC=F | USD | 期货 | | 🏆 大宗商品 | 原油 | CL=F | USD | 期货 | | 🇨🇳 A股 | 沪指 | 000001.SS | CNY | 股票 | | 🇭🇰 港股 | 恒生 | ^HSI | HKD | 股票 | | 🇯🇵 日股 | 日经 | ^N225 | JPY | 股票 | ## 🚀 快速开始 ### 1. 手动获取数据 ```bash # 运行脚本获取实时数据 python3 ~/.openclaw/workspace/skills/finance-reporter/tools/finance_data.py ``` ### 2. 钉钉群调用 在钉钉群中 @你的机器人： ``` @finance 获取实时财经数据 ``` ### 3. 配置定时任务 ```bash # 每天 01:20 自动推送 openclaw cron add \ --name "finance_daily" \ --schedule "20 1 * * *" \ --command "python3 ~/.openclaw/workspace/skills/finance-reporter/tools/finance_data.py" ``` ## 📋 输出格式示例 ``` 📊 实时财经数据 [2026-03-20 01:20] 💡 数据来源: Yahoo Finance API 🇺🇸 美股指数 ---------------------------------------- 📉 纳指 代码: ^IXIC 现价: $21,979.21 昨收: $22,152.42 涨跌: -173.21 (-0.78%) 📉 道指 代码: ^DJI 现价: $45,884.29 昨收: $46,225.15 涨跌: -340.86 (-0.74%) 🪙 加密货币 ---------------------------------------- 📉 比特币 代码: BTC-USD 现价: $69,296.45 24h前: $71,245.58 涨跌: -1,949.13 (-2.74%) ``` ## ⚙️ 配置说明 ### 环境要求 - Python 3.8+ - requests 库 ### 安装依赖 ```bash pip3 install requests ``` ### 自定义标的 编辑 `tools/finance_data.py` 中的 `SYMBOLS` 字典： ```python SYMBOLS = { "纳指": {"code": "^IXIC", "currency": "USD", "market": "stock"}, "道指": {"code": "^DJI", "currency": "USD", "market": "stock"}, # 添加你的标的... "特斯拉": {"code": "TSLA", "currency": "USD", "market": "stock"}, } ``` ### 市场类型说明 - `stock`：股票/指数，显示"昨收" - `crypto`：加密货币，显示"24h前" - `commodity`：大宗商品，显示"昨收" - `forex`：外汇，显示"昨收" ## 📡 数据来源 - **Primary**: [Yahoo Finance API](https://finance.yahoo.com)（免费，实时） - **数据更新**: 实时 - **API限制**: 无限制，但请合理使用 ## 🔧 故障排除 ### 数据获取失败 - 检查网络连接 - 脚本会自动重试3次 - 查看错误日志：`openclaw logs` ### 钉钉推送失败 - 确认钉钉插件已配置 - 检查群ID是否正确 - 查看绑定：`openclaw agents bindings` ## 📝 更新日志 ### v1.0.0 (2026-03-20) - ✅ 支持10个主要标的 - ✅ 智能涨跌幅计算 - ✅ 定时任务推送 - ✅ 钉钉集成 - ✅ 重试机制 ## 🤝 贡献 欢迎提交 PR 和 Issue！ ## 📄 许可证 MIT License

path: README.md
content: # Finance Reporter 📈

实时财经数据推送工具，支持全球股市、外汇、大宗商品、加密货币。

## 快速开始

```bash
# 安装
clawhub install finance-reporter

# 运行
python3 ~/.openclaw/workspace/skills/finance-reporter/tools/finance_data.py
```

## 功能

- ✅ 10+ 主要金融标的
- ✅ 实时数据（Yahoo Finance）
- ✅ 智能涨跌幅计算
- ✅ 定时推送（钉钉/微信）
- ✅ 自动重试机制

## 支持标的

| 类别 | 标的 |
|------|------|
| 美股指数 | 纳指、道指 |
| 外汇 | 美元指数、人民币/美元 |
| 加密货币 | 比特币 |
| 大宗商品 | 黄金、原油 |
| A股/港股/日股 | 沪指、恒生、日经 |

## 详细文档

查看 [SKILL.md](./SKILL.md)

## License

MIT


path: package.json
content: {
  "name": "finance-reporter",
  "version": "1.0.0",
  "description": "实时财经数据推送工具 - 支持全球股市、外汇、大宗商品、加密货币",
  "main": "tools/finance_data.py",
  "scripts": {
    "test": "python3 tools/finance_data.py"
  },
  "keywords": [
    "finance",
    "stock",
    "market",
    "crypto",
    "forex",
    "commodity",
    "dingtalk",
    "cron"
  ],
  "author": "A哥",
  "license": "MIT",
  "homepage": "https://github.com/openclaw/finance-reporter",
  "repository": {
    "type": "git",
    "url": "https://github.com/openclaw/finance-reporter.git"
  },
  "bugs": {
    "url": "https://github.com/openclaw/finance-reporter/issues"
  },
  "engines": {
    "python": ">=3.8"
  },
  "dependencies": {
    "requests": "^2.28.0"
  }
}


path: tools/finance_data.py
content: #!/usr/bin/env python3
"""
财经数据获取脚本 - 钉钉优化版
支持：美股、A股、港股、外汇、大宗商品、加密货币
"""

import requests
import json
import time
import sys
from datetime import datetime

# 配置
SYMBOLS = {
    "纳指": {"code": "^IXIC", "currency": "USD", "market": "stock"},
    "道指": {"code": "^DJI", "currency": "USD", "market": "stock"},
    "美元指数": {"code": "DX-Y.NYB", "currency": "", "market": "forex"},
    "黄金": {"code": "GC=F", "currency": "USD", "market": "commodity"},
    "原油": {"code": "CL=F", "currency": "USD", "market": "commodity"},
    "比特币": {"code": "BTC-USD", "currency": "USD", "market": "crypto"},
    "沪指": {"code": "000001.SS", "currency": "CNY", "market": "stock"},
    "恒生": {"code": "^HSI", "currency": "HKD", "market": "stock"},
    "日经": {"code": "^N225", "currency": "JPY", "market": "stock"},
    "人民币/美元": {"code": "CNY=X", "currency": "", "market": "forex"},
}

def get_yahoo_data(symbol_info, max_retries=3):
    """获取数据，带重试"""
    symbol = symbol_info["code"]
    market = symbol_info.get("market", "stock")
    
    for attempt in range(max_retries):
        try:
            # 加密货币使用1小时数据获取24小时前价格
            if market == "crypto":
                url = f"https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?interval=1h&range=2d"
            else:
                url = f"https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?interval=1d&range=2d"
            
            headers = {"User-Agent": "Mozilla/5.0"}
            response = requests.get(url, headers=headers, timeout=15)
            data = response.json()
            
            if "chart" in data and data["chart"]["result"]:
                result = data["chart"]["result"][0]
                meta = result["meta"]
                
                current = meta.get("regularMarketPrice", 0)
                previous = meta.get("previousClose", 0)
                
                # 从 indicators 获取价格
                if "indicators" in result and "quote" in result["indicators"]:
                    quotes = result["indicators"]["quote"][0]
                    if "close" in quotes and quotes["close"]:
                        closes = [c for c in quotes["close"] if c is not None]
                        if len(closes) >= 2:
                            if market == "crypto":
                                # 加密货币：24小时前的价格（约24个1小时数据点）
                                if len(closes) >= 24:
                                    previous = closes[-24]
                                else:
                                    previous = closes[0]
                            else:
                                # 股票：昨天收盘价
                                previous = closes[-2]
                
                change = current - previous if current and previous else 0
                change_pct = (change / previous * 100) if previous else 0
                
                return {
                    "price": current,
                    "previous": previous,
                    "change": change,
                    "change_pct": change_pct,
                    "currency": symbol_info.get("currency", "USD"),
                    "market": market,
                }
        except Exception as e:
            if attempt < max_retries - 1:
                print(f"Retry {attempt + 1}/{max_retries} for {symbol}...")
                time.sleep(1)
            else:
                print(f"Error: {symbol} failed after {max_retries} attempts")
    
    return None

def format_price(price, currency):
    if price is None:
        return "N/A"
    if currency == "USD":
        return f"${price:,.2f}"
    elif currency == "CNY":
        return f"¥{price:,.2f}"
    elif currency == "HKD":
        return f"HK${price:,.2f}"
    elif currency == "JPY":
        return f"¥{price:,.0f}"
    else:
        return f"{price:,.2f}"

def generate_report():
    report = []
    report.append(f"📊 实时财经数据 [{datetime.now().strftime('%Y-%m-%d %H:%M')}]\n")
    report.append("💡 数据来源: Yahoo Finance API\n")
    
    categories = [
        ("🇺🇸 美股指数", ["纳指", "道指"]),
        ("💵 外汇", ["美元指数", "人民币/美元"]),
        ("🪙 加密货币", ["比特币"]),
        ("🏆 大宗商品", ["黄金", "原油"]),
        ("🇨🇳 A股", ["沪指"]),
        ("🇭🇰 港股", ["恒生"]),
        ("🇯🇵 日股", ["日经"]),
    ]
    
    for category_name, symbols in categories:
        report.append(category_name)
        report.append("-" * 40)
        for name in symbols:
            data = get_yahoo_data(SYMBOLS[name])
            if data:
                emoji = "📈" if data["change"] >= 0 else "📉"
                market = data.get("market", "stock")
                # 加密货币显示"24h前"，其他显示"昨收"
                ref_label = "24h前" if market == "crypto" else "昨收"
                
                report.append(f"{emoji} {name}")
                report.append(f"   代码: {SYMBOLS[name]['code']}")
                report.append(f"   现价: {format_price(data['price'], data['currency'])}")
                report.append(f"   {ref_label}: {format_price(data['previous'], data['currency'])}")
                report.append(f"   涨跌: {data['change']:+.2f} ({data['change_pct']:+.2f}%)")
                report.append("")
            else:
                report.append(f"⚠️ {name}: 数据获取失败")
                report.append("")
        report.append("")
    
    return "\n".join(report)

if __name__ == "__main__":
    report = generate_report()
    print(report)


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)