Spaces:
Runtime error
Runtime error
Delete binance_api/yfinanceclient.py
Browse files
binance_api/yfinanceclient.py
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
import yfinance as yf
|
2 |
-
import pandas as pd
|
3 |
-
|
4 |
-
class YFinanceClient:
|
5 |
-
def __init__(self, ticker):
|
6 |
-
"""
|
7 |
-
Initializes the YFinanceClient with a stock ticker.
|
8 |
-
|
9 |
-
Args:
|
10 |
-
ticker (str): The stock ticker symbol.
|
11 |
-
"""
|
12 |
-
self.ticker = ticker
|
13 |
-
self.stock = yf.Ticker(ticker)
|
14 |
-
|
15 |
-
def fetch_historical_prices(self, period='1mo', interval='1h'):
|
16 |
-
"""
|
17 |
-
Fetches historical stock prices for the specified period and interval.
|
18 |
-
|
19 |
-
Args:
|
20 |
-
period (str): The period over which to fetch historical data (e.g., '1mo' for one month).
|
21 |
-
interval (str): The data interval (e.g., '1h' for hourly data).
|
22 |
-
|
23 |
-
Returns:
|
24 |
-
pd.DataFrame: A DataFrame containing the historical stock prices.
|
25 |
-
"""
|
26 |
-
hist = self.stock.history(period=period, interval=interval)
|
27 |
-
hist.reset_index(inplace=True)
|
28 |
-
# Ensure the DataFrame is in a consistent format with expected column names
|
29 |
-
hist.rename(columns={'Datetime': 'date', 'Open': 'open', 'High': 'high', 'Low': 'low', 'Close': 'close', 'Volume': 'volume'}, inplace=True)
|
30 |
-
return hist
|
31 |
-
|
32 |
-
# Example usage:
|
33 |
-
# client = YFinanceClient('AAPL')
|
34 |
-
# data = client.fetch_historical_prices(period='1mo', interval='1h')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|