Make stoploss method more flexible
This commit is contained in:
parent
ea197b79ca
commit
7ba92086c9
@ -823,27 +823,28 @@ class Exchange:
|
|||||||
else:
|
else:
|
||||||
# Otherwise pick only one available
|
# Otherwise pick only one available
|
||||||
ordertype = list(self._ft_has["stoploss_order_types"].values())[0]
|
ordertype = list(self._ft_has["stoploss_order_types"].values())[0]
|
||||||
|
user_order_type = list(self._ft_has["stoploss_order_types"].keys())[0]
|
||||||
|
|
||||||
# if user_order_type == 'limit':
|
stop_price_norm = self.price_to_precision(pair, stop_price)
|
||||||
|
rate = None
|
||||||
|
if user_order_type == 'limit':
|
||||||
# Limit price threshold: As limit price should always be below stop-price
|
# Limit price threshold: As limit price should always be below stop-price
|
||||||
limit_price_pct = order_types.get('stoploss_on_exchange_limit_ratio', 0.99)
|
limit_price_pct = order_types.get('stoploss_on_exchange_limit_ratio', 0.99)
|
||||||
rate = stop_price * limit_price_pct
|
rate = stop_price * limit_price_pct
|
||||||
|
|
||||||
stop_price = self.price_to_precision(pair, stop_price)
|
|
||||||
|
|
||||||
# Ensure rate is less than stop price
|
# Ensure rate is less than stop price
|
||||||
if stop_price <= rate:
|
if stop_price_norm <= rate:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
'In stoploss limit order, stop price should be more than limit price')
|
'In stoploss limit order, stop price should be more than limit price')
|
||||||
|
|
||||||
if self._config['dry_run']:
|
if self._config['dry_run']:
|
||||||
# TODO: will this work if ordertype is limit??
|
# TODO: will this work if ordertype is limit??
|
||||||
dry_order = self.create_dry_run_order(
|
dry_order = self.create_dry_run_order(
|
||||||
pair, ordertype, "sell", amount, stop_price)
|
pair, ordertype, "sell", amount, stop_price_norm)
|
||||||
return dry_order
|
return dry_order
|
||||||
|
|
||||||
try:
|
try:
|
||||||
params = self._get_stop_params(ordertype=ordertype, stop_price=stop_price)
|
params = self._get_stop_params(ordertype=ordertype, stop_price=stop_price_norm)
|
||||||
|
|
||||||
amount = self.amount_to_precision(pair, amount)
|
amount = self.amount_to_precision(pair, amount)
|
||||||
|
|
||||||
@ -851,7 +852,7 @@ class Exchange:
|
|||||||
|
|
||||||
order = self._api.create_order(symbol=pair, type=ordertype, side='sell',
|
order = self._api.create_order(symbol=pair, type=ordertype, side='sell',
|
||||||
amount=amount, price=rate, params=params)
|
amount=amount, price=rate, params=params)
|
||||||
logger.info(f"stoploss limit order added for {pair}. "
|
logger.info(f"stoploss {user_order_type} order added for {pair}. "
|
||||||
f"stop price: {stop_price}. limit: {rate}")
|
f"stop price: {stop_price}. limit: {rate}")
|
||||||
self._log_exchange_response('create_stoploss_order', order)
|
self._log_exchange_response('create_stoploss_order', order)
|
||||||
return order
|
return order
|
||||||
@ -871,7 +872,7 @@ class Exchange:
|
|||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
raise TemporaryError(
|
raise TemporaryError(
|
||||||
f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') from e
|
f'Could not place stoploss order due to {e.__class__.__name__}. Message: {e}') from e
|
||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
@ -900,7 +900,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_trailing_stoploss_on_exchange(self, trade: Trade, order: dict) -> None:
|
def handle_trailing_stoploss_on_exchange(self, trade: Trade, order: Dict) -> None:
|
||||||
"""
|
"""
|
||||||
Check to see if stoploss on exchange should be updated
|
Check to see if stoploss on exchange should be updated
|
||||||
in case of trailing stoploss on exchange
|
in case of trailing stoploss on exchange
|
||||||
|
Loading…
Reference in New Issue
Block a user