Class: EodServices::Contract
- Inherits:
-
Object
- Object
- EodServices::Contract
- 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
- .contract_expiry(contract_symbol) ⇒ Object
-
.contract_symbol(underlying:, expiry:, type:, strike:) ⇒ Object
rubocop:enable Metrics/LineLength.
- .contract_type(contract_symbol) ⇒ Object
- .underlying_symbol(contract_symbol) ⇒ Object
Class Method Details
.contract_expiry(contract_symbol) ⇒ Object
29 30 31 32 |
# File 'lib/eod_services/contract.rb', line 29 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 15 16 17 18 19 20 |
# File 'lib/eod_services/contract.rb', line 10 def contract_symbol(underlying:, expiry:, type:, strike:) return if type == EodModels::OptionType::STOCK contract = + expiration(expiry) + type + padded_strike(strike) unless EodServices::InstrumentType.option?(contract) raise ArgumentError, "Contract #{contract} is not a valid options contract" end contract end |
.contract_type(contract_symbol) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/eod_services/contract.rb', line 34 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
22 23 24 25 26 27 |
# File 'lib/eod_services/contract.rb', line 22 def (contract_symbol) match = contract_symbol.match(CONTRACT_REGEX) return match[:symbol] if match contract_symbol end |