From 542963c7a60e699c1ebd0602ecd4b5be7a86f6a7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 30 Nov 2021 19:45:20 +0100 Subject: [PATCH] Reduce code complexity by combining buy and buy_fill methods --- docs/webhook-config.md | 5 ++++- freqtrade/freqtradebot.py | 26 ++++++-------------------- mkdocs.yml | 1 + 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/docs/webhook-config.md b/docs/webhook-config.md index bea555385..40915c988 100644 --- a/docs/webhook-config.md +++ b/docs/webhook-config.md @@ -104,7 +104,8 @@ Possible parameters are: * `trade_id` * `exchange` * `pair` -* `limit` +* ~~`limit` # Deprecated - should no longer be used.~~ +* `open_rate` * `amount` * `open_date` * `stake_amount` @@ -146,6 +147,8 @@ Possible parameters are: * `stake_amount` * `stake_currency` * `fiat_currency` +* `order_type` +* `current_rate` * `buy_tag` ### Webhooksell diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index a6d1b36b9..32f08c178 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -592,17 +592,19 @@ class FreqtradeBot(LoggingMixin): return True - def _notify_enter(self, trade: Trade, order_type: str) -> None: + def _notify_enter(self, trade: Trade, order_type: Optional[str] = None, + fill: bool = False) -> None: """ Sends rpc notification when a buy occurred. """ msg = { 'trade_id': trade.id, - 'type': RPCMessageType.BUY, + 'type': RPCMessageType.BUY_FILL if fill else RPCMessageType.BUY, 'buy_tag': trade.buy_tag, 'exchange': self.exchange.name.capitalize(), 'pair': trade.pair, - 'limit': trade.open_rate, + 'limit': trade.open_rate, # Deprecated (?) + 'open_rate': trade.open_rate, 'order_type': order_type, 'stake_amount': trade.stake_amount, 'stake_currency': self.config['stake_currency'], @@ -641,22 +643,6 @@ class FreqtradeBot(LoggingMixin): # Send the message self.rpc.send_msg(msg) - def _notify_enter_fill(self, trade: Trade) -> None: - msg = { - 'trade_id': trade.id, - 'type': RPCMessageType.BUY_FILL, - 'buy_tag': trade.buy_tag, - 'exchange': self.exchange.name.capitalize(), - 'pair': trade.pair, - 'open_rate': trade.open_rate, - 'stake_amount': trade.stake_amount, - 'stake_currency': self.config['stake_currency'], - 'fiat_currency': self.config.get('fiat_display_currency', None), - 'amount': trade.amount, - 'open_date': trade.open_date, - } - self.rpc.send_msg(msg) - # # SELL / exit positions / close trades logic and methods # @@ -1312,7 +1298,7 @@ class FreqtradeBot(LoggingMixin): self.wallets.update() elif not trade.open_order_id: # Buy fill - self._notify_enter_fill(trade) + self._notify_enter(trade, fill=True) return False diff --git a/mkdocs.yml b/mkdocs.yml index 9eebd75e3..fb1b80ebf 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -86,4 +86,5 @@ markdown_extensions: alternate_style: true - pymdownx.tasklist: custom_checkbox: true + - pymdownx.tilde - mdx_truly_sane_lists