Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate yahoo finance blocking #611

Closed
StephanAkkerman opened this issue Aug 1, 2024 · 5 comments
Closed

Investigate yahoo finance blocking #611

StephanAkkerman opened this issue Aug 1, 2024 · 5 comments
Labels
Bug 🐛 Something isn't working Difficulty: Easy 😊 This issue can easily be solved, only a few line changes necessary Important ❗ Issue is important! Priority: Medium 🥈 Assign this label if this issue is used around once a day

Comments

@StephanAkkerman
Copy link
Owner

yf_info in yf_data.py seems to be blocking, is asynchronous=true really working?

@StephanAkkerman StephanAkkerman added Bug 🐛 Something isn't working Priority: Medium 🥈 Assign this label if this issue is used around once a day Difficulty: Easy 😊 This issue can easily be solved, only a few line changes necessary labels Aug 1, 2024
@StephanAkkerman
Copy link
Owner Author

Maybe it takes longer if we give it more tickers?

@StephanAkkerman
Copy link
Owner Author

Made the function async for now

@StephanAkkerman StephanAkkerman added the Important ❗ Issue is important! label Aug 3, 2024
@StephanAkkerman
Copy link
Owner Author

@StephanAkkerman
Copy link
Owner Author

Could get the OHLCV data async like this:

from io import StringIO

import aiohttp
import pandas as pd


async def fetch(session, url, headers):
    async with session.get(url, headers=headers) as response:
        return await response.text()


async def get_stock_price(ticker):
    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"
    }
    async with aiohttp.ClientSession() as session:
        response = await fetch(session, url, headers)
        df = pd.read_csv(StringIO(response))
        print(df)


import asyncio

asyncio.run(get_stock_price("NVDA"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Difficulty: Easy 😊 This issue can easily be solved, only a few line changes necessary Important ❗ Issue is important! Priority: Medium 🥈 Assign this label if this issue is used around once a day
Projects
None yet
Development

No branches or pull requests

1 participant