Skip to content

Commit

Permalink
notify_buy -> notify_enter, notify_sell -> notify_exit
Browse files Browse the repository at this point in the history
  • Loading branch information
samgermain committed Sep 8, 2021
1 parent e1f846f commit 362dc20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions freqtrade/freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ def execute_entry(self, pair: str, stake_amount: float, price: Optional[float] =
# Updating wallets
self.wallets.update()

self._notify_buy(trade, order_type)
self._notify_enter(trade, order_type)

return True

def _notify_buy(self, trade: Trade, order_type: str) -> None:
def _notify_enter(self, trade: Trade, order_type: str) -> None:
"""
Sends rpc notification when a buy occurred.
"""
Expand All @@ -617,7 +617,7 @@ def _notify_buy(self, trade: Trade, order_type: str) -> None:
# Send the message
self.rpc.send_msg(msg)

def _notify_buy_cancel(self, trade: Trade, order_type: str, reason: str) -> None:
def _notify_enter_cancel(self, trade: Trade, order_type: str, reason: str) -> None:
"""
Sends rpc notification when a buy cancel occurred.
"""
Expand All @@ -643,7 +643,7 @@ def _notify_buy_cancel(self, trade: Trade, order_type: str, reason: str) -> None
# Send the message
self.rpc.send_msg(msg)

def _notify_buy_fill(self, trade: Trade) -> None:
def _notify_enter_fill(self, trade: Trade) -> None:
msg = {
'trade_id': trade.id,
'type': RPCMessageType.BUY_FILL,
Expand Down Expand Up @@ -782,7 +782,7 @@ def handle_stoploss_on_exchange(self, trade: Trade) -> bool:
# Lock pair for one candle to prevent immediate rebuys
self.strategy.lock_pair(trade.pair, datetime.now(timezone.utc),
reason='Auto lock')
self._notify_sell(trade, "stoploss")
self._notify_exit(trade, "stoploss")
return True

if trade.open_order_id or not trade.is_open:
Expand Down Expand Up @@ -994,8 +994,8 @@ def handle_cancel_enter(self, trade: Trade, order: Dict, reason: str) -> bool:
reason += f", {constants.CANCEL_REASON['PARTIALLY_FILLED']}"

self.wallets.update()
self._notify_buy_cancel(trade, order_type=self.strategy.order_types['buy'],
reason=reason)
self._notify_enter_cancel(trade, order_type=self.strategy.order_types['buy'],
reason=reason)
return was_trade_fully_canceled

def handle_cancel_exit(self, trade: Trade, order: Dict, reason: str) -> str:
Expand Down Expand Up @@ -1032,7 +1032,7 @@ def handle_cancel_exit(self, trade: Trade, order: Dict, reason: str) -> str:
reason = constants.CANCEL_REASON['PARTIALLY_FILLED_KEEP_OPEN']

self.wallets.update()
self._notify_sell_cancel(
self._notify_exit_cancel(
trade,
order_type=self.strategy.order_types['sell'],
reason=reason
Expand Down Expand Up @@ -1150,11 +1150,11 @@ def execute_trade_exit(self, trade: Trade, limit: float, sell_reason: SellCheckT
self.strategy.lock_pair(trade.pair, datetime.now(timezone.utc),
reason='Auto lock')

self._notify_sell(trade, order_type)
self._notify_exit(trade, order_type)

return True

def _notify_sell(self, trade: Trade, order_type: str, fill: bool = False) -> None:
def _notify_exit(self, trade: Trade, order_type: str, fill: bool = False) -> None:
"""
Sends rpc notification when a sell occurred.
"""
Expand Down Expand Up @@ -1196,7 +1196,7 @@ def _notify_sell(self, trade: Trade, order_type: str, fill: bool = False) -> Non
# Send the message
self.rpc.send_msg(msg)

def _notify_sell_cancel(self, trade: Trade, order_type: str, reason: str) -> None:
def _notify_exit_cancel(self, trade: Trade, order_type: str, reason: str) -> None:
"""
Sends rpc notification when a sell cancel occurred.
"""
Expand Down Expand Up @@ -1291,13 +1291,13 @@ def update_trade_state(self, trade: Trade, order_id: str, action_order: Dict[str
# Updating wallets when order is closed
if not trade.is_open:
if not stoploss_order and not trade.open_order_id:
self._notify_sell(trade, '', True)
self._notify_exit(trade, '', True)
self.protections.stop_per_pair(trade.pair)
self.protections.global_stop()
self.wallets.update()
elif not trade.open_order_id:
# Buy fill
self._notify_buy_fill(trade)
self._notify_enter_fill(trade)

return False

Expand Down
6 changes: 3 additions & 3 deletions tests/test_freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,7 @@ def test_handle_cancel_enter(mocker, caplog, default_conf, limit_buy_order) -> N
mocker.patch('freqtrade.exchange.Exchange.cancel_order_with_result', cancel_order_mock)

freqtrade = FreqtradeBot(default_conf)
freqtrade._notify_buy_cancel = MagicMock()
freqtrade._notify_enter_cancel = MagicMock()

trade = MagicMock()
trade.pair = 'LTC/USDT'
Expand Down Expand Up @@ -2526,7 +2526,7 @@ def test_handle_cancel_enter_exchanges(mocker, caplog, default_conf,
cancel_order_mock = mocker.patch(
'freqtrade.exchange.Exchange.cancel_order_with_result',
return_value=limit_buy_order_canceled_empty)
nofiy_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot._notify_buy_cancel')
nofiy_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot._notify_enter_cancel')
freqtrade = FreqtradeBot(default_conf)

reason = CANCEL_REASON['TIMEOUT']
Expand Down Expand Up @@ -2555,7 +2555,7 @@ def test_handle_cancel_enter_corder_empty(mocker, default_conf, limit_buy_order,
)

freqtrade = FreqtradeBot(default_conf)
freqtrade._notify_buy_cancel = MagicMock()
freqtrade._notify_enter_cancel = MagicMock()

trade = MagicMock()
trade.pair = 'LTC/USDT'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_may_execute_exit_stoploss_on_exchange_multi(default_conf, ticker, fee,
mocker.patch.multiple(
'freqtrade.freqtradebot.FreqtradeBot',
create_stoploss_order=MagicMock(return_value=True),
_notify_sell=MagicMock(),
_notify_exit=MagicMock(),
)
mocker.patch("freqtrade.strategy.interface.IStrategy.should_sell", should_sell_mock)
wallets_mock = mocker.patch("freqtrade.wallets.Wallets.update", MagicMock())
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_forcebuy_last_unlimited(default_conf, ticker, fee, limit_buy_order, moc
mocker.patch.multiple(
'freqtrade.freqtradebot.FreqtradeBot',
create_stoploss_order=MagicMock(return_value=True),
_notify_sell=MagicMock(),
_notify_exit=MagicMock(),
)
should_sell_mock = MagicMock(side_effect=[
SellCheckTuple(sell_type=SellType.NONE),
Expand Down

0 comments on commit 362dc20

Please sign in to comment.