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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! # `/derivatives`
//!
//! - [/derivatives](Derivatives)
//! - [/derivatives/exchanges](Exchanges)
//! - [/derivatives/exchanges/{id}](Info)
//! - [/derivatives/exchanges/list](List)
//!
use crate::Route;

pub struct Derivatives {
    endpoint: String,
    pub include_tickers: String, // 'all' or 'expired'
}
pub struct Exchanges {
    endpoint: String,
    pub order: String, // name_asc,name_desc,open_interest_btc_asc,open_interest_btc_desc,trade_volume_24h_btc_asc,trade_volume_24h_btc_desc
    pub per_page: i32,
    pub page: i32,
}
pub struct Info {
    endpoint: String,
    pub id: String,
    pub include_tickers: String, // 'all' or 'expired'
}
pub struct List {
    endpoint: String,
}

impl Derivatives {
    pub fn required() -> Derivatives {
        Derivatives::default()
    }
}
impl Exchanges {
    pub fn required() -> Exchanges {
        Exchanges::default()
    }
}
impl Info {
    pub fn required(id: String) -> Info {
        Info {
            id,
            ..Default::default()
        }
    }
}
impl List {
    pub fn required() -> List {
        List::default()
    }
}

impl Default for Derivatives {
    fn default() -> Derivatives {
        Derivatives {
            endpoint: String::from("/derivatives"),
            include_tickers: String::from("unexpired"),
        }
    }
}
impl Default for Exchanges {
    fn default() -> Exchanges {
        Exchanges {
            endpoint: String::from("/derivatives/exchanges"),
            order: String::from("name_asc"), // guessed
            per_page: 100,
            page: 1,
        }
    }
}
impl Default for Info {
    fn default() -> Info {
        Info {
            endpoint: String::from("/derivatives/exchanges/ID"),
            id: String::from(""),
            include_tickers: String::from("unexpired"),
        }
    }
}
impl Default for List {
    fn default() -> List {
        List {
            endpoint: String::from("/derivatives/exchanges/list"),
        }
    }
}

impl Route for Derivatives {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        let default: Derivatives = Default::default();
        let include_tickers = self.format_query(
            "include_tickers".to_string(),
            &(self.include_tickers),
            &(default.include_tickers),
        );
        let optional = vec![include_tickers];
        self.collect_query_params(optional)
    }
}
impl Route for Exchanges {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        let default: Exchanges = Default::default();
        let per_page = self.format_query("per_page".to_string(), self.per_page, default.per_page);
        let page = self.format_query("page".to_string(), self.page, default.page);
        let order = self.format_query("order".to_string(), &(self.order), &(default.order));
        let optional = vec![per_page, page, order];
        self.collect_query_params(optional)
    }
}
impl Route for Info {
    fn api_endpoint(&self) -> String {
        let endpoint = self.endpoint.replace("ID", &(self.id));
        format!("{}", endpoint)
    }
    fn query_string(&self) -> String {
        let default: Info = Default::default();
        let include_tickers = self.format_query(
            "include_tickers".to_string(),
            &(self.include_tickers),
            &(default.include_tickers),
        );
        let optional = vec![include_tickers];
        self.collect_query_params(optional)
    }
}
impl Route for List {
    fn api_endpoint(&self) -> String {
        format!("{}", self.endpoint)
    }
    fn query_string(&self) -> String {
        String::from("")
    }
}