Class: IB::Models::Contract::Option
- Inherits:
-
IB::Models::Contract
- Object
- Model
- IB::Models::Contract
- IB::Models::Contract::Option
- Defined in:
- lib/ib-ruby/models/contract/option.rb
Constant Summary
Constants inherited from IB::Models::Contract
Constants inherited from Model
Instance Attribute Summary
Attributes inherited from IB::Models::Contract
Attributes inherited from Model
Class Method Summary collapse
-
.from_osi(osi) ⇒ Object
Make valid IB Contract definition from OSI (Option Symbology Initiative) code.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Option
constructor
A new instance of Option.
- #osi=(value) ⇒ Object
- #to_human ⇒ Object
Methods inherited from IB::Models::Contract
#==, build, from_ib_ruby, #serialize, #serialize_ib_ruby, #serialize_legs, #serialize_long, #serialize_short, #serialize_under_comp, #summary, #to_s, #to_short
Methods inherited from Model
Methods included from ModelProperties
#define_property, #define_property_methods, #prop
Constructor Details
#initialize(opts = {}) ⇒ Option
Returns a new instance of Option.
45 46 47 48 49 |
# File 'lib/ib-ruby/models/contract/option.rb', line 45 def initialize opts = {} super opts self[:sec_type] = IB::SECURITY_TYPES[:option] self[:description] ||= osi ? osi : "#{symbol} #{strike} #{right} #{expiry}" end |
Class Method Details
.from_osi(osi) ⇒ Object
Make valid IB Contract definition from OSI (Option Symbology Initiative) code. NB: Simply making a new Contract with local_symbol (osi) property set to a valid OSI code works just as well, just do NOT set expiry, right or strike properties at the same time. This class method provided as a backup, to show how to analyse OSI codes.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ib-ruby/models/contract/option.rb', line 21 def self.from_osi osi # Parse contract's OSI (OCC Option Symbology Initiative) code args = osi.match(/(\w+)\s?(\d\d)(\d\d)(\d\d)([pcPC])(\d+)/).to_a.drop(1) symbol = args.shift year = 2000 + args.shift.to_i month = args.shift.to_i day = args.shift.to_i right = args.shift.upcase strike = args.shift.to_i/1000.0 #p symbol, year, month, day, right, strike # Set correct expiry date - IB expiry date differs from OSI if expiry date # falls on Saturday (see https://github.com/arvicco/option_mower/issues/4) expiry_date = Time.new(year, month, day) expiry_date = Time.new(year, month, day-1) if expiry_date.saturday? new :symbol => symbol, :exchange => "SMART", :expiry => expiry_date.to_ib, :right => right, :strike => strike end |
Instance Method Details
#osi=(value) ⇒ Object
11 12 13 14 |
# File 'lib/ib-ruby/models/contract/option.rb', line 11 def osi= value # Normalize to 21 char self.local_symbol = value.sub(/ /, ' '*(22-value.size)) end |
#to_human ⇒ Object
51 52 53 |
# File 'lib/ib-ruby/models/contract/option.rb', line 51 def to_human "<Option: " + [symbol, expiry, right, strike, exchange, currency].join("-") + ">" end |