This is a trade engine mainly implemented by SpringBoot, Kafka and Flink based on FIFO matching orders algorithm.
Phase 1
- Temporarily store all unmatched trading orders into kafka (group name: rawData).
- 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).
- 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.
- Install JDK 1.8 or other higher versions.
- Install and start Zookeeper and Kafka server on port 2181 and 9092 respectively.
- Install JMeter and Postman for testing.
- 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
- You can find the JMeter script here.
- 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.
- 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.
- 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.
- Apart from the console log, you can also use
GET /summary
to query the real time trading result.