Skip to main content

TianQin SDK

Project description

TqSdk 天勤量化交易策略程序开发包

TqSdk 是一个由信易科技发起并贡献主要代码的开源 python 库. 依托快期多年积累成熟的交易及行情服务器体系, TqSdk 支持用户使用极少的代码量构建各种类型的量化交易策略程序, 并提供包含期货、期权、股票的 历史数据-实时数据-开发调试-策略回测-模拟交易-实盘交易-运行监控-风险管理 全套解决方案.

from tqsdk import TqApi, TqAccount, TargetPosTask

api = TqApi(TqAccount("H海通期货", "4003242", "123456"))      # 创建 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)

要快速了解如何使用TqSdk, 可以访问我们的 十分钟快速入门指南.

Architecture

系统架构图

Features

TqSdk 提供的功能可以支持从简单到复杂的各类策略程序.

  • 公司级数据运维,提供当前所有可交易合约从上市开始的 全部Tick数据和K线数据
  • 支持市场上90%的期货公司 实盘交易
  • 支持 模拟交易
  • 支持 Tick级和K线级回测, 支持 复杂策略回测
  • 提供近百个 技术指标函数及源码
  • 用户无须建立和维护数据库, 行情和交易数据全在 内存数据库 , 无访问延迟
  • 优化支持 pandasnumpy
  • 无强制框架结构, 支持任意复杂度的策略, 在一个交易策略程序中使用多个品种的K线/实时行情并交易多个品种
  • 配合开发者支持工具,能够进行交易信号打点,支持自定义指标画图

Installation

TqSdk 仅支持 Python 3.6 及更高版本. 要安装 TqSdk, 可使用 pip:

$ pip install tqsdk

Documentation

在线阅读HTML版本文档: https://doc.shinnytech.com/tqsdk/latest

在线问答社区: https://www.shinnytech.com/qa

知乎账户【天勤量化】:https://www.zhihu.com/org/tian-qin-liang-hua/activities

用户交流QQ群: 619870862 (目前只允许给我们点过STAR的同学加入, 加群时请提供github用户名)

Gui

TqSdk本身自带的web_gui功能,简单一行参数即可支持调用图形化界面,详情参考web_gui TqSdk web_gui

About us

信易科技 是专业的期货软件供应商和交易所授权行情服务商. 旗下的快期系列产品已为市场服务超过10年. TqSdk 是公司开源计划的一部分.

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tqsdk-2.0.3-py3-none-win_amd64.whl (3.1 MB view details)

Uploaded Python 3Windows x86-64

tqsdk-2.0.3-py3-none-win32.whl (3.0 MB view details)

Uploaded Python 3Windows x86

tqsdk-2.0.3-py3-none-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded Python 3

tqsdk-2.0.3-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

Details for the file tqsdk-2.0.3-py3-none-win_amd64.whl.

File metadata

  • Download URL: tqsdk-2.0.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for tqsdk-2.0.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e78399de18f9e2f42981dc391bcbea1d28f156666b1733d199c6bdc6d2d56b03
MD5 cbb14b43b57ca014d2e5b6c37fb5493d
BLAKE2b-256 a00b1f71753ba7e655f2270d424f16e7464182ee392acd5760df10686db391a9

See more details on using hashes here.

File details

Details for the file tqsdk-2.0.3-py3-none-win32.whl.

File metadata

  • Download URL: tqsdk-2.0.3-py3-none-win32.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for tqsdk-2.0.3-py3-none-win32.whl
Algorithm Hash digest
SHA256 4c81eeb9213a97fff5ea43ed1034a955825f231d0e759f01322fe154111a478c
MD5 0c7f1afc94b25b4f06d30810fc156880
BLAKE2b-256 4aa547c2e9bea77d4040b4f83bc865cd951534e3151c81444269958d7ee1a113

See more details on using hashes here.

File details

Details for the file tqsdk-2.0.3-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: tqsdk-2.0.3-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for tqsdk-2.0.3-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 09a0f4b1c3fed609264749c78e071e710713b1ca5daeab1f91fbe2a9792c9b25
MD5 613d032f4cdafb1b3f096a37d819c14a
BLAKE2b-256 b4a51dbee791836a91ea14889e65c2f9c7f73997b25679270a9303ae8fc369c3

See more details on using hashes here.

File details

Details for the file tqsdk-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: tqsdk-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for tqsdk-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 630defa5851f1b53455127365fbcb7b0ed6e348d975436ad9531a95e50daf008
MD5 de0a0d317cf33bbdf2dea16f89424722
BLAKE2b-256 f4c97e964a9e1f4b9826bc47121a9d72f36774c41b0b1707f9b7fac7f88db261

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page