tdx-quant-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese通达信量化开发技能 (TdxQuant Development Skill)
TdxQuant Development Skill
本技能用于辅助在通达信量化平台 (TdxQuant) 上开发量化交易策略。
This skill is used to assist in developing quantitative trading strategies on the Tongda Xin quantitative platform (TdxQuant).
核心概念
Core Concepts
TdxQuant 将 Python 集成到通达信金融终端中。它允许 Python 脚本访问实时和历史行情数据并执行交易策略。
核心模块是 。
tqcenterTdxQuant integrates Python into the Tongda Xin financial terminal. It allows Python scripts to access real-time and historical market data and execute trading strategies.
The core module is .
tqcenter环境配置
Environment Configuration
1. Python 路径设置
1. Python Path Setting
要使用 模块,必须确保 Python 环境能找到该模块。该模块通常位于通达信安装目录下的 目录中 (例如 )。
tqcenterPYPlugins/userC:/new_tdx64/PYPlugins/user通常需要在导入前将此路径添加到 :
sys.pathpython
import sys
sys.path.append('C:/new_tdx64/PYPlugins/user')
from tqcenter import tq
if __name__ == '__main__':
#所有策略连接通达信客户端都必须调用此函数进行初始化
tq.initialize(__file__)
#获取平安银行日线前复权收盘数据
df = tq.get_market_data(
field_list = ['Close'],
stock_list = ["000001.SZ"],
start_time = '20251219',
end_time = '20251225',
dividend_type='front',
period='1d',
)
print(df)To use the module, you must ensure that the Python environment can locate the module. This module is usually located in the directory under the Tongda Xin installation directory (e.g. ).
tqcenterPYPlugins/userC:/new_tdx64/PYPlugins/userYou usually need to add this path to before importing:
sys.pathpython
import sys
sys.path.append('C:/new_tdx64/PYPlugins/user')
from tqcenter import tq
if __name__ == '__main__':
#所有策略连接通达信客户端都必须调用此函数进行初始化
tq.initialize(__file__)
#获取平安银行日线前复权收盘数据
df = tq.get_market_data(
field_list = ['Close'],
stock_list = ["000001.SZ"],
start_time = '20251219',
end_time = '20251225',
dividend_type='front',
period='1d',
)
print(df)2. 行情数据下载(重要)
2. Market Data Download (Important)
注意: Python 接口之所以能获取到行情数据,是因为通达信提前下载好了行情数据。调用 Python 接口实际上并没有发生网络请求,而是直接从本地已经下载好的行情数据文件中读取。如果发现获取到的数据不是最新的,可能是没有下载最新的行情数据导致的。
行情数据包含两项,需要手动下载并覆盖到通达信安装目录(以 为例):
C:/new_tdx64-
日线行情数据
- 下载链接:
https://data.tdx.com.cn/vipdoc/hsjday.zip - 更新频率: 每天盘后约 1 小时后更新。
- 操作: 下载后解压,覆盖到 目录。
C:/new_tdx64/vipdoc
- 下载链接:
-
财务数据
- 下载链接:
https://data.tdx.com.cn/vipdoc/tdxfin.zip - 更新频率: 更新频率不高,无需每天下载。
- 操作: 下载后解压,覆盖到 目录。
C:/new_tdx64/vipdoc/cw
- 下载链接:
Note: The reason why the Python interface can obtain market data is that Tongda Xin has downloaded the market data in advance. Calling the Python interface does not actually send any network requests, but directly reads from the locally downloaded market data files. If the data obtained is not the latest, it may be caused by not downloading the latest market data.
Market data includes two items, which need to be manually downloaded and overwritten to the Tongda Xin installation directory (take as an example):
C:/new_tdx64-
Daily Market Data
- Download Link:
https://data.tdx.com.cn/vipdoc/hsjday.zip - Update Frequency: Updated about 1 hour after the market closes every day.
- Operation: Unzip after downloading, overwrite to the directory.
C:/new_tdx64/vipdoc
- Download Link:
-
Financial Data
- Download Link:
https://data.tdx.com.cn/vipdoc/tdxfin.zip - Update Frequency: Low update frequency, no need to download every day.
- Operation: Unzip after downloading, overwrite to the directory.
C:/new_tdx64/vipdoc/cw
- Download Link:
API 文档与详细指南
API Documentation and Detailed Guide
本技能包含了一系列详细的子文档,涵盖了 TdxQuant 开发的各个方面。请在回答用户具体问题时,优先读取以下相关文档:
This skill contains a series of detailed sub-documents covering all aspects of TdxQuant development. When answering specific user questions, please read the following relevant documents first:
基础入门
Basic Getting Started
- TdxQuant 简介: 平台介绍、运行环境要求及核心运行逻辑。
- 常见问题: 常见报错(如 DLL 错误、路径问题)及解决方法。
- 常量枚举: 市场类型、复权类型、K线周期等参数的常量定义。
- TdxQuant 简介: Platform introduction, operating environment requirements and core operating logic.
- 常见问题: Common errors (such as DLL errors, path problems) and solutions.
- 常量枚举: Constant definitions for parameters such as market type, dividend adjustment type, K-line period, etc.
核心功能 API
Core Function APIs
- 通用函数: 初始化、数据订阅、发送消息/预警、文件下载等。
- 行情类信息: 获取实时行情、历史 K 线、分笔数据等。
- 财务类数据: 获取财务数据、除权除息信息等。
- 债券和期货数据: 可转债及期货相关数据获取。
- 通用函数: Initialization, data subscription, message/alert sending, file download, etc.
- 行情类信息: Get real-time market quotes, historical K-lines, tick data, etc.
- 财务类数据: Get financial data, ex-rights and ex-dividend information, etc.
- 债券和期货数据: Acquisition of convertible bond and futures related data.
板块与选股
Sector and Stock Selection
- 分类和板块成份股: 获取系统分类、行业板块及其成份股。
- 自选股和自定义板块: 管理用户自定义板块及自选股。
- 分类和板块成份股: Obtain system classification, industry sectors and their constituent stocks.
- 自选股和自定义板块: Manage user-defined sectors and self-selected stocks.
高级功能
Advanced Features
- 调用通达信公式: 在 Python 中调用通达信指标公式进行计算。
- 回测及模拟交易: 策略回测流程及模拟交易说明。
- 调用通达信公式: Call Tongda Xin indicator formulas for calculation in Python.
- 回测及模拟交易: Strategy backtesting process and simulated trading instructions.
示例
Examples
- 场景化示例: 常见策略场景的代码实现示例。
- 场景化示例: Code implementation examples for common strategy scenarios.
常见问题排查
Common Troubleshooting
- ModuleNotFoundError: 确保 的路径正确并已添加到
PYPlugins/user。sys.path - DLL 错误: 如果看到 ,请检查父目录 (
FileNotFoundError: Could not find module ... TPythClient.dll) 下是否存在../PYPlugins/,并确保未被杀毒软件拦截。详细排查请参考 常见问题。tdxrpcx64.dll - 数据为空: 确保 足以进行公式计算 (例如,计算 5 日移动平均线至少需要 5 个数据点)。
count - 进程冲突: 如果外部脚本报告已在运行,请在通达信的 TQ 策略管理器中检查并停止现有的实例。
- ModuleNotFoundError: Make sure the path of is correct and has been added to
PYPlugins/user.sys.path - DLL Error: If you see , please check whether
FileNotFoundError: Could not find module ... TPythClient.dllexists in the parent directory (tdxrpcx64.dll) and make sure it is not blocked by anti-virus software. For detailed troubleshooting, please refer to 常见问题.../PYPlugins/ - Empty Data: Make sure is sufficient for formula calculation (for example, at least 5 data points are required to calculate 5-day moving average).
count - Process Conflict: If the external script reports that it is already running, please check and stop the existing instance in the TQ strategy manager of Tongda Xin.
参考资料
Reference Materials
- 官方文档: 通达信量化平台帮助文档
- Tip: 本技能内置文档更新于 2026年3月1日。由于 TdxQuant 平台可能会持续迭代,如需获取最新的 API 变更和功能说明,请务必访问上述官方文档链接。
- Official Documentation: Tongda Xin Quantitative Platform Help Documentation
- Tip: The built-in documentation of this skill was updated on March 1, 2026. As the TdxQuant platform may continue to iterate, if you need to get the latest API changes and feature descriptions, be sure to visit the official documentation link above.