Skip to content

Add Binance-backed Paul Wei trading analysis - #1

Merged
AaronL725 merged 1 commit into
mainfrom
codex/tradetrace-binance-analysis
Aug 1, 2026
Merged

Add Binance-backed Paul Wei trading analysis#1
AaronL725 merged 1 commit into
mainfrom
codex/tradetrace-binance-analysis

Conversation

@AaronL725

Copy link
Copy Markdown
Owner

What changed

  • Add a minimal tradetrace.py CLI with fetch and analyze commands.
  • Download and SHA-256 verify Binance USD-M BTCUSDT 1-minute archives, importing them into an ignored SQLite cache.
  • Reconstruct XBTUSD inverse-contract positions from ledger lastPx, align executions to Binance minute ranges, and generate CSV tables, figures, and a Chinese research report.
  • Add primary-source index for Paul Wei and offline unit tests.

Validation

  • 3,270,240 Binance candles imported; 0 minute gaps.
  • 98,874 XBTUSD Trade executions matched with original ledger prices; terminal position reconstructed as -998,000 contracts.
  • uv run python -m unittest test_tradetrace.py (6 tests passed).
  • Repeated fetch/analyze runs 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.

@AaronL725
AaronL725 marked this pull request as ready for review August 1, 2026 09:34
Copilot AI review requested due to automatic review settings August 1, 2026 09:34
@AaronL725
AaronL725 merged commit 1c966b6 into main Aug 1, 2026
@AaronL725
AaronL725 deleted the codex/tradetrace-binance-analysis branch August 1, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with fetch and analyze commands, 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 thread tradetrace.py
Comment on lines +101 to +102
def manifest() -> dict:
return json.loads(MANIFEST.read_text(encoding="utf-8"))
Comment thread tradetrace.py
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 thread tradetrace.py
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 thread tradetrace.py
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 thread README.md
Comment on lines +3 to +5
对 `BTC-Trading-Since-2020` 公开账本进行可复现研究,并用 Binance USD-M
`BTCUSDT` 永续 1 分钟 K 线为 XBTUSD 成交提供市场背景。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants