Skip to content

AttributeError: 'Alpaca' object has no attribute 'process_pending_orders' during await_market_to_close in live trading #1113

Description

@emagine-tech

Lumibot version: 4.5.62
alpaca-py version: 0.43.4
Broker: Alpaca (live/paper trading, not backtesting)
Python: 3.12

Description

During live paper trading, the strategy crashed after market close with the following traceback. The strategy was running normally throughout the day (entries and fills processed correctly via the trade-event stream), and the crash occurred specifically inside await_market_to_close().

2026-07-07 18:17:35,988 | ERROR | strategy_executor.py:run:2222 | [EmaCrossover] Traceback (most recent call last):
  File "lumibot/strategies/strategy_executor.py", line 2217, in run
    self._run_trading_session()
  File "lumibot/strategies/strategy_executor.py", line 2027, in _run_trading_session
    self.strategy.await_market_to_close()
  File "lumibot/strategies/strategy.py", line 1091, in await_market_to_close
    return self.broker._await_market_to_close(timedelta, strategy=self)
  File "lumibot/brokers/alpaca.py", line 379, in _await_market_to_close
    self.process_pending_orders(strategy=strategy)
AttributeError: 'Alpaca' object has no attribute 'process_pending_orders'

Expected behavior

process_pending_orders appears to be a method defined on BacktestingBroker (used to simulate fills bar-by-bar during backtests). It should not be called unconditionally from a code path that also runs for live brokers like Alpaca, which reports fills via the trade-event stream instead and has no such method.

Actual behavior

Alpaca._await_market_to_close() calls self.process_pending_orders(strategy=strategy) regardless of broker type, causing an AttributeError and crashing the strategy process every day at/after market close.

Impact

The process was auto-restarted by pm2 within seconds, so no trades were missed and no live orders were affected — the crash occurs after market close during end-of-day housekeeping, not during active trading. However, this means the strategy relies entirely on an external process manager to recover daily, and the crash would not be caught if pm2 restart limits were ever exhausted.

Steps to reproduce

  1. Run a live (or paper) strategy on the Alpaca broker via Lumibot 4.5.62
  2. Let the strategy run through await_market_to_close() at end of trading day
  3. Observe the AttributeError in logs shortly after market close

Suggested fix

Guard the process_pending_orders call in alpaca.py's _await_market_to_close so it's only invoked when the broker actually implements it (e.g., hasattr check, or move the call to BacktestingBroker-specific code path only).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions