掘金量化skill
掘金量化 Python SDK 专家技能。 当用户提到掘金、gm、gm.api、掘金量化、掘金策略、掘金SDK、掘金终端、 量化策略开发、回测、实时行情、订阅行情、历史行情、下单、委托、持仓、 order_volume、subscribe、history、set_token、get_symbols、get_sym... Skill: 掘金量化skill Owner: turkeydick Summary: 掘金量化 Python SDK 专家技能。 当用户提到掘金、gm、gm.api、掘金量化、掘金策略、掘金SDK、掘金终端、 量化策略开发、回测、实时行情、订阅行情、历史行情、下单、委托、持仓、 order_volume、subscribe、history、set_token、get_symbols、get_sym... Tags: automation:1.0.2, finance:1.0.2, gm:1.0.2, joinquant:1.0.2, latest:1.0.3, quant:1.0.2, stock:1.0.2, trading:1.0.2, workbuddy:1.0.2 Version history: v1.0.3 | 2026-05-26T09:22:10.719Z | user gmquant v1.0.3 - Add
Rank
62
Safety
84
Downloads
1.1k
Updated
Oct 11, 2026
Version
1.0.3
Source
CLAWHUB
About
What it does, and when to use it.
Capability contract not published. No trust telemetry is available yet. 1.1K downloads reported by the source. Last updated 10/11/2026.
Avoid when
- Contract metadata is missing or unavailable for deterministic execution.
Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing
Public facts
Every fact links back to the source it came from.
- Vendor
- Clawhubvendor · observed Oct 11, 2026
- Protocol compatibility
- OpenClawcompatibility · observed Oct 11, 2026
- Adoption signal
- 1.1K downloadsadoption · observed Oct 11, 2026
- Latest release
- 1.0.3release · observed May 26, 2026
- Handshake status
- UNKNOWNsecurity
Install and run
Setup complexity: low.
clawhub skill install s1720w1mawags81sjr872kwe1185smvf:gmquant- Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
- Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.
Contract: missing
curl -s "https://www.xpersona.co/api/v1/agents/clawhub-turkeydick-gmquant/snapshot"
Documentation
CLAWHUB
147,049 characters of source documentation, loaded on request.
Extracted files
5 files captured from the source.
SKILL.md
---
name: gm-quant
version: 2.1.0
description: >
掘金量化 Python SDK 专家技能。 当用户提到掘金、gm、gm.api、掘金量化、掘金策略、掘金SDK、掘金终端、
量化策略开发、回测、实时行情、订阅行情、历史行情、下单、委托、持仓、
order_volume、subscribe、history、set_token、get_symbols、get_symbol_infos、
get_history_symbol、history_n、current、last_tick、current_price、get_trading_dates、
order_percent、order_value、order_target_volume、algo_order、
get_orders、get_position、get_cash、bond_convertible、
L2行情、逐笔成交、逐笔委托、schedule定时任务、 财务数据、资产负债表、利润表、现金流量表、估值指标、PE/PB/PS/股息率、
市值、股本、流通股、成分股、行业分类、 可转债分析、转股溢价率、纯债价值、ETF成分股、基金净值、 期货合约信息、仓单数据、成交持仓排名、连续合约、
stk_get_fundamentals、stk_get_daily_valuation、stk_get_index_constituents、
stk_get_industry_category、stk_get_industry_constituents、stk_get_symbol_industry、
stk_get_sector_category、stk_get_sector_constituents、stk_get_symbol_sector、
stk_get_dividend、stk_get_ration、stk_get_adj_factor、stk_get_shareholder_num、
stk_get_top_shareholder、stk_get_share_change、stk_abnor_change_stocks、
stk_abnor_change_detail、stk_quota_shszhk_infos、stk_active_stock_top10_shszhk_info、
stk_get_money_flow、stk_get_finance_audit、stk_get_finance_forecast、
bnd_get_analysis、bnd_get_conversion_price、bnd_get_call_info、bnd_get_put_info、bnd_get_amount_change、
fnd_get_portfolio、fnd_get_etf_constituents、fnd_get_net_value、fnd_get_adj_factor、fnd_get_dividend、fnd_get_split、fnd_get_share、
fut_get_contract_info、fut_get_continuous_contracts、fut_get_transaction_rankings、fut_get_warehouse_receipt、
get_open_call_auction
时,自动加载此 skill。
---
# 掘金量化 SDK 技能 — v2.0 自然语言策略引擎
## 定位
你是**掘金量化平台的自然语言策略助手**。用户用中文描述交易想法,你负责:
1. **理解需求** → 提炼策略逻辑(标的/信号/风控)
2. **生成代码** → 输出可直接运行的完整策略 `.py` 文件
3. **执行运行** → 调用 `scripts/run_strategy.py` 一键启动回测或实盘
## 核心原则
1. **必须先 set_token**:纯数据查询(非策略 run)场景下,代码开头必须调用 `set_token('your_token')`。
2. **symbol 格式**:`交易所代码.证券代码`,如 `SHSE.600000`、`SZSE.000001`,**严格区分大小写**。
3. **gm 包通过掘金终端连接**:终端必须保持打开,否则接口会超时或报错。
4. **两种模式**:`MODE_LIVE=1`(实时/仿真)、`MODE_BACKTEST=2`(回测);`run()` 函数启动策略。
5. **数据查询不需要 run**:仅用 `set_token` 后直接调用数据函数即可。
## 🚀 用户工作流(自然语言→运行)
### 第 0 步:确认 Strategy ID(重要!)
**每次生成策略前,必须向用户索要 `strategy_id`。**
`strategy_id` 是策略在掘金终端中的唯一标识。填写后:
- 回测结果**持久化**到掘金终端后台
- 用户登录 [掘金终端网页](https://www.myquant.cn) → 策略列表 → 查看完整的**绩效分析图表**
(收益曲线、回撤分析、夏普比率、持仓明细等)
> **交互方式**:如果用户没有主动提供 strategy_id,在生成代码前询问:
> "请给我一个 **strategy_id**(英文/数字/下划线),用于在掘金终端标识这个策略。
> 填完后你可以在终端网页上看到绩效分析图表。例如:`ma_cross_600519`、`momentum_v1`"
| 场景 | 处理方式 |
|------|---------|
| 用户提供了 strategy_id | 直接使用 |
| 用户没提供 | **必须追问**,不能自己编造一个默认值后静默使用 |
| 用户说"随便起一个" | 根据策略特征起一个有意义的名字(如 `dual_ma_kweichow`) |
### 第一步:理解用户意图
当用户用自然语言描述策略时,按以下维度提取信息:
| 维度 | 需确认的信息 | 默认值(如未明确说明) |
|------|-------------|---------------------|
| **strategy_id** | 策略在掘金终端的标识(**必须用户提供,见第0步**) | 无默认,必须询问 |
| **标的池** | 哪些股票/指数? | 沪深300成分股 |
| **时间频率** | 日线/分钟线/tick? | 日线 `1d` |
| **买入信号** | 什么条件买入?(均线/指标/事件) | 必须明确,不能猜测 |
| **卖出信号** | 什么条件卖出? | 必须明确,不能猜测 |
| **仓位管理** | 全仓/固定金额/比例/等权 | 等权分配 |
| **止损止盈** | 有无?阈值多少? | 无 |
| **回测区间** | 开始~结束日期 | 最近1年 |
| **初始资金** | 多少钱? | 100万 README.md
# 掘金量化 Skill — 自然语言策略引擎 v2.1.0
> **用中文说话就能跑量化策略。** 告诉我你的交易想法,我帮你生成代码、执行回测、查看结果。
## 快速开始(3 步)
### 1️⃣ 准备环境
确保你的电脑已安装:
- [**掘金终端**](https://www.myquant.cn) — 打开并登录
- **Python 3.8+** — 安装 `gm` SDK 包:
```bash
pip install gm
```
### 2️⃣ 设置 Token
获取方式:掘金终端 → 系统设置 → 密钥管理 → 复制 Token
然后告诉我:"我的 token 是 `xxxxx`",我会自动保存。
### 3️⃣ 用自然语言描述策略 + 提供 Strategy ID
直接说你想做什么,**同时告诉我你的策略 ID**:
> "帮我写个双均线策略:茅台和平安银行,5 日均线上穿 20 日均线买入,下穿卖出,回测最近一年。**策略 ID 叫 `ma_cross_v1`**"
> "写个动量策略:沪深 300 里选过去 20 天涨幅最大的 10 只等权买入,每月初调仓。**strategy_id 用 `momentum_top10`**"
> "查一下贵州茅台最近半年的日线收盘价"(纯查询不需要 strategy_id)
我会自动生成完整的可运行策略文件并帮你跑起来。
---
## 支持的策略类型
| 类型 | 示例描述 | 关键字 |
|------|---------|--------|
| **趋势跟踪** | "双均线金叉死叉" / "布林带突破" / "MACD 策略" | 均线、MA、MACD、布林带 |
| **动量/因子** | "选涨幅最大的 N 只" / "RSI 超卖买入" / "量价配合" | 动量、RSI、成交量、排名 |
| **均值回归** | "偏离均值太多就反向操作" / "网格交易" | 均值回归、网格、偏离 |
| **多因子选股** | "按 PE+ROE 选股" / "小市值+高成长" | 因子、筛选、排序 |
| **事件驱动** | "财报后买入" / "涨停板打板" | 财报、涨停、事件 |
| **纯数据查询** | "查行情" / "拉数据" / "看 K 线" | 查询、历史、行情 |
---
## 运行模式
| 模式 | 说明 | 适用场景 |
|------|------|---------|
| **回测 (Backtest)** | 用历史数据模拟交易 | 验证策略效果(默认) |
| **实盘/仿真 (Live)** | 连接实时行情和模拟账户 | 策略验证后上线运行 |
---
## 典型对话示例
### 示例 1:从零开始写策略
```
你: 写个双均线交叉策略,标的用贵州茅台,5日和20日均线。策略ID用 ma_cross_kweichow
我: [生成 strategy_ma.py,strategy_id='ma_cross_kweichow']
策略已生成!参数如下:
- 策略ID: ma_cross_kweichow ← 终端可查看绩效
- 标的: SHSE.600519(贵州茅台)
- 周期: 日线 1d
- 信号: MA5上穿MA20买入 / 下穿卖出
- 回测: 2024-01 ~ 2025-12, 初始资金100万
要跑回测吗?
你: 跑吧
我: [自动调用 run_strategy.py --strategy-id ma_cross_kweichow 执行]
回测完成!结果摘要:
- 总收益: +23.5%
- 年化收益: 18.2%
- 最大回撤: -12.3%
- 夏普比率: 1.45
✅ 已保存到掘金终端 → 打开 https://www.myquant.cn 查看完整绩效图表
```
### 示例 2:只查询数据
```
你: 查一下中芯国际最近30天的收盘价
我: [直接调用 API 返回 DataFrame]
SZSE.002371 中芯国际 最近30日收盘价:
日期 | 收盘价 | 涨跌幅
2026-03-10 | 52.30 | +2.1%
2026-03-11 | 51.80 | -0.96%
...
```
---
## 文件结构
```
~/.workbuddy/skills/gm-quant/
├── SKILL.md # 技能主文件(AI 读取此文件理解如何工作)
├── README.md # 本文件 — 用户引导
├── TEST_REPORT.md # API 测试报告
├── references/ # API 详细参考文档(21篇)
│ ├── 01-quick-start.md
│ ├── 04-market-data.md
│ ├── 16-premium-data-apis.md # 增值数据 API 速查合集
│ ├── 18-stock-premium-apis.md # 股票增值数据(完整版)
│ ├── 19-fund-premium-apis.md # 基金增值数据(完整版)
│ ├── 20-cb-premium-apis.md # 可转债增值数据(完整版)
│ └── 21-futures-premium-apis.md # 期货增值数据(完整版)
└── scripts/
├── run_strategy.py # ⭐ 策略一键运行器
├── test_all_apis.py # API 全量测试脚本
├── test_account_apis.py # 账户 API 策略环境测试
└── check_import.py # 导入检测
```
---
## ⭐ Strategy ID — 在掘金终端查看绩效分析
> **这是使用回测功能前必须填写的一步。**
### 什么是 Strategy ID?
`strategy_id` 是你的策略在**掘金终端**中的唯一标识名。每次运行策略时传入它,回测结果会**持久化保存**到终端后台。
### 填写后你能看到什么?
登录 [掘金量化终端](https://www.myquant.cn) → **策略_meta.json
{
"ownerId": "kn73qb7dqheg4nh3p4x4ka1mxx85szhw",
"slug": "gmquant",
"version": "1.0.3",
"publishedAt": 1779787330719
}references/01-quick-start.md
# 快速开始 & 策略架构
## 策略三大结构
掘金量化策略主要有 3 种结构:
### 1. 定时任务型
```python
from gm.api import *
def init(context):
schedule(schedule_func=algo, date_rule='1d', time_rule='14:50:00')
def algo(context):
order_volume(symbol='SHSE.600000', volume=200, side=OrderSide_Buy,
order_type=OrderType_Market, position_effect=PositionEffect_Open, price=0)
if __name__ == '__main__':
run(strategy_id='YOUR_ID', filename='main.py', mode=MODE_BACKTEST,
token='YOUR_TOKEN', backtest_start_time='2024-01-01 09:00:00',
backtest_end_time='2024-06-30 15:30:00', backtest_adjust=ADJUST_PREV,
backtest_initial_cash=1000000, backtest_commission_ratio=0.0001,
backtest_slippage_ratio=0.0001)
```
### 2. 数据事件驱动型
```python
from gm.api import *
def init(context):
subscribe(symbols='SHSE.600000', frequency='60s')
def on_bar(context, bars):
print(bars)
```
### 3. 时间序列滑窗型
```python
from gm.api import *
def init(context):
subscribe(symbols='SHSE.600000', frequency='60s', count=50,
format='df', fields='symbol,close,eob')
def on_bar(context, bars):
data = context.data(symbol=bars[0]['symbol'], frequency='60s', count=50)
data['ma5'] = data['close'].rolling(5).mean()
print(data.tail())
```
## 纯数据研究(无需 run)
```python
from gm.api import *
set_token('YOUR_TOKEN') # 掘金终端需保持打开
data = history(symbol='SHSE.600000', frequency='1d',
start_time='2024-01-01 09:00:00', end_time='2024-12-31 16:00:00',
fields='open,high,low,close,eob', adjust=ADJUST_PREV, df=True)
print(data)
```
## 模式说明
| 模式 | 常量 | 说明 |
|------|------|------|
| 实时模式 | `MODE_LIVE = 1` | 仿真/实盘交易,接收实时行情 |
| 回测模式 | `MODE_BACKTEST = 2` | 历史数据回放,快速验证策略 |
## 运行参数 `run()` 全解
| 参数 | 类型 | 说明 |
|------|------|------|
| strategy_id | str | 掘金终端生成的策略 ID |
| filename | str | 策略文件名(如 `main.py`) |
| mode | int | MODE_LIVE 或 MODE_BACKTEST |
| token | str | 用户 token(终端系统设置-密钥管理) |
| backtest_start_time | str | 回测开始时间 `%Y-%m-%d %H:%M:%S` |
| backtest_end_time | str | 回测结束时间 `%Y-%m-%d %H:%M:%S` |
| backtest_initial_cash | float | 初始资金,默认 1000000 |
| backtest_transaction_ratio | float | 成交比例,默认 1.0 |
| backtest_commission_ratio | float | 佣金比例,默认 0 |
| backtest_slippage_ratio | float | 滑点比例,默认 0 |
| backtest_adjust | int | 复权方式:ADJUST_NONE/ADJUST_PREV/ADJUST_POST |
| backtest_match_mode | int | 0=延时撮合(下一bar开盘价),1=实时撮合(当前收盘价) |
| backtest_check_cache | int | 是否用缓存,默认 1 |
| serv_addr | str | 终端地址,默认本地,可指定 `ip:port` |
## 注意事项
- filename 必须与实际文件名一致
- 前复权/后复权回测不处理分红送转事件(已通过复权因子调整)
- 不复权模式会自动处理分红送转references/02-core-functions.md
# 核心基础函数
## set_token - 设置用户 Token
```python
set_token('YOUR_TOKEN_ID')
```
- 纯数据查询时第一步必须调用
- Token 在掘金终端「系统设置 → 密钥管理」中获取
- Token 不正确会抛出异常
---
## run - 启动策略
```python
run(strategy_id='', filename='', mode=MODE_UNKNOWN, token='',
backtest_start_time='', backtest_end_time='',
backtest_initial_cash=1000000, backtest_transaction_ratio=1,
backtest_commission_ratio=0, backtest_slippage_ratio=0,
backtest_adjust=ADJUST_NONE, backtest_check_cache=1,
serv_addr='', backtest_match_mode=0)
```
详细参数说明见 `01-quick-start.md`。
---
## stop - 停止策略
```python
stop()
```
- 停止策略,退出策略进程
- 示例:当订阅代码集合为空时停止
```python
if not context.symbols:
stop()
```
---
## schedule - 定时任务
```python
schedule(schedule_func, date_rule, time_rule)
```
| 参数 | 类型 | 说明 |
|------|------|------|
| schedule_func | function | 定时执行的函数 |
| date_rule | str | `n + d/w/m`,如 `'1d'`(每天)、`'1w'`(每周)、`'1m'`(每月) |
| time_rule | str | 执行时间 `HH:MM:SS`,**时分秒不可省略前导零**,如 `'09:40:00'` |
**注意**:`1w`、`1m` 仅回测可用;`time_rule` 不能写 `'9:40:0'` 这种格式。
```python
def init(context):
schedule(schedule_func=algo_daily, date_rule='1d', time_rule='09:40:00')
schedule(schedule_func=algo_monthly, date_rule='1m', time_rule='09:30:00')
def algo_daily(context):
print('每天09:40执行', context.now)
def algo_monthly(context):
print('每月第一个交易日09:30执行', context.now)
```
---
## timer / timer_stop - 毫秒级定时器
**仅实时/仿真模式可用,回测不生效。**
```python
# 设置定时器
result = timer(timer_func=my_func, period=60000, start_delay=0)
# result: {'timer_status': 0, 'timer_id': 1}
# 停止定时器
is_stopped = timer_stop(timer_id=result['timer_id'])
```
| 参数 | 类型 | 说明 |
|------|------|------|
| timer_func | function | 触发时执行的函数 |
| period | int | 间隔毫秒数,范围 [1, 43200000] |
| start_delay | int | 延迟启动毫秒数,范围 [0, 43200000] |
```python
def init(context):
# 每60秒执行一次,立即启动
context.timer_id = timer(timer_func=on_timer, period=60000, start_delay=0)
def on_timer(context):
cash = context.account().cash
print('定时检查资金:', cash['available'])
```
---
## log - 日志
**仅实时模式可用。**
```python
log(level='info', msg='信号触发', source='strategy')
```
| level | 说明 |
|-------|------|
| `'info'` | 信息级别 |
| `'warning'` | 警告级别 |
| `'error'` | 错误级别 |
---
## add_parameter - 动态参数
**仅实时模式可用,重启后重置。**
```python
add_parameter(key='k_value', value=23, min=0, max=100,
name='K值阈值', intro='KDJ策略K值阈值',
group='1', readonly=False)
```
- 在终端 UI 界面显示和实时修改参数
- 修改时触发 `on_parameter(context, parameter)` 事件
```python
def on_parameter(context, parameter):
if parameter['name'] == 'K值阈值':
context.k_value = parameter['value']
print('参数已更新:', context.k_value)
```AionUi
Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!
activepieces
AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
cherry-studio
AI productivity studio with smart chat, autonomous agents, and 300+ assistants.
CopilotKit
The Frontend for Agents & Generative UI. React + Angular
Machine-readable data
The same record, as JSON, for agents and crawlers.
{
"facts": [
{
"factKey": "vendor",
"category": "vendor",
"label": "Vendor",
"value": "Clawhub",
"href": "https://clawhub.ai/turkeydick/skills/gmquant",
"sourceUrl": "https://clawhub.ai/turkeydick/skills/gmquant",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-11T07:26:45.809Z",
"isPublic": true
},
{
"factKey": "protocols",
"category": "compatibility",
"label": "Protocol compatibility",
"value": "OpenClaw",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-turkeydick-gmquant/contract",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-turkeydick-gmquant/contract",
"sourceType": "contract",
"confidence": "medium",
"observedAt": "2026-10-11T07:26:45.809Z",
"isPublic": true
},
{
"factKey": "traction",
"category": "adoption",
"label": "Adoption signal",
"value": "1.1K downloads",
"href": "https://clawhub.ai/turkeydick/gmquant",
"sourceUrl": "https://clawhub.ai/turkeydick/gmquant",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-11T07:26:45.809Z",
"isPublic": true
},
{
"factKey": "latest_release",
"category": "release",
"label": "Latest release",
"value": "1.0.3",
"href": "https://clawhub.ai/turkeydick/gmquant",
"sourceUrl": "https://clawhub.ai/turkeydick/gmquant",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-05-26T09:22:10.719Z",
"isPublic": true
},
{
"factKey": "handshake_status",
"category": "security",
"label": "Handshake status",
"value": "UNKNOWN",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-turkeydick-gmquant/trust",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-turkeydick-gmquant/trust",
"sourceType": "trust",
"confidence": "medium",
"observedAt": null,
"isPublic": true
}
],
"events": [
{
"eventType": "release",
"title": "Release 1.0.3",
"description": "gmquant v1.0.3 - Added premium API references for stocks, funds, convertible bonds, and futures in the documentation. - Introduced new user guide/reference files for enhanced coverage. - Added scripts to test all premium and new APIs. - Updated SKILL.md description and function list; expanded API coverage in documentation. - Removed the old user guide reference (`references/18-user-guide.md`).",
"href": "https://clawhub.ai/turkeydick/gmquant",
"sourceUrl": "https://clawhub.ai/turkeydick/gmquant",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-05-26T09:22:10.719Z",
"isPublic": true
}
]
}Record generated Oct 11, 2026.
