Skip to content

Commit

Permalink
move exceptionhandling from create_order() to calling functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Aug 25, 2019
1 parent 95920f3 commit 8a17615
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions freqtrade/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def validate_ordertypes(self, order_types: Dict) -> None:
if (order_types.get("stoploss_on_exchange")
and not self._ft_has.get("stoploss_on_exchange", False)):
raise OperationalException(
'On exchange stoploss is not supported for %s.' % self.name
f'On exchange stoploss is not supported for {self.name}.'
)

def validate_order_time_in_force(self, order_time_in_force: Dict) -> None:
Expand Down Expand Up @@ -469,11 +469,26 @@ def stoploss_limit(self, pair: str, amount: float, stop_price: float, rate: floa

params = self._params.copy()
params.update({'stopPrice': stop_price})

order = self.create_order(pair, ordertype, 'sell', amount, rate, params)
logger.info('stoploss limit order added for %s. '
'stop price: %s. limit: %s', pair, stop_price, rate)
return order
try:
order = self.create_order(pair, ordertype, 'sell', amount, rate, params)
logger.info('stoploss limit order added for %s. '
'stop price: %s. limit: %s', pair, stop_price, rate)
return order
except ccxt.InsufficientFunds as e:
raise DependencyException(
f'Insufficient funds to create {ordertype} sell order on market {pair}.'
f'Tried to sell amount {amount} at rate {rate}.'
f'Message: {e}') from e
except ccxt.InvalidOrder as e:
raise DependencyException(
f'Could not create {ordertype} sell order on market {pair}. '
f'Tried to sell amount {amount} at rate {rate}.'
f'Message: {e}') from e
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
raise TemporaryError(
f'Could not place sell order due to {e.__class__.__name__}. Message: {e}') from e
except ccxt.BaseError as e:
raise OperationalException(e) from e

@retrier
def get_balance(self, currency: str) -> float:
Expand Down

0 comments on commit 8a17615

Please sign in to comment.