def cryptocurrency(API_key, currency): from alpha_vantage.cryptocurrencies import CryptoCurrencies import matplotlib.pyplot as plt cc=CryptoCurrencies(key=API_key,output_format='pandas') option=input('1. Exchange Rates\n2. Health Index\n3. Daily\n4. Weekly\n5. Monthly\n').lower() if option=='exchange rates' or option=='1': data=cc.get_currency_exchange_rate(from_currency=currency, to_currency='USD')[0] return data elif option=='health index' or option=='2': data=cc.get_crypto_rating(symbol=currency)[0] return data elif option=='daily' or option=='3': data=cc.get_digital_currency_daily(symbol=currency, market='CNY')[0] data.plot() plt.title(f'Crypto Daily for the {currency} stock') plt.tight_layout() plt.grid() plt.show() return data elif option=='weekly' or option=='4': data=cc.get_digital_currency_weekly(symbol=currency, market='CNY')[0] data.plot() plt.title(f'Crypto Weekly for the {currency} stock') plt.tight_layout() plt.grid() plt.show() return data elif option=='monthly' or option=='5': data=cc.get_digital_currency_monthly(symbol=currency, market='CNY')[0] data.plot() plt.title(f'Crypto Monthly for the {currency} stock') plt.tight_layout() plt.grid() plt.show() return data else: print("DATA NOT AVAILABLE")
ti = TechIndicators(key=mykey, output_format='pandas') data, meta_data = ti.get_bbands(symbol=myticker, time_period=20) data.tail(252).plot() # Plot last year only. plt.title('BBbands indicator for ' + myticker) plt.show() # Sector performance. sp = SectorPerformances(key=mykey, output_format='pandas') data, meta_data = sp.get_sector() data['Rank G: Year Performance'].plot(kind='bar') plt.title('Sector Performance (Year)') plt.tight_layout() plt.grid() plt.show() # Crypto currencies. cc = CryptoCurrencies(key=mykey, output_format='pandas') data, meta_data = cc.get_digital_currency_daily(symbol='BTC', market='CNY') data['4b. close (USD)'].plot(logy=True) plt.tight_layout() plt.title('Daily Value for Bitcoin (BTC)') plt.grid() plt.show() # Foreign exchange data is only available as JSON format (not in CSV # or Pandas format). There's also no metadata in this call (so we just # use a placeholder `_`). cc = ForeignExchange(key=mykey) data, _ = cc.get_currency_exchange_rate(from_currency='EUR', to_currency='USD') pprint(data)