Skip to content

fix: Binance Spot export format change (UTC_Time→Time, YY year)#81

Merged
przemyslawbialon merged 1 commit into
mainfrom
fix/binance-format-change
Apr 26, 2026
Merged

fix: Binance Spot export format change (UTC_Time→Time, YY year)#81
przemyslawbialon merged 1 commit into
mainfrom
fix/binance-format-change

Conversation

@przemyslawbialon

Copy link
Copy Markdown
Collaborator

Problem

Binance changed the Spot transaction history CSV format. Running the existing importer on a current export crashes:

```
File "pit38/plugins/crypto/binance/csv.py", line 22, in init
self.utc_time = datetime.strptime(row["utc_time"], "%Y-%m-%d %H:%M:%S")
KeyError: 'utc_time'
```

What changed

Element Old New
Columns `UTC_Time, Account, Operation, Coin, Change, Remark` `User ID, Time, Account, Operation, Coin, Change, Remark`
Time column name `UTC_Time` `Time`
Year format `2024-07-25 21:30:41` `24-07-25 21:30:41`
Leading column `User ID`

Fix

Two-line change in `BinanceTransaction.init`:

  • `row["utc_time"]` → `row["time"]`
  • date format `%Y` → `%y`

The new `User ID` column is simply ignored (parser never reads it). BOM + lowercase headers already handled by `open_csv_reader`.

Scope

Only the format change. No backward compatibility with pre-2025 exports — users with stale files can re-download from the Binance portal.

Out of scope (follow-up candidates)

  • `FiatValue.currency` gets populated with the raw "PLN" string instead of `Currency.ZLOTY`. Pre-existing quirk; tests assert on components so they stay honest without endorsing the drift.
  • Timezone handling — filename is `(UTC+2)`, parser treats timestamps as UTC. Can shift transactions across NBP business-day boundaries in edge cases.
  • `Transaction Sell` operations (`# TODO: handle sell operations` in the source). Not in the sample file.

Tests

  • New `tests/test_binance_csv.py` — 6 unit tests (first-ever Binance tests in this repo).
  • New `tests/e2e/fixtures/binance_transaction_history.csv` — 7 rows, anonymized (`User ID` 999999999, round amounts).
  • New `test_import_binance` CliRunner case in `tests/e2e/test_cli_e2e.py` — parity with revolut-stock and ibi-capital.
  • Manually verified on the user's real 20-row export: 6 transactions extracted, fee aggregated correctly into asset amount.

Test plan

  • `pytest tests/` — 182 → 189 passed, zero regressions
  • `flake8 pit38/plugins/crypto/binance/ --select=E9,F63,F7,F82` clean
  • Manual: `pit38 import binance -i ` exits 0 and produces CSV
  • Manual: `pit38 crypto -f -y 2024` runs end-to-end

Binance renamed the time column ("UTC_Time" → "Time"), added a leading
"User ID" column, and shortened timestamps from 4-digit to 2-digit year
in recent Spot exports. The parser now reads row["time"] and uses
"%y-%m-%d %H:%M:%S". Legacy exports need to be regenerated from the
Binance portal — back-compat would require a heuristic fallback that
isn't worth the surface area.

Also:
- First unit tests for the Binance parser (there were none before) —
  cover deposit-skip, convert-pair grouping, transaction-triple fee
  aggregation, and the YY vs YYYY guard.
- Anonymized 7-row fixture (User ID 999999999, round amounts).
- CliRunner test for `pit38 import binance` for parity with
  revolut-stock and ibi-capital.

Noted as out-of-scope for this fix: FiatValue.currency is populated
with the raw "PLN" string instead of Currency.ZLOTY (pre-existing
quirk). Tests assert on components so they're honest about the drift
without endorsing it.
@codecov

codecov Bot commented Apr 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@przemyslawbialon przemyslawbialon merged commit e916d93 into main Apr 26, 2026
5 checks passed
@przemyslawbialon przemyslawbialon deleted the fix/binance-format-change branch April 26, 2026 14:47
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.

1 participant