SuperAPI AI Directory

tdx-tq-sdk

Data & analytics

View repository

Updated 10-22 00:20

About this skill

TDX TQ SDK CLI Skill

Tongdaxin quantitative interface command-line tool, based on the TQ strategy mode, providing complete stock data retrieval and analysis functions.

Prerequisites

  1. Tongdaxin client: must be started and logged in
  2. Tongdaxin installation: default path D:\new_tdx64
  3. Python environment:Python 3.8+

Installation

cd D:/TDX-SKILL/tdx-tq-sdk/cli_agent
pip install -e .

Command groups

market - market data

Retrieve stock K-line data, real-time quotes, ex-rights and ex-dividend data, etc.

market get - retrieve K-line data

cli-anything-tdx-tq market get -s <股票代码> [选项]

Parameters:

  • -s, --stocks: stock code list, comma-separated (required)
  • -p, --period: period, options tick/1m/5m/1d/1w/1mon (default: 1d)
  • -c, --count: number to retrieve (default: 60)
  • -d, --dividend: adjustment type, options none/front/back (default: front)
  • -o, --output: output file path
  • --json: output in JSON format

Example:

# 获取亨通光电 60 条日线数据
cli-anything-tdx-tq market get -s 600487.SH -c 60

# 获取前复权数据
cli-anything-tdx-tq market get -s 600487.SH -d front

# 获取多只股票数据
cli-anything-tdx-tq market get -s 600487.SH,000001.SZ,600519.SH

# 输出 JSON 格式
cli-anything-tdx-tq market get -s 600487.SH --json

market snapshot - retrieve real-time quote snapshot

cli-anything-tdx-tq market snapshot -s <股票代码> [选项]

Parameters:

  • -s, --stock: stock code (required)
  • --json: output in JSON format

Example:

cli-anything-tdx-tq market snapshot -s 600487.SH
cli-anything-tdx-tq market snapshot -s 600487.SH --json

market divid - retrieve ex-rights and ex-dividend data

cli-anything-tdx-tq market divid -s <股票代码> [选项]

Parameters:

  • -s, --stock: stock code (required)
  • --start: start time YYYYMMDD
  • --end: end time YYYYMMDD
  • --json: output in JSON format

Example:

cli-anything-tdx-tq market divid -s 600487.SH
cli-anything-tdx-tq market divid -s 600487.SH --start 20230101 --end 20241231

stock - stock information

Retrieve basic stock information, more information, etc.

stock info - retrieve basic stock information

cli-anything-tdx-tq stock info -s <股票代码> [选项]

Parameters:

  • -s, --stock: stock code (required)
  • --json: output in JSON format

Example:

cli-anything-tdx-tq stock info -s 600487.SH
cli-anything-tdx-tq stock info -s 600487.SH --json

stock more - retrieve more stock information

cli-anything-tdx-tq stock more -s <股票代码> [选项]

Parameters:

  • -s, --stock: stock code (required)
  • -f, --fields: specified fields, comma-separated
  • --json: output in JSON format

Example:

cli-anything-tdx-tq stock more -s 600487.SH
cli-anything-tdx-tq stock more -s 600487.SH -f HisHigh,HisLow,ZTPrice

sector - sector data

Retrieve sector lists, sector constituent stocks, etc.

sector list - retrieve sector list

cli-anything-tdx-tq sector list [选项]

Parameters:

  • -t, --type: sector type, 0=industry/1=concept/2=style (default: 0)
  • --json: output in JSON format

Example:

# 获取行业板块
cli-anything-tdx-tq sector list

# 获取概念板块
cli-anything-tdx-tq sector list -t 1

sector stocks - retrieve sector constituent stocks

cli-anything-tdx-tq sector stocks -s <板块名称> [选项]

Parameters:

  • -s, --sector: sector name (required)
  • --json: output in JSON format

Example:

cli-anything-tdx-tq sector stocks -s 半导体
cli-anything-tdx-tq sector stocks -s 人工智能 --json

financial - financial data

Retrieve professional financial data.

financial get - retrieve professional financial data

cli-anything-tdx-tq financial get -s <股票列表> -f <字段列表> [选项]

Parameters:

  • -s, --stocks: stock code list, comma-separated (required)
  • -f, --fields: field list, comma-separated (required), such as FN1(EPS),FN4(BPS),FN6(ROE)
  • --start: start time YYYYMMDD
  • --end: end time YYYYMMDD
  • --json: output in JSON format

Common fields:

  • FN1: earnings per share (EPS)
  • FN4: net assets per share (BPS)
  • FN6: return on equity (ROE)
  • FN230: operating revenue
  • FN232: net profit

Example:

cli-anything-tdx-tq financial get -s 600487.SH -f FN1,FN4,FN6
cli-anything-tdx-tq financial get -s 600487.SH -f FN230,FN232 --start 20230101 --end 20241231

formula - formula invocation

Invoke Tongdaxin indicator formulas and stock selection formulas.

formula zb - Call indicator formula

cli-anything-tdx-tq formula zb -n <公式名> [选项]

Parameters:

  • -n, --name: Indicator formula name (required)
  • -a, --args: Formula parameters, comma-separated
  • -s, --stock: Stock code
  • --json: Output in JSON format

Example:

# 调用 MA 指标
cli-anything-tdx-tq formula zb -n MA -a 5,10,20

# 调用 KDJ 指标
cli-anything-tdx-tq formula zb -n KDJ -a 9,3,3

formula xg - Call stock selection formula

cli-anything-tdx-tq formula xg -n <公式名> [选项]

Parameters:

  • -n, --name: Stock selection formula name (required)
  • -a, --args: Formula parameters, comma-separated
  • -s, --stocks: Stock list, comma-separated
  • --json: Output in JSON format

Example:

cli-anything-tdx-tq formula xg -n KDJ -a 9,3,3

config - Configuration management

config show - Show current configuration

cli-anything-tdx-tq config show

config set - Set configuration

cli-anything-tdx-tq config set --tdx-path D:\new_tdx64

status - View status

cli-anything-tdx-tq status [--json]

Global options

Option Description
--help Show help information
--version Show version number
--tdx-path TDX installation path (can be set via the TDX_PATH environment variable)

Output format

JSON mode

All commands support the --json option, outputting data in JSON format:

cli-anything-tdx-tq stock info -s 600487.SH --json

Output example:

{
  "Code": "600487.SH",
  "Name": "亨通光电",
  "Industry": "通信设备",
  "Area": "江苏",
  ...
}

Usage scenarios

Scenario 1: Get data for a single stock

# 获取日线数据
cli-anything-tdx-tq market get -s 600487.SH -c 100 --json > data.json

Scenario 2: Get sector constituent stocks

# 获取半导体板块所有股票
cli-anything-tdx-tq sector stocks -s 半导体 --json > semiconductor.json

Scenario 3: Batch get financial data

# 获取多只股票的 EPS 和 ROE
cli-anything-tdx-tq financial get -s 600487.SH,000001.SZ,600519.SH -f FN1,FN6 --json

Notes

  1. Prerequisite: The TDX client must be started and logged in first
  2. Stock code format: 6 digits + market suffix, e.g. 600487.SH
  3. Time format: YYYYMMDD, e.g. 20240101
  4. Data period: tick, 1m, 5m, 1d, 1w, 1mon, etc.
  5. Adjustment type: none (no adjustment), front (forward adjustment), back (backward adjustment)

Troubleshooting

Initialization failed

Make sure the TDX client is started and logged in, and check the path configuration:

cli-anything-tdx-tq config show

Module not found

Reinstall:

cd D:/TDX-SKILL/tdx-tq-sdk/cli_agent
pip install -e .