Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Systrade: Live Trading Application

This project implements a robust algorithmic trading engine in Python, capable of both historical backtesting and live trading using the Alpaca API. It features a modular architecture with abstract history providers, corporate action adjustments, and a containerized live trading loop.

Project Structure

Here is where to find the key components of the project:

  • systrade/: The core Python package.
    • alpaca.py: (New) Live Feed and Broker implementations using alpaca-py.
    • history.py: (New) Abstract HistoryProvider with implementations for CSV files and QuestDB (including split/dividend adjustments).
    • feed.py: (Refactored) HistoricalFeed now accepts generic providers and handles sparse data gaps.
    • strategies.py: (New) Contains the MomentumStrategy logic that is used in live trading. This can be adapted to fit another trading strategy.
    • engine.py & broker.py: Core event loop and backtesting logic.
  • run_live.py: The main entry point for the live trading application.
  • Dockerfile: Configuration for building the application container.
  • tests/: Unit tests for the new components (Alpaca Connection, Corporate Action Adjustments, Feeds).

How to Build and Run

This application is containerized in Docker for easy deployment through background processes. To install locally instead of through a container (container is recommended), run

pip install .

in the root directory. Add -e flag for editable mode.

1. Build the Image

Run the following command in the project root directory:

docker build -t systrade .

2. Run the Program

Run the following command to start the application:

docker run --name systrade-final --restart unless-stopped -e ALPACA_API_KEY=YOUR_ALPACA_API_KEY -e ALPACA_SECRET=YOUR_ALPACA_API_SECRET systrade 

Optional Parameters:

  • Pass in -d flag to run in daemon mode (don't need to keep terminal open)
  • Pass in --interval flag (set to 1m for minute and 1d for daily bars), default is 1m
  • Pass in --symbol flag to set symbol you want to trade, default is SPY

3. View Activity

To view trading logs and activity, run the following command:

docker logs -f systrade-final

and

docker logs systrade-final > trading_log.txt

to save the logs to a file.

To stop the bot, run the following command:

docker stop systrade-final

Key Features Implemented

  • Abstract History Providers: Able to accept CSV or QuestDB (new!) database as inputs for backtesting engine
  • Corporate Actions: adjusted parameter in feed setup in backtest, which automatically calculates adjusted prices
  • Refactored Feed: Now supports multiple providers and handles sparse data (forward-filling gaps).
  • Alpaca Integration: Polls the API for 1-minute bars via IEX and handles order submission/fill reporting. Set paper=False in run_live.py if you are not paper trading.

Running Tests

To run the unit tests:

docker run --rm systrade-final pytest

if running containerized, otherwise

pytest

if running locally. Note: You will need a Tiingo API key to run the corporate action adjustment verification test. If so, add it to your environment under TIINGO_API_KEY.

About

Algorithmic live trading bot using Python and Alpaca API, containerized with Docker. Backtesting engine with QuestDB integration included.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages