Fix application state and add new optional config attribute: "initial_state"

* Move State handling to misc, to avoid circular imports
* Add optional config attribute "initial_state"
This commit is contained in:
gcarq
2017-09-09 00:31:40 +02:00
parent 996beae770
commit a4b2f4e4b9
6 changed files with 118 additions and 107 deletions

View File

@@ -8,6 +8,7 @@ from telegram.error import NetworkError
from telegram.ext import CommandHandler, Updater
from telegram import ParseMode, Bot, Update
from misc import get_state, State, update_state
from persistence import Trade
import exchange
@@ -89,7 +90,6 @@ def _status(bot: Bot, update: Update) -> None:
"""
# Fetch open trade
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
from main import get_state, State
if get_state() != State.RUNNING:
send_msg('*Status:* `trader is not running`', bot=bot)
elif not trades:
@@ -200,7 +200,6 @@ def _start(bot: Bot, update: Update) -> None:
:param update: message update
:return: None
"""
from main import get_state, State, update_state
if get_state() == State.RUNNING:
send_msg('*Status:* `already running`', bot=bot)
else:
@@ -216,10 +215,9 @@ def _stop(bot: Bot, update: Update) -> None:
:param update: message update
:return: None
"""
from main import get_state, State, update_state
if get_state() == State.RUNNING:
send_msg('`Stopping trader ...`', bot=bot)
update_state(State.PAUSED)
update_state(State.STOPPED)
else:
send_msg('*Status:* `already stopped`', bot=bot)
@@ -233,7 +231,6 @@ def _forcesell(bot: Bot, update: Update) -> None:
:param update: message update
:return: None
"""
from main import get_state, State
if get_state() != State.RUNNING:
send_msg('`trader is not running`', bot=bot)
return
@@ -281,7 +278,6 @@ def _performance(bot: Bot, update: Update) -> None:
:param update: message update
:return: None
"""
from main import get_state, State
if get_state() != State.RUNNING:
send_msg('`trader is not running`', bot=bot)
return