From bed7db7ee73415bea48d304156e28f862bc90eeb Mon Sep 17 00:00:00 2001 From: Chris Berkhout Date: Mon, 12 Apr 2021 17:58:54 +0200 Subject: [PATCH] Remove CoinMarketCap, add CoinDesk, add bases and quotes. --- src/pricehist/cli.py | 2 ++ src/pricehist/sources/CoinDesk.py | 32 ++++++++++++++++++++++++++ src/pricehist/sources/CoinMarketCap.py | 19 --------------- src/pricehist/sources/ECB.py | 11 +++++++++ src/pricehist/sources/__init__.py | 4 ++-- 5 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 src/pricehist/sources/CoinDesk.py delete mode 100644 src/pricehist/sources/CoinMarketCap.py diff --git a/src/pricehist/cli.py b/src/pricehist/cli.py index 28be090..109cd5b 100644 --- a/src/pricehist/cli.py +++ b/src/pricehist/cli.py @@ -26,6 +26,8 @@ def cmd_source(args): print(f'Name : {source.name()}') print(f'Description : {source.description()}') print(f'URL : {source.source_url()}') + print(f'Bases : {", ".join(source.bases())}') + print(f'Quotes : {", ".join(source.quotes())}') pass def build_parser(): diff --git a/src/pricehist/sources/CoinDesk.py b/src/pricehist/sources/CoinDesk.py new file mode 100644 index 0000000..1c7da7b --- /dev/null +++ b/src/pricehist/sources/CoinDesk.py @@ -0,0 +1,32 @@ +import json +import requests + +class CoinDesk(): + + @staticmethod + def id(): + return 'coindesk' + + @staticmethod + def name(): + return 'CoinDesk Bitcoin Price Index' + + @staticmethod + def description(): + return 'An average of bitcoin prices across leading global exchanges. Powered by CoinDesk, https://www.coindesk.com/price/bitcoin' + + @staticmethod + def source_url(): + return 'https://www.coindesk.com/coindesk-api' + + @staticmethod + def bases(): + return ['BTC'] + + @staticmethod + def quotes(): + url = 'https://api.coindesk.com/v1/bpi/supported-currencies.json' + response = requests.get(url) + data = json.loads(response.content) + symbols = sorted([item['currency'] for item in data]) + return symbols diff --git a/src/pricehist/sources/CoinMarketCap.py b/src/pricehist/sources/CoinMarketCap.py deleted file mode 100644 index d265322..0000000 --- a/src/pricehist/sources/CoinMarketCap.py +++ /dev/null @@ -1,19 +0,0 @@ -class CoinMarketCap(): - - @staticmethod - def id(): - return 'coinmarketcap' - - @staticmethod - def name(): - return 'CoinMarketCap' - - @staticmethod - def description(): - return 'CoinMarketCap historical price data' - - @staticmethod - def source_url(): - return 'https://coinmarketcap.com/' - - diff --git a/src/pricehist/sources/ECB.py b/src/pricehist/sources/ECB.py index 1336cae..6b5c0af 100644 --- a/src/pricehist/sources/ECB.py +++ b/src/pricehist/sources/ECB.py @@ -15,3 +15,14 @@ class ECB(): @staticmethod def source_url(): return 'https://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html' + + @staticmethod + def bases(): + return ['EUR'] + + @staticmethod + def quotes(): + return ['AUD', 'BGN', 'BRL', 'CAD', 'CHF', 'CNY', 'CZK', 'DKK', 'GBP', + 'HKD', 'HRK', 'HUF', 'IDR', 'ILS', 'INR', 'ISK', 'JPY', 'KRW', + 'MXN', 'MYR', 'NOK', 'NZD', 'PHP', 'PLN', 'RON', 'RUB', 'SEK', + 'SGD', 'THB', 'TRY', 'USD', 'ZAR'] diff --git a/src/pricehist/sources/__init__.py b/src/pricehist/sources/__init__.py index 06db3f6..b55f31b 100644 --- a/src/pricehist/sources/__init__.py +++ b/src/pricehist/sources/__init__.py @@ -1,7 +1,7 @@ -from .CoinMarketCap import CoinMarketCap +from .CoinDesk import CoinDesk from .ECB import ECB by_id = { - CoinMarketCap.id(): CoinMarketCap, + CoinDesk.id(): CoinDesk, ECB.id(): ECB }