Add stoploss tests for kucoin

This commit is contained in:
Matthias
2022-02-24 07:08:15 +01:00
parent 020729cf50
commit 0749199097
3 changed files with 124 additions and 4 deletions

View File

@@ -836,6 +836,7 @@ class Exchange:
if stop_price_norm <= rate:
raise OperationalException(
'In stoploss limit order, stop price should be more than limit price')
rate = self.price_to_precision(pair, rate)
if self._config['dry_run']:
# TODO: will this work if ordertype is limit??
@@ -848,8 +849,6 @@ class Exchange:
amount = self.amount_to_precision(pair, amount)
rate = self.price_to_precision(pair, rate)
order = self._api.create_order(symbol=pair, type=ordertype, side='sell',
amount=amount, price=rate, params=params)
logger.info(f"stoploss {user_order_type} order added for {pair}. "
@@ -872,7 +871,8 @@ class Exchange:
raise DDosProtection(e) from e
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
raise TemporaryError(
f'Could not place stoploss order due to {e.__class__.__name__}. Message: {e}') from e
f"Could not place stoploss order due to {e.__class__.__name__}. "
f"Message: {e}") from e
except ccxt.BaseError as e:
raise OperationalException(e) from e

View File

@@ -33,7 +33,7 @@ class Kucoin(Exchange):
Returns True if adjustment is necessary.
"""
# TODO: since kucoin uses Limit orders, changes to models will be required.
return order['info']['stop'] is not None and stop_loss > float(order['stopPrice'])
return order['info'].get('stop') is not None and stop_loss > float(order['stopPrice'])
def _get_stop_params(self, ordertype: str, stop_price: float) -> Dict: