Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/hummingbot/hummingbot/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The RunnableBase class provides the foundation for all runnable components in the Hummingbot V2 framework, including controllers and executors. It implements a control loop pattern that executes tasks at regular intervals.

Class Definition

class RunnableBase(ABC):
    def __init__(self, update_interval: float = 0.5)
Location: hummingbot/strategy_v2/runnable_base.py:10

Parameters

update_interval
float
default:"0.5"
The interval at which the control loop should be executed, in seconds

Properties

status

@property
def status(self) -> RunnableStatus
Returns the current status of the runnable component. Returns: The current RunnableStatus (NOT_STARTED, RUNNING, SHUTTING_DOWN, or TERMINATED)

Methods

start()

def start(self)
Starts the control loop of the smart component. If the component is not already started, it will initialize and begin the control loop. Location: runnable_base.py:42

stop()

def stop(self)
Stops the control loop of the smart component. Sets the status to TERMINATED and triggers the termination event. Location: runnable_base.py:52

control_loop()

async def control_loop(self)
The main control loop of the smart component. This method:
  1. Executes on_start() when the loop begins
  2. Continuously executes control_task() at the specified interval
  3. Calls on_stop() when the loop terminates
Location: runnable_base.py:61

on_start()

async def on_start(self)
Method executed when the control loop is started. Should be overridden in subclasses to provide specific initialization behavior. Location: runnable_base.py:83

on_stop()

def on_stop(self)
Method executed when the control loop is stopped. Should be overridden in subclasses to provide specific cleanup behavior. Location: runnable_base.py:76

control_task()

async def control_task(self)
The main task to be executed in the control loop. Must be overridden in subclasses to provide specific behavior. Location: runnable_base.py:90

RunnableStatus Enum

The RunnableStatus enum defines the possible states of a runnable component:
NOT_STARTED
int
Component has been created but not started
RUNNING
int
Component is actively running
SHUTTING_DOWN
int
Component is in the process of shutting down
TERMINATED
int
Component has been stopped and terminated

Usage Example

from hummingbot.strategy_v2.runnable_base import RunnableBase
from hummingbot.strategy_v2.models.base import RunnableStatus

class MyComponent(RunnableBase):
    def __init__(self):
        super().__init__(update_interval=1.0)  # Execute every second
    
    async def on_start(self):
        self.logger().info("Component starting...")
    
    async def control_task(self):
        # Your logic here
        self.logger().info("Executing task...")
    
    def on_stop(self):
        self.logger().info("Component stopped")

# Create and start component
component = MyComponent()
component.start()

# Check status
if component.status == RunnableStatus.RUNNING:
    print("Component is running")

# Stop component
component.stop()

Notes

  • The RunnableBase class is abstract and should not be instantiated directly
  • Subclasses must implement the control_task() method
  • The control loop handles exceptions and continues running even if a task fails
  • The update_interval determines how frequently the control task executes