Skip to main content

Easy ctp trade and market support

Project description

ctpbee

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用户无须设置 
sudo ctpbee -auto generate

灵感起源

使用来自于vnpy的交易接口, 重新提供上层封装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

回测截图

支持多周期多合约回测

avatar

PR支持

Only Accept PR code to dev branch, please remember that !

对于本地数据自动运维方案, 请👉 Hive

模拟测试 && 免责声明

本项目长期维护, 开源仅作爱好,本人不对代码产生的任何使用后果负责. 功能尽可能会保持稳定, 但是为了你的实盘账户着想,请先用simnow 或者openctp账户测试完善再上实盘!

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

遇到问题

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

License

  • MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctpbee-1.5.8.tar.gz (103.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page