tinkoff_api/apis/
market_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 `market_bonds_get`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum MarketBondsGetError {
22    Status500(crate::models::Error),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method `market_candles_get`
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum MarketCandlesGetError {
30    Status500(crate::models::Error),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method `market_currencies_get`
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum MarketCurrenciesGetError {
38    Status500(crate::models::Error),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method `market_etfs_get`
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum MarketEtfsGetError {
46    Status500(crate::models::Error),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method `market_orderbook_get`
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum MarketOrderbookGetError {
54    Status500(crate::models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method `market_search_by_figi_get`
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum MarketSearchByFigiGetError {
62    Status500(crate::models::Error),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method `market_search_by_ticker_get`
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum MarketSearchByTickerGetError {
70    Status500(crate::models::Error),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method `market_stocks_get`
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum MarketStocksGetError {
78    Status500(crate::models::Error),
79    UnknownValue(serde_json::Value),
80}
81
82
83pub async fn market_bonds_get(configuration: &configuration::Configuration, ) -> Result<crate::models::MarketInstrumentListResponse, Error<MarketBondsGetError>> {
84
85    let local_var_client = &configuration.client;
86
87    let local_var_uri_str = format!("{}/market/bonds", configuration.base_path);
88    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
89
90    if let Some(ref local_var_user_agent) = configuration.user_agent {
91        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
92    }
93    if let Some(ref local_var_token) = configuration.bearer_access_token {
94        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
95    };
96
97    let local_var_req = local_var_req_builder.build()?;
98    let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100    let local_var_status = local_var_resp.status();
101    let local_var_content = local_var_resp.text().await?;
102
103    if local_var_status.is_success() {
104        serde_json::from_str(&local_var_content).map_err(Error::from)
105    } else {
106        let local_var_entity: Option<MarketBondsGetError> = serde_json::from_str(&local_var_content).ok();
107        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
108        Err(Error::ResponseError(local_var_error))
109    }
110}
111
112pub async fn market_candles_get(configuration: &configuration::Configuration, figi: &str, from: String, to: String, interval: crate::models::CandleResolution) -> Result<crate::models::CandlesResponse, Error<MarketCandlesGetError>> {
113
114    let local_var_client = &configuration.client;
115
116    let local_var_uri_str = format!("{}/market/candles", configuration.base_path);
117    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
118
119    local_var_req_builder = local_var_req_builder.query(&[("figi", &figi.to_string())]);
120    local_var_req_builder = local_var_req_builder.query(&[("from", &from.to_string())]);
121    local_var_req_builder = local_var_req_builder.query(&[("to", &to.to_string())]);
122    local_var_req_builder = local_var_req_builder.query(&[("interval", &interval.to_string())]);
123    if let Some(ref local_var_user_agent) = configuration.user_agent {
124        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
125    }
126    if let Some(ref local_var_token) = configuration.bearer_access_token {
127        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
128    };
129
130    let local_var_req = local_var_req_builder.build()?;
131    let local_var_resp = local_var_client.execute(local_var_req).await?;
132
133    let local_var_status = local_var_resp.status();
134    let local_var_content = local_var_resp.text().await?;
135
136    if local_var_status.is_success() {
137        serde_json::from_str(&local_var_content).map_err(Error::from)
138    } else {
139        let local_var_entity: Option<MarketCandlesGetError> = serde_json::from_str(&local_var_content).ok();
140        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141        Err(Error::ResponseError(local_var_error))
142    }
143}
144
145pub async fn market_currencies_get(configuration: &configuration::Configuration, ) -> Result<crate::models::MarketInstrumentListResponse, Error<MarketCurrenciesGetError>> {
146
147    let local_var_client = &configuration.client;
148
149    let local_var_uri_str = format!("{}/market/currencies", configuration.base_path);
150    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
151
152    if let Some(ref local_var_user_agent) = configuration.user_agent {
153        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154    }
155    if let Some(ref local_var_token) = configuration.bearer_access_token {
156        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157    };
158
159    let local_var_req = local_var_req_builder.build()?;
160    let local_var_resp = local_var_client.execute(local_var_req).await?;
161
162    let local_var_status = local_var_resp.status();
163    let local_var_content = local_var_resp.text().await?;
164
165    if local_var_status.is_success() {
166        serde_json::from_str(&local_var_content).map_err(Error::from)
167    } else {
168        let local_var_entity: Option<MarketCurrenciesGetError> = serde_json::from_str(&local_var_content).ok();
169        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
170        Err(Error::ResponseError(local_var_error))
171    }
172}
173
174pub async fn market_etfs_get(configuration: &configuration::Configuration, ) -> Result<crate::models::MarketInstrumentListResponse, Error<MarketEtfsGetError>> {
175
176    let local_var_client = &configuration.client;
177
178    let local_var_uri_str = format!("{}/market/etfs", configuration.base_path);
179    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
180
181    if let Some(ref local_var_user_agent) = configuration.user_agent {
182        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
183    }
184    if let Some(ref local_var_token) = configuration.bearer_access_token {
185        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
186    };
187
188    let local_var_req = local_var_req_builder.build()?;
189    let local_var_resp = local_var_client.execute(local_var_req).await?;
190
191    let local_var_status = local_var_resp.status();
192    let local_var_content = local_var_resp.text().await?;
193
194    if local_var_status.is_success() {
195        serde_json::from_str(&local_var_content).map_err(Error::from)
196    } else {
197        let local_var_entity: Option<MarketEtfsGetError> = serde_json::from_str(&local_var_content).ok();
198        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
199        Err(Error::ResponseError(local_var_error))
200    }
201}
202
203pub async fn market_orderbook_get(configuration: &configuration::Configuration, figi: &str, depth: i32) -> Result<crate::models::OrderbookResponse, Error<MarketOrderbookGetError>> {
204
205    let local_var_client = &configuration.client;
206
207    let local_var_uri_str = format!("{}/market/orderbook", configuration.base_path);
208    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
209
210    local_var_req_builder = local_var_req_builder.query(&[("figi", &figi.to_string())]);
211    local_var_req_builder = local_var_req_builder.query(&[("depth", &depth.to_string())]);
212    if let Some(ref local_var_user_agent) = configuration.user_agent {
213        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
214    }
215    if let Some(ref local_var_token) = configuration.bearer_access_token {
216        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
217    };
218
219    let local_var_req = local_var_req_builder.build()?;
220    let local_var_resp = local_var_client.execute(local_var_req).await?;
221
222    let local_var_status = local_var_resp.status();
223    let local_var_content = local_var_resp.text().await?;
224
225    if local_var_status.is_success() {
226        serde_json::from_str(&local_var_content).map_err(Error::from)
227    } else {
228        let local_var_entity: Option<MarketOrderbookGetError> = serde_json::from_str(&local_var_content).ok();
229        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
230        Err(Error::ResponseError(local_var_error))
231    }
232}
233
234pub async fn market_search_by_figi_get(configuration: &configuration::Configuration, figi: &str) -> Result<crate::models::SearchMarketInstrumentResponse, Error<MarketSearchByFigiGetError>> {
235
236    let local_var_client = &configuration.client;
237
238    let local_var_uri_str = format!("{}/market/search/by-figi", configuration.base_path);
239    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
240
241    local_var_req_builder = local_var_req_builder.query(&[("figi", &figi.to_string())]);
242    if let Some(ref local_var_user_agent) = configuration.user_agent {
243        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244    }
245    if let Some(ref local_var_token) = configuration.bearer_access_token {
246        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
247    };
248
249    let local_var_req = local_var_req_builder.build()?;
250    let local_var_resp = local_var_client.execute(local_var_req).await?;
251
252    let local_var_status = local_var_resp.status();
253    let local_var_content = local_var_resp.text().await?;
254
255    if local_var_status.is_success() {
256        serde_json::from_str(&local_var_content).map_err(Error::from)
257    } else {
258        let local_var_entity: Option<MarketSearchByFigiGetError> = serde_json::from_str(&local_var_content).ok();
259        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
260        Err(Error::ResponseError(local_var_error))
261    }
262}
263
264pub async fn market_search_by_ticker_get(configuration: &configuration::Configuration, ticker: &str) -> Result<crate::models::MarketInstrumentListResponse, Error<MarketSearchByTickerGetError>> {
265
266    let local_var_client = &configuration.client;
267
268    let local_var_uri_str = format!("{}/market/search/by-ticker", configuration.base_path);
269    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
270
271    local_var_req_builder = local_var_req_builder.query(&[("ticker", &ticker.to_string())]);
272    if let Some(ref local_var_user_agent) = configuration.user_agent {
273        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274    }
275    if let Some(ref local_var_token) = configuration.bearer_access_token {
276        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
277    };
278
279    let local_var_req = local_var_req_builder.build()?;
280    let local_var_resp = local_var_client.execute(local_var_req).await?;
281
282    let local_var_status = local_var_resp.status();
283    let local_var_content = local_var_resp.text().await?;
284
285    if local_var_status.is_success() {
286        serde_json::from_str(&local_var_content).map_err(Error::from)
287    } else {
288        let local_var_entity: Option<MarketSearchByTickerGetError> = serde_json::from_str(&local_var_content).ok();
289        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
290        Err(Error::ResponseError(local_var_error))
291    }
292}
293
294pub async fn market_stocks_get(configuration: &configuration::Configuration, ) -> Result<crate::models::MarketInstrumentListResponse, Error<MarketStocksGetError>> {
295
296    let local_var_client = &configuration.client;
297
298    let local_var_uri_str = format!("{}/market/stocks", configuration.base_path);
299    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
300
301    if let Some(ref local_var_user_agent) = configuration.user_agent {
302        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
303    }
304    if let Some(ref local_var_token) = configuration.bearer_access_token {
305        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
306    };
307
308    let local_var_req = local_var_req_builder.build()?;
309    let local_var_resp = local_var_client.execute(local_var_req).await?;
310
311    let local_var_status = local_var_resp.status();
312    let local_var_content = local_var_resp.text().await?;
313
314    if local_var_status.is_success() {
315        serde_json::from_str(&local_var_content).map_err(Error::from)
316    } else {
317        let local_var_entity: Option<MarketStocksGetError> = serde_json::from_str(&local_var_content).ok();
318        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
319        Err(Error::ResponseError(local_var_error))
320    }
321}
322