- PostgreSQL (
docker & docker-compose
) - Python v3.11
- Pip3
- Docker
Located in the file config.py
and can be changed by setting corresponding environment variables:
- DATABASE_URL PostgreSQL database url
Configuration parameters can be set in either .env
, or through environment variables.
-
Install requirements:
pip3 install -r requirements.txt
-
Before running application, start postgres database in docker,
docker-compose up --build db
-
Run application
python main.py
- To run as uvicorn server
uvicorn main:app
- Populate historical data:
python populate.py --input-file data/exchange.csv
-
Start postgres database and app in docker,
docker-compose up --build
-
Populate historical data:
docker exec exchange-api python populate.py --input-file data/exchange.csv
http://localhost:8000/docs
CRUD currency operations:
curl -i --request POST --location 'http://127.0.0.1:8000/currencies/' --header 'Content-Type: application/json' --data '{"code": "USD"}'
curl -i --request PUT --location 'http://127.0.0.1:8000/currencies/1' --header 'Content-Type: application/json' --data '{"code": "USA"}'
curl -i --request DELETE --location 'http://127.0.0.1:8000/currencies/USA' --header 'Content-Type: application/json'
Retrieve all currencies:
curl -i --request GET --location 'http://127.0.0.1:8000/currencies/' --header 'Content-Type: application/json'
CRUD rate operations:
curl -i --request POST --location 'http://127.0.0.1:8000/rates/' --header 'Content-Type: application/json' --data '{"rate": 0.91,"currency_base": "USD", "currency_target": "EUR","date": "2023-12-20"}'
curl -i --request PUT --location 'http://127.0.0.1:8000/rates/1' --header 'Content-Type: application/json' --data '{"rate": 0.92,"currency_base": "USD", "currency_target": "EUR","date": "2023-12-20"}'
curl -i --request DELETE --location 'http://127.0.0.1:8000/rates/1' --header 'Content-Type: application/json'
Retrieve historical data:
curl -i --request GET --location 'http://127.0.0.1:8000/rates/history/USD/EUR' --header 'Content-Type: application/json'
Calculate rate for given pair at given date:
curl -i --request GET --location 'http://127.0.0.1:8000/rates/rate/USD/EUR/2020-12-01' --header 'Content-Type: application/json'
curl -i --request GET --location 'http://127.0.0.1:8000/rates/rate/NZD/AUD/2020-12-01' --header 'Content-Type: application/json'
curl -i --request GET --location 'http://127.0.0.1:8000/rates/rate/NZD/JPY/2020-12-01' --header 'Content-Type: application/json'
curl -i --request GET --location 'http://127.0.0.1:8000/rates/rate/AUD/NZD/2020-12-01' --header 'Content-Type: application/json'