1use crate::Route;
9
10pub struct Derivatives {
11 endpoint: String,
12 pub include_tickers: String, }
14pub struct Exchanges {
15 endpoint: String,
16 pub order: String, pub per_page: i32,
18 pub page: i32,
19}
20pub struct Info {
21 endpoint: String,
22 pub id: String,
23 pub include_tickers: String, }
25pub struct List {
26 endpoint: String,
27}
28
29impl Derivatives {
30 pub fn required() -> Derivatives {
31 Derivatives::default()
32 }
33}
34impl Exchanges {
35 pub fn required() -> Exchanges {
36 Exchanges::default()
37 }
38}
39impl Info {
40 pub fn required(id: String) -> Info {
41 Info {
42 id,
43 ..Default::default()
44 }
45 }
46}
47impl List {
48 pub fn required() -> List {
49 List::default()
50 }
51}
52
53impl Default for Derivatives {
54 fn default() -> Derivatives {
55 Derivatives {
56 endpoint: String::from("/derivatives"),
57 include_tickers: String::from("unexpired"),
58 }
59 }
60}
61impl Default for Exchanges {
62 fn default() -> Exchanges {
63 Exchanges {
64 endpoint: String::from("/derivatives/exchanges"),
65 order: String::from("name_asc"), per_page: 100,
67 page: 1,
68 }
69 }
70}
71impl Default for Info {
72 fn default() -> Info {
73 Info {
74 endpoint: String::from("/derivatives/exchanges/ID"),
75 id: String::from(""),
76 include_tickers: String::from("unexpired"),
77 }
78 }
79}
80impl Default for List {
81 fn default() -> List {
82 List {
83 endpoint: String::from("/derivatives/exchanges/list"),
84 }
85 }
86}
87
88impl Route for Derivatives {
89 fn api_endpoint(&self) -> String {
90 format!("{}", self.endpoint)
91 }
92 fn query_string(&self) -> String {
93 let default: Derivatives = Default::default();
94 let include_tickers = self.format_query(
95 "include_tickers".to_string(),
96 &(self.include_tickers),
97 &(default.include_tickers),
98 );
99 let optional = vec![include_tickers];
100 self.collect_query_params(optional)
101 }
102}
103impl Route for Exchanges {
104 fn api_endpoint(&self) -> String {
105 format!("{}", self.endpoint)
106 }
107 fn query_string(&self) -> String {
108 let default: Exchanges = Default::default();
109 let per_page = self.format_query("per_page".to_string(), self.per_page, default.per_page);
110 let page = self.format_query("page".to_string(), self.page, default.page);
111 let order = self.format_query("order".to_string(), &(self.order), &(default.order));
112 let optional = vec![per_page, page, order];
113 self.collect_query_params(optional)
114 }
115}
116impl Route for Info {
117 fn api_endpoint(&self) -> String {
118 let endpoint = self.endpoint.replace("ID", &(self.id));
119 format!("{}", endpoint)
120 }
121 fn query_string(&self) -> String {
122 let default: Info = Default::default();
123 let include_tickers = self.format_query(
124 "include_tickers".to_string(),
125 &(self.include_tickers),
126 &(default.include_tickers),
127 );
128 let optional = vec![include_tickers];
129 self.collect_query_params(optional)
130 }
131}
132impl Route for List {
133 fn api_endpoint(&self) -> String {
134 format!("{}", self.endpoint)
135 }
136 fn query_string(&self) -> String {
137 String::from("")
138 }
139}