use crate::Route;
pub struct Derivatives {
endpoint: String,
pub include_tickers: String, }
pub struct Exchanges {
endpoint: String,
pub order: String, pub per_page: i32,
pub page: i32,
}
pub struct Info {
endpoint: String,
pub id: String,
pub include_tickers: String, }
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"), 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("")
}
}