Closed FelixWeichselgartner closed 1 year ago
possible implementation:
import yfinance as yf
import requests
def isin2stockprice(isin):
request_string = f"""https://query2.finance.yahoo.com/v1/finance/search?q={isin}"esCount=6&newsCount=0&enableFuzzyQuery=false"esQueryId=tss_match_phrase_query&multiQuoteQueryId=multi_quote_single_token_query&newsQueryId=news_ss_symbols&enableCb=false&enableNavLinks=false&vespaNewsTimeoutMs=600"""
r = requests.get(request_string)
data = r.json()
try:
return yf.Ticker(data['quotes'][0]['symbol'])
except IndexError:
return None
Why not submitting a pull request ? You can find the TickerBase class in base.py (with a get_isin method doing the reverse operation via BusinessInsider, but tagged as experimental), you'll see that there is no verification of the ticker (you just end up with an empty dict if you look at .info on an invalid ticker), perhaps passing a "tick_is_ISIN" bool (defaulted to false) to the init which, if true turned to true, treat the ticker param as an isin ? Something like:
class TickerBase():
def __init__(self, ticker, isin_code=False):
if tick_is_ISIN: ticker = isin2ticker(ticker)
self.ticker = ticker.upper()
Hey ranaroussi,
I have a request for a new feature. A conversion of isin to symbol. @JakobLachermeier and me found a way to convert the an isin to a symbol using the following:
this returns a json like this:
From this you can extract the symbol of the isin. With this conversion you could implement an argument for an isin of your yfinance.Ticker class and not only for symbols.
Greetings Felix Weichselgartner