A simple trading API made for a company coding test.
Pre-requisites:
Docker/Docker Desktop installed and running.
- Open your command prompt, then create or open the folder where you want to clone the repo:
cd path/to/your/dev/folder/
mkdir constancy_brokers
cd constancy_brokers
- Clone this repository, it will download all the necessary files to you run this project in your localhost:
git clone https://github.com/Mikael-Caetano/Constancy-Brokers .
- Navigate to constancy_brokers:
cd constancy_brokers
- Run the
docker-compose up
command:
docker-compose up
If you get an "standard_init_linux.go:211: exec user process caused "no such file or directory" error: Checkout that the "End of line sequence" setting of the file docker-entrypoint.sh is LF, otherwise change it to LF.
-
Open your browser and go to 127.0.0.1:8000 or localhost, the application should be running. If you want to test the API you can use the Browsable API, to do that you can follow the API urls listed below.
-
For the sake of testing the API, you must create a superuser, to do that you can run or add the following command to the file docker-entrypoint.sh:
python manage.py createsuperuser --username example --password example --email example@example.com --first_name example --last_name example --is_provider_admin True --noinput
You can set all the example data to your preferences.
- (optional) In case you use postman, import the file Trade.postman_collection.json and User.postman_collection.json in your Postman software, it will help you test the application easily.
- POST - Register a new user - arguments: username, password, first_name, last_name, email
{
"username": "user_6",
"password": "password",
"first_name": "User",
"last_name": "6",
"email": "email@email.com"
}
- POST - Login in user account - arguments: username, password
{
"username": "{{USERNAME}}",
"password": "{{PASSWORD}}"
}
- POST - Create trade - arguments: provider, pair, quantity, price
{
"provider": 381,
"pair": 1258,
"quantity": 200,
"price": 300.04
}
- PUT - Update trade - arguments: provider, pair, quantity, price
{
"provider": 381,
"pair": 1258,
"quantity": 200,
"price": 300.04
}
-
GET - List providers
-
POST - Create provider - arguments: name, acronym
{
"name": "Test",
"acronym": "TES"
}
-
GET - Retrieve provider
-
PUT - Update provider - arguments: name, acronym
{
"name": "edited test",
"acronym": "ETS"
}
- DELETE - Delete provider
-
GET - List currencies
-
POST - Create currency - arguments: name, acronym
{
"name": "Test",
"acronym": "TES"
}
-
GET - Retrieve currency
-
PUT - Update currency - arguments: name, acronym
{
"name": "edited test",
"acronym": "ETS"
}
- DELETE - Delete currency
-
GET - List currency pairs
-
POST - Create currency pair - arguments: from_currency, to_currency
{
"from_currency": 442,
"to_currency": 446
}
-
GET - Retrieve currency pair
-
PUT - Update currency pair - arguments: from_currency, to_currency
{
"from_currency": 442,
"to_currency": 447
}
- DELETE - Delete currency pair
- GET - List providers for select
- query arguments: page, search
- GET - List providers for select
- query arguments: page, search
- List user trades
- query arguments: pairs, min_price, max_price, min_quantity, max_quantity, start, end
- GET - Retrieve trade data
- GET - Retrieve user trades graph
- query arguments: pairs, min_price, max_price, min_quantity, max_quantity, start, end
- GET - Retrieve market graph
-
query arguments: pair, providers, start, end
-
overall - The average selling price among all brokers.
-
feed - The selling price for the logged user.
-