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
点击阅读 document address
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支持
更多相关信息, 请参阅文档
支持多周期多合约回测
Only Accept PR code to dev
branch, please remember that !
对于高频解决方案, 请 👉 FlashFunk 注意: 本项目受限于协议问题无法开源数据底层.
对于本地数据自动运维方案, 请👉 Hive
本项目长期维护, 开源仅作爱好,本人不对代码产生的任何使用后果负责。功能尽可能会保持稳定, 但是为了你的实盘账户着想,请先用simnow
账户测试完善再上实盘!
如有问题, 请提issue, 会在1-2个工作日进行回复。
- MIT