Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Y-Research-SBU/QuantAgent/llms.txt

Use this file to discover all available pages before exploring further.

TradingGraph is the top-level entry point for running QuantAgent analysis. It initializes the language models, the TechnicalTools toolkit, and the compiled LangGraph StateGraph that wires together the Indicator, Pattern, Trend, and Decision agents.

Constructor

TradingGraph(config=None)
config
dict
default:"DEFAULT_CONFIG"
Optional configuration dictionary. When None, DEFAULT_CONFIG is used. Accepts the following keys:
KeyTypeDefaultDescription
agent_llm_providerstr"openai"Provider for per-agent LLMs ("openai", "anthropic", or "qwen").
agent_llm_modelstr"gpt-4o-mini"Model name for the agent LLM.
agent_llm_temperaturefloat0.1Sampling temperature for the agent LLM.
graph_llm_providerstr"openai"Provider for the vision/graph LLM.
graph_llm_modelstr"gpt-4o"Model name for the graph LLM. Must be vision-capable.
graph_llm_temperaturefloat0.1Sampling temperature for the graph LLM.
api_keystrOpenAI API key. Falls back to OPENAI_API_KEY env var.
anthropic_api_keystrAnthropic API key. Falls back to ANTHROPIC_API_KEY env var.
qwen_api_keystrQwen (DashScope) API key. Falls back to DASHSCOPE_API_KEY env var.
graph_llm_model must be a vision-capable model. The Pattern and Trend agents pass base64-encoded chart images to this LLM for visual analysis.

Attributes

AttributeTypeDescription
configdictActive configuration dictionary.
agent_llmBaseChatModelLLM instance used by the Pattern and Trend agents for the tool-dispatch step (chart generation).
graph_llmBaseChatModelPrimary LLM instance used by the Indicator agent (tool calling and report), the Pattern and Trend agents (vision analysis), and the Decision agent (trade synthesis). Must be vision-capable.
toolkitTechnicalToolsToolkit providing all indicator and charting tools.
graphCompiledStateGraphThe compiled LangGraph graph. Call .invoke() on this to run a full analysis.

graph.invoke(initial_state)

Runs all four agents in sequence (Indicator → Pattern → Trend → Decision) and returns the completed state dictionary.

Parameters

initial_state
dict
required
The starting state passed into the graph. Required keys:

Return value

Returns the final IndicatorAgentState dictionary. Key output fields:
final_trade_decision
str
JSON string containing the trade decision. Fields: forecast_horizon, decision (LONG or SHORT), justification, and risk_reward_ratio.
indicator_report
str
Narrative report from the Indicator agent summarizing RSI, MACD, Stochastic, ROC, and Williams %R values.
pattern_report
str
Narrative report from the Pattern agent identifying classical candlestick formations.
trend_report
str
Narrative report from the Trend agent describing support/resistance lines and directional bias.

update_api_key(api_key, provider='openai')

Updates the API key in both self.config and the corresponding environment variable, then calls refresh_llms() to rebuild all LLM objects.
api_key
str
required
The new API key value.
provider
str
default:"openai"
The provider whose key to update. One of "openai", "anthropic", or "qwen".

refresh_llms()

Recreates agent_llm, graph_llm, the SetGraph instance, and the compiled graph from the current self.config. Call this after manually modifying self.config to apply the changes.

Example

import yfinance as yf
from trading_graph import TradingGraph

# Download recent 4-hour BTC/USD data
ticker = yf.Ticker("BTC-USD")
df = ticker.history(period="7d", interval="1h").tail(30)
df.index.name = "Datetime"
df = df.reset_index()[["Datetime", "Open", "High", "Low", "Close"]]
df["Datetime"] = df["Datetime"].astype(str)
kline_data = df.to_dict(orient="list")

# Initialize with a custom config
config = {
    "agent_llm_provider": "openai",
    "agent_llm_model": "gpt-4o-mini",
    "graph_llm_provider": "openai",
    "graph_llm_model": "gpt-4o",
    "agent_llm_temperature": 0.1,
    "graph_llm_temperature": 0.1,
    "api_key": "sk-...",
}
tg = TradingGraph(config=config)

# Build the initial state
initial_state = {
    "kline_data": kline_data,
    "analysis_results": None,
    "messages": [],
    "time_frame": "1h",
    "stock_name": "BTC-USD",
}

# Run the full multi-agent pipeline
final_state = tg.graph.invoke(initial_state)

import json
decision = json.loads(final_state["final_trade_decision"])
print(decision["decision"])         # "LONG" or "SHORT"
print(decision["justification"])
print(final_state["indicator_report"])
print(final_state["pattern_report"])
print(final_state["trend_report"])

Updating the API key at runtime

# Switch to Anthropic mid-session
tg.update_api_key("sk-ant-...", provider="anthropic")
tg.config["agent_llm_model"] = "claude-haiku-4-5-20251001"
tg.config["graph_llm_model"] = "claude-haiku-4-5-20251001"
tg.refresh_llms()

Build docs developers (and LLMs) love