This application is a simple bot implementation to perform some trading operations. If you are really anxious to run the application just skip everything and jump to the Build & Run section.
This section describes this project architecture and design.
com.marcosbarbero.tradebot // (1)
com.marcosbarbero.tradebot.commons // (2)
com.marcosbarbero.tradeboot.config // (3)
com.marcosbarbero.tradebot.model // (4)
com.marcosbarbero.tradebot.service // (5)
-
Root package stores the StartUp class
-
Utility classes
-
Configuration files for the WebSocket connection and HTTP REST calls
-
All the data model used in the application such as WebSocket response as well as the REST API response and the storage layer.
-
Services and Handlers that execute the trading operations.
The current implementation favors convention over configuration and is designed to get you up and running as quickly as possible
trade:
api:
product-id: sb26493 // (1)
buy-price: 11513.6 // (2)
max-retries: 20 // (3)
interval: 1000 // (4)
endpoints:
subscription: ws://localhost:8080/subscriptions/me // (5)
buy-order: http://localhost:8080/core/16/users/me/trades // (6)
sell-order: http://localhost:8080/core/16/users/me/portfolio/positions/{positionId} // (7)
sell-price:
lower-limit: 11500.6 // (8)
upper-limit: 11553.6 // (9)
headers: // (10)
Accept-Language: nl-NL,en;q=0.8
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJyZWZyZXNoYWJsZSI6ZmFsc2UsInN1YiI6ImJiMGNkYTJiLWExMGUtNGVkMy1hZDVhLTBmODJiNGMxNTJjNCIsImF1ZCI6ImJldGEuZ2V0YnV4LmNvbSIsInNjcCI6WyJhcHA6bG9naW4iLCJydGY6bG9naW4iXSwiZXhwIjoxODIwODQ5Mjc5LCJpYXQiOjE1MDU0ODkyNzksImp0aSI6ImI3MzlmYjgwLTM1NzUtNGIwMS04NzUxLTMzZDFhNGRjOGY5MiIsImNpZCI6Ijg0NzM2MjI5MzkifQ.M5oANIi2nBtSfIfhyUMqJnex-JYg6Sm92KPYaUL9GKg
Content-Type: application/json
Accept: application/json
-
The product id to quote
-
The buy price
-
Max retries to close a position making a profit, default value 20
-
The WebSocket feed connection interval in milliseconds, default value 1000
-
WebSocket real-time feed subscription endpoint
-
The endpoint to buy order (Make a Trade)
-
The endpoint to sell order (Close Position)
-
The lower limit price to sell
-
The upper limit price to sell
-
Map containing default HTTP Headers to be sent in all requests
This section describes how to override this application properties. As this application is built using Spring Boot given us the possibility to override its properties in few ways.
-
Command line args
It’s possible to override the properties in the command line application startup just adding the following arguments$ java -jar /path/to/trade-bot.jar --trade.api.product-id=$productId --trade.api.buy-price=$buyPrice --trade.api.sell-price.lower-limit=$lowerLimit --trade.api.sell-price.upper-limit=$upperLimit
-
Editing application properties file
It’s possible to override the properties by editing the application.yml file.
Important
|
After editing the properties file it’s necessary to build the application before run it. |
Tip
|
Check spring-boot documentation for more details about externalizing configuration. |
Currently there are two available profiles in the application:
-
Default
-
Calls the API in localhost
-
There’s no need to add any argument to run using the default profile
-
-
Beta
-
Calls the API in the beta environment provided
-
To use beta profile add the following command line argument
$ java -jar /path/to/trade-bot.jar --spring.profiles.active=beta
-
-
Dev
-
Calls the API in the dev environment provided
-
To use dev profile add the following command line argument
$ java -jar /path/to/trade-bot.jar --spring.profiles.active=dev
-
Tip
|
Check spring boot documentation for more details about profiles |
This section describes how to build and run the application. Run the following commands in the root folder of the project.
$ ./mvnw clean package
$ java -jar target/trade-bot.jar
Important
|
|
This project uses Project Lombok to generate getters and setters etc. Compiling from the command line this shouldn’t cause any problems, but in an IDE you need to add an agent to the JVM. Full instructions can be found in the Lombok website. The sign that you need to do this is a lot of compiler errors to do with missing methods and fields.
This project uses JaCoCo.
The actual configuration excludes irrelevant packages from the coverage scan, those excluded packages are related to Java Configuration files and POJOs.
The JaCoco report can be found in the following path:
$ ./target/site/jacoco/index.html
Here’s some further improvements to be added in this project
-
Possibility to configure multiple products to quote, buy and sell
-
WebUI to configure the given properties values instead of a standalone running bot
-
WebSocket notifications feed endpoint to notify when a trade action occurs
-
Use state machine to control the application flow
-
Add some Rule Engine such as Drools in order to make the trade rules configurable without changing the code
-
Error handling for the API calls
-
Currently it’s not possible to execute the application using dev profile, it fails on Authentication.
TradeBot is released under the non-restrictive Apache 2.0 license, and follows a very standard Github development process, using Github tracker for issues and merging pull requests into master. If you want to contribute even something trivial please do not hesitate, but follow the guidelines below.
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].