Files
sure/app/models/security/price.rb
soky srm 4dfd2913c7 Investment prices fixes (#559)
* Fix investments retrieval

     Problem Summary

     Stock prices for securities like European stocks become stale because:
     1. sync_all_accounts runs at 2:22 UTC (before European markets open)
     2. Provider doesn't have today's price yet, so importer gap-fills with LOCF (yesterday's price)
     3. Later import_market_data at 22:00 UTC sees all prices exist and skips fetching
     4. Real closing price is never retrieved

     Solution Overview

     Add a provisional boolean column to mark gap-filled prices that should be re-fetched.

* Update schema.rb

---------

Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
2026-01-07 16:16:01 +01:00

17 lines
640 B
Ruby

class Security::Price < ApplicationRecord
belongs_to :security
validates :date, :price, :currency, presence: true
validates :date, uniqueness: { scope: %i[security_id currency] }
# Provisional prices from recent weekdays that should be re-fetched
# - Must be provisional (gap-filled)
# - Must be from the last few days (configurable, default 3)
# - Must be a weekday (Saturday = 6, Sunday = 0 in PostgreSQL DOW)
scope :refetchable_provisional, ->(lookback_days: 3) {
where(provisional: true)
.where(date: lookback_days.days.ago.to_date..Date.current)
.where("EXTRACT(DOW FROM date) NOT IN (0, 6)")
}
end