1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-04 21:15:19 +02:00

Use Synth for exchange rates (#514)

* Switch currency seeding over to Synth

* Switch all exchange rates over to Synth
This commit is contained in:
Josh Pigford 2024-03-04 10:26:20 -06:00 committed by GitHub
parent 0f2c41477d
commit 4843cf22c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 84 deletions

View file

@ -2,8 +2,6 @@ class DailyExchangeRateJob < ApplicationJob
queue_as :default
def perform
app_id = ENV["OPEN_EXCHANGE_APP_ID"]
# Get the last date for which exchange rates were fetched for each currency
last_fetched_dates = ExchangeRate.group(:base_currency).maximum(:date)
@ -11,10 +9,12 @@ class DailyExchangeRateJob < ApplicationJob
Currency.all.each do |currency|
last_fetched_date = last_fetched_dates[currency.iso_code] || Date.yesterday
next_day = last_fetched_date + 1.day
response = Faraday.get("https://openexchangerates.org/api/historical/#{next_day}.json") do |req|
req.params["app_id"] = app_id
req.params["base"] = currency.iso_code
req.params["symbols"] = Currency.where.not(iso_code: currency.iso_code).pluck(:iso_code).join(",")
response = Faraday.get("https://api.synthfinance.com/rates/historical") do |req|
req.headers["Authorization"] = "Bearer #{ENV["SYNTH_API_KEY"]}"
req.params["date"] = next_day.to_s
req.params["from"] = currency.iso_code
req.params["to"] = Currency.where.not(iso_code: currency.iso_code).pluck(:iso_code).join(",")
end
if response.success?