Skip to content

Commit

Permalink
can stop evaluators and return consumer in Matrix.new_consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Feb 1, 2020
1 parent c5137a0 commit 9410f67
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion octobot_evaluators/api/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# License along with this library.
import copy

from octobot_commons.constants import CONFIG_EVALUATOR_FILE_PATH, CONFIG_CRYPTO_CURRENCIES, CONFIG_WILDCARD
from octobot_commons.constants import CONFIG_EVALUATOR_FILE_PATH, CONFIG_WILDCARD
from octobot_commons.errors import ConfigEvaluatorError
from octobot_commons.logging.logging_util import get_logger
from octobot_commons.tentacles_management import create_classes_list, create_advanced_types_list
Expand Down Expand Up @@ -76,6 +76,10 @@ def __get_time_frames_to_create(evaluator_class, time_frames): # TODO replace w
return time_frames if time_frames and not evaluator_class.get_is_time_frame_wildcard() else [None]


async def stop_evaluator(evaluator) -> None:
return await evaluator.stop()


def get_evaluator_classes_from_type(evaluator_type, config, activated_only=True) -> list:
if activated_only:
return [cls for cls in create_advanced_types_list(EvaluatorClassTypes[evaluator_type], config)
Expand Down
4 changes: 4 additions & 0 deletions octobot_evaluators/api/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def get_matrix(matrix_id) -> Matrix:
return Matrices.instance().get_matrix(matrix_id)


def del_matrix(matrix_id) -> Matrix:
return Matrices.instance().del_matrix(matrix_id)


def get_node_children_by_names(matrix) -> dict:
return matrix.get_node_children_by_names_at_path([])

Expand Down
4 changes: 3 additions & 1 deletion octobot_evaluators/channels/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ async def new_consumer(self,
exchange_name=CHANNEL_WILDCARD,
time_frame=CHANNEL_WILDCARD,
filter_size=False):
await self._add_new_consumer_and_run(MatrixChannelConsumer(callback, size=size, filter_size=filter_size),
consumer = MatrixChannelConsumer(callback, size=size, filter_size=filter_size)
await self._add_new_consumer_and_run(consumer,
matrix_id=matrix_id,
cryptocurrency=cryptocurrency,
symbol=symbol,
evaluator_name=evaluator_name,
evaluator_type=evaluator_type,
exchange_name=exchange_name,
time_frame=time_frame)
return consumer

def get_filtered_consumers(self,
matrix_id=CHANNEL_WILDCARD,
Expand Down
7 changes: 7 additions & 0 deletions octobot_evaluators/evaluator/abstract_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ async def evaluation_completed(self,
async def start(self) -> None:
raise NotImplementedError("start is not implemented")

async def stop(self) -> None:
"""
implement if necessary
:return: None
"""
pass

async def prepare(self) -> None:
"""
Called just before start(), implement if necessary
Expand Down
10 changes: 9 additions & 1 deletion octobot_evaluators/evaluator/strategy_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
class StrategyEvaluator(AbstractEvaluator):
__metaclass__ = AbstractEvaluator

def __init__(self):
super().__init__()
self.consumer_instance = None

@classmethod
def get_config_tentacle_type(cls) -> str:
return CONFIG_EVALUATOR_STRATEGIES
Expand All @@ -36,7 +40,11 @@ async def start(self) -> None:
Subscribe to Matrix notification from self.symbols and self.time_frames
:return: None
"""
await get_chan(MATRIX_CHANNEL).new_consumer(self.matrix_callback)
self.consumer_instance = await get_chan(MATRIX_CHANNEL).new_consumer(self.matrix_callback)

async def stop(self) -> None:
if self.consumer_instance:
await get_chan(MATRIX_CHANNEL).remove_consumer(self.consumer_instance)

async def matrix_callback(self,
matrix_id,
Expand Down

0 comments on commit 9410f67

Please sign in to comment.