mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 14:19:39 +02:00
* Don't append missing prices if already known * Add failing test * Handle weekend stock prices * Fix tests and gapfill logic
33 lines
837 B
Ruby
33 lines
837 B
Ruby
class Issue::PricesMissing < Issue
|
|
store_accessor :data, :missing_prices
|
|
|
|
after_initialize :initialize_missing_prices
|
|
|
|
validates :missing_prices, presence: true, allow_blank: true
|
|
|
|
def append_missing_price(ticker, date)
|
|
missing_prices[ticker] ||= []
|
|
missing_prices[ticker] << date unless missing_prices[ticker].include?(date.to_s)
|
|
end
|
|
|
|
def stale?
|
|
stale = true
|
|
|
|
missing_prices.each do |ticker, dates|
|
|
next unless issuable.owns_ticker?(ticker)
|
|
|
|
oldest_date = dates.min.to_date
|
|
expected_price_count = (oldest_date..Date.current).count
|
|
prices = Security::Price.find_prices(ticker: ticker, start_date: oldest_date)
|
|
stale = false if prices.count < expected_price_count
|
|
end
|
|
|
|
stale
|
|
end
|
|
|
|
private
|
|
|
|
def initialize_missing_prices
|
|
self.missing_prices ||= {}
|
|
end
|
|
end
|