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
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`get_etfs_world`]
18#[derive(Clone, Debug, Default, Serialize, Deserialize)]
19pub struct GetEtfsWorldParams {
20    /// Symbol ticker of etf
21    pub symbol: Option<String>,
22    /// Filter by financial instrument global identifier (FIGI)
23    pub figi: Option<String>,
24    /// Filter by international securities identification number (ISIN)
25    pub isin: Option<String>,
26    /// 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
27    pub cusip: Option<String>,
28    /// Filter by country name or alpha code, e.g., `United States` or `US`
29    pub country: Option<String>,
30    /// Number of decimal places for floating values. Accepts value in range [0,11]
31    pub dp: Option<i64>
32}
33
34impl GetEtfsWorldParams {
35    /// Create a new builder for this parameter struct
36    pub fn builder() -> GetEtfsWorldParamsBuilder {
37        GetEtfsWorldParamsBuilder::default()
38    }
39}
40
41/// Builder for [`GetEtfsWorldParams`]
42#[derive(Clone, Debug, Default)]
43pub struct GetEtfsWorldParamsBuilder {
44    /// Symbol ticker of etf
45    symbol: Option<String>,
46    /// Filter by financial instrument global identifier (FIGI)
47    figi: Option<String>,
48    /// Filter by international securities identification number (ISIN)
49    isin: Option<String>,
50    /// 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
51    cusip: Option<String>,
52    /// Filter by country name or alpha code, e.g., `United States` or `US`
53    country: Option<String>,
54    /// Number of decimal places for floating values. Accepts value in range [0,11]
55    dp: Option<i64>
56}
57
58impl GetEtfsWorldParamsBuilder {
59    /// Symbol ticker of etf
60    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
61        self.symbol = Some(symbol.into());
62        self
63    }
64    /// Filter by financial instrument global identifier (FIGI)
65    pub fn figi(mut self, figi: impl Into<String>) -> Self {
66        self.figi = Some(figi.into());
67        self
68    }
69    /// Filter by international securities identification number (ISIN)
70    pub fn isin(mut self, isin: impl Into<String>) -> Self {
71        self.isin = Some(isin.into());
72        self
73    }
74    /// 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
75    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
76        self.cusip = Some(cusip.into());
77        self
78    }
79    /// Filter by country name or alpha code, e.g., `United States` or `US`
80    pub fn country(mut self, country: impl Into<String>) -> Self {
81        self.country = Some(country.into());
82        self
83    }
84    /// Number of decimal places for floating values. Accepts value in range [0,11]
85    pub fn dp(mut self, dp: i64) -> Self {
86        self.dp = Some(dp);
87        self
88    }
89
90    /// Build the parameter struct
91    pub fn build(self) -> GetEtfsWorldParams {
92        GetEtfsWorldParams {
93            symbol: self.symbol,
94            figi: self.figi,
95            isin: self.isin,
96            cusip: self.cusip,
97            country: self.country,
98            dp: self.dp
99        }
100    }
101}
102
103/// struct for passing parameters to the method [`get_etfs_world_composition`]
104#[derive(Clone, Debug, Default, Serialize, Deserialize)]
105pub struct GetEtfsWorldCompositionParams {
106    /// Symbol ticker of etf
107    pub symbol: Option<String>,
108    /// Filter by financial instrument global identifier (FIGI)
109    pub figi: Option<String>,
110    /// Filter by international securities identification number (ISIN)
111    pub isin: Option<String>,
112    /// 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
113    pub cusip: Option<String>,
114    /// Filter by country name or alpha code, e.g., `United States` or `US`
115    pub country: Option<String>,
116    /// Number of decimal places for floating values. Accepts value in range [0,11]
117    pub dp: Option<i64>
118}
119
120impl GetEtfsWorldCompositionParams {
121    /// Create a new builder for this parameter struct
122    pub fn builder() -> GetEtfsWorldCompositionParamsBuilder {
123        GetEtfsWorldCompositionParamsBuilder::default()
124    }
125}
126
127/// Builder for [`GetEtfsWorldCompositionParams`]
128#[derive(Clone, Debug, Default)]
129pub struct GetEtfsWorldCompositionParamsBuilder {
130    /// Symbol ticker of etf
131    symbol: Option<String>,
132    /// Filter by financial instrument global identifier (FIGI)
133    figi: Option<String>,
134    /// Filter by international securities identification number (ISIN)
135    isin: Option<String>,
136    /// 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
137    cusip: Option<String>,
138    /// Filter by country name or alpha code, e.g., `United States` or `US`
139    country: Option<String>,
140    /// Number of decimal places for floating values. Accepts value in range [0,11]
141    dp: Option<i64>
142}
143
144impl GetEtfsWorldCompositionParamsBuilder {
145    /// Symbol ticker of etf
146    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
147        self.symbol = Some(symbol.into());
148        self
149    }
150    /// Filter by financial instrument global identifier (FIGI)
151    pub fn figi(mut self, figi: impl Into<String>) -> Self {
152        self.figi = Some(figi.into());
153        self
154    }
155    /// Filter by international securities identification number (ISIN)
156    pub fn isin(mut self, isin: impl Into<String>) -> Self {
157        self.isin = Some(isin.into());
158        self
159    }
160    /// 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
161    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
162        self.cusip = Some(cusip.into());
163        self
164    }
165    /// Filter by country name or alpha code, e.g., `United States` or `US`
166    pub fn country(mut self, country: impl Into<String>) -> Self {
167        self.country = Some(country.into());
168        self
169    }
170    /// Number of decimal places for floating values. Accepts value in range [0,11]
171    pub fn dp(mut self, dp: i64) -> Self {
172        self.dp = Some(dp);
173        self
174    }
175
176    /// Build the parameter struct
177    pub fn build(self) -> GetEtfsWorldCompositionParams {
178        GetEtfsWorldCompositionParams {
179            symbol: self.symbol,
180            figi: self.figi,
181            isin: self.isin,
182            cusip: self.cusip,
183            country: self.country,
184            dp: self.dp
185        }
186    }
187}
188
189/// struct for passing parameters to the method [`get_etfs_world_performance`]
190#[derive(Clone, Debug, Default, Serialize, Deserialize)]
191pub struct GetEtfsWorldPerformanceParams {
192    /// Symbol ticker of etf
193    pub symbol: Option<String>,
194    /// Filter by financial instrument global identifier (FIGI)
195    pub figi: Option<String>,
196    /// Filter by international securities identification number (ISIN)
197    pub isin: Option<String>,
198    /// 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
199    pub cusip: Option<String>,
200    /// Filter by country name or alpha code, e.g., `United States` or `US`
201    pub country: Option<String>,
202    /// Number of decimal places for floating values. Accepts value in range [0,11]
203    pub dp: Option<i64>
204}
205
206impl GetEtfsWorldPerformanceParams {
207    /// Create a new builder for this parameter struct
208    pub fn builder() -> GetEtfsWorldPerformanceParamsBuilder {
209        GetEtfsWorldPerformanceParamsBuilder::default()
210    }
211}
212
213/// Builder for [`GetEtfsWorldPerformanceParams`]
214#[derive(Clone, Debug, Default)]
215pub struct GetEtfsWorldPerformanceParamsBuilder {
216    /// Symbol ticker of etf
217    symbol: Option<String>,
218    /// Filter by financial instrument global identifier (FIGI)
219    figi: Option<String>,
220    /// Filter by international securities identification number (ISIN)
221    isin: Option<String>,
222    /// 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
223    cusip: Option<String>,
224    /// Filter by country name or alpha code, e.g., `United States` or `US`
225    country: Option<String>,
226    /// Number of decimal places for floating values. Accepts value in range [0,11]
227    dp: Option<i64>
228}
229
230impl GetEtfsWorldPerformanceParamsBuilder {
231    /// Symbol ticker of etf
232    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
233        self.symbol = Some(symbol.into());
234        self
235    }
236    /// Filter by financial instrument global identifier (FIGI)
237    pub fn figi(mut self, figi: impl Into<String>) -> Self {
238        self.figi = Some(figi.into());
239        self
240    }
241    /// Filter by international securities identification number (ISIN)
242    pub fn isin(mut self, isin: impl Into<String>) -> Self {
243        self.isin = Some(isin.into());
244        self
245    }
246    /// 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
247    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
248        self.cusip = Some(cusip.into());
249        self
250    }
251    /// Filter by country name or alpha code, e.g., `United States` or `US`
252    pub fn country(mut self, country: impl Into<String>) -> Self {
253        self.country = Some(country.into());
254        self
255    }
256    /// Number of decimal places for floating values. Accepts value in range [0,11]
257    pub fn dp(mut self, dp: i64) -> Self {
258        self.dp = Some(dp);
259        self
260    }
261
262    /// Build the parameter struct
263    pub fn build(self) -> GetEtfsWorldPerformanceParams {
264        GetEtfsWorldPerformanceParams {
265            symbol: self.symbol,
266            figi: self.figi,
267            isin: self.isin,
268            cusip: self.cusip,
269            country: self.country,
270            dp: self.dp
271        }
272    }
273}
274
275/// struct for passing parameters to the method [`get_etfs_world_risk`]
276#[derive(Clone, Debug, Default, Serialize, Deserialize)]
277pub struct GetEtfsWorldRiskParams {
278    /// Symbol ticker of etf
279    pub symbol: Option<String>,
280    /// Filter by financial instrument global identifier (FIGI)
281    pub figi: Option<String>,
282    /// Filter by international securities identification number (ISIN)
283    pub isin: Option<String>,
284    /// 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
285    pub cusip: Option<String>,
286    /// Filter by country name or alpha code, e.g., `United States` or `US`
287    pub country: Option<String>,
288    /// Number of decimal places for floating values. Accepts value in range [0,11]
289    pub dp: Option<i64>
290}
291
292impl GetEtfsWorldRiskParams {
293    /// Create a new builder for this parameter struct
294    pub fn builder() -> GetEtfsWorldRiskParamsBuilder {
295        GetEtfsWorldRiskParamsBuilder::default()
296    }
297}
298
299/// Builder for [`GetEtfsWorldRiskParams`]
300#[derive(Clone, Debug, Default)]
301pub struct GetEtfsWorldRiskParamsBuilder {
302    /// Symbol ticker of etf
303    symbol: Option<String>,
304    /// Filter by financial instrument global identifier (FIGI)
305    figi: Option<String>,
306    /// Filter by international securities identification number (ISIN)
307    isin: Option<String>,
308    /// 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
309    cusip: Option<String>,
310    /// Filter by country name or alpha code, e.g., `United States` or `US`
311    country: Option<String>,
312    /// Number of decimal places for floating values. Accepts value in range [0,11]
313    dp: Option<i64>
314}
315
316impl GetEtfsWorldRiskParamsBuilder {
317    /// Symbol ticker of etf
318    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
319        self.symbol = Some(symbol.into());
320        self
321    }
322    /// Filter by financial instrument global identifier (FIGI)
323    pub fn figi(mut self, figi: impl Into<String>) -> Self {
324        self.figi = Some(figi.into());
325        self
326    }
327    /// Filter by international securities identification number (ISIN)
328    pub fn isin(mut self, isin: impl Into<String>) -> Self {
329        self.isin = Some(isin.into());
330        self
331    }
332    /// 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
333    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
334        self.cusip = Some(cusip.into());
335        self
336    }
337    /// Filter by country name or alpha code, e.g., `United States` or `US`
338    pub fn country(mut self, country: impl Into<String>) -> Self {
339        self.country = Some(country.into());
340        self
341    }
342    /// Number of decimal places for floating values. Accepts value in range [0,11]
343    pub fn dp(mut self, dp: i64) -> Self {
344        self.dp = Some(dp);
345        self
346    }
347
348    /// Build the parameter struct
349    pub fn build(self) -> GetEtfsWorldRiskParams {
350        GetEtfsWorldRiskParams {
351            symbol: self.symbol,
352            figi: self.figi,
353            isin: self.isin,
354            cusip: self.cusip,
355            country: self.country,
356            dp: self.dp
357        }
358    }
359}
360
361/// struct for passing parameters to the method [`get_etfs_world_summary`]
362#[derive(Clone, Debug, Default, Serialize, Deserialize)]
363pub struct GetEtfsWorldSummaryParams {
364    /// Symbol ticker of etf
365    pub symbol: Option<String>,
366    /// Filter by financial instrument global identifier (FIGI)
367    pub figi: Option<String>,
368    /// Filter by international securities identification number (ISIN)
369    pub isin: Option<String>,
370    /// 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
371    pub cusip: Option<String>,
372    /// Filter by country name or alpha code, e.g., `United States` or `US`
373    pub country: Option<String>,
374    /// Number of decimal places for floating values. Accepts value in range [0,11]
375    pub dp: Option<i64>
376}
377
378impl GetEtfsWorldSummaryParams {
379    /// Create a new builder for this parameter struct
380    pub fn builder() -> GetEtfsWorldSummaryParamsBuilder {
381        GetEtfsWorldSummaryParamsBuilder::default()
382    }
383}
384
385/// Builder for [`GetEtfsWorldSummaryParams`]
386#[derive(Clone, Debug, Default)]
387pub struct GetEtfsWorldSummaryParamsBuilder {
388    /// Symbol ticker of etf
389    symbol: Option<String>,
390    /// Filter by financial instrument global identifier (FIGI)
391    figi: Option<String>,
392    /// Filter by international securities identification number (ISIN)
393    isin: Option<String>,
394    /// 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
395    cusip: Option<String>,
396    /// Filter by country name or alpha code, e.g., `United States` or `US`
397    country: Option<String>,
398    /// Number of decimal places for floating values. Accepts value in range [0,11]
399    dp: Option<i64>
400}
401
402impl GetEtfsWorldSummaryParamsBuilder {
403    /// Symbol ticker of etf
404    pub fn symbol(mut self, symbol: impl Into<String>) -> Self {
405        self.symbol = Some(symbol.into());
406        self
407    }
408    /// Filter by financial instrument global identifier (FIGI)
409    pub fn figi(mut self, figi: impl Into<String>) -> Self {
410        self.figi = Some(figi.into());
411        self
412    }
413    /// Filter by international securities identification number (ISIN)
414    pub fn isin(mut self, isin: impl Into<String>) -> Self {
415        self.isin = Some(isin.into());
416        self
417    }
418    /// 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
419    pub fn cusip(mut self, cusip: impl Into<String>) -> Self {
420        self.cusip = Some(cusip.into());
421        self
422    }
423    /// Filter by country name or alpha code, e.g., `United States` or `US`
424    pub fn country(mut self, country: impl Into<String>) -> Self {
425        self.country = Some(country.into());
426        self
427    }
428    /// Number of decimal places for floating values. Accepts value in range [0,11]
429    pub fn dp(mut self, dp: i64) -> Self {
430        self.dp = Some(dp);
431        self
432    }
433
434    /// Build the parameter struct
435    pub fn build(self) -> GetEtfsWorldSummaryParams {
436        GetEtfsWorldSummaryParams {
437            symbol: self.symbol,
438            figi: self.figi,
439            isin: self.isin,
440            cusip: self.cusip,
441            country: self.country,
442            dp: self.dp
443        }
444    }
445}
446
447
448/// struct for typed errors of method [`get_etfs_world`]
449#[derive(Debug, Clone, Serialize, Deserialize)]
450#[serde(untagged)]
451pub enum GetEtfsWorldError {
452    UnknownValue(serde_json::Value),
453}
454
455/// struct for typed errors of method [`get_etfs_world_composition`]
456#[derive(Debug, Clone, Serialize, Deserialize)]
457#[serde(untagged)]
458pub enum GetEtfsWorldCompositionError {
459    UnknownValue(serde_json::Value),
460}
461
462/// struct for typed errors of method [`get_etfs_world_performance`]
463#[derive(Debug, Clone, Serialize, Deserialize)]
464#[serde(untagged)]
465pub enum GetEtfsWorldPerformanceError {
466    UnknownValue(serde_json::Value),
467}
468
469/// struct for typed errors of method [`get_etfs_world_risk`]
470#[derive(Debug, Clone, Serialize, Deserialize)]
471#[serde(untagged)]
472pub enum GetEtfsWorldRiskError {
473    UnknownValue(serde_json::Value),
474}
475
476/// struct for typed errors of method [`get_etfs_world_summary`]
477#[derive(Debug, Clone, Serialize, Deserialize)]
478#[serde(untagged)]
479pub enum GetEtfsWorldSummaryError {
480    UnknownValue(serde_json::Value),
481}
482
483
484/// 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.
485pub async fn get_etfs_world(configuration: &configuration::Configuration, params: GetEtfsWorldParams) -> Result<models::GetEtfsWorld200Response, 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/plain` content type response that cannot be converted to `models::GetEtfsWorld200Response`"))),
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::GetEtfsWorld200Response`")))),
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 { status, content, entity }))
549    }
550}
551
552/// 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.
553pub async fn get_etfs_world_composition(configuration: &configuration::Configuration, params: GetEtfsWorldCompositionParams) -> Result<models::GetEtfsWorldComposition200Response, Error<GetEtfsWorldCompositionError>> {
554    // Extract parameters from params struct
555    let p_query_symbol = params.symbol;
556    let p_query_figi = params.figi;
557    let p_query_isin = params.isin;
558    let p_query_cusip = params.cusip;
559    let p_query_country = params.country;
560    let p_query_dp = params.dp;
561
562    let uri_str = format!("{}/etfs/world/composition", configuration.base_path);
563    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
564
565    if let Some(ref param_value) = p_query_symbol {
566        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
567    }
568    if let Some(ref param_value) = p_query_figi {
569        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
570    }
571    if let Some(ref param_value) = p_query_isin {
572        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
573    }
574    if let Some(ref param_value) = p_query_cusip {
575        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
576    }
577    if let Some(ref param_value) = p_query_country {
578        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
579    }
580    if let Some(ref param_value) = p_query_dp {
581        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
582    }
583    if let Some(ref user_agent) = configuration.user_agent {
584        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
585    }
586    if let Some(ref apikey) = configuration.api_key {
587        let key = apikey.key.clone();
588        let value = match apikey.prefix {
589            Some(ref prefix) => format!("{} {}", prefix, key),
590            None => key,
591        };
592        req_builder = req_builder.header("Authorization", value);
593    };
594
595    let req = req_builder.build()?;
596    let resp = configuration.client.execute(req).await?;
597
598    let status = resp.status();
599    let content_type = resp
600        .headers()
601        .get("content-type")
602        .and_then(|v| v.to_str().ok())
603        .unwrap_or("application/octet-stream");
604    let content_type = super::ContentType::from(content_type);
605
606    if !status.is_client_error() && !status.is_server_error() {
607        let content = resp.text().await?;
608        match content_type {
609            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
610            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetEtfsWorldComposition200Response`"))),
611            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::GetEtfsWorldComposition200Response`")))),
612        }
613    } else {
614        let content = resp.text().await?;
615        let entity: Option<GetEtfsWorldCompositionError> = serde_json::from_str(&content).ok();
616        Err(Error::ResponseError(ResponseContent { status, content, entity }))
617    }
618}
619
620/// 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.
621pub async fn get_etfs_world_performance(configuration: &configuration::Configuration, params: GetEtfsWorldPerformanceParams) -> Result<models::GetEtfsWorldPerformance200Response, Error<GetEtfsWorldPerformanceError>> {
622    // Extract parameters from params struct
623    let p_query_symbol = params.symbol;
624    let p_query_figi = params.figi;
625    let p_query_isin = params.isin;
626    let p_query_cusip = params.cusip;
627    let p_query_country = params.country;
628    let p_query_dp = params.dp;
629
630    let uri_str = format!("{}/etfs/world/performance", configuration.base_path);
631    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
632
633    if let Some(ref param_value) = p_query_symbol {
634        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
635    }
636    if let Some(ref param_value) = p_query_figi {
637        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
638    }
639    if let Some(ref param_value) = p_query_isin {
640        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
641    }
642    if let Some(ref param_value) = p_query_cusip {
643        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
644    }
645    if let Some(ref param_value) = p_query_country {
646        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
647    }
648    if let Some(ref param_value) = p_query_dp {
649        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
650    }
651    if let Some(ref user_agent) = configuration.user_agent {
652        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
653    }
654    if let Some(ref apikey) = configuration.api_key {
655        let key = apikey.key.clone();
656        let value = match apikey.prefix {
657            Some(ref prefix) => format!("{} {}", prefix, key),
658            None => key,
659        };
660        req_builder = req_builder.header("Authorization", value);
661    };
662
663    let req = req_builder.build()?;
664    let resp = configuration.client.execute(req).await?;
665
666    let status = resp.status();
667    let content_type = resp
668        .headers()
669        .get("content-type")
670        .and_then(|v| v.to_str().ok())
671        .unwrap_or("application/octet-stream");
672    let content_type = super::ContentType::from(content_type);
673
674    if !status.is_client_error() && !status.is_server_error() {
675        let content = resp.text().await?;
676        match content_type {
677            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
678            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetEtfsWorldPerformance200Response`"))),
679            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::GetEtfsWorldPerformance200Response`")))),
680        }
681    } else {
682        let content = resp.text().await?;
683        let entity: Option<GetEtfsWorldPerformanceError> = serde_json::from_str(&content).ok();
684        Err(Error::ResponseError(ResponseContent { status, content, entity }))
685    }
686}
687
688/// 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.
689pub async fn get_etfs_world_risk(configuration: &configuration::Configuration, params: GetEtfsWorldRiskParams) -> Result<models::GetEtfsWorldRisk200Response, Error<GetEtfsWorldRiskError>> {
690    // Extract parameters from params struct
691    let p_query_symbol = params.symbol;
692    let p_query_figi = params.figi;
693    let p_query_isin = params.isin;
694    let p_query_cusip = params.cusip;
695    let p_query_country = params.country;
696    let p_query_dp = params.dp;
697
698    let uri_str = format!("{}/etfs/world/risk", configuration.base_path);
699    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
700
701    if let Some(ref param_value) = p_query_symbol {
702        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
703    }
704    if let Some(ref param_value) = p_query_figi {
705        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
706    }
707    if let Some(ref param_value) = p_query_isin {
708        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
709    }
710    if let Some(ref param_value) = p_query_cusip {
711        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
712    }
713    if let Some(ref param_value) = p_query_country {
714        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
715    }
716    if let Some(ref param_value) = p_query_dp {
717        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
718    }
719    if let Some(ref user_agent) = configuration.user_agent {
720        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
721    }
722    if let Some(ref apikey) = configuration.api_key {
723        let key = apikey.key.clone();
724        let value = match apikey.prefix {
725            Some(ref prefix) => format!("{} {}", prefix, key),
726            None => key,
727        };
728        req_builder = req_builder.header("Authorization", value);
729    };
730
731    let req = req_builder.build()?;
732    let resp = configuration.client.execute(req).await?;
733
734    let status = resp.status();
735    let content_type = resp
736        .headers()
737        .get("content-type")
738        .and_then(|v| v.to_str().ok())
739        .unwrap_or("application/octet-stream");
740    let content_type = super::ContentType::from(content_type);
741
742    if !status.is_client_error() && !status.is_server_error() {
743        let content = resp.text().await?;
744        match content_type {
745            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
746            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetEtfsWorldRisk200Response`"))),
747            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::GetEtfsWorldRisk200Response`")))),
748        }
749    } else {
750        let content = resp.text().await?;
751        let entity: Option<GetEtfsWorldRiskError> = serde_json::from_str(&content).ok();
752        Err(Error::ResponseError(ResponseContent { status, content, entity }))
753    }
754}
755
756/// 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.
757pub async fn get_etfs_world_summary(configuration: &configuration::Configuration, params: GetEtfsWorldSummaryParams) -> Result<models::GetEtfsWorldSummary200Response, Error<GetEtfsWorldSummaryError>> {
758    // Extract parameters from params struct
759    let p_query_symbol = params.symbol;
760    let p_query_figi = params.figi;
761    let p_query_isin = params.isin;
762    let p_query_cusip = params.cusip;
763    let p_query_country = params.country;
764    let p_query_dp = params.dp;
765
766    let uri_str = format!("{}/etfs/world/summary", configuration.base_path);
767    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
768
769    if let Some(ref param_value) = p_query_symbol {
770        req_builder = req_builder.query(&[("symbol", &param_value.to_string())]);
771    }
772    if let Some(ref param_value) = p_query_figi {
773        req_builder = req_builder.query(&[("figi", &param_value.to_string())]);
774    }
775    if let Some(ref param_value) = p_query_isin {
776        req_builder = req_builder.query(&[("isin", &param_value.to_string())]);
777    }
778    if let Some(ref param_value) = p_query_cusip {
779        req_builder = req_builder.query(&[("cusip", &param_value.to_string())]);
780    }
781    if let Some(ref param_value) = p_query_country {
782        req_builder = req_builder.query(&[("country", &param_value.to_string())]);
783    }
784    if let Some(ref param_value) = p_query_dp {
785        req_builder = req_builder.query(&[("dp", &param_value.to_string())]);
786    }
787    if let Some(ref user_agent) = configuration.user_agent {
788        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
789    }
790    if let Some(ref apikey) = configuration.api_key {
791        let key = apikey.key.clone();
792        let value = match apikey.prefix {
793            Some(ref prefix) => format!("{} {}", prefix, key),
794            None => key,
795        };
796        req_builder = req_builder.header("Authorization", value);
797    };
798
799    let req = req_builder.build()?;
800    let resp = configuration.client.execute(req).await?;
801
802    let status = resp.status();
803    let content_type = resp
804        .headers()
805        .get("content-type")
806        .and_then(|v| v.to_str().ok())
807        .unwrap_or("application/octet-stream");
808    let content_type = super::ContentType::from(content_type);
809
810    if !status.is_client_error() && !status.is_server_error() {
811        let content = resp.text().await?;
812        match content_type {
813            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
814            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetEtfsWorldSummary200Response`"))),
815            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::GetEtfsWorldSummary200Response`")))),
816        }
817    } else {
818        let content = resp.text().await?;
819        let entity: Option<GetEtfsWorldSummaryError> = serde_json::from_str(&content).ok();
820        Err(Error::ResponseError(ResponseContent { status, content, entity }))
821    }
822}
823