Harvest is a simple yet flexible Python framework for algorithmic trading. Paper trade and live trade stocks, cryptos, and options!12 Visit here for tutorials and documentation.
The example below is an algorithm to trade Twitter stocks using the moving average crossover strategy.
from harvest.algo import *
from harvest.trader import *
class Watch(BaseAlgo):
def config(self):
self.watchlist = ["TWTR"]
self.interval = "5MIN"
def main(self):
sma_long = self.sma(period=50)
sma_short = self.sma(period=20)
if self.crossover(sma_long, sma_short):
self.buy()
elif self.crossover(sma_short, sma_long):
self.sell()
To paper trade using this algorithm, run the following command:
harvest start -s yahoo -b paper
To live trade using Robinhood, run:
harvest start -s robinhood -b robinhood
With Harvest, the process of testing and deploying your strategies is a piece of cake 🍰
The only requirement is to have Python 3.9 or newer.
Once you're ready, install via pip:
pip install harvest-python
Next, install the dependencies necessary for the brokerage of your choice:
pip install harvest-python[BROKER]
Replace BROKER
with a brokerage/data source of your choice:
- Robinhood
- Alpaca
- Webull
- Kraken
- Polygon
Now you're all set!
Contributions are greatly appreciated. Check out the CONTRIBUTING document for details, and ABOUT for the long-term goals of this project.
- Harvest is not officially associated with Robinhood, Alpaca, Webull, Kraken, Polygon, or Yahoo.
- Many of the brokers were also not designed to be used for algo-trading. Excessive access to their API can result in your account getting locked.
- Tutorials and documentation solely exist to provide technical references of the code. They are not recommendations of any specific securities or strategies.
- Use Harvest at your own responsibility. Developers of Harvest take no responsibility for any financial losses you incur by using Harvest. By using Harvest, you certify you understand that Harvest is a software in early development and may contain bugs and unexpected behaviors.
- Trunk is a wrapper around linters. see
trunk.yaml
for details on which linters are enabled - Currently we run
ruff
which supports isort, pylint, black - For the best experience, please install the proper extensions under vscode "recommended extensions"
- To run lint checks manually, use
trunk check
, to run formatters, usetrunk fmt
- To run lint & format checks automatically, install the extensions recommended and save