This project is a comprehensive stock market order book simulator and microservice system designed to mimic stock market trading operations. It combines a C++ program for simulating stock orders with a Go-based microservice that handles asynchronous data processing and database operations. The system is containerized with Docker and deployable in a Kubernetes cluster for scalability and high availability.
-
Stock Market Simulation: The C++ program allows users to connect via sockets and submit stock orders in JSON format, which are processed in a simulated order book.
-
Go Microservice: The Go-based microservice handles asynchronous CRUD operations for orders, logs data to a PostgreSQL database, and communicates with the C++ program via asynchronous HTTP operations.
-
Docker Containerization: Both the C++ program and the Go microservice are containerized using Docker, making them easily deployable across various environments.
-
PostgreSQL Database: Order data is stored in a PostgreSQL database, providing data persistence and retrieval capabilities.
-
GitHub Container Registry: The Docker image of the Go microservice is hosted on the GitHub Container Registry for easy distribution.
-
Kubernetes Cluster: The system is designed to be deployed in a Kubernetes cluster, where it can be scaled horizontally for load balancing and high availability.
-
Kubernetes Service: A Kubernetes service acts as a single entry point to the cluster, enabling load balancing and efficient routing of incoming traffic.
To run this project, you will need:
- Clang: For compiling the C++ program with C++20 features.
- CMake: To build the C++ program.
- Go 1.19: To build and run the Go microservice.
- Docker: To build and run the containerized applications.
- Kubernetes: To deploy the system in a Kubernetes cluster.
- PostgreSQL: To set up the database for order data storage.
- nlohmann-json3-dev: For handling JSON data in the C++ program.
git clone https://github.com/your-username/stock-market-simulator.git
cd stock-market-simulator- Naviagte to the Go microservice
cd DBOperationMicroservice/-
Make a
.envfile that has the PostgreSQL database connection variables likeDB_HOST,DB_PORT,DB_USER,DB_PASSWORDandDB_NAME -
Build the Docker image for the Go microservice, specifying your desired image name (e.g., dbo-microservice):
docker build -t dbo-microservice .- You can host the docker image in docker desktop, ghcr, etc. Change the path in
orderbook-sim/DBOperationMicroservice/deployment.yamlto reflect accordingly.
1.Deploy the system in a Kubernetes cluster by applying the YAML configuration files.
kubectl apply -f deployment.yaml
kubectl apply -f service.yamlAfter applying the configurations, you can change CLUSTER_URL variable in the Dockerfile in orderbook-sim/C++app to the external URL of the cluster.
- Navigate to the C++ program directory
cd C++app- Build the Docker image for the C++ program, specifying your desired image name (e.g., order-book):
docker build -t order-book.- Run the Docker container for the Go microservice, mapping a host port to the container's exposed port (port 8081 on the host to port 80 in the container) to allow access:
docker run -p 8080:8080 order-book- Use a tool like
netcatto connect to the socket application running in the docker container:
nc localhost 8080{
"type": "order",
"ticker": "<string>",
"price": <double>,
"quantity": <double>,
"action": "buy/sell"
}{
"type": "order",
"ticker": "AAPL",
"price": 178.85,
"quantity": 130,
"action": "buy"
}
Special thanks to the open-source communities of Clang, CMake, C++20, Go, Gin, PostgreSQL, Docker, and Kubernetes for the tools and technologies that make this project possible.
