我想知道是否有地方可以下载给定股票的元数据。我之前正在研究 REST API,我想我也许可以使用这样的东西:
stock_code = "GME"
base_url = "https://somestockmarkekpage.com/api/stock?code={}"
resp = requests.get(base_url.format(stock_code))
print(resp.json()['short_ratio'])
Run Code Online (Sandbox Code Playgroud)
问题是我不知道可以从哪里下载这些数据的任何base_url,甚至不知道它是否免费存在。但是,我们非常欢迎您提供任何其他 API 或服务
雅虎提供了一个免费的 API,其中包含与多个票证相关的最新数据。您可以在此处查看 API 详细信息。从票证中提取元数据的一个示例是:
import yfinance as yf
stock_obj = yf.Ticker("GME")
# Here are some fixs on the JSON it returns
validated = str(stock_obj.info).replace("'","\"").replace("None", "\"NULL\"").replace("False", "\"FALSE\"").replace("True", "\"TRUE\"")
# Parsing the JSON here
meta_obj = json.loads(validated)
# Some of the short fields
print("sharesShort: "+str( meta_obj['sharesShort']))
print("shortRatio: "+str( meta_obj['shortRatio']))
print("shortPercentOfFloat: "+str( meta_obj['shortPercentOfFloat']))
Run Code Online (Sandbox Code Playgroud)
您感兴趣的票证的输出将是:
sharesShort: 61782730
shortRatio: 2.81
shortPercentOfFloat: 2.2642
Run Code Online (Sandbox Code Playgroud)