Expand description
§Barter-Data
A high-performance WebSocket integration library for streaming public market data from leading cryptocurrency exchanges - batteries included. It is:
- Easy: Barter-Data’s simple
StreamBuilderandDynamicStreamsinterface allows for easy & quick setup (see example below and /examples!). - Normalised: Barter-Data’s unified interface for consuming public WebSocket data means every Exchange returns a normalised data model.
- Real-Time: Barter-Data utilises real-time WebSocket integrations enabling the consumption of normalised tick-by-tick data.
- Extensible: Barter-Data is highly extensible, and therefore easy to contribute to with coding new integrations!
§User API
StreamBuilderfor initialisingMarketStreams of specific data kinds.DynamicStreamsfor initialisingMarketStreams of every supported data kind at once.- Define what exchange market data you want to stream using the
Subscriptiontype. - Pass
Subscriptions to theStreamBuilder::subscribeorDynamicStreams::initmethods. - Each call to the
StreamBuilder::subscribe(or each batch passed to theDynamicStreams::init) method opens a new WebSocket connection to the exchange - giving you full control.
§Examples
For a comprehensive collection of examples, see the /examples directory.
§Multi Exchange Public Trades
use barter_data::exchange::gateio::spot::GateioSpot;
use barter_data::{
exchange::{
binance::{futures::BinanceFuturesUsd, spot::BinanceSpot},
coinbase::Coinbase,
okx::Okx,
},
streams::{Streams, reconnect::stream::ReconnectingStream},
subscription::trade::PublicTrades,
};
use barter_integration::model::instrument::kind::InstrumentKind;
use futures::StreamExt;
use tracing::warn;
#[tokio::main]
async fn main() {
// Initialise PublicTrades Streams for various exchanges
// '--> each call to StreamBuilder::subscribe() initialises a separate WebSocket connection
let streams = Streams::<PublicTrades>::builder()
.subscribe([
(BinanceSpot::default(), "btc", "usdt", InstrumentKind::Spot, PublicTrades),
(BinanceSpot::default(), "eth", "usdt", InstrumentKind::Spot, PublicTrades),
])
.subscribe([
(BinanceFuturesUsd::default(), "btc", "usdt", InstrumentKind::Perpetual, PublicTrades),
(BinanceFuturesUsd::default(), "eth", "usdt", InstrumentKind::Perpetual, PublicTrades),
])
.subscribe([
(Coinbase, "btc", "usd", InstrumentKind::Spot, PublicTrades),
(Coinbase, "eth", "usd", InstrumentKind::Spot, PublicTrades),
])
.subscribe([
(GateioSpot::default(), "btc", "usdt", InstrumentKind::Spot, PublicTrades),
(GateioSpot::default(), "eth", "usdt", InstrumentKind::Spot, PublicTrades),
])
.subscribe([
(Okx, "btc", "usdt", InstrumentKind::Spot, PublicTrades),
(Okx, "eth", "usdt", InstrumentKind::Spot, PublicTrades),
(Okx, "btc", "usdt", InstrumentKind::Perpetual, PublicTrades),
(Okx, "eth", "usdt", InstrumentKind::Perpetual, PublicTrades),
])
.init()
.await
.unwrap();
// Select and merge every exchange Stream using futures_util::stream::select_all
// Note: use `Streams.select(ExchangeId)` to interact with individual exchange streams!
let mut joined_stream = streams
.select_all()
.with_error_handler(|error| warn!(?error, "MarketStream generated error"));
while let Some(event) = joined_stream.next().await {
println!("{event:?}");
}
}Modules§
- All
Errors generated in Barter-Data. - Defines the generic
MarketEvent<T>used in everyMarketStream. Connectorimplementations for each exchange.InstrumentDatatrait for instrument describing data.- High-level API types used for building
MarketStreams from collections of BarterSubscriptions. Subscriber,SubscriptionMapperandSubscriptionValidatortraits that define how aConnectorwill subscribe to exchangeMarketStreams.- Types that communicate the type of each
MarketStreamto initialise, and what normalised Barter output type the exchange will be transformed into. - Generic
ExchangeTransformerimplementations used byMarketStreams to translate exchange specific types to normalised Barter types.
Structs§
- Implementation of
SnapshotFetcherthat does not fetch any initial market data snapshots. Often used for statelessMarketStreams, such as public trades.
Traits§
- Defines a generic identification type for the implementor.
Streamthat yieldsMarket<Kind>events. The type ofMarket<Kind>depends on the providedSubscriptionKindof the passedSubscriptions.- Defines how to fetch market data snapshots for a collection of
Subscriptions.
Functions§
- Schedule the sending of custom application-level ping
WsMessages to the exchange using the providedPingInterval.
Type Aliases§
- Convenient type alias for an
ExchangeStreamutilising a tungsteniteWebSocket.