-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fetcher.py
More file actions
36 lines (30 loc) · 1.57 KB
/
Copy pathtest_fetcher.py
File metadata and controls
36 lines (30 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from datetime import datetime, timedelta
from src.data.market_data import MarketDataFetcher
def main():
"""Runs a test sequence to fetch and retrieve market data for selected technology stocks.
Initializes a MarketDataFetcher instance and attempts to fetch stock data for predefined symbols
('AAPL', 'MSFT', 'GOOGL') over the last 60 days. It then verifies the data storage by attempting
to retrieve the stored data for the same date range. Outputs informative messages about the
success or failure of each fetch and retrieval attempt.
This function serves as a basic integration test to validate the fetching and storage
capabilities of the MarketDataFetcher class."""
fetcher = MarketDataFetcher()
symbols = ["AAPL", "MSFT", "GOOGL"]
end_date = datetime.now()
start_date = end_date - timedelta(days=60)
for symbol in symbols:
try:
df = fetcher.fetch_stock_data(symbol, start_date, end_date)
if df.empty:
print(f"No data fetched for {symbol} in the given date range.")
else:
print(f"Fetched {len(df)} records for {symbol}")
stored_df = fetcher.get_stored_data(symbol, start_date, end_date)
if stored_df.empty:
print(f"No stored data available for {symbol} in the given date range.")
else:
print(f"Retrieved {len(stored_df)} records of stored data for {symbol}")
except Exception as e:
print(f"Error fetching or retrieving data for {symbol}: {e}")
if __name__ == "__main__":
main()