Bxbot
A simple Bitcoin trading bot written in Java.
Install / Use
/learn @gazbert/BxbotREADME
BX-bot
What is BX-bot?
<img src="./docs/bxbot-cropped.png" align="right" width="25%" />BX-bot (Bex) is a simple Bitcoin trading bot written in Java for trading on cryptocurrency exchanges.
The project contains the basic infrastructure to trade on a cryptocurrency exchange...
except for the trading strategies - you'll need to write those yourself! A simple
ExampleScalpingStrategy
is included to get you started with the Trading API - see Ta4j for more ideas.
Exchange Adapters for using Bitstamp, Bitfinex, Kraken, and Gemini are included. Feel free to improve these or contribute new adapters to the project; that would be shiny!
A TryModeExchangeAdapter is
configured by default to delegate public API calls to Bitstamp, but it simulates the private
API (order management) calls; it's good for testing your initial setup and
paper trading without actually sending orders to the exchange.
The Trading API provides support for limit orders traded at the spot price. If you're looking for something more sophisticated with a much richer Trading API, take a look at XChange.
Warning: Trading cryptocurrency carries significant financial risk; you could lose money. This software is provided 'as is' and released under the MIT license.
Architecture

- Trading Engine - the execution unit. It provides a framework for integrating Exchange Adapters and executing Trading Strategies.
- Exchange Adapters - the data stream unit. They provide access to a given exchange.
- Trading Strategies - the decision or strategy unit. This is where the trading decisions happen.
- Trading API - Trading Strategies use this API to make trades. Exchange Adapters implement this to provide access to a given exchange.
- Strategy API - Trading Strategies implement this so the Trading Engine can execute them.
Trading Strategies and Exchange Adapters are injected by the Trading Engine on startup. The bot uses a simple YAML backed dependency injection framework to achieve this; the long term goal is to convert it into a fully configurable Spring Boot app.
The bot was designed to fail hard and fast if any unexpected errors occur in the Exchange Adapters or Trading Strategies: it will log the error, send an email alert (if configured), and then shut down.
Installation Guide
The bot runs on Linux, macOS, and Windows.
BX-bot is supported on the current JDK 21 LTS. You'll need the JDK (e.g. OpenJDK 21 or Oracle JDK 21) installed on the machine you are going to use to build and run the bot. Be mindful of Oracle's recent licensing changes and how you intend to use the bot.
You can use Gradle or Maven to build the bot. The instructions below are for Linux/macOS, but equivalent Windows scripts are included.
Download the latest Release and unzip the bot.
Maven
- If you plan on using your own Trading Strategies/Exchange Adapters packaged in separate jar files, you'll need to add the dependency in the bxbot-app/pom.xml - see the commented out dependency examples inside it.
- From the project root, run
./mvnw clean packageto produce the distribution artifactsbxbot-app-<version>-dist.tar.gzandbxbot-app-<version>-dist.zipin the./bxbot-app/targetfolder. - Copy either the
bxbot-app-<version>-dist.tar.gzor thebxbot-app-<version>-dist.ziponto the machine you want to run the bot and unzip it someplace. - Configure the bot as required - see the main Configuration section.
The bot's default configuration uses the
ExampleScalpingStrategy, but you'll probably want to code your own! TheTryModeExchangeAdapteris configured out of the box to simulate trading with Bitstamp. - Usage:
./bxbot.sh [start|stop|status]
Gradle
- If you plan on using your own Trading Strategies/Exchange Adapters packaged in separate jar files, you'll need to add the dependency in the bxbot-app/build.gradle - see the commented out dependency examples inside it.
- From the project root, run
./gradlew clean buildto build the bot. - Then run
./gradlew buildTarGzipDistor./gradlew buildZipDistto build the distribution artifact: eitherbxbot-app-<version>.tar.gzorbxbot-app-<version>.ziprespectively. It will be placed in the./build/distributionsfolder. - Copy the artifact onto the machine you want to run the bot and unzip it someplace.
- Configure the bot as described in step 4 of the previous Maven section.
- Usage:
./bxbot.sh [start|stop|status]
Docker
If you want to just play around with the
ExampleScalpingStrategy
and evaluate the bot, Docker is the way to go.
- Install Docker on the machine you want to run the bot.
- Fetch the BX-bot image from Docker Hub:
docker pull gazbert/bxbot:2.2.1 - Run the Docker container:
docker container run --publish=8080:8080 --name bxbot-2.2.1 -it gazbert/bxbot:2.2.1 bash - Change into the bot's directory:
cd bxbot* - Configure the bot as described in step 4 of the previous Maven section.
- Usage:
./bxbot.sh [start|stop|status] - You can detach from the container and leave the bot running using the
CTRL-pCTRL-qkey sequence. - To re-attach to the Docker container, run
docker container lsto get the CONTAINER ID. Then run:docker container attach <CONTAINER ID>
You could modify the Dockerfile to containerise the bot and deploy to Kubernetes. The config can be externalised using a Docker volume mount.
Build Guide
If you plan on developing the bot, you'll need JDK 21 installed on your dev box.
You can use Gradle or Maven to build the bot and pull down the dependencies.
The instructions below are for Linux/macOS, but equivalent Windows scripts are included.
Clone the repo locally (main branch).
Maven
- From the project root, run
./mvnw clean install. If you want to run the exchange integration tests, use./mvnw clean install -Pint. To execute both unit and integration tests, use./mvnw clean install -Pall. - Take a look at the Javadoc in the
./target/apidocsfolders of the bxbot-trading-api, bxbot-strategy-api, and bxbot-exchange-api modules after the build completes.
Gradle
- From the project root, run
./gradlew build. If you want to run the exchange integration tests, use./gradlew integrationTests. To execute both unit and integration tests, use./gradlew build integrationTests. - To generate the Javadoc, run
./gradlew javadocand look in the./build/docs/javadocfolders of the bxbot-trading-api, bxbot-strategy-api, and bxbot-exchange-api modules.
Issue & Change Management
Issues and new features are managed using the project Issue Tracker - submit bugs here.
You are welcome to take on new features or fix bugs! See here for how to get involved.
For help and general questions about BX-bot, check out the Gitter channel.
Testing
The bot has undergone basic unit testing on a best-effort basis.
There is a CI build running on GitHub Actions.
The latest stable build can always be found on the Releases page. The SNAPSHOT builds on main are active development builds, but the tests should always pass and the bot should always be deployable.
User Guide
_"Change your opinions, keep to your princip
