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,9 +666,30 @@ 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
|
||||||
|
|
||||||
|
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)
|
||||||
|
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)
|
logger.debug('Handling stoploss on exchange %s ...', trade)
|
||||||
order = self.exchange.get_order(trade.stoploss_order_id, trade.pair)
|
order = self.exchange.get_order(trade.stoploss_order_id, trade.pair)
|
||||||
if order['status'] == 'closed':
|
if order['status'] == 'closed':
|
||||||
@ -705,6 +699,7 @@ class FreqtradeBot(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
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