Пример #1
0
    def _set_info_data(self, yf_ticker: yf.Ticker) -> None:
        info = yf_ticker.get_info()

        # Check if this is an equity. If not, raise error, since only equity is implemented.
        if not info['quoteType'] in self.supported_quote_type:
            raise Exception(
                f'"{self.symbol}" is "quoteType" == "{info["quoteType"]}". This "quoteType" is not implemented, '
                f'yet.')

        self.recommendation = info[
            'recommendationKey'] if 'recommendationKey' in info else 'N/A'
        self.volume = info['volume']
        prices_to_convert = {
            'current_price':
            info['preMarketPrice']
            if info['preMarketPrice'] else info['regularMarketPrice'],
            'price_52w_high':
            info['fiftyTwoWeekHigh'],
            'price_52w_low':
            info['fiftyTwoWeekLow']
        }

        if info['quoteType'] == 'EQUITY':
            self.percent_change_52w = info['52WeekChange']

        prices_converted = self._convert_to_local_currency(prices_to_convert)
        self.current_price = prices_converted['current_price']
        self.price_52w_high = prices_converted['price_52w_high']
        self.price_52w_low = prices_converted['price_52w_low']
        self.market_capitalization = self.volume * self.current_price
def get_ticker_symbol(ticker: yf.Ticker) -> str:
    try:
        return ticker.get_info()['symbol']
    except ImportError:
        return ""
Пример #3
0
from yfinance import Ticker
tsla = Ticker('TSLA')
print(tsla.ticker + " asking price: " + str(tsla.get_info()['ask']))