diff --git a/.github/workflows/manual-analysis.yml b/.github/workflows/manual-analysis.yml new file mode 100644 index 00000000..2fca5116 --- /dev/null +++ b/.github/workflows/manual-analysis.yml @@ -0,0 +1,62 @@ +name: Manual TradingAgents Analysis + +on: + workflow_dispatch: + inputs: + ticker: + description: 'Stock ticker symbol to analyze' + required: true + default: 'NVDA' + type: string + date: + description: 'Analysis date (YYYY-MM-DD format, leave empty for today)' + required: false + default: '' + type: string + +jobs: + analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Set analysis date + id: set_date + run: | + if [ "${{ github.event.inputs.date }}" != "" ]; then + echo "date=${{ github.event.inputs.date }}" >> $GITHUB_OUTPUT + else + echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT + fi + + - name: Create output directory + run: mkdir -p results/github-actions + + - name: Run TradingAgents Analysis + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + FINNHUB_API_KEY: ${{ secrets.FINNHUB_API_KEY }} + TRADINGAGENTS_TICKER: ${{ github.event.inputs.ticker }} + TRADINGAGENTS_DATE: ${{ steps.set_date.outputs.date }} + TRADINGAGENTS_OUTPUT_PATH: results/github-actions/analysis-${{ github.run_number }}.md + run: | + python cli/non_interactive.py + + - name: Upload analysis results + uses: actions/upload-artifact@v3 + with: + name: trading-analysis-${{ github.event.inputs.ticker }}-${{ steps.set_date.outputs.date }} + path: results/github-actions/ + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/trading-analysis.yml b/.github/workflows/trading-analysis.yml new file mode 100644 index 00000000..bf177e4e --- /dev/null +++ b/.github/workflows/trading-analysis.yml @@ -0,0 +1,133 @@ +name: TradingAgents Analysis + +on: + workflow_dispatch: + inputs: + ticker: + description: 'Stock ticker symbol to analyze' + required: true + default: 'NVDA' + type: string + date: + description: 'Analysis date (YYYY-MM-DD format)' + required: false + default: '' + type: string + deep_think_llm: + description: 'Deep thinking LLM model' + required: false + default: 'o4-mini' + type: string + quick_think_llm: + description: 'Quick thinking LLM model' + required: false + default: 'gpt-4o-mini' + type: string + max_debate_rounds: + description: 'Maximum debate rounds' + required: false + default: '1' + type: string + online_tools: + description: 'Use online tools (true/false)' + required: false + default: 'true' + type: string + debug: + description: 'Enable debug mode (true/false)' + required: false + default: 'false' + type: string + schedule: + # Run daily at 9 AM UTC (market open time) + - cron: '0 9 * * 1-5' + push: + branches: [ main ] + paths: + - 'tradingagents/**' + - 'cli/**' + - 'requirements.txt' + - '.github/workflows/trading-analysis.yml' + +jobs: + analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Cache pip dependencies + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Set analysis date + id: set_date + run: | + if [ "${{ github.event.inputs.date }}" != "" ]; then + echo "date=${{ github.event.inputs.date }}" >> $GITHUB_OUTPUT + else + echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT + fi + + - name: Create output directory + run: mkdir -p results/github-actions + + - name: Run TradingAgents Analysis + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + FINNHUB_API_KEY: ${{ secrets.FINNHUB_API_KEY }} + TRADINGAGENTS_TICKER: ${{ github.event.inputs.ticker || 'NVDA' }} + TRADINGAGENTS_DATE: ${{ steps.set_date.outputs.date }} + TRADINGAGENTS_DEEP_THINK_LLM: ${{ github.event.inputs.deep_think_llm || 'o4-mini' }} + TRADINGAGENTS_QUICK_THINK_LLM: ${{ github.event.inputs.quick_think_llm || 'gpt-4o-mini' }} + TRADINGAGENTS_MAX_DEBATE_ROUNDS: ${{ github.event.inputs.max_debate_rounds || '1' }} + TRADINGAGENTS_ONLINE_TOOLS: ${{ github.event.inputs.online_tools || 'true' }} + TRADINGAGENTS_DEBUG: ${{ github.event.inputs.debug || 'false' }} + TRADINGAGENTS_OUTPUT_PATH: results/github-actions/analysis-${{ github.run_number }}.md + run: | + python cli/non_interactive.py + + - name: Upload analysis results + uses: actions/upload-artifact@v3 + with: + name: trading-analysis-results-${{ github.run_number }} + path: results/github-actions/ + retention-days: 30 + + - name: Comment on PR (if triggered by PR) + if: github.event_name == 'pull_request' + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + try { + const resultsPath = 'results/github-actions/analysis-' + context.runNumber + '.md'; + if (fs.existsSync(resultsPath)) { + const content = fs.readFileSync(resultsPath, 'utf8'); + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `## š¤ TradingAgents Analysis Results\n\n${content}` + }); + } + } catch (error) { + console.log('Could not read or post results:', error.message); + } \ No newline at end of file diff --git a/GITHUB_ACTIONS.md b/GITHUB_ACTIONS.md new file mode 100644 index 00000000..1ddf4338 --- /dev/null +++ b/GITHUB_ACTIONS.md @@ -0,0 +1,141 @@ +# GitHub Actions for TradingAgents + +This document explains how to set up and use GitHub Actions to run TradingAgents analysis automatically. + +## Overview + +We've created two GitHub Actions workflows: + +1. **Manual TradingAgents Analysis** (`.github/workflows/manual-analysis.yml`) - Simple workflow for manual triggering +2. **TradingAgents Analysis** (`.github/workflows/trading-analysis.yml`) - Advanced workflow with more configuration options + +## Setup + +### 1. Add Repository Secrets + +You need to add the following secrets to your GitHub repository: + +1. Go to your repository on GitHub +2. Navigate to **Settings** ā **Secrets and variables** ā **Actions** +3. Add the following secrets: + - `OPENAI_API_KEY`: Your OpenAI API key + - `FINNHUB_API_KEY`: Your FinnHub API key + +### 2. Enable GitHub Actions + +The workflows will be automatically available once you push them to your repository. You can find them in the **Actions** tab. + +## Usage + +### Manual Analysis (Recommended for beginners) + +1. Go to the **Actions** tab in your repository +2. Select **Manual TradingAgents Analysis** +3. Click **Run workflow** +4. Fill in the required fields: + - **Ticker**: Stock symbol (e.g., `NVDA`, `AAPL`, `TSLA`) + - **Date**: Analysis date in YYYY-MM-DD format (leave empty for today) +5. Click **Run workflow** + +### Advanced Analysis + +1. Go to the **Actions** tab in your repository +2. Select **TradingAgents Analysis** +3. Click **Run workflow** +4. Configure all the parameters as needed: + - **Ticker**: Stock symbol + - **Date**: Analysis date + - **Deep Think LLM**: Model for deep thinking (default: `o4-mini`) + - **Quick Think LLM**: Model for quick thinking (default: `gpt-4o-mini`) + - **Max Debate Rounds**: Number of debate rounds (default: `1`) + - **Online Tools**: Whether to use online tools (default: `true`) + - **Debug**: Enable debug mode (default: `false`) + +## Environment Variables + +The non-interactive script (`cli/non_interactive.py`) uses the following environment variables: + +### Required +- `TRADINGAGENTS_TICKER`: Stock ticker symbol to analyze +- `OPENAI_API_KEY`: Your OpenAI API key +- `FINNHUB_API_KEY`: Your FinnHub API key + +### Optional +- `TRADINGAGENTS_DATE`: Analysis date (default: today) +- `TRADINGAGENTS_DEEP_THINK_LLM`: Deep thinking LLM model (default: `o4-mini`) +- `TRADINGAGENTS_QUICK_THINK_LLM`: Quick thinking LLM model (default: `gpt-4o-mini`) +- `TRADINGAGENTS_MAX_DEBATE_ROUNDS`: Maximum debate rounds (default: `1`) +- `TRADINGAGENTS_ONLINE_TOOLS`: Use online tools (default: `true`) +- `TRADINGAGENTS_DEBUG`: Enable debug mode (default: `false`) +- `TRADINGAGENTS_OUTPUT_PATH`: Path to save results (optional) + +## Results + +After the workflow completes: + +1. **Artifacts**: Analysis results are saved as GitHub artifacts that you can download +2. **Logs**: Full execution logs are available in the workflow run +3. **Output**: The final decision and analysis are displayed in the workflow output + +## Scheduled Runs + +The advanced workflow includes a scheduled run that executes daily at 9 AM UTC on weekdays (Monday-Friday). You can modify the schedule in the workflow file: + +```yaml +schedule: + - cron: '0 9 * * 1-5' # Daily at 9 AM UTC, Monday-Friday +``` + +## Local Testing + +You can test the non-interactive script locally: + +```bash +# Set environment variables +export OPENAI_API_KEY="your-openai-api-key" +export FINNHUB_API_KEY="your-finnhub-api-key" +export TRADINGAGENTS_TICKER="NVDA" +export TRADINGAGENTS_DATE="2024-01-15" + +# Run the analysis +python cli/non_interactive.py +``` + +## Troubleshooting + +### Common Issues + +1. **Missing API Keys**: Ensure both `OPENAI_API_KEY` and `FINNHUB_API_KEY` are set as repository secrets +2. **Invalid Ticker**: Make sure the ticker symbol is valid and exists +3. **Date Format**: Use YYYY-MM-DD format for dates +4. **API Limits**: Be aware of OpenAI and FinnHub API rate limits + +### Debug Mode + +Enable debug mode to get more detailed output: + +```yaml +TRADINGAGENTS_DEBUG: true +``` + +### Cost Optimization + +To reduce API costs: +- Use `o4-mini` and `gpt-4o-mini` models +- Set `max_debate_rounds` to `1` +- Use `online_tools: false` if you have cached data + +## Customization + +You can customize the workflows by: + +1. Modifying the workflow files in `.github/workflows/` +2. Adding new environment variables to the non-interactive script +3. Creating new workflows for specific use cases + +## Security Notes + +- Never commit API keys to your repository +- Use GitHub Secrets for sensitive information +- Consider using different API keys for testing vs production +- Monitor your API usage to avoid unexpected costs \ No newline at end of file diff --git a/README.md b/README.md index cac18691..cba54b0a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@