返回顶部
q

quant-trading-api量化交易接口

Professional quantitative trading API integration for Chinese securities. Supports major Chinese brokers (华泰, 银河, 广发, 中信建投) with order management, position tracking, real-time market data, and automated trading workflows.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
102
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

quant-trading-api

量化交易API

面向中国证券经纪商的专业交易API。

支持的券商

券商状态功能
华泰证券完整API
银河证券
✅ | 完整API | | 广发证券 | ✅ | 完整API | | 中信建投 | ✅ | 完整API | | 同花顺 | ✅ | 通用接口 |

功能特性

1. 行情数据

  • - 实时行情:Level 1/2行情数据
  • K线数据:1分钟/5分钟/15分钟/30分钟/60分钟/日线
  • 盘口数据:前50档买卖盘口
  • 交易日历:A股交易日
  • 市场状态:开市/闭市/集合竞价

2. 订单管理

  • - 下单:限价单、市价单、止损单
  • 撤单:撤销未成交订单
  • 改单:修改订单价格/数量
  • 订单状态:跟踪订单生命周期
  • 订单历史:历史订单记录

3. 持仓跟踪

  • - 实时持仓:当前持仓
  • 持仓盈亏:未实现/已实现盈亏
  • 交易历史:成交记录
  • 当日交易:今日交易记录

4. 账户管理

  • - 账户余额:现金、持仓、总资产
  • 保证金信息:保证金比例、可用保证金
  • 权限管理:市价单/限价单权限

5. 自动化

  • - 定时交易:基于时间的执行
  • 条件单:价格/成交量触发
  • 策略框架:内置策略运行器
  • 风险控制:自动止损/止盈

安装

bash
pip install requests pycryptodome websocket-client

配置

python

config.py


BROKER_CONFIG = {
broker: huatai, # huatai, galaxy, gf, citic, tonghuashun
account: 123456789,
password: your_password,
server: trade.htsc.com.cn, # 交易服务器
market: sz # sh, sz
}

使用说明

初始化交易API

python from quant_trading import TradingAPI

api = TradingAPI(
broker=huatai,
account=123456789,
password=your_password
)

登录

api.login() print(f登录成功: {api.accountinfo[accountname]})

获取行情数据

python

实时行情

quote = api.get_quote(600519) print(f价格: {quote[price]}, 成交量: {quote[volume]})

K线数据

kline = api.get_kline(000858, period=60min, count=100) print(kline.tail())

下单

python

买入股票

order = api.buy( symbol=600519, price=1850.0, volume=100 ) print(f订单ID: {order[order_id]})

卖出股票

order = api.sell( symbol=600519, price=1900.0, volume=100 )

订单管理

python

撤单

api.cancelorder(orderid=123456)

获取订单状态

status = api.getorder(orderid=123456) print(f状态: {status[status]})

获取所有订单

orders = api.get_orders(status=pending)

持仓与账户

python

获取持仓

positions = api.get_positions() for pos in positions: print(f{pos[symbol]}: {pos[volume]}股, 盈亏: {pos[pnl]})

获取账户余额

balance = api.get_balance() print(f总资产: {balance[total_assets]}) print(f可用资金: {balance[available]})

API参考

连接
方法描述
login()登录券商
logout()
登出 |

| heartbeat() | 保持连接活跃 |

行情数据
方法描述
getquote(symbol)获取实时行情
getkline(symbol, period, count)
获取K线数据 |

| get_orderbook(symbol) | 获取盘口数据 | | gettradingcalendar(start, end) | 获取交易日 |

订单
方法描述
buy(symbol, price, volume)买入订单
sell(symbol, price, volume)
卖出订单 |

| cancelorder(orderid) | 撤销订单 | | getorder(orderid) | 获取订单状态 | | get_orders(status) | 获取所有订单 |

持仓
方法描述
getpositions()获取当前持仓
gettrades()
获取今日成交 |

| get_history(start, end) | 历史记录 |

账户
方法描述
getbalance()获取账户余额
getmargin()
获取保证金信息 |

高级用法

自动化交易策略

python from quant_trading import TradingAPI, Strategy

class MomentumStrategy(Strategy):
def init(self, api):
self.api = api

def on_bar(self, bar):
# 检查信号
if self.check_signal(bar):
# 下单
self.api.buy(bar[symbol], bar[close], 100)

def check_signal(self, bar):
# 你的逻辑
return bar[volume] > 1000000

运行策略

api = TradingAPI(...) strategy = MomentumStrategy(api) api.run_strategy(strategy)

定时交易

python

在指定时间执行

api.schedule_order( symbol=600519, direction=buy, price=1850.0, volume=100, execute_time=09:35:00 )

止损/止盈

python

设置止损

api.setstoploss( symbol=600519, entry_price=1850.0, stoplosspct=0.05 # 5%止损 )

设置止盈

api.settakeprofit( symbol=600519, entry_price=1850.0, takeprofitpct=0.15 # 15%止盈 )

错误处理

python
try:
order = api.buy(600519, 1850.0, 100)
except OrderError as e:
print(f下单失败: {e.message})
if e.code == INSUFFICIENT_BALANCE:
print(余额不足)
elif e.code == LIMIT_UP:
print(股票涨停)
elif e.code == SUSPENDED:
print(股票停牌)

常见错误码

错误码描述
SUCCESS下单成功
INSUFFICIENT_BALANCE
资金不足 | | INSUFFICIENT_POSITION | 持仓不足 | | LIMIT_UP | 股票涨停 | | LIMIT_DOWN | 股票跌停 | | SUSPENDED | 股票停牌 | | NOT_TRADING | 非交易时间 | | INVALID_PRICE | 价格超出范围 |

最佳实践

  1. 1. 连接管理:失败时重新连接
  2. 频率限制:不超过API限制
  3. 订单验证:下单前验证
  4. 错误处理:始终处理异常
  5. 日志记录:记录所有交易活动
  6. 风险控制:设置止损/止盈

链接

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 quant-trading-api-1776100406 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 quant-trading-api-1776100406 技能

通过命令行安装

skillhub install quant-trading-api-1776100406

下载

⬇ 下载 quant-trading-api v1.0.0(免费)

文件大小: 7.26 KB | 发布时间: 2026-4-14 13:50

v1.0.0 最新 2026-4-14 13:50
Initial release of quant-trading-api.

- Integrates with major Chinese securities brokers (华泰, 银河, 广发, 中信建投, 同花顺)
- Provides real-time and historical market data, order management, and position tracking
- Features automated trading workflows, including scheduled and conditional orders, stop loss/take profit
- Includes detailed usage examples, configuration instructions, and API reference
- Supports error handling with common error codes and best practice recommendations

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部