Skip to content
All library documents

How a DCA Executor Schedules Orders Across Spot and Perpetual Markets

Article Hummingbot docs

Summary

The document describes an automated dollar-cost averaging executor that distributes an entry or exit across a sequence of orders. Its configuration includes a market, trading pair, side, order amounts and prices, leverage, order mode, and optional profit, loss, trailing-stop, and time limits. The example order routine converts a quote-denominated amount into asset quantity at the configured price and tracks successfully placed orders.

The stated execution flow starts with an initial order, waits for the configured interval, then repeats until the order set is complete while monitoring fills and managing adjustments or cancellations. The executor is intended for both spot and perpetual markets: spot orders can average an acquisition or sale price, while perpetual orders build or manage a position. The document gives an implementation overview rather than empirical results. DCA spreads execution over time but does not guarantee a lower average price or reduce every form of risk; outcomes depend on market movement, order parameters, and execution behavior.

Key ideas

  • DCA divides a planned trade into multiple orders placed over time.
  • The executor uses configured amounts, prices, order type, and timing to place and track orders.
  • The described configuration includes optional profit, loss, trailing-stop, and time limits.
  • The method applies to spot trades and perpetual positions, with different position-management contexts.
  • The document explains a software flow but provides no performance evidence or guarantee of improved outcomes.

Tags

Full text
# dcaexecutor


**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

```python
    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](https://github.com/hummingbot/hummingbot/blob/master/hummingbot/strategy_v2/executors/dca_executor/dca_executor.py) 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:

```python
    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.

---

Shown in full with attribution under the source's licence. Licence: Apache-2.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.