-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[DSL] POC2 #3299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[DSL] POC2 #3299
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d5c7c71
[TradingView] migrate to DSL implementation
GuillaumeDSM 3ec1d45
[DSL] add resolved_params and update octobot_node
GuillaumeDSM da17c46
[Exchanges] add initialize_from_exchange_data
GuillaumeDSM 173a01a
[CCXT] implement shared market status
GuillaumeDSM 4ef54d7
[Tests] add dbos recovery test
GuillaumeDSM 16fcece
[Exchanges] remove global rest_exchange system
GuillaumeDSM 2da63c4
[Node] single automation workflow migration
GuillaumeDSM 77d079a
[DSL] add wait keyword
GuillaumeDSM e7f0d37
[AutomationWorkflow] store all data in task and state
GuillaumeDSM 69c89ba
[Automations] add priority actions
GuillaumeDSM d6d0fa4
[Automations] refactor and add tests
GuillaumeDSM dca4299
[Automations] add optional automation dedicated log file
GuillaumeDSM ab1ecbd
[Flow] add octobot_flow package
GuillaumeDSM 233926d
[CI] fix octobot flow and node tests
GuillaumeDSM 2bd2ac5
[StopAutomation] convert to DSL
GuillaumeDSM ab117f3
[ExchangeData] refactor into different file
GuillaumeDSM 3b9dbfa
[Scheduler] add delete_workflows
GuillaumeDSM 186dcdd
[Errors] rename MiniOctobotError to OctobotFlowError
GuillaumeDSM 70665ea
[Flow] remove tmp code and clarify TODOs
GuillaumeDSM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/commons/octobot_commons/dsl_interpreter/operators/re_callable_operator_mixin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # Drakkar-Software OctoBot-Commons | ||
| # 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. | ||
| import dataclasses | ||
| import typing | ||
| import time | ||
| import enum | ||
|
|
||
| import octobot_commons.dataclasses | ||
| import octobot_commons.dsl_interpreter.operator_parameter as operator_parameter | ||
|
|
||
|
|
||
| class ReCallingOperatorResultKeys(str, enum.Enum): | ||
| WAITING_TIME = "waiting_time" | ||
| LAST_EXECUTION_TIME = "last_execution_time" | ||
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class ReCallingOperatorResult(octobot_commons.dataclasses.MinimizableDataclass): | ||
| reset_to_id: typing.Optional[str] = None | ||
| last_execution_result: typing.Optional[dict] = None | ||
|
|
||
| @staticmethod | ||
| def is_re_calling_operator_result(result: typing.Any) -> bool: | ||
| """ | ||
| Check if the result is a re-calling operator result. | ||
| """ | ||
| return isinstance(result, dict) and ( | ||
| ReCallingOperatorResult.__name__ in result | ||
| ) | ||
|
|
||
| def get_next_call_time(self) -> typing.Optional[float]: | ||
| """ | ||
| Returns the next call time based on the last execution result's | ||
| waiting time and last execution time. | ||
| """ | ||
| if ( | ||
| self.last_execution_result | ||
| and (waiting_time := self.last_execution_result.get(ReCallingOperatorResultKeys.WAITING_TIME.value)) | ||
| ): | ||
| last_execution_time = self.last_execution_result.get( | ||
| ReCallingOperatorResultKeys.LAST_EXECUTION_TIME.value | ||
| ) or time.time() | ||
| return last_execution_time + waiting_time | ||
| return None | ||
|
|
||
|
|
||
| class ReCallableOperatorMixin: | ||
| """ | ||
| Mixin for re-callable operators. | ||
| """ | ||
| LAST_EXECUTION_RESULT_KEY = "last_execution_result" | ||
|
|
||
| @classmethod | ||
| def get_re_callable_parameters(cls) -> list[operator_parameter.OperatorParameter]: | ||
| """ | ||
| Returns the parameters for the re-callable operator. | ||
| """ | ||
| return [ | ||
| operator_parameter.OperatorParameter( | ||
| name=cls.LAST_EXECUTION_RESULT_KEY, | ||
| description="the return value of the previous call", | ||
| required=False, | ||
| type=dict, | ||
| default=None, | ||
| ), | ||
| ] | ||
|
|
||
| def get_last_execution_result( | ||
| self, param_by_name: dict[str, typing.Any] | ||
| ) -> typing.Optional[dict]: | ||
| """ | ||
| Returns the potential last execution result from param_by_name. | ||
| """ | ||
| if ( | ||
| (result_dict := param_by_name.get(self.LAST_EXECUTION_RESULT_KEY, None)) | ||
| and ReCallingOperatorResult.is_re_calling_operator_result(result_dict) | ||
| ): | ||
| return ReCallingOperatorResult.from_dict(result_dict[ | ||
| ReCallingOperatorResult.__name__ | ||
| ]).last_execution_result | ||
| return None | ||
|
|
||
| def build_re_callable_result( | ||
| self, | ||
| reset_to_id: typing.Optional[str] = None, | ||
| waiting_time: typing.Optional[float] = None, | ||
| last_execution_time: typing.Optional[float] = None, | ||
| **kwargs: typing.Any, | ||
| ) -> dict: | ||
| """ | ||
| Builds a dict formatted re-callable result from the given parameters. | ||
| """ | ||
| return { | ||
| ReCallingOperatorResult.__name__: ReCallingOperatorResult( | ||
| reset_to_id=reset_to_id, | ||
| last_execution_result={ | ||
| ReCallingOperatorResultKeys.WAITING_TIME.value: waiting_time, | ||
| ReCallingOperatorResultKeys.LAST_EXECUTION_TIME.value: last_execution_time, | ||
| **kwargs, | ||
| }, | ||
| ).to_dict(include_default_values=False) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍