GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ctpbee/ctpbee: 简单易用的期货实盘ctp交易框架

BranchesTags
Open more actions menu

Latest commit

 

History

1,044 Commits
1,044 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
ci_script
ci_script
 
 
ctpbee
ctpbee
 
 
docs
docs
 
 
examples
examples
 
 
scraps
scraps
 
 
source
source
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
MANIFEST.in
MANIFEST.in
 
 
README.md
README.md
 
 
agentic.md
agentic.md
 
 
architecture.md
architecture.md
 
 
setup.py
setup.py
 
 

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.

🤖 AI 协作指引 / For AI Agents

如果你是 AI(Coding Agent),被要求阅读或修改本项目,请先阅读 agentic.md,再动任何代码。

该文件是本仓库的工作笔记:架构图与数据流、热路径规范(@frozen 规则 / 每 tick 禁止的可选依赖导入等)、已知边界(交易日历期限、DCE 时间戳口径等)、测试约定 (每次改动必须带全部通过的测试)以及完整变更历史。

忽略这些约定会静默损坏行情数据或破坏热路径吞吐。

If you are an AI coding agent working on this repository, read agentic.md before touching any code — it documents the architecture map, hot-path conventions, known edges, the standing rule that every change lands with passing tests, and the changelog. Violating those conventions silently corrupts tick data or breaks hot-path throughput.

环境设置

#  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

文档

📖 在线文档地址: https://ctpbee.github.io/ctpbee/ (GitHub Pages 自动部署,master 分支 docs/ 变更后自动更新)

  • 本地浏览完整版: docs/index.html —— 快速开始 · 配置 · 数据结构 · 策略 API · 下单接口 · Tool 用法 · 回测 · 注意事项

快速开始

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

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

简单策略示例

  • atr
  • bollinger
  • double_ma
  • macd
  • rsi

命令行运行效果

avatar

回测截图

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

模拟交易测试

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

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

DEMO: 推荐参阅openctp分发实现

遇到问题?

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

历史数据支持

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

插件支持

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

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

  • ctpbee_kline k线支持插件

还在苦恼ctpbee没有界面?

  • ctpbee_frontend 通过work_mode=Mode.DISPATCHER进行工作 (通过deepseek生成)

avatar

免责声明

本项目维护时间不定期, 开源仅作爱好, 请谨慎使用. 本人不对代码产生的任何使用后果负责. 推荐使用vnpy | wondertrader | quantaxis | openctp | tqsdk

License

  • MIT

About

简单易用的期货实盘ctp交易框架

Topics

ctpctpbeemicroframeworkquant

Resources

Readme
MIT license
Activity
Custom properties

Stars

1.0k stars

Watchers

44 watching

Forks

236 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.