Add absolute Profit to apiserver

This commit is contained in:
Matthias 2021-05-15 19:39:46 +02:00
parent 2ecb42a639
commit 6b2a38ccfb
3 changed files with 12 additions and 6 deletions

View File

@ -815,18 +815,20 @@ class Trade(_DECL_BASE, LocalTrade):
pair_rates = Trade.query.with_entities(
Trade.pair,
func.sum(Trade.close_profit).label('profit_sum'),
func.sum(Trade.close_profit_abs).label('profit_sum_abs'),
func.count(Trade.pair).label('count')
).filter(Trade.is_open.is_(False))\
.group_by(Trade.pair) \
.order_by(desc('profit_sum')) \
.order_by(desc('profit_sum_abs')) \
.all()
return [
{
'pair': pair,
'profit': rate,
'profit': profit,
'profit_abs': profit_abs,
'count': count
}
for pair, rate, count in pair_rates
for pair, profit, profit_abs, count in pair_rates
]
@staticmethod

View File

@ -57,6 +57,7 @@ class Count(BaseModel):
class PerformanceEntry(BaseModel):
pair: str
profit: float
profit_abs: float
count: int

View File

@ -710,7 +710,7 @@ def test_api_stats(botclient, mocker, ticker, fee, markets,):
assert 'draws' in rc.json()['durations']
def test_api_performance(botclient, mocker, ticker, fee):
def test_api_performance(botclient, fee):
ftbot, client = botclient
patch_get_signal(ftbot, (True, False))
@ -728,6 +728,7 @@ def test_api_performance(botclient, mocker, ticker, fee):
)
trade.close_profit = trade.calc_profit_ratio()
trade.close_profit_abs = trade.calc_profit()
Trade.query.session.add(trade)
trade = Trade(
@ -743,14 +744,16 @@ def test_api_performance(botclient, mocker, ticker, fee):
close_rate=0.391
)
trade.close_profit = trade.calc_profit_ratio()
trade.close_profit_abs = trade.calc_profit()
Trade.query.session.add(trade)
Trade.query.session.flush()
rc = client_get(client, f"{BASE_URI}/performance")
assert_response(rc)
assert len(rc.json()) == 2
assert rc.json() == [{'count': 1, 'pair': 'LTC/ETH', 'profit': 7.61},
{'count': 1, 'pair': 'XRP/ETH', 'profit': -5.57}]
assert rc.json() == [{'count': 1, 'pair': 'LTC/ETH', 'profit': 7.61, 'profit_abs': 0.01872279},
{'count': 1, 'pair': 'XRP/ETH', 'profit': -5.57, 'profit_abs': -0.1150375}]
def test_api_status(botclient, mocker, ticker, fee, markets):