Simulation Trading logo

Simulation Trading

CommunityPopular
qusong0627
simulation-trading

模拟交易 — 下单买卖、持仓管理、成交查询、账户状态、资金快照。在 QuantBot / Claude Code 中执行模拟交易、下单、查询持仓、查看账户、管理交易记录时使用。触发词:模拟交易、模拟下单、买入股票、卖出股票、查持仓、查账户、模拟账户、模拟交易记录、模拟撤单

Overview

Publisherqusong0627
RepositoryQuantMind
Skill namesimulation-trading
Stars
1.7K
Forks
387
Bundled files
Instructions only
LicenseAGPL-3.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by qusong0627 on GitHub. Read the source before you install it.

Installation

Install the Simulation Trading AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/qusong0627/QuantMind/tree/master/skills/simulation-trading
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/qusong0627/QuantMind.git /tmp/QuantMind
mkdir -p .claude/skills
cp -r /tmp/QuantMind/skills/simulation-trading .claude/skills/simulation-trading
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Simulation Trading in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Simulation Trading on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Simulation Trading is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

⚙️ 本技能遵循公共运行环境契约(最高优先级,先于本文其余内容执行): 详见 _shared/env-contract.md,执行前先读它。

模拟交易技能

QuantMind 模拟交易(纸面交易)完整操作:下单、持仓、成交、账户、资金快照、模拟盘启动。默认模拟资金 100 万,不影响实盘。

实盘 / 模拟盘切换

  • 前端切换:顶部 HeaderBar 右上角 REAL/SIM 拨动开关,切换实盘(通达信桥)与模拟盘。选择持久化到 localStorage['qm:trading_mode_pref'],默认模拟盘(simulation)。
  • 后端分流:账户按 GET /api/v1/real-trading/status 返回的 mode + 前端分流——SIMULATION 调 /simulation/account,REAL 调 /account。
  • 启动参数:POST /api/v1/real-trading/start 接收 trading_mode=SIMULATION/REAL;实盘需 ENABLE_REAL_TRADING=true 环境变量。
  • 交易就绪检查:/api/v1/real-trading/trading-precheck 返回信号就绪/交易权限(可交易/观察态/阻断)。
bash
# 检查交易就绪(启动前必查)
curl -s -H "$AUTH" "$BASE/api/v1/real-trading/trading-precheck"
# 返回: {passed, items:[{key,passed,detail}], signal_readiness, trading_permission}

认证

bash
BASE=http://127.0.0.1:8000
TOKEN=$(curl -s -X POST $BASE/api/v1/auth/login -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"admin123","tenant_id":"default"}' \
  | python3 -c "import sys,json; print(json.load(sys.stdin).get('access_token',''))")
AUTH="Authorization: Bearer $TOKEN"
CT="Content-Type: application/json"

1. 账户状态

1.1 查看模拟账户

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/account"
# 返回: {cash, total_asset, market_value, positions, initial_equity, ...}
# 默认现金 100 万,positions 为当前持仓

1.2 模拟交易设置

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/settings"

1.3 重置模拟账户

bash
curl -s -X POST -H "$AUTH" "$BASE/api/v1/simulation/reset"

1.4 资金快照

bash
# 手动捕获资金快照
curl -s -X POST -H "$AUTH" "$BASE/api/v1/simulation/snapshots/capture"
# 每日资金快照(总资产/现金/市值序列)
curl -s -H "$AUTH" "$BASE/api/v1/simulation/snapshots/daily"

2. 下单(核心)

2.1 买入/卖出

bash
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/simulation/orders" \
  -d '{
    "symbol": "600519.SH",
    "side": "buy",            # buy / sell
    "order_type": "market",   # market / limit
    "quantity": 100,
    "price": null,            # 限价单必填,市价单可空
    "remarks": "AI策略买入"
  }'

参数:

字段说明
symbol股票代码(600519.SH / SH600519)
sidebuy / sell
order_typemarket(市价)/ limit(限价)
quantity数量(股)
price限价单必填,市价单可空
remarks备注(可选)

返回:order_id + 订单状态(pending/filled/...)

2.2 撤单

bash
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/simulation/orders/{order_id}/cancel" \
  -d '{"reason":"手动撤单"}'

3. 订单与成交查询

3.1 订单列表

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/orders"
# 返回: [{order_id, symbol, side, order_type, quantity, status, ...}]

3.2 单笔订单

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/orders/{order_id}"

3.3 成交记录

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/trades"
# 返回: [{trade_id, symbol, side, quantity, price, ...}]

3.4 单笔成交

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/trades/{trade_id}"

3.5 成交统计

bash
curl -s -H "$AUTH" "$BASE/api/v1/simulation/trades/stats/summary"
# 返回: 盈亏/胜率/交易次数等统计

4. 模拟盘启动(real-trading)

模拟盘生命周期:策略绑定 → 预检查 → 启动 → 持仓跟踪 → 停止。

bash
# 策略绑定到组合(策略信号 → 下单)
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/portfolios/{portfolio_id}/bind-strategy" \
  -d '{"strategy_id":"strategy_xxx","model_id":"mdl_cn_xxx"}'

# 交易预检查(信号就绪 / 资金 / 风控)
curl -s -H "$AUTH" "$BASE/api/v1/real-trading/trading-precheck"

# 启动模拟盘
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/real-trading/start" \
  -d '{"portfolio_id":"xxx","strategy_id":"strategy_xxx"}'
# 停止模拟盘
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/real-trading/stop"

# 运行状态 / 日志 / 订单 / 历史
curl -s -H "$AUTH" "$BASE/api/v1/real-trading/status"
curl -s -H "$AUTH" "$BASE/api/v1/real-trading/logs"
curl -s -H "$AUTH" "$BASE/api/v1/real-trading/orders"
curl -s -H "$AUTH" "$BASE/api/v1/real-trading/history"

组合(Portfolio)管理:

bash
# 创建/列表组合
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/portfolios" -d '{"name":"我的组合","initial_capital":1000000}'
curl -s -H "$AUTH" "$BASE/api/v1/portfolios"
# 组合详情/绩效(分布只有全量口径,见持仓管理节)
curl -s -H "$AUTH" "$BASE/api/v1/portfolios/{id}"
curl -s -H "$AUTH" "$BASE/api/v1/portfolios/{id}/performance"
# 结算/快照/同步
curl -s -X POST -H "$AUTH" "$BASE/api/v1/portfolios/{id}/settlement"
curl -s -X POST -H "$AUTH" "$BASE/api/v1/portfolios/{id}/snapshot"
curl -s -X POST -H "$AUTH" "$BASE/api/v1/portfolios/{id}/sync-status"

持仓管理:

bash
# 组合持仓
curl -s -H "$AUTH" "$BASE/api/v1/portfolios/{id}/positions"
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/portfolios/{id}/positions" -d '{"symbol":"600519.SH","quantity":100}'
# 调整/清仓(注意是 positions/{position_id} 口径,不是 portfolios/{id} 下挂 adjust/close)
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/positions/{position_id}/adjust" -d '{"quantity":100}'
curl -s -X POST -H "$AUTH" -H "$CT" "$BASE/api/v1/positions/{position_id}/close"
curl -s -X PUT -H "$AUTH" -H "$CT" "$BASE/api/v1/positions/{position_id}/price" -d '{"price":1500.0}'
# 全量资产分布(无单组合 distribution,查全量再过滤)
curl -s -H "$AUTH" "$BASE/api/v1/portfolios/distribution"

5. 实战流程(推荐)

当用户要求"模拟交易/买入/卖出"时:

  1. 查账户:/simulation/account 看现金和持仓
  2. 确认标的:查股票当前价(用 [[quantdb-sdk]] 或 K线)
  3. 下单:/simulation/orders POST(市价/限价)
  4. 确认成交:/simulation/orders/{order_id} 查状态
  5. 查看持仓:/simulation/account 看更新后的 positions
  6. 统计:/simulation/trades/stats/summary 看收益

当用户要求"启动模拟盘 / 跑实盘模拟"时:

  1. 建组合:/portfolios POST 创建
  2. 绑定策略:/portfolios/{id}/bind-strategy(strategy_id + model_id)
  3. 预检查:/real-trading/trading-precheck 确认信号就绪
  4. 启动:/real-trading/start
  5. 监控:/real-trading/status + /simulation/account
  6. 停止:/real-trading/stop

6. 相关技能

  • [[stock-market-analysis]] — 分析选哪只股票(371 字段 + 风险评分)
  • [[smart-strategy-stock-picking]] — 条件选股找标的
  • [[quantdb-sdk]] — 查 K 线/估值确定买卖价
  • [[backtest-center]] — 回测验证策略后再模拟执行
  • [[ai-ide-strategy-writing]] — 写策略并执行回测

7. 常见问题

现象处理
买入资金不足查 account cash,减仓或调小 quantity
卖出无持仓查 account positions 确认持有
限价单未成交价格远离现价,改市价或调价
想重置/simulation/reset 恢复 100 万初始资金
模拟盘启动失败查 /real-trading/trading-precheck 看信号就绪状态
策略信号未生成确认模型已推理(见 [[quantmind-operations]])

Frequently asked questions

What does the Simulation Trading AI skill do?

模拟交易 — 下单买卖、持仓管理、成交查询、账户状态、资金快照。在 QuantBot / Claude Code 中执行模拟交易、下单、查询持仓、查看账户、管理交易记录时使用。触发词:模拟交易、模拟下单、买入股票、卖出股票、查持仓、查账户、模拟账户、模拟交易记录、模拟撤单

Why use Simulation Trading on TypingMind?

Because you install it once and use it with any model. Simulation Trading is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Simulation Trading in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/qusong0627/QuantMind/tree/master/skills/simulation-trading. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Simulation Trading?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Simulation Trading?

As many as you like. As long as a model supports skills, you can use Simulation Trading with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Simulation Trading AI skill free?

Yes. It is published on GitHub by qusong0627 under the AGPL-3.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇