replace pymarketcap with coinmarketcap
This commit is contained in:
parent
e907c48438
commit
31b30ed909
@ -5,7 +5,7 @@ e.g BTC to USD
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from pymarketcap import Pymarketcap
|
from coinmarketcap import Market
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -72,11 +72,17 @@ class CryptoToFiatConverter(object):
|
|||||||
"RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR", "USD"
|
"RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR", "USD"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
CRYPTOMAP = {
|
||||||
|
'BTC': 'bitcoin',
|
||||||
|
'ETH': 'ethereum',
|
||||||
|
'USDT': 'thether'
|
||||||
|
}
|
||||||
|
|
||||||
def __new__(cls):
|
def __new__(cls):
|
||||||
if CryptoToFiatConverter.__instance is None:
|
if CryptoToFiatConverter.__instance is None:
|
||||||
CryptoToFiatConverter.__instance = object.__new__(cls)
|
CryptoToFiatConverter.__instance = object.__new__(cls)
|
||||||
try:
|
try:
|
||||||
CryptoToFiatConverter._coinmarketcap = Pymarketcap()
|
CryptoToFiatConverter._coinmarketcap = Market()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
CryptoToFiatConverter._coinmarketcap = None
|
CryptoToFiatConverter._coinmarketcap = None
|
||||||
return CryptoToFiatConverter.__instance
|
return CryptoToFiatConverter.__instance
|
||||||
@ -171,10 +177,14 @@ class CryptoToFiatConverter(object):
|
|||||||
# Check if the fiat convertion you want is supported
|
# Check if the fiat convertion you want is supported
|
||||||
if not self._is_supported_fiat(fiat=fiat_symbol):
|
if not self._is_supported_fiat(fiat=fiat_symbol):
|
||||||
raise ValueError('The fiat {} is not supported.'.format(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:
|
try:
|
||||||
return float(
|
return float(
|
||||||
self._coinmarketcap.ticker(
|
self._coinmarketcap.ticker(
|
||||||
currency=crypto_symbol,
|
currency=self.CRYPTOMAP[crypto_symbol],
|
||||||
convert=fiat_symbol
|
convert=fiat_symbol
|
||||||
)['price_' + fiat_symbol.lower()]
|
)['price_' + fiat_symbol.lower()]
|
||||||
)
|
)
|
||||||
|
@ -19,7 +19,7 @@ hyperopt==0.1
|
|||||||
# do not upgrade networkx before this is fixed https://github.com/hyperopt/hyperopt/issues/325
|
# do not upgrade networkx before this is fixed https://github.com/hyperopt/hyperopt/issues/325
|
||||||
networkx==1.11
|
networkx==1.11
|
||||||
tabulate==0.8.2
|
tabulate==0.8.2
|
||||||
pymarketcap==3.3.158
|
coinmarketcap==4.2.1
|
||||||
|
|
||||||
# Required for plotting data
|
# Required for plotting data
|
||||||
#plotly==2.3.0
|
#plotly==2.3.0
|
||||||
|
Loading…
Reference in New Issue
Block a user