Harvest algorithmic trading
cd
mkdir harvest
cd harvest
python3 -m venv ./
source bin/activate
pip install harvest-python[[BROKER]]
Replace BROKER with a brokerage/data source of your choice:
- Robinhood
- Alpaca
- Webull
- Kraken
- Polygon
pip install harvest-python[[Alpaca]]
Example...
from harvest.algo import *
from harvest.trader import *
class Watch(BaseAlgo):
def config(self):
self.watchlist = [["TSLA"]]
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()
Command...
harvest start -s yahoo -b paper
Add more stocks
from harvest.algo import *
from harvest.trader import *
class Watch(BaseAlgo):
def config(self):
self.watchlist = [['NVDA','TSLA','AAPL','MSFT','GOOGL','META','TSM','TCEHY','ORCL']]
self.interval = "1MIN"
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()