From 31b30ed909d4963b3aeb22e0fe647852ad15b8a1 Mon Sep 17 00:00:00 2001 From: Matthias Voppichler Date: Fri, 16 Mar 2018 21:21:59 +0100 Subject: [PATCH] replace pymarketcap with coinmarketcap --- freqtrade/fiat_convert.py | 16 +++++++++++++--- requirements.txt | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/freqtrade/fiat_convert.py b/freqtrade/fiat_convert.py index 6f9d3d3d5..473f35ecc 100644 --- a/freqtrade/fiat_convert.py +++ b/freqtrade/fiat_convert.py @@ -5,7 +5,7 @@ e.g BTC to USD import logging import time -from pymarketcap import Pymarketcap +from coinmarketcap import Market logger = logging.getLogger(__name__) @@ -72,11 +72,17 @@ class CryptoToFiatConverter(object): "RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR", "USD" ] + CRYPTOMAP = { + 'BTC': 'bitcoin', + 'ETH': 'ethereum', + 'USDT': 'thether' + } + def __new__(cls): if CryptoToFiatConverter.__instance is None: CryptoToFiatConverter.__instance = object.__new__(cls) try: - CryptoToFiatConverter._coinmarketcap = Pymarketcap() + CryptoToFiatConverter._coinmarketcap = Market() except BaseException: CryptoToFiatConverter._coinmarketcap = None return CryptoToFiatConverter.__instance @@ -171,10 +177,14 @@ class CryptoToFiatConverter(object): # Check if the fiat convertion you want is supported if not self._is_supported_fiat(fiat=fiat_symbol): raise ValueError('The fiat {} is not supported.'.format(fiat_symbol)) + + if crypto_symbol not in self.CRYPTOMAP: + raise ValueError( + 'The crypto_symbol {} is not supported.'.format(crypto_symbol)) try: return float( self._coinmarketcap.ticker( - currency=crypto_symbol, + currency=self.CRYPTOMAP[crypto_symbol], convert=fiat_symbol )['price_' + fiat_symbol.lower()] ) diff --git a/requirements.txt b/requirements.txt index b2a2429c7..29361ecdb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,7 +19,7 @@ hyperopt==0.1 # do not upgrade networkx before this is fixed https://github.com/hyperopt/hyperopt/issues/325 networkx==1.11 tabulate==0.8.2 -pymarketcap==3.3.158 +coinmarketcap==4.2.1 # Required for plotting data #plotly==2.3.0