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



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

def defaults
	{}
end

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

Yields:

  • (the_spread)


25
26
27
28
29
30
31
32
33
34
# 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)
    # make sure that :exchange, :symbol and :currency are present
	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



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

def optional
	{ }
end

#parametersObject



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

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



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

def requirements
	{}
end