ROQ C++ Samples

repository·master·Indexed 41 days ago

https://github.com/roq-trading/roq-cpp-samples

Practical implementations of algorithmic trading features using the ROQ framework. Includes examples for market data subscription, order management, historical simulation, and state maintenance. Provides guidance on building with CMake and Conda, configuring gateways for Deribit and Coinbase Pro, and processing MarketByPrice (MBP) data.

Tokens
14.8K
Snippets
52
Records
69
Agent score
49%

What's inside ROQ C++ Samples

  1. Overview of available code samples

    master

    The repository contains several examples demonstrating algorithmic trading features:

    • Example 1: Connecting to a market gateway and subscribing using regex patterns.
    • Example 2: Managing disconnects, processing incremental market data updates, maintaining market depth views, and updating simple models.
    • Example 3: Maintaining positions, placing limit orders, handling order acks/updates, and performing historical or live trading.
    • Example 4: Basic subscription logic.
    • Example 5: Transferring CustomMessage from a secondary thread.
    • Import: Tools to convert any data source into an event-log (header-only dependencies).
  2. Overview of Example 1: Basic Event Processing

    master

    Example 1 is a sample implementation designed to demonstrate fundamental event processing capabilities within the ROQ framework. It covers three core areas:

    1. Market Data Subscription: Defining regex patterns to subscribe to specific market data.
    2. Connection Management: Utilizing the Trader interface to handle asynchronous connection management and event dispatching automatically.
    3. Logging: Using the asynchronous logger to output incoming events for monitoring and debugging.
  3. Structure of a Roq Event-Log

    master

    When encoding data into the Roq Event-Log format via Flatbuffers, follow this preferred message sequence to ensure correct processing:

    1. SourceInfo: Used to capture sequence numbers and timestamps.
    2. GatewaySettings: Must be the first message.
    3. ReferenceData: Should ideally precede any market data messages.
    4. MarketByPriceUpdate: Should ideally start with a snapshot (an image) followed by incremental updates (changes).
  4. Compiler standard requirements and Abseil compatibility

    master

    The library requires a compiler standard of at least c++14.

    Important Note on Abseil Compatibility: Certain abseil-cpp functions export signatures that depend on the default compiler standard version used during compilation. If you compile this project with c++14, abseil-cpp will not support std::string_view, even if the public interface appears to allow this type. To ensure full compatibility with modern types like std::string_view, ensure your build environment is configured for a higher C++ standard (e.g., c++17).

  5. Understand MarketByPrice (MBP) data behavior

    master

    When using MarketByPrice (the order book) in the samples, note the following data lifecycle behavior:

    • Download Phase: The MarketByPrice object includes a full snapshot of the order book when it is first received during the download phase.
    • Live Updates: Once the download phase is complete, subsequent live MarketByPrice updates will only contain incremental changes to the book.
  6. Compiler standard requirements and compatibility

    master

    The library requires a compiler standard of at least c++14. The library automatically selects the default compiler standard version and will hide types that are incompatible with its dependencies.

    Important Note on Abseil-cpp Compatibility: Certain abseil-cpp functions export signatures that depend on the default compiler standard used during compilation. For example, if compiled with c++14, abseil-cpp will not support std::string_view, even if the public interface appears to allow this type. Ensure your compiler standard is configured correctly to avoid type incompatibility issues with dependencies.

  7. Compiler standard requirements for roq-cpp-samples

    master

    The library requires a compiler that supports at least the C++14 standard. The library automatically selects the default compiler standard version based on this minimum requirement.

    Important Compatibility Note: The library hides types that are incompatible with its dependencies. Specifically, when compiled with C++14, certain abseil-cpp functions will not support std::string_view, even if the public interface appears to allow it. This is because abseil-cpp exports signatures based on the default compiler standard used during the project's compilation.

  8. Install simulation data

    master

    Simulation requires event logs. You can use your own captured logs or install sample data via conda from the unstable channel. Once installed, data is located in $CONDA_PREFIX/share/roq-data/.

    conda install -y --channel https://roq-trading.com/conda/unstable roq-data
  9. Build roq-cpp-samples packages with Conda

    master

    Use conda build from the current directory to create packages. You must specify the appropriate channel based on whether you want stable or unstable builds.

    Packages are output to the directory under $CONDA_PREFIX/conda-bld/ after a successful build.

    # For stable builds
    conda build . --channel https://roq-trading.com/conda/stable
    
    # For unstable builds
    conda build . --channel https://roq-trading.com/conda/unstable
  10. Run the roq-samples-io-context sample

    master

    The roq-samples-io-context sample can be run in two modes: broadcasting all available data or filtering data based on specific symbols. It uses a Unix domain socket for communication and exposes WebSocket and UDP ports for interaction.

    Broadcast everything

    To run the sample in a mode that broadcasts all data without symbol filtering, use the following command:

    ./roq-samples-io-context \
      --name trader \
      --ws_port 2345 \
      --udp_port 1234 \
      ~/run/deribit.sock

    Filter by symbols

    To restrict the data broadcast to only the symbols controlled by Rest/WS subscribe/unsubscribe requests, include the --filter_symbols flag:

    ./roq-samples-io-context \
      --name trader \
      --ws_port 2345 \
      --udp_port 1234 \
      --filter_symbols \
      ~/run/deribit.sock