Adding a Strategy
Directory Structure
custom_modules/strategies/<your strategy name>/custom_modules/ ├── strategies/ │ ├── my_strategy/ │ │ └── strategy.py
Implementing a Custom Strategy
from ats.strategies.base_strategy import BaseStrategy from ats.exchanges.data_classes.candle import Candle class Strategy(BaseStrategy): def validate_config(self) -> None: """ Validates the strategy-specific configuration. Raise an exception if any required config is missing or invalid. """ if "required_key" not in self.config: raise ValueError("Missing required configuration: 'required_key'") # Add additional validation logic here. def on_candle(self, candle: Candle) -> None: """ Implements the core logic of the strategy. This method is triggered whenever a new candle is received. Args: candle: The received Candle object. Returns: None """ # Example strategy logic: Print the candle close price print(f"Received candle close price: {candle.close}") def on_stop(self) -> None: """ Logic to execute when the strategy is stopped. This can include cleaning up resources or saving states. """ print("Strategy stopped.")
Accessing Exchange from the Strategy
Configuration Validation
Notes on Strategy Logic
Last updated