Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE check fee sign of fees in kraken ledger file and save fees wit… #163

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading