From 4901d137c6ac4163c23984a252959421df429963 Mon Sep 17 00:00:00 2001 From: Stefan Mach Date: Tue, 12 May 2020 14:01:23 +0200 Subject: [PATCH] Add historical price to exchangeratesapi --- .../plugins/prices/exchangeratesapi.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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')