Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pytest>=7.1
pytest-cov
pytest-mock
pytest-asyncio
pytest-timeout

mock>=4.0.1

Expand Down
1 change: 0 additions & 1 deletion octobot_node/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import logging

from huey import Huey
from octobot_node.app.core.config import settings
from octobot_node.scheduler.scheduler import Scheduler
from octobot_node.scheduler.consumer import SchedulerConsumer
Expand Down
11 changes: 10 additions & 1 deletion octobot_node/scheduler/octobot_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import mini_octobot
import mini_octobot.environment
import mini_octobot.parsers

# Requires mini_octobot import and importable tentacles folder

# ensure environment is initialized
Expand Down Expand Up @@ -105,6 +104,16 @@ def get_created_orders(self) -> list[dict]:
if action.result
]
return list_util.flatten_list(order_lists) if order_lists else []

def get_deposit_and_withdrawal_details(self) -> list[dict]:
if self.processed_actions is None:
raise ValueError("No bot actions were executed yet")
withdrawal_lists = [
action.result
for action in self.processed_actions
if action.result and isinstance(action.result, dict) and "network" in action.result
]
return withdrawal_lists


class OctoBotActionsJob:
Expand Down
30 changes: 18 additions & 12 deletions octobot_node/scheduler/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import datetime
import asyncio
import json
import logging
import time


from octobot_node.scheduler import SCHEDULER
from octobot_node.scheduler.task_context import encrypted_task
Expand Down Expand Up @@ -61,31 +64,34 @@ def start_octobot(task: Task):
}


def _reshedule_octobot_execution(task: Task, next_actions_description: octobot_lib.OctoBotActionsJobDescription):
def _reshedule_octobot_execution(
task: Task, next_actions_description: octobot_lib.OctoBotActionsJobDescription
):
task.content = json.dumps(next_actions_description.to_dict(include_default_values=False))
if next_actions_description.get_next_execution_time() == 0:
next_execution_time = datetime.datetime.now(tz=datetime.timezone.utc)
next_execution_time = next_actions_description.get_next_execution_time()
now_time = time.time()
if next_execution_time == 0 or next_execution_time < now_time:
delay = 0
else:
next_execution_time = datetime.datetime.fromtimestamp(
next_actions_description.get_next_execution_time(),
tz=datetime.timezone.utc
)
execute_octobot.schedule(args=[task], eta=next_execution_time)
delay = next_execution_time - now_time
logging.getLogger("octobot_node.scheduler.tasks").info(
f"Scheduling task '{task.name}' for execution in {delay} seconds"
)
return execute_octobot.schedule(args=[task], delay=delay)
Comment on lines +71 to +80
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍



@SCHEDULER.INSTANCE.task()
@async_task
async def execute_octobot(task: Task):
with encrypted_task(task):
if task.type == TaskType.EXECUTE_ACTIONS.value:
print(f"Executing actions with content: {task.content} ...")
logging.getLogger("octobot_node.scheduler.tasks").info(f"Executing task '{task.name}' with content: {task.content} ...")
result: octobot_lib.OctoBotActionsJobResult = await octobot_lib.OctoBotActionsJob(
task.content
).run()
task.result = {
"state": {
"orders": result.get_created_orders()
}
"orders": result.get_created_orders(),
"transfers": result.get_deposit_and_withdrawal_details(),
}
if result.next_actions_description:
_reshedule_octobot_execution(task, result.next_actions_description)
Expand Down
Loading