2025-05-16 14:17:56 -04:00
|
|
|
# This job runs daily at market close. See config/schedule.yml for details.
|
|
|
|
#
|
|
|
|
# The primary purpose of this job is to:
|
|
|
|
# 1. Determine what exchange rate pairs, security prices, and other market data all of our users need to view historical account balance data
|
|
|
|
# 2. For each needed rate/price, fetch from our data provider and upsert to our database
|
|
|
|
#
|
|
|
|
# Each individual account sync will still fetch any missing market data that isn't yet synced, but by running
|
|
|
|
# this job daily, we significantly reduce overlapping account syncs that both need the same market data (e.g. common security like `AAPL`)
|
|
|
|
#
|
2025-05-17 16:37:16 -04:00
|
|
|
class ImportMarketDataJob < ApplicationJob
|
2025-05-15 10:19:56 -04:00
|
|
|
queue_as :scheduled
|
|
|
|
|
2025-05-16 14:17:56 -04:00
|
|
|
def perform(opts)
|
2025-06-20 13:31:58 -04:00
|
|
|
return if Rails.env.development?
|
|
|
|
|
2025-05-16 14:17:56 -04:00
|
|
|
opts = opts.symbolize_keys
|
|
|
|
mode = opts.fetch(:mode, :full)
|
|
|
|
clear_cache = opts.fetch(:clear_cache, false)
|
|
|
|
|
2025-05-17 16:37:16 -04:00
|
|
|
MarketDataImporter.new(mode: mode, clear_cache: clear_cache).import_all
|
2025-05-15 10:19:56 -04:00
|
|
|
end
|
|
|
|
end
|