The algorithm used for storing and retrieving bids and asks in this microservice is based on Redis Sorted Sets. Redis Sorted Sets allow you to store prices along with their associated quantities. The scores(prices) are used to keep the elements(quantities) sorted.
Storing and retrieving orders with this algorithm has a time complexity of O(log(N)).
This project is built with Laravel Framework 10.
-
Clone the repository using git
git clone https://github.com/sasani72/orderbook-microservice.git
-
cd
into the folder created for cloned project:cd orderbook-microservice
-
Pull and build images using docker compose
docker compose up -d
-
Run this script to initialize the laravel project
docker compose exec app /usr/src/app/setup.sh
-
Create Kafka topics
docker compose exec kafka bash kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic new-order kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic cancel-order exit
-
Running Kafka producer command to produce data streams
docker compose exec app bash php artisan kafka:produce-order
-
Running Kafka consumer command to consume data streams
php artisan kafka:consume-order
-
Start Laravel local server
php artisan serve
-
You can now open another terminal to send requests for orderbooks:
curl -X GET "http://localhost:8000/api/orderbook?symbol=ETHUSDT&depth=200"
Licensed under the MIT license.