Sha256: a1a5a8cde898002d654fbb0c80ff335d65943147184db13832d520e7f93d9d8f
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
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 contract_hash( symbol: symbol, contracts: contracts, option_type: option_type ) end private def params(expiry) { from: expiry.to_s, to: expiry.to_s } end def url_path(underlying) "/options/#{underlying}" end def contract_hash(symbol:, contracts:, option_type:) by_expiration = contracts['data'].first expiration_date = by_expiration && by_expiration['expirationDate'] by_option_type = by_expiration && by_expiration['options'][option_type] contract = by_option_type&.find do |c| c['contractName'] == symbol end raise ArgumentError, "Contract #{symbol} not found" unless contract contract.merge('expirationDate' => expiration_date) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sensei_eod_utils-0.0.13 | lib/eod_facade/options.rb |