/currency_api

Currency API

Primary LanguageGo

Overview

Simple currency REST API. Parse https://nationalbank.kz/rss/rates_all.xml?switch=kazakh and save to db. History saves when refreshing too

Stacks

  1. Go
  2. PostgreSQL
  3. Cron
  4. Item 3a

Clone

git clone github.com/gospodinzerkalo/currency_api

Install & Run

docker-compose build 
docker-compose up

Usage (example)

POSTGRES_HOST: db
POSTGRES_DATABASE: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres

You can change cycle of job scheduler, I have put "@every 10s" for testing. For daily refresh pus "@daily"

_, err = cr.AddFunc("@every 10s", func() {
    if err := currencyService.RefreshCurrencies(); err != nil {
    log.Fatal(err)
}
})

API

Get all currency

GET http://localhost:8080/currency

response

[
  {
    "currency_pair": "TRY/KZT",
    "value": "57.38"
  },
  {
    "currency_pair": "UZS/KZT",
    "value": "4.04"
  },
    ...
]

add parameters for cross: base & quoted

GET http://localhost:8080/currency?base=USD&quoted=RUB

response

[
    {
        "currency_pair": "USD/RUB",
        "value": "75.22"
    }
]

Convert currency pair

POST http://localhost:8080/convert

Request body

{
    "convert_from": "USD",
    "convert_to": "RUB",
    "value" : 1
}

Response

{
  "convert_from": "USD",
  "convert_to": "RUB",
  "convert_from_value": 1,
  "convert_to_value": "75.2193"
}

Get history of change

GET http://localhost:8080/history

Response

[
    {
        "id": 1,
        "title": "AUD",
        "pub_date": "28.01.2021",
        "change": "+1.44"
    },  ...
]