Skip to content

Commit 8377c0e

Browse files
authored
Fixed bug merging dividends from different brokers (#149)
* Cleanup unused code * Fixed bug when merging dividends paid on the same day
1 parent d6e9c73 commit 8377c0e

File tree

13 files changed

+32
-56
lines changed

13 files changed

+32
-56
lines changed
File renamed without changes.

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,24 @@ See [Wiki - Developing Stonks Overwatch](./docs/Developing-Stonks-Overwatch)
128128
* [ ] Create a Crypto Rewards section
129129
* [ ] Show asset staking blocked amount as in Bitvavo UI
130130
* [ ] IBKR
131-
* [ ] Get Deposits & Withdrawals (Based on ticket only possible with a FlexQuery up to 365 days old)
132131
* [ ] Show closed positions
133132
* [ ] Realized % Gain/Loss is not showed when merging positions
134133
* [ ] Stock Category
135134
* [ ] Add support for Portfolio Growth
136-
* [ ] Diversification: Fix sectors to be properly grouped
137-
* [ ] Diversification: Remove Cash and Crypto from Holdings
135+
* [ ] Diversification:
136+
* [ ] Fix sectors to be properly grouped
137+
* [ ] Remove Cash and Crypto from Holdings
138138
* [ ] Fees: Add support for Fees
139139
* [ ] Transactions:
140140
* [ ] Add fees/taxes
141141
* [ ] Review provided values: Should Dividends be included in the transactions?
142142
* [ ] Web:
143143
* Performance & Reports / Transaction History: Shows transactions for the last 2 years
144144
* Flex Query: Allows creating custom reports.
145-
* [ ] Dividends: Implement Announced and Forecasted dividends
146-
* [ ] Deposits: Implement Deposits and Withdrawals
145+
* [ ] Dividends:
146+
* [ ] Taxes are not included in the dividends (See Fees)
147+
* [ ] Implement Announced and Forecasted dividends
148+
* [ ] Deposits: Implement Deposits and Withdrawals (As per support ticket it's only possible with a FlexQuery up to 365 days old)
147149
* [ ] Portfolio Growth: Implement Portfolio Growth
148150

149151
## Logos

src/stonks_overwatch/core/aggregators/base_aggregator.py

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from abc import ABC, abstractmethod
9-
from typing import Any, Dict, List, Optional, Union
9+
from typing import Any, Dict, List, Optional
1010

1111
from stonks_overwatch.config.config import Config
1212
from stonks_overwatch.core.exceptions import DataAggregationException
@@ -158,17 +158,13 @@ def _get_enabled_brokers(self, selected_portfolio: PortfolioId) -> List[str]:
158158
if self._is_broker_enabled(broker_name, selected_portfolio)
159159
]
160160

161-
def _collect_broker_data(
162-
self, selected_portfolio: PortfolioId, method_name: str, *args, **kwargs
163-
) -> Dict[str, Any]:
161+
def _collect_broker_data(self, selected_portfolio: PortfolioId, method_name: str) -> Dict[str, Any]:
164162
"""
165163
Collect data from all enabled brokers using the specified method.
166164
167165
Args:
168166
selected_portfolio: Selected portfolio configuration
169167
method_name: Name of the method to call on each broker service
170-
*args: Arguments to pass to the method
171-
**kwargs: Keyword arguments to pass to the method
172168
173169
Returns:
174170
Dictionary mapping broker names to their data
@@ -193,8 +189,8 @@ def _collect_broker_data(
193189

194190
# Check if it's a property or callable
195191
if callable(attr):
196-
# It's a method, call it with arguments
197-
data = attr(*args, **kwargs)
192+
# It's a method, call it with no arguments
193+
data = attr()
198194
else:
199195
# It's a property, just use the value
200196
data = attr
@@ -223,34 +219,6 @@ def _collect_broker_data(
223219

224220
return broker_data
225221

226-
def _merge_lists(self, data_lists: List[List[Any]]) -> List[Any]:
227-
"""
228-
Merge multiple lists into a single list.
229-
230-
Args:
231-
data_lists: List of lists to merge
232-
233-
Returns:
234-
Merged list containing all items
235-
"""
236-
merged = []
237-
for data_list in data_lists:
238-
if data_list:
239-
merged.extend(data_list)
240-
return merged
241-
242-
def _sum_numeric_values(self, values: List[Union[int, float]]) -> float:
243-
"""
244-
Sum numeric values with error handling.
245-
246-
Args:
247-
values: List of numeric values to sum
248-
249-
Returns:
250-
Sum of all values
251-
"""
252-
return sum(float(value) for value in values if value is not None)
253-
254222
@property
255223
def supported_brokers(self) -> List[str]:
256224
"""
@@ -272,7 +240,7 @@ def service_type(self) -> ServiceType:
272240
return self._service_type
273241

274242
@abstractmethod
275-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> Any:
243+
def aggregate_data(self, selected_portfolio: PortfolioId) -> Any:
276244
"""
277245
Aggregate data from all enabled brokers.
278246
@@ -306,7 +274,7 @@ def _collect_and_merge_lists(
306274
Returns:
307275
Combined (and optionally merged) list of data
308276
"""
309-
broker_data = self._collect_broker_data(selected_portfolio, method_name, *args, **kwargs)
277+
broker_data = self._collect_broker_data(selected_portfolio, method_name)
310278

311279
# Combine all data into a single list
312280
combined_data = []
@@ -345,7 +313,7 @@ def _collect_and_merge_objects(
345313
Returns:
346314
Merged object or list of objects
347315
"""
348-
broker_data = self._collect_broker_data(selected_portfolio, method_name, *args, **kwargs)
316+
broker_data = self._collect_broker_data(selected_portfolio, method_name)
349317

350318
# Collect objects of the expected type
351319
typed_objects = []

src/stonks_overwatch/services/aggregators/account_overview_aggregator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_account_overview(self, selected_portfolio: PortfolioId) -> List[AccountO
1515
selected_portfolio, "get_account_overview", sort_key=lambda k: k.datetime, reverse=True
1616
)
1717

18-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> List[AccountOverview]:
18+
def aggregate_data(self, selected_portfolio: PortfolioId) -> List[AccountOverview]:
1919
"""
2020
Aggregate account overview data from all enabled brokers.
2121

src/stonks_overwatch/services/aggregators/deposits_aggregator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_cash_deposits(self, selected_portfolio: PortfolioId) -> List[Deposit]:
5555
selected_portfolio, "get_cash_deposits", sort_key=lambda x: x.datetime, reverse=True
5656
)
5757

58-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> List[Deposit]:
58+
def aggregate_data(self, selected_portfolio: PortfolioId) -> List[Deposit]:
5959
"""
6060
Aggregate deposit data from all enabled brokers.
6161

src/stonks_overwatch/services/aggregators/dividends_aggregator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_dividends(self, selected_portfolio: PortfolioId) -> List[Dividend]:
1313
# Use the new helper method to collect and sort dividend data
1414
return self._collect_and_sort(selected_portfolio, "get_dividends", sort_key=lambda k: k.payment_date)
1515

16-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> List[Dividend]:
16+
def aggregate_data(self, selected_portfolio: PortfolioId) -> List[Dividend]:
1717
"""
1818
Aggregate dividend data from all enabled brokers.
1919

src/stonks_overwatch/services/aggregators/fees_aggregator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
from stonks_overwatch.core.aggregators.base_aggregator import BaseAggregator
24
from stonks_overwatch.core.service_types import ServiceType
35
from stonks_overwatch.services.models import Fee, PortfolioId
@@ -11,7 +13,7 @@ def get_fees(self, selected_portfolio: PortfolioId) -> list[Fee]:
1113
# Use the new helper method to collect and sort fee data
1214
return self._collect_and_sort(selected_portfolio, "get_fees", sort_key=lambda k: (k.date, k.time), reverse=True)
1315

14-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> list[Fee]:
16+
def aggregate_data(self, selected_portfolio: PortfolioId) -> List[Fee]:
1517
"""
1618
Aggregate fee data from all enabled brokers.
1719

src/stonks_overwatch/services/aggregators/portfolio_aggregator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def calculate_historical_value(self, selected_portfolio: PortfolioId) -> List[Da
8989
selected_portfolio, "calculate_historical_value", merger_func=DataMerger.merge_historical_values
9090
)
9191

92-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> List[PortfolioEntry]:
92+
def aggregate_data(self, selected_portfolio: PortfolioId) -> List[PortfolioEntry]:
9393
"""
9494
Aggregate portfolio data from all enabled brokers.
9595

src/stonks_overwatch/services/aggregators/transactions_aggregator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def get_transactions(self, selected_portfolio: PortfolioId) -> List[Transaction]
1818
reverse=True,
1919
)
2020

21-
def aggregate_data(self, selected_portfolio: PortfolioId, **kwargs) -> List[Transaction]:
21+
def aggregate_data(self, selected_portfolio: PortfolioId) -> List[Transaction]:
2222
"""
2323
Aggregate transaction data from all enabled brokers.
2424

src/stonks_overwatch/services/brokers/degiro/services/dividend_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _get_dividends(self) -> List[Dividend]:
5858
for transaction in overview:
5959
if transaction.description in self.DIVIDEND_DESCRIPTIONS:
6060
# Create a key to group by date and stock symbol
61-
key = (transaction.datetime.date(), transaction.stock_symbol)
61+
key = (transaction.value_datetime.date(), transaction.stock_symbol)
6262

6363
transaction_change = transaction.change
6464
currency = transaction.currency
@@ -72,7 +72,7 @@ def _get_dividends(self) -> List[Dividend]:
7272

7373
if key not in dividend_groups:
7474
dividend_groups[key] = {
75-
"payment_date": transaction.datetime,
75+
"payment_date": transaction.value_datetime,
7676
"stock_name": transaction.stock_name,
7777
"stock_symbol": transaction.stock_symbol,
7878
"currency": currency,

0 commit comments

Comments
 (0)