API to control bets, lost and winnings. So with that and a database, you'll can control your bets better. Then you'll can filter and compare previous bet profits for you. The only thing you need is to create an account.
- Dependencies
- Python and Pip
- FastAPI
- Peewee
- How To Run
- How To Test
- Run Specific Tests
- Run All Tests
- Models
- Models of Body
- Project Structure
- API Routes
- Database Relationship
- FAQ
Here you'll see the list of dependencies from this project.
- Python and Pip here and here language and package install resource
- FastAPI here used to build API Rest
- Peewee here used as a ORM
- Uvicorn here used as a server to access this API
Note: you can install uvicorn searching for install it by pip from FastAPI website.
Before you run this project, you need to check if all dependencies
are installed and access FAQ to set the file settings.json
and
.env
configurations.
To run this project, after you have made what was described here, you need to run the following command:
uvicorn main:app --reload
To run unit tests here you need to check what is described at How to Run topic. After you have two options:
- Access the package test then you have two options:
- controller the endpoints tests
- repository the persistence tests
- Run the following command in root dir for run all tests:
-
pytest
-
Bellow you can see our methods.
{
"player_name": "string",
"username": "string",
"password": "string"
}
{
"id_login": 0,
"home_team": "string",
"away_team": "string",
"team_bet": "string",
"odd": "1.00"
"value_invest": "1.00"
"profit": "1.00",
"bet_status": "success"
}
{
"id_login": 0,
"home_team": "string",
"away_team": "string",
"team_bet": "string",
"list_odds": [
"1.00"
],
"value_invest": "1.00"
"profit": "1.00",
"bet_status": "success"
}
Bodies to use as a custom JSON to make API operations.
{
"id": 0,
"bet_status": "string",
}
{
"login_id": 0,
"date_from": "2023-05-24",
"date_to": null
}
{
"login_id": 0,
"date_from": null,
"date_to": null
}
Here you can see the project tree for source
and tests
folders.
I used the structure of a html
code. Each tag
means a package.
<src>
<api>
<app>
__init__.py
app.py
</app>
<application>
__init__.py
application.py
</application>
<controller>
__init__.py
controller.py
</controller>
<data>
__init__.py
data_model.py
</data>
<models>
__init__.py
api_models.py
request_body.py
</models>
<repository>
__init__.py
</repository>
<routes>
__init__.py
routes.py
</routes>
__init__.py
</api>
<utils>
__init__.py
bet_status.py
checker.py
connection.py
create_tables.py
exceptions.py
types_utils.py
</utils>
__init__.py
</src>
<test>
<api>
<controller>
__init__.py
test_login_controller.py
test_single_bet_controller.py
test_multi_bet_controller.py
</controller>
<repository>
__init__.py
</repository>
<utils>
__init__.py
get_auth_headers.py
login_opps.py
</utils>
__init__.py
</api>
__init__.py
conftest.py
</test>
Here I present our routes for this API. It will be in JSON
format.
{
"post_login": "/login",
"post_login_auth": "/login/auth",
"post_single_bet": "/bet/single",
"post_multi_bet": "/bet/multi",
"patch_single_bet": "/bet/single",
"patch_multi_bet": "/bet/multi",
"get_filter_single": "/get/bet/single",
"get_filter_multi": "/get/bet/multi",
"get_profits_single": "/bet/single/profits",
"get_profits_multi": "/bet/multi/profits",
"get_lost_single": "/bet/single/lost",
"get_lost_multi": "/bet/multi/lost",
"get_all_profits": "/bet/profits/{id_login}/all",
"get_all_lost": "/bet/lost/{id_login}/all",
"post_compound_interest": "/compound-interest"
}
So we can see the name and the link to each endpoint at this API.
The main class of this project is named Login
. So we have others 2 (two) database
entities, SingleBet
and MultiBet
. Both are independent, but both is linked to Login
.
[ Login ]
___/ \___ Login <> SingleBet
___/ \___ Login <> MultiBet
___/ \___
/ \
SingleBet MultiBet
At this point, we select common questions to answer.
How to create a file settings.json
?
Note: it must be at project's root directory.
After, paste the following text:
{"database": "staging"}
How to set the file .env
?
At root directory, you will find the file .env.example
. Copy
it and rename to .env
, so open and sets the information required
there.
DATABASE_HOST
DATABASE_PORT
DATABASE_NAME
DATABASE_USER
DATABASE_PASSWD
You need to fill these variables.
How the module set_config.py
works?
This module has functions to use as a switch between databases as part
of this file to change the database between staging
,
production
and testing
.
What's the field potential_earnings
?
This field represents the earnings without the operator_fee
.
What's the field total_amount
?
This field represents the real earning after apply the operator_fee
.
What's the field profit
?
This field represents the profit of operation or the value_invest * odd