diff --git a/src/tariochbctools/plugins/prices/exchangeratesapi.py b/src/tariochbctools/plugins/prices/exchangeratesapi.py index 666493f..41e9cea 100644 --- a/src/tariochbctools/plugins/prices/exchangeratesapi.py +++ b/src/tariochbctools/plugins/prices/exchangeratesapi.py @@ -18,4 +18,14 @@ def get_latest_price(self, ticker): return source.SourcePrice(price, time, 'CHF') def get_historical_price(self, ticker, time): - return None + us_timezone = tz.gettz("Europe/Zurich") + reqdate = time.astimezone(us_timezone).date() + + resp = requests.get(url='https://api.exchangeratesapi.io/' + str(reqdate) + '?base=' + ticker + '&symbols=CHF') + data = resp.json() + + price = D(str(data['rates']['CHF'])) + date = parse(data['date']) + + time = date.astimezone(us_timezone) + return source.SourcePrice(price, time, 'CHF')