Fetch reciprocal exchange rates when syncing market data (#358)

* Fetch reciprocal exchange rates in sync

* Fix variable
This commit is contained in:
Jakub Kottnauer
2025-11-20 19:50:22 +01:00
committed by GitHub
parent 6decd6eaca
commit e50a5792a0
4 changed files with 48 additions and 2 deletions

View File

@@ -24,12 +24,18 @@ class Account::MarketDataImporter
.each do |source_currency, date|
key = [ source_currency, account.currency ]
pair_dates[key] = [ pair_dates[key], date ].compact.min
inverse_key = [ account.currency, source_currency ]
pair_dates[inverse_key] = [ pair_dates[inverse_key], date ].compact.min
end
# 2. ACCOUNT-BASED PAIR convert the account currency to the family currency (if different)
if foreign_account?
key = [ account.currency, account.family.currency ]
pair_dates[key] = [ pair_dates[key], account.start_date ].compact.min
inverse_key = [ account.family.currency, account.currency ]
pair_dates[inverse_key] = [ pair_dates[inverse_key], account.start_date ].compact.min
end
pair_dates.each do |(source, target), start_date|

View File

@@ -76,6 +76,9 @@ class MarketDataImporter
.each do |(source, target), date|
key = [ source, target ]
pair_dates[key] = [ pair_dates[key], date ].compact.min
inverse_key = [ target, source ]
pair_dates[inverse_key] = [ pair_dates[inverse_key], date ].compact.min
end
# 2. ACCOUNT-BASED PAIRS use the account's oldest entry date
@@ -91,6 +94,9 @@ class MarketDataImporter
key = [ account.source, account.target ]
pair_dates[key] = [ pair_dates[key], chosen_date ].compact.min
inverse_key = [ account.target, account.source ]
pair_dates[inverse_key] = [ pair_dates[inverse_key], chosen_date ].compact.min
end
# Convert to array of hashes for ease of use