Module: StockPivot::Quotes

Defined in:
lib/stock_pivot/quotes.rb

Class Method Summary collapse

Class Method Details

.exclude_holidays!(days_ago) ⇒ Object



27
28
29
30
31
32
# File 'lib/stock_pivot/quotes.rb', line 27

def exclude_holidays!(days_ago)
  beginning_of_year = days_ago.days.ago.beginning_of_year
  Holidays.between(beginning_of_year, 1.week.from_now, :us, :observed).map do |holiday|
    BusinessTime::Config.holidays << holiday[:date]
  end
end

.feed(symbol, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stock_pivot/quotes.rb', line 6

def feed(symbol, opts = {})
  opts = options.merge(opts)
  days_ago = opts.fetch(:days_ago)
  exclude_holidays!(days_ago)
  start_date = days_ago.business_days.ago
  end_date = 1.business_day.ago
  if Time.after_business_hours?(Time.now) && Date.today.weekday?
    start_date = (days_ago - 1).business_days.ago
    end_date = Date.today
  end
  StockPivot::FeedWrapper.get(
    symbol: symbol,
    start_date: start_date,
    end_date: end_date
  )
end

.optionsObject



23
24
25
# File 'lib/stock_pivot/quotes.rb', line 23

def options
  {days_ago: 10}
end