changed types might remove ticker info bc replaced by figi
This commit is contained in:
@@ -155,42 +155,6 @@ pub async fn build_figi_to_lei_map(lei_to_isins: &HashMap<String, Vec<String>>)
|
||||
Ok(figi_to_lei)
|
||||
}
|
||||
|
||||
/// Seed companies from hardcoded list (replaces get_tickers() + companies.json)
|
||||
fn get_seed_companies() -> Vec<CompanyMetadata> {
|
||||
vec![
|
||||
CompanyMetadata {
|
||||
lei: "549300JB8Z3P7D2X0Y43".to_string(), // JPMorgan (real LEI)
|
||||
figi: None,
|
||||
name: "JPMorgan Chase & Co.".to_string(),
|
||||
isins: vec!["US46625H1005".to_string()],
|
||||
primary_isin: "US46625H1005".to_string(),
|
||||
tickers: vec![TickerInfo {
|
||||
ticker: "JPM".to_string(),
|
||||
exchange_mic: "XNYS".to_string(),
|
||||
currency: "USD".to_string(),
|
||||
primary: true,
|
||||
}],
|
||||
},
|
||||
CompanyMetadata {
|
||||
lei: "549300MSFTN5VD1V2U95".to_string(), // Microsoft (real LEI)
|
||||
figi: None,
|
||||
name: "Microsoft Corporation".to_string(),
|
||||
isins: vec!["US5949181045".to_string()],
|
||||
primary_isin: "US5949181045".to_string(),
|
||||
tickers: vec![TickerInfo {
|
||||
ticker: "MSFT".to_string(),
|
||||
exchange_mic: "XNAS".to_string(),
|
||||
currency: "USD".to_string(),
|
||||
primary: true,
|
||||
}],
|
||||
},
|
||||
// Add the other 14 from your original companies.json here...
|
||||
// e.g., Industrial and Commercial Bank: lei="...", isins=["CNE000001P37"], tickers=[...]
|
||||
// Toyota: lei="...", etc.
|
||||
// Total: 16 seed companies
|
||||
]
|
||||
}
|
||||
|
||||
/// Load/build companies using FIGI as key (enriched with LEI via map)
|
||||
pub async fn load_or_build_companies_figi(
|
||||
lei_to_isins: &HashMap<String, Vec<String>>,
|
||||
@@ -200,42 +164,9 @@ pub async fn load_or_build_companies_figi(
|
||||
tokio::fs::create_dir_all(data_dir).await?;
|
||||
|
||||
let mut companies = Vec::new();
|
||||
let seed_companies = get_seed_companies();
|
||||
|
||||
for mut seed in seed_companies {
|
||||
// Enrich seed with all ISINs from LEI
|
||||
if let Some(all_isins) = lei_to_isins.get(&seed.lei) {
|
||||
let mut isins_set: HashSet<String> = seed.isins.iter().cloned().collect();
|
||||
isins_set.extend(all_isins.iter().cloned());
|
||||
seed.isins = isins_set.into_iter().collect();
|
||||
}
|
||||
|
||||
// Find primary FIGI (from primary ISIN or first equity FIGI)
|
||||
let primary_figi = if let Some(primary_isin) = seed.isins.first() {
|
||||
// Quick lookup or map via OpenFIGI if needed (stub—expand if no figi_to_lei hit)
|
||||
figi_to_lei
|
||||
.values()
|
||||
.find(|lei| lei.as_str() == seed.lei.as_str())
|
||||
.cloned()
|
||||
.unwrap_or_else(|| format!("FIGI{:019}", rand::random::<u64>()))
|
||||
} else {
|
||||
format!("FIGI{:019}", rand::random::<u64>())
|
||||
};
|
||||
|
||||
let company = CompanyMetadata {
|
||||
lei: seed.lei.clone(),
|
||||
figi: Some(primary_figi.clone()),
|
||||
name: seed.name.clone(),
|
||||
isins: seed.isins.clone(),
|
||||
primary_isin: seed.primary_isin.clone(),
|
||||
tickers: seed.tickers.clone(),
|
||||
};
|
||||
|
||||
let company_path = data_dir.join(format!("{}.json", primary_figi));
|
||||
tokio::fs::write(&company_path, serde_json::to_string_pretty(&company)?).await?;
|
||||
companies.push(company);
|
||||
}
|
||||
|
||||
println!("Built {} FIGI-keyed companies from seed", companies.len());
|
||||
println!("Built {} FIGI-keyed companies.", companies.len());
|
||||
Ok(companies)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ pub struct TickerInfo {
|
||||
pub ticker: String,
|
||||
pub exchange_mic: String,
|
||||
pub currency: String,
|
||||
pub primary: bool,
|
||||
pub isin: String, // ISIN belonging to this legal entity (primary + ADR + GDR)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -52,7 +52,6 @@ pub struct CompanyMetadata {
|
||||
pub lei: String,
|
||||
pub figi: Option<String>,
|
||||
pub name: String,
|
||||
pub isins: Vec<String>, // All ISINs belonging to this legal entity (primary + ADR + GDR)
|
||||
pub primary_isin: String, // The most liquid / preferred one (used for folder fallback)
|
||||
pub tickers: Vec<TickerInfo>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user