DISCOVER THE FUTURE OF AI AGENTSarrow_forward

AlpacaTradingAgent: Enhanced Multi-Agent Alpaca Trading Framework

calendar_todayAdded Apr 22, 2026
categoryAgent & Tooling
codeOpen Source
PythonWorkflow Automation大语言模型Multi-Agent SystemLangGraphAI AgentsAgent & ToolingModel & Inference FrameworkAutomation, Workflow & RPAProtocol, API & IntegrationFinance

A multi-agent LLM financial trading framework built on LangGraph, enabling real-time and paper trading for stocks and cryptocurrencies via Alpaca API.

Overview#

A multi-agent LLM financial trading framework built on LangGraph, customized for Alpaca trading users, providing a closed loop from multi-dimensional analysis to trade execution.

Core Capabilities#

Trade Execution & Portfolio Management#

  • Direct trade execution via Alpaca API with Paper Trading and Live Trading modes
  • Margin trading and short selling support
  • Real-time portfolio tracking, position monitoring, and order management
  • Mixed asset input: traditional stocks (e.g., NVDA, AAPL) and cryptocurrencies (e.g., BTC/USD, ETH/USD)

Multi-Agent Collaboration#

  • Five parallel analysts: Market Analyst, Social Sentiment Analyst, News Analyst, Fundamental Analyst, Macro Analyst (via FRED API)
  • Structured Bull/Bear debate: Bull/Bear Researchers conduct adversarial reasoning on analyst outputs (configurable max_debate_rounds)
  • Decision & risk control: Trader Agent makes direction, size, and timing decisions; Risk Management & Portfolio Manager continuously evaluates portfolio risk and position sizing

Automation & Scheduling#

  • Auto-execution during trading hours, respecting market open times for different asset classes
  • Configurable periodic analysis (every N hours), optional auto-trade execution (auto_execute_trades)

LLM Deployment Flexibility#

  • Cloud OpenAI models with dual-model strategy: deep_think_llm and quick_think_llm
  • Local LLM support (LM Studio, Ollama, vLLM) via OpenAI-compatible endpoints
  • Graceful degradation: skips memory lookup if local endpoint lacks Embeddings API; online_tools=False bypasses OpenAI cloud-dependent web search

Architecture & Implementation#

Data Flow#

  1. Parallel collection: 5 analyst agents simultaneously fetch data via external tools (staggered with analyst_start_delay/analyst_call_delay to prevent API overload)
  2. Debate integration: Bull/Bear Researchers conduct multi-round debates on analysis results
  3. Decision execution: Trader Agent synthesizes trade instructions, executed via Alpaca API
  4. Risk review: Risk Management & Portfolio Manager evaluates risk exposure

External Data Sources#

Finnhub (stock news), FRED (macroeconomic data), CoinDesk (crypto news), DeFi Llama (crypto fundamentals), Twitter/Reddit (social sentiment)

Memory Mechanism#

Reflection Memory (Embeddings-based) with graceful degradation in local mode

Installation & Usage#

Basic Setup

git clone https://github.com/huygiatrng/AlpacaTradingAgent.git
cd AlpacaTradingAgent
pip install -r requirements.txt
cp env.sample .env
# Edit .env with Alpaca API keys and LLM config

Docker Deployment

docker-compose up -d --build

CLI Usage

python -m cli.main
# Supports: NVDA / BTC/USD / NVDA, ETH/USD, AAPL, BTC/USD

Web UI

python run_webui_dash.py
# Default: http://localhost:7860

Python API

from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG

ta = TradingAgentsGraph(debug=True, config=DEFAULT_CONFIG.copy())
_, decision = ta.propagate("NVDA", "2024-05-10")
print(decision)

Use Cases#

  • AI-driven paper trading strategy testing
  • Multi-asset (stocks + crypto) comprehensive analysis research
  • Scheduled automated trading system deployment
  • Education and research on LLM multi-agent collaboration in financial risk control

⚠️ Disclaimer: For educational and research purposes only. Not financial, investment, or trading advice. Released under Apache-2.0.

Known Limitations#

  • No standalone backtesting engine; no verified historical performance data
  • Upstream TradingAgents (TauricResearch) repository maintenance status unclear
  • README references gpt-5-mini, likely a typo for gpt-4o-mini
  • API rate limits for CoinDesk and other external data sources undocumented
  • Web UI lacks screenshots or demo recordings; actual frontend completeness unconfirmed

Related Projects

View All arrow_forward

STAY UPDATED

Get the latest AI tools and trends delivered straight to your inbox. No spam, just intelligence.

rocket_launch