A Django-based API for scraping cryptocurrency data from CoinCodex and providing it in a structured JSON format.
- Scrape live cryptocurrency data, including:
- Rank
- Name
- Ticker
- Price
- 24-hour price change
- Market cap
- 24-hour trading volume
- Circulating supply
- Fetch data for a specific date using a POST request.
- Fetch data for the current date using a GET request.
- Data validation and error handling for user input.
- API response formatted using Django REST Framework serializers.
Fetch cryptocurrency data for the current date.
curl -X GET http://127.0.0.1:8000/api/get-crypto-data/
[
{
"index": "1",
"name": "Bitcoin",
"ticker": "BTC",
"price": "$30,000",
"change_24h": "2.5%",
"market_cap": "$600B",
"volume_24h": "$40B",
"circulating_supply": "19M BTC"
},
...
]
Fetch cryptocurrency data for a specific date.
Parameter | Type | Description |
---|---|---|
date |
string | Date in YYYY-MM-DD format |
curl -X POST http://127.0.0.1:8000/api/get-crypto-data/ \
-H "Content-Type: application/json" \
-d '{"date": "2023-01-01"}'
[
{
"index": "1",
"name": "Bitcoin",
"ticker": "BTC",
"price": "$30,000",
"change_24h": "2.5%",
"market_cap": "$600B",
"volume_24h": "$40B",
"circulating_supply": "19M BTC"
},
...
]
- 400 Bad Request: Missing or invalid date format.
- 500 Internal Server Error: Unable to scrape data from the source.
- Python 3.8 or higher
- Django 4.0 or higher
- Django REST Framework
requests
librarybeautifulsoup4
library
-
Clone the repository
git clone https://github.com/Amirreza-Jabbari/Crypto-API.git cd Crypto-API
-
Set up a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Run the server
python manage.py runserver
-
Access the API
- Use http://127.0.0.1:8000/api/get-crypto-data/ for GET requests.
- Use the same URL with a POST request and a
date
parameter to fetch data for a specific date.
- Django
- Django REST Framework
- requests
- beautifulsoup4
Install them with:
pip install django djangorestframework requests beautifulsoup4
This project is licensed under the MIT License. See the LICENSE
file for more details.