Skip to content

Commit

Permalink
Update insider trading limits and cache expiration times
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Nov 20, 2024
1 parent 7b853c7 commit c1b2fcd
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions app/presenters/tool/presenter/inside_trading_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def active_record
end

def insider_data
@insider_data ||= begin
@insider_data ||= Rails.cache.fetch("insider_trades/#{symbol}/#{180.days.ago.to_date}/#{Date.today}/250", expires_in: 6.hours) do
response = Provider::Synth.new.insider_trades(
ticker: symbol,
start_date: 180.days.ago,
end_date: Date.today,
limit: 100
limit: 250
)

if response.success?
Expand All @@ -87,9 +87,11 @@ def insider_data
end

def recent_insider_trades
response = Provider::Synth.new.recent_insider_trades(limit: 250)
return [] unless response[:trades]&.any?
format_trades(response[:trades])
Rails.cache.fetch("recent_insider_trades/#{Date.today}", expires_in: 6.hours) do
response = Provider::Synth.new.recent_insider_trades(limit: 250)
return [] unless response[:trades]&.any?
format_trades(response[:trades])
end
end

def format_trades(trades)
Expand Down Expand Up @@ -133,15 +135,19 @@ def format_trades(trades)
end

def fetch_filtered_trades(filters = {})
Rails.logger.warn "Fetching filtered trades with filters: #{filters}"
response = Provider::Synth.new.recent_insider_trades(
start_date: 90.days.ago,
end_date: Date.today,
limit: 25,
**filters
)

return [] unless response.success? && response.trades&.any?
format_trades(response.trades)
cache_key = "filtered_insider_trades/#{filters.to_json}/#{90.days.ago.to_date}/#{Date.today}"

Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
Rails.logger.warn "Fetching filtered trades with filters: #{filters}"
response = Provider::Synth.new.recent_insider_trades(
start_date: 90.days.ago,
end_date: Date.today,
limit: 250,
**filters
)

return [] unless response.success? && response.trades&.any?
format_trades(response.trades)
end
end
end

0 comments on commit c1b2fcd

Please sign in to comment.