Skip to content

AlgoTrader is an algorithmic trading bot that utilizes Alpaca’s commission-free stock trading API to automate buy and sell decisions based on custom strategies.

License

Notifications You must be signed in to change notification settings

Pranavh-2004/AlgoTrader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AlgoTrader

AlgoTrader is a Python-based algorithmic trading bot that leverages the Alpaca API to automate stock trading. The bot supports real-time market data fetching, executing buy and sell orders, and employing trading strategies based on simple market conditions.

Features

  • Real-time Market Data: Fetches historical stock data with customizable timeframes.
  • Trading Strategies: Implements basic strategies, such as buying when the price drops below a threshold and selling when it rises above a set value.
  • Automated Trading: Executes buy and sell orders on the Alpaca platform based on strategy decisions.
  • Scheduler: Allows periodic execution of trading actions, ensuring continuous trading activity.

Disclaimer

This is a work in progress.
This project is under active development, and features may change or be incomplete. Please use with caution and contribute if you'd like to help improve it!

Installation

Prerequisites

  • Python 3.8+
  • An Alpaca account and API credentials. Sign up here.
  • Install dependencies using pip.

Step 1: Clone the Repository

git clone https://github.com/yourusername/AlgoTrader.git
cd AlgoTrader

Step 2: Set Up Virtual Environment

python3 -m venv venv
source venv/bin/activate  # For Windows, use `venv\Scripts\activate`

Step 3: Install Dependencies

pip install -r requirements.txt

Step 4: Configure API Keys

Add your Alpaca API key and secret to a configuration file (config.py) or as environment variables. (Recommended)

# config.py
API_KEY = "your-api-key"
API_SECRET = "your-api-secret"
BASE_URL = "https://paper-api.alpaca.markets"  # For paper trading

Alternatively, you can set your API keys as environment variables:

export API_KEY="your-api-key"
export API_SECRET="your-api-secret"
export BASE_URL="https://paper-api.alpaca.markets"

Usage

Running the Bot

To run the bot, simply execute the main script:

python bot/main.py

Trading Strategies

You can define your custom trading strategies by creating new strategy classes or modifying the existing ones in the strategies/ folder. The bot includes a simple strategy where it buys stocks if the price drops below a certain value and sells if the price rises above another threshold.

Example of a basic strategy (Refer to simple_strategy.py)

Scheduling Trades

You can use the built-in scheduler to automate periodic trading actions. (Refer to scheduler.py) The will execute the trade_function every 5 minutes.

Testing

Unit tests are available for the various components of the bot.

Running Tests

To run the tests, use:

pytest

Contributing

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes.
  4. Push to your forked repository.
  5. Create a pull request.

License

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

Acknowledgments

  • Alpaca API for providing commission-free stock trading APIs.
  • Pandas for data handling.
  • APScheduler for scheduling tasks.

About

AlgoTrader is an algorithmic trading bot that utilizes Alpaca’s commission-free stock trading API to automate buy and sell decisions based on custom strategies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages