Repository navigation
feat: native Go day merge replacing external datatool binary - #60
Merged
Merged
Conversation
Replace the external datatool binary (Linux x86 ELF only) with a native Go implementation for the "day" subcommand, enabling cross-platform support including macOS arm64. The TDX .md1 and .cod binary formats were reverse-engineered: - .cod (150 bytes/record): maps stock codes to sequence numbers - .md1 (512 bytes/block): stores OHLCV data per block - Mapping: md1 offset = cod.seq_num * 512 The native merger reads .md1+.cod file pairs from vipdoc/refmhq/ and appends 32-byte .day records to per-stock files, with date-based deduplication to prevent duplicate appends on re-runs. Cross-validated against original datatool output for multiple stocks across SH/SZ/BJ exchanges — prices and volumes match exactly. "tick" and "min" subcommands continue to use the embedded datatool binary as fallback.
Owner
|
Thanks for your work; it's a huge improvement. 🙏 🚀 |
rains31
pushed a commit
to rains31/tdx2db
that referenced
this pull request
Nov 5, 2026
feat: native Go day merge replacing external datatool binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the external
datatoolbinary (Linux x86 ELF only) with a native Go implementation for thedaysubcommand, enabling cross-platform support including macOS arm64.Problem
The current
datatoolbinary embedded via//go:embedis a closed-source Linux x86 ELF. It cannot run on:This means
tdx2db cronfails withexec format erroron any non-Linux-x86 platform.Solution
Reverse-engineered the TDX
.md1and.codbinary formats:.cod.md1Mapping:
md1_offset = cod.seq_num * 512The native merger (
NativeDayMerge) reads.md1+.codfile pairs fromvipdoc/refmhq/and appends standard 32-byte.dayrecords to per-stock files.Backward Compatibility
"day"subcommand: uses native Go merger (cross-platform)"tick"and"min"subcommands: unchanged, still use the embeddeddatatoolbinary as fallbackVerification
Cross-validated against original
datatooloutput across all three exchanges:Spot-checked multiple stocks (OHLCV prices and volumes match exactly):
Date-based deduplication prevents duplicate records on re-runs.
Files Changed
tdx/merge.go— New: native .md1/.cod to .day merge implementationtdx/merge_test.go— New: unit teststdx/datatool.go— Modified: route day to native merge, keep fallback for tick/minTest plan