Home - pattertj/LoopTrader GitHub Wiki


LoopTrader

Key FeaturesHow To UseArchitectureLicense

Key Features

The goal for LoopTrader is to provide a flexible engine for running one or more option trading strategies in real-time against provided broker APIs. The Key Features include:

  • Simple to set up and run multiple trading bots
  • Extensibility for various brokers, trading strategies, and logging patterns
  • Local storage for trades and orders
  • Support for notifications and interactions through tools like Telegram

LoopTrader is very much a work in progress and is currently not feature complete. See the Issues for what remains open or to make a suggestion.

How To Use

Running LoopTrader does require some development experience. For example, configuring LoopTrader for various strategies, brokers, and enabling notifiers all take some editing of LoopTrader to work.

Configuring TD Ameritrade/ToS

Documentation for this process is in the wiki

How To Add Different Brokers

New Brokers can be added by creating a new class inheriting from Broker and Component and implementing the required abstract methods. This pattern will allow you to communicate with the Bot in a standard way and keep Brokers plug-and-play.

Configuring Telegram

The Telegram notifier uses the python-telegram-bot for communicating with Telegram. For personal use, you must install the module and create a new bot through @BotFather.

The required configuration parameters should be set up in LoopTrader's .env file using the documented Environment Variables.

# Telegram Notifier Variables
TELEGRAM_TOKEN= ""
TELEGRAM_CHATID= ""

Configuring Strategies

Strategies are currently configured in-code when the object is initialized. I plan to move this to YAML in a future enhancement.

How To Add Custom Strategies

Custom Strategies can be added by creating a new class inheriting from Strategy and Component and implementing the required abstract methods. This pattern will allow you to communicate with the bot in a standard way and keep strategies plug-and-play.

Architecture

LoopTrader is built on top of the latest version of Python and implements two main patterns: Mediator and Strategy

The Mediator pattern allows us to maintain independent components for the Broker API, Strategy, and Local DB's. This lets the user pick and choose the components to include in their Bot.

The Strategy pattern allows us to develop multiple implementations of trading strategies for the bot to execute.

The core components of LoopTrader are outlined below. For anyone interested in extending LoopTrader to a new Broker or Strategy, take a look at main.py for setting up your Bot and the sections below for how to extend the components.

Component

The Component abstract class is the base class for our Bot pieces; it should be on all classes that intend to be processed by the Bot.

Mediator

The Mediator abstract class is represented in its concrete form as the Bot; it is the core object for coordinating the Component pieces and handling the looping of Strategies.

Broker

The Broker abstract class represents the base class for concrete Broker implementations. This includes basic information about connecting to the Broker and Abstract Methods for acting on the Broker.

Notifier

The Notifier abstract class is how we can receive notifications and interact with our bot.

Database

The Database abstract class provides the scaffolding CRUD operations for various concrete local storage implementations.

Strategy

The Strategy abstract class is the base for all Strategies implemented in LoopTrader. Most of the logic within LoopTrader exists within the concrete Strategies to determine when to open and close positions. The first concrete strategy in progress is CashSecuredPuts, selected by target Delta.

⚠️ **GitHub.com Fallback** ⚠️