comparing with stopPrice instead of price

This commit is contained in:
misagh 2019-01-08 13:44:51 +01:00
parent 4fbb9d4462
commit aed855284c

View File

@ -613,7 +613,7 @@ class FreqtradeBot(object):
def handle_stoploss_on_exchange(self, trade: Trade) -> bool: def handle_stoploss_on_exchange(self, trade: Trade) -> bool:
""" """
Check if trade is fulfilled in which case the stoploss Check if trade is fulfilled in which case the stoploss
on exchange should be added immediately if stoploss on exchnage on exchange should be added immediately if stoploss on exchange
is enabled. is enabled.
""" """
@ -630,13 +630,14 @@ class FreqtradeBot(object):
stop_price = trade.open_rate * (1 + stoploss) stop_price = trade.open_rate * (1 + stoploss)
# limit price should be less than stop price. # limit price should be less than stop price.
# 0.98 is arbitrary here. # 0.99 is arbitrary here.
limit_price = stop_price * 0.98 limit_price = stop_price * 0.99
stoploss_order_id = self.exchange.stoploss_limit( stoploss_order_id = self.exchange.stoploss_limit(
pair=trade.pair, amount=trade.amount, stop_price=stop_price, rate=limit_price pair=trade.pair, amount=trade.amount, stop_price=stop_price, rate=limit_price
)['id'] )['id']
trade.stoploss_order_id = str(stoploss_order_id) trade.stoploss_order_id = str(stoploss_order_id)
trade.stoploss_last_update = datetime.now()
# Or the trade open and there is already a stoploss on exchange. # Or the trade open and there is already a stoploss on exchange.
# so we check if it is hit ... # so we check if it is hit ...
@ -647,12 +648,17 @@ class FreqtradeBot(object):
trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value
trade.update(order) trade.update(order)
result = True result = True
else: elif self.config.get('trailing_stop', False):
# check if trailing stoploss is enabled and stoploss value has changed # check if trailing stoploss is enabled and stoploss value has changed
# in which case we cancel stoploss order and put another one with new # in which case we cancel stoploss order and put another one with new
# value immediately # value immediately
if self.config.get('trailing_stop', False) and trade.stop_loss > order['price']: if trade.stop_loss > order['info']['stopPrice']:
# we check also if the update is neccesary
update_beat = self.strategy.order_types['stoploss_on_exchange_interval']
if (datetime.now() - trade.stoploss_last_update).total_seconds > update_beat:
# cancelling the current stoploss on exchange first
if self.exchange.cancel_order(order['id'], trade.pair): if self.exchange.cancel_order(order['id'], trade.pair):
# creating the new one
stoploss_order_id = self.exchange.stoploss_limit( stoploss_order_id = self.exchange.stoploss_limit(
pair=trade.pair, amount=trade.amount, pair=trade.pair, amount=trade.amount,
stop_price=stop_price, rate=limit_price stop_price=stop_price, rate=limit_price