Skip to content

DCA Executor

DCAExecutor: Manages the execution of Dollar Cost Averaging (DCA) strategies, allowing users to spread their investment across multiple orders over time to reduce the impact of volatility. It's designed for use in both spot and perpetual markets.

Initialization

    def create_dca_order(self, level: int):
        """
        This method is responsible for creating a new DCA order
        """
        price = self.config.prices[level]
        amount = self.config.amounts_quote[level] / price
        order_id = self.place_order(connector_name=self.config.exchange,
                                    trading_pair=self.config.trading_pair, order_type=self.open_order_type,
                                    side=self.config.side, amount=amount, price=price,
                                    position_action=PositionAction.OPEN)
        if order_id:
            self._open_orders.append(TrackedOrder(order_id=order_id))

Key Configs:

  • connector_name: The exchange the user is currently trading on
  • trading_pair: Specifies the trading pair
  • order_amount: Specifies the amount for each DCA order.
  • order_interval_seconds: Sets the time interval between orders.
  • total_orders: Determines the total number of orders to be executed.
  • order_type: Defines the type of orders to be placed (default is LIMIT).

The DCAExecutor class implements a Dollar Cost Averaging strategy, which is a popular method for mitigating the impact of volatility by spreading purchases or sales over time.

The DCA strategy is simple yet effective, involving the execution of orders at regular intervals regardless of the asset's price. This approach can lead to a lower average cost per share or unit over time, making it a favored strategy for long-term investors.

Spot vs Perpetual Behavior

The DCAExecutor class is versatile, designed to operate on both spot and perpetual exchanges. This allows for the implementation of DCA strategies across different market types:

  • On perpetual exchanges, it schedules orders at regular intervals to manage a position over time.
  • On spot exchanges, it executes a series of buy or sell orders to average out the entry or exit price of an asset.

Configuration

The DCAExecutor engages with the market by executing orders based on the DCAExecutorConfig. It applies the DCA strategy as follows:

    type = "dca_executor"
    exchange: str
    trading_pair: str
    side: TradeType
    leverage: int = 1
    amounts_quote: List[Decimal]
    prices: List[Decimal]
    take_profit: Optional[Decimal] = None
    stop_loss: Optional[Decimal] = None
    trailing_stop: Optional[TrailingStop] = None
    time_limit: Optional[int] = None
    mode: DCAMode = DCAMode.MAKER
    activation_bounds: Optional[List[Decimal]] = None

Execution Flow

Here's a simplified flow of how the DCAExecutor operates:

  1. The DCAExecutor initiates the first order based on the configured strategy parameters.
  2. It waits for the specified interval before executing the next order.
  3. This process repeats until all configured orders have been executed.
  4. The executor monitors each order's execution and manages any necessary adjustments or cancellations according to market conditions and strategy requirements.

Conclusion

The DCAExecutor is an essential component within Hummingbot for traders and investors looking to implement Dollar Cost Averaging strategies. By automating the execution of DCA orders, it simplifies the process of spreading out investments over time, which can help in managing the risks associated with market volatility. Whether for accumulating a position in a bullish market or distributing assets in a bearish scenario, the DCAExecutor provides a disciplined approach to market entry and exit.