Introduce forcebuy ordertype to allow specifiying a different ordertype for forcebuy / forcesells

This commit is contained in:
Matthias
2021-03-05 20:22:04 +01:00
parent 5196306407
commit a405d578da
6 changed files with 18 additions and 4 deletions

View File

@@ -179,6 +179,8 @@ CONF_SCHEMA = {
'properties': {
'buy': {'type': 'string', 'enum': ORDERTYPE_POSSIBILITIES},
'sell': {'type': 'string', 'enum': ORDERTYPE_POSSIBILITIES},
'forcesell': {'type': 'string', 'enum': ORDERTYPE_POSSIBILITIES},
'forcebuy': {'type': 'string', 'enum': ORDERTYPE_POSSIBILITIES},
'emergencysell': {'type': 'string', 'enum': ORDERTYPE_POSSIBILITIES},
'stoploss': {'type': 'string', 'enum': ORDERTYPE_POSSIBILITIES},
'stoploss_on_exchange': {'type': 'boolean'},

View File

@@ -520,7 +520,8 @@ class FreqtradeBot(LoggingMixin):
logger.info(f"Bids to asks delta for {pair} does not satisfy condition.")
return False
def execute_buy(self, pair: str, stake_amount: float, price: Optional[float] = None) -> bool:
def execute_buy(self, pair: str, stake_amount: float, price: Optional[float] = None,
forcebuy: bool = False) -> bool:
"""
Executes a limit buy for the given pair
:param pair: pair for which we want to create a LIMIT_BUY
@@ -548,6 +549,10 @@ class FreqtradeBot(LoggingMixin):
amount = stake_amount / buy_limit_requested
order_type = self.strategy.order_types['buy']
if forcebuy:
# Forcebuy can define a different ordertype
order_type = self.strategy.order_types.get('forcebuy', order_type)
if not strategy_safe_wrapper(self.strategy.confirm_trade_entry, default_retval=True)(
pair=pair, order_type=order_type, amount=amount, rate=buy_limit_requested,
time_in_force=time_in_force):

View File

@@ -593,7 +593,7 @@ class RPC:
pair, self._freqtrade.get_free_open_trades())
# execute buy
if self._freqtrade.execute_buy(pair, stakeamount, price):
if self._freqtrade.execute_buy(pair, stakeamount, price, forcebuy=True):
trade = Trade.get_trades([Trade.is_open.is_(True), Trade.pair == pair]).first()
return trade
else: