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

18
.editorconfig Normal file
View File

@ -0,0 +1,18 @@
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
[*.md]
max_line_length = 0
trim_trailing_whitespace = false
[COMMIT_EDITMSG]
max_line_length = 0

74
bin/run-docker Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
# Check if docker image exists
CMD_CHECK_IMAGE="docker images -q freqtrade:latest"
REBUILD=false
DRY_RUN=false
while getopts rdh option
do
case "${option}"
in
r) REBUILD=true
;;
d) DRY_RUN=true
;;
h) cat << EOF
Commands available :
-r Rebuild the container
-d Dry Run
-h This help message
EOF
exit 0
;;
esac
done
# Ensures files exists
[ -d ~/.freqtrade ] || mkdir ~/.freqtrade
cp config.json ~/.freqtrade/
touch ~/.freqtrade/tradesv2.sqlite
touch ~/.freqtrade/tradesv2.dry_run.sqlite
echo 'Stopping container...'
docker stop freqtrade > /dev/null \
&& docker rm freqtrade > /dev/null \
&& echo 'Container stopped'
if [[ -z $($CMD_CHECK_IMAGE) || $REBUILD = true ]]; then
echo "Building container"
docker build -t freqtrade .
fi
# Generates Docker commands based on options
DOCKER_CMD="docker run -d \
--name freqtrade \
-v ~/.freqtrade/config.json:/freqtrade/config.json"
if [[ $DRY_RUN = true ]]; then
DOCKER_CMD="$DOCKER_CMD \
-v ~/.freqtrade/tradesv2.dry_run.sqlite:/freqtrade/tradesv2.dry_run.sqlite"
else
DOCKER_CMD="$DOCKER_CMD \
-v ~/.freqtrade/tradesv2.sqlite:/freqtrade/tradesv2.sqlite"
fi
DOCKER_CMD="$DOCKER_CMD freqtrade"
echo 'Starting container'
eval $DOCKER_CMD \ > /dev/null \
&& echo 'Container ready' \
|| echo 'Problem starting container'
exit 0
docker run -d \
--name freqtrade \
-v ~/.freqtrade/config.json:/freqtrade/config.json \
-v ~/.freqtrade/tradesv2.dry_run.sqlite:/freqtrade/tradesv2.dry_run.sqlite \
freqtrade

View File

@ -45,6 +45,7 @@ def init(config: dict) -> None:
CommandHandler('stop', _stop), CommandHandler('stop', _stop),
CommandHandler('forcesell', _forcesell), CommandHandler('forcesell', _forcesell),
CommandHandler('performance', _performance), CommandHandler('performance', _performance),
CommandHandler('count', _count),
CommandHandler('help', _help), CommandHandler('help', _help),
] ]
for handle in handles: for handle in handles:
@ -310,6 +311,29 @@ def _performance(bot: Bot, update: Update) -> None:
send_msg(message, parse_mode=ParseMode.HTML) 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 @authorized_only
def _help(bot: Bot, update: Update) -> None: def _help(bot: Bot, update: Update) -> None:
""" """