mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
* PlaidConnectable concern * Remove bad abstraction * Put sync implementations in own concerns * Sync strategies * Move sync orchestration to Sync class * Clean up sync class, add state machine * Basic market data sync cron * Fix price sync * Improve sync window column names, add timestamps * 30 day syncs by default * Clean up market data methods * Report high duplicate sync counts to Sentry * Add sync states throughout app * account tab session * Persistent account tab selections * Remove manual sleep * Add migration to clear stale syncs on self hosted apps * Tweak sync states * Sync completion event broadcasts * Fix timezones in tests * Cleanup * More cleanup * Plaid item UI broadcasts for sync * Fix account ID namespace conflict * Sync broadcasters * Smoother account sync refreshes * Remove test sync delay
56 lines
1.5 KiB
Ruby
56 lines
1.5 KiB
Ruby
module Security::Provided
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
def provider
|
|
registry = Provider::Registry.for_concept(:securities)
|
|
registry.get_provider(:synth)
|
|
end
|
|
|
|
def search_provider(symbol, country_code: nil, exchange_operating_mic: nil)
|
|
return [] if symbol.blank? || symbol.length < 2
|
|
|
|
response = provider.search_securities(symbol, country_code: country_code, exchange_operating_mic: exchange_operating_mic)
|
|
|
|
if response.success?
|
|
response.data.map do |provider_security|
|
|
# Need to map to domain model so Combobox can display via to_combobox_option
|
|
Security.new(
|
|
ticker: provider_security.symbol,
|
|
name: provider_security.name,
|
|
logo_url: provider_security.logo_url,
|
|
exchange_operating_mic: provider_security.exchange_operating_mic,
|
|
)
|
|
end
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
end
|
|
|
|
def find_or_fetch_price(date: Date.current, cache: true)
|
|
price = prices.find_by(date: date)
|
|
|
|
return price if price.present?
|
|
|
|
# Make sure we have a data provider before fetching
|
|
return nil unless provider.present?
|
|
response = provider.fetch_security_price(self, date: date)
|
|
|
|
return nil unless response.success? # Provider error
|
|
|
|
price = response.data
|
|
Security::Price.find_or_create_by!(
|
|
security_id: price.security.id,
|
|
date: price.date,
|
|
price: price.price,
|
|
currency: price.currency
|
|
) if cache
|
|
price
|
|
end
|
|
|
|
private
|
|
def provider
|
|
self.class.provider
|
|
end
|
|
end
|