imperiuse / price_monitor

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Create .env file in root of project

And set up envs: PM_POSTGRES_USER and PM_POSTGRES_PASSWORD

Like this (cat .env):

PM_POSTGRES_USER=pm
PM_POSTGRES_PASSWORD=superpswd

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

About

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

License:MIT License


Languages

Language:Go 93.7%Language:Makefile 2.5%Language:PLpgSQL 2.1%Language:Dockerfile 1.6%Language:Shell 0.2%