Rename sources files and reutrn Price objects.
This commit is contained in:
parent
37d527913b
commit
ae69b9ec4e
3 changed files with 12 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
from .CoinDesk import CoinDesk
|
||||
from .ECB import ECB
|
||||
from .coindesk import CoinDesk
|
||||
from .ecb import ECB
|
||||
|
||||
by_id = {
|
||||
CoinDesk.id(): CoinDesk,
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
from decimal import Decimal
|
||||
import json
|
||||
import requests
|
||||
|
||||
from pricehist.price import Price
|
||||
|
||||
class CoinDesk():
|
||||
|
||||
@staticmethod
|
||||
|
@ -45,6 +48,8 @@ class CoinDesk():
|
|||
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']
|
||||
prices = []
|
||||
for (d, v) in data['bpi'].items():
|
||||
prices.append(Price(base, quote, d, Decimal(str(v))))
|
||||
|
||||
return bpi
|
||||
return prices
|
|
@ -4,6 +4,8 @@ import json
|
|||
import requests
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from pricehist.price import Price
|
||||
|
||||
class ECB():
|
||||
|
||||
@staticmethod
|
||||
|
@ -66,6 +68,6 @@ class ECB():
|
|||
# TODO what if it's not found for that day? (some quotes aren't in the earliest data)
|
||||
rate = Decimal(day.find(rate_xpath).attrib['rate'])
|
||||
all_rows.insert(0, (date, rate))
|
||||
selected = [ (d, r) for d, r in all_rows if d >= start and d <= end ]
|
||||
selected = [ Price(base, quote, d, r) for d, r in all_rows if d >= start and d <= end ]
|
||||
|
||||
return selected
|
Loading…
Add table
Reference in a new issue