Sha256: a5310a6bfef1efb4983ba39f64d0bc1c4c56d6fd765ee15cd069947f43820fe8

Contents?: true

Size: 852 Bytes

Versions: 2

Compression:

Stored size: 852 Bytes

Contents

# frozen_string_literal: true

module EodServices
  class InstrumentType
    class <<self
      def etf?(symbol)
        call(symbol) == EodModels::InstrumentType::ETF
      end

      def stock?(symbol)
        call(symbol) == EodModels::InstrumentType::STOCK
      end

      def option?(symbol)
        call(symbol) == EodModels::InstrumentType::OPTION
      end

      private

      def call(symbol)
        fundamentals = EodFacade::Fundamentals(symbol)

        if fundamentals['type'] == 'ETF'
          EodModels::InstrumentType::ETF
        elsif fundamentals['type'] == 'Common Stock'
          EodModels::InstrumentType::Stock
        elsif EodFacade::Options.call(symbol)
          EodModels::InstrumentType::Option
        else
          raise ArgumentError, "Invalid intrument type for #{symbol}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.21 lib/eod_services/instrument_type.rb
sensei_eod_utils-0.0.19 lib/eod_services/instrument_type.rb