mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Handle manually entered securities
This commit is contained in:
@@ -21,6 +21,21 @@ class Security::Importer
|
||||
.compact
|
||||
.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(
|
||||
securities_to_create,
|
||||
unique_by: [ :ticker, :exchange_mic ],
|
||||
|
||||
Reference in New Issue
Block a user