Skip to main content

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年.

Metadata

Release files for tqsdk2 2.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for tqsdk2 2.3.3
File
tqsdk2-2.3.3-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
tqsdk2-2.3.3-cp312-cp312-manylinux_2_31_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.31+ x86-64 Details
tqsdk2-2.3.3-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
tqsdk2-2.3.3-cp311-cp311-manylinux_2_31_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.31+ x86-64 Details
tqsdk2-2.3.3-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
tqsdk2-2.3.3-cp310-cp310-manylinux_2_31_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.31+ x86-64 Details
tqsdk2-2.3.3-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
tqsdk2-2.3.3-cp39-cp39-manylinux_2_31_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.31+ x86-64 Details
tqsdk2-2.3.3-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
tqsdk2-2.3.3-cp38-cp38-manylinux_2_31_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.31+ x86-64 Details
tqsdk2-2.3.3-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
tqsdk2-2.3.3-cp37-cp37m-manylinux_2_31_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.31+ x86-64 Details

Total release size: 28.0 MB

Release files / tqsdk2-2.3.3-cp312-cp312-win_amd64.whl

Download URL tqsdk2-2.3.3-cp312-cp312-win_amd64.whl
Size 2.0 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
93936adc3ab9a40252ace548dc73f4f31cf69ae1babd824ed66b02d7e3e4c420
BLAKE2b-256 checksum
How to use checksums
5b1e8a1d2f19a9af6eee5da2d496f9ad000359ba58f2c9046a0e7ac90a433192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp312-cp312-manylinux_2_31_x86_64.whl

Download URL tqsdk2-2.3.3-cp312-cp312-manylinux_2_31_x86_64.whl
Size 2.6 MB
Tags CPython 3.12 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
b7366b10cc7767184a686e716caf7c7524b091f5798d670de80a93ffc2615f1b
BLAKE2b-256 checksum
How to use checksums
2c701403f42988b38bcd2f6c02cf9b92a0343128c73dbfa12f79c8cb6e2c208c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp311-cp311-win_amd64.whl

Download URL tqsdk2-2.3.3-cp311-cp311-win_amd64.whl
Size 2.0 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
9c48ff76fa6298720bcbfa8873c9bf28ba92fc9b858ed22d03c43e2287da2a7b
BLAKE2b-256 checksum
How to use checksums
ef891878f633d205613f57cd1d69edc7b4d7d8e45542bf3599af12e3ac4661b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp311-cp311-manylinux_2_31_x86_64.whl

Download URL tqsdk2-2.3.3-cp311-cp311-manylinux_2_31_x86_64.whl
Size 2.6 MB
Tags CPython 3.11 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
27b89920e5087166f1bd928f3b3492b1df77f762f2b94884f27cdeca3beb905b
BLAKE2b-256 checksum
How to use checksums
d264cc2b42046fd09a2bc4c074ab1047f3e700e8ab58d3f868852cf03483277d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp310-cp310-win_amd64.whl

Download URL tqsdk2-2.3.3-cp310-cp310-win_amd64.whl
Size 2.0 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
0df8e22b3a2ea8d2a9ff8e9fde8536d14f653eee116a20e776b52bef3f56683f
BLAKE2b-256 checksum
How to use checksums
2fb80fd8f3668591fd98af569bbea1d72a7d600a214ccac8d5d06653b6bb8bc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp310-cp310-manylinux_2_31_x86_64.whl

Download URL tqsdk2-2.3.3-cp310-cp310-manylinux_2_31_x86_64.whl
Size 2.6 MB
Tags CPython 3.10 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
f50493633c5e9ec5d37d2e97f3cd8db4457f2db015a6ffd4c991e95cef8a95d8
BLAKE2b-256 checksum
How to use checksums
3162a8e52cb5b5106512ebe053a82f4342e2e983512c139efb3d3a3b4f949e93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp39-cp39-win_amd64.whl

Download URL tqsdk2-2.3.3-cp39-cp39-win_amd64.whl
Size 2.1 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
229ec2cb59ec856b590dac4bbaf0c3cbc25969c5e66ecd00031c407018e3d117
BLAKE2b-256 checksum
How to use checksums
dddfa6be576b850b4d328fde2045f6cfd3b9b280f7c44e5748e937e32fd88357
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp39-cp39-manylinux_2_31_x86_64.whl

Download URL tqsdk2-2.3.3-cp39-cp39-manylinux_2_31_x86_64.whl
Size 2.6 MB
Tags CPython 3.9 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
191a99ee25d3ba1da2223f7f33f5bf9a1b4ba3270b5b2e4625c4b8256f70eb78
BLAKE2b-256 checksum
How to use checksums
2150ad649a4a60034070154cd41cf34672fa944b62fa4b8e7c1f9be533623401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp38-cp38-win_amd64.whl

Download URL tqsdk2-2.3.3-cp38-cp38-win_amd64.whl
Size 2.0 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
a3d6fd02e5d36280ac99d7558a9aa2b91df498bb63f4e56d410568ea2adbb758
BLAKE2b-256 checksum
How to use checksums
4e046ac87f478248e265778299c7a195d0ceadafddaf3d3a4565b65b8f7b4aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp38-cp38-manylinux_2_31_x86_64.whl

Download URL tqsdk2-2.3.3-cp38-cp38-manylinux_2_31_x86_64.whl
Size 2.6 MB
Tags CPython 3.8 Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
1f5fa5b5d873d86eeff8c496fa72fc302e94c0c41e661fc808b544adab417bfd
BLAKE2b-256 checksum
How to use checksums
2e0b7cb11890353cf6015221b36eda23c3b65c7d75016263d216e2dd21547130
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp37-cp37m-win_amd64.whl

Download URL tqsdk2-2.3.3-cp37-cp37m-win_amd64.whl
Size 2.0 MB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
1dc0b3f475e34188d2328acf37120f02a6321a5c52355695ddad3072175e4ff6
BLAKE2b-256 checksum
How to use checksums
acd6b57cfbdaa4899a7b9f8ff445b81d0148553953b0c36797b9602b595791c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / tqsdk2-2.3.3-cp37-cp37m-manylinux_2_31_x86_64.whl

Download URL tqsdk2-2.3.3-cp37-cp37m-manylinux_2_31_x86_64.whl
Size 2.7 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.31+ x86-64
SHA-256 checksum
How to use checksums
98e468eb2c32d358f4dc9e5e84fdfbe5ff9f4ea1a6980d9064a7579c6d18a870
BLAKE2b-256 checksum
How to use checksums
059119531aa77a1a12e69e7fe56945269f3fad8ba22baa16b10d1be4ea1aef9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

2.3.3 This release

12 release files

2.3.1

12 release files

2.3.0

12 release files

2.2.8

12 release files

2.2.6

9 release files

2.2.5

9 release files

2.2.4

9 release files

2.2.3

9 release files

2.2.2

9 release files

2.2.1

9 release files

2.1.11

9 release files

2.1.10

9 release files

2.1.9

9 release files

2.1.8

2 release files

2.1.7

9 release files

2.1.6

9 release files

2.1.5

9 release files

2.1.4

9 release files

2.1.3

9 release files

2.1.2

9 release files

2.1.1

9 release files

2.1.0

9 release files

2.0.8

9 release files

2.0.7

9 release files

2.0.6

9 release files

2.0.5

9 release files

2.0.4

9 release files

2.0.3

9 release files

2.0.2

9 release files

2.0.1

9 release files

2.0.0

9 release files

1.9.9

9 release files

1.9.8

7 release files

1.9.7

7 release files

1.9.6

7 release files

1.9.5

7 release files

1.9.4

7 release files

1.9.3

7 release files

1.9.2

7 release files

1.9.1

7 release files

1.9.0

7 release files

1.8.9

7 release files

1.8.8

7 release files

1.8.7

7 release files

1.8.6

7 release files

1.8.5

7 release files

1.8.4

7 release files

1.8.3

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page