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:
parent
e5eb69bdc7
commit
c2561b5fb4
1 changed files with 15 additions and 0 deletions
|
@ -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 ],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue