the complex in the life of flake8 resolved
This commit is contained in:
parent
9144a8f79d
commit
1c2c19b12c
@ -555,35 +555,8 @@ class FreqtradeBot(object):
|
|||||||
|
|
||||||
trade.update(order)
|
trade.update(order)
|
||||||
|
|
||||||
# Check uf trade is fulfulled in which case the stoploss
|
if self.strategy.stoploss_on_exchange:
|
||||||
# on exchange should be added immediately if stoploss on exchnage
|
|
||||||
# is on
|
|
||||||
if self.strategy.stoploss_on_exchange and trade.is_open and \
|
|
||||||
trade.open_order_id is None and trade.stoploss_order_id is None:
|
|
||||||
|
|
||||||
if self.edge:
|
|
||||||
stoploss = self.edge.stoploss(pair=trade.pair)
|
|
||||||
else:
|
|
||||||
stoploss = self.strategy.stoploss
|
|
||||||
|
|
||||||
stop_price = trade.open_rate * (1 + stoploss)
|
|
||||||
|
|
||||||
# limit price should be less than stop price.
|
|
||||||
# 0.98 is arbitrary here.
|
|
||||||
limit_price = stop_price * 0.98
|
|
||||||
|
|
||||||
stoploss_order_id = self.exchange.stoploss_limit(
|
|
||||||
pair=trade.pair, amount=trade.amount, stop_price=stop_price, rate=limit_price
|
|
||||||
)['id']
|
|
||||||
|
|
||||||
trade.stoploss_order_id = str(stoploss_order_id)
|
|
||||||
|
|
||||||
# Or Check if there is a stoploss on exchnage and it is hit
|
|
||||||
elif self.strategy.stoploss_on_exchange and trade.stoploss_order_id:
|
|
||||||
# Check if stoploss is hit
|
|
||||||
result = self.handle_stoploss_on_exchage(trade)
|
result = self.handle_stoploss_on_exchage(trade)
|
||||||
|
|
||||||
# Updating wallets if stoploss is hit
|
|
||||||
if result:
|
if result:
|
||||||
self.wallets.update()
|
self.wallets.update()
|
||||||
return result
|
return result
|
||||||
@ -693,18 +666,40 @@ class FreqtradeBot(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_stoploss_on_exchage(self, trade: Trade) -> bool:
|
def handle_stoploss_on_exchage(self, trade: Trade) -> bool:
|
||||||
if not trade.is_open:
|
# Check uf trade is fulfulled in which case the stoploss
|
||||||
raise ValueError(f'attempt to handle stoploss on exchnage for a closed trade: {trade}')
|
# on exchange should be added immediately if stoploss on exchnage
|
||||||
|
# is on
|
||||||
|
if trade.is_open and trade.open_order_id is None and trade.stoploss_order_id is None:
|
||||||
|
if self.edge:
|
||||||
|
stoploss = self.edge.stoploss(pair=trade.pair)
|
||||||
|
else:
|
||||||
|
stoploss = self.strategy.stoploss
|
||||||
|
|
||||||
logger.debug('Handling stoploss on exchange %s ...', trade)
|
stop_price = trade.open_rate * (1 + stoploss)
|
||||||
order = self.exchange.get_order(trade.stoploss_order_id, trade.pair)
|
|
||||||
if order['status'] == 'closed':
|
# limit price should be less than stop price.
|
||||||
trade.sell_reason = SellType.STOPLOSS_ON_EXCHNAGE.value
|
# 0.98 is arbitrary here.
|
||||||
trade.update(order)
|
limit_price = stop_price * 0.98
|
||||||
return True
|
|
||||||
else:
|
stoploss_order_id = self.exchange.stoploss_limit(
|
||||||
|
pair=trade.pair, amount=trade.amount, stop_price=stop_price, rate=limit_price
|
||||||
|
)['id']
|
||||||
|
|
||||||
|
trade.stoploss_order_id = str(stoploss_order_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Or Check if there is a stoploss on exchnage and it is hit
|
||||||
|
elif trade.stoploss_order_id:
|
||||||
|
logger.debug('Handling stoploss on exchange %s ...', trade)
|
||||||
|
order = self.exchange.get_order(trade.stoploss_order_id, trade.pair)
|
||||||
|
if order['status'] == 'closed':
|
||||||
|
trade.sell_reason = SellType.STOPLOSS_ON_EXCHNAGE.value
|
||||||
|
trade.update(order)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def check_sell(self, trade: Trade, sell_rate: float, buy: bool, sell: bool) -> bool:
|
def check_sell(self, trade: Trade, sell_rate: float, buy: bool, sell: bool) -> bool:
|
||||||
if self.edge:
|
if self.edge:
|
||||||
stoploss = self.edge.stoploss(trade.pair)
|
stoploss = self.edge.stoploss(trade.pair)
|
||||||
|
Loading…
Reference in New Issue
Block a user