convert get_name and get_id to properties

This commit is contained in:
xmatthias 2018-06-18 22:20:50 +02:00
parent ef53134499
commit 896afe7118
3 changed files with 16 additions and 12 deletions

View File

@ -65,7 +65,7 @@ class Exchange(object):
exchange_config = config['exchange']
self._api = self._init_ccxt(exchange_config)
logger.info('Using Exchange "%s"', self.get_name())
logger.info('Using Exchange "%s"', self.name)
# Check if all pairs are available
self.validate_pairs(config['exchange']['pair_whitelist'])
@ -95,10 +95,14 @@ class Exchange(object):
return api
def get_name(self) -> str:
@property
def name(self) -> str:
"""exchange Name (from ccxt)"""
return self._api.name
def get_id(self) -> str:
@property
def id(self) -> str:
"""exchange ccxt id"""
return self._api.id
def validate_pairs(self, pairs: List[str]) -> None:
@ -124,7 +128,7 @@ class Exchange(object):
f'Pair {pair} not compatible with stake_currency: {stake_cur}')
if pair not in markets:
raise OperationalException(
f'Pair {pair} is not available at {self.get_name()}')
f'Pair {pair} is not available at {self.name}')
def exchange_has(self, endpoint: str) -> bool:
"""
@ -376,7 +380,7 @@ class Exchange(object):
return url_base + _EXCHANGE_URLS[self._api.id].format(base=base, quote=quote)
except KeyError:
logger.warning('Could not get exchange url for %s', self.get_name())
logger.warning('Could not get exchange url for %s', self.name)
return ""
@retrier

View File

@ -254,7 +254,7 @@ class FreqtradeBot(object):
interval = self.analyze.get_ticker_interval()
stake_currency = self.config['stake_currency']
fiat_currency = self.config['fiat_display_currency']
exc_name = self.exchange.get_name()
exc_name = self.exchange.name
logger.info(
'Checking buy signals to create a new trade with stake_amount: %f ...',
@ -314,7 +314,7 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
open_rate=buy_limit,
open_rate_requested=buy_limit,
open_date=datetime.utcnow(),
exchange=self.exchange.get_id(),
exchange=self.exchange.id,
open_order_id=order_id
)
Trade.session.add(trade)

View File

@ -66,7 +66,7 @@ def test_validate_pairs_not_compatible(default_conf, mocker):
def test_validate_pairs_exception(default_conf, mocker, caplog):
caplog.set_level(logging.INFO)
api_mock = MagicMock()
mocker.patch('freqtrade.exchange.Exchange.get_name', MagicMock(return_value='Binance'))
mocker.patch('freqtrade.exchange.Exchange.name', PropertyMock(return_value='Binance'))
api_mock.load_markets = MagicMock(return_value={})
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', api_mock)
@ -570,21 +570,21 @@ def test_get_order(default_conf, mocker):
assert api_mock.fetch_order.call_count == 1
def test_get_name(default_conf, mocker):
def test_name(default_conf, mocker):
mocker.patch('freqtrade.exchange.Exchange.validate_pairs',
side_effect=lambda s: True)
default_conf['exchange']['name'] = 'binance'
exchange = Exchange(default_conf)
assert exchange.get_name() == 'Binance'
assert exchange.name == 'Binance'
def test_get_id(default_conf, mocker):
def test_id(default_conf, mocker):
mocker.patch('freqtrade.exchange.Exchange.validate_pairs',
side_effect=lambda s: True)
default_conf['exchange']['name'] = 'binance'
exchange = Exchange(default_conf)
assert exchange.get_id() == 'binance'
assert exchange.id == 'binance'
def test_get_pair_detail_url(default_conf, mocker, caplog):