-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mutual funds trades tracking (#16)
Related to #8 Add real-time mutual funds trades tracking functionality. * **New File: `data/mutual_funds_tracker.py`** - Define `MutualFundsTracker` class to handle real-time tracking of mutual funds trades. - Implement `fetch_mutual_funds_trades` method to fetch real-time mutual funds trades data. - Implement `process_mutual_funds_trades` method to process mutual funds trades data. * **Update `main.py`** - Import `MutualFundsTracker` from `data/mutual_funds_tracker`. - Initialize `MutualFundsTracker` in the main function. - Add `mutual_funds_tracker` to the `process_market_data` function parameters. - Create a task to process mutual funds trades in `process_market_data` function. * **Update `config/config.py`** - Add `mutual_funds_tracking_enabled` and `mutual_funds_data_source` settings under `investment_banking` section. * **Update `config/api_config.py`** - Add `mutual_funds_api_key` and `mutual_funds_api_endpoint` settings. - Add `mutual_funds_headers` method to return headers for Mutual Funds API. - Add `get_mutual_funds_endpoint` method to return the Mutual Funds API endpoint. * **New File: `tests/test_mutual_funds_tracker.py`** - Define tests for `MutualFundsTracker` class. - Test `fetch_mutual_funds_trades` method. - Test `process_mutual_funds_trades` method.
- Loading branch information
Showing
5 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
from typing import Dict, Any | ||
from datetime import datetime | ||
|
||
class MutualFundsTracker: | ||
""" | ||
Handles real-time tracking of mutual funds trades. | ||
""" | ||
|
||
def __init__(self, config: Dict[str, Any]): | ||
""" | ||
Initialize the MutualFundsTracker with configuration settings. | ||
Args: | ||
config: Dictionary containing configuration parameters | ||
""" | ||
self.config = config | ||
self.logger = logging.getLogger(__name__) | ||
self.logger.info("Initializing MutualFundsTracker") | ||
|
||
async def fetch_mutual_funds_trades(self) -> Dict[str, Any]: | ||
""" | ||
Fetch real-time mutual funds trades data. | ||
Returns: | ||
Dictionary containing mutual funds trades data | ||
""" | ||
try: | ||
self.logger.info("Fetching mutual funds trades data") | ||
# Implementation for fetching mutual funds trades data would go here | ||
# This would typically involve API calls to the data provider | ||
|
||
# Placeholder return | ||
return { | ||
"timestamp": datetime.now().isoformat(), | ||
"trades": [] | ||
} | ||
|
||
except Exception as e: | ||
self.logger.error(f"Error fetching mutual funds trades data: {str(e)}") | ||
raise | ||
|
||
async def process_mutual_funds_trades(self, trades_data: Dict[str, Any]) -> None: | ||
""" | ||
Process mutual funds trades data. | ||
Args: | ||
trades_data: Dictionary containing mutual funds trades data | ||
""" | ||
try: | ||
self.logger.info("Processing mutual funds trades data") | ||
# Implementation for processing mutual funds trades data would go here | ||
|
||
except Exception as e: | ||
self.logger.error(f"Error processing mutual funds trades data: {str(e)}") | ||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import unittest | ||
from unittest.mock import patch, AsyncMock | ||
from data.mutual_funds_tracker import MutualFundsTracker | ||
|
||
class TestMutualFundsTracker(unittest.TestCase): | ||
def setUp(self): | ||
self.config = { | ||
"investment_banking": { | ||
"mutual_funds_tracking_enabled": True, | ||
"mutual_funds_data_source": "test_source" | ||
} | ||
} | ||
self.tracker = MutualFundsTracker(self.config) | ||
|
||
@patch('data.mutual_funds_tracker.MutualFundsTracker.fetch_mutual_funds_trades') | ||
async def test_fetch_mutual_funds_trades(self, mock_fetch): | ||
# Mock response data | ||
mock_data = { | ||
"timestamp": "2023-01-01T00:00:00Z", | ||
"trades": [ | ||
{"trade_id": 1, "symbol": "TEST", "price": 100.0, "volume": 1000} | ||
] | ||
} | ||
mock_fetch.return_value = mock_data | ||
|
||
# Test fetching data | ||
result = await self.tracker.fetch_mutual_funds_trades() | ||
|
||
# Verify results | ||
self.assertEqual(result["timestamp"], "2023-01-01T00:00:00Z") | ||
self.assertEqual(len(result["trades"]), 1) | ||
self.assertEqual(result["trades"][0]["symbol"], "TEST") | ||
|
||
@patch('data.mutual_funds_tracker.MutualFundsTracker.process_mutual_funds_trades') | ||
async def test_process_mutual_funds_trades(self, mock_process): | ||
# Mock trades data | ||
trades_data = { | ||
"timestamp": "2023-01-01T00:00:00Z", | ||
"trades": [ | ||
{"trade_id": 1, "symbol": "TEST", "price": 100.0, "volume": 1000} | ||
] | ||
} | ||
|
||
# Test processing data | ||
await self.tracker.process_mutual_funds_trades(trades_data) | ||
|
||
# Verify processing was called | ||
mock_process.assert_called_once_with(trades_data) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |