{"id":13488443,"url":"https://github.com/shinnytech/tqsdk-python","last_synced_at":"2026-04-16T09:08:42.760Z","repository":{"id":37405455,"uuid":"136556542","full_name":"shinnytech/tqsdk-python","owner":"shinnytech","description":"天勤量化开发包, 期货量化, 实时行情/历史数据/实盘交易","archived":false,"fork":false,"pushed_at":"2026-01-19T09:12:23.000Z","size":56572,"stargazers_count":4453,"open_issues_count":90,"forks_count":730,"subscribers_count":117,"default_branch":"master","last_synced_at":"2026-01-27T00:17:29.502Z","etag":null,"topics":["diff","futures","program-trading","python","quant","team-fi"],"latest_commit_sha":null,"homepage":"https://doc.shinnytech.com/tqsdk/latest","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnytech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-06-08T02:38:38.000Z","updated_at":"2026-01-26T23:56:55.000Z","dependencies_parsed_at":"2024-01-24T08:31:55.617Z","dependency_job_id":"a8b1c642-2794-481f-a0b3-8e084098f545","html_url":"https://github.com/shinnytech/tqsdk-python","commit_stats":null,"previous_names":[],"tags_count":109,"template":false,"template_full_name":null,"purl":"pkg:github/shinnytech/tqsdk-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnytech%2Ftqsdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnytech%2Ftqsdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnytech%2Ftqsdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnytech%2Ftqsdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnytech","download_url":"https://codeload.github.com/shinnytech/tqsdk-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnytech%2Ftqsdk-python/sbom","scorecard":{"id":819221,"data":{"date":"2025-08-11","repo":{"name":"github.com/shinnytech/tqsdk-python","commit":"c5fd96afd024c301e5bd9d3c45b238f1d2b4a8d5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":3,"reason":"4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/run-tqsdk.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":0,"reason":"dangerous workflow patterns detected","details":["Warn: script injection with untrusted input ' github.event.head_commit.message ': .github/workflows/run-tqsdk.yml:29"],"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-tqsdk.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/shinnytech/tqsdk-python/run-tqsdk.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/run-tqsdk.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/shinnytech/tqsdk-python/run-tqsdk.yml/master?enable=pin","Info:   0 out of   1 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"32 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2023-120 / GHSA-45c4-8wx5-qw6w","Warn: Project is vulnerable to: GHSA-5m98-qgg9-wh84","Warn: Project is vulnerable to: GHSA-7gpw-8wmc-pm8g","Warn: Project is vulnerable to: GHSA-8495-4g3g-x7pr","Warn: Project is vulnerable to: PYSEC-2024-26 / GHSA-8qpw-xqxj-h4r2","Warn: Project is vulnerable to: GHSA-9548-qrrj-x5pj","Warn: Project is vulnerable to: PYSEC-2023-246 / GHSA-gfw2-4jvh-wgfg","Warn: Project is vulnerable to: GHSA-pjjw-qhg8-p2p9","Warn: Project is vulnerable to: PYSEC-2023-250 / GHSA-q3qx-c6g2-7pw2","Warn: Project is vulnerable to: PYSEC-2023-251 / GHSA-qvrw-v9rv-5rjx","Warn: Project is vulnerable to: PYSEC-2021-76 / GHSA-v6wp-4m6f-gcjg","Warn: Project is vulnerable to: PYSEC-2023-247 / GHSA-xx9p-xxvh-7g8j","Warn: Project is vulnerable to: PYSEC-2018-34 / GHSA-2fc2-6r4j-p65h","Warn: Project is vulnerable to: PYSEC-2021-856 / GHSA-5545-2q6w-2gh6","Warn: Project is vulnerable to: PYSEC-2019-108 / GHSA-9fq2-x9r6-wfmf","Warn: Project is vulnerable to: PYSEC-2018-33 / GHSA-cw6w-4rcx-xphc","Warn: Project is vulnerable to: PYSEC-2021-857 / GHSA-f7c7-j99h-c22f","Warn: Project is vulnerable to: GHSA-fpfv-jqm9-f5jm","Warn: Project is vulnerable to: PYSEC-2017-1 / GHSA-frgw-fgh6-9g52","Warn: Project is vulnerable to: PYSEC-2017-24 / GHSA-r9jw-mwhq-wp62","Warn: Project is vulnerable to: PYSEC-2014-14 / GHSA-652x-xj99-gmcc","Warn: Project is vulnerable to: GHSA-9hjg-9r4m-mvj7","Warn: Project is vulnerable to: GHSA-9wx4-h78v-vm56","Warn: Project is vulnerable to: PYSEC-2014-13 / GHSA-cfj3-7x9c-4p3h","Warn: Project is vulnerable to: PYSEC-2018-28 / GHSA-x84v-xcm2-53pg","Warn: Project is vulnerable to: PYSEC-2019-156 / GHSA-xp76-357g-9wqq","Warn: Project is vulnerable to: PYSEC-2023-102","Warn: Project is vulnerable to: PYSEC-2023-114","Warn: Project is vulnerable to: PYSEC-2022-43167","Warn: Project is vulnerable to: PYSEC-2023-206","Warn: Project is vulnerable to: GHSA-9772-cwx9-r4cj","Warn: Project is vulnerable to: PYSEC-2021-95 / GHSA-8ch4-58qp-g3mp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T14:57:44.347Z","repository_id":37405455,"created_at":"2025-08-23T14:57:44.347Z","updated_at":"2025-08-23T14:57:44.347Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31878916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T07:36:03.521Z","status":"ssl_error","status_checked_at":"2026-04-16T07:35:53.576Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","futures","program-trading","python","quant","team-fi"],"created_at":"2024-07-31T18:01:15.863Z","updated_at":"2026-04-16T09:08:42.753Z","avatar_url":"https://github.com/shinnytech.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src =\"https://raw.githubusercontent.com/shinnytech/tqsdk-python/master/doc/images/tqsdk_new_logo.png\"/\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src =\"https://img.shields.io/pypi/v/tqsdk?color=blueviolet\"\u003e\n    \u003cimg src =\"https://img.shields.io/badge/platform-windows|linux|macos-green.svg\"/\u003e\n    \u003cimg src =\"https://img.shields.io/badge/python-3.8+-blue.svg\" /\u003e\n    \u003cimg src =\"https://img.shields.io/pypi/dm/tqsdk?color=yellowgreen\"\u003e\n    \u003cimg src =\"https://img.shields.io/github/license/shinnytech/tqsdk-python.svg?color=orange\"/\u003e\n\u003c/p\u003e\n\n# TqSdk 天勤量化交易策略程序开发包\n\nTqSdk 是一个由[信易科技](https://www.shinnytech.com)发起并贡献主要代码的开源 Python 库。\nTqSdk 支持用户使用极少的代码量构建各种类型的量化交易策略程序，\n并提供包含期货、期权、股票的 历史数据-实时数据-开发调试-策略回测-模拟交易-实盘交易-运行监控-风险管理 全套解决方案。\n\n## 快速开始\n\n``` python\nfrom tqsdk import TqApi, TqAuth, TqAccount, TargetPosTask\n\napi = TqApi(TqAccount(\"H海通期货\", \"4003242\", \"123456\"), auth=TqAuth(\"快期账户\", \"账户密码\"))      # 创建 TqApi 实例, 指定交易账户\nq_2309 = api.get_quote(\"SHFE.rb2309\")                         # 订阅近月合约行情\nt_2309 = TargetPosTask(api, \"SHFE.rb2309\")                    # 创建近月合约调仓工具\nq_2401 = api.get_quote(\"SHFE.rb2401\")                         # 订阅远月合约行情\nt_2401 = TargetPosTask(api, \"SHFE.rb2401\")                    # 创建远月合约调仓工具\n\nwhile True:\n  api.wait_update()                                           # 等待数据更新\n  spread = q_2309[\"last_price\"] - q_2401[\"last_price\"]        # 计算近月合约-远月合约价差\n  print(\"当前价差:\", spread)\n  if spread \u003e 250:\n    print(\"价差过高: 空近月，多远月\")                            \n    t_2309.set_target_volume(-1)                              # 要求把2309合约调整为空头1手\n    t_2401.set_target_volume(1)                               # 要求把2401合约调整为多头1手\n  elif spread \u003c 200:\n    print(\"价差回复: 清空持仓\")                               # 要求把 2309 和 2401合约都调整为不持仓\n    t_2309.set_target_volume(0)\n    t_2401.set_target_volume(0)\n```\n\n要快速了解如何使用TqSdk，请访问我们的 [十分钟快速入门指南](https://doc.shinnytech.com/tqsdk/latest/quickstart.html)。\n\n## 系统架构\n\n\u003cimg alt=\"系统架构图\" src=\"https://raw.githubusercontent.com/shinnytech/tqsdk-python/master/doc/arch.svg?sanitize=true\"\u003e\n\n* 行情网关负责提供实时行情和历史数据\n* 交易中继网关负责连接到期货公司交易系统\n* 这两个网关统一以Diff协议对下方提供服务\n* TqSdk按照Diff协议连接到行情网关和交易中继网关，实现行情和交易功能\n\n## 主要功能特点\n\nTqSdk提供的功能可以支持从简单到复杂的各类策略程序：\n\n* **公司级数据运维**，提供当前所有可交易合约从上市开始的**全部Tick数据和K线数据**\n* **多账户支持**，支持使用多个实盘账户、模拟账户同时交易\n* **支持市场上90%的期货公司实盘交易**\n* **支持股票、期权、期货交易** \n* **支持CTP直连交易**，以及众期、融航、杰宜斯等资管柜台，易达、ctpmini 等高速柜台\n* **支持模拟交易**\n* **支持Tick级和K线级回测**，支持复杂策略回测\n* **提供近百个技术指标函数及源码**\n* **用户无须建立和维护数据库**，行情和交易数据全在内存数据库，无访问延迟\n* **优化支持pandas和numpy库**，方便数据分析\n* **灵活的策略编写方式**，无强制框架结构，支持任意复杂度的策略，在一个交易策略程序中使用多个品种的K线/实时行情并交易多个品种\n\n* **配合天勤AI助手**，提供函数解释、策略编写指导、错误分析等支持\n\n## 配合 AI / Agent 使用 TqSdk\n\n如果你想让自己的 AI、Agent 或 OpenClaw 更好地理解和使用 TqSdk，可以把下面这段内容直接复制给它：\n\n\u003e 请先下载并解压 TqSdk 技能包：https://doc.shinnytech.com/tqsdk/latest/ai_editor/skills/tqsdk-trading-and-data.zip，然后先阅读其中的 SKILL.md，并按里面的说明再回答任何 TqSdk 问题或编写任何 TqSdk 代码。\n\n相关文档与资源：\n\n* [通过 AI 工具使用 TqSdk](https://doc.shinnytech.com/tqsdk/latest/ai_editor/index.html)\n* [在 Trae 中高效学习和使用 TqSdk](https://doc.shinnytech.com/tqsdk/latest/ai_editor/tqsdk_trae.html)\n* [使用 Codex 协作开发 TqSdk 项目](https://doc.shinnytech.com/tqsdk/latest/ai_editor/tqsdk_codex.html)\n* [TqSdk Skills 压缩包与使用说明](https://doc.shinnytech.com/tqsdk/latest/ai_editor/tqsdk_skills.html)\n* [下载 TqSdk 技能包 `tqsdk-trading-and-data.zip`](https://doc.shinnytech.com/tqsdk/latest/ai_editor/skills/tqsdk-trading-and-data.zip)\n\n## 安装方法\n\nTqSdk 仅支持 Python 3.8 及更高版本。要安装 TqSdk，可使用 pip：\n\n```bash\npip install tqsdk\n```\n\n## 文档与社区支持\n\n在线阅读HTML版本文档: https://doc.shinnytech.com/tqsdk/latest\n\n知乎账户【天勤量化】：https://www.zhihu.com/org/tian-qin-liang-hua/activities\n\n天勤AI助手：https://www.shinnytech.com/products/tqsdk - 解释函数，编写demo策略，分析报错原因，它都可以做到！\n\n用户交流QQ群: **611806823** (目前只允许给我们点过STAR的同学加入, 加群时请提供github用户名)\n\n## 关于我们\n\n[信易科技](https://www.shinnytech.com) 是专业的期货软件供应商和交易所授权行情服务商。旗下的快期系列产品已为市场服务超过10年。TqSdk 是公司开源计划的一部分。\n\n","funding_links":[],"categories":["Python","Financial Data SDK","量化交易平台"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnytech%2Ftqsdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnytech%2Ftqsdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnytech%2Ftqsdk-python/lists"}