Custom v2 - Recreating Controller instance every controller config update period
Describe the bug
I've added logs to my MyController(ControllerBase).init() method. And I see in my logs, that controller class has been regularly reinitialized during HB work. I'm loosing controller state, when controller reinitialize 😦 I've checked the period of the controller re-initialization - it's match with parameter config_update_interval of the strategy configuration. If I change config_update_interval period of the re-initialization is changing too. Looks like instead of update configuration of the current controller instance , HB creates new controller instance with new configuration. If you are in the status --live mode, this mode is also shutting down when HB updates controller configuration. Looks like bug, because we have is_updatable flag for the params of controller config which we want update periodically, but now controller totally loose it's state.
This issue is happens when there is no id in the controller config. `` I'm using HB dev-2.5.0 but HB 2.4.0 has the same issue.
Steps to reproduce
- Add minimal controller to the HB generic controllers directory. Code of
test_issue_controller.pybelow:
from typing import List
import pandas_ta as ta # noqa: F401
from pydantic import Field
from hummingbot.client.config.config_data_types import ClientFieldData
from hummingbot.data_feed.candles_feed.data_types import CandlesConfig
from hummingbot.strategy_v2.controllers.directional_trading_controller_base import (
ControllerBase,
ControllerConfigBase,
)
from hummingbot.strategy_v2.models.executor_actions import ExecutorAction
class TestIssueControllerConfig(ControllerConfigBase):
controller_name = "test_issue"
controller_type: str = "generic"
connector_name: str = Field(
default="okx",
client_data=ClientFieldData(
prompt_on_new=True,
prompt=lambda mi: "Enter the connector name: ",
)
)
candles_config: List[CandlesConfig] = []
class TestIssueController(ControllerBase):
inits_count: int = 0
def __init__(self, config: TestIssueControllerConfig, *args, **kwargs):
self.config = config
self.logger().info(f"INIT -> Controller initialized: {TestIssueController.inits_count}")
TestIssueController.inits_count += 1
super().__init__(config, *args, **kwargs)
async def update_processed_data(self):
return None
def determine_executor_actions(self) -> List[ExecutorAction]:
return []
- Add controller config yaml file to the conf/controllers folder. Make sure, that id is commented or deleted.
test_issue_controller.yml:
# id: AbQDQ3QySK3DJArewBqFVPMGQ23en8vApgWhsahXZfx
connector_name: okx
controller_name: test_issue_controller
controller_type: generic
total_amount_quote: 100
manual_kill_switch: null
candles_config: []
- Add script config file to the conf/script dir.
v2_with_controllers_test.yml:
markets: {}
candles_config: []
controllers_config:
- test_issue_controller.yml
config_update_interval: 20
script_file_name: v2_with_controllers.py
time_to_cash_out: null
max_global_drawdown: null
max_controller_drawdown: null
performance_report_interval: 5
rebalance_interval: null
extra_inventory: 0.02
min_amount_to_rebalance_usd: 8
asset_to_rebalance: USDT
-
run the HB with v2_with_controllers script using script config from point 3.
-
see in logs repeated messages about controller initialization. Check the period of this logs - it will be the same as param
config_update_intervalin the script config file.
Release version
2.4.0, dev-2.5.0
Type of installation
Source