Here’s a helpful summary and README guide you can use for your GitHub project:
This is a simple prototype of a trading system that maintains buy and sell orders in an order book. The system supports multiple users, allows placing, modifying, and canceling orders, and automatically matches buy and sell orders based on price levels. The trades are recorded in the system for tracking.
- Order Matching Engine: Matches buy and sell orders based on price and quantity.
- Order Book: Manages orders in separate buy and sell books, with price levels sorted accordingly.
- Multi-threading Support: Ensures safe concurrent access with locks.
- Trade Execution: Automatically executes trades when orders are matched.
- User Management: Registers and tracks users by unique IDs.
- Order Modification and Cancellation: Supports modifying existing orders or canceling them before execution.
- TradingSystem: The main class managing users, order books, and trades.
- OrderBook: Manages buy and sell orders for a specific symbol. Orders are sorted by price.
- Order: Represents an individual order placed by a user.
- PriceLevel: Represents a level in the order book with a specific price and the queued orders.
- User: Tracks user details such as name, phone, and email.
- Trade: Represents a matched buy-sell transaction between two orders.
To run this project, ensure you have Python installed.
-
Clone this repository:
git clone https://github.com/your-username/trading-system-prototype.git cd trading-system-prototype
from trading_system import TradingSystem
system = TradingSystem()
user_id = system.register_user(name="John Doe", phone="123456789", email="[email protected]")order_id = system.place_order(user_id, order_type="BUY", symbol="AAPL", quantity=10, price=150)system.modify_order(symbol="AAPL", order_id=order_id, order_type="BUY", price=155, quantity=5)system.cancel_order(symbol="AAPL", order_id=order_id)system.print_order_book(symbol="AAPL")total_trades = system.get_total_trades()
total_quantity = system.get_total_trade_quantity()Feel free to fork this repository, submit pull requests, or report issues.
This guide provides a brief overview of how to get started with the Trading System Prototype. For more details, refer to the individual class documentation and code comments.
Let me know if you need further changes to this!