CoinDesk fetch.
This commit is contained in:
parent
7cf91f1332
commit
94ef73439b
1 changed files with 18 additions and 0 deletions
|
@ -30,3 +30,21 @@ class CoinDesk():
|
||||||
data = json.loads(response.content)
|
data = json.loads(response.content)
|
||||||
symbols = sorted([item['currency'] for item in data])
|
symbols = sorted([item['currency'] for item in data])
|
||||||
return symbols
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue