Add Binance-backed Paul Wei trading analysis - #1
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a standalone Python CLI that fetches Binance BTCUSDT USD‑M perpetual 1m candle archives into a local SQLite cache and performs a reproducible analysis of the (submodule-provided) Paul Wei trading ledger to generate derived CSVs, figures, and a Chinese research report.
Changes:
- Introduces
tradetrace.pywithfetchandanalyzecommands, SQLite caching, candle matching, and report/table generation. - Adds offline unit tests for core timestamp bucketing, candle matching, inverse fill math, and SQLite ingest behavior.
- Adds a primary-source index and checks in generated report artifacts under
reports/.
Reviewed changes
Copilot reviewed 14 out of 36 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tradetrace.py |
New CLI + analysis pipeline for fetching Binance candles, reconstructing positions, and generating outputs. |
test_tradetrace.py |
Unit tests for several key helper functions and ingest logic. |
research/paulwei-sources.md |
Primary-source index for research claims and usage rules. |
reports/tables/order_summary.csv |
Generated order summary output. |
reports/tables/market_summary.csv |
Generated per-market trading summary output. |
reports/tables/market_data_quality.csv |
Generated market data coverage/gap summary. |
reports/tables/hourly_activity.csv |
Generated hourly activity aggregation. |
reports/tables/execution_summary.csv |
Generated execution/matching summary output. |
reports/tables/data_audit.csv |
Generated input file audit output. |
reports/tables/cycle_summary.csv |
Generated cycle-window summary output. |
reports/tables/case_summary.csv |
Generated case-study window summary output. |
reports/paulwei-analysis.md |
Generated Chinese analysis report (Markdown). |
README.md |
Project usage overview and CLI invocation instructions. |
pyproject.toml |
Project metadata and dependencies (matplotlib). |
.gitignore |
Ignores local market cache directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+101
to
+102
| def manifest() -> dict: | ||
| return json.loads(MANIFEST.read_text(encoding="utf-8")) |
Comment on lines
+387
to
+394
| def dedupe_orders(rows: list[dict]) -> tuple[list[dict], int]: | ||
| seen, result = set(), [] | ||
| for row in rows: | ||
| key = tuple(row.items()) | ||
| if key not in seen: | ||
| seen.add(key) | ||
| result.append(row) | ||
| return result, len(rows) - len(result) |
Comment on lines
+1257
to
+1259
| snapshot_position = int(decimal(next(read_csv("api-v1-position.snapshot.csv"))["currentQty"])) | ||
| if position_metrics["terminal_position"] != snapshot_position or snapshot_position != -998_000: | ||
| raise ValueError(f"terminal position mismatch: {position_metrics['terminal_position']}") |
Comment on lines
+110
to
+116
| def write_csv(path: Path, rows: list[dict], fieldnames: list[str] | None = None) -> None: | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
| fields = fieldnames or (list(rows[0]) if rows else []) | ||
| with path.open("w", newline="", encoding="utf-8") as handle: | ||
| writer = csv.DictWriter(handle, fieldnames=fields, lineterminator="\n") | ||
| writer.writeheader() | ||
| writer.writerows(rows) |
Comment on lines
+3
to
+5
| 对 `BTC-Trading-Since-2020` 公开账本进行可复现研究,并用 Binance USD-M | ||
| `BTCUSDT` 永续 1 分钟 K 线为 XBTUSD 成交提供市场背景。 | ||
|
|
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.
What changed
tradetrace.pyCLI withfetchandanalyzecommands.BTCUSDT1-minute archives, importing them into an ignored SQLite cache.lastPx, align executions to Binance minute ranges, and generate CSV tables, figures, and a Chinese research report.Validation
uv run python -m unittest test_tradetrace.py(6 tests passed).fetch/analyzeruns are idempotent; generated report hashes are unchanged.Binance candles are used only as the XBTUSD market proxy; all fill, position, PnL, and fee calculations retain ledger values.