Skip to main content

crypto_ws_client/clients/gate/
gate_future.rs

1use async_trait::async_trait;
2
3use super::utils::{GateCommandTranslator, GateMessageHandler, EXCHANGE_NAME};
4use crate::{
5    clients::common_traits::{
6        Candlestick, Level3OrderBook, OrderBook, OrderBookTopK, Ticker, Trade, BBO,
7    },
8    common::{command_translator::CommandTranslator, ws_client_internal::WSClientInternal},
9    WSClient,
10};
11
12const INVERSE_FUTURE_WEBSOCKET_URL: &str = "wss://fx-ws.gateio.ws/v4/ws/delivery/btc";
13const LINEAR_FUTURE_WEBSOCKET_URL: &str = "wss://fx-ws.gateio.ws/v4/ws/delivery/usdt";
14
15/// The WebSocket client for Gate InverseFuture market.
16///
17/// * WebSocket API doc: <https://www.gate.io/docs/developers/delivery/ws/en/>
18/// * Trading at <https://www.gate.io/futures-delivery/btc>
19pub struct GateInverseFutureWSClient {
20    client: WSClientInternal<GateMessageHandler<'F'>>,
21    translator: GateCommandTranslator<'F'>,
22}
23
24/// The WebSocket client for Gate LinearFuture market.
25///
26/// * WebSocket API doc: <https://www.gate.io/docs/developers/delivery/ws/en/>
27/// * Trading at <https://www.gate.io/futures-delivery/usdt>
28pub struct GateLinearFutureWSClient {
29    client: WSClientInternal<GateMessageHandler<'F'>>,
30    translator: GateCommandTranslator<'F'>,
31}
32
33impl_new_constructor!(
34    GateInverseFutureWSClient,
35    EXCHANGE_NAME,
36    INVERSE_FUTURE_WEBSOCKET_URL,
37    GateMessageHandler::<'F'> {},
38    GateCommandTranslator::<'F'> {}
39);
40
41impl_new_constructor!(
42    GateLinearFutureWSClient,
43    EXCHANGE_NAME,
44    LINEAR_FUTURE_WEBSOCKET_URL,
45    GateMessageHandler::<'F'> {},
46    GateCommandTranslator::<'F'> {}
47);
48
49impl_trait!(Trade, GateInverseFutureWSClient, subscribe_trade, "trades");
50#[rustfmt::skip]
51impl_trait!(OrderBook, GateInverseFutureWSClient, subscribe_orderbook, "order_book");
52#[rustfmt::skip]
53impl_trait!(Ticker, GateInverseFutureWSClient, subscribe_ticker, "tickers");
54
55#[rustfmt::skip]
56impl_trait!(Trade, GateLinearFutureWSClient, subscribe_trade, "trades");
57#[rustfmt::skip]
58impl_trait!(OrderBook, GateLinearFutureWSClient, subscribe_orderbook, "order_book");
59#[rustfmt::skip]
60impl_trait!(Ticker, GateLinearFutureWSClient, subscribe_ticker, "tickers");
61
62impl_candlestick!(GateInverseFutureWSClient);
63impl_candlestick!(GateLinearFutureWSClient);
64
65panic_bbo!(GateInverseFutureWSClient);
66panic_bbo!(GateLinearFutureWSClient);
67panic_l2_topk!(GateInverseFutureWSClient);
68panic_l2_topk!(GateLinearFutureWSClient);
69panic_l3_orderbook!(GateInverseFutureWSClient);
70panic_l3_orderbook!(GateLinearFutureWSClient);
71
72impl_ws_client_trait!(GateInverseFutureWSClient);
73impl_ws_client_trait!(GateLinearFutureWSClient);