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

Improve ticker handling for multiple tickers #507

Open
StephanAkkerman opened this issue Feb 21, 2024 · 1 comment
Open

Improve ticker handling for multiple tickers #507

StephanAkkerman opened this issue Feb 21, 2024 · 1 comment
Labels
Difficulty: Medium 😐 This issue can be solved, but a decent amount of lines need to be changed Improvement 📈 Improvement Priority: Low 🥉 Assign this label if this issue is used once every few days

Comments

@StephanAkkerman
Copy link
Owner

StephanAkkerman commented Feb 21, 2024

We could make it quicker because many libraries support querying multiple tickers at the same time:
yahooquery:

from yahooquery import Ticker

symbols = ['fb', 'aapl', 'amzn', 'nflx', 'goog']

faang = Ticker(symbols)

faang.summary_detail

tradingview_ta also supports it, ccxt might, coingecko?

@StephanAkkerman StephanAkkerman added Improvement 📈 Improvement Priority: Low 🥉 Assign this label if this issue is used once every few days Difficulty: Medium 😐 This issue can be solved, but a decent amount of lines need to be changed labels Feb 21, 2024
@StephanAkkerman
Copy link
Owner Author

StephanAkkerman commented Aug 7, 2024

Yahoo: (from https://stackoverflow.com/questions/76065035/yahoo-finance-v7-api-now-requiring-cookies-python)

import requests

apiBase = "https://query2.finance.yahoo.com"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"}


def getCredentials(
    cookieUrl="https://fc.yahoo.com", crumbUrl=apiBase + "/v1/test/getcrumb"
):
    cookie = requests.get(cookieUrl).cookies
    crumb = requests.get(url=crumbUrl, cookies=cookie, headers=headers).text
    return {"cookie": cookie, "crumb": crumb}


def quote(symbols, credentials):
    url = apiBase + "/v7/finance/quote"
    params = {"symbols": ",".join(symbols), "crumb": credentials["crumb"]}
    response = requests.get(
        url, params=params, cookies=credentials["cookie"], headers=headers
    )
    quotes = response.json()["quoteResponse"]["result"]
    return quotes

credentials = getCredentials()
quotes = quote(["GOOG", "TSLA"], credentials)
print(quotes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium 😐 This issue can be solved, but a decent amount of lines need to be changed Improvement 📈 Improvement Priority: Low 🥉 Assign this label if this issue is used once every few days
Projects
None yet
Development

No branches or pull requests

1 participant