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` * `trade_id`
* `exchange` * `exchange`
* `pair` * `pair`
* `limit` * ~~`limit` # Deprecated - should no longer be used.~~
* `open_rate`
* `amount` * `amount`
* `open_date` * `open_date`
* `stake_amount` * `stake_amount`
@ -146,6 +147,8 @@ Possible parameters are:
* `stake_amount` * `stake_amount`
* `stake_currency` * `stake_currency`
* `fiat_currency` * `fiat_currency`
* `order_type`
* `current_rate`
* `buy_tag` * `buy_tag`
### Webhooksell ### Webhooksell

View File

@ -592,17 +592,19 @@ class FreqtradeBot(LoggingMixin):
return True 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. Sends rpc notification when a buy occurred.
""" """
msg = { msg = {
'trade_id': trade.id, 'trade_id': trade.id,
'type': RPCMessageType.BUY, 'type': RPCMessageType.BUY_FILL if fill else RPCMessageType.BUY,
'buy_tag': trade.buy_tag, 'buy_tag': trade.buy_tag,
'exchange': self.exchange.name.capitalize(), 'exchange': self.exchange.name.capitalize(),
'pair': trade.pair, 'pair': trade.pair,
'limit': trade.open_rate, 'limit': trade.open_rate, # Deprecated (?)
'open_rate': trade.open_rate,
'order_type': order_type, 'order_type': order_type,
'stake_amount': trade.stake_amount, 'stake_amount': trade.stake_amount,
'stake_currency': self.config['stake_currency'], 'stake_currency': self.config['stake_currency'],
@ -641,22 +643,6 @@ class FreqtradeBot(LoggingMixin):
# Send the message # Send the message
self.rpc.send_msg(msg) 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 # SELL / exit positions / close trades logic and methods
# #
@ -1312,7 +1298,7 @@ class FreqtradeBot(LoggingMixin):
self.wallets.update() self.wallets.update()
elif not trade.open_order_id: elif not trade.open_order_id:
# Buy fill # Buy fill
self._notify_enter_fill(trade) self._notify_enter(trade, fill=True)
return False return False

View File

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