4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/iex/endpoints/historial_prices.rb', line 4
def historical_prices(symbol, options = {})
if options[:range] == 'date'
raise ArgumentError unless options[:date].present?
raise ArgumentError unless options[:chartByDay].present?
end
options = options.dup
options[:date] = options[:date].strftime('%Y%m%d') if options[:date].is_a?(Date)
path = "stock/#{symbol}/chart"
path += "/#{options[:range]}" if options.key?(:range)
path += "/#{options[:date]}" if options[:range] == 'date'
options.delete(:range)
options.delete(:date)
(get(path, { token: publishable_token }.merge(options)) || []).map do |data|
IEX::Resources::HistorialPrices.new(data)
end
rescue Faraday::ResourceNotFound => e
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
end
|