Skip to content

Data Feed (src/fyers_store/data_feed.py)

The DataFeed is a poll-based bridge between WebSocket messages and Backtrader bar delivery. It keeps the Backtrader loop responsive by draining the market queue in bounded batches with a time budget.

flowchart TD
    FEED["FyersData<br/>(data_feed.py)"]
    STORE["FyersStore<br/>(store.py)"]
    MKT_QUEUE["Market WS queue"]
    NORMALIZE["normalize_bar()<br/>(models)"]
    BAR_Q["internal bar queue"]
    STALL["stall warning<br/>(no data)"]

    FEED --> STORE
    STORE --> MKT_QUEUE
    FEED -->|"drain_market_messages(max=N)"| STORE
    STORE -->|"get_nowait loop"| MKT_QUEUE
    FEED --> NORMALIZE
    NORMALIZE --> BAR_Q
    BAR_Q -->|"Backtrader _load()"| FEED

    FEED -.stale threshold exceeded.-> STALL