use self::subscription::ExchangeSub;
use crate::{
MarketStream, SnapshotFetcher,
instrument::InstrumentData,
subscriber::{Subscriber, validator::SubscriptionValidator},
subscription::{Map, SubscriptionKind},
};
use barter_instrument::exchange::ExchangeId;
use barter_integration::{Validator, error::SocketError, protocol::websocket::WsMessage};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use std::{fmt::Debug, time::Duration};
use url::Url;
pub mod binance;
pub mod bitfinex;
pub mod bitmex;
pub mod bybit;
pub mod coinbase;
pub mod gateio;
pub mod kraken;
pub mod okx;
pub mod subscription;
pub const DEFAULT_SUBSCRIPTION_TIMEOUT: Duration = Duration::from_secs(10);
pub trait StreamSelector<Instrument, Kind>
where
Self: Connector,
Instrument: InstrumentData,
Kind: SubscriptionKind,
{
type SnapFetcher: SnapshotFetcher<Self, Kind>;
type Stream: MarketStream<Self, Instrument, Kind>;
}
pub trait Connector
where
Self: Clone + Default + Debug + for<'de> Deserialize<'de> + Serialize + Sized,
{
const ID: ExchangeId;
type Channel: AsRef<str>;
type Market: AsRef<str>;
type Subscriber: Subscriber;
type SubValidator: SubscriptionValidator;
type SubResponse: Validator<Error = SocketError> + Debug + DeserializeOwned;
fn url() -> Result<Url, url::ParseError>;
fn ping_interval() -> Option<PingInterval> {
None
}
fn requests(exchange_subs: Vec<ExchangeSub<Self::Channel, Self::Market>>) -> Vec<WsMessage>;
fn expected_responses<InstrumentKey>(map: &Map<InstrumentKey>) -> usize {
map.0.len()
}
fn subscription_timeout() -> Duration {
DEFAULT_SUBSCRIPTION_TIMEOUT
}
}
pub trait ExchangeServer: Default + Debug + Clone + Send {
const ID: ExchangeId;
fn websocket_url() -> &'static str;
}
#[derive(Debug)]
pub struct PingInterval {
pub interval: tokio::time::Interval,
pub ping: fn() -> WsMessage,
}