Make direct use of mic codes

This commit is contained in:
Josh Pigford
2024-10-30 08:37:17 -04:00
parent 4a3c331e20
commit d5163c4547
3 changed files with 8 additions and 11 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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