Deepvest/ProfilingAI
0
1import finnhub2import datetime3import pandas as pd4 5class FinnhubDataProvider:6 def __init__(self):7 self.client = finnhub.Client(api_key="csrq269r01qj3u0os3r0csrq269r01qj3u0os3rg")8 9 def get_stock_data(self, symbol, start_date, end_date):10 start_timestamp = int(datetime.datetime.strptime(start_date, '%Y-%m-%d').timestamp())11 end_timestamp = int(datetime.datetime.strptime(end_date, '%Y-%m-%d').timestamp())12 13 try:14 data = self.client.stock_candles(symbol, 'D', start_timestamp, end_timestamp)15 if data['s'] == 'ok':16 df = pd.DataFrame({17 'date': pd.to_datetime(data['t'], unit='s'),18 'close': data['c'],19 'high': data['h'],20 'low': data['l'],21 'open': data['o'],22 'volume': data['v']23 })24 df.set_index('date', inplace=True)25 return df26 else:27 print(f"Error fetching data for {symbol}")28 return None29 except Exception as e:30 print(f"Error: {e}")31 return None32 