Sha256: 3250ac360126a7827be39f58ff191b25d8417af4136f1d3ca21beda2dc0d7ceb

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

require 'oj'

module EodFacade
  class Options < ::EodFacade::Base
    class << self
      def call(symbol)
        underlying = EodServices::Contract.underlying_symbol(symbol)
        expiry = EodServices::Contract.contract_expiry(symbol)

        unless expiry
          raise ArgumentError, "Invalid expiration date for option #{symbol}"
        end

        response = make_request(url_path(underlying), params(expiry))

        unless response.success?
          raise ArgumentError, "Error fetching options data for #{symbol}"
        end

        unless response.parsed_response[symbol]
          raise ArgumentError, "Option contract #{symbol} not found"
        end

        response.parsed_response[symbol]
      end

      private

      def params(expiry)
        {
          from: expiry.to_s,
          to: expiry.to_s
        }
      end

      def url_path(underlying)
        "/options/#{underlying}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.12 lib/eod_facade/options.rb