[−][src]Trait crypto_ws_client::WSClient
The public interface of every WebSocket client.
Required methods
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
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
pub fn subscribe_trade(&mut 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
pub fn subscribe_bbo(&mut 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.
pub fn subscribe_orderbook(&mut 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_20.high_freq
for contracts,mbp.20
for Spot - Kraken
book
withdepth=25
- MXC
depth
for Swap,symbol
for Spot - OKEx
depth_l2_tbt
, top 100
pub fn subscribe_orderbook_snapshot(&mut 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
depth10
, top 10, every 100ms - 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.step7
for contracts,depth.step1
for Spot, both are top 20, 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
pub fn subscribe_ticker(&mut 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.
pub fn subscribe_candlestick(&mut 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.
pub fn subscribe(&mut 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.
pub fn unsubscribe(&mut self, raw_channels: &[String])
[src]
Unsubscribes from raw channels, lower level API.
pub fn run(&mut 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.
Implementors
impl<'a> WSClient<'a> for BinanceFutureWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for BinanceInverseSwapWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for BinanceLinearSwapWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for BinanceSpotWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for BitMEXWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> BitMEXWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> BitMEXWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for BitfinexWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> BitfinexWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> BitfinexWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for BitstampWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> BitstampWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> BitstampWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for CoinbaseProWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> CoinbaseProWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> CoinbaseProWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for HuobiFutureWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for HuobiInverseSwapWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for HuobiLinearSwapWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for HuobiOptionWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for HuobiSpotWSClient<'a>
[src]
pub fn new(on_msg: Box<dyn FnMut(String) + 'a>, url: Option<&str>) -> Self
[src]
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for KrakenWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> KrakenWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> KrakenWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for MXCSpotWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> MXCSpotWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> MXCSpotWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for MXCSwapWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> MXCSwapWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> MXCSwapWSClient<'a>
pub fn subscribe_trade(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook(&mut self, channels: &[String])
[src]
pub fn subscribe_orderbook_snapshot(&mut self, channels: &[String])
[src]
pub fn subscribe_ticker(&mut self, channels: &[String])
[src]
pub fn subscribe_bbo(&mut self, channels: &[String])
[src]
pub fn subscribe_candlestick(&mut self, pairs: &[String], interval: u32)
[src]
pub fn subscribe(&mut self, channels: &[String])
[src]
pub fn unsubscribe(&mut self, channels: &[String])
[src]
pub fn run(&mut self, duration: Option<u64>)
[src]
impl<'a> WSClient<'a> for OKExWSClient<'a>
[src]
pub fn new(
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> OKExWSClient<'a>
[src]
on_msg: Box<dyn FnMut(String) + 'a>,
url: Option<&str>
) -> OKExWSClient<'a>