Module: IB::SpreadPrototype

Included in:
Butterfly, Calendar, StockSpread, Straddle, Strangle, Vertical
Defined in:
lib/ib/spread-prototypes.rb

Instance Method Summary collapse

Instance Method Details

#build(from:, **fields) ⇒ Object



20
21
22
# File 'lib/ib/spread-prototypes.rb', line 20

def build from: , **fields
  
end

#defaultsObject



39
40
41
# File 'lib/ib/spread-prototypes.rb', line 39

def defaults
  {}
end

#initialize_spread(ref_contract = nil, **attributes) {|the_spread| ... } ⇒ Object

Yields:

  • (the_spread)


25
26
27
28
29
30
31
32
33
# File 'lib/ib/spread-prototypes.rb', line 25

def initialize_spread ref_contract = nil, **attributes
  error "Initializing of Spread failed – contract is missing" unless ref_contract.is_a?(IB::Contract)
  the_contract =  ref_contract.merge( **attributes ).verify.first
  error "Underlying for Spread is not valid: #{ref_contract.to_human}" if the_contract.nil?
  the_spread= IB::Spread.new  the_contract.attributes.slice( :exchange, :symbol, :currency )
  error "Initializing of Spread failed – Underling is no Contract" if the_spread.nil?
  yield the_spread if block_given?  # yield outside mutex controlled verify-environment
  the_spread  # return_value
end

#optionalObject



43
44
45
# File 'lib/ib/spread-prototypes.rb', line 43

def optional
  { }
end

#parametersObject



47
48
49
50
51
52
53
# File 'lib/ib/spread-prototypes.rb', line 47

def parameters
  the_output = ->(var){ var.empty? ? "none" : var.map{|x| x.join(" --> ") }.join("\n\t: ")}

  "Required : " + the_output[requirements] + "\n --------------- \n" +
    "Optional : " + the_output[optional] + "\n --------------- \n" 

end

#requirementsObject



35
36
37
# File 'lib/ib/spread-prototypes.rb', line 35

def requirements
  {}
end