以前我只是使用www.example.com来获取数据,但是现在我必须异步地进行。yf.download for data, but now i have to do it asynchronously.
我有这个密码
import aiohttp
import asyncio
import pandas as pd
from io import StringIO
ticker = 'BTC-USD'
url = f'https://query1.finance.yahoo.com/v7/finance/download/{ticker}?'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.57'
}
params = {
'range': 'max',
'interval': '1d', # change interval to '1d' for daily data
'events': 'history'
}
async def fetch(session, url, params, headers):
async with session.get(url, params=params, headers=headers) as response:
return await response.text()
async def get_data():
async with aiohttp.ClientSession() as session:
response = await fetch(session, url, params, headers)
df = pd.read_csv(StringIO(response))
print(df)
asyncio.run(get_data())
但是它只能得到每周的数据。我怎么能修复它呢?
1条答案
按热度按时间laawzig21#
尝试将参数更改为
period1
/period2
:图纸: