Trade Republic Coding Challenge

Challenge

Your task is to build a system that enables users to view price histories. It will receive updates from a partner service, transform these updates and provide the aggregated data through an endpoint.

Intro and terminology

Instruments and Quotes

Every asset that can be traded is represented by an “instrument”, which has a unique identifier (ISIN). Each time the instrument price changes, an update message called “quote” is broadcasted for this instrument to inform about the change.

What is a candlestick?

A candlestick is a representation that describes the price movement for a given asset in a fixed amount of time
chart

While a candlestick “contains” all prices where the timestamp of the price update is higher than the openTimestamp (timstamp >= openTimestamp) and lower than the closeTimestamp (timstamp < closeTimestamp) of the candle, the basic idea is that we don’t need to know about all price changes during that time. We are only interested in a few specific data points: the first price that was received (openPrice) during that duration, the last price that was received (closePrice) and the highest and lowest price that was observed.

Input data

The input data is received through a websocket stream from a partner service. The code provides handles connecting and consuming the stream (Streams.kt). There are two types of input messages:

  • Instrument additions/deletions, which adds or removes an instrument from our catalogue
  • Instrument price updates, giving the most recent price for a specific instrument

Output (Aggregated-Price History)

The output (and the main point of this challenge) is the aggregated price history endpoint. It should provide the history in form of candlesticks (check information below).

End-users of the service are interested in a specific instruments price history. They want to see the last 30 minutes in a form that is easy to read, hence we provide a candlestick chart.

To display this chart, the system needs to return the candlesticks for the last 30 minutes.

The endpoint for fetching candlesticks is already provided (Server.kt). Consumers of the endpoint need to provide the instrument id (ISIN) as a query parameter (e.g. http://localhost:9000/candlesticks?isin={ISIN}).

Your task is to implement a service that will consume the stream data and make it reachable through the API in the format mentioned above

Requirements

  JVM running on your local machine
  Gradle
  Any IDE

Running partner service

To run a partner service you can either use docker-compose

docker-compose up -d

or Java

java -jar partner-service-1.0-all.jar

Running the app

To run the app you can use the following gradle commands

./gradlew build -> compiles project 
./gradlew test -> run tests
./gradlew run -> run on port 8080

Once the server is running you can check the results at

http://localhost:9000/candlesticks?isin={ISIN}

Note: if you don’t implement your service you might see the exception there

GitHub

View Github