我正在尝试使用以下代码从 yfinance 获取真实的雾滴数据。 但我只是得到相同的收盘价/最高价/最低价/开盘结果。 我开始认为 yfinance 是不可能的。有没有免费和欧洲替代方案?
提前非常感谢!!
#import libraries
import schedule
import time
import alpaca_trade_api as tradeapi
import yfinance as yf
import pandas as pd
# Ask what stocks you want to check
pd = pd.DataFrame()
n = int(input("Enter the size of the list "))
print("\n")
numList = list(num for num in input("Enter the list numbers separated by space ").strip().split())[:n]
print("User List: ", numList)
# Get info for every stock chosen.
def get_data():
for ticker in numList:
ticker_yahoo = yf.Ticker(ticker)
data = ticker_yahoo.history(period = "1d", interval="1m")
data = (data.tail(1).iloc[0])
pd[ticker] = data
print(pd)
get_data()
使用 Pandas Datareader 使用
get_quote_yahoo()
方法更快
import pandas_datareader as web
tickers = ["MSFT", "XOM", "KKR"]
current_price = web.get_quote_yahoo(tickers)["regularMarketPrice"]
如果你坚持使用
yfinance
,你可以使用下面的代码,但要注意它会慢很多,这是因为1)实例化Ticker
对象并拉取info属性需要时间,2)不方便使用 Tickers
类(而不是 Ticker
),因此您必须使用 for 循环。
import yfinance as yf
tickers = ["MSFT", "XOM", "KKR"]
current_price = list()
for i in range(len(tickers)):
company = yf.Ticker(ticker[i])
current_price[i] = company.info["regularMarketPrice"]
显然,这些解决方案也适用于其他类型的证券。请注意,由于请求限制、高延迟、稳定性问题等,使用此(或任何其他免费)数据源进行真实货币算法交易是不可能的。
yfinance 的下载方法不提供实时的分钟数据吗?