diff --git a/octobot_evaluators/api/matrix.py b/octobot_evaluators/api/matrix.py new file mode 100644 index 00000000..4ce6f70d --- /dev/null +++ b/octobot_evaluators/api/matrix.py @@ -0,0 +1,37 @@ +# Drakkar-Software OctoBot-Evaluators +# Copyright (c) Drakkar-Software, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. +from octobot_evaluators.data.matrix import Matrix +from octobot_evaluators.matrices.matrices import Matrices + + +def get_matrix(matrix_id) -> Matrix: + return Matrices.instance().get_matrix(matrix_id) + + +def get_node_children_by_names(matrix) -> dict: + return matrix.get_node_children_by_names_at_path([]) + + +def get_children_list(matrix_node) -> list: + return matrix_node.children + + +def has_children(matrix_node) -> bool: + return bool(matrix_node.children) + + +def get_value(matrix_node) -> object: + return matrix_node.node_value diff --git a/octobot_evaluators/data/matrix.pxd b/octobot_evaluators/data/matrix.pxd index b441fb82..c8e40e8e 100644 --- a/octobot_evaluators/data/matrix.pxd +++ b/octobot_evaluators/data/matrix.pxd @@ -24,6 +24,7 @@ cdef class Matrix: cpdef void set_tentacle_value(self, object value, object value_type, list value_path) cpdef list get_node_children_at_path(self, list node_path, EventTreeNode starting_node=*) + cpdef dict get_node_children_by_names_at_path(self, list node_path, EventTreeNode starting_node=*) cpdef EventTreeNode get_node_at_path(self, list node_path, EventTreeNode starting_node=*) cpdef list get_tentacle_nodes(self, str exchange_name=*, object tentacle_type=*, str tentacle_name=*) cpdef list get_tentacles_value_nodes(self, list tentacle_nodes, str cryptocurrency=*, str symbol=*, str time_frame=*) diff --git a/octobot_evaluators/data/matrix.py b/octobot_evaluators/data/matrix.py index 30861543..3f7f07fe 100644 --- a/octobot_evaluators/data/matrix.py +++ b/octobot_evaluators/data/matrix.py @@ -40,6 +40,13 @@ def get_node_children_at_path(self, node_path, starting_node=None): except NodeExistsError: return [] + def get_node_children_by_names_at_path(self, node_path, starting_node=None): + try: + return {key: val + for key, val in self.matrix.get_node(node_path, starting_node=starting_node).children.items()} + except NodeExistsError: + return {} + def get_node_at_path(self, node_path, starting_node=None): try: return self.matrix.get_node(node_path, starting_node=starting_node)