Skip to content

Commit

Permalink
Merge pull request #18 from stmach/master
Browse files Browse the repository at this point in the history
Add historical price to exchangeratesapi
  • Loading branch information
tarioch authored May 12, 2020
2 parents a38e0bd + 4901d13 commit 6c8c327
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/tariochbctools/plugins/prices/exchangeratesapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 6c8c327

Please sign in to comment.