| Crates.io | exchange-connectors |
| lib.rs | exchange-connectors |
| version | 0.1.0 |
| created_at | 2025-10-03 12:52:04.0913+00 |
| updated_at | 2025-10-03 12:52:04.0913+00 |
| description | Unified Rust connectors for Binance, KuCoin, Kraken, MEXC (REST + WebSocket) |
| homepage | https://github.com/wajahat414/price_fetcher_server |
| repository | https://github.com/wajahat414/price_fetcher_server |
| max_upload_size | |
| id | 1866631 |
| size | 118,668 |
Unified Rust connectors for top crypto exchanges (Binance, KuCoin, Kraken, MEXC) providing simple REST and WebSocket APIs with a consistent interface.
In your Cargo.toml:
[dependencies]
exchange-connectors = "0.1"
MSRV: Rust 1.70+ recommended.
use exchange_connectors::adapters::{BinanceConnector, KucoinConnector, MexcConnector};
use exchange_connectors::traits::RestApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Binance uses BTCUSDT (no dash); KuCoin uses BTC-USDT (with dash); MEXC uses BTCUSDT.
let binance = BinanceConnector::new();
let b_price = binance.ticker_price("BTC-USDT").await?; // internally normalizes to BTCUSDT
println!("Binance BTC price: {}", b_price);
let kucoin = KucoinConnector::new();
let k_price = kucoin.ticker_price("BTC-USDT").await?;
println!("KuCoin BTC price: {}", k_price);
let mexc = MexcConnector::new();
let m_price = mexc.ticker_price("BTC-USDT").await?;
println!("MEXC BTC price: {}", m_price);
Ok(())
}
use exchange_connectors::adapters::{BinanceConnector, KucoinConnector};
use exchange_connectors::traits::WebSocketApi;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Binance expects lowercase streams and BTCUSDT; KuCoin expects BTC-USDT.
let binance = BinanceConnector::new();
tokio::spawn(async move {
let _ = binance
.subscribe_book_ticker(vec!["BTCUSDT".to_string()], |symbol, bid, ask| {
println!("[Binance] {symbol} bid={:?} ask={:?}", bid, ask);
})
.await;
});
let kucoin = KucoinConnector::new();
kucoin
.subscribe_book_ticker(vec!["BTC-USDT".to_string()], |symbol, bid, ask| {
println!("[KuCoin] {symbol} bid={:?} ask={:?}", bid, ask);
})
.await?;
Ok(())
}
Traits
RestApi
type Error: std::error::Error + Send + 'staticasync fn ticker_price(&self, symbol: &str) -> Result<f64, Self::Error>WebSocketApi
type Error: std::error::Error + Send + 'staticasync fn subscribe_book_ticker<F>(&self, symbols: Vec<String>, on_update: F) -> Result<(), Self::Error>
F: Fn(String, (f64, f64), (f64, f64)) + Send + Sync + 'staticErrors
ConnectorError enum for common cases (HTTP, WS, Binance, Serde, Join, Other)BTCUSDT (no dash). This crate normalizes BTC-USDT -> BTCUSDT for REST.BTC-USDT (dash required).BTCUSDT (no dash). This crate normalizes BTC-USDT -> BTCUSDT for REST.This repository ships with a simple binary (price_fetcher_server) showing how to call a connector. You can run it with:
cargo run
Or create your own binary with the code examples above.
This crate is intended for crates.io. To publish:
Cargo.toml is correct (name, version, license, repository, readme)cargo login
cargo publish --dry-run
cargo publish
cargo build
cargo clippy --all-targets -- -D warnings
cargo fmt --all
cargo run
Notes:
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.