目录

AI Trader Frontend

License Python Streamlit

A Streamlit dashboard application for visualizing trading account information and positions from the Alpaca Trading API. The dashboard displays portfolio value, positions, profit/loss metrics, and trading diary entries.

📊 Features

  • Real-time Account Data: View portfolio value, cash balance, and buying power
  • Positions Tracking: Monitor your positions with detailed information on current prices, market values, and profit/loss
  • Trading Diary: Keep track of your trading thoughts and strategies with date-organized diary entries
  • Collapsible Interface: Clean UI with collapsible diary sections and intuitive navigation

🛠️ Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/ai-trader-frontend.git
    cd ai-trader-frontend
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables in a .env file:

    ALPACA_API_KEY=your_api_key
    ALPACA_SECRET_KEY=your_secret_key
    ALPACA_PAPER=true  # Use paper trading account

🚀 Usage

  1. Run the Streamlit dashboard:

    cd dashboard
    streamlit run app.py
  2. Update portfolio data:

    cd dashboard/update_jobs
    python positions_job.py
  3. Deploy to Streamlit Cloud:

    • Connect your GitHub repository to Streamlit Cloud
    • Set the main file path as dashboard/app.py
    • Add your environment variables (ALPACA_API_KEY, ALPACA_SECRET_KEY, ALPACA_PAPER)
  4. Automated Data Updates: This project includes a GitHub Actions workflow that automatically updates portfolio data every 15 minutes.

    To set up automated updates:

    • Push this repository to GitHub
    • Add your Alpaca API keys as GitHub secrets:
      • ALPACA_API_KEY
      • ALPACA_SECRET_KEY
      • ALPACA_PAPER (optional, defaults to true)
    • The workflow will run every 15 minutes, fetch new data, and commit it to your repository
    • Streamlit Cloud will automatically use the latest data

📁 Project Structure

  • dashboard/app.py - Main Streamlit application
  • dashboard/data/snapshots/ - JSON files of account snapshots
  • dashboard/data/diary/ - Markdown files for trading diary entries
  • dashboard/update_jobs/positions_job.py - Job for fetching data from Alpaca API

📝 Data Format

  • Snapshots: JSON files with naming pattern {agent_name}_{YYYYMMDD_HHMMSS}.json
  • Diary Entries: Markdown files with naming pattern {agent_name}_{YYYY-MM-DD}.md

🔑 Environment Variables

  • ALPACA_API_KEY: API key for Alpaca
  • ALPACA_SECRET_KEY: Secret key for Alpaca
  • ALPACA_PAPER: Whether to use paper trading (default: true)

📸 Screenshots

Dashboard Overview

🔄 Data Flow

Alpaca Trading API → positions_job.py → JSON snapshots → app.py → Dashboard UI

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

🙏 Acknowledgements

  • Alpaca API - For providing the trading API
  • Streamlit - For the awesome dashboard framework
  • Pandas - For data manipulation capabilities
关于
25.1 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号