A real-time trading platform API built with FastAPI and WebSockets. The API allows users to place, cancel, and monitor orders, with real-time updates via WebSockets.
- REST API for order placement, retrieval, and cancellation.
- WebSockets for real-time order status updates.
- Dockerized environment for easy deployment.
- Automated tests using
pytestandhttpx. - Swagger UI for interactive API documentation.
git clone https://github.com/rmariusg/trading-platform.git
cd trading-platformdocker compose up --buildThis will:
- Build the Docker container
- Start the FastAPI server on port
8080
- Swagger UI: http://localhost:8080/docs
- WebSocket Endpoint:
ws://localhost:8080/ws
To run all tests inside Docker:
docker compose exec trading-api pytest tests/To run tests locally (without Docker):
pip install -r requirements.txt
pytest tests/| Method | Endpoint | Description |
|---|---|---|
POST |
/orders |
Create a new order |
GET |
/orders |
Get all orders |
GET |
/orders/{order_id} |
Get a specific order by ID |
DELETE |
/orders/{order_id} |
Cancel an order |
- Connect to WebSocket:
ws://localhost:8080/ws - Real-time updates:
- Order created ->
"status": "pending" - Order executed ->
"status": "executed" - Order canceled ->
"status": "canceled"
- Order created ->
trading-platform/
│── app/
│ ├── main.py # FastAPI entry point
│ ├── routes.py # API endpoints
│ ├── database.py # Order processing logic
│ ├── models.py # Order model & enums
│ ├── schemas.py # API request/response schemas
│ ├── websocket.py # WebSocket manager
│── tests/
│ ├── test_api.py # REST API tests
│ ├── test_websocket.py # WebSocket tests
│ ├── test_performance.py # Performance tests
│── docker-compose.yml # Docker services
│── Dockerfile # API containerization
│── requirements.txt # Python dependencies
│── README.md # Documentation
- Ensure Docker is running before executing
docker compose up. - Orders transition from
"pending"->"executed"automatically after a delay (5s). - Canceled orders remain in memory but cannot be executed.
Developed by Marius Rusu as part of XM SDET take-home task.
This project is licensed under the MIT License.