1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 22:29:38 +02:00

Handle manually entered securities

This commit is contained in:
Josh Pigford 2024-10-28 13:33:27 -04:00
parent e5eb69bdc7
commit c2561b5fb4

View file

@ -21,6 +21,21 @@ class Security::Importer
.compact .compact
.uniq { |security| [ security[:ticker], security[:exchange_mic] ] } .uniq { |security| [ security[:ticker], security[:exchange_mic] ] }
# First update any existing securities that only have a ticker
Security.where(exchange_mic: nil)
.where(ticker: securities_to_create.map { |s| s[:ticker] })
.update_all(
securities_to_create.map do |security|
{
name: security[:name],
country_code: security[:country_code],
exchange_mic: security[:exchange_mic],
exchange_acronym: security[:exchange_acronym]
}
end.first
)
# Then create/update any remaining securities
Security.upsert_all( Security.upsert_all(
securities_to_create, securities_to_create,
unique_by: [ :ticker, :exchange_mic ], unique_by: [ :ticker, :exchange_mic ],