This skill is used to assist in developing quantitative trading strategies on the Tongdaxin quantitative platform (TdxQuant).
Core Concepts
TdxQuant integrates Python into the Tongdaxin 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 Path Setup
To use the tqcenter module, you must ensure that the Python environment can find the module. This module is usually located in the PYPlugins/user directory under the Tongdaxin installation directory (for example, C:/new_tdx64/PYPlugins/user)。
Usually, this path needs to be added before importing to sys.path:
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. Market Data Download (Important)
Note: The reason the Python interface can obtain market data is that Tongdaxinhas downloaded it in advancemarket data. Calling the Python interface actuallydoes not make a network request, but instead reads directly from the locally downloaded market data files. If you find that 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 Tongdaxin installation directory (using C:/new_tdx64 as an example):
-
Daily Market Data
- Download Link:
https://data.tdx.com.cn/vipdoc/hsjday.zip - Update Frequency: Updated about 1 hour after the market closes each day.
- Operation: After downloading, unzip and overwrite to the
C:/new_tdx64/vipdocdirectory.
- Download Link:
-
Financial Data
- Download Link:
https://data.tdx.com.cn/vipdoc/tdxfin.zip - Update Frequency: The update frequency is not high, so there is no need to download it every day.
- Operation: After downloading, unzip and overwrite to the
C:/new_tdx64/vipdoc/cwdirectory.
- Download Link:
API Documentation and Detailed Guide
This skill includes a series of detailed sub-documents covering all aspects of TdxQuant development.When answering users' specific questions, please prioritize reading the following relevant documents:
Getting Started Basics
- TdxQuant Introduction: Platform introduction, runtime environment requirements, and core operating logic.
- FAQ: Common errors (such as DLL errors, path issues) and solutions.
- Constant Enumerations: Constant definitions for parameters such as market type, adjustment type, and K-line period.
Core Function APIs
- General Functions: Initialization, data subscription, sending messages/alerts, file downloads, etc.
- Market Information: Obtain real-time quotes, historical K-lines, tick data, etc.
- Financial Data: Obtain financial data, ex-rights and ex-dividend information, etc.
- Bond and Futures Data: Acquisition of convertible bond and futures-related data.
Sectors and Stock Selection
- Categories and Sector Constituent Stocks: Obtain system categories, industry sectors, and their constituent stocks.
- Watchlist and Custom Sectors: Manage user-defined sectors and watchlist.
Advanced Features
- Calling TDX Formulas: Call TDX indicator formulas in Python for calculation.
- Backtesting and Simulated Trading: Strategy backtesting process and simulated trading instructions.
Examples
- Scenario-based Examples: Code implementation examples for common strategy scenarios.
Common Troubleshooting
- ModuleNotFoundError: Ensure the path of
PYPlugins/useris correct and has been added tosys.path。 - DLL Error: If you see
FileNotFoundError: Could not find module ... TPythClient.dll, check whether../PYPlugins/exists under the parent directory (tdxrpcx64.dll) and ensure it is not blocked by antivirus software. For detailed troubleshooting, refer to Common Questions。 - Empty Data: Ensure
countis sufficient for formula calculation (for example, calculating a 5-day moving average requires at least 5 data points). - Process Conflict: If an external script reports that it is already running, check and stop the existing instance in TDX's TQ Strategy Manager.
Reference Materials
- Official Documentation: TDX Quantitative Platform Help Documentation
- Tip: The built-in documentation for this skill was updated on March 1, 2026. Since the TdxQuant platform may continue to iterate, to obtain the latest API changes and feature descriptions, be sure to visit the above official documentation link.