Enum barter_data::ExchangeId
source · pub enum ExchangeId {
BinanceFuturesUsd,
Binance,
Coinbase,
Ftx,
Kraken,
}Expand description
Used to uniquely identify an ExchangeTransformer implementation. Each variant represents an
exchange server which can be subscribed to. Note that an exchange may have multiple servers
(eg/ binance, binance_futures), therefore there could be a many-to-one relationship between
an ExchangeId and an Exchange.
Variants§
Implementations§
source§impl ExchangeId
impl ExchangeId
sourcepub fn name(&self) -> &'static str
pub fn name(&self) -> &'static str
Return the exchange name associated with this ExchangeId.
eg/ ExchangeId::BinanceFuturesUsd => “binance”
sourcepub fn as_str(&self) -> &'static str
pub fn as_str(&self) -> &'static str
Return the &str representation this ExchangeId is associated with.
Examples found in repository?
More examples
79 80 81 82 83 84 85 86 87 88 89 90 91 92
fn from((exchange, instrument, trade): (ExchangeId, Instrument, FtxTrade)) -> Self {
Self {
exchange_time: trade.time,
received_time: Utc::now(),
exchange: Exchange::from(exchange.as_str()),
instrument,
kind: DataKind::Trade(PublicTrade {
id: trade.id.to_string(),
price: trade.price,
quantity: trade.size,
side: trade.side,
}),
}
}112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
fn try_from(kind: &SubKind) -> Result<Self, Self::Error> {
match kind {
SubKind::Trade => Ok(KrakenSubKind::Trade {
channel: KrakenSubKind::TRADE,
}),
SubKind::Candle(interval) => Ok(KrakenSubKind::Candle {
channel: KrakenSubKind::CANDLE,
interval: u32::from(KrakenInterval::try_from(interval)?),
}),
other => Err(SocketError::Unsupported {
entity: Kraken::EXCHANGE.as_str(),
item: other.to_string(),
}),
}
}
}
/// Kraken time interval used for specifying the interval of a [`KrakenSubKind::Candle`].
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Deserialize, Serialize)]
pub enum KrakenInterval {
Minute1,
Minute5,
Minute15,
Minute30,
Hour1,
Hour4,
Hour12,
Day1,
Week1,
}
impl TryFrom<&Interval> for KrakenInterval {
type Error = SocketError;
fn try_from(interval: &Interval) -> Result<Self, Self::Error> {
match interval {
Interval::Minute1 => Ok(KrakenInterval::Minute1),
Interval::Minute5 => Ok(KrakenInterval::Minute5),
Interval::Minute15 => Ok(KrakenInterval::Minute15),
Interval::Minute30 => Ok(KrakenInterval::Minute30),
Interval::Hour1 => Ok(KrakenInterval::Hour1),
Interval::Hour4 => Ok(KrakenInterval::Hour4),
Interval::Hour12 => Ok(KrakenInterval::Hour12),
Interval::Day1 => Ok(KrakenInterval::Day1),
Interval::Week1 => Ok(KrakenInterval::Week1),
other => Err(SocketError::Unsupported {
entity: Kraken::EXCHANGE.as_str(),
item: other.to_string(),
}),
}
}103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
pub fn build_channel_meta(sub: &Subscription) -> Result<(&str, String), SocketError> {
// Validate provided Subscription InstrumentKind is supported by Coinbase
let sub = sub.validate()?;
// Determine Coinbase channel using the Subscription SubKind
let channel = match &sub.kind {
SubKind::Trade => Self::CHANNEL_TRADES,
other => {
return Err(SocketError::Unsupported {
entity: Self::EXCHANGE.as_str(),
item: other.to_string(),
})
}
};
// Determine Coinbase market identifier using the Instrument (eg/ "BTC-USD")
let market = format!("{}-{}", sub.instrument.base, sub.instrument.quote).to_uppercase();
Ok((channel, market))
}139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
pub fn build_channel_meta(sub: &Subscription) -> Result<(&str, String), SocketError> {
// Validate provided Subscription InstrumentKind is supported by BinanceFuturesUsd
let sub = sub.validate()?;
// Determine the BinanceFuturesUsd channel
let channel = match &sub.kind {
SubKind::Trade => Self::CHANNEL_TRADES,
SubKind::OrderBook => Self::CHANNEL_ORDER_BOOK,
SubKind::Liquidation => Self::CHANNEL_LIQUIDATIONS,
other => {
return Err(SocketError::Unsupported {
entity: BinanceFuturesUsd::EXCHANGE.as_str(),
item: other.to_string(),
})
}
};
// Determine BinanceFuturesUsd market using the Instrument
let market = format!("{}{}", sub.instrument.base, sub.instrument.quote);
Ok((channel, market))
}116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
pub fn build_channel_meta(sub: &Subscription) -> Result<(&str, String), SocketError> {
// Validate provided Subscription InstrumentKind is supported by Ftx
let sub = sub.validate()?;
// Determine Ftx channel using the Subscription SubKind
let channel = match &sub.kind {
SubKind::Trade => Self::CHANNEL_TRADES,
other => {
return Err(SocketError::Unsupported {
entity: Self::EXCHANGE.as_str(),
item: other.to_string(),
})
}
};
// Determine Ftx market using the Instrument
let market = match &sub.instrument.kind {
InstrumentKind::Spot => format!("{}/{}", sub.instrument.base, sub.instrument.quote),
InstrumentKind::FuturePerpetual => format!("{}-PERP", sub.instrument.base),
};
Ok((channel, market.to_uppercase()))
}sourcepub fn supports_spot(&self) -> bool
pub fn supports_spot(&self) -> bool
Determines whether this ExchangeId supports the ingestion of
InstrumentKind::Spot market data.
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn validate(self) -> Result<Self, SocketError>
where
Self: Sized,
{
// Check if ExchangeId supports the Subscription InstrumentKind
match self.instrument.kind {
InstrumentKind::Spot if self.exchange.supports_spot() => {}
InstrumentKind::FuturePerpetual if self.exchange.supports_futures() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
// Check if ExchangeId supports the Subscription SubKind
match self.kind {
SubKind::Trade if self.exchange.supports_trades() => {}
SubKind::Candle(_) if self.exchange.supports_candles() => {}
SubKind::OrderBook if self.exchange.supports_order_books() => {}
SubKind::Liquidation if self.exchange.supports_liquidations() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
Ok(self)
}sourcepub fn supports_futures(&self) -> bool
pub fn supports_futures(&self) -> bool
Determines whether this ExchangeId supports the collection of
InstrumentKind::Future** market data.
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn validate(self) -> Result<Self, SocketError>
where
Self: Sized,
{
// Check if ExchangeId supports the Subscription InstrumentKind
match self.instrument.kind {
InstrumentKind::Spot if self.exchange.supports_spot() => {}
InstrumentKind::FuturePerpetual if self.exchange.supports_futures() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
// Check if ExchangeId supports the Subscription SubKind
match self.kind {
SubKind::Trade if self.exchange.supports_trades() => {}
SubKind::Candle(_) if self.exchange.supports_candles() => {}
SubKind::OrderBook if self.exchange.supports_order_books() => {}
SubKind::Liquidation if self.exchange.supports_liquidations() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
Ok(self)
}sourcepub fn supports_trades(&self) -> bool
pub fn supports_trades(&self) -> bool
Determines whether this ExchangeId supports the collection of
PublicTrade market data.
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn validate(self) -> Result<Self, SocketError>
where
Self: Sized,
{
// Check if ExchangeId supports the Subscription InstrumentKind
match self.instrument.kind {
InstrumentKind::Spot if self.exchange.supports_spot() => {}
InstrumentKind::FuturePerpetual if self.exchange.supports_futures() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
// Check if ExchangeId supports the Subscription SubKind
match self.kind {
SubKind::Trade if self.exchange.supports_trades() => {}
SubKind::Candle(_) if self.exchange.supports_candles() => {}
SubKind::OrderBook if self.exchange.supports_order_books() => {}
SubKind::Liquidation if self.exchange.supports_liquidations() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
Ok(self)
}sourcepub fn supports_candles(&self) -> bool
pub fn supports_candles(&self) -> bool
Determines whether this ExchangeId supports the collection of
Candle market data.
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn validate(self) -> Result<Self, SocketError>
where
Self: Sized,
{
// Check if ExchangeId supports the Subscription InstrumentKind
match self.instrument.kind {
InstrumentKind::Spot if self.exchange.supports_spot() => {}
InstrumentKind::FuturePerpetual if self.exchange.supports_futures() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
// Check if ExchangeId supports the Subscription SubKind
match self.kind {
SubKind::Trade if self.exchange.supports_trades() => {}
SubKind::Candle(_) if self.exchange.supports_candles() => {}
SubKind::OrderBook if self.exchange.supports_order_books() => {}
SubKind::Liquidation if self.exchange.supports_liquidations() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
Ok(self)
}sourcepub fn supports_order_books(&self) -> bool
pub fn supports_order_books(&self) -> bool
Determines whether this ExchangeId supports the collection of OrderBook snapshot
market data.
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn validate(self) -> Result<Self, SocketError>
where
Self: Sized,
{
// Check if ExchangeId supports the Subscription InstrumentKind
match self.instrument.kind {
InstrumentKind::Spot if self.exchange.supports_spot() => {}
InstrumentKind::FuturePerpetual if self.exchange.supports_futures() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
// Check if ExchangeId supports the Subscription SubKind
match self.kind {
SubKind::Trade if self.exchange.supports_trades() => {}
SubKind::Candle(_) if self.exchange.supports_candles() => {}
SubKind::OrderBook if self.exchange.supports_order_books() => {}
SubKind::Liquidation if self.exchange.supports_liquidations() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
Ok(self)
}sourcepub fn supports_order_book_l2_deltas(&self) -> bool
pub fn supports_order_book_l2_deltas(&self) -> bool
Determines whether this ExchangeId supports the collection of
L2 OrderBook delta market data.
sourcepub fn supports_order_book_l3_deltas(&self) -> bool
pub fn supports_order_book_l3_deltas(&self) -> bool
Determines whether this ExchangeId supports the collection of
L3 OrderBook delta market data.
sourcepub fn supports_liquidations(&self) -> bool
pub fn supports_liquidations(&self) -> bool
Determines whether this ExchangeId supports the collection of
liquidation orders market data.
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
fn validate(self) -> Result<Self, SocketError>
where
Self: Sized,
{
// Check if ExchangeId supports the Subscription InstrumentKind
match self.instrument.kind {
InstrumentKind::Spot if self.exchange.supports_spot() => {}
InstrumentKind::FuturePerpetual if self.exchange.supports_futures() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
// Check if ExchangeId supports the Subscription SubKind
match self.kind {
SubKind::Trade if self.exchange.supports_trades() => {}
SubKind::Candle(_) if self.exchange.supports_candles() => {}
SubKind::OrderBook if self.exchange.supports_order_books() => {}
SubKind::Liquidation if self.exchange.supports_liquidations() => {}
other => {
return Err(SocketError::Unsupported {
entity: self.exchange.as_str(),
item: other.to_string(),
})
}
};
Ok(self)
}Trait Implementations§
source§impl Clone for ExchangeId
impl Clone for ExchangeId
source§fn clone(&self) -> ExchangeId
fn clone(&self) -> ExchangeId
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ExchangeId
impl Debug for ExchangeId
source§impl<'de> Deserialize<'de> for ExchangeId
impl<'de> Deserialize<'de> for ExchangeId
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for ExchangeId
impl Display for ExchangeId
source§impl From<ExchangeId> for Exchange
impl From<ExchangeId> for Exchange
source§fn from(exchange_id: ExchangeId) -> Self
fn from(exchange_id: ExchangeId) -> Self
source§impl Hash for ExchangeId
impl Hash for ExchangeId
source§impl Ord for ExchangeId
impl Ord for ExchangeId
source§fn cmp(&self, other: &ExchangeId) -> Ordering
fn cmp(&self, other: &ExchangeId) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq<ExchangeId> for ExchangeId
impl PartialEq<ExchangeId> for ExchangeId
source§fn eq(&self, other: &ExchangeId) -> bool
fn eq(&self, other: &ExchangeId) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd<ExchangeId> for ExchangeId
impl PartialOrd<ExchangeId> for ExchangeId
source§fn partial_cmp(&self, other: &ExchangeId) -> Option<Ordering>
fn partial_cmp(&self, other: &ExchangeId) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl Serialize for ExchangeId
impl Serialize for ExchangeId
impl Copy for ExchangeId
impl Eq for ExchangeId
impl StructuralEq for ExchangeId
impl StructuralPartialEq for ExchangeId
Auto Trait Implementations§
impl RefUnwindSafe for ExchangeId
impl Send for ExchangeId
impl Sync for ExchangeId
impl Unpin for ExchangeId
impl UnwindSafe for ExchangeId
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.