Skip to content

rmariusg/trading-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trading Platform API

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.

Features

  • REST API for order placement, retrieval, and cancellation.
  • WebSockets for real-time order status updates.
  • Dockerized environment for easy deployment.
  • Automated tests using pytest and httpx.
  • Swagger UI for interactive API documentation.

1️. Installation & Setup

Prerequisites

  • Docker & Docker Compose (Install from Docker)
  • Git (Install from Git)

Clone the Repository

git clone https://github.com/rmariusg/trading-platform.git
cd trading-platform

Build and Run the Application

docker compose up --build

This will:

  • Build the Docker container
  • Start the FastAPI server on port 8080

Access the API


2️. Running the Test Suite

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/

3️. API Endpoints

Orders

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

WebSockets

  • Connect to WebSocket: ws://localhost:8080/ws
  • Real-time updates:
    • Order created -> "status": "pending"
    • Order executed -> "status": "executed"
    • Order canceled -> "status": "canceled"

4️. Project Structure

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

5️. Notes

  • 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.

6️. Contributors

Developed by Marius Rusu as part of XM SDET take-home task.


7️. License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors