Extract query to it's own function
This commit is contained in:
parent
ab117527c9
commit
01efebc42f
@ -768,7 +768,7 @@ class FreqtradeBot:
|
|||||||
buy_timeout_threshold = arrow.utcnow().shift(minutes=-buy_timeout).datetime
|
buy_timeout_threshold = arrow.utcnow().shift(minutes=-buy_timeout).datetime
|
||||||
sell_timeout_threshold = arrow.utcnow().shift(minutes=-sell_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:
|
try:
|
||||||
# FIXME: Somehow the query above returns results
|
# FIXME: Somehow the query above returns results
|
||||||
# where the open_order_id is in fact None.
|
# where the open_order_id is in fact None.
|
||||||
|
@ -391,6 +391,13 @@ class Trade(_DECL_BASE):
|
|||||||
profit_percent = (close_trade_price / open_trade_price) - 1
|
profit_percent = (close_trade_price / open_trade_price) - 1
|
||||||
return float(f"{profit_percent:.8f}")
|
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
|
@staticmethod
|
||||||
def total_open_trades_stakes() -> float:
|
def total_open_trades_stakes() -> float:
|
||||||
"""
|
"""
|
||||||
@ -403,7 +410,10 @@ class Trade(_DECL_BASE):
|
|||||||
return total_open_stake_amount or 0
|
return total_open_stake_amount or 0
|
||||||
|
|
||||||
@staticmethod
|
@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(
|
pair_rates = Trade.session.query(
|
||||||
Trade.pair,
|
Trade.pair,
|
||||||
func.sum(Trade.close_profit).label('profit_sum'),
|
func.sum(Trade.close_profit).label('profit_sum'),
|
||||||
@ -423,6 +433,9 @@ class Trade(_DECL_BASE):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_best_pair():
|
def get_best_pair():
|
||||||
|
"""
|
||||||
|
Get best pair with closed trade.
|
||||||
|
"""
|
||||||
best_pair = Trade.session.query(
|
best_pair = Trade.session.query(
|
||||||
Trade.pair, func.sum(Trade.close_profit).label('profit_sum')
|
Trade.pair, func.sum(Trade.close_profit).label('profit_sum')
|
||||||
).filter(Trade.is_open.is_(False)) \
|
).filter(Trade.is_open.is_(False)) \
|
||||||
|
Loading…
Reference in New Issue
Block a user