| Crates.io | exchange-pb |
| lib.rs | exchange-pb |
| version | 0.1.0 |
| created_at | 2025-06-02 06:57:45.554575+00 |
| updated_at | 2025-06-02 06:57:45.554575+00 |
| description | protobuf for crypto exchanges |
| homepage | https://github.com/MoyuFunding/exchange-pb |
| repository | https://github.com/MoyuFunding/exchange-pb |
| max_upload_size | |
| id | 1697741 |
| size | 50,339 |
This Rust library provides Protocol Buffer definitions and generated code for MEXC exchange data structures.
This library contains protobuf definitions for various MEXC exchange APIs including:
mexc module)prost for efficient protobuf encoding/decodingAdd this to your Cargo.toml:
[dependencies]
exchange-pb = { path = "." }
use exchange_pb::mexc::*; // Import from mexc module
fn main() {
// Create a book ticker
let book_ticker = PublicBookTickerV3Api {
bid_price: "50000.00".to_string(),
bid_quantity: "1.5".to_string(),
ask_price: "50001.00".to_string(),
ask_quantity: "2.0".to_string(),
};
println!("Bid: {} @ {}", book_ticker.bid_quantity, book_ticker.bid_price);
println!("Ask: {} @ {}", book_ticker.ask_quantity, book_ticker.ask_price);
// Create a wrapper for push data
let wrapper = PushDataV3ApiWrapper {
channel: "spot@public.bookTicker.v3.api".to_string(),
body: Some(push_data_v3_api_wrapper::Body::PublicBookTicker(book_ticker)),
symbol: "BTCUSDT".to_string(),
symbol_id: "BTC_USDT".to_string(),
create_time: 1640995200000,
send_time: 1640995200001,
};
}
The library is organized into modules based on protobuf packages:
exchange_pb::mexc::* - All MEXC exchange related typesYou can import types in different ways:
// Import all types from mexc module
use exchange_pb::mexc::*;
// Import specific types
use exchange_pb::mexc::{PublicBookTickerV3Api, PrivateOrdersV3Api};
// Use fully qualified names
let ticker = exchange_pb::mexc::PublicBookTickerV3Api { /* ... */ };
All generated types support serde serialization:
use exchange_pb::mexc::*;
use serde_json;
let ticker = PublicBookTickerV3Api {
bid_price: "50000.00".to_string(),
bid_quantity: "1.5".to_string(),
ask_price: "50001.00".to_string(),
ask_quantity: "2.0".to_string(),
};
// Serialize to JSON
let json = serde_json::to_string_pretty(&ticker)?;
println!("{}", json);
// Deserialize from JSON
let deserialized: PublicBookTickerV3Api = serde_json::from_str(&json)?;
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 tickerPrivateOrdersV3Api - Order informationPrivateDealsV3Api - Private trade execution dataPrivateAccountV3Api - Account balance and infoPushDataV3ApiWrapper - Main wrapper for all push data typesThe project uses a custom build script to compile all protobuf files recursively:
cargo build
The build script will:
.proto files in the proto/ directory recursivelyprost-build with package supportmexc.rs)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.
To add new protobuf definitions:
.proto files to the appropriate directory under proto/package mexc;import "SomeType.proto") for files in the same packagecargo build to regenerate the Rust codeRun the tests to verify everything works:
cargo test
Run the examples:
# Basic usage example
cargo run --example basic_usage
# Modular usage example with JSON serialization
cargo run --example modular_usage
This project is licensed under the MIT License.