diff --git a/app/models/account/trade_builder.rb b/app/models/account/trade_builder.rb index d28c508e..e174a5c2 100644 --- a/app/models/account/trade_builder.rb +++ b/app/models/account/trade_builder.rb @@ -31,12 +31,10 @@ class Account::TradeBuilder < Account::EntryBuilder end def security - exchange_acronym = ticker.match(/\((.*?)\)/)&.captures&.first + exchange_mic = ticker.match(/\((.*?)\)/)&.captures&.first ticker_symbol = ticker.gsub(/\s*\(.*?\)\s*/, "") - exchange = StockExchange.find_by(acronym: exchange_acronym) - - Security.find_or_create_by(ticker: ticker_symbol, exchange_mic: exchange.mic) + Security.find_or_create_by(ticker: ticker_symbol, exchange_mic: exchange_mic) end def amount diff --git a/app/models/provider/synth.rb b/app/models/provider/synth.rb index e610bd44..2fd94f31 100644 --- a/app/models/provider/synth.rb +++ b/app/models/provider/synth.rb @@ -136,7 +136,8 @@ class Provider::Synth symbol: security.dig("symbol"), name: security.dig("name"), logo_url: security.dig("logo_url"), - exchange_acronym: security.dig("exchange", "acronym") + exchange_acronym: security.dig("exchange", "acronym"), + exchange_mic: security.dig("exchange", "mic") } end diff --git a/app/models/security/synth_combobox_option.rb b/app/models/security/synth_combobox_option.rb index 09bde82d..9b9b727a 100644 --- a/app/models/security/synth_combobox_option.rb +++ b/app/models/security/synth_combobox_option.rb @@ -1,19 +1,17 @@ class Security::SynthComboboxOption include ActiveModel::Model + include Providable - attr_accessor :symbol, :name, :logo_url, :exchange_acronym + attr_accessor :symbol, :name, :logo_url, :exchange_acronym, :exchange_mic class << self def find_in_synth(query) - Provider::Synth.new(ENV["SYNTH_API_KEY"]) - .search_securities(query:, dataset: "limited", country_code: Current.family.country) - .securities - .map { |attrs| new(**attrs) } + security_prices_provider.search_securities(query:, dataset: "limited", country_code: Current.family.country).securities.map { |attrs| new(**attrs) } end end def id - "#{symbol} (#{exchange_acronym})" # submitted by combobox as value + "#{symbol} (#{exchange_mic})" # submitted by combobox as value end def to_combobox_display