Skip to content

Commit

Permalink
Merge pull request #163 from provinzio/162-kraken-ledger-fee-sign
Browse files Browse the repository at this point in the history
CHANGE check fee sign of fees in kraken ledger file and save fees wit…
  • Loading branch information
provinzio committed Mar 29, 2024
2 parents ad51191 + 3db8b0b commit aa46a71
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 aa46a71

Please sign in to comment.