Skip to content

Broker (Developer Guide)

What It Does

The Broker builds order intents, submits them via REST, consumes Order WS updates, and maps FYERS order events into Backtrader bt.Order lifecycles.

Why It Exists

FYERS order behavior requires explicit reconciliation and fill deduplication. The broker centralizes these rules and keeps them consistent across strategies.

Config Dependencies

  • config/broker.yaml (environment and allow list)
  • config/state.yaml (runtime persistence)

With Backtrader

Set the broker on Cerebro and use broker.dispatch_order_notifications() for a heartbeat.

Without Backtrader

Use submit_order_intent(...) and consume dispatch_order_notifications(...) to maintain state without a full Cerebro loop.

Limitations

  • Live orders are blocked unless environment is LIVE or allow_live_orders is enabled.
  • place_order is single-shot; unknown state requires manual reconciliation.

Scenario Example

Scenario: You need to block CO/BO orders. - Set allowed_product_types to CNC/INTRADAY only. - The broker will raise a clear error for unsupported types.