twelve_data_client/models/
quote.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 crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
15pub struct Quote {
16    /// Symbol passed
17    #[serde(rename = "symbol", skip_serializing_if = "Option::is_none")]
18    pub symbol: Option<String>,
19    /// Name of the instrument
20    #[serde(rename = "name", skip_serializing_if = "Option::is_none")]
21    pub name: Option<String>,
22    /// Exchange where instrument is traded
23    #[serde(rename = "exchange", skip_serializing_if = "Option::is_none")]
24    pub exchange: Option<String>,
25    /// Market identifier code (MIC) under ISO 10383 standard. Available for stocks, ETFs, mutual funds, bonds
26    #[serde(rename = "mic_code", skip_serializing_if = "Option::is_none")]
27    pub mic_code: Option<String>,
28    /// Currency in which the equity is denominated. Available for stocks, ETFs, mutual funds, bonds
29    #[serde(rename = "currency", skip_serializing_if = "Option::is_none")]
30    pub currency: Option<String>,
31    /// Datetime in defined timezone referring to when the bar with specified interval was opened
32    #[serde(rename = "datetime", skip_serializing_if = "Option::is_none")]
33    pub datetime: Option<String>,
34    /// Unix timestamp representing the opening candle of the specified interval
35    #[serde(rename = "timestamp", skip_serializing_if = "Option::is_none")]
36    pub timestamp: Option<i64>,
37    /// Unix timestamp of last minute candle
38    #[serde(rename = "last_quote_at", skip_serializing_if = "Option::is_none")]
39    pub last_quote_at: Option<i64>,
40    /// Price at the opening of current bar
41    #[serde(rename = "open", skip_serializing_if = "Option::is_none")]
42    pub open: Option<String>,
43    /// Highest price which occurred during the current bar
44    #[serde(rename = "high", skip_serializing_if = "Option::is_none")]
45    pub high: Option<String>,
46    /// Lowest price which occurred during the current bar
47    #[serde(rename = "low", skip_serializing_if = "Option::is_none")]
48    pub low: Option<String>,
49    /// Close price at the end of the bar
50    #[serde(rename = "close", skip_serializing_if = "Option::is_none")]
51    pub close: Option<String>,
52    /// Trading volume during the bar. Available not for all instrument types
53    #[serde(rename = "volume", skip_serializing_if = "Option::is_none")]
54    pub volume: Option<String>,
55    /// Close price at the end of the previous bar
56    #[serde(rename = "previous_close", skip_serializing_if = "Option::is_none")]
57    pub previous_close: Option<String>,
58    /// Close - previous_close
59    #[serde(rename = "change", skip_serializing_if = "Option::is_none")]
60    pub change: Option<String>,
61    /// (Close - previous_close) / previous_close * 100
62    #[serde(rename = "percent_change", skip_serializing_if = "Option::is_none")]
63    pub percent_change: Option<String>,
64    /// Average volume of the specified period. Available not for all instrument types
65    #[serde(rename = "average_volume", skip_serializing_if = "Option::is_none")]
66    pub average_volume: Option<String>,
67    /// Percent change in price between the current and the backward one, where period is 1 day. Available for crypto
68    #[serde(rename = "rolling_1d_change", skip_serializing_if = "Option::is_none")]
69    pub rolling_1d_change: Option<String>,
70    /// Percent change in price between the current and the backward one, where period is 7 days. Available for crypto
71    #[serde(rename = "rolling_7d_change", skip_serializing_if = "Option::is_none")]
72    pub rolling_7d_change: Option<String>,
73    /// Percent change in price between the current and the backward one, where period specified in request param rolling_period. Available for crypto
74    #[serde(rename = "rolling_change", skip_serializing_if = "Option::is_none")]
75    pub rolling_change: Option<String>,
76    /// True if market is open; false if closed
77    #[serde(rename = "is_market_open", skip_serializing_if = "Option::is_none")]
78    pub is_market_open: Option<bool>,
79    #[serde(rename = "fifty_two_week", skip_serializing_if = "Option::is_none")]
80    pub fifty_two_week: Option<Box<models::QuoteFiftyTwoWeek>>,
81    /// Diff between the regular close price and the latest extended price. Displayed only if prepost is true
82    #[serde(rename = "extended_change", skip_serializing_if = "Option::is_none")]
83    pub extended_change: Option<String>,
84    /// Percent change in price between the regular close price and the latest extended price. Displayed only if prepost is true
85    #[serde(
86        rename = "extended_percent_change",
87        skip_serializing_if = "Option::is_none"
88    )]
89    pub extended_percent_change: Option<String>,
90    /// Latest extended price. Displayed only if prepost is true
91    #[serde(rename = "extended_price", skip_serializing_if = "Option::is_none")]
92    pub extended_price: Option<String>,
93    /// Unix timestamp of the last extended price. Displayed only if prepost is true
94    #[serde(rename = "extended_timestamp", skip_serializing_if = "Option::is_none")]
95    pub extended_timestamp: Option<String>,
96}
97
98impl Quote {
99    pub fn new() -> Quote {
100        Quote {
101            symbol: None,
102            name: None,
103            exchange: None,
104            mic_code: None,
105            currency: None,
106            datetime: None,
107            timestamp: None,
108            last_quote_at: None,
109            open: None,
110            high: None,
111            low: None,
112            close: None,
113            volume: None,
114            previous_close: None,
115            change: None,
116            percent_change: None,
117            average_volume: None,
118            rolling_1d_change: None,
119            rolling_7d_change: None,
120            rolling_change: None,
121            is_market_open: None,
122            fifty_two_week: None,
123            extended_change: None,
124            extended_percent_change: None,
125            extended_price: None,
126            extended_timestamp: None,
127        }
128    }
129}