mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Match Plaid holding values on current day (#2212)
* Match Plaid holding values on current day * Fix chart timezone issue * Add timezone tests for syncs * Hide sidebars on trades test
This commit is contained in:
parent
470b753833
commit
2000f05453
16 changed files with 242 additions and 21 deletions
|
@ -21,11 +21,15 @@ class Holding::PortfolioCache
|
|||
end
|
||||
end
|
||||
|
||||
def get_price(security_id, date)
|
||||
def get_price(security_id, date, source: nil)
|
||||
security = @security_cache[security_id]
|
||||
raise SecurityNotFound.new(security_id, account.id) unless security
|
||||
|
||||
price = security[:prices].select { |p| p.price.date == date }.min_by(&:priority)&.price
|
||||
if source.present?
|
||||
price = security[:prices].select { |p| p.price.date == date && p.source == source }.min_by(&:priority)&.price
|
||||
else
|
||||
price = security[:prices].select { |p| p.price.date == date }.min_by(&:priority)&.price
|
||||
end
|
||||
|
||||
return nil unless price
|
||||
|
||||
|
@ -46,7 +50,7 @@ class Holding::PortfolioCache
|
|||
end
|
||||
|
||||
private
|
||||
PriceWithPriority = Data.define(:price, :priority)
|
||||
PriceWithPriority = Data.define(:price, :priority, :source)
|
||||
|
||||
def trades
|
||||
@trades ||= account.entries.includes(entryable: :security).trades.chronological.to_a
|
||||
|
@ -86,7 +90,8 @@ class Holding::PortfolioCache
|
|||
db_prices = security.prices.where(date: account.start_date..Date.current).map do |price|
|
||||
PriceWithPriority.new(
|
||||
price: price,
|
||||
priority: 1
|
||||
priority: 1,
|
||||
source: "db"
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -101,7 +106,8 @@ class Holding::PortfolioCache
|
|||
currency: trade.entryable.currency,
|
||||
date: trade.date
|
||||
),
|
||||
priority: 2
|
||||
priority: 2,
|
||||
source: "trade"
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -115,7 +121,8 @@ class Holding::PortfolioCache
|
|||
currency: holding.currency,
|
||||
date: holding.date
|
||||
),
|
||||
priority: 3
|
||||
priority: 3,
|
||||
source: "holding"
|
||||
)
|
||||
end
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue