only init FIATConvert when telegram is enabled

This commit is contained in:
Matthias 2018-07-21 20:13:32 +02:00
parent 6f7898809a
commit 9467461160
3 changed files with 7 additions and 21 deletions

View File

@ -16,7 +16,6 @@ from cachetools import TTLCache, cached
from freqtrade import (DependencyException, OperationalException,
TemporaryError, __version__, constants, persistence)
from freqtrade.exchange import Exchange
from freqtrade.fiat_convert import CryptoToFiatConverter
from freqtrade.persistence import Trade
from freqtrade.rpc import RPCManager, RPCMessageType
from freqtrade.state import State
@ -49,7 +48,6 @@ class FreqtradeBot(object):
# Init objects
self.config = config
self.strategy: IStrategy = StrategyResolver(self.config).strategy
self.fiat_converter = CryptoToFiatConverter()
self.rpc: RPCManager = RPCManager(self)
self.persistence = None
self.exchange = Exchange(self.config)
@ -363,12 +361,6 @@ class FreqtradeBot(object):
order_id = self.exchange.buy(pair, buy_limit, amount)['id']
stake_amount_fiat = self.fiat_converter.convert_amount(
stake_amount,
stake_currency,
fiat_currency
)
self.rpc.send_msg({
'type': RPCMessageType.BUY_NOTIFICATION,
'exchange': self.exchange.name.capitalize(),
@ -376,7 +368,6 @@ class FreqtradeBot(object):
'market_url': pair_url,
'limit': buy_limit,
'stake_amount': stake_amount,
'stake_amount_fiat': stake_amount_fiat,
'stake_currency': stake_currency,
'fiat_currency': fiat_currency
})
@ -643,14 +634,7 @@ class FreqtradeBot(object):
if 'stake_currency' in self.config and 'fiat_display_currency' in self.config:
stake_currency = self.config['stake_currency']
fiat_currency = self.config['fiat_display_currency']
fiat_converter = CryptoToFiatConverter()
profit_fiat = fiat_converter.convert_amount(
profit_trade,
stake_currency,
fiat_currency,
)
msg.update({
'profit_fiat': profit_fiat,
'stake_currency': stake_currency,
'fiat_currency': fiat_currency,
})

View File

@ -12,6 +12,7 @@ from telegram.error import NetworkError, TelegramError
from telegram.ext import CommandHandler, Updater
from freqtrade.__init__ import __version__
from freqtrade.fiat_convert import CryptoToFiatConverter
from freqtrade.rpc import RPC, RPCException, RPCMessageType
logger = logging.getLogger(__name__)
@ -66,6 +67,7 @@ class Telegram(RPC):
self._updater: Updater = None
self._config = freqtrade.config
self._init()
self._fiat_converter = CryptoToFiatConverter()
def _init(self) -> None:
"""
@ -114,6 +116,9 @@ class Telegram(RPC):
""" Send a message to telegram channel """
if msg['type'] == RPCMessageType.BUY_NOTIFICATION:
msg['stake_amount_fiat'] = self._fiat_converter.convert_amount(
msg['stake_amount'], msg['stake_currency'], msg['fiat_currency'])
message = "*{exchange}:* Buying [{pair}]({market_url})\n" \
"with limit `{limit:.8f}\n" \
"({stake_amount:.6f} {stake_currency}," \
@ -135,6 +140,8 @@ class Telegram(RPC):
# This might not be the case if the message origin is triggered by /forcesell
if all(prop in msg for prop in ['gain', 'profit_fiat',
'fiat_currency', 'stake_currency']):
msg['profit_fiat'] = self._fiat_converter.convert_amount(
msg['profit_amount'], msg['stake_currency'], msg['fiat_currency'])
message += '` ({gain}: {profit_amount:.8f} {stake_currency}`' \
'` / {profit_fiat:.3f} {fiat_currency})`'.format(**msg)

View File

@ -62,7 +62,6 @@ def test_main_fatal_exception(mocker, default_conf, caplog) -> None:
'freqtrade.configuration.Configuration._load_config_file',
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
args = ['-c', 'config.json.example']
@ -90,7 +89,6 @@ def test_main_keyboard_interrupt(mocker, default_conf, caplog) -> None:
'freqtrade.configuration.Configuration._load_config_file',
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
args = ['-c', 'config.json.example']
@ -118,7 +116,6 @@ def test_main_operational_exception(mocker, default_conf, caplog) -> None:
'freqtrade.configuration.Configuration._load_config_file',
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
args = ['-c', 'config.json.example']
@ -146,7 +143,6 @@ def test_main_reload_conf(mocker, default_conf, caplog) -> None:
'freqtrade.configuration.Configuration._load_config_file',
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
# Raise exception as side effect to avoid endless loop
@ -174,7 +170,6 @@ def test_reconfigure(mocker, default_conf) -> None:
'freqtrade.configuration.Configuration._load_config_file',
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
freqtrade = FreqtradeBot(default_conf)