Skill: gold3bear/hk-stock-radar (version 1.0.1)

--- name: hk-stock-radar description: 港股行情与舆情监控工具。当用户询问「港股怎么样」「恒生指数」「港股大盘」「港股涨跌」「HK股」「港股行情监控」「南向资金」时使用。支持东方财富港股API、新浪财经港股接口、Yahoo Finance获取实时行情，以及Google News RSS和X/Twitter舆情监控。📢微信公众号：PM熊叔（打造一人公司的投研团队） --- # 港股雷达 (HK-Stock Radar) ## 数据源总览 | 数据源 | 用途 | 稳定性 | |--------|------|--------| | 东方财富港股板块API | 行业/概念板块涨跌排行、热点追踪 | ⭐⭐⭐ | | 新浪财经港股接口 | 个股实时行情（最稳定） | ⭐⭐⭐ | | Yahoo Finance | 恒生指数实时行情 | ⭐⭐ | | akshare | 港股实时行情、沪深港通 | ⭐⭐ | ## 实时行情查询 ### 恒生指数实时行情 ```python import requests def get_hsi(): """恒生指数 + 国企指数 + 恒生科技""" url = "https://hq.sinajs.cn/list=hkHSI,hkHSTECH,hkHSCEI" headers = {"Referer": "http://finance.sina.com.cn"} r = requests.get(url, headers=headers, timeout=10) r.encoding = 'gbk' results = {} for line in r.text.strip().split('\n'): if '=' not in line: continue _, data = line.split('=') vals = data.replace('"', '').replace(';', '').split(',') if len(vals) < 6: continue name = vals[0] price = float(vals[1]) chg = float(vals[4]) pct = float(vals[5]) results[name] = {"price": price, "chg": chg, "pct": pct} return results ``` ### 新浪财经港股个股行情 ```python import requests def get_hk_quote(codes): """查询港股实时行情 codes: str or list, e.g. 'hk00700' or ['hk00700', 'hk09988'] """ if isinstance(codes, str): codes = [codes] url = f"https://hq.sinajs.cn/list={','.join(codes)}" headers = {"Referer": "http://finance.sina.com.cn"} r = requests.get(url, headers=headers, timeout=10) r.encoding = 'gbk' results = [] for line in r.text.strip().split('\n'): if '=' not in line: continue _, data = line.split('=') code = _[-7:].replace('"', '') # e.g. hk00700 vals = data.replace('"', '').replace(';', '').split(',') if len(vals) < 6: continue try: name = vals[0] price = float(vals[1]) prev = float(vals[2]) chg = price - prev pct = chg / prev * 100 high = float(vals[4]) low = float(vals[5]) volume = float(vals[3]) / 1e6 # 成交量（手） arrow = "🔴" if pct > 0 else "🟢" if pct < 0 else "⚪" results.append({ "code": code, "name": name, "price": price, "chg": chg, "pct": pct, "high": high, "low": low, "volume": volume, "arrow": arrow }) except (ValueError, IndexError): continue return results ``` ### 东方财富港股板块 API ```python import requests def get_hk_sector_ranking(): """港股行业板块涨跌排行""" url = "http://push2.eastmoney.com/api/qt/clist/get" params = { "pn": 1, "pz": 30, "po": 1, "np": 1, "fltt": 2, "invt": 2, "fid": "f3", "fs": "m:1+t:23", # 港股行业板块 "fields": "f12,f14,f2,f3,f5,f6" } headers = {"Referer": "http://quote.eastmoney.com/"} r = requests.get(url, params=params, headers=headers, timeout=10) diff = r.json()["data"]["diff"] return [{"板块": x["f14"], "现价": x["f2"], "涨跌幅": x["f3"], "成交额": x["f6"]} for x in diff] ``` ### 沪深港通（南向资金） ```python import akshare as ak def get_southbound_flow(): """南向资金净流入""" df = ak.stock_hsgt_north_net_flow_em() # 沪深港通北向资金 return df.tail(5) # 最近5个交易日 ``` ## 主流港股代码速查 | 股票 | 代码 | 名称 | |------|------|------| | 腾讯 | hk00700 | 腾讯控股 | | 阿里 | hk09988 | 阿里巴巴 | | 美团 | hk03690 | 美团 | | 比亚迪 | hk01211 | 比亚迪股份 | | 京东 | hk09618 | 京东集团 | | 小米 | hk01810 | 小米集团 | | 恒生指数 | hkHSI | 恒生指数 | | 恒生科技 | hkHSTECH | 恒生科技指数 | | 国企指数 | hkHSCEI | 恒生国企指数 | ## 舆情监控 ### Google News Live（突发新闻） ``` https://news.google.com/rss/search?q=港股+恒生+今日+when:1h https://news.google.com/rss/search?q=香港股市+2026+when:1h https://news.google.com/rss/search?q=南向资金+港股+when:1h ``` ### X/Twitter 港股舆情 使用 browser 工具访问已登录的 @bearfrom2077： ``` https://x.com/search?q=港股%20恒生指数&f=live https://x.com/search?q=南向资金&f=live https://x.com/search?q=hkstocks%20hangseng&f=live ``` **核心关键词组合：** - `港股 恒生` — 大盘情绪 - `南向资金` — 外资态度 - `HK IPO` — 新股动态 - `科技股 港股` — 板块热点 ## 情报解读框架 | 指标 | 阈值 | 信号 | |------|------|------| | 恒生指数跌幅 | > 1.5% | 系统性风险预警 | | 南向资金净流入 | > 50亿/日 | 内地资金抄底 | | 南向资金净流出 | > 30亿/日 | 谨慎信号 | | 腾讯/阿里/美团 | 同时下跌 > 2% | 科技股出逃 | | 防御板块（银行/公用）领涨 | 资金抱团 | 非系统性风险 | **分析顺序：** 1. 恒生指数 + 国企指数 + 恒生科技（大盘方向） 2. 科技股（腾讯/阿里/美团/小米）— 港股主线 3. 南向资金（内地钱往哪走） 4. 板块涨跌（资金在哪里） 5. 交叉验证 + 给出判断 ## Cron 配置建议 | 频率 | 内容 | 适用场景 | |------|------|----------| | 每15分钟 | 恒生指数 + 恒生科技 | 盘中监控 | | 每30分钟 | 科技股四巨头（腾讯/阿里/美团/小米） | 港股主线 | | 每小时 | 港股板块排行 + 舆情 | 热点追踪 | | 有问才查 | 个股行情 | 被动触发 | ## 快速查询命令 ```bash cd C:\Users\gold3\.openclaw\workspace\skills\hk-stock-radar\scripts # 恒生指数 python hk_index.py # 个股行情（传入港股代码） python hk_quote.py hk00700 # 港股板块 python hk_sector.py # 南向资金 python southbound.py ```

path: scripts/dashboard.py
content: """
港股雷达仪表盘：一键汇总恒生指数 + 科技股 + 板块
用法: python dashboard.py
"""
import subprocess
import sys
import os

base = os.path.dirname(os.path.abspath(__file__))

print("=" * 50)
print("  🦞 港股雷达仪表盘")
print("=" * 50)

print("\n>>> 恒生指数")
subprocess.run([sys.executable, os.path.join(base, "hk_index.py")])

print("\n>>> 港股科技四巨头 (腾讯/阿里/美团/小米)")
subprocess.run([sys.executable, os.path.join(base, "hk_quote.py"),
                "hk00700", "hk09988", "hk03690", "hk01810"])

print("\n>>> 港股板块涨跌TOP10")
subprocess.run([sys.executable, os.path.join(base, "hk_sector.py"), "30"])


path: scripts/hk_index.py
content: """
港股主要指数实时行情
恒生指数、恒生科技、恒生国企指数
"""
import requests

HK_INDICES = {
    "hkHSI": "恒生指数",
    "hkHSTECH": "恒生科技",
    "hkHSCEI": "恒生国企指数",
}

def get_hk_indices():
    codes = ",".join(HK_INDICES.keys())
    url = f"https://hq.sinajs.cn/list={codes}"
    headers = {"Referer": "http://finance.sina.com.cn"}
    try:
        r = requests.get(url, headers=headers, timeout=10)
        r.raise_for_status()
    except requests.RequestException:
        return {}
    r.encoding = 'gbk'
    results = {}
    for line in r.text.strip().split('\n'):
        if '=' not in line:
            continue
        key, data = line.split('=', 1)
        code = key.split('_')[-1].replace('"', '')  # e.g. hkHSI
        if code not in HK_INDICES:
            continue
        vals = data.replace('"', '').replace(';', '').split(',')
        if len(vals) < 9:
            continue
        try:
            name = vals[1]  # 恒生指数
            price = float(vals[6])
            prev = float(vals[3])
            if prev == 0:
                continue
            chg = price - prev
            pct = chg / prev * 100
            arrow = "🔴" if pct > 0 else "🟢" if pct < 0 else "⚪"
            results[code] = f"{arrow} {name}: {price:.2f} {chg:+.2f}({pct:+.2f}%)"
        except (ValueError, IndexError):
            continue
    return results

if __name__ == "__main__":
    print("\n=== 港股主要指数 ===")
    indices = get_hk_indices()
    for v in indices.values():
        print(v)


path: scripts/hk_quote.py
content: """
新浪财经港股个股实时行情
用法: python hk_quote.py hk00700
       python hk_quote.py hk00700 hk09988 hk03690
"""
import requests
import sys

def get_hk_quote(codes):
    if isinstance(codes, str):
        codes = [codes]
    url = f"https://hq.sinajs.cn/list={','.join(codes)}"
    headers = {"Referer": "http://finance.sina.com.cn"}
    r = requests.get(url, headers=headers, timeout=10)
    r.encoding = 'gbk'
    for line in r.text.strip().split('\n'):
        if '=' not in line:
            continue
        key, data = line.split('=')
        code = key.split('_')[-1].replace('"', '')  # e.g. hk00700
        vals = data.replace('"', '').replace(';', '').split(',')
        if len(vals) < 6:
            continue
        try:
            # 新浪港股格式: 0=代码,1=名称,2=现价,3=昨收,4=今开,5=高,6=低,7=涨跌额,8=涨跌幅%
            name = vals[1]
            price = float(vals[2])
            prev = float(vals[3])
            chg = price - prev
            pct = chg / prev * 100
            high = float(vals[5])
            low = float(vals[6])
            vol = float(vals[12]) / 1e4 if len(vals) > 12 else 0  # 成交量（手）
            arrow = "🔴" if pct > 0 else "🟢" if pct < 0 else "⚪"
            print(f"{arrow} {name:12s} {code:8s} 现价:{price:.2f} "
                  f"涨跌:{chg:+.2f}({pct:+.2f}%) 高:{high:.2f} 低:{low:.2f} 量:{vol:.0f}手")
        except (ValueError, IndexError):
            continue

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("用法: python hk_quote.py hk00700 [hk09988 ...]")
        sys.exit(1)
    get_hk_quote(sys.argv[1:])


path: scripts/hk_sector.py
content: """
东方财富港股行业板块涨跌榜
"""
import requests
import sys

def get_hk_sector_ranking(top=20):
    url = "http://push2.eastmoney.com/api/qt/clist/get"
    params = {
        "pn": 1, "pz": top, "po": 1, "np": 1,
        "fltt": 2, "invt": 2,
        "fid": "f3",
        "fs": "m:1+t:23",  # 港股行业板块
        "fields": "f12,f14,f2,f3,f5,f6,f8"
    }
    headers = {"Referer": "http://quote.eastmoney.com/"}
    r = requests.get(url, params=params, headers=headers, timeout=10)
    r.raise_for_status()
    diff = r.json()["data"]["diff"]
    return diff

def format_sector(s):
    pct = s["f3"]
    arrow = "🔴" if pct > 0 else "🟢" if pct < 0 else "⚪"
    return f"{arrow} {s['f14']:15s} {'+' if pct>=0 else ''}{pct}%  成交额:{s['f6']/1e8:.1f}亿"

if __name__ == "__main__":
    top = int(sys.argv[1]) if len(sys.argv) > 1 else 20
    print("\n=== 港股板块涨跌榜 ===")
    data = get_hk_sector_ranking(top)
    print("\n【涨幅榜】")
    for s in sorted(data, key=lambda x: x["f3"], reverse=True)[:10]:
        print(format_sector(s))
    print("\n【跌幅榜】")
    for s in sorted(data, key=lambda x: x["f3"])[:10]:
        print(format_sector(s))


path: scripts/southbound.py
content: """
南向资金（沪深港通港股通）净流入
需要 akshare: pip install akshare
"""
try:
    import akshare as ak
    import pandas as pd
except ImportError as e:
    print(f"需要安装akshare: pip install akshare ({e})")
    exit(1)

def get_southbound():
    print("\n=== 南向资金（港股通）===")
    try:
        # 沪深港通南向资金历史
        df = ak.stock_hsgt_north_net_flow_em()
        print(df.tail(5).to_string(index=False))
    except Exception as e:
        print(f"南向资金获取失败: {e}")
        print("\n尝试替代方案...")
        try:
            # 替代：东方财富南向资金
            url = "https://push2.eastmoney.com/api/qt/kamt.rtmin/get"
            params = {"fields1": "f1,f2,f3,f4", "fields2": "f51,f52,f53,f54,f55,f56"}
            r = requests.get(url, params=params, timeout=10)
            print(r.json())
        except Exception as e2:
            print(f"替代方案也失败: {e2}")

if __name__ == "__main__":
    get_southbound()


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