Skip to content

Auth (Developer Guide)

What It Does

src/fyers/auth.py manages the FYERS login flow, token generation, and token persistence.

Why It Exists

FYERS sessions are short-lived and can be invalidated. Centralizing auth avoids duplicated logic and inconsistent token handling.

Config Dependencies

  • config/fyers_credentials.yaml
  • FYERS_CREDENTIALS_YAML override
  • FYERS_TOKEN_PATH override

With Backtrader

Auth is used indirectly by the REST adapter during startup.

Without Backtrader

Call config_from_yaml() and get_access_token() directly in scripts.

Limitations

  • Network calls are required; mock them in tests.
  • Tokens are refreshed at a daily IST cutoff.

Scenario Example

Scenario: You need to refresh tokens before market open. - Run fyers-auth as part of your pre-open checklist.