Backtrader Setup
This page shows the recommended way to wire fyers-store into Backtrader.
Recommended Pattern
Use one Store per process and share it across Broker and DataFeed.
from fyers.auth import config_from_yaml, get_access_token
from fyers_store import FyersBroker, FyersData
from fyers_store.adapters import FyersDataWsAdapter, FyersOrderWsAdapter, FyersSdkRestAdapter
from fyers_store.store import FyersStore
from logging_module.config import setup_logging
setup_logging()
cfg = config_from_yaml()
access_token = get_access_token(cfg)
ws_token = f"{cfg.client_id}:{access_token}"
rest = FyersSdkRestAdapter(config=cfg)
data_ws = FyersDataWsAdapter(access_token=ws_token, config_path="config/fyers_ws.yaml")
order_ws = FyersOrderWsAdapter(access_token=ws_token, config_path="config/fyers_ws.yaml")
store = FyersStore(rest_adapter=rest, market_ws_adapter=data_ws, order_ws_adapter=order_ws)
broker = FyersBroker(store=store)
data = FyersData(store=store, dataname="NSE:SBIN-EQ", resolution="1", historical=False)
What NOT To Do
- Do not create multiple Store instances for the same process.
- Do not start the Order WS before reconciliation completes.
- Do not ignore AuthError or ReconcileFailureError.
Scenario Example
Scenario: You start the data feed but orders never update.
- Ensure the broker is created and started so the Order WS is running.
- Use a heartbeat to drain order notifications (see docs/usage/order-heartbeat.md).