exchange-connectors
Unified Rust connectors for top crypto exchanges (Binance, KuCoin, Kraken, MEXC) providing simple REST and WebSocket APIs with a consistent interface.
Why this library?
- One small, consistent API across multiple exchanges
- Minimal dependencies; straightforward to integrate into bots, data collectors, and services
- Start with best-bid/ask (book ticker) and spot ticker; extend as needed
Features
- Consistent traits across exchanges
- REST: fetch simple spot ticker price
- WebSocket: subscribe to book ticker (best bid/ask) updates
- Adapters included
- Binance: REST + WS (bookTicker)
- KuCoin: REST + WS (ticker)
- Kraken: stubs (TODO)
- MEXC: REST implemented, WS stub (TODO)
- Optional example binary left in the repo (price_fetcher_server)
Crate status
- Alpha: API surface is small and may change.
- Implemented: Binance (REST/WS), KuCoin (REST/WS), MEXC (REST)
- Planned: Kraken (REST/WS), MEXC (WS)
Install
In your Cargo.toml:
[]
= "0.1"
MSRV: Rust 1.70+ recommended.
Support matrix
- Binance: REST ticker (OK), WS bookTicker (OK)
- KuCoin: REST ticker (OK), WS ticker (OK)
- MEXC: REST ticker (OK), WS (Planned)
- Kraken: REST/WS (Planned)
Quick start
REST usage
use ;
use RestApi;
async
WebSocket usage (book ticker)
use ;
use WebSocketApi;
async
API surface
-
Traits
RestApitype Error: std::error::Error + Send + 'staticasync fn ticker_price(&self, symbol: &str) -> Result<f64, Self::Error>
WebSocketApitype 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 + 'static
-
Errors
- Unified
ConnectorErrorenum for common cases (HTTP, WS, Binance, Serde, Join, Other)
- Unified
Symbol conventions
- Binance:
BTCUSDT(no dash). This crate normalizesBTC-USDT->BTCUSDTfor REST. - KuCoin:
BTC-USDT(dash required). - MEXC:
BTCUSDT(no dash). This crate normalizesBTC-USDT->BTCUSDTfor REST. - Kraken: varies; mapping TBD (coming soon).
Examples
This repository ships with a simple binary (price_fetcher_server) showing how to call a connector. You can run it with:
Or create your own binary with the code examples above.
Publishing (maintainers)
This crate is intended for crates.io. To publish:
- Ensure metadata in
Cargo.tomlis correct (name, version, license, repository, readme) - Login to crates.io and dry-run:
- Publish:
Development
- Build and check:
- Run the example binary:
Notes:
- Public/private endpoints beyond ticker are not yet implemented (no auth flow)
- Handle exchange rate limits yourself; this crate performs raw requests
- Network errors and stream drops are surfaced via errors; consider reconnect/backoff in your app
Roadmap
- Implement Kraken REST ticker
- Implement Kraken WS book ticker
- Implement MEXC WS book ticker
- Add feature flags per exchange to make deps optional
- Add tests and CI
- Stabilize trait API and version 0.2
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
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.