How tpim/thenextquant works
Project Type and Purpose
• The project is an asynchronous event-driven quantitative trading and market-making system.
• It’s designed to support crypto exchange integrations (e.g., Binance, Huobi, OKEx) with asynchronous I/O (using Python’s asyncio along with aiohttp and aioamqp).
• It leverages external systems (RabbitMQ for event publishing/subscription and optionally MongoDB for data storage) to handle key trading system functionalities.
File Structure
• Core Directory – “quant”: This is the heart of the framework and contains modules such as:
• quant/quant.py (central engine)
• Modules for market, trade, asset, order, etc.
• Helper modules like “quant/utils” for decorators, logging, web utilities, and “quant/platform” for exchange-specific connectors (binance.py, huobi.py, okex.py).
• Example Directory – “example”: Contains implementations and configuration samples for different exchanges; highlights how an end user can set up their trading strategy.
• Documentation – “docs”: Provides configuration, usage instructions, and architecture overviews (with schematic images referenced).
• Setup & Configuration – Files like setup.py, config.py, config.json (in multiple locations) signal that configuration is key to the architecture.
Extract Architectural and Technical Insights from the README
• The system uses Python’s native asynchronous capabilities (asyncio) for event-driven operations.
• External services include:
• RabbitMQ: For event streaming (publishing and subscribing to events).
• MongoDB (optional): For persistent data storage.
• The README points to examples demonstrating how to plug in strategies and interact with various exchanges.
a. Main Components to Include:
• Core Trading Engine (in the “quant” directory):
• Event Handling Module: (quant/event.py, heartbeat, tasks)
• Business Logic Modules: (market.py, trade.py, asset.py, order.py, position.py)
• Configuration Management: (quant/config.py, const.py)
• Exchange Integration Layer:
• “quant/platform” modules: Each file (binance.py, huobi.py, okex.py) acts as a connector for specific exchange API interactions.
• Example implementations: “example/binance”, “example/huobi”, “example/okex” show how configurations and concrete trading operations are executed.
• Utility and Support Components:
• Utility libraries (logging, tools, web) to support asynchronous operations.
• Decorator support for event-driven triggers.
• External Dependencies:
• RabbitMQ: Indicated for event communication.
• MongoDB: (Optional) for persistent storage.
• Python Async Libraries: aiohttp and aioamqp ensuring the asynchronous non-blocking I/O behavior.
b. Relationships and Interactions:
• From the core engine invoking exchange connectors.
• From the exchange connectors back to the core engine with market data and order execution responses.
• Event propagation paths: how events are generated (by tasks, heartbeat) and propagated via RabbitMQ.
• How utilities feed into the core modules (e.g., logging, decorators).
• Separate the asynchronous event loop (the backbone of the entire system) from the business logic modules. Represent how the event loop manages callbacks and asynchronous communications.
c. Highlighting Architectural Patterns:
• Asynchronous/Event-Driven Architecture: Emphasize the use of asyncio; denote event publishers and subscribers.
• Modular Design: Clearly separate exchange connectors in “quant/platform” from core logic in “quant”.
• Configuration Driven: Show that the system is highly configurable via JSON files (config.json) and scripts demonstrated in the examples.
d. Relevant Technologies:
• Language: Python 3.5.3+
• Frameworks/Libraries: asyncio, aiohttp, aioamqp, motor (for MongoDB integration)
• External Systems: RabbitMQ, MongoDB (optional)
• Miscellaneous: Usage of decorators and event handlers for asynchronous patterns.
• Yet another for external services (RabbitMQ, MongoDB)
• Brief annotations where necessary to explain the roles (e.g., “Handles asynchronous event publishing” for RabbitMQ).