From 9fe77ec4114a78d9ecbbe84dc5f132b4e4a56bfa Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sat, 30 Jan 2021 14:15:43 +0100 Subject: updated for 2021 av --- generate_prices | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/generate_prices b/generate_prices index a167e2b..5d74699 100755 --- a/generate_prices +++ b/generate_prices @@ -1,13 +1,67 @@ #!/usr/bin/python3 from alpha_vantage.timeseries import TimeSeries +from alpha_vantage.cryptocurrencies import CryptoCurrencies +from alpha_vantage.foreignexchange import ForeignExchange -symbols = ["GOOGL", "APPL"] +api_key = "key" -for symbol in symbols: - ts = TimeSeries(key="your alpha_vantage key") - data, meta_data = ts.get_monthly(symbol) - for key in data: - for year in desired_years: - if year in key: - print("P " + key.replace("-", "/") + " " + symbol + " " + data[key]["4. close"] + " USD") + +def stocks(symbols, desired_years): + for symbol in symbols: + ts = TimeSeries(key=api_key) + data, meta_data = ts.get_monthly(symbol) + for key in data: + for year in desired_years: + if year in key: + print( + "P " + + key.replace("-", "/") + + " " + + symbol + + " " + + data[key]["4. close"] + + " USD" + ) + + +def crypto(symbols, desired_years): + for symbol in symbols: + cc = CryptoCurrencies(key=api_key) + data, meta_data = cc.get_digital_currency_monthly(symbol, market="USD") + for key in data: + for year in desired_years: + if year in key: + print( + "P " + + key.replace("-", "/") + + " " + + symbol + + " " + + data[key]["4a. close (USD)"] + + " USD" + ) + + +def currency(symbols, desired_years): + for symbol in symbols: + fe = ForeignExchange(key=api_key) + data, meta_data = fe.get_currency_exchange_monthly(symbol, "USD") + for key in data: + for year in desired_years: + if year in key: + print( + "P " + + key.replace("-", "/") + + " " + + symbol + + " " + + data[key]["4. close"] + + " USD" + ) + + +desired_years = ["2017", "2018", "2019", "2020", "2021"] +# stocks(["APPL"], desired_years) +# crypto(["ETH"], desired_years) +# currency(["EUR"], desired_years) -- cgit v1.2.3