diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index a8fc6bc7e..ef9a85154 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -768,7 +768,7 @@ class FreqtradeBot: buy_timeout_threshold = arrow.utcnow().shift(minutes=-buy_timeout).datetime sell_timeout_threshold = arrow.utcnow().shift(minutes=-sell_timeout).datetime - for trade in Trade.query.filter(Trade.open_order_id.isnot(None)).all(): + for trade in Trade.get_open_order_trades(): try: # FIXME: Somehow the query above returns results # where the open_order_id is in fact None. diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index fe0b64bcc..e527cde16 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -391,6 +391,13 @@ class Trade(_DECL_BASE): profit_percent = (close_trade_price / open_trade_price) - 1 return float(f"{profit_percent:.8f}") + @staticmethod + def get_open_order_trades(): + """ + Returns all open trades + """ + return Trade.query.filter(Trade.open_order_id.isnot(None)).all() + @staticmethod def total_open_trades_stakes() -> float: """ @@ -403,7 +410,10 @@ class Trade(_DECL_BASE): return total_open_stake_amount or 0 @staticmethod - def get_overall_performance() -> Dict: + def get_overall_performance() -> List[Dict]: + """ + Returns List of dicts containing all Trades, including profit and trade count + """ pair_rates = Trade.session.query( Trade.pair, func.sum(Trade.close_profit).label('profit_sum'), @@ -423,6 +433,9 @@ class Trade(_DECL_BASE): @staticmethod def get_best_pair(): + """ + Get best pair with closed trade. + """ best_pair = Trade.session.query( Trade.pair, func.sum(Trade.close_profit).label('profit_sum') ).filter(Trade.is_open.is_(False)) \