Crates.io | barter-data-sniper |
lib.rs | barter-data-sniper |
version | 0.9.2 |
source | src |
created_at | 2024-11-16 11:13:45.664867 |
updated_at | 2024-11-16 17:37:41.779076 |
description | High performance & normalised WebSocket integration for leading cryptocurrency exchanges - batteries included. |
homepage | |
repository | https://github.com/barter-rs/barter-rs |
max_upload_size | |
id | 1450309 |
size | 571,256 |
A high-performance WebSocket integration library for streaming public market data from leading cryptocurrency exchanges - batteries included. It is:
See: Barter
, Barter-Integration
, Barter-Execution
& Barter-Macro
Barter-Data is a high-performance WebSocket integration library for streaming public market data from leading cryptocurrency exchanges. It presents an easy-to-use and extensible set of interfaces that can deliver normalised exchange data in real-time.
From a user perspective, the major component is the StreamBuilder
structures that assists in initialising an
arbitrary number of exchange MarketStream
s using input Subscription
s. Simply build your dream set of
MarketStreams
and Barter-Data
will do the rest!
Exchange | Constructor Code | InstrumentKinds | SubscriptionKinds |
---|---|---|---|
BinanceSpot | BinanceSpot::default() |
Spot | PublicTrades OrderBooksL1 OrderBooksL2 |
BinanceFuturesUsd | BinanceFuturesUsd::default() |
Perpetual | PublicTrades OrderBooksL1 OrderBooksL2 |
Bitfinex | Bitfinex |
Spot | PublicTrades |
Bitmex | Bitmex |
Perpetual | PublicTrades |
BybitSpot | BybitSpot::default() |
Spot | PublicTrades |
BybitPerpetualsUsd | BybitPerpetualsUsd::default() |
Perpetual | PublicTrades |
Coinbase | Coinbase |
Spot | PublicTrades |
GateioSpot | GateioSpot::default() |
Spot | PublicTrades |
GateioFuturesUsd | GateioFuturesUsd::default() |
Future | PublicTrades |
GateioFuturesBtc | GateioFuturesBtc::default() |
Future | PublicTrades |
GateioPerpetualsUsd | GateioPerpetualsUsd::default() |
Perpetual | PublicTrades |
GateioPerpetualsBtc | GateioPerpetualsBtc::default() |
Perpetual | PublicTrades |
GateioOptionsBtc | GateioOptions::default() |
Option | PublicTrades |
Kraken | Kraken |
Spot | PublicTrades OrderBooksL1 |
Okx | Okx |
Spot Future Perpetual Option |
PublicTrades |
See barter-data-rs/examples for a more comprehensive selection of examples!
use barter_data_sniper::{
exchange::{
binance::{futures::BinanceFuturesUsd, spot::BinanceSpot},
bitmex::Bitmex,
bybit::{futures::BybitPerpetualsUsd, spot::BybitSpot},
coinbase::Coinbase,
gateio::{
option::GateioOptions,
perpetual::{GateioPerpetualsBtc, GateioPerpetualsUsd},
spot::GateioSpot,
},
okx::Okx,
},
streams::{Streams, reconnect::stream::ReconnectingStream},
subscription::trade::PublicTrades,
};
use barter_integration_copy::model::instrument::kind::{
FutureContract, InstrumentKind, OptionContract, OptionExercise, OptionKind,
};
use chrono::{TimeZone, Utc};
use futures::StreamExt;
#[tokio::main]
async fn main() {
// Initialise PublicTrades Streams for various exchanges
// '--> each call to StreamBuilder::subscribe() creates 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),
])
.subscribe([
(GateioPerpetualsUsd::default(), "btc", "usdt", InstrumentKind::Perpetual, PublicTrades),
])
.subscribe([
(GateioPerpetualsBtc::default(), "btc", "usd", InstrumentKind::Perpetual, PublicTrades),
])
.subscribe([
(GateioOptions::default(), "btc", "usdt", InstrumentKind::Option(put_contract()), PublicTrades),
])
.subscribe([
(Okx, "btc", "usdt", InstrumentKind::Spot, PublicTrades),
(Okx, "btc", "usdt", InstrumentKind::Perpetual, PublicTrades),
(Okx, "btc", "usd", InstrumentKind::Future(future_contract()), PublicTrades),
(Okx, "btc", "usd", InstrumentKind::Option(call_contract()), PublicTrades),
])
.subscribe([
(BybitSpot::default(), "btc", "usdt", InstrumentKind::Spot, PublicTrades),
(BybitSpot::default(), "eth", "usdt", InstrumentKind::Spot, PublicTrades),
])
.subscribe([
(BybitPerpetualsUsd::default(), "btc", "usdt", InstrumentKind::Perpetual, PublicTrades),
])
.subscribe([
(Bitmex, "xbt", "usd", 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| println!(format!("MarketStream generated error: {error:?}")));
while let Some(event) = joined_stream.next().await {
println!("{event:?}");
}
}
Firstly, see if the answer to your question can be found in the API Documentation. If the answer is not there, I'd be happy to help via Chat and try answer your question via Discord.
Thanks in advance for helping to develop the Barter ecosystem! Please do get hesitate to get touch via the Discord Chat to discuss development, new features, and the future roadmap.
Connector
trait implementation in src/exchange/<exchange_name>.mod.rs (eg/ see exchange::okx::Okx).SubscriptionKind
trait implementation in src/subscription/<sub_kind_name>.rs (eg/ see subscription::trade::PublicTrades).SubscriptionKind::Event
data model (eg/ see subscription::trade::PublicTrade).MarketStream
type the exchange Connector
will initialise for the new SubscriptionKind
: impl StreamSelector<SubscriptionKind> for <ExistingExchangeConnector> { ... }
In addition to the Barter-Execution crate, the Barter project also maintains:
Barter
: High-performance, extensible & modular trading components with batteries-included. Contains a
pre-built trading Engine that can serve as a live-trading or backtesting system.Barter-Integration
: High-performance, low-level framework for composing flexible web integrations.Barter-Execution
: High-performance WebSocket integration library for streaming public market data from leading
cryptocurrency exchanges.Barter-Macro
: Barter ecosystem macros.This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Barter-Data by you, shall be licensed as MIT, without any additional terms or conditions.