From d53d4b808be0507a17dda6e3fda67ca4cca18d50 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste LE STANG Date: Tue, 30 Jan 2018 09:38:24 +0100 Subject: [PATCH] Fixing buy and sell order --- freqtrade/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/freqtrade/main.py b/freqtrade/main.py index 6f7a67df2..163597eee 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -55,7 +55,7 @@ def refresh_whitelist(whitelist: List[str]) -> List[str]: return final_list -def process_maybe_execute_buy(interval): +def process_maybe_execute_buy(interval: int) -> bool: """ Tries to execute a buy trade in a safe way :return: True if executed @@ -75,7 +75,7 @@ def process_maybe_execute_buy(interval): return False -def process_maybe_execute_sell(trade, interval): +def process_maybe_execute_sell(trade: Trade, interval: int) -> bool: """ Tries to execute a sell trade :return: True if executed @@ -114,12 +114,15 @@ def _process(interval: int, nb_assets: Optional[int] = 0) -> bool: # Query trades from persistence layer trades = Trade.query.filter(Trade.is_open.is_(True)).all() - if len(trades) < _CONF['max_open_trades']: - state_changed = process_maybe_execute_buy(interval) + # First process current opened trades for trade in trades: state_changed |= process_maybe_execute_sell(trade, interval) + # Then looking for buy opportunities + if len(trades) < _CONF['max_open_trades']: + state_changed = process_maybe_execute_buy(interval) + if 'unfilledtimeout' in _CONF: # Check and handle any timed out open orders check_handle_timedout(_CONF['unfilledtimeout'])