44

数字货币的python量化交易(一)--量化策略框架

 3 years ago
source link: https://zhuanlan.zhihu.com/p/232151103
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

数字货币的python量化交易(一)--量化策略框架

专注数字货币的程序化交易

数字货币的入门,相对ctp来说,简单多了,github上有很多的demo,对于小白来说还是复杂了些。

我来做个简易的策略框架,希望对新手有所帮助。

策略代码分为三部分:

1,全局变量定义,一般在__init__中定义,比如self.ma=[],self.buy_price=0等

2,通过websocket获取行情、登陆账号、获得个人的订单推送等

3,通过收到的行情,计算指标和做逻辑判断,然后做下单、撤单等指令。

如下图所示,显示了okex平台的一个策略框架,运行程序的时候,先从strategy().run()来运行代码;run()是个无限循环,有时websocket断线的时候,通过这个来自动重连;runforever()函数是连接websocket,并okex的服务器订阅行情数据,如图则是订阅depth5的深度行情和1分钟的k线;然后对于获取的深度行情推向on_depth_data()和on_kbar_data(),这两个函数则执行策略的逻辑。

使用python执行这个文件,就可以看到打印出来的日志了,有推送来的深度和k线数据。

更进一步,可以在run_forever()做websocket的登陆,订阅账号、订单等推送信息,具体可以去平台看下具体的api文档。

策略代码可以查看:

https://github.com/steve-ay/quant_digital​github.com

需要注册okex的可以点这边:

Welcome Bonus | Register in OKEx | Cryptocurrency Bitcoin Registration | 1907863​www.okex.me图标


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK