price_monitor

module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2022 License: MIT

README

Price monitoring

The test task. Creating a tiny service which allows to monitor Bitcoin prices over a specified period of time with specified frequency.

Task

The task is it to create a tiny service which allows to monitor Bitcoin prices over a specified period of time with specified frequency. For example a user sends a request to the service to monitor Bitcoin price for a period of 5 minutes with frequency every 10 seconds. User is assumed to be able to do 2 operations:

  1. Call the service with period and frequency parameters, which will start monitoring. Returns monitoring ID. A user can start many monitors in parallel without waiting for previous monitors to finish.
  2. Call the service with monitoring ID to check if monitoring is complete and to get results (if monitoring is not finished yet, return some kind of error).

Full task description:

img

Solution

Main architecture diagram

img

I have chosen first approach.

ERP

img.png

Before please install this

  1. Docker and Docker Compose
  2. Be sure that your system support Makefile more_info
  3. Optional Go (for local development) Go install
Run

From root of the repository:

make start 
Stop
make stop
How to make requests
  1. Health check

    curl --request GET --url http://localhost:4000/health

  2. Start monitoring

    curl --request POST --url http://localhost:4000/api/v1/monitoring?cur=btcusd&period=1m&freq=10s img

  3. img

  4. Get results of monitoring

    curl --request GET --url http://localhost:4000/api/v1/monitoring/1

img img img

Optional:

  1. Get result monitoring and delete monitoring record from db

    curl --request GET --url http://localhost:4000/api/v1/monitoring/1?delete=true

Insomnia examples:

see in folder -> .insomnia

Docker Compose run

img

TODOS:

  1. Refactor a little (see many todo's)
  2. Full-implementing hexagonal-architecture -> https://medium.com/@matiasvarela/hexagonal-architecture-in-go-cfd4e436faa3
  3. Tests-tests-tests -> Increase test coverage (http api tests cases, consul - MUST!)
  4. Add more errors handlers
  5. Think about better sql select where case (select prices)
  6. Add pagination
  7. Add Swagger docs
  8. Implements 2 and 3 variants of architecture =) 7.1) Compare them in real world with benchmarks

Development

Env up
make dev_env_up

After that can run go app (in JetBrains IDE or VSCode) (do not forget set up .env file and add ENVs)

img img

Remove old container or volumes
make docker_clean_all
Rebuild prod app container
make rebuild

Made by Arseny Sazanov 2022

arseny.sazanov@gmail.com

MIT

Directories

Path Synopsis
cmd
internal
env
logger/field
nolint golint
nolint golint
servers/http/middlerware
Package middlerware provides middleware functions
Package middlerware provides middleware functions
services/controllers/master/scanner
Package scanner - package for price scanning
Package scanner - package for price scanning

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL