import yfinance as yf
import pandas as pd
def get_last_two_days_ohlc(ticker):
# Fetch historical data for the last 5 days to ensure we get at least two closed days
data = yf.download(ticker, period="5d")
# Drop rows with missing data
data.dropna(inplace=True)
# Get the last two closed days
last_two_days = data.iloc[-2:]
# Return the OHLC data
return last_two_days[['Open', 'High', 'Low', 'Close']]
# Example usage
ticker = "EURUSD=X"
ohlc_data = get_last_two_days_ohlc(ticker)
print(ohlc_data)
Yfinance не возвращает вчерашние данные [code]import yfinance as yf import pandas as pd
def get_last_two_days_ohlc(ticker): # Fetch historical data for the last 5 days to ensure we get at least two closed days data = yf.download(ticker, period="5d")
# Drop rows with missing data data.dropna(inplace=True)
# Get the last two closed days last_two_days = data.iloc[-2:]
# Return the OHLC data return last_two_days[['Open', 'High', 'Low', 'Close']]
# Example usage ticker = "EURUSD=X" ohlc_data = get_last_two_days_ohlc(ticker) print(ohlc_data)
[/code] Вот результат [code] [*********************100%***********************] 1 of 1 completed Open High Low Close Date 2024-08-29 1.112496 1.114020 1.105632 1.112496 2024-08-30 1.108045 1.109570 1.105400 1.108045 2024-09-02 1.104484 1.107763 1.104252 1.104484 2024-09-04 1.104606 1.106562 1.104240 1.105583 [/code] Я пробовал использовать разные символы, но это происходит со всеми из них.