Skip to content

Commit

Permalink
CHANGE check fee sign of fees in kraken ledger file and save fees wit…
Browse files Browse the repository at this point in the history
…h correct sign

Raise error when fees in one file have different signs.
  • Loading branch information
provinzio committed Mar 29, 2024
1 parent ad51191 commit 3db8b0b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ def _read_kraken_trades(self, file_path: Path) -> None:
)

def _read_kraken_ledgers(self, file_path: Path) -> None:
fee_sign_of_file: Optional[bool] = None

platform = "kraken"
operation_mapping = {
"spend": "Sell", # Sell ordered via 'Buy Crypto' button
Expand Down Expand Up @@ -636,6 +638,26 @@ def _read_kraken_ledgers(self, file_path: Path) -> None:
_asset = _asset.removesuffix(".S")
coin = kraken_asset_map.get(_asset, _asset)
fee = misc.force_decimal(_fee)
# An older implementation expected always positive fees
# It seems that newer ledger files can have negative fee
# values instead.
if fee != 0:
# As soon as the first fee!=0 appears, check whether the
# fees are positive or negative. All fees in the file
# should have the same sign.
if fee_sign_of_file is None:
fee_sign_of_file = fee < 0
# Adjust the fee sign so that fees are always positive.
if fee_sign_of_file is True:
fee *= -1
if fee < 0:
log.error(
f"{file_path} row {row}: Unexpected fee sign. "
"All fees should have the same sign. "
"Please create an Issue or PR."
)
raise RuntimeError

operation = operation_mapping.get(_type)
if operation is None:
if _type == "trade":
Expand Down

0 comments on commit 3db8b0b

Please sign in to comment.