Class: EodServices::Contract

Inherits:
Object
  • Object
show all
Defined in:
lib/eod_services/contract.rb

Constant Summary collapse

CONTRACT_REGEX =

rubocop:disable Metrics/LineLength

/^(?<symbol>[A-Z]+)(?<expiry>[0-9]{6})(?<option_type>[CP]{1})[0-9]{8}$/.freeze

Class Method Summary collapse

Class Method Details

.contract_expiry(contract_symbol) ⇒ Object



23
24
25
26
# File 'lib/eod_services/contract.rb', line 23

def contract_expiry(contract_symbol)
  match = contract_symbol.match(CONTRACT_REGEX)
  Date.parse(match[:expiry]) if match
end

.contract_symbol(underlying:, expiry:, type:, strike:) ⇒ Object

rubocop:enable Metrics/LineLength



10
11
12
13
14
# File 'lib/eod_services/contract.rb', line 10

def contract_symbol(underlying:, expiry:, type:, strike:)
  return underlying if type == EodModels::OptionType::STOCK

  underlying + expiration(expiry) + type + padded_strike(strike)
end

.contract_type(contract_symbol) ⇒ Object



28
29
30
31
32
33
# File 'lib/eod_services/contract.rb', line 28

def contract_type(contract_symbol)
  match = contract_symbol.match(CONTRACT_REGEX)
  return match[:option_type] if match

  EodModels::OptionType::STOCK
end

.underlying_symbol(contract_symbol) ⇒ Object



16
17
18
19
20
21
# File 'lib/eod_services/contract.rb', line 16

def underlying_symbol(contract_symbol)
  match = contract_symbol.match(CONTRACT_REGEX)
  return match[:symbol] if match

  contract_symbol
end