How quantweb3-com/nexustrader works
Main Components
• Engine & Core: At the center is the “Engine” (nexustrader/engine.py) that orchestrates the entire flow. Surrounding it are the core modules (found in nexustrader/core) handling caching, logging, entity management, and the central registry.
• API/Connector Modules: There are “Connector” classes in the base folder (nexustrader/base) and in each exchange-specific folder (nexustrader/exchange/binance, bybit, okx, etc.) which handle both public (market data) and private (order execution) connections.
• Order Management: Components such as the “OrderExecutionSystem” and “OrderManagementSystem” (defined conceptually in the README and implemented in files like oms.py) control order submission, updates, and status management.
• Integration Components: The configuration modules (nexustrader/config.py) tie everything together, mapping basic configurations and connector configurations for different exchange types.
• External Dependencies & Performance Optimizations: The system integrates technologies like uvloop (to boost asyncio performance), picows (for fast WebSocket handling), and msgspec (for efficient data serialization). There are also Rust-powered modules (via nautilius) that underpin components like the MessageBus and Clock.
Relationships and Interactions
• The Engine initializes all the core modules and uses configuration settings to set up the corresponding connectors for each exchange.
• The “Connector” serves as the key interface with external exchanges—providing both market data (via the PublicConnector) and trade execution (via the PrivateConnector).
• Order information flows from the Engine to the OrderExecutionSystem where orders are sent to exchanges; subsequent responses and order updates then return via the OrderManagementSystem to the strategy.
• The asynchronous event loop (powered by uvloop) and high-performance WebSocket framework (picows) ensure that data flows efficiently between these components.
Architectural Patterns and Design Principles
• Asynchronous, event-driven design: The whole framework is built on asyncio, with strategies reacting to market events and timer signals.
• Modular separation: There’s a clear separation for exchange-specific logic (different folders under nexustrader/exchange) and core engine functionalities, making it easy to extend by adding new exchanges or strategies.
• Pub/Sub and callback handling: The design employs callback functions for various order statuses (accepted, filled, etc.) and market updates, making the system reactive to real-time events.
• High-performance optimizations: The use of uvloop and picows (along with efficient serialization via msgspec) are crucial design choices for ensuring low latency and high throughput.
Relevant Technologies, Frameworks, and Libraries
• Python 3.11+ with asyncio for asynchronous operations.
• uvloop for the event loop,
• picows for WebSocket communication,
• msgspec for data serialization,
• Docker, Redis (as shown in the docker-compose.yml and start_redis.sh) for deployment and caching/queueing,
• Rust (via nautilius) for some core module implementations.
• CI/CD configurations are available under .github/workflows.