A fully automated trading bot which analyses US stock market data with a variety of technical indicators **UPDATE** Crypto trading enabled
Please note: This repo and project is in no way affiliated with or endorsed by Alpaca. We also strongly advise that you thoroughly test this project, its settings and algorithms with a paper trading account. we accept no liability whatsoever in the usage of this project in accordance with the provided license.
The RoboBull Trading Bot is a fully automated trading bot which analyses stock market data with a variety of technical indicators. Technical indicators are mapped to specified weightings which determine whether a signal (BUY/SELL) is generated. If an overall weightings threshold is met, based on generated signals, an order is created.
The bot currently supports both live trading (paper account recommended) and historical back testing via Alpaca's API as an integrated trading provider and plan to support others in the future.
Unfortunately we no longer have an integrated Stock Screener for this project which provides market analyses and top performing stocks. Donations welcome to reactivate it!
Tip: If you want to use our stock screener, please get in touch and then enabled it by setting useStockScreener to true.
Tip: If the US markets are closed then you can use back testing instead.
Install using Docker Compose which requires you to install Docker:
Go to Alpaca and sign up for a free account. We recommend paper trading only for using this project. You don't need to spend real dollars to test this project. Once you have a paper trading account you can create your API key and secret which will be needed in the next step.
Copy .env-example and rename to .env and then add your Alpaca key (API_KEY) and secret (SECRET_API_KEY). Important: keep your key/secret locally, don't commit it or share with anyone.
Ensure you have edited your settings.json for live/paper trading or back testing
Run docker-compose up
Create a new user by going here: (http://localhost:3000/create-user). You'll then be redirected to the trading terminal. You only need to create a new user once.
Once you've created a new user, you can re-run the trading bot in the future by visiting (http://localhost:3000/run). However, you may need to stop the docker container and start it again to rerun the trading bot (this is due to only 1 connection allowed per trading account on Alpaca).
You can also visit (http://localhost:8081) to view and manage MongoDb data
It's worth familiarizing yourself with the basic settings before you run docker-compose up
during the installation. You can find all settings and their explanations later in this readme.
Tip: You need to restart your Docker container each time you make a change to your settings or code. Just Control-C out of the current process and then docker-compose up
again.
Tip: All positions will automatically close (sell) 15mins before end of the market closing. It may be beneficial to keep your positions, especially if you're at a loss, but its completely up to you. If you wish to do so, set useClosePositionsBeforeMarketClose to false (then restart the docker process).
Edit your stock symbols/tickers in this file. The stocks will be used as your default stocks for live trading as well as the stocks used for back testing (if enabled).
The algorithms / technical indicators are massively customizable and have been tested for optimal performance. It may be better to retain the current setup and use the basic properties below until you have spent time analysing your trading ROI (both live/paper and back testing).
Feel free to tweak the settings in algo.json file as much as you like. A more detailed explanation of algo settings is coming soon. Tip: You may want to increase the thresholdToBuy setting to 40 which will tell the bot to be stricter when buying stocks.
Edit your crypto symbols in this file. The crypto will be used for live trading (if enabled). Note: crypto has yet to be tested for backtesting.
This feature allows you to run live/paper trading 24/7 with crypto stocks/symbols. In order to run crypto mode you need to enable it by editing enableCrypto to true in the settings.json file. You can also edit the crypto symbols that will be subscribed to and traded within the crypto.json file.
This feature allows you to run both live/paper trading and back testing without the need of a web browser. In order to do this open a terminal tab:
docker-compose up
Then open another terminal tab:
docker exec -it $(docker ps -aqf "ancestor=trading-bot_app") npm run console
Change the following in settings.json, then re-run docker-compose up
and go to http://localhost:3000/run
alpaca
true
true
The code follows mostly the standard structure used within Express Framework related projects.
We love these dependencies to speed up development!
Big shout out to Kendel Chopp for Alpaca JS Backtesting and Anand Aravindan for Technical Indicators.
Moment (worth replacing with DayJs)
├── config
│ ├── algos.json # structured data for your algorithms / technical indicators along with weighting thresholds
│ ├── crypto.json # default selection of crypto to subscribe to (if enabled)
│ ├── settings.json # default settings for the trading bot
│ └── stocks.json # default selection of stocks to subscribe to
├── data # files used for persistent mongo data storage (git ignored)
├── docker # files required to run project in self contained docker environment
├── public # files required for frontend views such as css styling and javascript
├── src
│ ├── controllers # controller files which are called via routes / endpoints
│ ├── models # mongoose database schema models for reading / writing data to MongoDb
│ ├── providers # files / methods related to specific trading providers (currently only Alpaca)
│ ├── routes # contains the routes e.g. url structure
│ ├── services # contains services such as stocks, orders, portfolio
│ └── views # templates for frontend views such as HTML structure etc
├── .env # you'll need to create/edit this file copied from .env-example
├── .env-example # example for your .env variables
├── index.js # entry point to run trading via Express framework (via web browser)
├── console-only.js # entry point to run trading via console only
├── docker-compose.yml # settings file for running docker containers
├── package.json # dependencies used within this project
├── LICENSE # license for usage of this project
└── README.md # this file
We are currently working on more Unit tests but the setup for robust tests are in place.
brew install nvm
node --version
npm install
npm test