以下是一段使用Alpha Vantage API获取美国股票价格数据的Python程序:

import requests
import json

# set your API key here
api_key = 'your_api_key'

# set the stock symbol and the time interval
symbol = 'AAPL'
interval = 'daily'

# set the API endpoint and query parameters
url = f'https://www.alphavantage.co/query?function=TIME_SERIES_{interval}&symbol={symbol}&apikey={api_key}'

# make the request to the API
response = requests.get(url)

# parse the JSON response
data = json.loads(response.text)

# extract the prices for the past year
prices = {}
for date, price_data in data[f'Time Series ({interval})'].items():
    if date > '2020-06-01':
        prices[date] = float(price_data['4. close'])

# print the prices
print(prices)

在上面的程序中,我们使用了Alpha Vantage API来获取美国股票价格数据。你需要在代码中设置你自己的API密钥。然后,我们设置了股票代码和时间间隔,发起了API请求并解析了JSON响应。最后,我们提取了过去一年的价格数据,并将其打印出来

帮我写一段Python程序用来提取某个美国股票在过去一年的价格数据

原文地址: https://www.cveoy.top/t/topic/heUm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录