Skip to content

This is a trade engine mainly implemented by SpringBoot, Kafka and Flink based on FIFO matching orders algorithm.

Notifications You must be signed in to change notification settings

damncan/OrderMatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OrderMatch

This is a trade engine mainly implemented by SpringBoot, Kafka and Flink based on FIFO matching orders algorithm.


Architecture

Architecture drawio

Phase 1
  • Temporarily store all unmatched trading orders into kafka (group name: rawData).

Phase 2
  • When any buy/sell order has been polled from kafka (topic name: rawData), match it with all unmatched orders in unmatched buy/sell queue.
  • After matching every order, send each matched result into kafka (topic name: cookedData).

Phase 3
  • Poll trading result from kafka (topic name: cookedData) and analyze the summary of trading, such as the total quantity and amount for all buy/sell-side orders, every 5 seconds.
  • After that, store the analysing result into an in-memory database, H2.

Requirements

  1. Install JDK 1.8 or other higher versions.
  2. Install and start Zookeeper and Kafka server on port 2181 and 9092 respectively.
  3. Install JMeter and Postman for testing.
  4. If you encounter any java.lang.reflect.InaccessibleObjectException, please add the following vm options before starting the application again.

--add-opens java.base/java.util=ALL-UNNAMED

--add-opens java.base/java.lang=ALL-UNNAMED

--add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED

--add-opens java.base/jdk.internal.module=ALL-UNNAMED


Testing

  1. You can find the JMeter script here.
  2. Before you start running the auto-testing script, you can define your simulation situation by adjusting the Thread Properties first. For example, as following setting, there will be 10 simultaneous http requests per second lasting for 60 seconds. JMeter Thread Properties
  3. After running the script, it will generate several buy/sell side orders and start to match unmatched orders stored in unmatched sell/buy side queues.
  4. For example, the following picture shows the trading result after matching 10 orders. After the first 5 orders are matched, the total matched order, amount and quantity on sell side is 1750, 104465 and 1745. Running Result
  5. Apart from the console log, you can also use GET /summary to query the real time trading result. GET summary

About

This is a trade engine mainly implemented by SpringBoot, Kafka and Flink based on FIFO matching orders algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages