TianQin SDK2
Project description
TqSdk2 天勤量化交易策略程序开发包
TqSdk2 是一个由 信易科技 发起并贡献主要代码的, 采用 C++ 核心架构, 对外提供 python 和 C++ 接口的库.
依托 快期多年积累成熟的交易和行情服务器体系 和开源量化 python 库 TqSdk, TqSdk2 支持用户使用很少的代码量构建各种类型的量化交易策略程序, 并提供包含 历史数据-实时数据-开发调试-策略回测-模拟交易-实盘交易-运行监控-风险管理 的全套解决方案
from tqsdk2 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)
要快速了解如何使用TqSdk2 , 可以访问我们的 十分钟快速入门指南.
Features
TqSdk2 提供的功能可以支持从简单到复杂的各类策略程序.
- 提供当前所有可交易合约从上市开始的 全部Tick数据和K线数据
- 支持数十家期货公司的 实盘交易
- 支持通过直连模式接入期货公司进行交易
- 支持直连直连模式接入期货公司 CTP 柜台
- 支持 模拟交易
- 提供近百个 技术指标函数及源码
- 用户无须建立和维护数据库, 行情和交易数据全在 内存数据库 , 无访问延迟
- 优化支持 pandas 和 numpy 库
- 无强制框架结构, 支持任意复杂度的策略, 在一个交易策略程序中使用多个品种的K线/实时行情并交易多个品种
Installation
TqSdk2 支持 Windows 和 Ubuntu 20.04 环境下 Python 3.6.4 及以上版本。
Windows
TqSdk2 核心代码依赖 C++ 运行库, 若您的环境中缺少该库, 可以到微软官网下载安装对应版本即可( vc_redist 下载地址).
推荐使用 pip 进行安装
$ pip install tqsdk2
Linux
TqSdk2 采用发布包遵循 PEP600 标准, 支持 Linux 发行版如下:
安装如下:
$ sudo apt update
$ sudo apt install -y build-essential
$ sudo apt install -y python3 python3-pip
$ sudo pip install pip --upgrade
$ sudo pip install tqsdk2
注: 国内用户使用 pip 进行 Python 包安装下载时, 默认采用的是国外镜像源, 下载速度可能较慢. 推荐切换至清华源 后再进行 TqSdk2 的下载安装.
Documentation
在线阅读HTML版本文档: https://doc.shinnytech.com/tqsdk2/latest
在线问答社区: https://www.shinnytech.com/qa
知乎账户【天勤量化】:https://www.zhihu.com/org/tian-qin-liang-hua/activities
用户交流QQ群: 619870862 (目前只允许给我们点过STAR的同学加入, 加群时请提供github用户名)
License
TqSdk2 在 Apache License 2.0 协议下提供, 使用者可在遵循此协议的前提下自由使用本软件.
About us
信易科技 是专业的期货软件供应商和交易所授权行情服务商. 旗下的快期系列产品已为市场服务超过10年.
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 Distributions
Built Distributions
File details
Details for the file tqsdk2-2.3.3-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93936adc3ab9a40252ace548dc73f4f31cf69ae1babd824ed66b02d7e3e4c420 |
|
MD5 | 21eb670e6be16c4acee17f55bd76b2de |
|
BLAKE2b-256 | 5b1e8a1d2f19a9af6eee5da2d496f9ad000359ba58f2c9046a0e7ac90a433192 |
File details
Details for the file tqsdk2-2.3.3-cp312-cp312-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp312-cp312-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.12, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7366b10cc7767184a686e716caf7c7524b091f5798d670de80a93ffc2615f1b |
|
MD5 | b52d3580770d4a6da374153a30b06ac6 |
|
BLAKE2b-256 | 2c701403f42988b38bcd2f6c02cf9b92a0343128c73dbfa12f79c8cb6e2c208c |
File details
Details for the file tqsdk2-2.3.3-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c48ff76fa6298720bcbfa8873c9bf28ba92fc9b858ed22d03c43e2287da2a7b |
|
MD5 | a058462022faa3a6967aca6b2f745607 |
|
BLAKE2b-256 | ef891878f633d205613f57cd1d69edc7b4d7d8e45542bf3599af12e3ac4661b1 |
File details
Details for the file tqsdk2-2.3.3-cp311-cp311-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27b89920e5087166f1bd928f3b3492b1df77f762f2b94884f27cdeca3beb905b |
|
MD5 | 83169b7e9268b35b8b4cd093b8de99fa |
|
BLAKE2b-256 | d264cc2b42046fd09a2bc4c074ab1047f3e700e8ab58d3f868852cf03483277d |
File details
Details for the file tqsdk2-2.3.3-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0df8e22b3a2ea8d2a9ff8e9fde8536d14f653eee116a20e776b52bef3f56683f |
|
MD5 | f3197ae4941e7f2b7bc8253f47225c48 |
|
BLAKE2b-256 | 2fb80fd8f3668591fd98af569bbea1d72a7d600a214ccac8d5d06653b6bb8bc6 |
File details
Details for the file tqsdk2-2.3.3-cp310-cp310-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp310-cp310-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.10, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f50493633c5e9ec5d37d2e97f3cd8db4457f2db015a6ffd4c991e95cef8a95d8 |
|
MD5 | 2cf39b1efff5e322849c76babcc9b7d7 |
|
BLAKE2b-256 | 3162a8e52cb5b5106512ebe053a82f4342e2e983512c139efb3d3a3b4f949e93 |
File details
Details for the file tqsdk2-2.3.3-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229ec2cb59ec856b590dac4bbaf0c3cbc25969c5e66ecd00031c407018e3d117 |
|
MD5 | 44aca082eacb7a112e3b1289f8ccdfaa |
|
BLAKE2b-256 | dddfa6be576b850b4d328fde2045f6cfd3b9b280f7c44e5748e937e32fd88357 |
File details
Details for the file tqsdk2-2.3.3-cp39-cp39-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp39-cp39-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 191a99ee25d3ba1da2223f7f33f5bf9a1b4ba3270b5b2e4625c4b8256f70eb78 |
|
MD5 | 98e33fa2445e75634460a150ac966b2f |
|
BLAKE2b-256 | 2150ad649a4a60034070154cd41cf34672fa944b62fa4b8e7c1f9be533623401 |
File details
Details for the file tqsdk2-2.3.3-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3d6fd02e5d36280ac99d7558a9aa2b91df498bb63f4e56d410568ea2adbb758 |
|
MD5 | f0c4e9bda14ae2fb3f2da2746920238e |
|
BLAKE2b-256 | 4e046ac87f478248e265778299c7a195d0ceadafddaf3d3a4565b65b8f7b4aac |
File details
Details for the file tqsdk2-2.3.3-cp38-cp38-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp38-cp38-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.8, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f5fa5b5d873d86eeff8c496fa72fc302e94c0c41e661fc808b544adab417bfd |
|
MD5 | 34177aa3813c3339686ad14b35641977 |
|
BLAKE2b-256 | 2e0b7cb11890353cf6015221b36eda23c3b65c7d75016263d216e2dd21547130 |
File details
Details for the file tqsdk2-2.3.3-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dc0b3f475e34188d2328acf37120f02a6321a5c52355695ddad3072175e4ff6 |
|
MD5 | 14efddff9effd8092c58836cc9df56cf |
|
BLAKE2b-256 | acd6b57cfbdaa4899a7b9f8ff445b81d0148553953b0c36797b9602b595791c7 |
File details
Details for the file tqsdk2-2.3.3-cp37-cp37m-manylinux_2_31_x86_64.whl
.
File metadata
- Download URL: tqsdk2-2.3.3-cp37-cp37m-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.7m, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98e468eb2c32d358f4dc9e5e84fdfbe5ff9f4ea1a6980d9064a7579c6d18a870 |
|
MD5 | da3d11bf9254f947bb4ca2ec5e889f34 |
|
BLAKE2b-256 | 059119531aa77a1a12e69e7fe56945269f3fad8ba22baa16b10d1be4ea1aef9b |