Skip to content

Simple bot implementation to perform some trading operations.

License

Notifications You must be signed in to change notification settings

marcosbarbero/trade-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trade Bot Build Status Coverage Status

Overview

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.

Architecture & Design

This section describes this project architecture and design.

Packages

Packages structure and content
com.marcosbarbero.tradebot // (1)
com.marcosbarbero.tradebot.commons // (2)
com.marcosbarbero.tradeboot.config // (3)
com.marcosbarbero.tradebot.model // (4)
com.marcosbarbero.tradebot.service // (5)
  1. Root package stores the StartUp class

  2. Utility classes

  3. Configuration files for the WebSocket connection and HTTP REST calls

  4. All the data model used in the application such as WebSocket response as well as the REST API response and the storage layer.

  5. Services and Handlers that execute the trading operations.

Configuration properties

The current implementation favors convention over configuration and is designed to get you up and running as quickly as possible

Externalized configuration properties
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
  1. The product id to quote

  2. The buy price

  3. Max retries to close a position making a profit, default value 20

  4. The WebSocket feed connection interval in milliseconds, default value 1000

  5. WebSocket real-time feed subscription endpoint

  6. The endpoint to buy order (Make a Trade)

  7. The endpoint to sell order (Close Position)

  8. The lower limit price to sell

  9. The upper limit price to sell

  10. Map containing default HTTP Headers to be sent in all requests

Overriding default configuration properties

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.

Profiles

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

Build & Run

Build Status

This section describes how to build and run the application. Run the following commands in the root folder of the project.

Build
$ ./mvnw clean package
Run
$ java -jar target/trade-bot.jar
Important
  • By default the application will be running in the port 8081.

  • If executed as is it will be dependent to the external API to be available in localhost:8080. Check the Profiles section to run it pointing to an external API.

Adding Project Lombok Agent

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.

Code coverage

Coverage Status

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:

JaCoCo report
$ ./target/site/jacoco/index.html

Roadmap - Further Improvements

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

Known issues

  • Currently it’s not possible to execute the application using dev profile, it fails on Authentication.

Contributing

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.

Code of Conduct

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].

About

Simple bot implementation to perform some trading operations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published