mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Plaid sync tests and multi-currency investment support (#1531)
* Plaid sync tests and multi-currency investment support * Fix system test * Cleanup * Remove data migration
This commit is contained in:
parent
b2a56aefc1
commit
800eb4c146
21 changed files with 406 additions and 165 deletions
|
@ -134,10 +134,12 @@ class Provider::Plaid
|
|||
|
||||
def get_item_investments(item, start_date: nil, end_date: Date.current)
|
||||
start_date = start_date || MAX_HISTORY_DAYS.days.ago.to_date
|
||||
holdings = get_item_holdings(item)
|
||||
transactions, securities = get_item_investment_transactions(item, start_date:, end_date:)
|
||||
holdings, holding_securities = get_item_holdings(item)
|
||||
transactions, transaction_securities = get_item_investment_transactions(item, start_date:, end_date:)
|
||||
|
||||
InvestmentsResponse.new(holdings:, transactions:, securities:)
|
||||
merged_securities = ((holding_securities || []) + (transaction_securities || [])).uniq { |s| s.security_id }
|
||||
|
||||
InvestmentsResponse.new(holdings:, transactions:, securities: merged_securities)
|
||||
end
|
||||
|
||||
def get_item_liabilities(item)
|
||||
|
@ -154,15 +156,7 @@ class Provider::Plaid
|
|||
request = Plaid::InvestmentsHoldingsGetRequest.new({ access_token: item.access_token })
|
||||
response = client.investments_holdings_get(request)
|
||||
|
||||
securities_by_id = response.securities.index_by(&:security_id)
|
||||
accounts_by_id = response.accounts.index_by(&:account_id)
|
||||
|
||||
response.holdings.each do |holding|
|
||||
holding.define_singleton_method(:security) { securities_by_id[holding.security_id] }
|
||||
holding.define_singleton_method(:account) { accounts_by_id[holding.account_id] }
|
||||
end
|
||||
|
||||
response.holdings
|
||||
[ response.holdings, response.securities ]
|
||||
end
|
||||
|
||||
def get_item_investment_transactions(item, start_date:, end_date:)
|
||||
|
@ -179,15 +173,8 @@ class Provider::Plaid
|
|||
)
|
||||
|
||||
response = client.investments_transactions_get(request)
|
||||
securities_by_id = response.securities.index_by(&:security_id)
|
||||
accounts_by_id = response.accounts.index_by(&:account_id)
|
||||
|
||||
response.investment_transactions.each do |t|
|
||||
t.define_singleton_method(:security) { securities_by_id[t.security_id] }
|
||||
t.define_singleton_method(:account) { accounts_by_id[t.account_id] }
|
||||
transactions << t
|
||||
end
|
||||
|
||||
transactions += response.investment_transactions
|
||||
securities += response.securities
|
||||
|
||||
break if transactions.length >= response.total_investment_transactions
|
||||
|
|
|
@ -43,18 +43,23 @@ class Provider::Synth
|
|||
)
|
||||
end
|
||||
|
||||
def fetch_security_prices(ticker:, mic_code:, start_date:, end_date:)
|
||||
prices = paginate(
|
||||
"#{base_url}/tickers/#{ticker}/open-close",
|
||||
mic_code: mic_code,
|
||||
def fetch_security_prices(ticker:, start_date:, end_date:, mic_code: nil)
|
||||
params = {
|
||||
start_date: start_date,
|
||||
end_date: end_date
|
||||
}
|
||||
|
||||
params[:mic_code] = mic_code if mic_code.present?
|
||||
|
||||
prices = paginate(
|
||||
"#{base_url}/tickers/#{ticker}/open-close",
|
||||
params
|
||||
) do |body|
|
||||
body.dig("prices").map do |price|
|
||||
{
|
||||
date: price.dig("date"),
|
||||
price: price.dig("close")&.to_f || price.dig("open")&.to_f,
|
||||
currency: "USD"
|
||||
currency: price.dig("currency") || "USD"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue