DCA 执行器
DCA 执行器:负责执行定投(Dollar Cost Averaging, DCA)策略,允许用户将投资分散在多个订单中随时间逐步完成,以降低市场波动的影响。该执行器适用于现货和永续合约市场。
初始化¶
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))
关键配置项:
connector_name:用户当前进行交易的交易所trading_pair:指定交易对order_amount:指定每个 DCA 订单的金额order_interval_seconds:设置订单之间的时间间隔(秒)total_orders:确定要执行的订单总数order_type:定义要下单的类型(默认为限价单 LIMIT)
类 DCAExecutor 实现了一种定投(Dollar Cost Averaging)策略,这是一种通过在一段时间内分散买入或卖出操作来减轻市场波动影响的常用方法。
DCA 策略简单而有效,其核心是在固定时间间隔执行订单,而不考虑资产价格。这种方法可以随时间推移降低每股或每单位的平均成本,因此受到长期投资者的青睐。
现货与永续合约行为对比¶
类 DCAExecutor 具有良好的适应性,可在现货和永续合约交易所中运行,从而支持在不同类型市场中实施 DCA 策略:
- 在永续合约交易所中,它会按固定时间间隔下达订单,以实现对头寸的长期管理。
- 在现货交易所中,它会执行一系列买入或卖出订单,以摊低资产的建仓或平仓均价。
配置¶
DCAExecutor 根据 DCAExecutorConfig 配置与市场交互,并按以下方式应用 DCA 策略:
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
执行流程¶
以下是 DCAExecutor 运作流程的简化说明:
DCAExecutor根据配置的策略参数发起第一个订单。- 等待设定的时间间隔后,再执行下一个订单。
- 此过程重复进行,直到所有预设的订单均已执行完毕。
- 执行器会监控每个订单的执行情况,并根据市场状况和策略要求进行必要的调整或取消操作。
结论¶
DCAExecutor 是 Hummingbot 中帮助交易者和投资者实施定投策略的关键组件。通过自动化执行 DCA 订单,它简化了将投资分散到不同时间段的过程,有助于应对市场波动带来的风险。无论是在牛市中逐步建仓,还是在熊市中分批卖出资产,DCAExecutor 都提供了一种纪律性的市场进出方法。