Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
/ metal-price Public archive

The Metal Price is an API, which provides current price of precious metals on the market

Notifications You must be signed in to change notification settings

chutommy/metal-price

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Metal Price

Metal Price is an API (REST) which provides resl-time market prices of 6 precious metals in 33 different currencies and 6 weight units.

The project uses gRPC within internal microservices architecture. All services are containerized in Docker containers and the whole application can be easily run with the multi-container tool Docker Compose (docker-compose.yml).

Services:

Installation

Requirements

$ git clone https://github.com/chutommy/metal-price.git

$ make build      # build or rebuild the service
$ make run        # start the docker containers

$ curl localhost:3001/ping
{"message":"pong"}

API sources

Endpoints

Path Response
host:3001/ping OK if the server is running
host:3001/i/{metal} current {metal} price per oz in USD
host:3001/i/{metal}/{currency} current {metal} price per oz in {currency}
host:3001/i/{metal}/{currency}/{weight-unit} current {metal} price per {weight_unit} in {currency}

Usage

$ make build      # build or rebuild the service
$ make run        # start the docker containers

docker-compose -f docker-compose.yml -p metal-pricer up

Starting metal-pricer_metalsrv_1    ... done
Starting metal-pricer_currencysrv_1 ... done
Starting metal-pricer_metal_price_1 ... done
Attaching to metal-pricer_currencysrv_1, metal-pricer_metalsrv_1, metal-pricer_metal_price_1

currencysrv_1  | [CURRENCY SERVICE] 2020/07/14 07:46:17 Currency service is running (active)
metalsrv_1     | [METAL SERVICE] 2020/07/14 07:46:17 Metal service is running (active)
metal_price_1  | [SERVER] 2020/07/14 07:46:18 Listening and serving HTTP on port 3001

Examples

Run in another terminal

host:3001/i/ {metal} :

$ curl localhost:3001/i/rhodium
{
    "metal": "rhodium",
    "price": 8100,
    "currency": "USD",
    "unit": "oz"
}

host:3001/i/ {metal} / {currency} :

$ curl localhost:3001/i/au/cad
{
    "metal": "gold",
    "price": 2455.86,
    "currency": "CAD",
    "unit": "oz"
}

host:3001/i/ {metal} / {currency} / {weight-unit} :

$ curl localhost:3001/i/ag/czk/kg
{
    "metal": "silver",
    "price": 15922.17,
    "currency": "CZK",
    "unit": "kg"
}

Notice the log messages:

currencysrv_1  | [CURRENCY SERVICE] 2020/07/14 07:46:17 Currency service is running (active)
metalsrv_1     | [METAL SERVICE] 2020/07/14 07:46:17 Metal service is running (active)
metal_price_1  | [SERVER] 2020/07/14 07:46:18 Listening and serving HTTP on port 3001
metalsrv_1     | [METAL SERVICE] 2020/07/14 07:48:01 Handling GetPrice; Material: rhodium
metal_price_1  | [GIN] 2020/07/14 - 07:48:01 | 200 |  1.261795294s |      172.21.0.1 | GET      "/i/rhodium"
currencysrv_1  | [CURRENCY SERVICE] 2020/07/14 07:48:27 Handling GetRate; Base: USD, Destination: CAD
metalsrv_1     | [METAL SERVICE] 2020/07/14 07:48:28 Handling GetPrice; Material: gold
metal_price_1  | [GIN] 2020/07/14 - 07:48:28 | 200 |  986.333154ms |      172.21.0.1 | GET      "/i/au/cad"
currencysrv_1  | [CURRENCY SERVICE] 2020/07/14 07:48:30 Handling GetRate; Base: USD, Destination: CZK
metalsrv_1     | [METAL SERVICE] 2020/07/14 07:48:31 Handling GetPrice; Material: silver
metal_price_1  | [GIN] 2020/07/14 - 07:48:31 | 200 |   861.97045ms |      172.21.0.1 | GET      "/i/ag/czk/kg"

Use <Ctrl-C> to gracefully stop the server and all services:

Stopping metal-pricer_metal_price_1 ... done
Stopping metal-pricer_currencysrv_1 ... done
Stopping metal-pricer_metalsrv_1    ... done

API documentation

Swagger 2.0: swagger.json

Run the service and visit localhost:3001/swagger/index.html.

Directory structure

 /
 ├── api-server
 ├── currency
 ├── metal
 ├── docker-compose.yml
 ├── Makefile
 └── README.md