我是python新手,我的目标是编写一些股票分析代码。我安装了yahoo_fin我开始尝试使用它。我开始使用get_live_price提取实时报价
即
<>之前在祝辞祝辞事情就让它get_live_price (, aapl')126.12000274658203我正在处理以美元计价的股票和以加元计价的股票,这使我需要用一种共同的货币来表示它们。所以我想把所有美元股票换成加元,反之亦然。当然,在转换货币之前,我需要首先确定股票的币种。我发现yahoo_fin.stock_info包括get_quote_data例如
<>之前在祝辞祝辞get_quote_data(' apl')导致字典
{'language'; 'en-US', 'region';quoteType'; 'EQUITY';quoteSourceName'; 'triggerable'; True, 'currency'; 'USD'; epstrailingtwelvmonth'; 3.687, 'epsForward'; 4.68, 'priceEpsCurrentYear'; 4.45, 'sharesOutstanding'; 16788100096, 'bookValue';3.936, 'fiftyDayAverageChange': 133.55576, 'fiftyDayAverageChangePercent': -6.8364563, 'twoHundredDayAverageChangePercent': 122.48235, 'twoHundredDayAverageChangePercent': 4.236946, 'twoHundredDayAverageChangePercent': 0.034592297, 'marketCap': 2127376285696, 'priceToBook': 32.194942, 'sourceInterval': 15, 'exchangeDataDelayedBy':0, 'tradeable': False, 'marketState': 'regularMarketChangePercent': -3.1506958, 'regularMarketChangePercent': -2.4260383, 'regularMarketTime': 1614010862, 'regularMarketPrice': 126.7193, 'regularMarketDayRange': 129.72, '125.6 - 129.72; 'regularMarketVolume': 45892833, 'regularMarketVolume': 45892833, ';129.87, 'bid': 126.36, 'askSize': 126.3, 'bidSize': 8, ' fulllexchangename '; 'NasdaqGS';askSize'; 8, 'financialCurrency'; 'USD'; 'regularMarketOpen'; 128.01, 'averageDailyVolume3Month'; 104097755, 'averageDailyVolume10Day'; 84604500, ';fiftyTwoWeekLowChangePercent'; 1.3840704, 'fiftyTwoWeekRange';'53.1525 - 145.09' 'fiftyTwoWeekHighChangePercent': -0.12661588, 'fiftyTwoWeekLow': 53.1525, 'fiftyTwoWeekHigh': 145.09, 'dividendDate': 1611765000, 'earningsTimestampStart': 1619607540, 'trailingAnnualDividendRate': 0.807, 'trailingPE'34.369217, 'trailingAnnualDividendYield': 0.006213906, ' firsttradedatemillisseconds ': 345479400000, 'priceHint': 'exchange';NMS', 'shortName'; 'Apple Inc.', 'messageBoardId'; 'finmb_24937', 'exchangeTimezoneName'; 'America/New_York', 'exchangeTimezoneShortName';;-18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': ' apos;}
我不熟悉字典,我不知道如何处理这些数据,但在那长列表的早期,我看到
"货币":"美元">
所以我的问题是,我如何从这样的字典中获取货币数据或任何其他相关数据。
所以我的问题是,我怎么能只采取货币数据,或任何其他这方面的数据,从这样的字典。
存在键和值对的字典。在您的特定情况下,您可以通过以下方式访问'currency':'USD'
:
data = {'language': 'en-US', 'region': 'US', 'quoteType': 'EQUITY', 'quoteSourceName': 'Nasdaq Real Time Price', 'triggerable': True, 'currency': 'USD', 'epsTrailingTwelveMonths': 3.687, 'epsForward': 4.68, 'epsCurrentYear': 4.45, 'priceEpsCurrentYear': 28.476248, 'sharesOutstanding': 16788100096, 'bookValue': 3.936, 'fiftyDayAverage': 133.55576, 'fiftyDayAverageChange': -6.8364563, 'fiftyDayAverageChangePercent': -0.051188033, 'twoHundredDayAverage': 122.48235, 'twoHundredDayAverageChange': 4.236946, 'twoHundredDayAverageChangePercent': 0.034592297, 'marketCap': 2127376285696, 'forwardPE': 27.076775, 'priceToBook': 32.194942, 'sourceInterval': 15, 'exchangeDataDelayedBy': 0, 'tradeable': False, 'marketState': 'REGULAR', 'regularMarketChange': -3.1506958, 'regularMarketChangePercent': -2.4260383, 'regularMarketTime': 1614010862, 'regularMarketPrice': 126.7193, 'regularMarketDayHigh': 129.72, 'regularMarketDayRange': '125.6 - 129.72', 'regularMarketDayLow': 125.6, 'regularMarketVolume': 45892833, 'regularMarketPreviousClose': 129.87, 'bid': 126.36, 'ask': 126.3, 'bidSize': 8, 'askSize': 8, 'fullExchangeName': 'NasdaqGS', 'financialCurrency': 'USD', 'regularMarketOpen': 128.01, 'averageDailyVolume3Month': 104097755, 'averageDailyVolume10Day': 84604500, 'fiftyTwoWeekLowChange': 73.5668, 'fiftyTwoWeekLowChangePercent': 1.3840704, 'fiftyTwoWeekRange': '53.1525 - 145.09', 'fiftyTwoWeekHighChange': -18.370697, 'fiftyTwoWeekHighChangePercent': -0.12661588, 'fiftyTwoWeekLow': 53.1525, 'fiftyTwoWeekHigh': 145.09, 'dividendDate': 1613001600, 'earningsTimestamp': 1611765000, 'earningsTimestampStart': 1619607540, 'earningsTimestampEnd': 1620043200, 'trailingAnnualDividendRate': 0.807, 'trailingPE': 34.369217, 'trailingAnnualDividendYield': 0.006213906, 'firstTradeDateMilliseconds': 345479400000, 'priceHint': 2, 'exchange': 'NMS', 'shortName': 'Apple Inc.', 'longName': 'Apple Inc.', 'messageBoardId': 'finmb_24937', 'exchangeTimezoneName': 'America/New_York', 'exchangeTimezoneShortName': 'EST', 'gmtOffSetMilliseconds': -18000000, 'market': 'us_market', 'esgPopulated': False, 'displayName': 'Apple', 'symbol': 'AAPL'}
print(data['currency'])
当您从字典data
中访问键currency
的值时,输出将是USD
。
For进一步阅读关于字典,我建议:
- https://www.w3schools.com/python/python_dictionaries.asp
- https://docs.python.org/3/tutorial/datastructures.html字典
- https://realpython.com/python-dicts/