A multi-agent autonomous trading analysis system that provides real-time stock recommendations via Telegram. Built with AutoGen, TwelveData, and NewsAPI.
This agent leverages a "Chain of Thought" approach to stock analysis. When a user sends a stock symbol (e.g., AAPL, NVDA), the system orchestrates multiple agents to fetch technical data and market news, perform sentiment analysis, and generate a unified trade recommendation.
The system follows a structured pipeline designed to mimic a professional day trader's workflow:
Upon receiving a symbol, the system triggers parallel requests to:
- TwelveData API: Fetches OHLCV (Open, High, Low, Close, Volume) data for three timeframes:
1m,15m, and1h. - NewsAPI: Fetches the most recent and relevant news articles from the past 24 hours.
The news articles are passed to the SentimentAnalyzer agent. This agent:
- Evaluates market reaction and news impact.
- Determines a category (
Positive,Neutral,Negative). - Calculates a sentiment score (
-1to1). - Provides a rationale with key headlines.
The TradeDecisionAgent aggregates the multi-timeframe candle data and the sentiment report. It follows these steps:
- Trend Confirmation: Uses
1hdata to identify the primary trend. - Entry Signals: Analyzes
1mand15maction for optimal entry levels. - Sentiment Integration: Weighs the technical signals against real-time market sentiment.
- Output Generation: Produces a structured recommendation including Buy/Sell/Hold, Entry Price, Stop-Loss, Target Price, and a detailed Rationale.
This project uses uv, an extremely fast Python package manager.
If you haven't installed uv yet, run:
# macOS/Linux
curl -lsSf https://astral.sh/uv/install.sh | shgit clone https://github.com/alfredang/stock_analysis_telegram_agent.git
cd stock_analysis_telegram_agentInitialize the project and install dependencies:
uv syncThis will automatically create a virtual environment in .venv and install all required packages.
Create a .env file in the root directory and add your API keys:
OPENAI_API_KEY=your_openai_key
TWELVEDATA_API_KEY=your_twelvedata_key
NEWSAPI_API_KEY=your_newsapi_key
TELEGRAM_BOT_TOKEN=your_telegram_bot_tokenuv run stock_agent.pyTo verify the analysis logic without Telegram, you can run the interactive test script:
uv run test_analysis.pyWhen prompted, enter a stock ticker (e.g., AAPL, NVDA). The script will fetch the multi-timeframe candle data, perform sentiment analysis, and display the final unified trade recommendation with rationale directly in your terminal.
MIT