Skip to content

Commit

Permalink
Documentation and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oittaa committed Nov 19, 2021
1 parent 29e409d commit 6d9cc85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ibkr_report/exchangerates.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ def download_official_rates(self, url: str) -> None:

def get_rate(self, currency_from: str, currency_to: str, date_str: str) -> Decimal:
"""Exchange rate between two currencies on a given day."""
one = Decimal(1)
if currency_from == currency_to:
return one
return Decimal(1)

original_date = search_date = get_date(date_str)
while original_date - search_date < timedelta(MAX_BACKTRACK_DAYS):
date_rates = self.rates.get(search_date.strftime(_DATE), {})
from_rate = one if currency_from == "EUR" else date_rates.get(currency_from)
to_rate = one if currency_to == "EUR" else date_rates.get(currency_to)
from_rate = "1" if currency_from == "EUR" else date_rates.get(currency_from)
to_rate = "1" if currency_to == "EUR" else date_rates.get(currency_to)
if from_rate is not None and to_rate is not None:
return Decimal(to_rate) / Decimal(from_rate)
search_date -= timedelta(1)
Expand Down
12 changes: 12 additions & 0 deletions ibkr_report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
class Report:
"""Total selling prices, total capital gains, and total capital losses
calculated from the CSV files.
Args:
file (Iterable[bytes]): The input file in CSV format
report_currency (str): The currency used in the output
use_deemed_acquisition_cost (bool): Whether to use acquisition cost
Attributes:
prices (Decimal): Total selling prices
gains (Decimal): Total capital gains
losses (Decimal): Total capital losses
details(List): Details from trades such as dates and quantities
options (Dict): Whether to use acquisition cost, report currency
"""

prices: Decimal = Decimal(0)
Expand Down

0 comments on commit 6d9cc85

Please sign in to comment.