barter_data/exchange/coinbase/
channel.rs

1use super::Coinbase;
2use crate::{
3    Identifier,
4    subscription::{Subscription, trade::PublicTrades},
5};
6use serde::Serialize;
7
8/// Type that defines how to translate a Barter [`Subscription`] into a
9/// [`Coinbase`] channel to be subscribed to.
10///
11/// See docs: <https://docs.cloud.coinbase.com/exchange/docs/websocket-overview#subscribe>
12#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)]
13pub struct CoinbaseChannel(pub &'static str);
14
15impl CoinbaseChannel {
16    /// [`Coinbase`] real-time trades channel.
17    ///
18    /// See docs: <https://docs.cloud.coinbase.com/exchange/docs/websocket-channels#match>
19    pub const TRADES: Self = Self("matches");
20}
21
22impl<Instrument> Identifier<CoinbaseChannel> for Subscription<Coinbase, Instrument, PublicTrades> {
23    fn id(&self) -> CoinbaseChannel {
24        CoinbaseChannel::TRADES
25    }
26}
27
28impl AsRef<str> for CoinbaseChannel {
29    fn as_ref(&self) -> &str {
30        self.0
31    }
32}