Sha256: d39265d8f872697bf11b2eb86cfe04c491ce78a42319963ebd323232fd0b157e

Contents?: true

Size: 1 KB

Versions: 14

Compression:

Stored size: 1 KB

Contents

require 'integration_helper'

# Define butterfly
def butterfly symbol, expiry, right, *strikes
  raise 'Unable to create butterfly, no connection' unless @ib && @ib.connected?

  legs = strikes.zip([1, -2, 1]).map do |strike, weight|

    # Create contract
    contract = IB::Option.new :symbol => symbol,
                              :expiry => expiry,
                              :right => right,
                              :strike => strike

    # Find out contract's con_id
    @ib.clear_received :ContractData, :ContractDataEnd
    @ib.send_message :RequestContractData, :id => strike, :contract => contract
    @ib.wait_for :ContractDataEnd, 3
    con_id = @ib.received[:ContractData].last.contract.con_id

    # Create Comboleg from con_id and weight
    IB::ComboLeg.new :con_id => con_id, :weight => weight
  end

  # Return butterfly Combo
  IB::Bag.new :symbol => symbol,
              :currency => "USD", # Only US options in combo Contracts
              :exchange => "SMART",
              :legs => legs
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ib-ruby-0.9.2 spec/combo_helper.rb
ib-ruby-0.9.1 spec/combo_helper.rb
ib-ruby-0.9.0 spec/combo_helper.rb
ib-ruby-0.8.5 spec/combo_helper.rb
ib-ruby-0.8.4 spec/combo_helper.rb
ib-ruby-0.8.3 spec/combo_helper.rb
ib-ruby-0.8.1 spec/combo_helper.rb
ib-ruby-0.8.0 spec/combo_helper.rb
ib-ruby-0.7.12 spec/combo_helper.rb
ib-ruby-0.7.11 spec/combo_helper.rb
ib-ruby-0.7.10 spec/combo_helper.rb
ib-ruby-0.7.9 spec/combo_helper.rb
ib-ruby-0.7.8 spec/combo_helper.rb
ib-ruby-0.7.6 spec/combo_helper.rb