Exchange Rate Receiver is a GRPC service that retrieves the USDT exchange rate from the Garantex exchange. It provides ask and bid prices along with a timestamp, and stores this information in a PostgreSQL database upon each request.
- GRPC method
GetRates
for retrieving USDT exchange rates from Garantex. - Stores the exchange rates with a timestamp in PostgreSQL.
- Healthcheck method to check the service's health.
- Graceful shutdown.
- Go 1.22 or higher
- Docker and Docker Compose
- PostgreSQL
Configuration parameters can be managed using environment variables or command-line flags. The following parameters are used:
DATABASE_URL
: PostgreSQL connection string (postgres://user:password@localhost:5432/exchangerates?sslmode=disable
)GRPC_PORT
: Port for the GRPC server (default:50051
)
Copy .env.example to .env in your local environment
git clone https://github.com/yourusername/exchange-rate-receiver.git
cd exchange-rate-receiver
make build
docker-compose build
docker-compose up
docker-compose run --rm app ./app
make test
(MacOS)
To install protoc
run
brew install protobuf
Then download Go protobuf plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Navigate to the root directory of your project and run the following commands to generate the Go code from the protobuf definitions:
protoc --go_out=.. --go-grpc_out=.. proto/exchange_rate.proto
-
Install dependencies:
go mod download
-
Build the application:
cd cmd/server go build -o ../../exchange_rate-receiver cd ../..
-
Run the application:
./exchange_rate-receiver