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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use std::fmt::Debug;
use std::convert::Into;
use std::str::FromStr;
use error::*;
use types::*;
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Exchange {
Bitstamp,
Kraken,
Poloniex,
Bittrex,
Gdax,
}
impl Into<String> for Exchange {
fn into(self) -> String {
match self {
Exchange::Bitstamp => "Bitstamp".to_string(),
Exchange::Kraken => "Kraken".to_string(),
Exchange::Poloniex => "Poloniex".to_string(),
Exchange::Bittrex => "Bittrex".to_string(),
Exchange::Gdax => "Gdax".to_string(),
}
}
}
impl FromStr for Exchange {
type Err = Error;
fn from_str(input: &str) -> ::std::result::Result<Self, Self::Err> {
match input.to_lowercase().as_str() {
"bitstamp" => Ok(Exchange::Bitstamp),
"kraken" => Ok(Exchange::Kraken),
"poloniex" => Ok(Exchange::Poloniex),
"bittrex" => Ok(Exchange::Bittrex),
"gdax" => Ok(Exchange::Gdax),
_ => Err(ErrorKind::InvalidExchange(input.to_string()).into()),
}
}
}
pub trait ExchangeApi: Debug {
fn ticker(&mut self, pair: Pair) -> Result<Ticker>;
fn orderbook(&mut self, pair: Pair) -> Result<Orderbook>;
fn add_order(&mut self,
order_type: OrderType,
pair: Pair,
quantity: Volume,
price: Option<Price>)
-> Result<OrderInfo>;
fn balances(&mut self) -> Result<Balances>;
}