VoltTrade is a robust, high-performance web backend designed to simulate a real-world cryptocurrency trading platform. Built with Django REST Framework, the project prioritizes data integrity and high-concurrency safety, making it suitable for financial applications.
- Robust Financial Engine: Guaranteed data consistency explicitly designed to ensure money is never lost during sudden network outages or concurrent trade executions.
- Pessimistic Data Locking: Prevents dangerous race conditions using strict database-level row locking with
select_for_update(). - Deadlock Prevention Mechanisms: Algorithmically prevents deadlocks during peer-to-peer transfers by implementing deterministic ID sorting prior to multi-row locking.
- Data Normalization & Precision: Adheres to strict data casing and relies on
Decimalprecision to avoid binary floating-point errors inherent to financial calculations. - Live Market Data: Integrates directly with the CoinGecko API for real-time cryptocurrency pricing and exchange rates.
- Backend Framework: Django & Django REST Framework (DRF)
- Database: SQLite3 (Configurable for PostgreSQL)
- External Services: CoinGecko API integration for live crypto prices
Ensure you have the following installed on your local machine:
- Python 3.8+
pippackage managervirtualenv(recommended)
-
Clone the repository:
git clone https://github.com/yourusername/VoltTrade.git cd VoltTrade -
Create and activate a virtual environment:
python -m venv env source env/bin/activate # On Windows, use `env\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Apply database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
Access the DRF browsable API at
http://127.0.0.1:8000/api/wallets/.
| Endpoint | Method | Description |
|---|---|---|
/register/ |
POST | Register a new user |
/api/wallets/ |
GET | Retrieve wallets |
/api/wallets/transfer/ |
POST | Transfer USD safely to another user |
/api/wallets/buy_coin/ |
POST | Buy cryptocurrency (e.g., BTC, ETH) using USD balance |
/api/wallets/sell_coin/ |
POST | Sell cryptocurrency to convert back to USD |
VoltTrade addresses the classic "double-spend" database problem frequently seen in naive trading applications. This is handled by wrapping potentially sensitive views in a transaction.atomic() block, and heavily utilizing Django's select_for_update() query method. By doing so, the database forces sequential execution of transactions touching the same wallet or asset ledger, practically eliminating race conditions while maintaining rapid transactional throughput.
This project is open-source and available under the MIT License.