Financial Protocol C++ Library

August 9, 2025 · View on GitHub

This repository contains a C++ implementation of various financial market protocols and their associated binary message formats. It provides encoding/decoding capabilities for multiple exchange protocols, along with supporting utilities for buffer management, checksum calculation, and data serialization.

Project Structure

├── include/                 # Header files for all protocol implementations
├── test/                    # Unit tests for all components
├── CMakeLists.txt           # CMake build configuration
├── Makefile                 # Build automation

Supported Protocols

  1. BJSE Binary Protocol (bjse_binary.hpp)

    • Implementation of Beijing Stock Exchange binary protocol
    • Supports various order types, execution reports, and market data messages
  2. RC Binary Protocol (rc_binary.hpp)

    • Risk control binary protocol implementation
    • Focused on order management and risk validation
  3. SSE Binary Protocol (sse_binary.hpp)

    • Shanghai Stock Exchange binary protocol
    • Supports trading and market data message formats
  4. SZSE Binary Protocol (szse_binary.hpp)

    • Shenzhen Stock Exchange binary protocol
    • Comprehensive implementation of SZSE message specifications
  5. Root Packet Protocol (root_packet.hpp)

    • Generic packet structure with payload encapsulation
    • Supports nested packet structures and various data types

Core Components

Byte Buffer (bytebuf.hpp)

  • Efficient byte buffer implementation for serialization/deserialization
  • Supports reading/writing of various primitive data types
  • Provides bounds checking and memory management

Codec Utilities (codec.hpp)

  • String serialization with length encoding
  • Fixed-length string handling
  • Vector/list serialization utilities
  • Data joining and formatting functions

Checksum Services (checksum.hpp)

  • CRC16 and CRC32 checksum implementations
  • Exchange-specific checksum algorithms (SSE, SZSE)
  • Context-based checksum service selection

Building the Project

Prerequisites

  • C++17 compatible compiler
  • CMake 3.16 or higher
  • ZLIB library
  • GoogleTest (for unit tests)

Build Instructions

# Using CMake
mkdir build && cd build
cmake ..
make

Running Tests

The project includes comprehensive unit tests for all protocols and utilities:

# Run all tests
ctest

# Or run specific test executables
./bytebuf_test
./codec_test
./root_packet_test
./sse_bin_test
./szse_bin_test
./rc_bin_test
./checksum_test
./bjse_trade_test

Key Features

  1. Protocol Compliance: Implements exact specifications for multiple exchange protocols
  2. Memory Efficient: Uses smart pointers and efficient buffer management
  3. Type Safe: Strong typing for all protocol fields and messages
  4. Extensible: Easy to add new protocols or extend existing ones
  5. Well Tested: Comprehensive test coverage for all components
  6. Cross-Platform: Compatible with major operating systems

Usage Example

#include "include/sse_binary.hpp"
#include "include/bytebuf.hpp"

// Create and populate a message
Logon logon;
logon.senderCompId = "TRADER_001";
logon.targetCompId = "EXCHANGE";
logon.heartBtInt = 30;

// Encode to buffer
ByteBuf buffer;
logon.encode(buffer);

// Decode from buffer
Logon decoded;
decoded.decode(buffer);

Development

This library is generated using the fin-protoc protocol compiler, which transforms protocol definition files (.pdsl) into C++ code. Manual modifications to generated files should be avoided as they will be overwritten during regeneration.

  • fin-proto

    • A comprehensive financial protocol library
    • Supports SSE, SZSE, and risk protocols
    • Includes Lua dissectors for Wireshark
  • fin-proto-rs

    • High-performance binary codec in Rust
    • Zero-copy serialization/deserialization
    • Supports SSE, SZSE, and risk protocols
    • Includes unit testing infrastructure
  • fin-proto-go

    • Native Go implementation of the protocols
    • Standardized codec interface
    • Modular, exchange-specific architecture
    • This repository has been integrated into the gt-auto repository, an automated testing tool for financial systems(gateway,engine and so on)
  • fin-proto-java

    • Binary protocol codec for Java
    • Netty ByteBuf integration
    • Gradle build system
    • Java 17+ compatible
  • fin-proto-py

    • Python implementation for financial protocols
    • SSE, SZSE, and risk protocol support
    • Easy-to-use parsing and serialization API

License

Copyright 2025 xinchentechnote

Code generated by fin-protoc. DO NOT EDIT.

Ask DeepWiki