Class: EodFacade::Options

Inherits:
Base
  • Object
show all
Defined in:
lib/eod_facade/options.rb

Class Method Summary collapse

Methods inherited from Base

make_request

Class Method Details

.call(symbol) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eod_facade/options.rb', line 9

def call(symbol)
  underlying = EodServices::Contract.underlying_symbol(symbol)
  expiry = EodServices::Contract.contract_expiry(symbol)
  option_type = contract_type(symbol)

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

  unless Cache::RedisCache.get(redis_key(underlying, expiry))
    response = make_request(url_path(underlying))
    
    unless response.success?
      raise ArgumentError, "Error fetching options data for #{underlying}"
    end

    Cache::RedisCache.set(
      redis_key(underlying, expiry),
      response.parsed_response.to_json
    )
  end

  contracts = Oj.load(Cache::RedisCache.get(redis_key(underlying, expiry)))

  contract_hash(
    symbol: symbol,
    contracts: contracts,
    option_type: option_type
  )
end