Trait crypto_ws_client::WSClient [−][src]
The public interface of every WebSocket client.
Required methods
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
Creates a new client.
Arguments
on_msg
- A callback function to process original JSON messagesurl
- Optional server url, usually you don't need specify it
fn subscribe_trade(&self, pairs: &[String])
[src]
Subscribes to trade channels.
A trade channel sends tick-by-tick trade data, which is the complete copy of a market's trading information.
Each exchange has its own pair formats, for example:
- BitMEX
XBTUSD
,XBTM21
- Binance
btcusdt
,btcusd_perp
- OKEx
BTC-USDT
fn subscribe_bbo(&self, pairs: &[String])
[src]
Subscribes to BBO(best bid & offer) channels.
BBO represents best bid and offer, which is also refered to as level1 data. It is the top 1 bid and ask from the orginal orderbook, so BBO is updated per tick and non-aggregated.
Not all exchanges have the BBO channel, calling this function with these exchanges will panic.
- Binance, BitMEX, Huobi and Kraken have BBO directly.
- Bitfinex uses
book
channel withlen=1
andprec="R0"
to get BBO data.
fn subscribe_orderbook(&self, pairs: &[String])
[src]
Subscribes to incremental level2 orderbook channels.
An incremental level2 orderbook channel sends a snapshot followed by tick-by-tick updates.
Level2 orderbook is the raw orderbook(Level3) aggregated by price level, it is also refered to as "market by price level" data.
This function subscribes to exchange specific channels as the following:
- Binance
depth@100ms
- Bitfinex
book
channel withprec=P0
,frec=F0
andlen=25
- BitMEX
orderBookL2_25
- Bitstamp
diff_order_book
, top 100 - CoinbasePro
level2
- Huobi
depth.size_150.high_freq
withdata_type=incremental
for contracts,mbp.150
for Spot - Kraken
book
withdepth=25
- MXC
depth
for Swap,symbol
for Spot - OKEx
depth_l2_tbt
, top 100
fn subscribe_orderbook_snapshot(&self, pairs: &[String])
[src]
Subscribes to level2 orderbook snapshot channels.
A level2 orderbook snapshot channel sends a complete snapshot every interval.
This function subscribes to exchange specific channels as the following:
- Binance
depth20
, every 1000ms - Bitfinex has no snapshot channel
- BitMEX
orderBook10
, top 10, every tick - Bitstamp
order_book
, top 100, every 100ms - CoinbasePro has no snapshot channel
- Huobi
depth.step0
, top 150, every 1s - Kraken has no snapshot channel
- MXC
depth.full
for Swap, top 20, every 100ms;get.depth
for Spot, full, every 26s - OKEx
depth5
, top 5, every 100ms
fn subscribe_ticker(&self, pairs: &[String])
[src]
Subscribes to ticker channels.
A ticker channel pushes realtime 24hr rolling window ticker messages, which contains OHLCV information.
Not all exchanges have the ticker channel, for example, BitMEX, Bitstamp, MXC Spot, etc.
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
Subscribes to candlestick channels.
The candlestick channel sends OHLCV messages at interval.
interval
specifies the interval of candlesticks in seconds.
Not all exchanges have candlestick channels, for example, Bitstamp and CoinbasePro.
fn subscribe(&self, raw_channels: &[String])
[src]
Subscribes to raw channels, lower level API.
A raw_channel
can be:
- A plain string, supported by Binance, BitMEX, Bitstamp, Huobi, OKEx.
For example, Binance
btcusdt@aggTrade
, BitMEXtrade:XBTUSD,
instrument, Bitstamp
live_trades_btcusd, Huobi
market.btcusdt.trade.detail,
market.overview, OKEx
spot/trade:BTC-USDT`. - channel:pair. For exchanges not supporting plain string channels,
this library will split this kind of
raw_channel
by:
, then compose a JSON string. For example, Bitfinextrades:tBTCUST
, CoinbasePromatches:BTC-USD
, Krakentrade:XBT/USD
- A JSON string, supported by all exchanges. If a
raw_channel
starts with{
, which means it is the final JSON string, thus it will be sent out directly without parsing.
fn unsubscribe(&self, raw_channels: &[String])
[src]
Unsubscribes from raw channels, lower level API.
fn run(&self, duration: Option<u64>)
[src]
Starts the infinite loop until time is up or the server closes the connection.
Arguments
duration
- How many seconds to run, None means infinite.
fn close(&self)
[src]
Breaks the loop and closes the connection.
Implementors
impl<'a> WSClient<'a> for BinanceFutureWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BinanceInverseSwapWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BinanceLinearSwapWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BinanceOptionWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> BinanceOptionWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> BinanceOptionWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BinanceSpotWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BitfinexWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
_url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
_url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, symbols: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BitmexWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> BitmexWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> BitmexWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for BitstampWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> BitstampWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> BitstampWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for CoinbaseProWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> CoinbaseProWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> CoinbaseProWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for DeribitWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> DeribitWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> DeribitWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for HuobiFutureWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for HuobiInverseSwapWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for HuobiLinearSwapWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for HuobiOptionWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for HuobiSpotWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> Self
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for KrakenWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> KrakenWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> KrakenWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for MxcSpotWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> MxcSpotWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> MxcSpotWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for MxcSwapWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> MxcSwapWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> MxcSwapWSClient<'a>
fn subscribe_trade(&self, channels: &[String])
[src]
fn subscribe_orderbook(&self, channels: &[String])
[src]
fn subscribe_orderbook_snapshot(&self, channels: &[String])
[src]
fn subscribe_ticker(&self, channels: &[String])
[src]
fn subscribe_bbo(&self, channels: &[String])
[src]
fn subscribe_candlestick(&self, pairs: &[String], interval: u32)
[src]
fn subscribe(&self, channels: &[String])
[src]
fn unsubscribe(&self, channels: &[String])
[src]
fn run(&self, duration: Option<u64>)
[src]
fn close(&self)
[src]
impl<'a> WSClient<'a> for OkexWSClient<'a>
[src]
fn new(
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> OkexWSClient<'a>
[src]
on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
url: Option<&str>
) -> OkexWSClient<'a>