tinkoff_api/apis/
portfolio_api.rs1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum PortfolioCurrenciesGetError {
22 Status500(crate::models::Error),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum PortfolioGetError {
30 Status500(crate::models::Error),
31 UnknownValue(serde_json::Value),
32}
33
34
35pub async fn portfolio_currencies_get(configuration: &configuration::Configuration, broker_account_id: Option<&str>) -> Result<crate::models::PortfolioCurrenciesResponse, Error<PortfolioCurrenciesGetError>> {
36
37 let local_var_client = &configuration.client;
38
39 let local_var_uri_str = format!("{}/portfolio/currencies", configuration.base_path);
40 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
41
42 if let Some(ref local_var_str) = broker_account_id {
43 local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
44 }
45 if let Some(ref local_var_user_agent) = configuration.user_agent {
46 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
47 }
48 if let Some(ref local_var_token) = configuration.bearer_access_token {
49 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
50 };
51
52 let local_var_req = local_var_req_builder.build()?;
53 let local_var_resp = local_var_client.execute(local_var_req).await?;
54
55 let local_var_status = local_var_resp.status();
56 let local_var_content = local_var_resp.text().await?;
57
58 if local_var_status.is_success() {
59 serde_json::from_str(&local_var_content).map_err(Error::from)
60 } else {
61 let local_var_entity: Option<PortfolioCurrenciesGetError> = serde_json::from_str(&local_var_content).ok();
62 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
63 Err(Error::ResponseError(local_var_error))
64 }
65}
66
67pub async fn portfolio_get(configuration: &configuration::Configuration, broker_account_id: Option<&str>) -> Result<crate::models::PortfolioResponse, Error<PortfolioGetError>> {
68
69 let local_var_client = &configuration.client;
70
71 let local_var_uri_str = format!("{}/portfolio", configuration.base_path);
72 let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
73
74 if let Some(ref local_var_str) = broker_account_id {
75 local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
76 }
77 if let Some(ref local_var_user_agent) = configuration.user_agent {
78 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79 }
80 if let Some(ref local_var_token) = configuration.bearer_access_token {
81 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82 };
83
84 let local_var_req = local_var_req_builder.build()?;
85 let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87 let local_var_status = local_var_resp.status();
88 let local_var_content = local_var_resp.text().await?;
89
90 if local_var_status.is_success() {
91 serde_json::from_str(&local_var_content).map_err(Error::from)
92 } else {
93 let local_var_entity: Option<PortfolioGetError> = serde_json::from_str(&local_var_content).ok();
94 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
95 Err(Error::ResponseError(local_var_error))
96 }
97}
98