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§

§

BinanceFuturesUsd

§

Binance

§

Coinbase

§

Ftx

§

Kraken

Implementations§

Return the exchange name associated with this ExchangeId.

eg/ ExchangeId::BinanceFuturesUsd => “binance”

Return the &str representation this ExchangeId is associated with.

Examples found in repository?
src/lib.rs (line 223)
222
223
224
225
226
227
228
229
230
    fn from(exchange_id: ExchangeId) -> Self {
        Exchange::from(exchange_id.as_str())
    }
}

impl Display for ExchangeId {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
More examples
Hide additional examples
src/exchange/ftx/model.rs (line 83)
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,
            }),
        }
    }
src/exchange/kraken/model.rs (line 122)
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(),
            }),
        }
    }
src/exchange/coinbase/mod.rs (line 112)
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))
    }
src/exchange/binance/futures.rs (line 150)
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))
    }
src/exchange/ftx/mod.rs (line 125)
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()))
    }

Determines whether this ExchangeId supports the ingestion of InstrumentKind::Spot market data.

Examples found in repository?
src/model/subscription.rs (line 33)
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)
    }

Determines whether this ExchangeId supports the collection of InstrumentKind::Future** market data.

Examples found in repository?
src/model/subscription.rs (line 34)
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)
    }

Determines whether this ExchangeId supports the collection of PublicTrade market data.

Examples found in repository?
src/model/subscription.rs (line 45)
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)
    }

Determines whether this ExchangeId supports the collection of Candle market data.

Examples found in repository?
src/model/subscription.rs (line 46)
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)
    }

Determines whether this ExchangeId supports the collection of OrderBook snapshot market data.

Examples found in repository?
src/model/subscription.rs (line 47)
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)
    }

Determines whether this ExchangeId supports the collection of L2 OrderBook delta market data.

Determines whether this ExchangeId supports the collection of L3 OrderBook delta market data.

Determines whether this ExchangeId supports the collection of liquidation orders market data.

Examples found in repository?
src/model/subscription.rs (line 48)
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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more