Struct barter_data::exchange::ftx::Ftx
source · pub struct Ftx {
pub ids: SubscriptionIds,
}Expand description
Ftx Subscriber & ExchangeTransformer implementor for the collection
of Spot & Futures data.
Fields§
§ids: SubscriptionIdsImplementations§
source§impl Ftx
impl Ftx
sourcepub const CHANNEL_TRADES: &'static str = "trades"
pub const CHANNEL_TRADES: &'static str = "trades"
Ftx trades channel name.
See docs: https://docs.ftx.com/#trades
sourcepub fn build_channel_meta(
sub: &Subscription
) -> Result<(&str, String), SocketError>
pub fn build_channel_meta(
sub: &Subscription
) -> Result<(&str, String), SocketError>
Determine the Ftx channel metadata associated with an input Barter Subscription.
This includes the Ftx &str channel identifier, and a String market identifier. Both
are used to build an Ftx subscription payload.
Example Ok Return: Ok(“trades”, “BTC/USDT”) where channel == “trades” & market == “BTC/USDT”
Examples found in repository?
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 62 63 64
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 Ftx subscriptions
let subscriptions = subscriptions
.iter()
.map(|subscription| {
// Determine the Ftx 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
// eg/ SubscriptionId("trades|BTC/USDT")
ids.insert(Ftx::subscription_id(channel, &market), subscription.clone());
// Construct Ftx 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 Ftx compatible subscription message using the channel & market provided.
Examples found in repository?
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 62 63 64
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 Ftx subscriptions
let subscriptions = subscriptions
.iter()
.map(|subscription| {
// Determine the Ftx 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
// eg/ SubscriptionId("trades|BTC/USDT")
ids.insert(Ftx::subscription_id(channel, &market), subscription.clone());
// Construct Ftx 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 Ftx compatible SubscriptionId using the channel & market provided.
This is used to associate Ftx data structures received over the WebSocket with it’s
original Barter Subscription.
eg/ SubscriptionId(“trades|BTC/USDT”)
Examples found in repository?
More examples
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 62 63 64
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 Ftx subscriptions
let subscriptions = subscriptions
.iter()
.map(|subscription| {
// Determine the Ftx 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
// eg/ SubscriptionId("trades|BTC/USDT")
ids.insert(Ftx::subscription_id(channel, &market), subscription.clone());
// Construct Ftx 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 Ftx
impl<'de> Deserialize<'de> for Ftx
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 Ftx
impl ExchangeTransformer for Ftx
source§const EXCHANGE: ExchangeId = ExchangeId::Ftx
const EXCHANGE: ExchangeId = ExchangeId::Ftx
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 Subscriber for Ftx
impl Subscriber for Ftx
§type SubResponse = FtxSubResponse
type SubResponse = FtxSubResponse
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 Ftx
impl Transformer<MarketEvent> for Ftx
type Input = FtxMessage
type OutputIter = Vec<Result<MarketEvent, SocketError>, Global>
fn transform(&mut self, input: Self::Input) -> Self::OutputIter
impl Eq for Ftx
impl StructuralEq for Ftx
impl StructuralPartialEq for Ftx
Auto Trait Implementations§
impl RefUnwindSafe for Ftx
impl Send for Ftx
impl Sync for Ftx
impl Unpin for Ftx
impl UnwindSafe for Ftx
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.