Adds /count command

Adds /count command

Adds /count command
This commit is contained in:
Sebastien Moreau
2017-10-23 16:43:05 -04:00
parent 871b5e17ee
commit 0e1eb20781
3 changed files with 116 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ def init(config: dict) -> None:
CommandHandler('stop', _stop),
CommandHandler('forcesell', _forcesell),
CommandHandler('performance', _performance),
CommandHandler('count', _count),
CommandHandler('help', _help),
]
for handle in handles:
@@ -310,6 +311,29 @@ def _performance(bot: Bot, update: Update) -> None:
send_msg(message, parse_mode=ParseMode.HTML)
@authorized_only
def _count(bot: Bot, update: Update) -> None:
"""
Handler for /count.
Returns the number of trades running
:param bot: telegram bot
:param update: message update
:return: None
"""
if get_state() != State.RUNNING:
send_msg('`trader is not running`', bot=bot)
return
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
current_trades_count = len(trades)
max_trades_count = _CONF['max_open_trades']
message = '<b>Count:</b>\ncurrent/max\n{}/{}\n'.format(current_trades_count, max_trades_count)
logger.debug(message)
send_msg(message, parse_mode=ParseMode.HTML)
@authorized_only
def _help(bot: Bot, update: Update) -> None:
"""