SFC 模拟炒股(集成实时行情)
结合 sfc-quote 实时行情数据 + esimapi 模拟交易系统,提供完整的模拟炒股体验。
核心特性
- ✅ 实时行情接入:下单前自动从 sfc-quote 获取实时行情并同步到模拟系统
- ✅ 市价委托:
buym/sellm自动获取最新价下单,无需手动输入价格 - ✅ 实时盈亏:持仓列表自动显示实时行情计算的盈亏
- ✅ 账户汇总增强:持仓显示实时价格标记
- ✅ 行情同步:
sync命令批量同步多只股票行情到模拟系统
接口信息
| 模块 | 基础 URL | 说明 |
|---|---|---|
| 模拟交易 | https://terminal.sfccn.com/terminal/esimapi |
esimapi |
| 实时行情 | https://terminal.sfccn.com/terminal/quotes/api |
sfc-quote |
| 账户管理 | https://terminal.sfccn.com/terminal/zxt-web/simulated |
zxt-web |
接口调用顺序
正确的使用流程:
- 账户管理 → 通过 zxt-web 接口创建/删除/查询账户列表
- 同步行情 → 从 sfc-quote 获取实时行情并同步到模拟系统
- 交易操作 → 使用 esimapi 接口进行下单、查询等操作
统一响应结构
模拟交易接口(esimapi):
{
"code": "000000", // 成功;"999999" 失败
"message": "success",
"result": { } // 业务数据
}
账户列表接口(zxt-web):
{
"code": 200,
"msg": "操作成功",
"data": [
{
"id": 3,
"userId": "100001",
"userUniqKey": "模拟账户100001",
"deleteFlag": 0,
"createTime": 1779331926000,
"sid": 3,
"isSystem": false
}
],
"date": 1780563432848,
"vs": "1.0.3"
}
使用方式
命令行调用
# === 账户管理 ===
# 查询当前用户所有模拟账户列表
python skills/sfc-etrade-sim/call.py accounts
# 创建模拟账户(默认初始资金100万)
python skills/sfc-etrade-sim/call.py create my_account
# 创建模拟账户并指定初始资金
python skills/sfc-etrade-sim/call.py create my_account -m 2000000
# 删除模拟账户
python skills/sfc-etrade-sim/call.py delete my_account
# 根据ID删除模拟账户
python skills/sfc-etrade-sim/call.py delete my_account -i 3
# === 行情查询 ===
# 查询实时行情
python skills/sfc-etrade-sim/call.py quote 000001
# 同步实时行情到模拟系统(单只)
python skills/sfc-etrade-sim/call.py sync 000001
# 批量同步行情
python skills/sfc-etrade-sim/call.py sync 000001 300724 600519
# === 账户操作 ===
# 创建账户(默认初始资金)
python skills/sfc-etrade-sim/call.py account user001
# 创建账户并指定初始资金
python skills/sfc-etrade-sim/call.py account user001 -m 1000000
# 重置账户资金
python skills/sfc-etrade-sim/call.py account user001 -r
# 查看账户汇总(含实时盈亏)
python skills/sfc-etrade-sim/call.py stat 10001
# === 交易操作 ===
# 限价买入(指定价格,自动同步行情)
python skills/sfc-etrade-sim/call.py buy 10001 000001 10.50 100
# 市价买入(自动获取实时最新价)
python skills/sfc-etrade-sim/call.py buym 10001 000001 100
# 限价卖出
python skills/sfc-etrade-sim/call.py sell 10001 000001 11.00 100
# 市价卖出(自动获取实时最新价)
python skills/sfc-etrade-sim/call.py sellm 10001 000001 100
# 撤单
python skills/sfc-etrade-sim/call.py withdraw 12345 10001
# 计算最大可买量(自动使用实时价)
python skills/sfc-etrade-sim/call.py max-vol 10001 000001
# 指定价格计算最大可买量
python skills/sfc-etrade-sim/call.py max-vol 10001 000001 --price 10.50
# 计算可买金额/可卖数量
python skills/sfc-etrade-sim/call.py calc 10001 000001
# === 查询 ===
# 在途订单
python skills/sfc-etrade-sim/call.py orders 10001
# 订单历史
python skills/sfc-etrade-sim/call.py order-history 10001 -n 20
# 持仓列表(含实时盈亏)
python skills/sfc-etrade-sim/call.py positions 10001
# === 收益分析 ===
# 收益走势(本月)
python skills/sfc-etrade-sim/call.py profit-trend 10001 -t MONTH
# 收益统计(当日)
python skills/sfc-etrade-sim/call.py profit-stats 10001 -t DAY --year 2026 --month 6
# 收益贡献(本月)
python skills/sfc-etrade-sim/call.py profit-contrib 10001 -t MONTH --year 2026 --month 6
# JSON 输出(所有命令支持)
python skills/sfc-etrade-sim/call.py stat 10001 --json
Python 代码调用
from call import (
account_info, account_stat, place_order, place_order_market,
withdraw_order, order_list, order_history, position_list,
profit_trend, profit_stats, profit_contribution, calc_max_vol,
get_real_quote, query_real_quote, sync_quote_to_sim, sync_quotes_to_sim
)
# 1. 创建/查询账户
result = account_info('user001', init_money=1000000)
account_id = result['data']['id']
# 2. 查看实时行情
quote = get_real_quote('000001')
print(f"{quote['name']} 最新价: {quote['lastPrice']}")
# 3. 同步行情到模拟系统
sync_quote_to_sim('000001')
# 4. 市价买入(自动获取实时价)
result = place_order_market(account_id, '000001', direction=0, vol=100)
if result['data']['success']:
print("市价买入成功")
# 5. 限价买入(自动同步行情后下单)
result = place_order(account_id, '000001', direction=0, price=10.50, vol=100)
# 6. 查看账户汇总(含实时盈亏)
result = account_stat(account_id)
data = result['data']
print(f"总资产: {data['totalAsset']}, 累计盈亏: {data['profit']}")
# 7. 查看持仓(含实时盈亏)
result = position_list(account_id)
for pos in result['data']['positionList']:
print(f"{pos['secCode']} 持仓:{pos['vol']} 成本:{pos['price']}")
# 8. 收益走势
result = profit_trend(account_id, 'MONTH')
series = result['data']['series']
# 9. 批量同步行情 + 交易
sync_quotes_to_sim(['000001', '300724', '600519'])
result = place_order(account_id, '300724', direction=0, price=110.00, vol=100)
触发关键词
| 用户请求 | 自动触发动作 | 说明 |
|---|---|---|
| "模拟炒股" | 创建/查询账户 | account_info |
| "模拟买入 XX" | 市价买入 | place_order_market |
| "模拟卖出 XX" | 市价卖出 | place_order_market |
| "查看持仓" | 持仓列表(实时盈亏) | position_list |
| "查看订单" | 在途订单 | order_list |
| "模拟行情 XX" | 查询实时行情 | get_real_quote |
| "收益走势" | 收益走势 | profit_trend |
| "收益统计" | 收益统计 | profit_stats |
交易常量
交易方向
| 值 | 常量 | 说明 |
|---|---|---|
| 0 | BUY | 买入 |
| 1 | SALE | 卖出 |
订单状态
| 值 | 常量 | 说明 |
|---|---|---|
| 0 | STATUS_IN_PROCESS | 进行中/待成交 |
| 1 | STATUS_FINISHED | 已成交 |
| -1 | STATUS_SYS_WITHDRAW | 系统撤单 |
| -2 | STATUS_USER_WITHDRAW | 用户撤单 |
市场类型
| 类型 | 说明 |
|---|---|
| ST | 普通股票 |
| ETF | 场内基金 |
| FND | 场外基金 |
| CONVERTIBLE_BOND | 可转债 |
| T_BOND | 国债 |
| HK_C_ST | 港股通 |
| ST_TECH | 科创板 |
交易失败码
| 失败码 | 说明 |
|---|---|
| 900009 | 系统异常 |
| 900010 | 非交易时间 |
| 900011 | 资金不足 |
| 900012 | 持仓不足 |
| 900013 | 订单信息错误 |
| 900015 | 买入量非交易单位整数倍 |
| 900016 | 证券代码不存在 |
| 900017 | 价格超过昨收上限 |
| 900018 | 价格低于昨收下限 |
| 900032 | 无行情信息 |
| 900033 | 价格超过现价浮动范围 |
功能模块
| # | 方法 | 路径 | 说明 | 基础URL |
|---|---|---|---|---|
| 0 | GET | /zxt-web/simulated/account/list | 查询账户列表 | zxt-web |
| 1 | POST | /zxt-web/simulated/create | 创建模拟账户 | zxt-web |
| 2 | POST | /zxt-web/simulated/account/delete | 删除模拟账户 | zxt-web |
| 3 | POST | /trade/order/add | 下单 | esimapi |
| 4 | POST | /trade/order/withdraw | 撤单 | esimapi |
| 5 | POST | /trade/order/batchWithdraw | 批量撤单 | esimapi |
| 6 | POST | /trade/order/etf/trans | ETF 转换 | esimapi |
| 7 | POST | /trade/order/bond/trans | 可转债转股 | esimapi |
| 8 | POST | /trade/calcMaxVol | 最大可买量 | esimapi |
| 9 | POST | /account/info | 查询/创建账户 | esimapi |
| 10 | POST | /account/stat | 账户汇总 | esimapi |
| 11 | POST | /account/remove | 删除账户 | esimapi |
| 12 | POST | /account/history | 账户变更历史 | esimapi |
| 13 | POST | /account/calcAvailMoneyVol | 可买金额/可卖数量 | esimapi |
| 14 | POST | /account/profit/trend | 收益走势 | esimapi |
| 15 | POST | /account/profit/stats | 收益统计 | esimapi |
| 16 | POST | /account/profit/contribution | 收益贡献 | esimapi |
| 17 | POST | /order/list | 在途订单 | esimapi |
| 18 | POST | /order/history | 订单历史 | esimapi |
| 19 | POST | /position/list | 持仓列表 | esimapi |
| 20 | POST | /quote/set | 批量设置行情 | esimapi |
| 21 | GET | /quote/get/{secCode} | 查询单只行情 | esimapi |
| 22 | GET | /quote/list | 全部行情 | esimapi |
| 23 | POST | /quotes/api/quote | 实时行情查询 | quotes |
文件输出规则
所有本技能生成的文件统一保存到 ~/.openclaw/workspace/nancai/ 目录下。
文件命名规范:{类型}_{主题}_{日期}.md
配置
Token 配置与其他 SFC 技能共用,优先级:
1. 环境变量 SFC_TOKEN
2. ~/.openclaw/identity/sfc_token
3. skills/sfc-etrade-sim/config.json 中的 api_key