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 .coindesk import CoinDesk
|
||||||
from .ECB import ECB
|
from .ecb import ECB
|
||||||
|
|
||||||
by_id = {
|
by_id = {
|
||||||
CoinDesk.id(): CoinDesk,
|
CoinDesk.id(): CoinDesk,
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
from decimal import Decimal
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from pricehist.price import Price
|
||||||
|
|
||||||
class CoinDesk():
|
class CoinDesk():
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -45,6 +48,8 @@ class CoinDesk():
|
||||||
url = f'https://api.coindesk.com/v1/bpi/historical/close.json?currency={quote}&start={start}&end={end}'
|
url = f'https://api.coindesk.com/v1/bpi/historical/close.json?currency={quote}&start={start}&end={end}'
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
data = json.loads(response.content)
|
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
|
import requests
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
|
from pricehist.price import Price
|
||||||
|
|
||||||
class ECB():
|
class ECB():
|
||||||
|
|
||||||
@staticmethod
|
@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)
|
# 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'])
|
rate = Decimal(day.find(rate_xpath).attrib['rate'])
|
||||||
all_rows.insert(0, (date, 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
|
return selected
|
Loading…
Add table
Reference in a new issue