Trading-Bot_with_ALPACA

logo

Alpaca Trading Bot

Overview

This is a Python script that creates a trading bot using the Alpaca API. The bot scans for trading opportunities based on the top losing stocks and popular crypto assets from YahooFinance. It then uses the Alpaca API to execute buy and sell orders and sends notifications via Slack about the trades it makes.

Key Features

  • Retrieves historical market data for stocks and crypto via the Alpaca API
  • Calculates the rate of change (ROC) of the ask price for a list of stocks over a 1 minute timeframe
  • Compares the ask price and last traded price for the stock with the highest ROC
  • Places a buy order for the stock if ask price > last traded price, allocating 100% of capital
  • Sells the stock after a 2% gain
  • Sends trade notifications via Slack

Setup

To use the bot, you'll need:

  • An Alpaca account (paper trading account recommended)
  • API keys from Alpaca
  • Python installed with required libraries like alpaca-trade-api and pandas

Procedure:

1. Create a virtual environment `conda create -n trader python=3.10`
2. Activate it `conda activate trader`
3. Install initial deps `pip install lumibot timedelta alpaca-trade-api==3.1.1`
4. Install transformers and friends `pip install torch torchvision torchaudio transformers`
5. Update the `API_KEY` and `API_SECRET` with values from your Alpaca account
6. Run the bot `python tradingbot.py`

Usage

The bot can be run from the command line by executing the main Python script. It will automatically scan for trading opportunities, place orders, and send Slack notifications.

Other References 🔗

-Lumibot:trading bot library, makes lifecycle stuff easier .

Disclaimer

This bot is for educational and informational purposes only. It does not constitute financial advice. Past performance is not indicative of future results. Use at your own risk.