Exchange Protocol Buffers
This Rust library provides Protocol Buffer definitions and generated code for MEXC exchange data structures.
Overview
This library contains protobuf definitions for various MEXC exchange APIs including:
- Public market data (book tickers, mini tickers, deals, depths, klines)
- Private account data (orders, deals, account info)
- Batch operations for multiple data items
- Aggregated data structures
Features
- Modular Structure: Generated code is organized by package (e.g.,
mexcmodule) - Async-ready: Generated structs work seamlessly with async Rust code
- Serde compatible: All generated types support JSON serialization/deserialization
- Type-safe: Leverages Rust's type system for safe data handling
- Performance: Uses
prostfor efficient protobuf encoding/decoding
Usage
Add this to your Cargo.toml:
[]
= { = "." }
Basic Example
use *; // Import from mexc module
Module Structure
The library is organized into modules based on protobuf packages:
exchange_pb::mexc::*- All MEXC exchange related types
You can import types in different ways:
// Import all types from mexc module
use *;
// Import specific types
use ;
// Use fully qualified names
let ticker = PublicBookTickerV3Api ;
JSON Serialization
All generated types support serde serialization:
use *;
use serde_json;
let ticker = PublicBookTickerV3Api ;
// Serialize to JSON
let json = to_string_pretty?;
println!;
// Deserialize from JSON
let deserialized: PublicBookTickerV3Api = from_str?;
Available Types
Public Market Data
PublicBookTickerV3Api- Best bid/ask prices and quantitiesPublicBookTickerBatchV3Api- Batch of book tickersPublicMiniTickerV3Api- Mini ticker with basic price infoPublicMiniTickersV3Api- Batch of mini tickersPublicDealsV3Api- Trade execution dataPublicIncreaseDepthsV3Api- Order book depth updatesPublicLimitDepthsV3Api- Order book snapshotPublicSpotKlineV3Api- Candlestick/kline dataPublicAggreDepthsV3Api- Aggregated depth dataPublicAggreDealsV3Api- Aggregated trade dataPublicAggreBookTickerV3Api- Aggregated book ticker
Private Account Data
PrivateOrdersV3Api- Order informationPrivateDealsV3Api- Private trade execution dataPrivateAccountV3Api- Account balance and info
Wrapper Types
PushDataV3ApiWrapper- Main wrapper for all push data types
Building
The project uses a custom build script to compile all protobuf files recursively:
The build script will:
- Find all
.protofiles in theproto/directory recursively - Compile them using
prost-buildwith package support - Generate Rust code organized by package (e.g.,
mexc.rs) - Include the generated code in the library modules
Proto File Structure
proto/
└── mexc/
├── PublicBookTickerV3Api.proto (package mexc;)
├── PublicMiniTickerV3Api.proto (package mexc;)
├── PrivateOrdersV3Api.proto (package mexc;)
├── PushDataV3ApiWrapper.proto (package mexc;)
└── ... (other proto files)
All proto files in the mexc/ directory use package mexc; which results in generated code being placed in the mexc.rs file and accessible via the mexc module.
Development
To add new protobuf definitions:
- Add your
.protofiles to the appropriate directory underproto/ - Include the package declaration:
package mexc; - Ensure imports use just the filename (e.g.,
import "SomeType.proto") for files in the same package - Run
cargo buildto regenerate the Rust code - The new types will be available in the appropriate module
Testing
Run the tests to verify everything works:
Run the examples:
# Basic usage example
# Modular usage example with JSON serialization
License
This project is licensed under the MIT License.