Class: IB::Future
- Inherits:
-
Object
- Object
- IB::Future
- Defined in:
- lib/ib/models/future.rb
Instance Method Summary collapse
-
#roll(**args) ⇒ Object
helper method to roll an existing future.
Instance Method Details
#roll(**args) ⇒ Object
helper method to roll an existing future
Argument is the expiry of the target-future.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ib/models/future.rb', line 8 def roll **args error "specify expiry to roll a future" if args.empty? args[:to] = args[:expiry] if args[:expiry].present? && args[:expiry] =~ /[mwMW]$/ args[:expiry]= IB::Spread.transform_distance( expiry, args.delete(:to )) if args[:to].present? new_future = merge( **args ).verify.first error "Cannot roll future; target is no IB::Contract" unless new_future.is_a? IB::Future target = IB::Spread.new exchange: exchange, symbol: symbol, currency: currency target.add_leg self, action: :buy target.add_leg new_future, action: :sell end |