use std::rc::Rc;
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::HashMap;
use hyper;
use serde_json::{self, Value};
use futures;
use futures::{Future, Stream};
use hyper::header::UserAgent;
use super::{Error, configuration};
pub struct CCPBetaApiClient<C: hyper::client::Connect> {
configuration: Rc<configuration::Configuration<C>>,
}
impl<C: hyper::client::Connect> CCPBetaApiClient<C> {
pub fn new(configuration: Rc<configuration::Configuration<C>>) -> CCPBetaApiClient<C> {
CCPBetaApiClient {
configuration: configuration,
}
}
}
pub trait CCPBetaApi {
fn ccp_account_get(&self, ) -> Box<Future<Item = ::models::InlineResponse200, Error = Error<serde_json::Value>>>;
fn ccp_auth_init_post(&self, compete: bool, locale: &str, mac: &str, machine_id: &str, username: &str) -> Box<Future<Item = ::models::InlineResponse2001, Error = Error<serde_json::Value>>>;
fn ccp_auth_response_post(&self, auth: ::models::Auth) -> Box<Future<Item = ::models::InlineResponse2002, Error = Error<serde_json::Value>>>;
fn ccp_order_delete(&self, acct: &str, id: f32) -> Box<Future<Item = ::models::OrderData, Error = Error<serde_json::Value>>>;
fn ccp_order_post(&self, acct: &str, conid: f32, ccy: &str, exchange: &str, qty: f32, _type: &str, side: &str, price: f32, tif: &str) -> Box<Future<Item = ::models::OrderData, Error = Error<serde_json::Value>>>;
fn ccp_order_put(&self, acct: &str, id: f32) -> Box<Future<Item = ::models::OrderData, Error = Error<serde_json::Value>>>;
fn ccp_orders_get(&self, acct: &str, cancelled: bool) -> Box<Future<Item = ::models::InlineResponse2003, Error = Error<serde_json::Value>>>;
fn ccp_positions_get(&self, ) -> Box<Future<Item = ::models::PositionData, Error = Error<serde_json::Value>>>;
fn ccp_status_get(&self, ) -> Box<Future<Item = ::models::InlineResponse2004, Error = Error<serde_json::Value>>>;
fn ccp_trades_get(&self, from: &str, to: &str) -> Box<Future<Item = ::models::InlineResponse2003, Error = Error<serde_json::Value>>>;
}
impl<C: hyper::client::Connect>CCPBetaApi for CCPBetaApiClient<C> {
fn ccp_account_get(&self, ) -> Box<Future<Item = ::models::InlineResponse200, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Get;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/ccp/account?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::InlineResponse200, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_auth_init_post(&self, compete: bool, locale: &str, mac: &str, machine_id: &str, username: &str) -> Box<Future<Item = ::models::InlineResponse2001, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Post;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/ccp/auth/init?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::InlineResponse2001, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_auth_response_post(&self, auth: ::models::Auth) -> Box<Future<Item = ::models::InlineResponse2002, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Post;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/ccp/auth/response?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
let serialized = serde_json::to_string(&auth).unwrap();
req.headers_mut().set(hyper::header::ContentType::json());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
req.set_body(serialized);
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::InlineResponse2002, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_order_delete(&self, acct: &str, id: f32) -> Box<Future<Item = ::models::OrderData, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Delete;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("acct", &acct.to_string());
query.append_pair("id", &id.to_string());
query.finish()
};
let uri_str = format!("{}/ccp/order?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::OrderData, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_order_post(&self, acct: &str, conid: f32, ccy: &str, exchange: &str, qty: f32, _type: &str, side: &str, price: f32, tif: &str) -> Box<Future<Item = ::models::OrderData, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Post;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("acct", &acct.to_string());
query.append_pair("conid", &conid.to_string());
query.append_pair("ccy", &ccy.to_string());
query.append_pair("exchange", &exchange.to_string());
query.append_pair("qty", &qty.to_string());
query.append_pair("type", &_type.to_string());
query.append_pair("side", &side.to_string());
query.append_pair("price", &price.to_string());
query.append_pair("tif", &tif.to_string());
query.finish()
};
let uri_str = format!("{}/ccp/order?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::OrderData, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_order_put(&self, acct: &str, id: f32) -> Box<Future<Item = ::models::OrderData, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Put;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("acct", &acct.to_string());
query.append_pair("id", &id.to_string());
query.finish()
};
let uri_str = format!("{}/ccp/order?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::OrderData, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_orders_get(&self, acct: &str, cancelled: bool) -> Box<Future<Item = ::models::InlineResponse2003, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Get;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("acct", &acct.to_string());
query.append_pair("cancelled", &cancelled.to_string());
query.finish()
};
let uri_str = format!("{}/ccp/orders?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::InlineResponse2003, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_positions_get(&self, ) -> Box<Future<Item = ::models::PositionData, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Get;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/ccp/positions?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::PositionData, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_status_get(&self, ) -> Box<Future<Item = ::models::InlineResponse2004, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Get;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/ccp/status?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::InlineResponse2004, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
fn ccp_trades_get(&self, from: &str, to: &str) -> Box<Future<Item = ::models::InlineResponse2003, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let method = hyper::Method::Get;
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("from", &from.to_string());
query.append_pair("to", &to.to_string());
query.finish()
};
let uri_str = format!("{}/ccp/trades?{}", configuration.base_path, query_string);
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
Box::new(
configuration.client.request(req)
.map_err(|e| Error::from(e))
.and_then(|resp| {
let status = resp.status();
resp.body().concat2()
.and_then(move |body| Ok((status, body)))
.map_err(|e| Error::from(e))
})
.and_then(|(status, body)| {
if status.is_success() {
Ok(body)
} else {
Err(Error::from((status, &*body)))
}
})
.and_then(|body| {
let parsed: Result<::models::InlineResponse2003, _> = serde_json::from_slice(&body);
parsed.map_err(|e| Error::from(e))
})
)
}
}