1#[macro_use]
4extern crate failure;
5#[macro_use]
6extern crate serde_derive;
7extern crate hashbrown;
8extern crate serde;
9
10extern crate cxmr_balances;
11extern crate cxmr_currency;
12#[macro_use]
13extern crate err_convert_macro;
14
15pub mod filters;
16mod info;
17pub mod limits;
18mod markets;
19mod orders;
20mod status;
21mod trade;
22
23pub use self::filters::*;
24pub use self::info::*;
25pub use self::limits::*;
26pub use self::markets::*;
27pub use self::orders::*;
28pub use self::status::*;
29pub use self::trade::*;
30
31use std::str::FromStr;
32use std::string::ToString;
33
34#[derive(Debug, Fail)]
36pub enum Error {
37 #[fail(display = "{} is not a valid exchange.", _0)]
39 InvalidExchange(String),
40 #[fail(display = "{} is not a valid market.", _0)]
42 InvalidMarket(String),
43 #[fail(display = "{} is not a valid order side.", _0)]
45 InvalidOrderSide(String),
46 #[fail(display = "{} is not a valid order side id.", _0)]
48 InvalidOrderSideId(i64),
49 #[fail(display = "option none error: {:?}", _0)]
51 Currency(#[cause] ::cxmr_currency::Error),
52}
53
54err_converter!(Currency, ::cxmr_currency::Error);
55
56#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, PartialOrd, Ord, Copy, Clone, Debug)]
58pub enum Exchange {
59 Unknown = 0,
61 Poloniex = 1,
63 Bitfinex = 2,
65 Bittrex = 3,
67 Binance = 4,
69 Cryptopia = 5,
71 Simulation = 6,
73}
74
75impl Exchange {
76 pub fn short(self: &Exchange) -> &str {
78 match self {
79 Exchange::Unknown => "unk",
80 Exchange::Poloniex => "pnx",
81 Exchange::Bitfinex => "bfx",
82 Exchange::Bittrex => "brx",
83 Exchange::Binance => "bnc",
84 Exchange::Cryptopia => "crt",
85 Exchange::Simulation => "sim",
86 }
87 }
88}
89
90impl ToString for Exchange {
91 fn to_string(&self) -> String {
92 match self {
93 Exchange::Unknown => "Unknown".to_owned(),
94 Exchange::Poloniex => "Poloniex".to_owned(),
95 Exchange::Bitfinex => "Bitfinex".to_owned(),
96 Exchange::Bittrex => "Bittrex".to_owned(),
97 Exchange::Binance => "Binance".to_owned(),
98 Exchange::Cryptopia => "Cryptopia".to_owned(),
99 Exchange::Simulation => "Simulation".to_owned(),
100 }
101 }
102}
103
104impl FromStr for Exchange {
105 type Err = Error;
106
107 fn from_str(s: &str) -> Result<Self, Self::Err> {
108 match s {
109 "Unknown" => Ok(Exchange::Unknown),
110 "Poloniex" => Ok(Exchange::Poloniex),
111 "Bitfinex" => Ok(Exchange::Bitfinex),
112 "Bittrex" => Ok(Exchange::Bittrex),
113 "Binance" => Ok(Exchange::Binance),
114 "Cryptopia" => Ok(Exchange::Cryptopia),
115 "Simulation" => Ok(Exchange::Simulation),
116 "unk" => Ok(Exchange::Unknown),
117 "pnx" => Ok(Exchange::Poloniex),
118 "bfx" => Ok(Exchange::Bitfinex),
119 "brx" => Ok(Exchange::Bittrex),
120 "bnc" => Ok(Exchange::Binance),
121 "crt" => Ok(Exchange::Cryptopia),
122 "sim" => Ok(Exchange::Simulation),
123 _ => Err(Error::InvalidExchange(s.to_owned())),
124 }
125 }
126}
127
128#[cfg(test)]
129mod tests {
130 use super::*;
131
132 #[test]
133 fn exchange_debug() {
134 assert_eq!("pnx", Exchange::Poloniex.short());
135 assert_eq!("Poloniex".to_owned(), format!("{:?}", Exchange::Poloniex));
136 }
137}