simplify sell conditions

This commit is contained in:
Janne Sinivirta 2017-09-25 15:17:29 +03:00
parent f3ccca1c66
commit 877dd6d3fa

12
main.py
View File

@ -117,11 +117,11 @@ def handle_trade(trade: Trade) -> None:
raise ValueError('attempt to handle closed trade: {}'.format(trade)) raise ValueError('attempt to handle closed trade: {}'.format(trade))
logger.debug('Handling open trade %s ...', trade) logger.debug('Handling open trade %s ...', trade)
# Get current rate
current_rate = exchange.get_ticker(trade.pair)['bid']
current_profit = 100.0 * ((current_rate - trade.open_rate) / trade.open_rate)
if 'stoploss' in _CONF and current_profit < float(_CONF['stoploss']) * 100.0: current_rate = exchange.get_ticker(trade.pair)['bid']
current_profit = (current_rate - trade.open_rate) / trade.open_rate
if 'stoploss' in _CONF and current_profit < float(_CONF['stoploss']):
logger.debug('Stop loss hit.') logger.debug('Stop loss hit.')
execute_sell(trade, current_rate) execute_sell(trade, current_rate)
return return
@ -130,11 +130,11 @@ def handle_trade(trade: Trade) -> None:
duration, threshold = float(duration), float(threshold) duration, threshold = float(duration), float(threshold)
# Check if time matches and current rate is above threshold # Check if time matches and current rate is above threshold
time_diff = (datetime.utcnow() - trade.open_date).total_seconds() / 60 time_diff = (datetime.utcnow() - trade.open_date).total_seconds() / 60
if time_diff > duration and current_rate > (1 + threshold) * trade.open_rate: if time_diff > duration and current_profit > threshold:
execute_sell(trade, current_rate) execute_sell(trade, current_rate)
return return
logger.debug('Threshold not reached. (cur_profit: %1.2f%%)', current_profit) logger.debug('Threshold not reached. (cur_profit: %1.2f%%)', current_profit * 100.0)
except ValueError: except ValueError:
logger.exception('Unable to handle open order') logger.exception('Unable to handle open order')