DSH users who perform AI investment analysis often face the problem that the model cannot access market data and can only rely on stale prices from training memory. This plugin connects to Tongdaxin (pytdx) to provide the model with real K-line data, real-time quotes, technical indicators, and sector data, resolving the missing data source issue.
Plugin Overview¶
- Name: dsh-tdx
- Owner: guozede12593312
- Positioning: An online tool plugin that provides financial data through the local Tongdaxin interface.
- Core value: Provides DSH models with K-line queries, real-time snapshots, technical indicator calculations, and concept sector analysis.
Core Features¶
The plugin provides the following four types of query tools:
- A-share historical K-line (OHLCV): Supports fetching historical data for a specified period and count.
- Real-time market snapshots (batch): Supports querying the current prices of multiple stocks in one request.
- Technical indicators: Supports calculating indicators such as MACD, RSI, MA, and EMA.
- Concept sectors: Supports querying the constituent stock list or the constituents of a specific sector.
Prerequisites and Configuration¶
Before using the plugin, please ensure the following environment requirements are met:
- Node.js: Used to run the plugin itself.
- Python 3.6+: Used for data fetching; the
pytdxlibrary must be installed.- Installation command:
pip install pytdx
- Installation command:
- Environment variable: If
pythonis not in the system PATH, set the environment variableDSH_TDX_PYTHONto point to the Python interpreter path.
Installation and Enabling¶
The installation command is as follows:
dsh plugin --profile <your-profile> add https://github.com/guozede12593312/dsh-tdx
After installation, the plugin tools can be invoked in DSH sessions.
Local Debugging¶
If you need to debug the plugin locally, enter the plugin directory and manually install dependencies:
cd dsh-tdx && npm install
DSH_TDX_PYTHON=<python path> dsh plugin --profile <your-profile> add ./dsh-tdx
Note: In link mode, the copy at
~/.dsh/plugins-src/dsh-tdxalso requires runningnpm installin that directory, because link mode does not automatically sharenode_modules.
Typical Usage¶
Below are examples of plugin tool calls:
# 获取贵州茅台最近 60 个交易日的日 K 线
tdx_kline(code=600519, period=day, count=60)
# 获取贵州茅台最近 60 个交易日的 MACD 指标
tdx_indicator(code=600519, indicator=macd, count=60)
# 获取贵州茅台最近 60 个交易日的 RSI 指标
tdx_indicator(code=600519, indicator=rsi, count=60)
# 查询“人工智能”板块的成分股
tdx_sector(name=人工智能)
Technical Design¶
The plugin adopts a thin-shell pattern, separating registration logic from core computation:
- Data layer: It calls Python scripts from Node, using
pytdxto connect to Tongdaxin servers and retrieve raw data. - Logic layer: Indicator calculation logic (MA/EMA/MACD/RSI) is implemented as pure functions in
lib.js, reducing external dependencies. - Testing: After installing dependencies, unit tests can be run with
npm install && node --test.
Use Cases and Notes¶
- Use cases: Suitable for DSH users who need AI investment analysis based on real-time or historical market data.
- Permission notes: The plugin runs with the permissions of the current DSH process. Please ensure the environment configuration is secure.
- Source review: It is recommended to review the source code and license (MIT) before installation.