The personal finance app for everyone
Handle market holidays during holding sync (#1292)
Zach Gollwitzer3399b748493f
diff --git a/Gemfile b/Gemfileindex 9c97c3e9..cdb9fca0 100644--- a/Gemfile+++ b/Gemfile@@ -48,6 +48,7 @@ gem "csv"gem "redcarpet"gem "stripe"gem "intercom-rails"+gem "holidays"group :development, :test dogem "debug", platforms: %i[mri windows]diff --git a/Gemfile.lock b/Gemfile.lockindex 81a4b742..155b548a 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -183,6 +183,7 @@ GEMthor (>= 1.0.0)hashdiff (1.1.1)highline (3.0.1)+ holidays (8.8.0)hotwire-livereload (1.4.1)actioncable (>= 6.0.0)listen (>= 3.0.0)@@ -486,6 +487,7 @@ DEPENDENCIESfaraday-multipartfaraday-retrygood_job+ holidayshotwire-livereloadi18n-tasksimage_processing (>= 1.2)diff --git a/app/models/gapfiller.rb b/app/models/gapfiller.rbindex a7870c1b..ba8a57f4 100644--- a/app/models/gapfiller.rb+++ b/app/models/gapfiller.rb@@ -32,7 +32,11 @@ class Gapfillerattr_reader :date_range, :cachedef should_gapfill?(date, record)- date.on_weekend? && record.nil?+ (date.on_weekend? || holiday?(date)) && record.nil?+ end++ def holiday?(date)+ Holidays.on(date, :federalreserve, :us, :informal).any?enddef create_gapfilled_record(prev_record, date)diff --git a/app/models/security/price/provided.rb b/app/models/security/price/provided.rbindex 1523cba8..599f19ff 100644--- a/app/models/security/price/provided.rb+++ b/app/models/security/price/provided.rb@@ -38,13 +38,15 @@ module Security::Price::Providedif response.success?response.prices.map do |price|- new_price = Security::Price.new \+ new_price = Security::Price.find_or_initialize_by(ticker: ticker,- date: price[:date],- price: price[:price],- currency: price[:currency]+ date: price[:date]+ ) do |p|+ p.price = price[:price]+ p.currency = price[:currency]+ end- new_price.save! if cache+ new_price.save! if cache && new_price.new_record?new_priceendelse