Write a python function to get Bitcoin prices after every given 'interval' seconds
def get_btc_price(interval=5):
import requests
import json
from time import sleep
def getBitcoinPrice():
URL = "https://www.bitstamp.net/api/ticker/"
try:
r = requests.get(URL)
priceFloat = float(json.loads(r.text)["last"])
return priceFloat
except requests.ConnectionError:
print("Error querying Bitstamp API")
while True:
print("Bitstamp last price: US $ " + str(getBitcoinPrice()) + "/BTC")
sleep(interval)
Write a python function to get stock prices for a company from 2015 to 2020-12
def get_stock_prices(tickerSymbol='TSLA'):
import yfinance as yf
# get data on this ticker
tickerData = yf.Ticker(tickerSymbol)
# get the historical prices for this ticker
tickerDf = tickerData.history(period='1d', start='2015-1-1', end='2020-12-20')
# see your data
print(tickerDf)