An algorithm intended for share purchase and sale operations in a Home Broker environment. The application was built on a microservices architecture, using Go and Kafka, which is adopted as a messaging system, where purchase and sale orders are produced on a specific topic. The algorithm, in turn, consumes these orders, processes them and, when there is a match, produces the resulting transaction in another topic. all encapsulated in Docker containers with the advantage of easy access to Confluent's Control Center for monitoring and managing Kafka.
Built With
Table of Contents
-
Getting Started
- License
- Contact
Getting Started
To get started, You need to have Go 1.21+ installed on your machine, for more information visit Go Downloads. You also need to have Docker Desktop installed, for more information visit Docker Desktop Install.
OBS: This guide is designed to run this project locally (Local Development), on Linux-based systems.
Installation
- Clone the repository.
git clone https://github.com/caard0s0/home-broker-system.git
Usage
After completing the installation, you can run the project.
-
Create and run the Containers.
docker compose up -d
-
Open a browser tab at localhost:9021
to access your Cluster in the Confluent Control Center.
-
Opening your terminal at the root of the application, run the project.
go run cmd/main.go
-
Create a new Topic.
WARNING: The Topic name must be exactly as written in the image.
-
Create two new messages (one at a time) using the data below, to generate a New Match and consequently a Transaction.
{
"order_id": 1,
"investor_id": 1,
"stock_id": "Stock1",
"current_shares": 10,
"shares": 10,
"price": 10,
"order_type": "BUY"
}
{
"order_id": 2,
"investor_id": 2,
"stock_id": "Stock1",
"current_shares": 10,
"shares": 10,
"price": 10,
"order_type": "SELL"
}
-
Opening your terminal, you will see the result of the transaction exactly as it is below.
OBS: You can also see the result in your Cluster.
{
"order_id": 1,
"investor_id": 1,
"stock_id": "Stock1",
"order_type": "BUY",
"status": "CLOSED",
"partial": 0,
"shares": 10,
"transactions": [
{
"transaction_id": "324cb1a1-e73d-4deb-99bc-bf1440907412",
"buyer_id": 1,
"seller_id": 2,
"stock_id": "Stock1",
"price": 10,
"shares": 10
}
]
}
{
"order_id": 2,
"investor_id": 2,
"stock_id": "Stock1",
"order_type": "SELL",
"status": "CLOSED",
"partial": 0,
"shares": 10,
"transactions": [
{
"transaction_id": "324cb1a1-e73d-4deb-99bc-bf1440907412",
"buyer_id": 1,
"seller_id": 2,
"stock_id": "Stock1",
"price": 10,
"shares": 10
}
]
}
Tests
To be able to run all the tests, follow the command below.
- Run all the Tests.
go test -v -cover ./...
License
This project is being distributed under the MIT License, see LICENSE.txt
for more information.
- Software Engineer
- Vinicius Cardoso - Email
↑ back to top