Yosafxai/AionVanguard_Autonomous
AionVanguard - Autonomous Trading Agent
This project is an autonomous trading agent designed to execute trades based on a robust technical analysis strategy. It features a decoupled, multi-threaded architecture and a responsive user interface built with Streamlit for easy monitoring and control.

Table of Contents
- Overview
- Architecture
- Features
- Deployment to Streamlit Cloud
- Local Setup
- Configuration
- Code Structure
- Testing
Overview
AionVanguard is a Python-based autonomous trading agent. It uses a Moving Average (MA) Crossover strategy combined with a Relative Strength Index (RSI) filter to identify trading opportunities. The agent is designed for robustness and maintainability, with a clear separation between its core logic and the user interface.
Architecture
The agent is built with a modern, decoupled architecture to ensure stability and responsiveness:
- Multi-Threaded Design: The core
TradingAgentruns in a separate background thread from the Streamlit UI. This ensures that the agent's long-running tasks (like fetching data and checking for signals) do not block or freeze the user interface. - Message Queue Communication: The background agent communicates with the front-end via a thread-safe message queue (
queue.Queue). This allows the agent to send logs, status updates, and position changes to the UI in a safe and organized manner. - Decoupled Logic: The agent's core logic (
agent.py) is completely independent of the Streamlit framework, making it easier to test, maintain, and potentially reuse in other applications.
Features
- Core Strategy: A classic and effective Moving Average Crossover with RSI Filter.
- A "BUY" signal is generated when the short-term MA crosses above the long-term MA, provided the RSI is not in overbought territory.
- A "SELL" signal is generated when the short-term MA crosses below the long-term MA, provided the RSI is not in oversold territory.
- Risk Management: Implements position sizing, stop loss, take profit, and daily risk limits.
- Broker Flexibility: Modular design allows for integration with brokers like Alpaca, Binance, etc. (Currently, Alpaca is implemented).
- Live Dashboard: A Streamlit-based UI for real-time monitoring, control, and performance tracking.
Deployment to Streamlit Cloud
The easiest way to deploy this application is using Streamlit Cloud, which integrates directly with your GitHub repository.
- Click the Deploy Button: Click the "Deploy to Streamlit Cloud" button at the top of this README.
- Connect Your Account: If you haven't already, you'll be prompted to connect your GitHub account to Streamlit Cloud.
- Deploy: Follow the on-screen instructions. Streamlit Cloud will automatically detect the repository and the
streamlit_app.pyfile and deploy the application. - Add Secrets: Once deployed, you will need to add your broker API keys as secrets in the Streamlit Cloud settings for your app. Go to your app's settings (
...->Settings->Secrets) and add your keys (e.g.,ALPACA_API_KEY_ID,ALPACA_API_SECRET_KEY).
Local Setup
- Clone the repository:
git clone https://github.com/Hali-creater/AionVanguard.git
cd AionVanguard- Install dependencies:
pip install -r requirements.txt- Launch the Dashboard:
streamlit run streamlit_app.pyConfiguration
The agent is configured using environment variables. For local development, you can create a .env file in the project root. For Streamlit Cloud deployment, use the built-in Secrets management.
Example `.env` file:
# --- Broker Configuration ---
BROKER=Alpaca
ALPACA_API_KEY_ID=YOUR_ALPACA_API_KEY_ID
ALPACA_API_SECRET_KEY=YOUR_ALPACA_API_SECRET_KEY
ALPACA_BASE_URL=https://paper-api.alpaca.marketsCode Structure
.
├── README.md
├── requirements.txt
├── streamlit_app.py
└── autonomous_trading_agent/
├── __init__.py
├── agent.py <-- Core agent logic
├── adaptability/
├── broker_integration/
├── data_fetching/
├── execution/
├── risk_management/
├── strategy/
└── tests/Testing
The project includes a tests/ directory with robust unit and integration tests. Run tests using pytest from the project root. It is recommended to run it as a Python module to ensure it uses the correct environment.
python3 -m pytest