finance_query/models/currencies/
response.rs

1//! Currency Response Model
2//!
3//! Represents currency information from Yahoo Finance
4
5use serde::{Deserialize, Serialize};
6
7/// A single currency with its properties
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[cfg_attr(feature = "dataframe", derive(crate::ToDataFrame))]
10#[serde(rename_all = "camelCase")]
11#[non_exhaustive]
12pub struct Currency {
13    /// Short name (e.g., "USD/EUR")
14    pub short_name: Option<String>,
15    /// Long name (e.g., "USD/EUR")
16    pub long_name: Option<String>,
17    /// Symbol (e.g., "USDEUR=X")
18    pub symbol: Option<String>,
19    /// Local long name
20    pub local_long_name: Option<String>,
21}
22
23/// Raw response from currencies endpoint
24#[derive(Debug, Clone, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub(crate) struct RawCurrenciesResponse {
27    pub currencies: Option<CurrenciesResult>,
28}
29
30#[derive(Debug, Clone, Deserialize)]
31#[serde(rename_all = "camelCase")]
32pub(crate) struct CurrenciesResult {
33    pub result: Option<Vec<Currency>>,
34}
35
36impl Currency {
37    /// Parse currencies from the raw JSON response
38    pub(crate) fn from_response(value: serde_json::Value) -> Result<Vec<Self>, serde_json::Error> {
39        let raw: RawCurrenciesResponse = serde_json::from_value(value)?;
40        Ok(raw.currencies.and_then(|c| c.result).unwrap_or_default())
41    }
42}