rpc refactor 8/
This commit is contained in:
parent
64bbf3f9fb
commit
c99ec4d567
@ -380,6 +380,7 @@ def rpc_stop():
|
||||
return (True, '*Status:* `already stopped`')
|
||||
|
||||
|
||||
# FIX: no test for this!!!!
|
||||
def rpc_forcesell(trade_id) -> None:
|
||||
"""
|
||||
Handler for forcesell <id>.
|
||||
@ -405,3 +406,25 @@ def rpc_forcesell(trade_id) -> None:
|
||||
return (True, 'Invalid argument. See `/help` to view usage')
|
||||
|
||||
_exec_forcesell(trade)
|
||||
|
||||
|
||||
def rpc_performance() -> None:
|
||||
"""
|
||||
Handler for performance.
|
||||
Shows a performance statistic from finished trades
|
||||
"""
|
||||
if get_state() != State.RUNNING:
|
||||
return (True, '`trader is not running`')
|
||||
|
||||
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()
|
||||
trades = []
|
||||
for (pair, rate, count) in pair_rates:
|
||||
trades.append({'pair': pair, 'profit': round(rate * 100, 2), 'count': count})
|
||||
|
||||
return (False, trades)
|
||||
|
@ -1,7 +1,6 @@
|
||||
import logging
|
||||
from typing import Any, Callable
|
||||
|
||||
from sqlalchemy import func, text
|
||||
from tabulate import tabulate
|
||||
from telegram import Bot, ParseMode, ReplyKeyboardMarkup, Update
|
||||
from telegram.error import NetworkError, TelegramError
|
||||
@ -15,6 +14,7 @@ from freqtrade.rpc.__init__ import (rpc_status_table,
|
||||
rpc_start,
|
||||
rpc_stop,
|
||||
rpc_forcesell,
|
||||
rpc_performance,
|
||||
)
|
||||
|
||||
from freqtrade import __version__, exchange
|
||||
@ -324,26 +324,18 @@ def _performance(bot: Bot, update: Update) -> None:
|
||||
:param update: message update
|
||||
:return: None
|
||||
"""
|
||||
if get_state() != State.RUNNING:
|
||||
send_msg('`trader is not running`', bot=bot)
|
||||
(error, trades) = rpc_performance()
|
||||
if error:
|
||||
send_msg(trades, bot=bot)
|
||||
return
|
||||
|
||||
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(text('profit_sum DESC')) \
|
||||
.all()
|
||||
|
||||
stats = '\n'.join('{index}.\t<code>{pair}\t{profit:.2f}% ({count})</code>'.format(
|
||||
index=i + 1,
|
||||
pair=pair,
|
||||
profit=round(rate * 100, 2),
|
||||
count=count
|
||||
) for i, (pair, rate, count) in enumerate(pair_rates))
|
||||
|
||||
pair=trade['pair'],
|
||||
profit=trade['profit'],
|
||||
count=trade['count']
|
||||
) for i, trade in enumerate(trades))
|
||||
message = '<b>Performance:</b>\n{}'.format(stats)
|
||||
logger.debug(message)
|
||||
send_msg(message, parse_mode=ParseMode.HTML)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user