First pass at security price reference (#1388)

* First pass at security price reference

* Data cleanup

* Synth security fetching does better with a mic_code

* Update test suite

😭

* Update schema.rb

* Update generator.rb
This commit is contained in:
Josh Pigford
2024-10-29 15:37:59 -04:00
committed by GitHub
parent bf695972e4
commit 490f44589e
16 changed files with 155 additions and 88 deletions

View File

@@ -6,17 +6,18 @@ module Security::Price::Provided
class_methods do
private
def fetch_price_from_provider(ticker:, date:, cache: false)
def fetch_price_from_provider(security:, date:, cache: false)
return nil unless security_prices_provider.present?
response = security_prices_provider.fetch_security_prices \
ticker: ticker,
ticker: security.ticker,
mic_code: security.exchange_mic,
start_date: date,
end_date: date
if response.success? && response.prices.size > 0
price = Security::Price.new \
ticker: ticker,
security: security,
date: response.prices.first[:date],
price: response.prices.first[:price],
currency: response.prices.first[:currency]
@@ -28,18 +29,20 @@ module Security::Price::Provided
end
end
def fetch_prices_from_provider(ticker:, start_date:, end_date:, cache: false)
def fetch_prices_from_provider(security:, start_date:, end_date:, cache: false)
return [] unless security_prices_provider.present?
return [] unless security
response = security_prices_provider.fetch_security_prices \
ticker: ticker,
ticker: security.ticker,
mic_code: security.exchange_mic,
start_date: start_date,
end_date: end_date
if response.success?
response.prices.map do |price|
new_price = Security::Price.find_or_initialize_by(
ticker: ticker,
security: security,
date: price[:date]
) do |p|
p.price = price[:price]