← Back to Skills Marketplace
shouldnotappearcalm

A股模拟账户交易

by calm · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ⚠ suspicious
140
Downloads
1
Stars
0
Active Installs
2
Versions
Install in OpenClaw
/install a-share-paper-trading
Description
A股模拟盘交易与回测技能。Use when 用户要启动模拟仓服务、创建多账户、下限价单/市价单、撤单、查询持仓资金、验证涨跌停成交逻辑或运行A股回测。
README (SKILL.md)

A股模拟盘

独立的模拟盘 skill。交易服务、CLI、账户、撮合与行情适配都在本目录内,不依赖其他 skill 脚本。

何时使用

  • 启动或检查模拟盘服务
  • 创建/重置账户
  • 限价买卖、市价买卖、撤单
  • 查询账户、持仓、订单、成交
  • 验证涨跌停、T+1、收盘过期
  • 跑简单回测

启动

SKILL_DIR="\x3C本skill绝对路径>"
python3 "$SKILL_DIR/scripts/paper_trading_service.py" --host 127.0.0.1 --port 18765

默认监听 http://127.0.0.1:18765,默认数据库不再落在 skill 目录,而是落到用户级数据目录:

  • macOS: ~/Library/Application Support/a-share-paper-trading/paper_trading.db
  • Linux: ${XDG_DATA_HOME:-~/.local/share}/a-share-paper-trading/paper_trading.db

若本机该端口已有模拟盘进程在跑,不要再启动第二个实例:会报 Address already in use,且多进程可能争用同一 SQLite 库文件。启动前可先检查端口是否在监听,例如:

lsof -iTCP:18765 -sTCP:LISTEN

或向 http://127.0.0.1:18765/accountsGET(CLI 默认 --base-url 与此一致)。已有服务时直接用 paper_trade_cli.py 即可。

更推荐使用控制脚本常驻运行:

python3 "$SKILL_DIR/scripts/paper_trading_ctl.py" start
python3 "$SKILL_DIR/scripts/paper_trading_ctl.py" status
python3 "$SKILL_DIR/scripts/paper_trading_ctl.py" stop

在 macOS 上,如需持续自启动,可安装 launchd:

python3 "$SKILL_DIR/scripts/paper_trading_ctl.py" install-launchd

服务会:

  • 交易时段定时撮合挂单
  • 非交易时段停止撮合
  • 收盘后让当日未成单过期
  • 定时写账户净值快照

可用启动参数:

  • --host
  • --port
  • --db-path
  • --match-interval
  • --valuation-interval
  • --idle-valuation-interval

默认端口与 CLI 基址已改为 18765,避免和常见本地开发服务冲突。

CLI

python3 "$SKILL_DIR/scripts/paper_trade_cli.py" create-account alpha --cash 500000
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" list-accounts
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" show-default-account
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" set-default-account alpha
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" reset-account alpha --cash 300000
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" add-cash alpha 50000 --note 入金
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" deduct-cash alpha 10000 --note 出金
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" buy alpha 600519 100 --market
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" sell alpha 600519 100 --price 1450
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" orders alpha
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" positions alpha
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" show-account alpha
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" trades alpha
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" cancel \x3Corder_id>
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" process-orders
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" run-snapshots
python3 "$SKILL_DIR/scripts/paper_trade_cli.py" backtest 600519 --strategy sma_cross --start 2025-01-01 --end 2026-03-31 --cash 200000

支持的 CLI 子命令:

  • create-account
  • show-default-account
  • set-default-account
  • reset-account
  • list-accounts
  • show-account
  • positions
  • orders
  • trades
  • buy
  • sell
  • cancel
  • add-cash
  • deduct-cash
  • process-orders
  • run-snapshots
  • backtest

Agent 执行规则(账户路由)

  • 首次创建模拟账户前,必须先向用户确认初始资金金额。
  • 若系统存在多个账户且用户未指明账户,先反问“本次操作哪个账户”再继续。
  • 若仅有一个账户且该账户已存在,默认直接使用该账户。
  • 若存在默认账户(show-default-account 可查),且用户未指定账户,优先使用默认账户。
  • 需要切换默认账户时,使用 set-default-account

首次初始化资金规则(默认 100w)

  • 当用户首次要进行交易但尚未初始化账户资金时,先反问确认,不直接执行。
  • 默认建议初始资金为 1000000(100w),提问模板建议为:
    • “当前未初始化模拟账户,默认按 100w 启动,是否确认?如需修改请直接给出金额。”
  • 仅在用户明确确认后,才执行创建默认账户。
  • 若用户给出其他金额,按用户金额创建并继续后续操作。

CLI 参数约束(Agent 必读)

  • buy/sell
    • 限价单必须带 --price
    • 市价单使用 --market,不应再传 --price
  • orders --status 可用值:open / filled / cancelled / expired / rejected
  • add-cash / deduct-cashamount 必须为正数,单位为人民币元。
  • 默认优先使用 --json 输出,便于后续结构化解析与决策。

执行前检查(下单前固定三步)

  1. 先确认账户路由:show-default-accountlist-accounts
  2. 再确认资金:show-account \x3Caccount_id>
  3. 下单前确认持仓与未完成单:positions \x3Caccount_id>orders \x3Caccount_id> --status open

资金调整规则(加减可用资金)

  • 入金使用 add-cash \x3Caccount_id> \x3Camount>,出金使用 deduct-cash \x3Caccount_id> \x3Camount>
  • 入金/出金金额必须为正数。
  • 出金只能减少可用资金,不得穿透冻结资金;可用不足时应先告知用户再调整。

常见错误与处理动作

  • Address already in use:不要重复启动服务,直接使用现有服务地址。
  • default account not set:触发首次初始化反问流程,确认金额后创建默认账户。
  • insufficient available cash:提示当前可用资金,建议入金或降低下单数量/价格。
  • insufficient sellable qty:提示可卖数量,说明可能受 T+1 影响或持仓不足。
  • order is not open:先查询订单状态(可能已成交/已撤/已过期),再决定下一步。
  • market orders are only accepted during trading hours:改用限价单或等待交易时段。

规则摘要

  • 只支持 A 股 long-only
  • 买入数量必须是 100 股整数倍
  • 卖出遵守 T+1
  • 限价单价格必须符合 0.01 元最小报价单位
  • 板块涨跌幅兜底规则:
    • 主板普通股 10%
    • 创业板/科创板 20%
    • 主板 ST 5%
  • 限价单价格不能超出当日涨跌停
  • 一字涨停默认买不进
  • 一字跌停默认卖不出
  • 市价单仅在连续竞价时段接受
  • 集合竞价与午休时段不做自动撮合
  • 行情时间戳不是当日时,视为陈旧行情,不执行市价成交
  • 费用模型包含最低佣金、卖出印花税、沪市过户费
  • 当日单收盘后过期

结构

  • scripts/paper_trading_service.py: 启动 HTTP 服务
  • scripts/paper_trade_cli.py: CLI
  • scripts/paper_trading_ctl.py: 启停、状态、launchd 安装
  • scripts/paper_trading_runtime.py: 运行时默认目录、端口、路径
  • scripts/paper_trading/: 账户、撮合、估值、数据适配

服务接口

默认暴露这些 HTTP 路由:

  • GET /accounts
  • GET /accounts/default
  • POST /accounts
  • POST /accounts/default
  • GET /accounts/{account_id}
  • POST /accounts/{account_id}/reset
  • POST /accounts/{account_id}/cash-adjust
  • GET /accounts/{account_id}/positions
  • GET /accounts/{account_id}/orders
  • GET /accounts/{account_id}/trades
  • POST /orders
  • POST /orders/{order_id}/cancel
  • POST /orders/process
  • POST /snapshots/run
  • POST /backtest
  • GET /health

参考

Usage Guidance
This package appears to implement a local A‑share paper trading server and CLI as described, but before installing or running it you should: 1) Inspect scripts/paper_trading/market_data.py to see whether it performs network calls or expects API keys (and where it sends data). 2) Do not install the LaunchAgent (install‑launchd) until you review the launch plist and confirm you want a user‑level service started at login. 3) Run the service in an isolated environment (temporary user or container) first — it will create a SQLite DB and logs under your home directory. 4) If you plan to run validation/backtest scripts, be aware they may access real market data and could require network access or credentials not declared in SKILL.md. 5) Review any code that calls subprocess/urllib for external endpoints and confirm no unexpected telemetry or exfiltration. If you want, provide the contents of scripts/paper_trading/market_data.py and I can review it for external network calls or hidden credential usage.
Capability Analysis
Type: OpenClaw Skill Name: a-share-paper-trading Version: 1.0.1 The skill bundle implements a legitimate A-share paper trading system with a local HTTP service, SQLite persistence, and a backtesting engine. It fetches market data from standard financial providers (Sina, Tencent, and Eastmoney via the akshare library) and includes comprehensive validation and smoke test scripts (e.g., full_function_smoke_check.py). While paper_trading_ctl.py includes functionality to install a macOS launchd agent for persistence, this is a documented feature for service management and lacks malicious intent.
Capability Assessment
Purpose & Capability
Name, description, CLI and HTTP routes match the included code: a local paper‑trading engine, server, CLI and backtest/validation scripts. The files and runtime instructions are coherent with the stated purpose.
Instruction Scope
SKILL.md instructs how to run the service, CLI and install a user launchd agent and documents DB/log locations. However several included validation/backtest scripts call MarketDataProvider (paper_trading.market_data) to load real quotes; SKILL.md does not document any network activity or external API use. The server binds to 127.0.0.1 by default (good), but if the MarketDataProvider performs remote HTTP calls or requires credentials this is not reflected in the instructions and broadens the runtime scope.
Install Mechanism
There is no external install step or remote download: the package is instruction + code files. The control script launches the service via subprocess and can install a user LaunchAgent on macOS; nothing downloads arbitrary code from unknown URLs.
Credentials
The skill declares no required environment variables or credentials, which fits a local simulator. But the MarketDataProvider and validation scripts (real_stock_rule_validation.py, backtest_batch_validation.py) may fetch live market data or expect API keys — if that code uses network APIs or env vars for credentials, those are not declared here and should be verified.
Persistence & Privilege
always:false and agent invocation is normal. The skill writes a SQLite DB and log under user-level application data directories and can install a macOS LaunchAgent (~/Library/LaunchAgents) to auto-start the service; installing the LaunchAgent is optional but would make the service persistent in the user account.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install a-share-paper-trading
  3. After installation, invoke the skill by name or use /a-share-paper-trading
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.1
- 新增服务控制脚本 paper_trading_ctl.py,支持服务一键启动、停止、状态检测和 macOS 启动项安装。 - 默认端口更改为 18765 ,CLI 及服务不再与常用开发端口冲突。 - 默认数据库路径迁移至用户数据目录(macOS/Linux),避免覆盖 skill 目录下数据。 - 规则更新:明确市价单仅限连续竞价时段,涨跌停幅度规则与撮合、费用细节补充说明。 - 新增运行时脚本及回测、验证类辅助脚本,提升可运维性和测试覆盖。
v1.0.0
Initial release of A股模拟盘交易与回测 skill. - Introduced a standalone A股模拟盘 (A-share paper trading) service with no external dependencies. - Provides HTTP service and CLI for account management, cash adjustment, trading, order management, and backtesting. - Implements key trading rules (e.g., T+1, price limits, minimum trading units, order expiry). - Supports multi-account management, default account routing, and user confirmation flows for initialization and cash operations. - Includes built-in error handling logic and process guidelines for stable interaction.
Metadata
Slug a-share-paper-trading
Version 1.0.1
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 2
Frequently Asked Questions

What is A股模拟账户交易?

A股模拟盘交易与回测技能。Use when 用户要启动模拟仓服务、创建多账户、下限价单/市价单、撤单、查询持仓资金、验证涨跌停成交逻辑或运行A股回测。 It is an AI Agent Skill for Claude Code / OpenClaw, with 140 downloads so far.

How do I install A股模拟账户交易?

Run "/install a-share-paper-trading" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is A股模拟账户交易 free?

Yes, A股模拟账户交易 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does A股模拟账户交易 support?

A股模拟账户交易 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created A股模拟账户交易?

It is built and maintained by calm (@shouldnotappearcalm); the current version is v1.0.1.

💬 Comments