Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked from ctpbee/ctpbee

简单易用的期货实盘ctp交易框架 支持ctp和ctp_mini

License

Notifications You must be signed in to change notification settings

xtyangzheng/ctpbee

Repository files navigation

ctpbee

avatar PyPI Latest Release Build Status PyPI Downloads License - MIT

bee bee .... for developer's trading ~

tiny but strong

ctpbee provide a micro core of trading, you can make trade and backtest in it.

环境设置

# linux用户快速生成中文支持/ windows用户无须设置 
## for root 
bee init-locale 
## for user, xxx为你的用户密码, 注意你当前用户需要拥有sudo权限 
bee init-locale --password xxxxx 

灵感起源

使用来自于vnpy的交易接口, 重新提供上层封装API, 简化安装流程, 提供快速实现交易功能.

快速安装

mac用户注意, ctpbee_api目前仅仅提供源码安装方式, 需要你预先安装ctpbee_api, 安装参见

# python version: 3.6+
# 源码安装 
git clone https://github.com/ctpbee/ctpbee && cd ctpbee && python3 setup.py install 
# pip源安装
pip3 install ctpbee

支持系统

  • Linux
  • Windows
  • MacOS

文档与交流

文档地址

论坛地址

快速开始

from ctpbee import CtpBee
from ctpbee import CtpbeeApi
from ctpbee.constant import *
class CTA(CtpbeeApi):
 def __init__(self, name):
 super().__init__(name)
 def on_init(self, init: bool) -> None: # 初始化完成回调 
 self.info("init successful")
 def on_tick(self, tick: TickData) -> None:
 print(tick.datetime, tick.last_price) # 打印tick时间戳以及最新价格 
 # 买开
 self.action.buy_open(tick.last_price, 1, tick)
 # 买平
 self.action.buy_close(tick.last_price, 1, tick)
 # 卖开
 self.action.sell_open(tick.last_price, 1, tick)
 # 卖平 
 self.action.sell_close(tick.last_price, 1, tick)
 # 获取合约的仓位
 position = self.center.get_position(tick.local_symbol)
 print(position)
 def on_contract(self, contract: ContractData) -> None:
 if contract.local_symbol == "rb2205.SHFE":
 self.action.subscribe(contract.local_symbol) # 订阅行情 
 print("合约乘数: ", contract.size)
if __name__ == '__main__':
 app = CtpBee('ctp', __name__)
 info = {
 "CONNECT_INFO": {
 "userid": "",
 "password": "",
 "brokerid": "",
 "md_address": "",
 "td_address": "",
 "appid": "",
 "auth_code": "",
 "product_info": ""
 },
 "INTERFACE": "ctp",
 "TD_FUNC": True, # Open trading feature
 }
 app.config.from_mapping(info) # loading config from dict object
 cta = CTA("cta")
 app.add_extension(cta)
 app.start() 

功能支持

  • 简单易用的下单功能
  • 仓位盈亏计算
  • 多周期多合约回测
  • 实时行情
  • k线生成
  • 回测报告生成
  • 自动运维
  • 插件系统的支持
  • 多交易接口支持
    • ctp
    • ctp_mini
    • rohon
    • open_ctp

更多相关信息, 请参阅文档

命令行运行效果

avatar

回测截图

支持多周期多合约回测, 回测参考example/backtest示例 avatar

模拟交易测试

本项目推荐使用openctp 或者simnow做模拟交易测试

关于如何对接openctp,请参阅此教程click here

DEMO: 推荐参阅openctp分发实现

遇到问题?

请提交issue或者于issue搜索关键字, 或者查阅此处

历史数据支持

对于本地数据自动运维方案, 请👉 Hive 本项目不提供直接的历史数据访问服务.

插件支持

ctpbee提供了一个ToolRegister机制以支持访问数据触发机制, 可以实现交易各类插件.

欢迎各位大佬参与开发进来. 实现相关生态功能. 如果有相关疑惑, 可以发送邮件到somewheve@gmail.com寻求技术支持. 下面是提供的插件列表

  • ctpbee_kline k线支持插件
  • ctpbee_webline 使用flask编写后端, 通过with_tools接口接入策略, vue3+tauri 编写桌面应用, 敬请期待

免责声明

本项目长期维护, 开源仅作爱好, 本人不对代码产生的任何使用后果负责. 功能尽可能会保持稳定.

License

  • MIT

About

简单易用的期货实盘ctp交易框架 支持ctp和ctp_mini

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.3%
  • HTML 2.7%

AltStyle によって変換されたページ (->オリジナル) /