Skip to content

Commit

Permalink
HoldingsModel.get_asset_history_payments() was improved to protect it…
Browse files Browse the repository at this point in the history
… if somehow trades are absent.
  • Loading branch information
titov-vv committed Mar 24, 2024
1 parent e7fd3ec commit b4167bb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jal/db/holdings_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import logging
from datetime import datetime
from decimal import Decimal

Expand Down Expand Up @@ -195,6 +196,9 @@ def get_data_for_tax(self, index):
# 2nd (Decimal) = 0 (not implemented - the amount of payments that were accumulated for given asset)
def get_asset_history_payments(self, account: JalAccount, asset: JalAsset, end_ts: int) -> (int, Decimal):
trades = account.open_trades_list(asset, end_ts)
if len(trades) == 0:
logging.warning(self.tr("Open position was expected but not found for (account-asset-date): ") + f"'{account.name()}' - {asset.symbol()} - {ts2d(end_ts)}")
return end_ts, Decimal('0')
since = min([x['operation'].timestamp() for x in trades])
amount = account.asset_payments_amount(asset, since, end_ts)
for trade in trades:
Expand Down

0 comments on commit b4167bb

Please sign in to comment.