How mbiskho/stocksharp works
Project type and purpose
• “StockSharp” is a pluggable, full-stack algorithmic‐trading framework.
• It exposes a C# API for building strategies, ships core libraries for message processing, connects to external exchanges via connectors, stores/exports data, loads scripts (C#/F#/Python), and provides sample UIs.
File structure
• Top-level “Algo”, “BusinessEntities”, “Messages”, “Charting.Interfaces” represent the core engine, domain objects, messaging bus and UI contracts.
• “Connectors” contains one project per exchange, each implementing message adapters for market data/orders via HTTP/WebSocket.
• “Storages”, “Algo.Export”, “Algo.Analytics.*” are plug-in modules for persistence, export and custom analytics.
• “Configuration” and “ServicesRegistry” handle dependency injection and component registration.
• “Samples” provides WPF demo front-ends.
• Build scripts, .props files and the root solution file glue it all together.
README for insights
• High-level components: Designer (visual strategy builder), Hydra (data loader/storage), Terminal (charting/trading UI), Shell (generic UI framework), API (C# library).
• Over 50 exchange connectors for crypto, stocks, futures, options, forex.
• Features: event-driven architecture, plugin extensibility, scriptable analytics, high-performance HFT support.
Main components & interactions
a. UI Layer (blue)
– Designer / Terminal / Shell sample apps (WPF)
– Samples folder (WPF and console demos)
⮕ Call into API Layer to create connectors, subscribe to data, display charts, send orders.
b. API Layer (light-green)
– StockSharp.API, BusinessEntities, Charting.Interfaces
– Exposes domain models (CandleSeries, Order, Position, Portfolio) and interfaces (IConnector, IMarketDataProvider).
c. Core Engine (green)
– Algo (Strategy base, message adapters, processors)
– Messages (IMessage, IMessageAdapter, MessageChannel, MessageProcessor)
– Configuration & ServicesRegistry (DI container, component lookup)
– Patterns: pub/sub via message bus, Strategy pattern for trading logic, Factory/Provider for connectors and storages.
d. Infrastructure & Plugins (yellow)
– Connectors (per-exchange message adapters over HTTP/WebSocket)
– Storages (CSV, binary, remote, cache layers)
– Exporters (Excel, JSON, XML, DB)
– Analytics scripts (Algo.Analytics.CSharp/FSharp/Python)
e. External Systems (gray)
– Exchanges and brokers (Binance, Coinbase, IB, FIX, MT4/5, etc.)
– Databases or file systems for persistence.
Interactions:
• Connectors ingest market data / trades / account events → push IMessage into MessageChannel.
• Core Engine dispatches messages to subscribers: Strategies (Algo), Storages, Exporters, Analytics.
• Strategies generate order messages → routed back through MessageChannel → Connectors → external exchanges.
• UI apps subscribe to business entities and charting interfaces to render data and control strategies.
• Configuration/ServicesRegistry wires up all modules at startup.
Architectural patterns & design principles
• Modular plugin architecture: each connector, storage, exporter, analytics script is discovered via ServicesRegistry.
• Pub/sub asynchronous message bus (MessageChannel, AsyncMessageAdapter, MessageProcessor).
• Dependency injection via custom ServicesRegistry (ConfigurationServicesRegistry).
• Strategy pattern for trading logic (Strategy base class).
• Factory/provider for connectors, storages, commission/risk rules.
• Separation of concerns: UI ↔ API ↔ Core ↔ Infrastructure ↔ External.