finance_query/models/discovery/figi.rs
1//! Security-identifier mapping models.
2//!
3//! Populated by the OpenFIGI adapter, which resolves a CUSIP, ISIN, SEDOL, or
4//! FIGI to the instruments carrying it.
5
6use serde::{Deserialize, Serialize};
7
8/// One instrument matching a security identifier.
9///
10/// A single CUSIP or ISIN maps to **many** instruments — one per venue the
11/// security trades on — which is why resolution returns a list. Entries that
12/// share a `composite_figi` are the same security on different venues; the
13/// `share_class_figi` groups share classes across countries.
14///
15/// Obtain via [`openfigi::resolve_cusip`](crate::openfigi::resolve_cusip) and
16/// friends.
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19#[non_exhaustive]
20pub struct SecurityMapping {
21 /// The instrument's Financial Instrument Global Identifier.
22 pub figi: String,
23 /// Ticker symbol, as the venue lists it.
24 pub ticker: Option<String>,
25 /// Security name (usually the issuer).
26 pub name: Option<String>,
27 /// Exchange code — `"US"` for the composite, otherwise a venue code.
28 pub exchange_code: Option<String>,
29 /// FIGI of the country-level composite this instrument rolls up to.
30 pub composite_figi: Option<String>,
31 /// FIGI shared by every listing of this share class worldwide.
32 pub share_class_figi: Option<String>,
33 /// Instrument type, e.g. `"Common Stock"`, `"ETP"`.
34 pub security_type: Option<String>,
35 /// Market sector, e.g. `"Equity"`, `"Corp"`, `"Govt"`.
36 pub market_sector: Option<String>,
37}
38
39/// The kind of identifier being resolved.
40///
41/// Maps onto OpenFIGI's `idType` values.
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
43#[non_exhaustive]
44pub enum SecurityIdKind {
45 /// North American security identifier (9 characters).
46 Cusip,
47 /// International Securities Identification Number (12 characters).
48 Isin,
49 /// UK/Ireland security identifier (7 characters).
50 Sedol,
51 /// A FIGI, resolved to its siblings.
52 Figi,
53 /// Exchange ticker symbol.
54 Ticker,
55}
56
57impl SecurityIdKind {
58 /// The `idType` string OpenFIGI expects.
59 pub fn as_str(self) -> &'static str {
60 match self {
61 Self::Cusip => "ID_CUSIP",
62 Self::Isin => "ID_ISIN",
63 Self::Sedol => "ID_SEDOL",
64 Self::Figi => "ID_BB_GLOBAL",
65 Self::Ticker => "TICKER",
66 }
67 }
68}
69
70impl std::fmt::Display for SecurityIdKind {
71 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72 f.write_str(self.as_str())
73 }
74}