Module: IB::StockSpread
- Extended by:
- SpreadPrototype
- Defined in:
- lib/ib/spread_prototypes/stock-spread.rb
Class Method Summary collapse
-
.fabricate(*underlying, ratio: [1,-1], **args) ⇒ Object
Fabricate a StockSpread from Scratch —————————————–.
-
.order_requirements ⇒ Object
always route a order as NonGuaranteed.
- .the_description(spread) ⇒ Object
Methods included from SpreadPrototype
build, defaults, initialize_spread, optional, parameters, requirements
Class Method Details
.fabricate(*underlying, ratio: [1,-1], **args) ⇒ Object
Fabricate a StockSpread from Scratch
-----------------------------------------
Call with
IB::StockSpread.fabricate 'GE','F', ratio:[1,-2]
or
IB::StockSpread.fabricate IB::Stock.new(symbol:'GE'), 'F', ratio:[1,-2]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ib/spread_prototypes/stock-spread.rb', line 19 def fabricate *, ratio: [1,-1], **args # are_stocks = ->(l){ l.all?{|y| y.is_a? IB::Stock} } legs = .map{|y| y.is_a?( IB::Stock ) ? y.merge(**args) : IB::Stock.new( symbol: y ).merge(**args)} error "only spreads with two underyings of type »IB::Stock« are supported" unless legs.size==2 && are_stocks[legs] initialize_spread( legs.first ) do | the_spread | c_l = legs.zip(ratio).map do |l,r| action = r >0 ? :buy : :sell the_spread.add_leg l, action: action, ratio: r.abs end the_spread.description = the_description( the_spread ) the_spread.symbol = legs.map( &:symbol ).sort.join(",") # alphabetical order end end |
.order_requirements ⇒ Object
always route a order as NonGuaranteed
42 43 44 |
# File 'lib/ib/spread_prototypes/stock-spread.rb', line 42 def order_requirements { combo_params: ['NonGuaranteed', true] } end |
.the_description(spread) ⇒ Object
35 36 37 38 39 |
# File 'lib/ib/spread_prototypes/stock-spread.rb', line 35 def the_description spread info= spread.legs.map( &:symbol ).zip(spread.combo_legs.map( &:weight )) "<StockSpread #{info.map{|c| c.join(":")}.join(" , ")} (#{spread.currency} )>" end |