barter_data/exchange/gateio/perpetual/
mod.rs

1use self::trade::GateioFuturesTrades;
2use super::Gateio;
3use crate::{
4    ExchangeWsStream, NoInitialSnapshots,
5    exchange::{ExchangeServer, StreamSelector},
6    instrument::InstrumentData,
7    subscription::trade::PublicTrades,
8    transformer::stateless::StatelessTransformer,
9};
10use barter_instrument::exchange::ExchangeId;
11use std::fmt::Display;
12
13/// Public trades types.
14pub mod trade;
15
16/// [`GateioPerpetualsUsd`] WebSocket server base url.
17///
18/// See docs: <https://www.gate.io/docs/developers/futures/ws/en/>
19pub const WEBSOCKET_BASE_URL_GATEIO_PERPETUALS_USD: &str = "wss://fx-ws.gateio.ws/v4/ws/usdt";
20
21/// [`Gateio`] perpetual usd exchange.
22pub type GateioPerpetualsUsd = Gateio<GateioServerPerpetualsUsd>;
23
24/// [`Gateio`] perpetual usd [`ExchangeServer`].
25#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
26pub struct GateioServerPerpetualsUsd;
27
28impl ExchangeServer for GateioServerPerpetualsUsd {
29    const ID: ExchangeId = ExchangeId::GateioPerpetualsUsd;
30
31    fn websocket_url() -> &'static str {
32        WEBSOCKET_BASE_URL_GATEIO_PERPETUALS_USD
33    }
34}
35
36impl<Instrument> StreamSelector<Instrument, PublicTrades> for GateioPerpetualsUsd
37where
38    Instrument: InstrumentData,
39{
40    type SnapFetcher = NoInitialSnapshots;
41    type Stream = ExchangeWsStream<
42        StatelessTransformer<Self, Instrument::Key, PublicTrades, GateioFuturesTrades>,
43    >;
44}
45
46impl Display for GateioPerpetualsUsd {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        write!(f, "GateioPerpetualsUsd")
49    }
50}
51
52/// [`GateioPerpetualsBtc`] WebSocket server base url.
53///
54/// See docs: <https://www.gate.io/docs/developers/futures/ws/en/>
55pub const WEBSOCKET_BASE_URL_GATEIO_PERPETUALS_BTC: &str = "wss://fx-ws.gateio.ws/v4/ws/btc";
56
57/// [`Gateio`] perpetual btc exchange.
58pub type GateioPerpetualsBtc = Gateio<GateioServerPerpetualsBtc>;
59
60/// [`Gateio`] perpetual btc [`ExchangeServer`].
61#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
62pub struct GateioServerPerpetualsBtc;
63
64impl ExchangeServer for GateioServerPerpetualsBtc {
65    const ID: ExchangeId = ExchangeId::GateioPerpetualsBtc;
66
67    fn websocket_url() -> &'static str {
68        WEBSOCKET_BASE_URL_GATEIO_PERPETUALS_BTC
69    }
70}
71
72impl<Instrument> StreamSelector<Instrument, PublicTrades> for GateioPerpetualsBtc
73where
74    Instrument: InstrumentData,
75{
76    type SnapFetcher = NoInitialSnapshots;
77    type Stream = ExchangeWsStream<
78        StatelessTransformer<Self, Instrument::Key, PublicTrades, GateioFuturesTrades>,
79    >;
80}
81
82impl Display for GateioPerpetualsBtc {
83    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84        write!(f, "GateioPerpetualsBtc")
85    }
86}