SuperAPI AI Directory

tdxquant

Data & analytics

View repository

Updated 10-15 09:29

About this skill

Tongdaxin quantitative data acquisition skill

Task objective

  • This Skill is used to: obtain A-share market data, perform technical analysis, and query trading-related information through the Tongdaxin TdxQuant (tqcenter) interface
  • Capabilities include: market snapshots, K-line data, basic securities information, professional financial data, stock/sector/market trading data, sectors and constituent stocks, convertible bond/ETF/new stock information, trading calendar, Tongdaxin formula execution, market quote subscription, trading order placement
  • Trigger conditions: the user mentions tdxquant, Tongdaxin, TdxQuant, tqcenter, obtaining A-share data, K-line queries, financial data, sector analysis, etc.

Prerequisites

  • tqcenter module description: tqcenter is located in the Tongdaxin installation directory's PYPlugins\user\tqcenter.py. The script automatically detects the installation directory through _tdx_init.py and adds the path to sys.path. Users can also specify the installation directory by setting the environment variable TDX_ROOT .
  • Environment requirements: Tongdaxin Financial Terminal must be installed (Professional Research Edition, Quantitative Simulation Edition, or Futures Connect that supports TQ strategy functionality), and the client must be started in advance
  • Python version: supports 64-bit Python 3.7~3.14, 3.13 recommended
  • Data preparation: some data (such as professional financial data and trading data) requires downloading the corresponding data package in the client first

Core concepts

  • Securities code format: 6 digits + market suffix (upper or lower case both acceptable), such as 600519.SH(Shanghai),000001.SZ(Shenzhen),430047.BJ(Beijing Stock Exchange)
  • Period parameter:1m/5m/15m/30m/1h/1d/1w/1mon/1q/1y/tick
  • Adjustment type:none no adjustment,front forward adjustment,back backward adjustment
  • Market type suffix:.SHShanghai .SZShenzhen .BJBeijing Stock Exchange .HKHong Kong stocks .USUS stocks .CSICSI indices .CNICNI indices .CFFCICC futures, etc.

Installation directory structure:

通达信安装目录\
├── TdxW.exe              # 主程序
├── PYPlugins\
│   ├── TPyth.dll         # 通信DLL
│   ├── TPythClient.dll   # 通信DLL
│   ├── user\
│   │   └── tqcenter.py   # TdxQuant 核心模块
│   ├── data\             # 下载数据目录
│   └── file\             # 发送文件目录

Operation steps

  1. Determine data requirements — the agent understands the user's intent
  2. Call the corresponding script — select the script according to the data type
  3. Parse results — the agent analyzes the returned JSON-format data

Intent recognition mapping examples

User question Corresponding function module Call parameters
"Kweichow Moutai real-time stock price" market_data.py snapshot --code 600519.sh
"Ping An Bank K-line data" market_data.py kline --code 000001.sz --period 1d
"China Merchants Bank basic information" market_data.py stock_info --code 600036.sh
"China Merchants Bank financial indicators" financial_data.py financial --code 600036.sh --fields fn193,fn197
"Semiconductor sector constituent stocks" sector_data.py sector_stocks --block_name Semiconductor
"Today's new stock subscriptions" etf_bond_data.py ipo_info --ipo_type 2 --ipo_date 1
"Market margin trading data" trading_data.py scjy --fields sc1,sc25
"MACD indicator" formula.py zb --name MACD --arg 12,26,9
"Stock selection for 3 consecutive days of gains" formula.py xg --name UPN --arg 3

Usage examples

  • Example 1: Obtain a real-time stock market snapshot
    • Scenario/input: the user says "Check Kweichow Moutai's real-time market quotes"
    • Expected output: return information such as stock code, name, current price, change percentage, trading volume, five-level bid/ask, etc.
    • Key points: call python scripts/market_data.py snapshot --code 600519.sh
  • Example 2: Get daily K-line data
    • Scenario/Input: The user says "Get the daily K-line data of Ping An Bank for the last 100 days"
    • Expected output: return OHLCV data such as date, opening price, highest price, lowest price, closing price, trading volume, etc.
    • Key points: call python scripts/market_data.py kline --code 000001.sz --period 1d --count 100
  • Example 3: Query professional financial data
    • Scenario/Input: The user says "View China Merchants Bank's recent cost-expense profit margin and operating profit margin"
    • Expected output: return financial indicators such as fn193 cost-expense profit margin, fn194 operating profit margin, etc.
    • Key points: call python scripts/financial_data.py financial --code 600036.sh --fields fn193,fn194 --start 20240101

Script call mapping reference

  • Market snapshot → python scripts/market_data.py snapshot --code 600519.sh
  • K-line data → python scripts/market_data.py kline --code 600519.sh --period 1d --count 100
  • Basic securities information → python scripts/market_data.py stock_info --code 600519.sh
  • More stock information → python scripts/market_data.py more_info --code 600519.sh
  • Dividend distribution → python scripts/market_data.py divid_factors --code 600519.sh
  • Share capital data → python scripts/market_data.py gb_info --code 600519.sh --dates 20250101,20250601
  • Professional financial data → python scripts/financial_data.py financial --code 600519.sh --fields fn193,fn194,fn197 --start 20250101
  • Financial data for a specified date → python scripts/financial_data.py financial_by_date --code 600519.sh --fields fn193,fn197 --year 0 --mmdd 0
  • Single financial indicator → python scripts/financial_data.py gp_one_data --code 600519.sh --fields go1,go3,go5
  • Stock trading data → python scripts/trading_data.py gpjy --code 600519.sh --fields gp1,gp2,gp3 --start 20250101
  • Sector trading data → python scripts/trading_data.py bkjy --code 880660.sh --fields bk5,bk6,bk9 --start 20250101
  • Market trading data → python scripts/trading_data.py scjy --fields sc1,sc2,sc3 --start 20250101
  • System classification constituent stocks → python scripts/sector_data.py stock_list --list_type 5
  • Sector code list → python scripts/sector_data.py sector_list --with_name
  • Sector constituent stocks → python scripts/sector_data.py sector_stocks --block_code 880081.sh
  • Sectors to which a stock belongs → python scripts/sector_data.py stock_relation --code 688318.sh
  • Custom sector operations → python scripts/sector_data.py user_sector --action list
  • Convertible bond information → python scripts/etf_bond_data.py kzz_info --code 123039.sz
  • ETF tracked index → python scripts/etf_bond_data.py trackzs_etf --zs_code 950162.csi
  • New stock subscription → python scripts/etf_bond_data.py ipo_info --ipo_type 2 --ipo_date 1
  • Trading day list → python scripts/calendar.py --start 20250101 --end 20250601
  • TDX formula (indicator) → python scripts/formula.py zb --name MACD --arg 12,26,9 --code 688318.sh --period 1d --count 100
  • TDX formula (stock selection) → python scripts/formula.py xg --name UPN --arg 3 --code 688318.sh --period 1d --count 100
  • Batch stock selection formula → python scripts/formula.py mul_xg --name UPN --arg 3 --codes 688318.sh,600519.sh --period 1d --count 20

Resource index

Data acquisition scripts

  • scripts/market_data.py (Purpose and parameters: market snapshot snapshot, K-line kline, basic information stock_info, more information more_info, dividends divid_factors, share capital gb_info)
  • scripts/financial_data.py (Purpose and parameters: professional financial financial, financial by specified date financial_by_date, single indicator gp_one_data)
  • scripts/trading_data.py (Purpose and parameters: stock trading gpjy, sector trading bkjy, market trading scjy and their by_date variants)
  • scripts/sector_data.py (Purpose and parameters: system classification stock_list, sector list sector_list, sector constituent stocks sector_stocks, sectors to which a stock belongs stock_relation, custom sector user_sector)
  • scripts/etf_bond_data.py (Purpose and parameters: convertible bonds kzz_info, ETF tracking trackzs_etf, new stock subscription ipo_info)
  • scripts/calendar.py (Purpose and parameters: get trading day list, supports --start/--end/--count)
  • scripts/formula.py (Purpose and parameters: TDX formula execution, supports zb indicator/xg stock selection/exp expert/mul batch)
  • scripts/trade.py (Purpose and parameters: trading order placement, query positions/orders/assets, order cancellation)

Extended reference

Notes

  • Before running the script, you must first start the TongDaXin financial terminal (a version that supports TQ strategy functionality), and the TdxW.exe process must be running
  • If it does not exist in the installation directory tqcenter.py, it means the current client does not support TQ strategy and the TongDaXin terminal needs to be upgraded
  • Securities codes must include the market suffix (such as .SH、.SZ、.BJ), either uppercase or lowercase is acceptable, but it cannot be omitted
  • Professional financial data and trading data require first downloading the corresponding data packages in the client
  • Some data (such as margin financing and securities lending, Stock Connect, etc. in trading data) only displays data after specific dates
  • K-line data returns at most 24,000 records at a time; obtaining complete minute-level lines requires multiple batch retrievals
  • When executing TongDaXin formulas, formula names and parameters must conform to TongDaXin syntax specifications
  • Post-adjustment data is related to the number of data records obtained; post-adjustment is only performed on the returned data
  • Use sys.path.insert(0, ...) instead of append(), ensuring that tqcenter.py in the TongDaXin installation directory is loaded with priority