This project simulates the purchase and sale of shares. It does not use any database, all data is stored in memory during the execution of a list of operations.
The application will receive a list of operations that it can execute purchase and sale, returning for each operation how much tax was paid. The operations will be in the order in which they occurred, that is, the second operation in the list happened after the first and so on. Each line is an independent simulation, the program will not maintain the state obtained in one line for the others.
Below we have the application input and output data.
Input:
Name | Detail |
---|---|
operation | Whether the operation is a purchase(buy) or sale(sell) operation |
unit-cost | Share unit price in a currency with two decimal places |
quantity | Number of shares traded |
Output:
Name | Detail |
---|---|
tax | Amount of tax paid for the operation performed |
In the resources folder we have several examples to run the application. In the CASES.md we are detailing these examples.
The technology used is the Go language in version 1.22.
├── /cmd
├── /app....................: Contains main file to run the application
└── /handlers...............: Contains the entry point for application integration
├── /docs.......................: Contains the documentation from some examples
├── /internal...................: All core implementation its here
├── /models.................: Contains Data structure
├── /services...............: Contains all business validation
└── /utils..................: General stuff
The application expects data in STDIN format and will return json in STDOUT format. So you can provide a JSON or a file containing several lines with each line having a JSON. Examples below:
You can run the commands below to run the application
go run cmd/app/main.go
go run cmd/app/main.go < resources/case_7
Just run the docker commands below to create the docker image and run the container.
docker run -it --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock golang:1.22 go run cmd/app/main.go
docker run -i --rm -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock golang:1.22 go run cmd/app/main.go < resources/case_1
Run the command below in the terminal to run the application tests.
make -f Makefile test-docker
make -f Makefile test
The commands bellow need gotestsum
and golangci-lint
installed
make -f Makefile lint
make -f Makefile cover