1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Crypto-bank WebSocket market stream.

extern crate chrono;
extern crate crypto_currency as currency;
extern crate crypto_market as market;
extern crate crypto_market_event as event;
extern crate crypto_market_stream as stream;
extern crate crypto_util as util;
extern crate futures;
#[macro_use]
extern crate log;
extern crate serde_json;
extern crate tokio_core;
extern crate websocket;

mod connect;
pub mod errors;
mod handle;
mod msg;

// TODO: do not expose handle, create a "builder"
pub use self::connect::connect;
pub use self::handle::Handle;
pub use self::msg::Message;

use market::Market;
use stream::Command;

/// WebSocket Stream protocol trait.
pub trait Protocol {
    /// Protocol error.
    type Error: ::std::error::Error;

    /// Returns WebSocket stream addrss.
    fn address() -> &'static str;

    /// Returns protocol market identifier.
    fn market() -> Market;

    /// Parses received WebSocket message.
    fn parse(msg: &str) -> Result<Option<Message>, Self::Error>;

    /// Serializes WebSocket command.
    fn serialize(cmd: Command) -> String;
}