Sha256: 420cf5d5b780156f9a0a69d40d00105906edeebfd811311600669800179f9729

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

module IB
  module Symbols
    module Forex
      extend Symbols

      def self.contracts
        @contracts ||= define_contracts
      end

      private

      # IDEALPRO is for orders over 20,000 and routes to the interbank quote stream.
      # IDEAL is for smaller orders, and has wider spreads/slower execution... generally
      # used for smaller currency conversions. IB::Symbols::Forex contracts are pre-defined
      # on IDEALPRO, if you need something else please define forex contracts manually.
      def self.define_contracts
        @contracts = {}

        # use combinations of these currencies for pre-defined forex contracts
        currencies = [ "aud", "cad", "chf", "eur", "gbp", "hkd", "jpy", "nzd", "usd" ]

        # create pairs list from currency list
        pairs = currencies.product(currencies).
          map { |pair| pair.join.upcase unless pair.first == pair.last }.compact

        # now define each contract
        pairs.each do |pair|
          @contracts[pair.downcase.to_sym] = IB::Contract.new(
            :symbol => pair[0..2],
            :exchange => "IDEALPRO",
            :currency => pair[3..5],
            :sec_type => :forex,
            :description => pair
          )
        end
        
        @contracts
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
my-ib-api-0.0.4 lib/ib/symbols/forex.rb
my-ib-api-0.0.3 lib/ib/symbols/forex.rb
my-ib-api-0.0.2 lib/ib/symbols/forex.rb
my-ib-api-0.0.1 lib/ib/symbols/forex.rb
ib-ruby-0.9.2 lib/ib/symbols/forex.rb
ib-ruby-0.9.1 lib/ib/symbols/forex.rb
ib-ruby-0.9.0 lib/ib/symbols/forex.rb