Struct barter_data::exchange::coinbase::Coinbase
source · pub struct Coinbase {
pub ids: SubscriptionIds,
}Expand description
Coinbase Subscriber & ExchangeTransformer implementor for the collection
of Spot & Futures data.
Fields§
§ids: SubscriptionIdsImplementations§
source§impl Coinbase
impl Coinbase
sourcepub const CHANNEL_TRADES: &'static str = "matches"
pub const CHANNEL_TRADES: &'static str = "matches"
Coinbase trades channel name.
See docs: https://docs.cloud.coinbase.com/exchange/docs/websocket-channels#match
sourcepub fn build_channel_meta(
sub: &Subscription
) -> Result<(&str, String), SocketError>
pub fn build_channel_meta(
sub: &Subscription
) -> Result<(&str, String), SocketError>
Determine the Coinbase channel metadata associated with an input Barter Subscription.
This includes the Coinbase &str channel, and a String market identifier. Both are
used to build an Coinbase subscription payload.
Example Ok return: Ok(“matches”, “BTC-USD”) where channel == “matches” & market == “BTC-USD”.
Examples found in repository?
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 59 60 61
fn build_subscription_meta(
subscriptions: &[Subscription],
) -> Result<SubscriptionMeta, SocketError> {
// Allocate SubscriptionIds HashMap to track identifiers for each actioned Subscription
let mut ids = SubscriptionIds(HashMap::with_capacity(subscriptions.len()));
// Map Barter Subscriptions to Coinbase channels
let subscriptions = subscriptions
.iter()
.map(|subscription| {
// Determine the Coinbase specific channel & market for this Barter Subscription
let (channel, market) = Self::build_channel_meta(subscription)?;
// Use "channel|market" as the SubscriptionId key in the SubscriptionIds HashMap
// eg/ SubscriptionId("matches|ETH-USD")
ids.insert(
Coinbase::subscription_id(channel, &market),
subscription.clone(),
);
// Construct Coinbase specific subscription message
Ok(Self::subscription(channel, &market))
})
.collect::<Result<Vec<_>, SocketError>>()?;
Ok(SubscriptionMeta {
ids,
expected_responses: subscriptions.len(),
subscriptions,
})
}sourcepub fn subscription(channel: &str, market: &str) -> WsMessage
pub fn subscription(channel: &str, market: &str) -> WsMessage
Build a Coinbase compatible subscription message using the channel & market provided.
Examples found in repository?
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 59 60 61
fn build_subscription_meta(
subscriptions: &[Subscription],
) -> Result<SubscriptionMeta, SocketError> {
// Allocate SubscriptionIds HashMap to track identifiers for each actioned Subscription
let mut ids = SubscriptionIds(HashMap::with_capacity(subscriptions.len()));
// Map Barter Subscriptions to Coinbase channels
let subscriptions = subscriptions
.iter()
.map(|subscription| {
// Determine the Coinbase specific channel & market for this Barter Subscription
let (channel, market) = Self::build_channel_meta(subscription)?;
// Use "channel|market" as the SubscriptionId key in the SubscriptionIds HashMap
// eg/ SubscriptionId("matches|ETH-USD")
ids.insert(
Coinbase::subscription_id(channel, &market),
subscription.clone(),
);
// Construct Coinbase specific subscription message
Ok(Self::subscription(channel, &market))
})
.collect::<Result<Vec<_>, SocketError>>()?;
Ok(SubscriptionMeta {
ids,
expected_responses: subscriptions.len(),
subscriptions,
})
}sourcepub fn subscription_id(channel: &str, market: &str) -> SubscriptionId
pub fn subscription_id(channel: &str, market: &str) -> SubscriptionId
Build a Coinbase compatible SubscriptionId using the channel & market provided.
This is used to associate Coinbase data structures received over the WebSocket with it’s
original Barter Subscription.
eg/ SubscriptionId(“matches|ETH-USD”)
Examples found in repository?
More examples
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 59 60 61
fn build_subscription_meta(
subscriptions: &[Subscription],
) -> Result<SubscriptionMeta, SocketError> {
// Allocate SubscriptionIds HashMap to track identifiers for each actioned Subscription
let mut ids = SubscriptionIds(HashMap::with_capacity(subscriptions.len()));
// Map Barter Subscriptions to Coinbase channels
let subscriptions = subscriptions
.iter()
.map(|subscription| {
// Determine the Coinbase specific channel & market for this Barter Subscription
let (channel, market) = Self::build_channel_meta(subscription)?;
// Use "channel|market" as the SubscriptionId key in the SubscriptionIds HashMap
// eg/ SubscriptionId("matches|ETH-USD")
ids.insert(
Coinbase::subscription_id(channel, &market),
subscription.clone(),
);
// Construct Coinbase specific subscription message
Ok(Self::subscription(channel, &market))
})
.collect::<Result<Vec<_>, SocketError>>()?;
Ok(SubscriptionMeta {
ids,
expected_responses: subscriptions.len(),
subscriptions,
})
}Trait Implementations§
source§impl<'de> Deserialize<'de> for Coinbase
impl<'de> Deserialize<'de> for Coinbase
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 ExchangeTransformer for Coinbase
impl ExchangeTransformer for Coinbase
source§const EXCHANGE: ExchangeId = ExchangeId::Coinbase
const EXCHANGE: ExchangeId = ExchangeId::Coinbase
ExchangeTransformer.source§fn new(_: UnboundedSender<WsMessage>, ids: SubscriptionIds) -> Self
fn new(_: UnboundedSender<WsMessage>, ids: SubscriptionIds) -> Self
ExchangeTransformer using a transmitter to the WsSink and the
SubscriptionIds HashMap. Read moresource§impl PartialEq<Coinbase> for Coinbase
impl PartialEq<Coinbase> for Coinbase
source§impl Subscriber for Coinbase
impl Subscriber for Coinbase
§type SubResponse = CoinbaseSubResponse
type SubResponse = CoinbaseSubResponse
Subscriber expects to receive from the exchange in
response to Subscription requests. Implements Validator in order to determine
if the SubResponse communicates a successful outcome.source§fn base_url() -> &'static str
fn base_url() -> &'static str
source§fn build_subscription_meta(
subscriptions: &[Subscription]
) -> Result<SubscriptionMeta, SocketError>
fn build_subscription_meta(
subscriptions: &[Subscription]
) -> Result<SubscriptionMeta, SocketError>
Subscriptions to build exchange specific subscription
payloads. Generates a SubscriptionIds Hashmap that is used by an ExchangeTransformer
to identify the Barter Subscriptions associated with received messages.source§fn subscribe<'life0, 'async_trait>(
subscriptions: &'life0 [Subscription]
) -> Pin<Box<dyn Future<Output = Result<(WebSocket, SubscriptionIds), SocketError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn subscribe<'life0, 'async_trait>(
subscriptions: &'life0 [Subscription]
) -> Pin<Box<dyn Future<Output = Result<(WebSocket, SubscriptionIds), SocketError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
WebSocket connection, actions the provided collection of Barter
Subscriptions, and validates that the Subscription were accepted by the exchange.source§fn validate<'life0, 'async_trait>(
ids: SubscriptionIds,
websocket: &'life0 mut WebSocket,
expected_responses: usize
) -> Pin<Box<dyn Future<Output = Result<SubscriptionIds, SocketError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn validate<'life0, 'async_trait>(
ids: SubscriptionIds,
websocket: &'life0 mut WebSocket,
expected_responses: usize
) -> Pin<Box<dyn Future<Output = Result<SubscriptionIds, SocketError>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
WebSocket connection to consume Subscription responses and
validate their outcomes.source§fn subscription_timeout() -> Duration
fn subscription_timeout() -> Duration
Duration in which the exchange will respond to all actioned
WebSocket Subscription requests. Read moresource§impl Transformer<MarketEvent> for Coinbase
impl Transformer<MarketEvent> for Coinbase
type Input = CoinbaseMessage
type OutputIter = Vec<Result<MarketEvent, SocketError>, Global>
fn transform(&mut self, input: Self::Input) -> Self::OutputIter
impl Eq for Coinbase
impl StructuralEq for Coinbase
impl StructuralPartialEq for Coinbase
Auto Trait Implementations§
impl RefUnwindSafe for Coinbase
impl Send for Coinbase
impl Sync for Coinbase
impl Unpin for Coinbase
impl UnwindSafe for Coinbase
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.