Sha256: 4dc7956deb055a2841fa95735dbfb43c92aac78a499d35d8037200af48957215

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

module IEX
  module Endpoints
    module Chart
      def chart(symbol, range = nil, options = {})
        url = [
          'stock',
          symbol,
          'chart',
          range && range.respond_to?(:strftime) ? "date/#{range.strftime('%Y%m%d')}" : range
        ].compact.join('/')

        params = {}

        options&.each_pair do |k, v|
          k = k.to_s.split('_').map(&:capitalize).join.sub(/^[A-Z]/, &:downcase)
          params[k.to_sym] = v
        end

        response = get(url, { token: publishable_token }.merge(params))

        if range && range.to_s == 'dynamic'
          range = response['range']
          response = response['data']
        end
        response.map do |data|
          case range
          when '1d', Date, DateTime
            IEX::Resources::Chart::OneDay.new data
          else
            IEX::Resources::Chart::Default.new data
          end
        end
      rescue Faraday::ResourceNotFound => e
        raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
iex-ruby-client-2.1.0 lib/iex/endpoints/chart.rb
iex-ruby-client-2.0.0 lib/iex/endpoints/chart.rb
iex-ruby-client-1.6.0 lib/iex/endpoints/chart.rb
iex-ruby-client-1.5.0 lib/iex/endpoints/chart.rb
iex-ruby-client-1.4.1 lib/iex/endpoints/chart.rb
iex-ruby-client-1.4.0 lib/iex/endpoints/chart.rb
iex-ruby-client-1.3.0 lib/iex/endpoints/chart.rb
iex-ruby-client-1.2.0 lib/iex/endpoints/chart.rb
iex-ruby-client-1.1.2 lib/iex/endpoints/chart.rb
iex-ruby-client-1.1.1 lib/iex/endpoints/chart.rb