twelve_data_client/apis/
etfs_api.rs

1/*
2 * Twelve Data API
3 *
4 * ## Overview  Welcome to Twelve Data developer docs — your gateway to comprehensive financial market data through a powerful and easy-to-use API. Twelve Data provides access to financial markets across over 50 global countries, covering more than 1 million public instruments, including stocks, forex, ETFs, mutual funds, commodities, and cryptocurrencies.  ## Quickstart  To get started, you'll need to sign up for an API key. Once you have your API key, you can start making requests to the API.  ### Step 1: Create Twelve Data account  Sign up on the Twelve Data website to create your account [here](https://twelvedata.com/register). This gives you access to the API dashboard and your API key.  ### Step 2: Get your API key  After signing in, navigate to your [dashboard](https://twelvedata.com/account/api-keys) to find your unique API key. This key is required to authenticate all API and WebSocket requests.  ### Step 3: Make your first request  Try a simple API call with cURL to fetch the latest price for Apple (AAPL):  ``` curl \"https://api.twelvedata.com/price?symbol=AAPL&apikey=your_api_key\" ```  ### Step 4: Make a request from Python or Javascript  Use our client libraries or standard HTTP clients to make API calls programmatically. Here’s an example in [Python](https://github.com/twelvedata/twelvedata-python) and JavaScript:  #### Python (using official Twelve Data SDK):  ```python from twelvedata import TDClient  # Initialize client with your API key td = TDClient(apikey=\"your_api_key\")  # Get latest price for Apple price = td.price(symbol=\"AAPL\").as_json()  print(price) ```  #### JavaScript (Node.js):  ```javascript const fetch = require('node-fetch');  fetch('https://api.twelvedata.com/price?symbol=AAPL&apikey=your_api_key') &nbsp;&nbsp;.then(response => response.json()) &nbsp;&nbsp;.then(data => console.log(data)); ```  ### Step 5: Perform correlation analysis between Tesla and Microsoft prices  Fetch historical price data for Tesla (TSLA) and Microsoft (MSFT) and calculate the correlation of their closing prices:  ```python from twelvedata import TDClient import pandas as pd  # Initialize client with your API key td = TDClient(apikey=\"your_api_key\")  # Fetch historical price data for Tesla tsla_ts = td.time_series( &nbsp;&nbsp;&nbsp;&nbsp;symbol=\"TSLA\", &nbsp;&nbsp;&nbsp;&nbsp;interval=\"1day\", &nbsp;&nbsp;&nbsp;&nbsp;outputsize=100 ).as_pandas()  # Fetch historical price data for Microsoft msft_ts = td.time_series( &nbsp;&nbsp;&nbsp;&nbsp;symbol=\"MSFT\", &nbsp;&nbsp;&nbsp;&nbsp;interval=\"1day\", &nbsp;&nbsp;&nbsp;&nbsp;outputsize=100 ).as_pandas()  # Align data on datetime index combined = pd.concat( &nbsp;&nbsp;&nbsp;&nbsp;[tsla_ts['close'].astype(float), msft_ts['close'].astype(float)], &nbsp;&nbsp;&nbsp;&nbsp;axis=1, &nbsp;&nbsp;&nbsp;&nbsp;keys=[\"TSLA\", \"MSFT\"] ).dropna()  # Calculate correlation correlation = combined[\"TSLA\"].corr(combined[\"MSFT\"]) print(f\"Correlation of closing prices between TSLA and MSFT: {correlation:.2f}\") ```  ### Authentication  Authenticate your requests using one of these methods:  #### Query parameter method ``` GET https://api.twelvedata.com/endpoint?symbol=AAPL&apikey=your_api_key ```  #### HTTP header method (recommended) ``` Authorization: apikey your_api_key ```  ##### API key useful information <ul> <li> Demo API key (<code>apikey=demo</code>) available for demo requests</li> <li> Personal API key required for full access</li> <li> Premium endpoints and data require higher-tier plans (testable with <a href=\"https://twelvedata.com/exchanges\">trial symbols</a>)</li> </ul>  ### API endpoints   Service | Base URL | ---------|----------|  REST API | `https://api.twelvedata.com` |  WebSocket | `wss://ws.twelvedata.com` |  ### Parameter guidelines <ul> <li><b>Separator:</b> Use <code>&</code> to separate multiple parameters</li> <li><b>Case sensitivity:</b> Parameter names are case-insensitive</li>  <ul><li><code>symbol=AAPL</code> = <code>symbol=aapl</code></li></ul>  <li><b>Multiple values:</b> Separate with commas where supported</li> </ul>  ### Response handling  #### Default format All responses return JSON format by default unless otherwise specified.  #### Null values <b>Important:</b> Some response fields may contain `null` values when data is unavailable for specific metrics. This is expected behavior, not an error.  ##### Best Practices: <ul> <li>Always implement <code>null</code> value handling in your application</li> <li>Use defensive programming techniques for data processing</li> <li>Consider fallback values or error handling for critical metrics</li> </ul>  #### Error handling Structure your code to gracefully handle: <ul> <li>Network timeouts</li> <li>Rate limiting responses</li> <li>Invalid parameter errors</li> <li>Data unavailability periods</li> </ul>  ##### Best practices <ul> <li><b>Rate limits:</b> Adhere to your plan’s rate limits to avoid throttling. Check your dashboard for details.</li> <li><b>Error handling:</b> Implement retry logic for transient errors (e.g., <code>429 Too Many Requests</code>).</li> <li><b>Caching:</b> Cache responses for frequently accessed data to reduce API calls and improve performance.</li> <li><b>Secure storage:</b> Store your API key securely and never expose it in client-side code or public repositories.</li> </ul>  ## Errors  Twelve Data API employs a standardized error response format, delivering a JSON object with `code`, `message`, and `status` keys for clear and consistent error communication.  ### Codes  Below is a table of possible error codes, their HTTP status, meanings, and resolution steps:   Code | status | Meaning | Resolution |  --- | --- | --- | --- |  **400** | Bad Request | Invalid or incorrect parameter(s) provided. | Check the `message` in the response for details. Refer to the API Documenta­tion to correct the input. |  **401** | Unauthor­ized | Invalid or incorrect API key. | Verify your API key is correct. Sign up for a key <a href=\"https://twelvedata.com/account/api-keys\">here</a>. |  **403** | Forbidden | API key lacks permissions for the requested resource (upgrade required). | Upgrade your plan <a href=\"https://twelvedata.com/pricing\">here</a>. |  **404** | Not Found | Requested data could not be found. | Adjust parameters to be less strict as they may be too restrictive. |  **414** | Parameter Too Long | Input parameter array exceeds the allowed length. | Follow the `message` guidance to adjust the parameter length. |  **429** | Too Many Requests | API request limit reached for your key. | Wait briefly or upgrade your plan <a href=\"https://twelvedata.com/pricing\">here</a>. |  **500** | Internal Server Error | Server-side issue occurred; retry later. | Contact support <a href=\"https://twelvedata.com/contact\">here</a> for assistance. |  ### Example error response  Consider the following invalid request:  ``` https://api.twelvedata.com/time_series?symbol=AAPL&interval=0.99min&apikey=your_api_key ```  Due to the incorrect `interval` value, the API returns:  ```json { &nbsp;&nbsp;\"code\": 400, &nbsp;&nbsp;\"message\": \"Invalid **interval** provided: 0.99min. Supported intervals: 1min, 5min, 15min, 30min, 45min, 1h, 2h, 4h, 8h, 1day, 1week, 1month\", &nbsp;&nbsp;\"status\": \"error\" } ```  Refer to the API Documentation for valid parameter values to resolve such errors.  ## Libraries  Twelve Data provides a growing ecosystem of libraries and integrations to help you build faster and smarter in your preferred environment. Official libraries are actively maintained by the Twelve Data team, while selected community-built libraries offer additional flexibility.  A full list is available on our [GitHub profile](https://github.com/search?q=twelvedata).  ### Official SDKs <ul> <li><b>Python:</b> <a href=\"https://github.com/twelvedata/twelvedata-python\">twelvedata-python</a></li> <li><b>R:</b> <a href=\"https://github.com/twelvedata/twelvedata-r-sdk\">twelvedata-r-sdk</a></li> </ul>  ### AI integrations <ul> <li><b>Twelve Data MCP Server:</b> <a href=\"https://github.com/twelvedata/mcp\">Repository</a> — Model Context Protocol (MCP) server that provides seamless integration with AI assistants and language models, enabling direct access to Twelve Data's financial market data within conversational interfaces and AI workflows.</li> </ul>  ### Spreadsheet add-ons <ul> <li><b>Excel:</b> <a href=\"https://twelvedata.com/excel\">Excel Add-in</a></li> <li><b>Google Sheets:</b> <a href=\"https://twelvedata.com/google-sheets\">Google Sheets Add-on</a></li> </ul>  ### Community libraries  The community has developed libraries in several popular languages. You can explore more community libraries on [GitHub](https://github.com/search?q=twelvedata). <ul> <li><b>C#:</b> <a href=\"https://github.com/pseudomarkets/TwelveDataSharp\">TwelveDataSharp</a></li> <li><b>JavaScript:</b> <a href=\"https://github.com/evzaboun/twelvedata\">twelvedata</a></li> <li><b>PHP:</b> <a href=\"https://github.com/ingelby/twelvedata\">twelvedata</a></li> <li><b>Go:</b> <a href=\"https://github.com/soulgarden/twelvedata\">twelvedata</a></li> <li><b>TypeScript:</b> <a href=\"https://github.com/Clyde-Goodall/twelve-data-wrapper\">twelve-data-wrapper</a></li> </ul>  ### Other Twelve Data repositories <ul> <li><b>searchindex</b> <i>(Go)</i>: <a href=\"https://github.com/twelvedata/searchindex\">Repository</a> — In-memory search index by strings</li> <li><b>ws-tools</b> <i>(Python)</i>: <a href=\"https://github.com/twelvedata/ws-tools\">Repository</a> — Utility tools for WebSocket stream handling</li> </ul>  ### API specification <ul> <li><b>OpenAPI / Swagger:</b> Access the <a href=\"https://api.twelvedata.com/doc/swagger/openapi.json\">complete API specification</a> in OpenAPI format. You can use this file to automatically generate client libraries in your preferred programming language, explore the API interactively via Swagger tools, or integrate Twelve Data seamlessly into your AI and LLM workflows.</li> </ul>
5 *
6 * The version of the OpenAPI document: 0.0.1
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for passing parameters to the method [`get_etfs_world`]
17#[derive(Clone, Debug, Default, Serialize, Deserialize)]
18pub struct GetEtfsWorldParams {
19    /// Symbol ticker of etf
20    pub symbol: Option<String>,
21    /// Filter by financial instrument global identifier (FIGI)
22    pub figi: Option<String>,
23    /// Filter by international securities identification number (ISIN)
24    pub isin: Option<String>,
25    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
26    pub cusip: Option<String>,
27    /// Filter by country name or alpha code, e.g., `United States` or `US`
28    pub country: Option<String>,
29    /// Number of decimal places for floating values. Accepts value in range [0,11]
30    pub dp: Option<i64>,
31}
32
33impl GetEtfsWorldParams {
34    /// Create a new builder for this parameter struct
35    pub fn builder() -> GetEtfsWorldParamsBuilder {
36        GetEtfsWorldParamsBuilder::default()
37    }
38}
39
40/// Builder for [`GetEtfsWorldParams`]
41#[derive(Clone, Debug, Default)]
42pub struct GetEtfsWorldParamsBuilder {
43    /// Symbol ticker of etf
44    symbol: Option<String>,
45    /// Filter by financial instrument global identifier (FIGI)
46    figi: Option<String>,
47    /// Filter by international securities identification number (ISIN)
48    isin: Option<String>,
49    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
50    cusip: Option<String>,
51    /// Filter by country name or alpha code, e.g., `United States` or `US`
52    country: Option<String>,
53    /// Number of decimal places for floating values. Accepts value in range [0,11]
54    dp: Option<i64>,
55}
56
57impl GetEtfsWorldParamsBuilder {
58    /// Symbol ticker of etf
59    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
60        self.symbol = Some(symbol.into());
61        self
62    }
63    /// Filter by financial instrument global identifier (FIGI)
64    pub fn figi(mut self, figi: impl Into<String>) -> Self {
65        self.figi = Some(figi.into());
66        self
67    }
68    /// Filter by international securities identification number (ISIN)
69    pub fn isin(mut self, isin: impl Into<String>) -> Self {
70        self.isin = Some(isin.into());
71        self
72    }
73    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
74    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
75        self.cusip = Some(cusip.into());
76        self
77    }
78    /// Filter by country name or alpha code, e.g., `United States` or `US`
79    pub fn country(mut self, country: impl Into<String>) -> Self {
80        self.country = Some(country.into());
81        self
82    }
83    /// Number of decimal places for floating values. Accepts value in range [0,11]
84    pub fn dp(mut self, dp: i64) -> Self {
85        self.dp = Some(dp);
86        self
87    }
88
89    /// Build the parameter struct
90    pub fn build(self) -> GetEtfsWorldParams {
91        GetEtfsWorldParams {
92            symbol: self.symbol,
93            figi: self.figi,
94            isin: self.isin,
95            cusip: self.cusip,
96            country: self.country,
97            dp: self.dp,
98        }
99    }
100}
101
102/// struct for passing parameters to the method [`get_etfs_world_composition`]
103#[derive(Clone, Debug, Default, Serialize, Deserialize)]
104pub struct GetEtfsWorldCompositionParams {
105    /// Symbol ticker of etf
106    pub symbol: Option<String>,
107    /// Filter by financial instrument global identifier (FIGI)
108    pub figi: Option<String>,
109    /// Filter by international securities identification number (ISIN)
110    pub isin: Option<String>,
111    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
112    pub cusip: Option<String>,
113    /// Filter by country name or alpha code, e.g., `United States` or `US`
114    pub country: Option<String>,
115    /// Number of decimal places for floating values. Accepts value in range [0,11]
116    pub dp: Option<i64>,
117}
118
119impl GetEtfsWorldCompositionParams {
120    /// Create a new builder for this parameter struct
121    pub fn builder() -> GetEtfsWorldCompositionParamsBuilder {
122        GetEtfsWorldCompositionParamsBuilder::default()
123    }
124}
125
126/// Builder for [`GetEtfsWorldCompositionParams`]
127#[derive(Clone, Debug, Default)]
128pub struct GetEtfsWorldCompositionParamsBuilder {
129    /// Symbol ticker of etf
130    symbol: Option<String>,
131    /// Filter by financial instrument global identifier (FIGI)
132    figi: Option<String>,
133    /// Filter by international securities identification number (ISIN)
134    isin: Option<String>,
135    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
136    cusip: Option<String>,
137    /// Filter by country name or alpha code, e.g., `United States` or `US`
138    country: Option<String>,
139    /// Number of decimal places for floating values. Accepts value in range [0,11]
140    dp: Option<i64>,
141}
142
143impl GetEtfsWorldCompositionParamsBuilder {
144    /// Symbol ticker of etf
145    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
146        self.symbol = Some(symbol.into());
147        self
148    }
149    /// Filter by financial instrument global identifier (FIGI)
150    pub fn figi(mut self, figi: impl Into<String>) -> Self {
151        self.figi = Some(figi.into());
152        self
153    }
154    /// Filter by international securities identification number (ISIN)
155    pub fn isin(mut self, isin: impl Into<String>) -> Self {
156        self.isin = Some(isin.into());
157        self
158    }
159    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
160    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
161        self.cusip = Some(cusip.into());
162        self
163    }
164    /// Filter by country name or alpha code, e.g., `United States` or `US`
165    pub fn country(mut self, country: impl Into<String>) -> Self {
166        self.country = Some(country.into());
167        self
168    }
169    /// Number of decimal places for floating values. Accepts value in range [0,11]
170    pub fn dp(mut self, dp: i64) -> Self {
171        self.dp = Some(dp);
172        self
173    }
174
175    /// Build the parameter struct
176    pub fn build(self) -> GetEtfsWorldCompositionParams {
177        GetEtfsWorldCompositionParams {
178            symbol: self.symbol,
179            figi: self.figi,
180            isin: self.isin,
181            cusip: self.cusip,
182            country: self.country,
183            dp: self.dp,
184        }
185    }
186}
187
188/// struct for passing parameters to the method [`get_etfs_world_performance`]
189#[derive(Clone, Debug, Default, Serialize, Deserialize)]
190pub struct GetEtfsWorldPerformanceParams {
191    /// Symbol ticker of etf
192    pub symbol: Option<String>,
193    /// Filter by financial instrument global identifier (FIGI)
194    pub figi: Option<String>,
195    /// Filter by international securities identification number (ISIN)
196    pub isin: Option<String>,
197    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
198    pub cusip: Option<String>,
199    /// Filter by country name or alpha code, e.g., `United States` or `US`
200    pub country: Option<String>,
201    /// Number of decimal places for floating values. Accepts value in range [0,11]
202    pub dp: Option<i64>,
203}
204
205impl GetEtfsWorldPerformanceParams {
206    /// Create a new builder for this parameter struct
207    pub fn builder() -> GetEtfsWorldPerformanceParamsBuilder {
208        GetEtfsWorldPerformanceParamsBuilder::default()
209    }
210}
211
212/// Builder for [`GetEtfsWorldPerformanceParams`]
213#[derive(Clone, Debug, Default)]
214pub struct GetEtfsWorldPerformanceParamsBuilder {
215    /// Symbol ticker of etf
216    symbol: Option<String>,
217    /// Filter by financial instrument global identifier (FIGI)
218    figi: Option<String>,
219    /// Filter by international securities identification number (ISIN)
220    isin: Option<String>,
221    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
222    cusip: Option<String>,
223    /// Filter by country name or alpha code, e.g., `United States` or `US`
224    country: Option<String>,
225    /// Number of decimal places for floating values. Accepts value in range [0,11]
226    dp: Option<i64>,
227}
228
229impl GetEtfsWorldPerformanceParamsBuilder {
230    /// Symbol ticker of etf
231    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
232        self.symbol = Some(symbol.into());
233        self
234    }
235    /// Filter by financial instrument global identifier (FIGI)
236    pub fn figi(mut self, figi: impl Into<String>) -> Self {
237        self.figi = Some(figi.into());
238        self
239    }
240    /// Filter by international securities identification number (ISIN)
241    pub fn isin(mut self, isin: impl Into<String>) -> Self {
242        self.isin = Some(isin.into());
243        self
244    }
245    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
246    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
247        self.cusip = Some(cusip.into());
248        self
249    }
250    /// Filter by country name or alpha code, e.g., `United States` or `US`
251    pub fn country(mut self, country: impl Into<String>) -> Self {
252        self.country = Some(country.into());
253        self
254    }
255    /// Number of decimal places for floating values. Accepts value in range [0,11]
256    pub fn dp(mut self, dp: i64) -> Self {
257        self.dp = Some(dp);
258        self
259    }
260
261    /// Build the parameter struct
262    pub fn build(self) -> GetEtfsWorldPerformanceParams {
263        GetEtfsWorldPerformanceParams {
264            symbol: self.symbol,
265            figi: self.figi,
266            isin: self.isin,
267            cusip: self.cusip,
268            country: self.country,
269            dp: self.dp,
270        }
271    }
272}
273
274/// struct for passing parameters to the method [`get_etfs_world_risk`]
275#[derive(Clone, Debug, Default, Serialize, Deserialize)]
276pub struct GetEtfsWorldRiskParams {
277    /// Symbol ticker of etf
278    pub symbol: Option<String>,
279    /// Filter by financial instrument global identifier (FIGI)
280    pub figi: Option<String>,
281    /// Filter by international securities identification number (ISIN)
282    pub isin: Option<String>,
283    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
284    pub cusip: Option<String>,
285    /// Filter by country name or alpha code, e.g., `United States` or `US`
286    pub country: Option<String>,
287    /// Number of decimal places for floating values. Accepts value in range [0,11]
288    pub dp: Option<i64>,
289}
290
291impl GetEtfsWorldRiskParams {
292    /// Create a new builder for this parameter struct
293    pub fn builder() -> GetEtfsWorldRiskParamsBuilder {
294        GetEtfsWorldRiskParamsBuilder::default()
295    }
296}
297
298/// Builder for [`GetEtfsWorldRiskParams`]
299#[derive(Clone, Debug, Default)]
300pub struct GetEtfsWorldRiskParamsBuilder {
301    /// Symbol ticker of etf
302    symbol: Option<String>,
303    /// Filter by financial instrument global identifier (FIGI)
304    figi: Option<String>,
305    /// Filter by international securities identification number (ISIN)
306    isin: Option<String>,
307    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
308    cusip: Option<String>,
309    /// Filter by country name or alpha code, e.g., `United States` or `US`
310    country: Option<String>,
311    /// Number of decimal places for floating values. Accepts value in range [0,11]
312    dp: Option<i64>,
313}
314
315impl GetEtfsWorldRiskParamsBuilder {
316    /// Symbol ticker of etf
317    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
318        self.symbol = Some(symbol.into());
319        self
320    }
321    /// Filter by financial instrument global identifier (FIGI)
322    pub fn figi(mut self, figi: impl Into<String>) -> Self {
323        self.figi = Some(figi.into());
324        self
325    }
326    /// Filter by international securities identification number (ISIN)
327    pub fn isin(mut self, isin: impl Into<String>) -> Self {
328        self.isin = Some(isin.into());
329        self
330    }
331    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
332    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
333        self.cusip = Some(cusip.into());
334        self
335    }
336    /// Filter by country name or alpha code, e.g., `United States` or `US`
337    pub fn country(mut self, country: impl Into<String>) -> Self {
338        self.country = Some(country.into());
339        self
340    }
341    /// Number of decimal places for floating values. Accepts value in range [0,11]
342    pub fn dp(mut self, dp: i64) -> Self {
343        self.dp = Some(dp);
344        self
345    }
346
347    /// Build the parameter struct
348    pub fn build(self) -> GetEtfsWorldRiskParams {
349        GetEtfsWorldRiskParams {
350            symbol: self.symbol,
351            figi: self.figi,
352            isin: self.isin,
353            cusip: self.cusip,
354            country: self.country,
355            dp: self.dp,
356        }
357    }
358}
359
360/// struct for passing parameters to the method [`get_etfs_world_summary`]
361#[derive(Clone, Debug, Default, Serialize, Deserialize)]
362pub struct GetEtfsWorldSummaryParams {
363    /// Symbol ticker of etf
364    pub symbol: Option<String>,
365    /// Filter by financial instrument global identifier (FIGI)
366    pub figi: Option<String>,
367    /// Filter by international securities identification number (ISIN)
368    pub isin: Option<String>,
369    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
370    pub cusip: Option<String>,
371    /// Filter by country name or alpha code, e.g., `United States` or `US`
372    pub country: Option<String>,
373    /// Number of decimal places for floating values. Accepts value in range [0,11]
374    pub dp: Option<i64>,
375}
376
377impl GetEtfsWorldSummaryParams {
378    /// Create a new builder for this parameter struct
379    pub fn builder() -> GetEtfsWorldSummaryParamsBuilder {
380        GetEtfsWorldSummaryParamsBuilder::default()
381    }
382}
383
384/// Builder for [`GetEtfsWorldSummaryParams`]
385#[derive(Clone, Debug, Default)]
386pub struct GetEtfsWorldSummaryParamsBuilder {
387    /// Symbol ticker of etf
388    symbol: Option<String>,
389    /// Filter by financial instrument global identifier (FIGI)
390    figi: Option<String>,
391    /// Filter by international securities identification number (ISIN)
392    isin: Option<String>,
393    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
394    cusip: Option<String>,
395    /// Filter by country name or alpha code, e.g., `United States` or `US`
396    country: Option<String>,
397    /// Number of decimal places for floating values. Accepts value in range [0,11]
398    dp: Option<i64>,
399}
400
401impl GetEtfsWorldSummaryParamsBuilder {
402    /// Symbol ticker of etf
403    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
404        self.symbol = Some(symbol.into());
405        self
406    }
407    /// Filter by financial instrument global identifier (FIGI)
408    pub fn figi(mut self, figi: impl Into<String>) -> Self {
409        self.figi = Some(figi.into());
410        self
411    }
412    /// Filter by international securities identification number (ISIN)
413    pub fn isin(mut self, isin: impl Into<String>) -> Self {
414        self.isin = Some(isin.into());
415        self
416    }
417    /// The CUSIP of an instrument for which data is requested. CUSIP access is activating in the <a href=\"https://twelvedata.com/account/add-ons\">Add-ons</a> section
418    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
419        self.cusip = Some(cusip.into());
420        self
421    }
422    /// Filter by country name or alpha code, e.g., `United States` or `US`
423    pub fn country(mut self, country: impl Into<String>) -> Self {
424        self.country = Some(country.into());
425        self
426    }
427    /// Number of decimal places for floating values. Accepts value in range [0,11]
428    pub fn dp(mut self, dp: i64) -> Self {
429        self.dp = Some(dp);
430        self
431    }
432
433    /// Build the parameter struct
434    pub fn build(self) -> GetEtfsWorldSummaryParams {
435        GetEtfsWorldSummaryParams {
436            symbol: self.symbol,
437            figi: self.figi,
438            isin: self.isin,
439            cusip: self.cusip,
440            country: self.country,
441            dp: self.dp,
442        }
443    }
444}
445
446/// struct for typed errors of method [`get_etfs_world`]
447#[derive(Debug, Clone, Serialize, Deserialize)]
448#[serde(untagged)]
449pub enum GetEtfsWorldError {
450    UnknownValue(serde_json::Value),
451}
452
453/// struct for typed errors of method [`get_etfs_world_composition`]
454#[derive(Debug, Clone, Serialize, Deserialize)]
455#[serde(untagged)]
456pub enum GetEtfsWorldCompositionError {
457    UnknownValue(serde_json::Value),
458}
459
460/// struct for typed errors of method [`get_etfs_world_performance`]
461#[derive(Debug, Clone, Serialize, Deserialize)]
462#[serde(untagged)]
463pub enum GetEtfsWorldPerformanceError {
464    UnknownValue(serde_json::Value),
465}
466
467/// struct for typed errors of method [`get_etfs_world_risk`]
468#[derive(Debug, Clone, Serialize, Deserialize)]
469#[serde(untagged)]
470pub enum GetEtfsWorldRiskError {
471    UnknownValue(serde_json::Value),
472}
473
474/// struct for typed errors of method [`get_etfs_world_summary`]
475#[derive(Debug, Clone, Serialize, Deserialize)]
476#[serde(untagged)]
477pub enum GetEtfsWorldSummaryError {
478    UnknownValue(serde_json::Value),
479}
480
481/// The ETF full data endpoint provides detailed information about global Exchange-Traded Funds. It returns comprehensive data, including a summary, performance metrics, risk assessment, and composition details. This endpoint is ideal for users seeking an in-depth analysis of worldwide ETFs, enabling them to access key financial metrics and portfolio breakdowns.
482pub async fn get_etfs_world(
483    configuration: &configuration::Configuration,
484    params: GetEtfsWorldParams,
485) -> Result<models::GetEtfsWorldResponse, Error<GetEtfsWorldError>> {
486    // Extract parameters from params struct
487    let p_query_symbol = params.symbol;
488    let p_query_figi = params.figi;
489    let p_query_isin = params.isin;
490    let p_query_cusip = params.cusip;
491    let p_query_country = params.country;
492    let p_query_dp = params.dp;
493
494    let uri_str = format!("{}/etfs/world", configuration.base_path);
495    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
496
497    if let Some(ref param_value) = p_query_symbol {
498        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
499    }
500    if let Some(ref param_value) = p_query_figi {
501        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
502    }
503    if let Some(ref param_value) = p_query_isin {
504        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
505    }
506    if let Some(ref param_value) = p_query_cusip {
507        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
508    }
509    if let Some(ref param_value) = p_query_country {
510        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
511    }
512    if let Some(ref param_value) = p_query_dp {
513        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
514    }
515    if let Some(ref user_agent) = configuration.user_agent {
516        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
517    }
518    if let Some(ref apikey) = configuration.api_key {
519        let key = apikey.key.clone();
520        let value = match apikey.prefix {
521            Some(ref prefix) => format!("{} {}", prefix, key),
522            None => key,
523        };
524        req_builder = req_builder.header("Authorization", value);
525    };
526
527    let req = req_builder.build()?;
528    let resp = configuration.client.execute(req).await?;
529
530    let status = resp.status();
531    let content_type = resp
532        .headers()
533        .get("content-type")
534        .and_then(|v| v.to_str().ok())
535        .unwrap_or("application/octet-stream");
536    let content_type = super::ContentType::from(content_type);
537
538    if !status.is_client_error() && !status.is_server_error() {
539        let content = resp.text().await?;
540        match content_type {
541            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
542            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/*` content type response that cannot be converted to `models::GetEtfsWorldResponse`"))),
543            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetEtfsWorldResponse`")))),
544        }
545    } else {
546        let content = resp.text().await?;
547        let entity: Option<GetEtfsWorldError> = serde_json::from_str(&content).ok();
548        Err(Error::ResponseError(ResponseContent {
549            status,
550            content,
551            entity,
552        }))
553    }
554}
555
556/// The ETFs composition endpoint provides detailed information about the composition of global Exchange-Traded Funds. It returns data on the sectors included in the ETF, specific holding details, and the weighted exposure of each component. This endpoint is useful for users who need to understand the specific makeup and sector distribution of an ETF portfolio.
557pub async fn get_etfs_world_composition(
558    configuration: &configuration::Configuration,
559    params: GetEtfsWorldCompositionParams,
560) -> Result<models::GetEtfsWorldCompositionResponse, Error<GetEtfsWorldCompositionError>> {
561    // Extract parameters from params struct
562    let p_query_symbol = params.symbol;
563    let p_query_figi = params.figi;
564    let p_query_isin = params.isin;
565    let p_query_cusip = params.cusip;
566    let p_query_country = params.country;
567    let p_query_dp = params.dp;
568
569    let uri_str = format!("{}/etfs/world/composition", configuration.base_path);
570    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
571
572    if let Some(ref param_value) = p_query_symbol {
573        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
574    }
575    if let Some(ref param_value) = p_query_figi {
576        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
577    }
578    if let Some(ref param_value) = p_query_isin {
579        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
580    }
581    if let Some(ref param_value) = p_query_cusip {
582        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
583    }
584    if let Some(ref param_value) = p_query_country {
585        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
586    }
587    if let Some(ref param_value) = p_query_dp {
588        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
589    }
590    if let Some(ref user_agent) = configuration.user_agent {
591        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
592    }
593    if let Some(ref apikey) = configuration.api_key {
594        let key = apikey.key.clone();
595        let value = match apikey.prefix {
596            Some(ref prefix) => format!("{} {}", prefix, key),
597            None => key,
598        };
599        req_builder = req_builder.header("Authorization", value);
600    };
601
602    let req = req_builder.build()?;
603    let resp = configuration.client.execute(req).await?;
604
605    let status = resp.status();
606    let content_type = resp
607        .headers()
608        .get("content-type")
609        .and_then(|v| v.to_str().ok())
610        .unwrap_or("application/octet-stream");
611    let content_type = super::ContentType::from(content_type);
612
613    if !status.is_client_error() && !status.is_server_error() {
614        let content = resp.text().await?;
615        match content_type {
616            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
617            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/*` content type response that cannot be converted to `models::GetEtfsWorldCompositionResponse`"))),
618            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetEtfsWorldCompositionResponse`")))),
619        }
620    } else {
621        let content = resp.text().await?;
622        let entity: Option<GetEtfsWorldCompositionError> = serde_json::from_str(&content).ok();
623        Err(Error::ResponseError(ResponseContent {
624            status,
625            content,
626            entity,
627        }))
628    }
629}
630
631/// The ETFs performance endpoint provides comprehensive performance data for exchange-traded funds globally. It returns detailed metrics such as trailing returns and annual returns, enabling users to evaluate the historical performance of various ETFs. This endpoint is ideal for users looking to compare ETF performance over different time periods and assess their investment potential.
632pub async fn get_etfs_world_performance(
633    configuration: &configuration::Configuration,
634    params: GetEtfsWorldPerformanceParams,
635) -> Result<models::GetEtfsWorldPerformanceResponse, Error<GetEtfsWorldPerformanceError>> {
636    // Extract parameters from params struct
637    let p_query_symbol = params.symbol;
638    let p_query_figi = params.figi;
639    let p_query_isin = params.isin;
640    let p_query_cusip = params.cusip;
641    let p_query_country = params.country;
642    let p_query_dp = params.dp;
643
644    let uri_str = format!("{}/etfs/world/performance", configuration.base_path);
645    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
646
647    if let Some(ref param_value) = p_query_symbol {
648        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
649    }
650    if let Some(ref param_value) = p_query_figi {
651        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
652    }
653    if let Some(ref param_value) = p_query_isin {
654        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
655    }
656    if let Some(ref param_value) = p_query_cusip {
657        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
658    }
659    if let Some(ref param_value) = p_query_country {
660        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
661    }
662    if let Some(ref param_value) = p_query_dp {
663        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
664    }
665    if let Some(ref user_agent) = configuration.user_agent {
666        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
667    }
668    if let Some(ref apikey) = configuration.api_key {
669        let key = apikey.key.clone();
670        let value = match apikey.prefix {
671            Some(ref prefix) => format!("{} {}", prefix, key),
672            None => key,
673        };
674        req_builder = req_builder.header("Authorization", value);
675    };
676
677    let req = req_builder.build()?;
678    let resp = configuration.client.execute(req).await?;
679
680    let status = resp.status();
681    let content_type = resp
682        .headers()
683        .get("content-type")
684        .and_then(|v| v.to_str().ok())
685        .unwrap_or("application/octet-stream");
686    let content_type = super::ContentType::from(content_type);
687
688    if !status.is_client_error() && !status.is_server_error() {
689        let content = resp.text().await?;
690        match content_type {
691            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
692            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/*` content type response that cannot be converted to `models::GetEtfsWorldPerformanceResponse`"))),
693            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetEtfsWorldPerformanceResponse`")))),
694        }
695    } else {
696        let content = resp.text().await?;
697        let entity: Option<GetEtfsWorldPerformanceError> = serde_json::from_str(&content).ok();
698        Err(Error::ResponseError(ResponseContent {
699            status,
700            content,
701            entity,
702        }))
703    }
704}
705
706/// The ETFs risk endpoint provides essential risk metrics for global Exchange Traded Funds. It returns data such as volatility, beta, and other risk-related indicators, enabling users to assess the potential risk associated with investing in various ETFs worldwide.
707pub async fn get_etfs_world_risk(
708    configuration: &configuration::Configuration,
709    params: GetEtfsWorldRiskParams,
710) -> Result<models::GetEtfsWorldRiskResponse, Error<GetEtfsWorldRiskError>> {
711    // Extract parameters from params struct
712    let p_query_symbol = params.symbol;
713    let p_query_figi = params.figi;
714    let p_query_isin = params.isin;
715    let p_query_cusip = params.cusip;
716    let p_query_country = params.country;
717    let p_query_dp = params.dp;
718
719    let uri_str = format!("{}/etfs/world/risk", configuration.base_path);
720    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
721
722    if let Some(ref param_value) = p_query_symbol {
723        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
724    }
725    if let Some(ref param_value) = p_query_figi {
726        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
727    }
728    if let Some(ref param_value) = p_query_isin {
729        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
730    }
731    if let Some(ref param_value) = p_query_cusip {
732        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
733    }
734    if let Some(ref param_value) = p_query_country {
735        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
736    }
737    if let Some(ref param_value) = p_query_dp {
738        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
739    }
740    if let Some(ref user_agent) = configuration.user_agent {
741        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
742    }
743    if let Some(ref apikey) = configuration.api_key {
744        let key = apikey.key.clone();
745        let value = match apikey.prefix {
746            Some(ref prefix) => format!("{} {}", prefix, key),
747            None => key,
748        };
749        req_builder = req_builder.header("Authorization", value);
750    };
751
752    let req = req_builder.build()?;
753    let resp = configuration.client.execute(req).await?;
754
755    let status = resp.status();
756    let content_type = resp
757        .headers()
758        .get("content-type")
759        .and_then(|v| v.to_str().ok())
760        .unwrap_or("application/octet-stream");
761    let content_type = super::ContentType::from(content_type);
762
763    if !status.is_client_error() && !status.is_server_error() {
764        let content = resp.text().await?;
765        match content_type {
766            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
767            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/*` content type response that cannot be converted to `models::GetEtfsWorldRiskResponse`"))),
768            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetEtfsWorldRiskResponse`")))),
769        }
770    } else {
771        let content = resp.text().await?;
772        let entity: Option<GetEtfsWorldRiskError> = serde_json::from_str(&content).ok();
773        Err(Error::ResponseError(ResponseContent {
774            status,
775            content,
776            entity,
777        }))
778    }
779}
780
781/// The ETFs summary endpoint provides a concise overview of global Exchange-Traded Funds. It returns key data points such as ETF names, symbols, and current market values, enabling users to quickly assess the performance and status of various international ETFs. This summary is ideal for users who need a snapshot of the global ETF landscape without delving into detailed analysis.
782pub async fn get_etfs_world_summary(
783    configuration: &configuration::Configuration,
784    params: GetEtfsWorldSummaryParams,
785) -> Result<models::GetEtfsWorldSummaryResponse, Error<GetEtfsWorldSummaryError>> {
786    // Extract parameters from params struct
787    let p_query_symbol = params.symbol;
788    let p_query_figi = params.figi;
789    let p_query_isin = params.isin;
790    let p_query_cusip = params.cusip;
791    let p_query_country = params.country;
792    let p_query_dp = params.dp;
793
794    let uri_str = format!("{}/etfs/world/summary", configuration.base_path);
795    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
796
797    if let Some(ref param_value) = p_query_symbol {
798        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
799    }
800    if let Some(ref param_value) = p_query_figi {
801        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
802    }
803    if let Some(ref param_value) = p_query_isin {
804        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
805    }
806    if let Some(ref param_value) = p_query_cusip {
807        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
808    }
809    if let Some(ref param_value) = p_query_country {
810        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
811    }
812    if let Some(ref param_value) = p_query_dp {
813        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
814    }
815    if let Some(ref user_agent) = configuration.user_agent {
816        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
817    }
818    if let Some(ref apikey) = configuration.api_key {
819        let key = apikey.key.clone();
820        let value = match apikey.prefix {
821            Some(ref prefix) => format!("{} {}", prefix, key),
822            None => key,
823        };
824        req_builder = req_builder.header("Authorization", value);
825    };
826
827    let req = req_builder.build()?;
828    let resp = configuration.client.execute(req).await?;
829
830    let status = resp.status();
831    let content_type = resp
832        .headers()
833        .get("content-type")
834        .and_then(|v| v.to_str().ok())
835        .unwrap_or("application/octet-stream");
836    let content_type = super::ContentType::from(content_type);
837
838    if !status.is_client_error() && !status.is_server_error() {
839        let content = resp.text().await?;
840        match content_type {
841            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
842            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/*` content type response that cannot be converted to `models::GetEtfsWorldSummaryResponse`"))),
843            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetEtfsWorldSummaryResponse`")))),
844        }
845    } else {
846        let content = resp.text().await?;
847        let entity: Option<GetEtfsWorldSummaryError> = serde_json::from_str(&content).ok();
848        Err(Error::ResponseError(ResponseContent {
849            status,
850            content,
851            entity,
852        }))
853    }
854}