This project is a tool to generate some reports about some currency exchange data. Basically, this is a Django project that uses django-restframework.
Python 3.8
-
Activate your virtual environment
-
install dependencies:
make deps
-
Start the database container:
make startdb
-
Create the database (Only the first time):
make createdb
-
Run the initials migrations:
make migrate
-
Start the project
make start
-
Stop the database
make stopdb
-
Remove the database and volume:
make removedb
-
Install pre-commit hooks (required to developed not to users) :
make setup
-
Run test
make test
Create a virtual environment and install required dependencies by executing:
pip install -r requirements.txt
or using make make deps
There are two options for this:
- Using a PostgreSQL docker container (require install docker)
- Using a local PostgreSQL database
To use a docker container, make sure you have installed docker before execute the following command.
docker run -d --name stock_service_db \ -v stock_service_data:/var/lib/postgresql/data \ -p 5432:5432 \ -e POSTGRES_HOST_AUTH_METHOD=trust \ postgres:12
or if you have make installed:
make startdb
and after make createdb
to create the database.
To use a local PostgreSQL database, just configure a new database using 'stock_service' as database name using the postgres default port.
After that, execute database migrations:
python manage.py migrate
or if you have make installed:
make migrate
Now you have everything installed, you can populate your database by executing:
python manage.py load_data <symbol>
for example python manage.py load_data BTC-USD
You can load as many symbols as you want, just make sure to do it one at a time.
Please DO NOT LOAD THE SYMBOL DATA TWICE since orders are unique. Due to this, try to insert the same data into the database cause Duplicated key errors. To update the data you need to reset the database:
python manage.py reset_db
or if you have make installed
make reset_db
After that, load the data again.
In case you want to check your loaded data, you can use de Django Admin. Just create a superuser:
python manage.py createsuperuser
or make createsuperuser
Run the application (see section Run the application) and then visit localhost:8000/admin
,
login in using your username and password. Now you can check your data.
Now that you have everything ready, run the application by executing:
python manage.py runserver
or using make:
make start
To check available reports (three of them) over your data, just open a browser and visit
http://localhost:8000/statistics/{symbol}/{report_type}
. For example:
http://localhost:8000/statistics/BTC-USD/asks
to see Asks report
http://localhost:8000/statistics/BTC-USD/bids
to see Bids report
http://localhost:8000/statistics/BTC-USD/totals
to see total report
As a result you will a json like this (totals report example):
{ "data": { "BTC-USD": { "bids": { "count": 192, "qty": 92.81548968, "value": 1404201.1333760887 }, "asks": { "count": 243, "qty": 35.26452092, "value": 2644726.784921361 } } } }
To run the application tests just run:
python manage.py test
or using make:
make tests