-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Add fees as crypto cost #28
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,10 +13,15 @@ class YearlyProfitCalculator: | |||||||
| def __init__(self, exchanger: Exchanger): | ||||||||
| self.exchanger = exchanger | ||||||||
|
|
||||||||
| def profit_per_year(self, transactions: List[Transaction]) -> ProfitPerYear: | ||||||||
| def profit_per_year(self, transactions: List[Transaction], include_fees: bool) -> ProfitPerYear: | ||||||||
| income = self._sum_transactions_per_year(transactions, Action.SELL) | ||||||||
| cost = self._sum_transactions_per_year(transactions, Action.BUY) | ||||||||
| fees = self._sum_fees_per_year(transactions) | ||||||||
| profit = ProfitPerYear(income, cost) | ||||||||
| if include_fees: | ||||||||
| logger.info("Adding fees to the cost calculation") | ||||||||
| for year in fees.keys(): | ||||||||
| profit.add_cost(year, fees[year]) | ||||||||
| logger.info(f"Calculated profit per year: {profit}") | ||||||||
| return profit | ||||||||
|
|
||||||||
|
|
@@ -31,3 +36,9 @@ def _sum_transactions_per_year(self, transactions: List[Transaction], transactio | |||||||
| transactions_sum_per_year[transaction.year()] += transaction_value_in_base_currency | ||||||||
|
|
||||||||
| return transactions_sum_per_year | ||||||||
|
|
||||||||
| def _sum_fees_per_year(self, transactions: List[Transaction]) -> defaultdict[int, FiatValue]: | ||||||||
| fees_sum_per_year: defaultdict[int, FiatValue] = defaultdict(lambda: FiatValue(0)) | ||||||||
| for transaction in transactions: | ||||||||
| fees_sum_per_year[transaction.year()] += transaction.fees | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
_sum_fees_per_year was adding fees directly without converting them to PLN first. Some fees were in USD and others in PLN, causing the InvalidCurrencyException. So we need to exchange the fees to the base currency (PLN) before summing, just like _sum_transactions_per_year already does for transaction values |
||||||||
| return fees_sum_per_year | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fees always be included - so if they weren't it's an omission and no need to add flag/option for that.