Extract query to it's own function

This commit is contained in:
Matthias 2019-10-29 13:32:07 +01:00
parent ab117527c9
commit 01efebc42f
2 changed files with 15 additions and 2 deletions

View File

@ -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.

View File

@ -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)) \