From 6b948cfc7eed65da52c24037ff4e12db04849e8a Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 12 Mar 2019 22:01:19 +0100 Subject: [PATCH] Don't move notify_sell to rpc_manager - it needs exchange stuff --- freqtrade/freqtradebot.py | 39 ++++++++++++++++++++++++++++++++++-- freqtrade/rpc/rpc_manager.py | 33 ------------------------------ 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 58888a4f8..f6662e062 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -658,7 +658,7 @@ class FreqtradeBot(object): if order['status'] == 'closed': trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value trade.update(order) - self.rpc.notify_sell(trade, self.config, trade.close_rate) + self.notify_sell(trade) result = True elif self.config.get('trailing_stop', False): # if trailing stoploss is enabled we check if stoploss value has changed @@ -849,4 +849,39 @@ class FreqtradeBot(object): trade.close_rate_requested = limit trade.sell_reason = sell_reason.value Trade.session.flush() - self.rpc.notify_sell(trade, self.config, self.exchange.get_ticker(trade.pair)['bid']) + self.notify_sell(trade) + + def notify_sell(self, trade: Trade): + """ + Sends rpc notification when a sell occured. + """ + profit_trade = trade.calc_profit(rate=trade.close_rate_requested) + current_rate = self.exchange.get_ticker(trade.pair)['bid'] + profit_percent = trade.calc_profit_percent(trade.close_rate_requested) + gain = "profit" if profit_percent > 0 else "loss" + + msg = { + 'type': RPCMessageType.SELL_NOTIFICATION, + 'exchange': trade.exchange.capitalize(), + 'pair': trade.pair, + 'gain': gain, + 'limit': trade.close_rate_requested, + 'amount': trade.amount, + 'open_rate': trade.open_rate, + 'current_rate': current_rate, + 'profit_amount': profit_trade, + 'profit_percent': profit_percent, + 'sell_reason': trade.sell_reason + } + + # For regular case, when the configuration exists + 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'] + msg.update({ + 'stake_currency': stake_currency, + 'fiat_currency': fiat_currency, + }) + + # Send the message + self.rpc.send_msg(msg) diff --git a/freqtrade/rpc/rpc_manager.py b/freqtrade/rpc/rpc_manager.py index 7a3971356..7f0d0a5d4 100644 --- a/freqtrade/rpc/rpc_manager.py +++ b/freqtrade/rpc/rpc_manager.py @@ -4,7 +4,6 @@ This module contains class to manage RPC communications (Telegram, Slack, ...) import logging from typing import Any, Dict, List -from freqtrade.persistence import Trade from freqtrade.rpc import RPC, RPCMessageType logger = logging.getLogger(__name__) @@ -81,35 +80,3 @@ class RPCManager(object): 'status': f'Searching for {stake_currency} pairs to buy and sell ' f'based on {pairlist.short_desc()}' }) - - def notify_sell(self, trade: Trade, config, current_rate: float): - profit_trade = trade.calc_profit(rate=trade.close_rate_requested) - - profit_percent = trade.calc_profit_percent(trade.close_rate_requested) - gain = "profit" if profit_percent > 0 else "loss" - - msg = { - 'type': RPCMessageType.SELL_NOTIFICATION, - 'exchange': trade.exchange.capitalize(), - 'pair': trade.pair, - 'gain': gain, - 'limit': trade.close_rate_requested, - 'amount': trade.amount, - 'open_rate': trade.open_rate, - 'current_rate': current_rate, - 'profit_amount': profit_trade, - 'profit_percent': profit_percent, - 'sell_reason': trade.sell_reason - } - - # For regular case, when the configuration exists - if 'stake_currency' in config and 'fiat_display_currency' in config: - stake_currency = config['stake_currency'] - fiat_currency = config['fiat_display_currency'] - msg.update({ - 'stake_currency': stake_currency, - 'fiat_currency': fiat_currency, - }) - - # Send the message - self.send_msg(msg)