bot state moved back to freqtradebot from worker
This commit is contained in:
parent
06144a1fc4
commit
7251e5bd62
@ -22,7 +22,6 @@ from freqtrade.resolvers import ExchangeResolver, StrategyResolver, PairListReso
|
|||||||
from freqtrade.state import State
|
from freqtrade.state import State
|
||||||
from freqtrade.strategy.interface import SellType, IStrategy
|
from freqtrade.strategy.interface import SellType, IStrategy
|
||||||
from freqtrade.wallets import Wallets
|
from freqtrade.wallets import Wallets
|
||||||
from freqtrade.worker import Worker
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -34,7 +33,7 @@ class FreqtradeBot(object):
|
|||||||
This is from here the bot start its logic.
|
This is from here the bot start its logic.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config: Dict[str, Any], worker: Optional[Worker] = None) -> None:
|
def __init__(self, config: Dict[str, Any]) -> None:
|
||||||
"""
|
"""
|
||||||
Init all variables and objects the bot needs to work
|
Init all variables and objects the bot needs to work
|
||||||
:param config: configuration dict, you can use Configuration.get_config()
|
:param config: configuration dict, you can use Configuration.get_config()
|
||||||
@ -43,9 +42,11 @@ class FreqtradeBot(object):
|
|||||||
|
|
||||||
logger.info('Starting freqtrade %s', __version__)
|
logger.info('Starting freqtrade %s', __version__)
|
||||||
|
|
||||||
|
# Init bot state
|
||||||
|
self.state = State.STOPPED
|
||||||
|
|
||||||
# Init objects
|
# Init objects
|
||||||
self.config = config
|
self.config = config
|
||||||
self._worker = worker
|
|
||||||
|
|
||||||
self.strategy: IStrategy = StrategyResolver(self.config).strategy
|
self.strategy: IStrategy = StrategyResolver(self.config).strategy
|
||||||
|
|
||||||
@ -73,17 +74,9 @@ class FreqtradeBot(object):
|
|||||||
|
|
||||||
persistence.init(self.config)
|
persistence.init(self.config)
|
||||||
|
|
||||||
@property
|
# Set initial bot state from config
|
||||||
def state(self) -> State:
|
initial_state = self.config.get('initial_state')
|
||||||
if self._worker is None:
|
self.state = State[initial_state.upper()] if initial_state else State.STOPPED
|
||||||
raise DependencyException("No Worker is available")
|
|
||||||
return self._worker.state
|
|
||||||
|
|
||||||
@state.setter
|
|
||||||
def state(self, value: State):
|
|
||||||
if self._worker is None:
|
|
||||||
raise DependencyException("No Worker is available")
|
|
||||||
self._worker.state = value
|
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
def cleanup(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -11,6 +11,7 @@ import sdnotify
|
|||||||
from freqtrade import (constants, OperationalException, TemporaryError,
|
from freqtrade import (constants, OperationalException, TemporaryError,
|
||||||
__version__)
|
__version__)
|
||||||
from freqtrade.configuration import Configuration
|
from freqtrade.configuration import Configuration
|
||||||
|
from freqtrade.freqtradebot import FreqtradeBot
|
||||||
from freqtrade.state import State
|
from freqtrade.state import State
|
||||||
from freqtrade.rpc import RPCMessageType
|
from freqtrade.rpc import RPCMessageType
|
||||||
|
|
||||||
@ -46,19 +47,8 @@ class Worker(object):
|
|||||||
# Load configuration
|
# Load configuration
|
||||||
self._config = Configuration(self._args, None).get_config()
|
self._config = Configuration(self._args, None).get_config()
|
||||||
|
|
||||||
# Import freqtradebot here in order to avoid python circular
|
|
||||||
# dependency error, damn!
|
|
||||||
from freqtrade.freqtradebot import FreqtradeBot
|
|
||||||
|
|
||||||
# Init the instance of the bot
|
# Init the instance of the bot
|
||||||
self.freqtrade = FreqtradeBot(self._config, self)
|
self.freqtrade = FreqtradeBot(self._config)
|
||||||
|
|
||||||
# Set initial bot state
|
|
||||||
initial_state = self._config.get('initial_state')
|
|
||||||
if initial_state:
|
|
||||||
self._state = State[initial_state.upper()]
|
|
||||||
else:
|
|
||||||
self._state = State.STOPPED
|
|
||||||
|
|
||||||
self._throttle_secs = self._config.get('internals', {}).get(
|
self._throttle_secs = self._config.get('internals', {}).get(
|
||||||
'process_throttle_secs',
|
'process_throttle_secs',
|
||||||
@ -70,11 +60,11 @@ class Worker(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> State:
|
def state(self) -> State:
|
||||||
return self._state
|
return self.freqtrade.state
|
||||||
|
|
||||||
@state.setter
|
@state.setter
|
||||||
def state(self, value: State):
|
def state(self, value: State):
|
||||||
self._state = value
|
self.freqtrade.state = value
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
state = None
|
state = None
|
||||||
@ -89,7 +79,7 @@ class Worker(object):
|
|||||||
:param old_state: the previous service state from the previous call
|
:param old_state: the previous service state from the previous call
|
||||||
:return: current service state
|
:return: current service state
|
||||||
"""
|
"""
|
||||||
state = self._state
|
state = self.freqtrade.state
|
||||||
if throttle_secs is None:
|
if throttle_secs is None:
|
||||||
throttle_secs = self._throttle_secs
|
throttle_secs = self._throttle_secs
|
||||||
|
|
||||||
@ -141,7 +131,6 @@ class Worker(object):
|
|||||||
state_changed = False
|
state_changed = False
|
||||||
try:
|
try:
|
||||||
state_changed = self.freqtrade.process()
|
state_changed = self.freqtrade.process()
|
||||||
|
|
||||||
except TemporaryError as error:
|
except TemporaryError as error:
|
||||||
logger.warning(f"Error: {error}, retrying in {constants.RETRY_TIMEOUT} seconds...")
|
logger.warning(f"Error: {error}, retrying in {constants.RETRY_TIMEOUT} seconds...")
|
||||||
time.sleep(constants.RETRY_TIMEOUT)
|
time.sleep(constants.RETRY_TIMEOUT)
|
||||||
@ -153,7 +142,8 @@ class Worker(object):
|
|||||||
'status': f'OperationalException:\n```\n{tb}```{hint}'
|
'status': f'OperationalException:\n```\n{tb}```{hint}'
|
||||||
})
|
})
|
||||||
logger.exception('OperationalException. Stopping trader ...')
|
logger.exception('OperationalException. Stopping trader ...')
|
||||||
self.state = State.STOPPED
|
self.freqtrade.state = State.STOPPED
|
||||||
|
### state_changed = True
|
||||||
return state_changed
|
return state_changed
|
||||||
|
|
||||||
def _reconfigure(self):
|
def _reconfigure(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user