tdxrs: a Rust rewrite of the TDX market data parser with Python bindings
tdxrs is a high-performance Rust implementation of the Tongdaxin (TDX) market data parsing library, exposing a native Python interface via PyO3/maturin. It is API-compatible with tdxpy but rewrites the core parsing engine in Rust for order-of-magnitude local parsing speedups, especially with large historical datasets.
At a glance
- What is it?
- tdxrs keeps the tdxpy API but moves the parsing engine into Rust, cutting local file parse times to under a millisecond for a thousand bars. The gain is real for bulk history work and much smaller for live network calls.
- Who is it for?
- Adopt tdxrs if you already write Python against pytdx or tdxpy and your bottleneck is reading .day, .lc5 or gpcw files in bulk, because the API is deliberately kept compatible and the local readers are the part rewritten in Rust. Do not adopt it if you need a vendor-supported data feed, a documented rollback story, or Windows x86_64-pc-windows-gnu builds without MSYS2 dlltool.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 19 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- jiangtaovan/tdxrs518 ★ · +43
| Repository | 2026-09-28 | 2026-11-24 |
|---|---|---|
| jiangtaovan/tdxrs | 475 | 518 |
43 Stars in the last 57 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What tdxrs replaces, and for whom
TDX (通达信) is a Chinese retail trading terminal that stores quote history in its own binary files and serves live data over a proprietary TCP protocol. If you want that data in Python, the long-standing route is pytdx and its fork tdxpy, both pure Python. tdxrs is a Rust implementation of the same parsing work, published to PyPI as a compiled extension, with a Python API that the README says is compatible with tdxpy.
The intended reader is someone who already has Python code against that API and wants it to run faster, or someone pulling large local archives rather than a few hundred bars at a time. The README's own framing is that the advantage is most visible on bulk historical data. That is a narrower audience than "anyone who wants Chinese market data in Python", and the numbers below explain why.
Where the 9x to 11x actually lands
The README splits performance into two tables, and the split matters more than the headline. Local file parsing is where Rust earns its place: 1000 daily bars in 0.3ms against 2.8ms for tdxpy, 1000 minute bars in 0.5ms against 5.1ms, 500 block records in 1.2ms against 12.0ms, 500 financial records in 0.8ms against 8.5ms. Those are single-digit milliseconds either way, so the win is proportional, not absolute, unless you are reading thousands of files.
Network calls are a different story. K-line requests of 100 bars go from 110ms to 73ms, and three-symbol quotes from 95ms to 75ms. That is 1.3x to 1.5x. The reason is obvious once you think about it: the time is spent waiting on a remote server, and no amount of Rust optimizes a socket. If your workload is live quotes, tdxrs will feel like a modest improvement with a new dependency attached.
The concurrency table is the most interesting part and the least flattering. Under 60 threads, the direct client stays at 344ms against 381ms at 5 threads, which the README calls zero degradation. The pooled client goes from 337ms at 5 threads to 4110ms at 60, and the async client from 345ms to 3880ms. Those are 12x and 11x regressions. The README presents this as a scaling ratio, but read plainly it says the connection pool and the tokio client fall apart under heavy parallelism while the naive one-connection-per-request client does not. That is a real design trade-off, and it means the choice of client class is not cosmetic.
Four client classes and when each one is wrong
The README documents four clients. TdxHqClient is the default: a pool of five connections with heartbeat, retry and caching, meant for sequential requests. TdxHqFundClient shares that pool and adds fund code validation. TdxDirectClient opens a fresh TCP connection per request and is the one the concurrency table shows holding steady at 60 threads. AsyncTdxHqClient wraps tokio for asyncio-style integration.
Given the benchmark, picking TdxHqClient for a 60-thread fan-out is the wrong call, and the README's own table is the evidence. Picking TdxDirectClient for a loop of sequential requests throws away the pool, the heartbeat and the cache. The documentation states the intended scenarios but does not explain the mechanism behind the pool's collapse under load, so if you plan to run high concurrency you are choosing between a documented slow path and an undocumented fast one.
Rate limiting is built in and adapts to the trading session: 15 requests per second during 9:30-15:00, 30 in the pre and post windows, 60 when the market is closed. The README notes that limiting is per connection, so a four-connection pool multiplies throughput by four, and that batch quote calls cap at 60 symbols with automatic truncation beyond that. That truncation is silent in the sense that you get fewer rows than you asked for, so check lengths rather than assuming.
Installing tdxrs and pulling a first series
The README gives a one-line install from PyPI. The package requires Python 3.11 or newer, per pyproject.toml, and pandas is an optional extra needed only for the *_dataframe() methods.
pip install tdxrsBuilding from source instead uses maturin, which is declared as the build backend with a floor of 1.5 and a ceiling below 2.0. The README's source path clones the repository, installs maturin, and runs a release build.
git clone https://github.com/jiangtaovan/tdxrs && cd tdxrs
pip install maturin
maturin develop --releaseThe README warns that Windows target x86_64-pc-windows-gnu needs MSYS2 dlltool in addition, pointing at docs/INSTALL.md. That is the one platform caveat stated outright.
With the package installed, the first real call connects to any available server and requests daily bars. The README's example fetches 500 bars for 600519 on the Shanghai market and computes a 20-day moving average.
from tdxrs import TdxHqClient
from tdxrs.constants import MARKET_SH, KLINE_DAILY
client = TdxHqClient()
client.connect_to_any()
df = client.get_security_bars_dataframe(KLINE_DAILY, MARKET_SH, "600519", 0, 500)
df["ma20"] = df["close"].rolling(20).mean()What you should see is a DataFrame with an ma20 column whose first 19 rows are NaN. If connect_to_any() raises, the CLI has a way to probe the situation: the README lists a servers subcommand among the CLI examples, and the same page shows quote, bars, trades and download subcommands for terminal use without writing Python at all.
Adjustment runs on your machine, not the server
This is the design decision most likely to bite. The README states plainly that the TDX server returns unadjusted raw data and that tdxrs computes forward and backward adjustment client-side, using the standard Chinese A-share ex-dividend formula, handling dividends, bonus shares and rights issues together, and backfilling early corporate actions through something the README calls the context_bars mechanism. Passing fq=0 takes a path with no extra cost.
Two consequences follow. First, any adjustment result is only as good as the corporate action history the client can assemble, so symbols with sparse early history are the ones to spot-check rather than the ones to trust. Second, the fq parameter is a choice you make per call, and the README shows FQ_QFQ, FQ_HFQ and FQ_NONE as separate constants. Defaulting to forward adjustment is convenient and also means a naive comparison against raw exchange data will not match.
The financial data path carries a similar caveat. The README says get_finance_info returns TDX raw values without unit conversion and offers an empirical rule: share capital and asset figures are roughly in ten-thousands, per-share indicators roughly in yuan. An empirical rule in the documentation is a signal that the units are not authoritative, so treat any derived metric as needing a sanity check against a known figure.
Local readers, the downloader and the CLI
The local file layer covers four formats: .day daily bars through DailyBarReader, .lc5 and .lc1 minute bars through MinBarReader and LcMinBarReader, .dat block files through BlockReader with flat and group modes, and gpcw*.dat financial files through FinancialReader. Each reader offers dict, tuple or DataFrame output. The README's example passes coefficient=0.01 to DailyBarReader, which implies the stored prices are integers scaled by 100 and you are responsible for setting that scale correctly.
The downloader module handles bulk acquisition: multiple servers, automatic pagination, incremental updates and resume. The README's example constructs Downloader with a data_dir, calls run() with markets and categories, and calls update() for incremental work, noting that incremental updates are only supported for fq=0. Minute and tick downloads are per-date and require explicit codes, which is a real constraint if you were hoping to sweep the whole market for a date range without listing symbols.
On the Rust side, the crate builds both a cdylib for the Python extension and an rlib for Rust tests, and the release profile sets opt-level 3 with link-time optimization. The dependency list is small: pyo3, serde, serde_json, thiserror, flate2, encoding_rs, regex and tokio. encoding_rs is there for GBK and GB2312, which is what you need for Chinese names in block and financial data. The repository also ships a multi-stage Dockerfile that builds a Linux wheel in a python:3.13-slim builder stage and produces a test image whose default command imports tdxrs and prints a confirmation string.
Alternatives and the honest comparison
The direct alternative is pytdx, the project the README links as tdxpy's origin, and tdxpy itself. Both are pure Python, which means no compilation step, no maturin, no Rust toolchain, and no platform-specific dlltool problem on Windows. tdxrs is a compiled extension, so you inherit a build matrix you did not have before, and the README's Windows note is the visible edge of that.
The difference in approach is where the work happens. A pure Python parser walks the binary structures in the interpreter, which is why the README's tables show 2.8ms for 1000 daily bars. tdxrs does the same walk in compiled code with link-time optimization, which is why it shows 0.3ms. Neither approach changes the network time, and the README's own 1.3x to 1.5x figures for live requests confirm that the protocol, not the language, is the limit there.
So the honest split is this: if your pipeline is dominated by local archive parsing, the rewrite addresses your bottleneck. If it is dominated by live requests against TDX servers, you are swapping a pure Python dependency for a compiled one to gain roughly a third of the wall time, and you are taking on build complexity to do it. There is also no vendor relationship here. This talks to TDX servers the same way the Python libraries do, and the built-in rate limiter exists precisely because that access is not officially granted.
Maintenance, licensing and what to check before upgrading
The repository is not archived, and the last push was on 2026-09-15. pyproject.toml and Cargo.toml both carry version 0.6.7, so the two are in step, and the classifiers mark the project as Development Status 4 - Beta. Beta is the honest reading: the API is stable enough to mirror tdxpy, but the version number has not reached 1.0 and the repository has no published GitHub releases, so there is no changelog to read before upgrading.
On licensing, the project is MIT, declared in LICENSE, pyproject.toml and Cargo.toml. MIT is permissive and imposes no source disclosure on your own code, but the dependency tree is what you should actually review: pyo3, tokio, serde, flate2, encoding_rs and regex all ship under their own terms, and the Dockerfile pulls in the Rust toolchain and build-essential at build time. None of that is legal advice, and if you redistribute a wheel you should read the licenses yourself rather than trusting a summary.
The upgrade cost is genuinely low for the Python surface, because the API deliberately tracks tdxpy. The cost sits in the native artifact: a version bump means a new compiled wheel per platform and Python version, and the README's Windows note means one of those platforms has extra prerequisites. If you vendor a built wheel, pin it and re-read docs/INSTALL.md when you move it.
Editorial conclusion
Adopt tdxrs if you already write Python against pytdx or tdxpy and your bottleneck is reading .day, .lc5 or gpcw files in bulk, because the API is deliberately kept compatible and the local readers are the part rewritten in Rust. Do not adopt it if you need a vendor-supported data feed, a documented rollback story, or Windows x86_64-pc-windows-gnu builds without MSYS2 dlltool. Before committing, verify three things yourself: that pip install tdxrs resolves for your Python version (the package requires 3.11 or newer), that connect_to_any() reaches a working TDX server from your network, and that the futures you get back match the same series from tdxpy on a symbol with a recent dividend, since the adjustment math runs on the client.
Frequently asked questions
How do I install tdxrs?
The README gives a single command, pip install tdxrs, and the package requires Python 3.11 or newer. Building from source instead uses maturin with a release build after cloning the repository.
Is tdxrs API compatible with tdxpy?
The README states that tdxrs keeps API compatibility with the Python tdxpy library, which is why the client classes and constants follow the same naming. It is a claim from the project's own documentation, so verify it against the specific calls your code makes.
Does tdxrs work on Windows?
The README notes that the Windows target x86_64-pc-windows-gnu additionally requires MSYS2 dlltool, and points at docs/INSTALL.md for details. No other platform caveat is stated in the README.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/jiangtaovan-tdxrs)Star history chart for your README
[](https://hysenlabs.com/projects/jiangtaovan-tdxrs)Was this useful?