#[macro_use]
extern crate failure;
#[macro_use]
extern crate serde_derive;
extern crate hashbrown;
extern crate serde;
extern crate cxmr_balances;
extern crate cxmr_currency;
#[macro_use]
extern crate err_convert_macro;
pub mod filters;
mod info;
pub mod limits;
mod markets;
mod orders;
mod status;
mod trade;
pub use self::filters::*;
pub use self::info::*;
pub use self::limits::*;
pub use self::markets::*;
pub use self::orders::*;
pub use self::status::*;
pub use self::trade::*;
use std::str::FromStr;
use std::string::ToString;
#[derive(Debug, Fail)]
pub enum Error {
#[fail(display = "{} is not a valid exchange.", _0)]
InvalidExchange(String),
#[fail(display = "{} is not a valid market.", _0)]
InvalidMarket(String),
#[fail(display = "{} is not a valid order side.", _0)]
InvalidOrderSide(String),
#[fail(display = "{} is not a valid order side id.", _0)]
InvalidOrderSideId(i64),
#[fail(display = "option none error: {:?}", _0)]
Currency(#[cause] ::cxmr_currency::Error),
}
err_converter!(Currency, ::cxmr_currency::Error);
#[derive(Serialize, Deserialize, Hash, Eq, PartialEq, PartialOrd, Ord, Copy, Clone, Debug)]
pub enum Exchange {
Unknown = 0,
Poloniex = 1,
Bitfinex = 2,
Bittrex = 3,
Binance = 4,
Cryptopia = 5,
Simulation = 6,
}
impl Exchange {
pub fn short(self: &Exchange) -> &str {
match self {
Exchange::Unknown => "unk",
Exchange::Poloniex => "pnx",
Exchange::Bitfinex => "bfx",
Exchange::Bittrex => "brx",
Exchange::Binance => "bnc",
Exchange::Cryptopia => "crt",
Exchange::Simulation => "sim",
}
}
}
impl ToString for Exchange {
fn to_string(&self) -> String {
match self {
Exchange::Unknown => "Unknown".to_owned(),
Exchange::Poloniex => "Poloniex".to_owned(),
Exchange::Bitfinex => "Bitfinex".to_owned(),
Exchange::Bittrex => "Bittrex".to_owned(),
Exchange::Binance => "Binance".to_owned(),
Exchange::Cryptopia => "Cryptopia".to_owned(),
Exchange::Simulation => "Simulation".to_owned(),
}
}
}
impl FromStr for Exchange {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Unknown" => Ok(Exchange::Unknown),
"Poloniex" => Ok(Exchange::Poloniex),
"Bitfinex" => Ok(Exchange::Bitfinex),
"Bittrex" => Ok(Exchange::Bittrex),
"Binance" => Ok(Exchange::Binance),
"Cryptopia" => Ok(Exchange::Cryptopia),
"Simulation" => Ok(Exchange::Simulation),
"unk" => Ok(Exchange::Unknown),
"pnx" => Ok(Exchange::Poloniex),
"bfx" => Ok(Exchange::Bitfinex),
"brx" => Ok(Exchange::Bittrex),
"bnc" => Ok(Exchange::Binance),
"crt" => Ok(Exchange::Cryptopia),
"sim" => Ok(Exchange::Simulation),
_ => Err(Error::InvalidExchange(s.to_owned())),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn exchange_debug() {
assert_eq!("pnx", Exchange::Poloniex.short());
assert_eq!("Poloniex".to_owned(), format!("{:?}", Exchange::Poloniex));
}
}