OsEngine Documentation

repository·master·Indexed 21 days ago

https://github.com/alexwan/osengine

A high-performance algorithmic trading engine for developing, testing, and executing trading strategies. It features a complete workflow including data acquisition, strategy optimization, an exchange emulator for testing, and a live robot execution station. OsEngine supports over 300 built-in robots across trend-following, counter-trend, and arbitrage strategies, with connectivity for MOEX, international brokers (e.g., Interactive Brokers), and numerous cryptocurrency exchanges.

Tokens
98K
Snippets
210
Records
388
Agent score
73%

What's inside OsEngine

  1. What is OsEngine?

    master

    OsEngine is a comprehensive suite of programs designed for automating stock exchange trading. It provides a complete workflow from data acquisition to live robot execution.

    The core components include:

    • Data: A program to download historical data, including candles, market depths, and trades from various sources.
    • Optimizer: A tool used to select the optimal parameters for a trading strategy.
    • Tester: An exchange emulator that allows for testing multiple strategies simultaneously on historical data using a single portfolio. It supports multi-timeframe and multi-instrument translation.
    • Bot station: The environment used to run trading robots in live market conditions.
    • Robot Creation Layer: A scripting layer for creating robots, designed to be simple and maintain backward compatibility (similar to Wealth-Lab or Ninja Script).

    OsEngine includes over 300 built-in robots covering classic trend strategies (e.g., Moving Average crossing, Bill Williams, Jesse Livermore), counter-trend systems (e.g., Bollinger bands, market-making), and arbitrage strategies (e.g., correlating instrument divergences).

  2. What is OsEngine?

    master
    OsEngine is a high-performance trading engine designed for algorithmic trading. It provides a framework for developing, testing, and executing trading strategies, likely supporting various asset classes and connectivity options (though specific details are contained in subsequent segments).
  3. Built-in Trading Robots

    master

    OsEngine comes bundled with over 300 built-in robots, categorized into several strategy types:

    1. Trend Following: Classic trend-based robots (e.g., Moving Average crossovers, Bill Williams strategies, or Jesse Livermore trend strategies).
    2. Counter-Trend: Systems based on Bollinger Bands, balance lines, and certain market-making strategies.
    3. Arbitrage: Strategies designed to trade the divergence between correlated instruments, including single-leg arbitrage.
  4. Use the modified QuikSharp library for OsEngine

    master

    OsEngine uses a modified version of the QuikSharp library to interface with the QUIK terminal. If you need to inspect the specific implementation used by OsEngine or require the source code for this modified version, you should refer to the dedicated repository rather than the original QUIKSharp repository.

  5. Navigate the OsEngine project structure

    master

    The project is organized into functional directories. Use this map to locate where to develop specific features or find existing logic:

    • Robots/: The primary directory for trading bot development. Subfolders include:
      • MyBots/: Default location for new robots.
      • Trend/: Trend-following strategies.
      • CounterTrend/: Mean-reversion/counter-trend strategies.
      • Patterns/: Candle patterns and levels.
      • Screeners/: Multi-instrument screening.
      • PositionsMicromanagement/: Advanced position management.
      • PairArbitrage/: Pair trading.
      • Grids/: Grid trading strategies.
      • TechSamples/: API technical examples.
    • Indicators/: Contains Aindicator implementations, samples, and scripts.
    • Market/: Exchange connectivity (e.g., Market/Servers/ for Binance, MOEX, etc.).
    • Entity/: Core data structures like candles, positions, and orders.
    • OsTrader/: The trading terminal application.
    • OsOptimizer/: Strategy optimization tools.
  6. How to write and use indicators with Aindicator

    master
    Indicators in OsEngine are built using the Aindicator base class. This documentation provides guidance on implementing custom indicators, understanding their lifecycle, and managing data series. For the underlying robot architecture that utilizes these indicators, refer to CONTEXT.md. For prompt templates to generate new indicators via AI, refer to CONTEXT_PROMPTS_INDICATORS.md.
  7. What is a Monitor-robot?

    master

    A Monitor-robot is an extension of BotTabScreener designed to observe multiple instruments simultaneously. Unlike standard trading bots, a Monitor-robot:

    1. Collects metrics for every instrument in the screener (e.g., RSI, volume rating, movement to High/Low).
    2. Displays a UI table (DataGridView) directly within the robot's parameter panel.
    3. Triggers alerts via sound and log messages when specific thresholds are met.
    4. Enables trading both automatically via logic and manually via interactive buttons (Chart, Open, Close) inside the UI table.

    Core Components

    • BotTabScreener: The data source providing candles and positions for the instrument portfolio.
    • DataGridView: The UI component used to display metrics and interaction buttons.
    • SignalData + Dictionary: Used for alert deduplication (ensuring only one signal per candle).
    • SoundPlayer: Handles audio notifications.
    • NonTradePeriods: Manages trading restrictions based on specific hours or days.
  8. Overview of the OsEngine MCP API

    master

    The MCP (Model Context Protocol) API in OsEngine is an interface designed for AI agents to interact with the platform. It is implemented using a combination of HTTP, JSON-RPC 2.0, and Server-Sent Events (SSE), integrated directly into the MainWindow.

    All operations are performed through tools via the tools/call method, and the available capabilities can be discovered using tools/list. This architecture allows AI agents to programmatically manage terminals, logs, settings, server instances, and various trading/data modules.

  9. Module Structure of the MCP API

    master

    The MCP implementation is organized into several functional areas within the OsEngine/MCP/ directory:

    • Core Engine: McpMaster.cs (HTTP server, routing, SSE), McpSettings.cs (host settings), and McpApiUi.xaml (UI management).
    • Data Transfer Objects (DTOs): Located in Json/, handling McpJsonRpcRequest, McpJsonRpcResponse, McpJsonRpcError, McpEvent, and McpTool.
    • Tool Providers: Implement IMcpToolProvider.cs to handle specific domains:
      • TerminalApi.cs: Terminal events (terminal_*, terminal.*).
      • LogsApi.cs: Log retrieval (log_get_*).
      • SettingsApi.cs: Terminal settings (prime_settings_*).
      • McpConfigApi.cs: MCP-specific settings (mcp_settings_*).
      • ServerManagementApi.cs & ServerInstanceApi.cs: Server lifecycle and management.
      • Wiki*Api.cs: Specialized wiki data (Robots, Indicators, Securities, Dividends).
      • OsDataApi.cs: General data operations (data_*).
      • RobotsApi.cs: Robot management (bot_*).
      • SystemLoadApi.cs: System metrics (RAM, CPU, ECQ, MOQ).
      • ComparePositionsApi.cs: Position synchronization and comparison.
      • ProxyApi.cs: Proxy routing and management.
      • OptimizerApi.cs: Optimizer execution and reporting.
      • TesterApi.cs: Tester configuration.
      • McpProtocolApi.cs: Core protocol methods (initialize, tools/list, tools/call).
  10. Identify MOEX security types and classifications

    master

    Based on the MoexDataServer metadata, securities are categorized by their nameClass. Common patterns include:

    • Stocks (Акции): Identified by nameClass containing #TQBR (e.g., T, TATN, TGKA).
    • Expired Futures (Фьючерсы истёкшие): Identified by nameClass containing #RFUD (e.g., SYH0, SZH6).

    When constructing queries or identifying instruments, use the nameId for precise targeting, as it combines the ticker with its full classification path.