From 4375a1fa74aec59696205f0fffa6bb94cce7bd92 Mon Sep 17 00:00:00 2001 From: EtWnn Date: Wed, 6 Apr 2022 08:12:17 +0200 Subject: [PATCH 1/2] Removal coinbase support (#36) * remove coinbasepro-python dependencies * update README * Remove coinbase retriever * bump to 0.2.0dev * fix doc * fix docs --- CryptoPrice/__about__.py | 4 +- CryptoPrice/__init__.py | 7 +- CryptoPrice/retrievers/CoinbaseRetriever.py | 87 --------------------- README.rst | 7 +- docs/source/conf.py | 2 +- docs/source/overview.rst | 7 +- docs/source/retrievers.rst | 5 -- requirements.txt | 3 +- setup.py | 3 +- 9 files changed, 12 insertions(+), 113 deletions(-) delete mode 100644 CryptoPrice/retrievers/CoinbaseRetriever.py diff --git a/CryptoPrice/__about__.py b/CryptoPrice/__about__.py index 2146c44..58b392c 100644 --- a/CryptoPrice/__about__.py +++ b/CryptoPrice/__about__.py @@ -1,2 +1,2 @@ -__version__ = "0.1.3" -__author__ = "EtWnn" \ No newline at end of file +__version__ = "0.2.0dev" +__author__ = "EtWnn" diff --git a/CryptoPrice/__init__.py b/CryptoPrice/__init__.py index 52bce25..7584575 100644 --- a/CryptoPrice/__init__.py +++ b/CryptoPrice/__init__.py @@ -2,16 +2,15 @@ from CryptoPrice.retrievers.BinanceRetriever import BinanceRetriever from CryptoPrice.retrievers.KucoinRetriever import KucoinRetriever -from CryptoPrice.retrievers.CoinbaseRetriever import CoinbaseRetriever from CryptoPrice.retrievers.MetaRetriever import MetaRetriever def get_default_retriever() -> MetaRetriever: """ - Provides a hands on price retriever made from the default BinanceRetriever, the default KucoinRetriever - and the default CoinbaseRetriever + Provides a hands on price retriever made from the default BinanceRetriever and the default KucoinRetriever + :return: the meta retriever constructed :rtype: MetaRetriever """ - return MetaRetriever([BinanceRetriever(), KucoinRetriever(), CoinbaseRetriever()]) + return MetaRetriever([BinanceRetriever(), KucoinRetriever()]) diff --git a/CryptoPrice/retrievers/CoinbaseRetriever.py b/CryptoPrice/retrievers/CoinbaseRetriever.py deleted file mode 100644 index 4c10a96..0000000 --- a/CryptoPrice/retrievers/CoinbaseRetriever.py +++ /dev/null @@ -1,87 +0,0 @@ -from datetime import datetime, timedelta, timezone -import traceback -from typing import List - -import cbpro - -from CryptoPrice.common.trade import TradingPair -from CryptoPrice.exceptions import RateAPIException -from CryptoPrice.retrievers.KlineRetriever import KlineRetriever -from CryptoPrice.common.prices import Kline -from CryptoPrice.utils.time import TIMEFRAME - - -class CoinbaseRetriever(KlineRetriever): - """ - This class is in charge of fetching klines from the Coinbase Pro API - - docs: https://github.com/teleprint-me/coinbasepro-python - """ - - def __init__(self, kline_timeframe: TIMEFRAME = TIMEFRAME.m1, closest_window: int = 310): - self.client = cbpro.public_client() - super(CoinbaseRetriever, self).__init__('coinbase', kline_timeframe, closest_window) - - def get_supported_pairs(self) -> List[TradingPair]: - """ - Return the list of trading pair supported by this retriever - - :return: list of trading pairs - :rtype: List[TradingPair] - """ - coinbase_symbols = list(self.client.products.list()) - trading_pairs = [TradingPair(s['base_currency'] + s['quote_currency'], - s['base_currency'], - s['quote_currency'], - source=self.name) for s in coinbase_symbols] - return trading_pairs - - def _get_klines_online(self, asset: str, ref_asset: str, timeframe: TIMEFRAME, - start_time: int, end_time: int) -> List[Kline]: - """ - Fetch klines online by asking the CoinbasePro API - - :param asset: asset of the trading pair - :type asset: str - :param ref_asset: reference asset of the trading pair - :type ref_asset: str - :param timeframe: timeframe for the kline - :type timeframe: TIMEFRAME - :param start_time: fetch only klines with an open time greater or equal than start_time - :type start_time: Optional[int] - :param end_time: fetch only klines with an open time lower than end_time - :type end_time: Optional[int] - :return: list of klines - :rtype: List[Kline] - """ - klines = [] - pair_name = f"{asset}-{ref_asset}" - granularity = 60 * timeframe.value - batch_size = 300 - start_datetime = datetime.fromtimestamp(start_time, tz=timezone.utc) - end_datetime = datetime.fromtimestamp(end_time, tz=timezone.utc) - while start_datetime < end_datetime: - batch_end_datetime = start_datetime + timedelta(seconds=granularity*batch_size) - params = { - 'start': start_datetime.isoformat(), - 'end': batch_end_datetime.isoformat(), - 'granularity': granularity - } - result = self.client.products.history(pair_name, params) - - for row in result: - open_timestamp = int(row[0]) - open = float(row[3]) - high = float(row[2]) - low = float(row[1]) - close = float(row[4]) - - klines.append(Kline(open_timestamp, open, high, low, close, - asset, ref_asset, timeframe, source=self.name)) - - if len(result): - start_datetime = datetime.fromtimestamp(result[0][0], tz=timezone.utc) + timedelta(seconds=granularity) - else: - start_datetime = start_datetime + timedelta(seconds=granularity * batch_size) - - return klines diff --git a/README.rst b/README.rst index 7adcebd..1d1c063 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ =============================== -Welcome to CryptoPrice 0.1.3 +Welcome to CryptoPrice 0.2.0dev =============================== @@ -26,7 +26,6 @@ amount of different tokens or to compare the price difference between exchanges. It currently includes: - Binance API - Kucoin API - - Coinbase API - Cross-API logic Quick Tour @@ -38,10 +37,8 @@ Quick Tour .. code:: bash - pip install --no-deps python-CryptoPrice pip install python-CryptoPrice -*Note*: `--no-deps` is needed as one of the dependencies is not hosted one PYPI, simply on git. You can also install the latest developments (not stable): @@ -95,7 +92,7 @@ than the one above as several API calls (or database requests) may be needed. .. code-block:: bash - >>LTC = 420.76841 XRP, source: {'binance', 'kucoin', 'coinbase'} + >>LTC = 420.76841 XRP, source: {'binance', 'kucoin'} Donation diff --git a/docs/source/conf.py b/docs/source/conf.py index f4e8ac3..9e6b22c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,7 +24,7 @@ # The full version, including alpha/beta/rc tags this_directory = os.path.abspath(os.path.dirname(__file__)) about = {} -with open(os.path.join(this_directory, f'../../{project}/__init__.py'), encoding='utf-8') as f: +with open(os.path.join(this_directory, f'../../{project}/__about__.py'), encoding='utf-8') as f: exec(f.read(), about) release = about['__version__'] diff --git a/docs/source/overview.rst b/docs/source/overview.rst index 52b5826..ebc92fc 100644 --- a/docs/source/overview.rst +++ b/docs/source/overview.rst @@ -8,11 +8,8 @@ Installation .. code:: bash - pip install --no-deps python-CryptoPrice pip install python-CryptoPrice -*Note*: `--no-deps` is needed as one of the dependencies is not hosted one PYPI, simply on git. - You can also install the latest developments (not stable): .. code:: bash @@ -29,7 +26,7 @@ Get a retriever --------------- To fetch some prices, you will need to use a retriever, there are several kinds and instances of retrievers in this -library so we made a default one for you: +library so a default one is ready for you: .. code:: python @@ -85,4 +82,4 @@ than the one above as several API calls (or database requests) have to be made. .. code-block:: bash - >>LTC = 420.76841 XRP, source: {'binance', 'kucoin', 'coinbase'} \ No newline at end of file + >>LTC = 420.76841 XRP, source: {'binance', 'kucoin'} \ No newline at end of file diff --git a/docs/source/retrievers.rst b/docs/source/retrievers.rst index a201eb2..d3be6cc 100644 --- a/docs/source/retrievers.rst +++ b/docs/source/retrievers.rst @@ -31,11 +31,6 @@ Implemented Retrievers Below are the retrievers implemented in this library. -.. automodule:: CryptoPrice.retrievers.CoinbaseRetriever - :special-members: __init__ - :members: - :undoc-members: - .. automodule:: CryptoPrice.retrievers.BinanceRetriever :special-members: __init__ :members: diff --git a/requirements.txt b/requirements.txt index ee0815f..f3dae79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,5 +3,4 @@ appdirs sphinx sphinx_rtd_theme python-binance -kucoin-python -git+https://github.com/teleprint-me/coinbasepro-python.git@2.1.28#egg=cbpro \ No newline at end of file +kucoin-python \ No newline at end of file diff --git a/setup.py b/setup.py index 9fe4be7..fc98ee4 100644 --- a/setup.py +++ b/setup.py @@ -28,8 +28,7 @@ install_requires=['requests', 'appdirs', 'python-binance', - 'kucoin-python', - 'cbpro@git+https://github.com/teleprint-me/coinbasepro-python.git@2.1.28'], + 'kucoin-python'], keywords='eth bsc price ohlc candle history API Binance Kucoin', classifiers=[ 'Intended Audience :: Developers', From 7fae0c6b05eeba29ac54d9b9029cdac2e56063c3 Mon Sep 17 00:00:00 2001 From: EtWnn Date: Wed, 6 Apr 2022 08:18:52 +0200 Subject: [PATCH 2/2] Bump to 0.2.0 (#37) * update readme version * update package version --- CryptoPrice/__about__.py | 2 +- README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CryptoPrice/__about__.py b/CryptoPrice/__about__.py index 58b392c..88c3659 100644 --- a/CryptoPrice/__about__.py +++ b/CryptoPrice/__about__.py @@ -1,2 +1,2 @@ -__version__ = "0.2.0dev" +__version__ = "0.2.0" __author__ = "EtWnn" diff --git a/README.rst b/README.rst index 1d1c063..5b0c0da 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ =============================== -Welcome to CryptoPrice 0.2.0dev +Welcome to CryptoPrice 0.2.0 ===============================