mirror of
https://github.com/we-promise/sure.git
synced 2026-04-20 12:34:12 +00:00
Fetch reciprocal exchange rates when syncing market data (#358)
* Fetch reciprocal exchange rates in sync * Fix variable
This commit is contained in:
@@ -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|
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user