How shidenggui/easyquant works
Project Type and Purpose
• Project Type: A quantitative trading framework.
• Purpose: To integrate market data (using free real-time sources like Sina, lf), trading execution via various brokers (华泰, 佣金宝, 银河, 雪球模拟盘) and strategies. It leverages an event-driven design for its trading and quotation engines.
• Key Indicators: The README explicitly mentions its foundation on easytrader and easyquotation, outlines various engine components (event, clock, push, quotation) and demonstrates strategy development examples.
File Structure
• Top-Level Directories/Files:
• “easyquant” directory: This is the core framework with multiple submodules.
• Components include “event_engine.py” (event-driven architecture), “main_engine.py” (orchestrates components), “multiprocess” (for multi-process strategy execution), “push_engine” (for market data push), “strategy” (strategy template definitions), and “log_handler” (for logging management).
• “custom”: Contains alternative or demo engines (e.g. fixeddataengine, fixedmainengine) for demonstration purposes.
• “strategies”: Contains example strategy implementations.
• Various JSON configuration files (e.g. ht.json, xq.json) that store broker account info.
• Additional helper utilities (e.g. inside “easydealutils” and “easyredis” files).
• Architectural Patterns:
• Event-driven and modular design (inspired by vnpy’s event engine for handling asynchronous events).
• Separation of concerns: Different modules handle logging, event processing, data pushing (push_engine), strategy execution, and connection to external brokerage systems.
README for Additional Insights
• The README outlines the purpose of each engine (quotation engine, trading engine) and how to configure accounts.
• It provides examples for both simple “Hello World” strategies and more complex strategies utilizing clock and custom log handling.
• Direct references to external dependencies (easytrader, easyquotation) indicate integration points with third-party services.
a. Main Components to Include:
• Main Engine:
• Acts as the orchestrator that loads strategies, initializes different engine components, and manages overall workflow.
• Event Engine:
• Handles asynchronous events, triggers strategy callbacks and clock events.
• Quotation Engine(s):
• DefaultQuotationEngine (using Sina or other free sources).
• Custom or alternative engines (e.g., LFEngine for ten-level market data, etc.).
• Push Engine:
• Responsible for pushing real-time market data to strategies.
• Clock Engine:
• Schedules timed events, such as market opening/closing events and custom intervals.
• Strategy Module:
• Template and implementations found in “easyquant/strategy” and “strategies” folders.
• Trading Engine:
• Powered by easytrader to execute orders; not directly shown as a separate file but integrated via broker configuration files and account settings.
• Logging Component:
• Customizable global and per-strategy log handlers.
• Configuration and Utility Modules:
• Utility modules like easydealutils and easyredis and JSON configuration files for account management.
b. Relationships and Interactions:
• The Main Engine initiates and coordinates the Event Engine, Quotation Engine, Push Engine, and Clock Engine.
• The Event Engine listens for market events and clock ticks, and then dispatches these events to strategies.
• The Quotation Engine obtains market data from external sources and forwards this data through the Push Engine.
• Strategies (residing in the “strategies” folder) subscribe to these events, process data, and call the Trading Engine (via easytrader commands through the user API) to execute orders.
• Log handlers capture events and output logs either to console or files.
• The multiprocess module indicates that strategies or parts of the engine might run in parallel processes, so include communication pathways (if applicable) between the main process and worker processes.
c. Important Architectural Patterns:
• Event-Driven Architecture: Central to dispatching market data and clock events.
• Modular Design: Each component (e.g., quotation, clock, push, trading, logging) is encapsulated and can be extended or swapped.
• Strategy Pattern: Strategies are designed to follow the template (StrategyTemplate) and plug into the engine.
d. Relevant Technologies and Frameworks:
• Python 3.5+ for development.
• Easyquotation and Easytrader as external dependencies.
• Use of logging frameworks (e.g., DefaultLogHandler) and time utilities (e.g., dateutil).
• Use of multiprocess for parallel strategy execution.
Essential Elements
• Use clear labels for each main component (Main Engine, Event Engine, Quotation Engine, Push Engine, Clock Engine, Strategy Manager, Trading Connector, Logging System, and Configuration/Utility layer).
• Market Data Flow: External Data Sources → Quotation Engine → Push Engine → Event Engine → Strategy.
• Command Flow: Strategy → Main Engine → Trading Connector (via easytrader).
• Logging flow to be shown from each component to the Logging System.
• Rectangles for engines/modules.
• Ovals or clouds for external services (broker API, data providers).