下拉刷新
Repository Details
Shared bynavbar_avatar
repo_avatar
HelloGitHub Rating
0 ratings
天勤量化 Python 开发包
FreeApache-2.0
Claim
Collect
Share
3.7k
Stars
Yes
Chinese
Python
Language
Yes
Active
16
Contributors
79
Issues
Yes
Organization
3.7.4
Latest
657
Forks
Apache-2.0
License
More
tqsdk-python image
开源的 Python 量化交易框架。使用少量代码即可实现量化交易程序,还支持历史数据、实时数据、策略回测、实盘交易、图形化界面展示等功能。但免费版本仅提供全部的期货、商品/金融期权和上证50、沪深300 和中证500 的实时行情,付费版支持更多种类以及更加稳定的服务 ```python from tqsdk import TqApi, TqAuth, TqAccount, TargetPosTask api = TqApi(TqAccount("H海通期货", "4003242", "123456"), auth=TqAuth("信易账户", "账户密码")) # 创建 TqApi 实例, 指定交易账户 q_1910 = api.get_quote("SHFE.rb1910") # 订阅近月合约行情 t_1910 = TargetPosTask(api, "SHFE.rb1910") # 创建近月合约调仓工具 q_2001 = api.get_quote("SHFE.rb2001") # 订阅远月合约行情 t_2001 = TargetPosTask(api, "SHFE.rb2001") # 创建远月合约调仓工具 while True: api.wait_update() # 等待数据更新 spread = q_1910.last_price - q_2001.last_price # 计算近月合约-远月合约价差 print("当前价差:", spread) if spread > 250: print("价差过高: 空近月,多远月") t_1910.set_target_volume(-1) # 要求把1910合约调整为空头1手 t_2001.set_target_volume(1) # 要求把2001合约调整为多头1手 elif spread < 200: print("价差回复: 清空持仓") # 要求把 1910 和 2001合约都调整为不持仓 t_1910.set_target_volume(0) t_2001.set_target_volume(0) ```
Included in:
Vol.64
Tags:
Quantitative
Python

Comments

Rating:
No comments yet