This project is a multi-strategy, multi-account trade execution engine designed to work with Alpaca. The engine is capable of executing various trading strategies across multiple accounts and can be expanded to support other brokers in the future. It is developed to be easily deployed to a linux server.
- alpaca_api/: Contains the Alpaca API integration functions.
- historical_data/: Manages historical data fetching and updating.
- postgresql/: Contains the Flask application, database models, and PostgreSQL management scripts.
- schedulers/: Scheduler scripts for different trading strategies.
- systems/: Implementation of various trading strategies.
- crontab: Crontab configuration for scheduling tasks.
- maintenance.sh: Script for system maintenance.
- run_schedulers.sh: Script to run all schedulers.
- requirements.txt: Python dependencies.
-
Clone the repository:
git clone https://github.com/yourusername/yourrepository.git cd yourrepository
-
Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up the environment variables:
- Copy the .env files in alpaca_api and postgresql directories and fill in the required values.
- Configure your Alpaca API keys in .env:
API_PUBLIC=your_public_key API_SECRET=your_secret_key
- Configure your PostgreSQL database in .env:
DB_USER=your_db_user DB_PASSWORD=your_db_password DB_HOST=your_db_host DB_PORT=your_db_port DB_NAME=your_db_name
-
Navigate to the postgresql directory:
cd postgresql
-
Run the Flask application:
python flaskapp.py
- Run the run_schedulers.sh script to start all schedulers:
bash run_schedulers.sh
- Run the maintenance.sh script for system maintenance:
bash maintenance.sh
This script starts all the scheduler scripts in separate tmux
sessions.
This script performs system maintenance tasks such as terminating tmux
sessions, cleaning up the system, and rebooting.
The Flask application provides an interface to manage user accounts and their API keys.
- Endpoint:
/manage
- Methods:
GET
,POST
- Form Fields:
- email: User's email.
- api_public: Alpaca Public API key.
- api_secret: Alpaca Secret API key.
- stop_strategy: Checkbox to stop the strategy.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE(LICENSE) file for details.