Sha256: 3065d49d1e1076125698ea7e28cd2ebc63c8414721fee6716b4d7cec06aea5f1

Contents?: true

Size: 839 Bytes

Versions: 1

Compression:

Stored size: 839 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

        response.parsed_response
      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.11 lib/eod_facade/options.rb