← 返回 Skills 市场
stevenge791

模拟交易系统

作者 StevenGE791 · GitHub ↗ · v1.0.3 · MIT-0
cross-platform ⚠ suspicious
96
总下载
0
收藏
0
当前安装
4
版本数
在 OpenClaw 中安装
/install simulated-trading
功能描述
全功能模拟交易系统。创建投资组合、下单买入卖出、撤单、撮合成交、管理行情数据、计算净值与组合绩效(收益率、波动率、夏普比率、最大回撤)。支持东方财富实时行情自动刷新。Use when user wants to simulate stock/fund trading, create paper trading p...
使用说明 (SKILL.md)

模拟交易系统 Simulated Trading

快速开始

所有脚本在 scripts/ 目录下,使用前会自动初始化数据库(SQLite,路径可设 SIMTRADE_DB_PATH 环境变量,默认 ~/.openclaw/workspace/data/simulated-trading.db)。

完整数据库表结构见 references/schema.md

工作流

模拟交易的标准操作流程:

  1. 创建组合portfolio.py create
  2. 录入行情market_data.py update/batch(或使用自动刷新)
  3. 下单交易order.py place
  4. 撮合挂单matching.py
  5. 记录净值performance.py snapshot
  6. 分析绩效performance.py perf

一、组合管理 portfolio.py

🔄 自动刷新行情: show 命令默认会从东方财富 API 拉取持仓标的的实时价格,确保显示的盈亏基于最新行情。如需使用数据库缓存价格,添加 --no-refresh 参数。

# 创建组合
python scripts/portfolio.py create \x3C名称> \x3C初始资金> [描述]

# 列出所有组合
python scripts/portfolio.py list

# 查看组合详情(含持仓、挂单、近期成交)— 默认自动刷新实时价格
python scripts/portfolio.py show \x3C组合ID>

# 查看组合详情(使用数据库缓存价格,不刷新)
python scripts/portfolio.py show \x3C组合ID> --no-refresh

# 删除组合
python scripts/portfolio.py delete \x3C组合ID>

# 入金
python scripts/portfolio.py deposit \x3C组合ID> \x3C金额>

# 出金
python scripts/portfolio.py withdraw \x3C组合ID> \x3C金额>

二、行情管理 market_data.py

⚠️ 先录行情,再下单。市价单和撮合都必须有行情数据。

# 更新单个标的价格
python scripts/market_data.py update \x3C代码> \x3C价格> [名称]

# 批量更新(JSON 数组字符串)
python scripts/market_data.py batch '[{"symbol":"000001","price":12.5,"name":"平安银行"}]'

# 查询某个标的价格
python scripts/market_data.py price \x3C代码>

# 列出所有行情
python scripts/market_data.py list [搜索关键词]

# 删除行情
python scripts/market_data.py delete \x3C代码>

三、订单管理 order.py

# 下单(限价单)
python scripts/order.py place \x3C组合ID> \x3C代码> \x3Cbuy|sell> limit \x3C数量> \x3C价格> [名称]

# 下单(市价单,立即按行情成交)
python scripts/order.py place \x3C组合ID> \x3C代码> \x3Cbuy|sell> market \x3C数量>

# 撤单
python scripts/order.py cancel \x3C订单ID>

# 查询订单
python scripts/order.py query [组合ID] [status]

# 查看订单详情(含成交记录)
python scripts/order.py show \x3C订单ID>

四、撮合引擎 matching.py

撮合规则:价格优先、时间优先。限价买单在行情价 \x3C= 限价时成交;限价卖单在行情价 >= 限价时成交。成交价均以行情价为准。

# 撮合所有待成交订单
python scripts/matching.py

# 撮合指定组合的待成交订单
python scripts/matching.py \x3C组合ID>

五、净值与绩效 performance.py

🔄 自动刷新行情: navsnapshotperf 命令默认会从东方财富 API 拉取持仓标的的实时价格。如需使用数据库缓存价格,添加 --no-refresh 参数。

# 即时计算当前净值(不存库)— 默认自动刷新实时价格
python scripts/performance.py nav \x3C组合ID> [日期]

# 记录净值快照(存入 nav_history 表)— 默认自动刷新
python scripts/performance.py snapshot \x3C组合ID> [日期]

# 绩效分析报告 — 默认自动刷新
python scripts/performance.py perf \x3C组合ID> [开始日期] [结束日期]

# 以上三个命令均支持 --no-refresh 跳过自动刷新
python scripts/performance.py nav \x3C组合ID> --no-refresh

# 查看净值历史(不涉及行情,无需刷新)
python scripts/performance.py history \x3C组合ID> [条数]

绩效指标说明

指标 说明
total_return_pct 区间总收益率
annualized_return_pct 年化收益率(假设 252 交易日/年)
annualized_volatility_pct 年化波动率
sharpe_ratio 夏普比率(无风险利率 2%)
max_drawdown_pct 最大回撤
win_rate_pct 日胜率

典型使用示例

# 1. 创建 10 万初始资金的组合
python scripts/portfolio.py create "我的策略" 100000 "量化策略v1"
# → 返回 PTFxxxxxxxx

# 2. 录入行情
python scripts/market_data.py batch '[{"symbol":"000001","price":12.5,"name":"平安银行"},{"symbol":"600519","price":1680,"name":"贵州茅台"}]'

# 3. 限价买入
python scripts/order.py place PTFxxxx 000001 buy limit 1000 12.0 平安银行
# → 挂单中,需撮合或等行情达到

# 4. 市价买入
python scripts/order.py place PTFxxxx 600519 buy market 100
# → 立即按 1680 成交

# 5. 撮合所有挂单
python scripts/matching.py

# 6. 记录净值快照
python scripts/performance.py snapshot PTFxxxx

# 7. 查看绩效
python scripts/performance.py perf PTFxxxx

六、实时行情刷新 refresh_prices.py

独立的行情刷新工具,自动从东方财富妙想 API 获取实时价格(回退方案:东方财富直连 API)。portfolio.py showperformance.py nav/snapshot/perf 已内置自动调用,通常无需手动执行。

🔑 需要 EM_API_KEY 环境变量(或写入 ~/.bashrc)。脚本会自动从 bashrc 读取。

# 刷新指定组合所有持仓的实时价格
python scripts/refresh_prices.py portfolio \x3C组合ID>

# 刷新指定标的列表的实时价格(逗号分隔)
python scripts/refresh_prices.py symbols \x3C代码1,代码2,...>

所有脚本输出均为 JSON 格式,可直接解析。

安全使用建议
Review this skill before installing. Use it only if you are comfortable with its access to trading or portfolio account data, provide the API key through a scoped environment variable or secret manager rather than allowing shell-profile inspection, and avoid delete operations unless you have a backup or the skill adds an explicit confirmation step.
能力标签
requires-sensitive-credentials
能力评估
Purpose & Capability
Using an API key and managing portfolios are aligned with a trading or portfolio-management skill, but reading shell configuration for credentials and immediate permanent portfolio deletion create material safety concerns.
Instruction Scope
The documented instruction to read EM_API_KEY from ~/.bashrc is broader than necessary for a single credential, and the delete path lacks an explicit user confirmation or recovery mechanism.
Install Mechanism
No VirusTotal telemetry or supplied artifact evidence indicates a deceptive installer, hidden package behavior, or unrelated installation side effects.
Credentials
Accessing ~/.bashrc is disproportionate because shell startup files can contain unrelated secrets and personal configuration beyond the API key the skill needs.
Persistence & Privilege
No background persistence was evidenced, but the skill has destructive authority over portfolio state through permanent deletion without a confirmation interlock.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install simulated-trading
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /simulated-trading 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.3
重大升级:行情刷新改为东方财富妙想 API 优先,批量查询更稳定;自动从 bashrc 读取 EM_API_KEY;修复单标的/多标的两种响应格式兼容;新增 refresh_prices.py 独立批量刷新工具
v1.0.2
行情刷新升级:优先走东方财富妙想 API,直连 API 作为回退;自动从 bashrc 读取 EM_API_KEY;修复部分标的刷新失败问题
v1.0.1
优化中文搜索触发词,提升可发现性;新增持仓查询、模拟交易等场景关键词
v1.0.0
初始版本:组合管理、订单管理、撮合引擎、净值计算与绩效分析,支持东方财富实时行情自动刷新
元数据
Slug simulated-trading
版本 1.0.3
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 4
常见问题

模拟交易系统 是什么?

全功能模拟交易系统。创建投资组合、下单买入卖出、撤单、撮合成交、管理行情数据、计算净值与组合绩效(收益率、波动率、夏普比率、最大回撤)。支持东方财富实时行情自动刷新。Use when user wants to simulate stock/fund trading, create paper trading p... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 96 次。

如何安装 模拟交易系统?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install simulated-trading」即可一键安装,无需额外配置。

模拟交易系统 是免费的吗?

是的,模拟交易系统 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

模拟交易系统 支持哪些平台?

模拟交易系统 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 模拟交易系统?

由 StevenGE791(@stevenge791)开发并维护,当前版本 v1.0.3。

💬 留言讨论