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
#![allow(new_ret_no_self)]
use std::path::PathBuf;
use exchange::{Exchange, ExchangeApi};
use bitstamp::{BitstampApi, BitstampCreds};
use kraken::{KrakenApi, KrakenCreds};
use poloniex::{PoloniexApi, PoloniexCreds};
use bittrex::{BittrexApi, BittrexCreds};
use gdax::{GdaxApi, GdaxCreds};
use error::*;
pub trait Credentials {
fn get(&self, cred: &str) -> Option<String>;
fn exchange(&self) -> Exchange;
fn name(&self) -> String;
}
#[derive(Debug)]
pub struct Coinnect;
impl Coinnect {
pub fn new<C: Credentials>(exchange: Exchange, creds: C) -> Result<Box<ExchangeApi>> {
match exchange {
Exchange::Bitstamp => Ok(Box::new(BitstampApi::new(creds)?)),
Exchange::Kraken => Ok(Box::new(KrakenApi::new(creds)?)),
Exchange::Poloniex => Ok(Box::new(PoloniexApi::new(creds)?)),
Exchange::Bittrex => Ok(Box::new(BittrexApi::new(creds)?)),
Exchange::Gdax => Ok(Box::new(GdaxApi::new(creds)?)),
}
}
pub fn new_from_file(exchange: Exchange,
name: &str,
path: PathBuf)
-> Result<Box<ExchangeApi>> {
match exchange {
Exchange::Bitstamp => {
Ok(Box::new(BitstampApi::new(BitstampCreds::new_from_file(name, path)?)?))
}
Exchange::Kraken => {
Ok(Box::new(KrakenApi::new(KrakenCreds::new_from_file(name, path)?)?))
}
Exchange::Poloniex => {
Ok(Box::new(PoloniexApi::new(PoloniexCreds::new_from_file(name, path)?)?))
}
Exchange::Bittrex => {
Ok(Box::new(BittrexApi::new(BittrexCreds::new_from_file(name, path)?)?))
}
Exchange::Gdax => {
Ok(Box::new(GdaxApi::new(GdaxCreds::new_from_file(name, path)?)?))
}
}
}
}