tinkoff_api/apis/
sandbox_api.rs

1/*
2 * OpenAPI
3 *
4 * tinkoff.ru/invest OpenAPI.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: al.a.volkov@tinkoff.ru
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `sandbox_clear_post`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SandboxClearPostError {
22    Status500(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `sandbox_currencies_balance_post`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum SandboxCurrenciesBalancePostError {
30    Status500(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `sandbox_positions_balance_post`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum SandboxPositionsBalancePostError {
38    Status500(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `sandbox_register_post`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum SandboxRegisterPostError {
46    Status500(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method `sandbox_remove_post`
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum SandboxRemovePostError {
54    Status500(crate::models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58
59/// Удаление всех позиций клиента
60pub async fn sandbox_clear_post(configuration: &configuration::Configuration, broker_account_id: Option<&str>) -> Result<crate::models::Empty, Error<SandboxClearPostError>> {
61
62    let local_var_client = &configuration.client;
63
64    let local_var_uri_str = format!("{}/sandbox/clear", configuration.base_path);
65    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
66
67    if let Some(ref local_var_str) = broker_account_id {
68        local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
69    }
70    if let Some(ref local_var_user_agent) = configuration.user_agent {
71        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    if let Some(ref local_var_token) = configuration.bearer_access_token {
74        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
75    };
76
77    let local_var_req = local_var_req_builder.build()?;
78    let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80    let local_var_status = local_var_resp.status();
81    let local_var_content = local_var_resp.text().await?;
82
83    if local_var_status.is_success() {
84        serde_json::from_str(&local_var_content).map_err(Error::from)
85    } else {
86        let local_var_entity: Option<SandboxClearPostError> = serde_json::from_str(&local_var_content).ok();
87        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
88        Err(Error::ResponseError(local_var_error))
89    }
90}
91
92pub async fn sandbox_currencies_balance_post(configuration: &configuration::Configuration, sandbox_set_currency_balance_request: crate::models::SandboxSetCurrencyBalanceRequest, broker_account_id: Option<&str>) -> Result<crate::models::Empty, Error<SandboxCurrenciesBalancePostError>> {
93
94    let local_var_client = &configuration.client;
95
96    let local_var_uri_str = format!("{}/sandbox/currencies/balance", configuration.base_path);
97    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
98
99    if let Some(ref local_var_str) = broker_account_id {
100        local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
101    }
102    if let Some(ref local_var_user_agent) = configuration.user_agent {
103        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104    }
105    if let Some(ref local_var_token) = configuration.bearer_access_token {
106        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
107    };
108    local_var_req_builder = local_var_req_builder.json(&sandbox_set_currency_balance_request);
109
110    let local_var_req = local_var_req_builder.build()?;
111    let local_var_resp = local_var_client.execute(local_var_req).await?;
112
113    let local_var_status = local_var_resp.status();
114    let local_var_content = local_var_resp.text().await?;
115
116    if local_var_status.is_success() {
117        serde_json::from_str(&local_var_content).map_err(Error::from)
118    } else {
119        let local_var_entity: Option<SandboxCurrenciesBalancePostError> = serde_json::from_str(&local_var_content).ok();
120        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
121        Err(Error::ResponseError(local_var_error))
122    }
123}
124
125pub async fn sandbox_positions_balance_post(configuration: &configuration::Configuration, sandbox_set_position_balance_request: crate::models::SandboxSetPositionBalanceRequest, broker_account_id: Option<&str>) -> Result<crate::models::Empty, Error<SandboxPositionsBalancePostError>> {
126
127    let local_var_client = &configuration.client;
128
129    let local_var_uri_str = format!("{}/sandbox/positions/balance", configuration.base_path);
130    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
131
132    if let Some(ref local_var_str) = broker_account_id {
133        local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
134    }
135    if let Some(ref local_var_user_agent) = configuration.user_agent {
136        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_token) = configuration.bearer_access_token {
139        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
140    };
141    local_var_req_builder = local_var_req_builder.json(&sandbox_set_position_balance_request);
142
143    let local_var_req = local_var_req_builder.build()?;
144    let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146    let local_var_status = local_var_resp.status();
147    let local_var_content = local_var_resp.text().await?;
148
149    if local_var_status.is_success() {
150        serde_json::from_str(&local_var_content).map_err(Error::from)
151    } else {
152        let local_var_entity: Option<SandboxPositionsBalancePostError> = serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
154        Err(Error::ResponseError(local_var_error))
155    }
156}
157
158/// Создание счета и валютных позиций для клиента
159pub async fn sandbox_register_post(configuration: &configuration::Configuration, sandbox_register_request: Option<crate::models::SandboxRegisterRequest>) -> Result<crate::models::SandboxRegisterResponse, Error<SandboxRegisterPostError>> {
160
161    let local_var_client = &configuration.client;
162
163    let local_var_uri_str = format!("{}/sandbox/register", configuration.base_path);
164    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
165
166    if let Some(ref local_var_user_agent) = configuration.user_agent {
167        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168    }
169    if let Some(ref local_var_token) = configuration.bearer_access_token {
170        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
171    };
172    local_var_req_builder = local_var_req_builder.json(&sandbox_register_request);
173
174    let local_var_req = local_var_req_builder.build()?;
175    let local_var_resp = local_var_client.execute(local_var_req).await?;
176
177    let local_var_status = local_var_resp.status();
178    let local_var_content = local_var_resp.text().await?;
179
180    if local_var_status.is_success() {
181        serde_json::from_str(&local_var_content).map_err(Error::from)
182    } else {
183        let local_var_entity: Option<SandboxRegisterPostError> = serde_json::from_str(&local_var_content).ok();
184        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
185        Err(Error::ResponseError(local_var_error))
186    }
187}
188
189/// Удаление счета клиента
190pub async fn sandbox_remove_post(configuration: &configuration::Configuration, broker_account_id: Option<&str>) -> Result<crate::models::Empty, Error<SandboxRemovePostError>> {
191
192    let local_var_client = &configuration.client;
193
194    let local_var_uri_str = format!("{}/sandbox/remove", configuration.base_path);
195    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
196
197    if let Some(ref local_var_str) = broker_account_id {
198        local_var_req_builder = local_var_req_builder.query(&[("brokerAccountId", &local_var_str.to_string())]);
199    }
200    if let Some(ref local_var_user_agent) = configuration.user_agent {
201        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
202    }
203    if let Some(ref local_var_token) = configuration.bearer_access_token {
204        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205    };
206
207    let local_var_req = local_var_req_builder.build()?;
208    let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210    let local_var_status = local_var_resp.status();
211    let local_var_content = local_var_resp.text().await?;
212
213    if local_var_status.is_success() {
214        serde_json::from_str(&local_var_content).map_err(Error::from)
215    } else {
216        let local_var_entity: Option<SandboxRemovePostError> = serde_json::from_str(&local_var_content).ok();
217        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
218        Err(Error::ResponseError(local_var_error))
219    }
220}
221