CoinDesk fetch.

This commit is contained in:
Chris Berkhout 2021-04-13 22:30:33 +02:00
parent 7cf91f1332
commit 94ef73439b

View file

@ -30,3 +30,21 @@ class CoinDesk():
data = json.loads(response.content)
symbols = sorted([item['currency'] for item in data])
return symbols
def fetch(self, pair, start, end):
base, quote = pair.split('/')
if base not in self.bases():
exit(f'Invalid base {base}')
if quote not in self.quotes():
exit(f'Invalid quote {quote}')
min_start = '2010-07-17'
if start < min_start:
exit(f'start {start} too early. The CoinDesk BPI only covers data from {min_start} onwards.')
url = f'https://api.coindesk.com/v1/bpi/historical/close.json?currency={quote}&start={start}&end={end}'
response = requests.get(url)
data = json.loads(response.content)
bpi = data['bpi']
return bpi