Reduce code complexity by combining buy and buy_fill methods

This commit is contained in:
Matthias 2021-11-30 19:45:20 +01:00
parent f0abe218a2
commit 542963c7a6
3 changed files with 11 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -86,4 +86,5 @@ markdown_extensions:
alternate_style: true
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tilde
- mdx_truly_sane_lists