Skip to content

Commit

Permalink
FIX coinbase eur_subtotal might be None (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzio committed May 14, 2022
1 parent cd85986 commit 68d442c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ def _read_coinbase(self, file_path: Path) -> None:
operation,
coin,
_change,
_eur_spot,
_eur_subtotal,
_eur_spot, # Rounded price from CSV, unused
_eur_subtotal, # Cost without fees
_eur_total,
_eur_fee,
remark,
Expand All @@ -319,10 +319,8 @@ def _read_coinbase(self, file_path: Path) -> None:
utc_time = utc_time.replace(tzinfo=datetime.timezone.utc)
operation = operation_mapping.get(operation, operation)
change = misc.force_decimal(_change)
# Rounded price from CSV
# eur_spot = misc.force_decimal(_eur_spot)
# Cost without fees
eur_subtotal = misc.force_decimal(_eur_subtotal)
# `eur_subtotal` and `eur_fee` are None for withdrawals.
eur_subtotal = misc.xdecimal(_eur_subtotal)
eur_fee = misc.xdecimal(_eur_fee)

# Validate data.
Expand All @@ -332,9 +330,11 @@ def _read_coinbase(self, file_path: Path) -> None:
assert _currency_spot == "EUR"

# Calculated price
price_calc = eur_subtotal / change
# Save price in our local database for later.
set_price_db(platform, coin, "EUR", utc_time, price_calc)
if eur_subtotal:
assert isinstance(eur_subtotal, decimal.Decimal)
price_calc = eur_subtotal / change
# Save price in our local database for later.
set_price_db(platform, coin, "EUR", utc_time, price_calc)

if operation == "Convert":
# Parse change + coin from remark, which is
Expand Down Expand Up @@ -401,6 +401,7 @@ def _read_coinbase(self, file_path: Path) -> None:
raise NotImplementedError(f"unknown operation type {operation}")

if eur_fee:
assert isinstance(eur_fee, decimal.Decimal)
self.append_operation(
"Fee", utc_time, platform, eur_fee, "EUR", row, file_path
)
Expand Down

0 comments on commit 68d442c

Please sign in to comment.