How office365/financial-agent-india works
What this project is (type + purpose)
This repo is a Python CLI-style “agent” toolkit (not a deployed service) that:
• Authenticates to AngelOne SmartAPI (Indian market brokerage API)
• Fetches equity OHLCV (and optionally options chain with Greeks/IV/OI)
• Sends structured market data to Anthropic Claude for LLM-driven analysis
• Includes a reference order placement script (dry-run by default)
So your “system” is primarily: User → Python scripts → external APIs (AngelOne, Anthropic) with credentials loaded from .env.
File tree into architectural components
Use the file tree as your authoritative decomposition (each file is effectively a component/module boundary):
• Configuration / Secrets
• .env.example, config.py
• Responsibility: load API keys, client ID/password, TOTP secret, Anthropic key.
• Brokerage API Integration (AngelOne SmartAPI)
• connect.py
• Responsibility: login + session creation (tokens like session/feed token).
• (Implicit sub-responsibilities: TOTP generation, error handling)
• Market Data Retrieval
• fetch_data.py
• Responsibility: pull 30 days daily candles (OHLCV) for a symbol token.
• Data output: printed table / returned data structure.
• LLM Agent (Core Analysis)
• agent.py
• Responsibility: orchestrate connect → fetch equity candles → prompt Claude → parse/print structured analysis.
• LLM Agent (Enhanced with Options)
• agent_with_options.py
• Responsibility: connect → fetch equity candles + options chain → prompt Claude with combined context → parse/print deeper analysis.
• Trading Action (Scaffold)
• place_order.py
• Responsibility: demonstrate SmartAPI order placement flow; gated by DRY_RUN.
• Project dependencies
• requirements.txt
This structure strongly suggests a pipeline/orchestrator pattern (agent scripts orchestrate calls) rather than layered web architecture.
Python Runtime / Scripts
• agent.py
• agent_with_options.py
• fetch_data.py
• connect.py
• place_order.py
• config.py (shared config/secrets loader)
AngelOne SmartAPI
• Auth endpoint (session/token)
• Market data endpoints (candles, quotes)
• Options chain endpoints
• Order endpoints
• (Optional future: WebSocket streaming, but not shown as implemented unless you add it)
Anthropic API (Claude)
• Prompt + response for analysis
Credentials/Secrets
• From .env: API keys, client creds, TOTP secret
Session Tokens
• Session token / feed token returned by SmartAPI login
Market Data Payloads
• OHLCV candles
• Options chain snapshot (IV/OI/Greeks)
LLM Prompt + Structured Output
• Trend/support/resistance/volume summary (+ options interpretation)
User → agent.py
• Inputs: --symbol, --token (or defaults)
agent.py → config.py
• Reads .env secrets
agent.py → connect.py → AngelOne SmartAPI (Auth)
• Sends: client ID + password + TOTP + API key
• Receives: session token, feed token
agent.py → AngelOne SmartAPI (Market Data)
• Requests: historical candles (30 days daily OHLCV)
• Receives: OHLCV array/time series
agent.py → Anthropic Claude
• Sends: prompt containing OHLCV (and any derived stats) + instructions for structured output
• Receives: structured analysis text/JSON-like output
agent.py → User
• Prints formatted report
Enhanced flow (agent_with_options.py)
Same as above, plus:
• agent_with_options.py → AngelOne SmartAPI (Options Chain)
• Receives: chain with IV/OI/Greeks
• agent_with_options.py → Claude
• Sends: combined equity candles + options chain context
Order scaffold flow (place_order.py)
• User → place_order.py
• place_order.py → connect/auth → SmartAPI order endpoint
• Explicitly annotate DRY_RUN gate:
• If DRY_RUN=True, no external order call is executed (or request is not sent).
Architectural patterns / design principles to highlight
• Orchestrator scripts: agent.py and agent_with_options.py orchestrate multiple integrations.
• Integration boundaries:
• “Brokerage API boundary” (SmartAPI)
• “LLM boundary” (Anthropic)
• Credential isolation: .env + config.py as the single source of secrets.
• Session-based auth: SmartAPI login yields tokens used for subsequent calls.
Use this as your “component inventory” so you don’t miss anything:
• Local Execution Environment
• Python 3.8+
• requirements.txt dependencies (SDKs for SmartAPI + Anthropic; TOTP library likely)
• Config/Security
• .env (ANGELONE_API_KEY, CLIENT_ID, PASSWORD, TOTP_SECRET, ANTHROPIC_API_KEY)
• config.py (loader)
• SmartAPI Integration
• connect.py (auth/session token generation)
• Data endpoints used by fetch_data.py / agents
• Order endpoint used by place_order.py
• LLM Integration
• Prompt construction in agent.py / agent_with_options.py
• Output parsing/formatting (even if lightweight, show it as “Response formatting”)
“Don’t overthink it” rule for this repo
• Treating each script as a first-class component
• Treating AngelOne and Anthropic as distinct external subsystems
• Explicitly drawing session/token and prompt/response flows