Module: IB::Symbols

Defined in:
lib/ib-ruby/symbols/forex.rb,
lib/ib-ruby/symbols/futures.rb

Constant Summary collapse

Forex =
{
 :gbpusd => Datatypes::Contract.new({
                                      :symbol => "GBP",
                                      :exchange => "IDEALPRO",
                                      :currency => "USD",
                                      :sec_type => Datatypes::Contract::SECURITY_TYPES[:forex],
                                      :description => "GBPUSD"
                                      
                                    }),
 :eurusd => Datatypes::Contract.new({
                                      :symbol => "EUR",
                                      :exchange => "IDEALPRO",
                                      :currency => "USD",
                                      :sec_type => Datatypes::Contract::SECURITY_TYPES[:forex],
                                      :description => "EURUSD"

                                    }),
 :usdjpy => Datatypes::Contract.new({
                                      :symbol => "USD",
                                      :exchange => "IDEALPRO",
                                      :currency => "JPY",
                                      :sec_type => Datatypes::Contract::SECURITY_TYPES[:forex],
                                      :description => "USDJPY"

                                    })

}
Futures =
{
  :es => Datatypes::Contract.new({
                                   :symbol => "ES",
                                   :expiry => self.next_expiry(Time.now),
                                   :exchange => "GLOBEX",
                                   :currency => "USD",
                                   :sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
                                   :multiplier => 50,
                                   :description => "E-Mini S&P 500"
                                 }),

  :gbp => Datatypes::Contract.new({
                                   :symbol => "GBP",
                                   :expiry => self.next_expiry(Time.now),
                                   :exchange => "GLOBEX",
                                   :currency => "USD",
                                   :sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
                                   :multiplier => 62500,
                                   :description => "British Pounds"
                                 }),
  :eur => Datatypes::Contract.new({
                                   :symbol => "EUR",
                                   :expiry => self.next_expiry(Time.now),
                                   :exchange => "GLOBEX",
                                   :currency => "USD",
                                   :sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
                                   :multiplier => 12500,
                                   :description => "Euro FX"
                                 }),
  :jpy => Datatypes::Contract.new({
                                   :symbol => "JPY",
                                   :expiry => self.next_expiry(Time.now),
                                   :exchange => "GLOBEX",
                                   :currency => "USD",
                                   :sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
                                   :multiplier => 12500000,
                                   :description => "Japanese Yen"
                                 }),
  :hsi => Datatypes::Contract.new({
                                   :symbol => "HSI",
                                   :expiry => self.next_expiry(Time.now),
                                   :exchange => "HKFE",
                                   :currency => "HKD",
                                   :sec_type => Datatypes::Contract::SECURITY_TYPES[:future],
                                   :multiplier => 50,
                                   :description => "Hang Seng Index"
                                 })
}

Class Method Summary collapse

Class Method Details

.next_expiry(time) ⇒ Object



55
56
57
# File 'lib/ib-ruby/symbols/futures.rb', line 55

def self.next_expiry(time)
  "#{ self.next_quarter_year(time) }#{ self.next_quarter_month(time) }"
end

.next_quarter_month(time) ⇒ Object



43
44
45
# File 'lib/ib-ruby/symbols/futures.rb', line 43

def self.next_quarter_month(time)
  sprintf("%02d", [3, 6, 9, 12].find{|month| month >= time.month })
end

.next_quarter_year(time) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/ib-ruby/symbols/futures.rb', line 47

def self.next_quarter_year(time)
  if self.next_quarter_month(time).to_i < time.month
    time.year + 1
  else
    time.year
  end
end