Move performance-calculation to persistence

This commit is contained in:
Matthias
2019-10-29 11:09:41 +01:00
parent 669a6cf119
commit f20f5cebbe
3 changed files with 45 additions and 15 deletions

View File

@@ -8,17 +8,15 @@ from typing import Any, Dict, List, Optional
import arrow
from sqlalchemy import (Boolean, Column, DateTime, Float, Integer, String,
create_engine, inspect)
create_engine, desc, func, inspect)
from sqlalchemy.exc import NoSuchModuleError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.scoping import scoped_session
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy import func
from sqlalchemy.pool import StaticPool
from freqtrade import OperationalException
logger = logging.getLogger(__name__)
@@ -404,6 +402,25 @@ class Trade(_DECL_BASE):
.scalar()
return total_open_stake_amount or 0
@staticmethod
def get_overall_performance() -> Dict:
pair_rates = Trade.session.query(
Trade.pair,
func.sum(Trade.close_profit).label('profit_sum'),
func.count(Trade.pair).label('count')
).filter(Trade.is_open.is_(False))\
.group_by(Trade.pair) \
.order_by(desc('profit_sum')) \
.all()
return [
{
'pair': pair,
'profit': round(rate * 100, 2),
'count': count
}
for pair, rate, count in pair_rates
]
@staticmethod
def get_open_trades() -> List[Any]:
"""

View File

@@ -442,18 +442,7 @@ class RPC:
Handler for performance.
Shows a performance statistic from finished trades
"""
pair_rates = Trade.session.query(Trade.pair,
sql.func.sum(Trade.close_profit).label('profit_sum'),
sql.func.count(Trade.pair).label('count')) \
.filter(Trade.is_open.is_(False)) \
.group_by(Trade.pair) \
.order_by(sql.text('profit_sum DESC')) \
.all()
return [
{'pair': pair, 'profit': round(rate * 100, 2), 'count': count}
for pair, rate, count in pair_rates
]
return Trade.get_overall_performance()
def _rpc_count(self) -> Dict[str, float]:
""" Returns the number of trades running """