mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 06:55:21 +02:00
More reference replacements
This commit is contained in:
parent
7a1f10ec6e
commit
5f97faecbe
12 changed files with 36 additions and 36 deletions
|
@ -7,7 +7,7 @@
|
|||
# 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`)
|
||||
#
|
||||
class SyncMarketDataJob < ApplicationJob
|
||||
class ImportMarketDataJob < ApplicationJob
|
||||
queue_as :scheduled
|
||||
|
||||
def perform(opts)
|
|
@ -33,7 +33,7 @@ class Account::MarketDataImporter
|
|||
end
|
||||
|
||||
pair_dates.each do |(source, target), start_date|
|
||||
ExchangeRate.sync_provider_rates(
|
||||
ExchangeRate.import_provider_rates(
|
||||
from: source,
|
||||
to: target,
|
||||
start_date: start_date,
|
||||
|
@ -50,12 +50,12 @@ class Account::MarketDataImporter
|
|||
return if account_securities.empty?
|
||||
|
||||
account_securities.each do |security|
|
||||
security.sync_provider_prices(
|
||||
security.import_provider_prices(
|
||||
start_date: first_required_price_date(security),
|
||||
end_date: Date.current
|
||||
)
|
||||
|
||||
security.sync_provider_details
|
||||
security.import_provider_details
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ class Account::Syncer
|
|||
|
||||
def perform_sync(sync)
|
||||
Rails.logger.info("Processing balances (#{account.linked? ? 'reverse' : 'forward'})")
|
||||
sync_market_data
|
||||
sync_balances
|
||||
import_market_data
|
||||
materialize_balances
|
||||
end
|
||||
|
||||
def perform_post_sync
|
||||
|
@ -16,9 +16,9 @@ class Account::Syncer
|
|||
end
|
||||
|
||||
private
|
||||
def sync_balances
|
||||
def materialize_balances
|
||||
strategy = account.linked? ? :reverse : :forward
|
||||
Balance::Syncer.new(account, strategy: strategy).sync_balances
|
||||
Balance::Materializer.new(account, strategy: strategy).materialize_balances
|
||||
end
|
||||
|
||||
# Syncs all the exchange rates + security prices this account needs to display historical chart data
|
||||
|
@ -28,7 +28,7 @@ class Account::Syncer
|
|||
#
|
||||
# We rescue errors here because if this operation fails, we don't want to fail the entire sync since
|
||||
# we have reasonable fallbacks for missing market data.
|
||||
def sync_market_data
|
||||
def import_market_data
|
||||
Account::MarketDataImporter.new(account).import_all
|
||||
rescue => e
|
||||
Rails.logger.error("Error syncing market data for account #{account.id}: #{e.message}")
|
||||
|
|
|
@ -12,7 +12,7 @@ class ExchangeRate::Importer
|
|||
end
|
||||
|
||||
# Constructs a daily series of rates for the given currency pair for date range
|
||||
def sync_provider_rates
|
||||
def import_provider_rates
|
||||
if !clear_cache && all_rates_exist?
|
||||
Rails.logger.info("No new rates to sync for #{from} to #{to} between #{start_date} and #{end_date}, skipping")
|
||||
return
|
||||
|
|
|
@ -28,9 +28,9 @@ module ExchangeRate::Provided
|
|||
end
|
||||
|
||||
# @return [Integer] The number of exchange rates synced
|
||||
def sync_provider_rates(from:, to:, start_date:, end_date:, clear_cache: false)
|
||||
def import_provider_rates(from:, to:, start_date:, end_date:, clear_cache: false)
|
||||
unless provider.present?
|
||||
Rails.logger.warn("No provider configured for ExchangeRate.sync_provider_rates")
|
||||
Rails.logger.warn("No provider configured for ExchangeRate.import_provider_rates")
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -41,7 +41,7 @@ module ExchangeRate::Provided
|
|||
start_date: start_date,
|
||||
end_date: end_date,
|
||||
clear_cache: clear_cache
|
||||
).sync_provider_rates
|
||||
).import_provider_rates
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,13 +23,13 @@ class MarketDataImporter
|
|||
end
|
||||
|
||||
Security.where.not(exchange_operating_mic: nil).find_each do |security|
|
||||
security.sync_provider_prices(
|
||||
security.import_provider_prices(
|
||||
start_date: get_first_required_price_date(security),
|
||||
end_date: end_date,
|
||||
clear_cache: clear_cache
|
||||
)
|
||||
|
||||
security.sync_provider_details(clear_cache: clear_cache)
|
||||
security.import_provider_details(clear_cache: clear_cache)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ class MarketDataImporter
|
|||
# pair is a Hash with keys :source, :target, and :start_date
|
||||
start_date = snapshot? ? default_start_date : pair[:start_date]
|
||||
|
||||
ExchangeRate.sync_provider_rates(
|
||||
ExchangeRate.import_provider_rates(
|
||||
from: pair[:source],
|
||||
to: pair[:target],
|
||||
start_date: start_date,
|
||||
|
|
|
@ -12,7 +12,7 @@ class Security::Price::Importer
|
|||
|
||||
# Constructs a daily series of prices for a single security over the date range.
|
||||
# Returns the number of rows upserted.
|
||||
def sync_provider_prices
|
||||
def import_provider_prices
|
||||
if !clear_cache && all_prices_exist?
|
||||
Rails.logger.info("No new prices to sync for #{security.ticker} between #{start_date} and #{end_date}, skipping")
|
||||
return 0
|
||||
|
|
|
@ -49,9 +49,9 @@ module Security::Provided
|
|||
price
|
||||
end
|
||||
|
||||
def sync_provider_details(clear_cache: false)
|
||||
def import_provider_details(clear_cache: false)
|
||||
unless provider.present?
|
||||
Rails.logger.warn("No provider configured for Security.sync_provider_details")
|
||||
Rails.logger.warn("No provider configured for Security.import_provider_details")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -76,9 +76,9 @@ module Security::Provided
|
|||
end
|
||||
end
|
||||
|
||||
def sync_provider_prices(start_date:, end_date:, clear_cache: false)
|
||||
def import_provider_prices(start_date:, end_date:, clear_cache: false)
|
||||
unless provider.present?
|
||||
Rails.logger.warn("No provider configured for Security.sync_provider_prices")
|
||||
Rails.logger.warn("No provider configured for Security.import_provider_prices")
|
||||
return 0
|
||||
end
|
||||
|
||||
|
@ -88,7 +88,7 @@ module Security::Provided
|
|||
start_date: start_date,
|
||||
end_date: end_date,
|
||||
clear_cache: clear_cache
|
||||
).sync_provider_prices
|
||||
).import_provider_prices
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
sync_market_data:
|
||||
import_market_data:
|
||||
cron: "0 22 * * 1-5" # 5:00 PM EST / 6:00 PM EDT (NY time)
|
||||
class: "SyncMarketDataJob"
|
||||
class: "ImportMarketDataJob"
|
||||
queue: "scheduled"
|
||||
description: "Syncs market data daily at 5:00 PM EST (1 hour after market close)"
|
||||
description: "Imports market data daily at 5:00 PM EST (1 hour after market close)"
|
||||
args:
|
||||
mode: "full"
|
||||
clear_cache: false
|
||||
|
|
|
@ -32,7 +32,7 @@ class Account::MarketDataImporterTest < ActiveSupport::TestCase
|
|||
accountable: Depository.new
|
||||
)
|
||||
|
||||
# Seed a rate for the first required day so that the syncer only needs the next day forward
|
||||
# Seed a rate for the first required day so that the importer only needs the next day forward
|
||||
existing_date = account.start_date
|
||||
ExchangeRate.create!(from_currency: "CAD", to_currency: "USD", date: existing_date, rate: 2.0)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class ExchangeRate::ImporterTest < ActiveSupport::TestCase
|
|||
to: "EUR",
|
||||
start_date: 2.days.ago.to_date,
|
||||
end_date: Date.current
|
||||
).sync_provider_rates
|
||||
).import_provider_rates
|
||||
|
||||
db_rates = ExchangeRate.where(from_currency: "USD", to_currency: "EUR", date: 2.days.ago.to_date..Date.current)
|
||||
.order(:date)
|
||||
|
@ -59,7 +59,7 @@ class ExchangeRate::ImporterTest < ActiveSupport::TestCase
|
|||
to: "EUR",
|
||||
start_date: 3.days.ago.to_date,
|
||||
end_date: Date.current
|
||||
).sync_provider_rates
|
||||
).import_provider_rates
|
||||
|
||||
db_rates = ExchangeRate.order(:date)
|
||||
assert_equal 4, db_rates.count
|
||||
|
@ -81,7 +81,7 @@ class ExchangeRate::ImporterTest < ActiveSupport::TestCase
|
|||
to: "EUR",
|
||||
start_date: 3.days.ago.to_date,
|
||||
end_date: Date.current
|
||||
).sync_provider_rates
|
||||
).import_provider_rates
|
||||
end
|
||||
|
||||
# A helpful "reset" option for when we need to refresh provider data
|
||||
|
@ -110,7 +110,7 @@ class ExchangeRate::ImporterTest < ActiveSupport::TestCase
|
|||
start_date: 2.days.ago.to_date,
|
||||
end_date: Date.current,
|
||||
clear_cache: true
|
||||
).sync_provider_rates
|
||||
).import_provider_rates
|
||||
|
||||
db_rates = ExchangeRate.where(from_currency: "USD", to_currency: "EUR").order(:date)
|
||||
assert_equal [ 1.3, 1.4, 1.5 ], db_rates.map(&:rate)
|
||||
|
@ -135,7 +135,7 @@ class ExchangeRate::ImporterTest < ActiveSupport::TestCase
|
|||
to: "EUR",
|
||||
start_date: Date.current,
|
||||
end_date: future_date
|
||||
).sync_provider_rates
|
||||
).import_provider_rates
|
||||
|
||||
assert_equal 1, ExchangeRate.count
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ class Security::Price::ImporterTest < ActiveSupport::TestCase
|
|||
security_provider: @provider,
|
||||
start_date: 2.days.ago.to_date,
|
||||
end_date: Date.current
|
||||
).sync_provider_prices
|
||||
).import_provider_prices
|
||||
|
||||
db_prices = Security::Price.where(security: @security, date: 2.days.ago.to_date..Date.current).order(:date)
|
||||
|
||||
|
@ -57,7 +57,7 @@ class Security::Price::ImporterTest < ActiveSupport::TestCase
|
|||
security_provider: @provider,
|
||||
start_date: 3.days.ago.to_date,
|
||||
end_date: Date.current
|
||||
).sync_provider_prices
|
||||
).import_provider_prices
|
||||
|
||||
db_prices = Security::Price.where(security: @security).order(:date)
|
||||
assert_equal 4, db_prices.count
|
||||
|
@ -78,7 +78,7 @@ class Security::Price::ImporterTest < ActiveSupport::TestCase
|
|||
security_provider: @provider,
|
||||
start_date: 3.days.ago.to_date,
|
||||
end_date: Date.current
|
||||
).sync_provider_prices
|
||||
).import_provider_prices
|
||||
end
|
||||
|
||||
test "full upsert if clear_cache is true" do
|
||||
|
@ -106,7 +106,7 @@ class Security::Price::ImporterTest < ActiveSupport::TestCase
|
|||
start_date: 2.days.ago.to_date,
|
||||
end_date: Date.current,
|
||||
clear_cache: true
|
||||
).sync_provider_prices
|
||||
).import_provider_prices
|
||||
|
||||
db_prices = Security::Price.where(security: @security).order(:date)
|
||||
assert_equal [ 150, 155, 160 ], db_prices.map(&:price)
|
||||
|
@ -131,7 +131,7 @@ class Security::Price::ImporterTest < ActiveSupport::TestCase
|
|||
security_provider: @provider,
|
||||
start_date: Date.current,
|
||||
end_date: future_date
|
||||
).sync_provider_prices
|
||||
).import_provider_prices
|
||||
|
||||
assert_equal 1, Security::Price.count
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue