use reqwest;
use crate::apis::ResponseContent;
use super::{Error, configuration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrdersCancelPostError {
Status500(crate::models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrdersGetError {
Status500(crate::models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrdersLimitOrderPostError {
Status500(crate::models::Error),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OrdersMarketOrderPostError {
Status500(crate::models::Error),
UnknownValue(serde_json::Value),
}
pub async fn orders_cancel_post(configuration: &configuration::Configuration, order_id: &str, broker_account_id: Option<&str>) -> Result<crate::models::Empty, Error<OrdersCancelPostError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/orders/cancel", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("orderId", &order_id.to_string())]);
if let Some(ref local_var_str) = broker_account_id {
local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<OrdersCancelPostError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn orders_get(configuration: &configuration::Configuration, broker_account_id: Option<&str>) -> Result<crate::models::OrdersResponse, Error<OrdersGetError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/orders", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = broker_account_id {
local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<OrdersGetError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn orders_limit_order_post(configuration: &configuration::Configuration, figi: &str, limit_order_request: crate::models::LimitOrderRequest, broker_account_id: Option<&str>) -> Result<crate::models::LimitOrderResponse, Error<OrdersLimitOrderPostError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/orders/limit-order", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("figi", &figi.to_string())]);
if let Some(ref local_var_str) = broker_account_id {
local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&limit_order_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<OrdersLimitOrderPostError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
pub async fn orders_market_order_post(configuration: &configuration::Configuration, figi: &str, market_order_request: crate::models::MarketOrderRequest, broker_account_id: Option<&str>) -> Result<crate::models::MarketOrderResponse, Error<OrdersMarketOrderPostError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/orders/market-order", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("figi", &figi.to_string())]);
if let Some(ref local_var_str) = broker_account_id {
local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.json(&market_order_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if local_var_status.is_success() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<OrdersMarketOrderPostError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}