Don't move notify_sell to rpc_manager - it needs exchange stuff
This commit is contained in:
parent
9054165e8a
commit
6b948cfc7e
@ -658,7 +658,7 @@ class FreqtradeBot(object):
|
|||||||
if order['status'] == 'closed':
|
if order['status'] == 'closed':
|
||||||
trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value
|
trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value
|
||||||
trade.update(order)
|
trade.update(order)
|
||||||
self.rpc.notify_sell(trade, self.config, trade.close_rate)
|
self.notify_sell(trade)
|
||||||
result = True
|
result = True
|
||||||
elif self.config.get('trailing_stop', False):
|
elif self.config.get('trailing_stop', False):
|
||||||
# if trailing stoploss is enabled we check if stoploss value has changed
|
# 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.close_rate_requested = limit
|
||||||
trade.sell_reason = sell_reason.value
|
trade.sell_reason = sell_reason.value
|
||||||
Trade.session.flush()
|
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)
|
||||||
|
@ -4,7 +4,6 @@ This module contains class to manage RPC communications (Telegram, Slack, ...)
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
from freqtrade.persistence import Trade
|
|
||||||
from freqtrade.rpc import RPC, RPCMessageType
|
from freqtrade.rpc import RPC, RPCMessageType
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -81,35 +80,3 @@ class RPCManager(object):
|
|||||||
'status': f'Searching for {stake_currency} pairs to buy and sell '
|
'status': f'Searching for {stake_currency} pairs to buy and sell '
|
||||||
f'based on {pairlist.short_desc()}'
|
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)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user