Scripts are the entry point for Hummingbot strategies. They enable Hummingbot users to build customized strategies using the Strategy V2 framework, and access the full power of Hummingbot exchange connectors in a few lines of Python code.
Note
Should your script run into an error, it's crucial that you exit Hummingbot entirely, correct or debug the faulty script, and then restart Hummingbot. The stop command won't rectify the issue in case of an error. To get back on track, a complete shutdown and subsequent relaunch of Hummingbot is required.
For more info, see the Script Walkthrough. This detailed walkthrough shows you how to run a simple directional algo trading strategy.
Scripts can be created both with and without config files.
To create a configuration file for your script, execute:
create--script-config[SCRIPT_FILE]
This command auto-completes with scripts from the local /scripts directory that are configurable. You'll be prompted to specify strategy parameters, which are then saved in a YAML file within the conf/scripts directory. To run the script, use:
Scripts that use the Strategy V2 framework inherit from the StrategyV2Base class. These scripts allow the user to create a config file with parameters.
Other scripts, including simple examples and older scripts, inherit from the ScriptStrategyBase class. These scripts define their parameters in the script code and do not expose config parameters.
The entry point for StrategyV2 is a Hummingbot script that inherits from the StrategyV2Base class.
This script fetches data from the Market Data Provider and manages how each Executor behaves. Optionally, it can load a Controller to manage the stategy logic instead of defining it in within the script. Go through the Walkthrough to learn how it works.
See Sample Scripts for more examples of StrategyV2-compatible scripts.
To add user-defined parameters to a StategyV2 script, add a configuration class that extends the StrategyV2ConfigBase class in StrategyV2Base class.
This defines a set of configuration parameters that are prompted to the user when they run create to generate the config file. Only questions marked prompt_on_new are displayed.
Afterwards, these parameters are stored in a config file. The script checks this config file every config_update_interval (default: 60 seconds) and updates the parameters that it uses in-flight.
classStrategyV2ConfigBase(BaseClientModel):""" Base class for version 2 strategy configurations. """markets:Dict[str,Set[str]]=Field(default="binance_perpetual.JASMY-USDT,RLC-USDT",client_data=ClientFieldData(prompt_on_new=True,prompt=lambdami:("Enter markets in format 'exchange1.tp1,tp2:exchange2.tp1,tp2':")))candles_config:List[CandlesConfig]=Field(default="binance_perpetual.JASMY-USDT.1m.500:binance_perpetual.RLC-USDT.1m.500",client_data=ClientFieldData(prompt_on_new=True,prompt=lambdami:("Enter candle configs in format 'exchange1.tp1.interval1.max_records:""exchange2.tp2.interval2.max_records':")))controllers_config:List[str]=Field(default=None,client_data=ClientFieldData(is_updatable=True,prompt_on_new=True,prompt=lambdami:"Enter controller configurations (comma-separated file paths), leave it empty if none: "))config_update_interval:int=Field(default=60,gt=0,client_data=ClientFieldData(prompt_on_new=False,prompt=lambdami:"Enter the config update interval in seconds (e.g. 60): ",))
This overrides the standard status function and provides a formatted string representing the current status of the strategy, including the name, trading pair, and status of each executor.
Users can customize this function to display their custom strategy variables.
defformat_status(self)->str:ifnotself.ready_to_trade:return"Market connectors are not ready."lines=[]fortrading_pair,executor_handlerinself.executor_handlers.items():lines.extend([f"Strategy: {executor_handler.controller.config.strategy_name} | Trading Pair: {trading_pair}",executor_handler.to_format_status()])return"\n".join(lines)