async def crypto_current_price(ctx, symbol: str, market: str): cc = CryptoCurrencies(key=os.environ['ALPHA_VANTAGE_API_KEY']) data = cc.get_digital_currency_intraday(symbol=symbol, market=market) current_time = max(data[0].keys()) most_recent_entry = data[0][current_time] output_header = "{} ({})".format(symbol, market) output = get_nice_output(output_header, current_time, most_recent_entry) print(output) await bot.say(output)
# ------------------------------ # Part Three: Sector Performance # ------------------------------ sp = SectorPerformances(key='API_KEY', output_format='pandas') data, metadata = sp.get_sector() data['Rank A: Real-Time Performance'].plot(kind='bar') plt.title('Real Time Performance (%) per Sector') plt.tight_layout() plt.grid() plt.show() # --------------------------- # Part Four: Cryptocurrencies # --------------------------- ticker = 'BTC' cc = CryptoCurrencies(key='YOUR_API_KEY', output_format='pandas') data, metadata = cc.get_digital_currency_intraday(symbol=ticker, market='CNY') data['1b. price (USD)'].plot() plt.tight_layout() plt.title('Intraday value for bitcoin (BTC)') plt.grid() plt.show() # -------------------------------- # Part Five: Foreign Exchange (FX) # -------------------------------- fe = ForeignExchange(key='YOUR_API_KEY') # No metadata here data, _ = fe.get_currency_exchange_rate(from_currency='BTC', to_currency='USD') pprint(data)
# Source(s): # [http://www.alphavantage.co/documentation] from alpha_vantage.cryptocurrencies import CryptoCurrencies from pprint import pprint Cryp = CryptoCurrencies(key='YOUR_API_KEY', output_format = 'pandas') Data, meta_data = Cryp.get_digital_currency_intraday(symbol='BTC', market='INR') pprint(Data.head(2)) #head(2) represents 2 entries of different intervals import matplotlib.pyplot as plt plt.figure(figsize=(10,10)) Data['1a. price (INR)'].plot() plt.tight_layout() plt.title('Intraday value for bitcoin (BTC)') plt.grid() #plt.show() plt.savefig('CurrencyPlot.png') '''
def getCrypto(bot, update, args): try: # The args contain the crypto name cryptoName = " ".join(args).upper() # Call the constructor of the Alphavantage API wrapper cc = CryptoCurrencies(key=alphaVantage_apiKey, output_format='pandas') # Calls the method to fetch intraday prices data, meta_data = cc.get_digital_currency_intraday(cryptoName, market='USD') #Plotting the close values data['1a. price (USD)'].plot() # To show all of the graph, since crypto prices can spike a lot plt.tight_layout() plt.grid() #Setting the Graph title plotTitle = 'Intraday price for {}'.format(cryptoName) plt.title(plotTitle) # Using a Python Util called Temporary file in order to convert the graph into a file object #tmpfile = tempfile.TemporaryFile(suffix=".png") tmpfile = BytesIO() plt.savefig(tmpfile, format="png") tmpfile.seek(0) img = tmpfile # Calls the method to fetch daily prices data, meta_data = cc.get_digital_currency_daily(cryptoName, market='USD') dataList = data.iloc[-1] openUSD = dataList['1a. open (USD)'] highUSD = dataList['2a. high (USD)'] lowUSD = dataList['3a. low (USD)'] closeUSD = dataList['4a. close (USD)'] volume = dataList['5. volume'] marketCapUSD = dataList['6. market cap (USD)'] message = ''' <b> {} </b> \n Open: <em>${}</em> \n Close: <em>${}</em> \n High: <em>${}</em> \n Low: <em>${}</em> \n Volume: <em>{}</em> \n Market Cap: <em>${}</em> '''.format(cryptoName, openUSD, highUSD, lowUSD, closeUSD, volume, marketCapUSD) update.message.reply_photo(img) plt.close() # Sends the above formatted message to the user update.message.reply_html(message) except Exception as e: # Catches the exception and prints the stack trace logging.exception("message") message = '''You probably used the incorrect format for the command.\nUse <pre>/crypto <pre>'companyName' </pre>\nFor more info, please check /help''' # If any exception, send the message showing the frequent cause of exception update.message.reply_html(message)
def alpha_collect_crypto(): cc = CryptoCurrencies(key=Config.keys.alphaVantageApi, output_format='pandas') data, meta_data = cc.get_digital_currency_intraday(symbol='INDEXSP', interval='60min', outputsize='full')
from alpha_vantage.cryptocurrencies import CryptoCurrencies cc = CryptoCurrencies(key='XNPHCZ8ACJ6PW4T6') data, meta_data = cc.get_digital_currency_intraday(symbol='XRP', market='USD') dailyData, dailyMetaData = cc.get_digital_currency_daily(symbol='XRP', market='USD') print(dailyData) # data['1b. price (USD)'].plot() # plt.tight_layout() # plt.title('Intraday value for ripple (XRP)') # plt.grid() # plt.show()