Module: IB::Symbols
- Defined in:
- lib/ib-ruby/symbols.rb,
lib/ib-ruby/symbols/forex.rb,
lib/ib-ruby/symbols/stocks.rb,
lib/ib-ruby/symbols/futures.rb,
lib/ib-ruby/symbols/options.rb
Constant Summary collapse
- Forex =
IDEALPRO is for orders over 25,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.
{ :audusd => Models::Contract.new(:symbol => "AUD", :exchange => "IDEALPRO", :currency => "USD", :sec_type => SECURITY_TYPES[:forex], :description => "AUDUSD"), :gbpusd => Models::Contract.new(:symbol => "GBP", :exchange => "IDEALPRO", :currency => "USD", :sec_type => SECURITY_TYPES[:forex], :description => "GBPUSD"), :euraud => Models::Contract.new(:symbol => "EUR", :exchange => "IDEALPRO", :currency => "AUD", :sec_type => SECURITY_TYPES[:forex], :description => "EURAUD"), :eurgbp => Models::Contract.new(:symbol => "EUR", :exchange => "IDEALPRO", :currency => "GBP", :sec_type => SECURITY_TYPES[:forex], :description => "EURGBP"), :eurjpy => Models::Contract.new(:symbol => "EUR", :exchange => "IDEALPRO", :currency => "JPY", :sec_type => SECURITY_TYPES[:forex], :description => "EURJPY"), :eurusd => Models::Contract.new(:symbol => "EUR", :exchange => "IDEALPRO", :currency => "USD", :sec_type => SECURITY_TYPES[:forex], :description => "EURUSD"), :eurcad => Models::Contract.new(:symbol => "EUR", :exchange => "IDEALPRO", :currency => "CAD", :sec_type => SECURITY_TYPES[:forex], :description => "EURCAD"), :usdchf => Models::Contract.new(:symbol => "USD", :exchange => "IDEALPRO", :currency => "CHF", :sec_type => SECURITY_TYPES[:forex], :description => "USDCHF"), :usdcad => Models::Contract.new(:symbol => "USD", :exchange => "IDEALPRO", :currency => "CAD", :sec_type => SECURITY_TYPES[:forex], :description => "USDCAD"), :usdjpy => Models::Contract.new(:symbol => "USD", :exchange => "IDEALPRO", :currency => "JPY", :sec_type => SECURITY_TYPES[:forex], :description => "USDJPY") }
- Stocks =
{:wfc => Models::Contract.new(:symbol => "WFC", :exchange => "NYSE", :currency => "USD", :sec_type => SECURITY_TYPES[:stock], :description => "Wells Fargo"), :aapl => Models::Contract.new(:symbol => "AAPL", :currency => "USD", :sec_type => SECURITY_TYPES[:stock], :description => "Apple Inc."), :wrong => Models::Contract.new(:symbol => "QEEUUE", :exchange => "NYSE", :currency => "USD", :sec_type => SECURITY_TYPES[:stock], :description => "Non-existent stock"), }
- Futures =
{ :ym => Models::Contract.new(:symbol => "YM", :expiry => next_expiry, :exchange => "ECBOT", :currency => "USD", :sec_type => SECURITY_TYPES[:future], :description => "Mini Dow Jones Industrial"), :es => Models::Contract.new(:symbol => "ES", :expiry => next_expiry, :exchange => "GLOBEX", :currency => "USD", :sec_type => SECURITY_TYPES[:future], :multiplier => 50, :description => "E-Mini S&P 500"), :gbp => Models::Contract.new(:symbol => "GBP", :expiry => next_expiry, :exchange => "GLOBEX", :currency => "USD", :sec_type => SECURITY_TYPES[:future], :multiplier => 62500, :description => "British Pounds"), :eur => Models::Contract.new(:symbol => "EUR", :expiry => next_expiry, :exchange => "GLOBEX", :currency => "USD", :sec_type => SECURITY_TYPES[:future], :multiplier => 12500, :description => "Euro FX"), :jpy => Models::Contract.new(:symbol => "JPY", :expiry => next_expiry, :exchange => "GLOBEX", :currency => "USD", :sec_type => SECURITY_TYPES[:future], :multiplier => 12500000, :description => "Japanese Yen"), :hsi => Models::Contract.new(:symbol => "HSI", :expiry => next_expiry, :exchange => "HKFE", :currency => "HKD", :sec_type => SECURITY_TYPES[:future], :multiplier => 50, :description => "Hang Seng Index") }
- Options =
{:wfc20 => Models::Contract::Option.new(:symbol => "WFC", :expiry => "201207", :right => "CALL", :strike => 20.0, :description => "Wells Fargo 20 Call 2012-07"), :aapl500 => Models::Contract::Option.new(:symbol => "AAPL", :expiry => "201301", :right => "CALL", :strike => 500, :description => "Apple 500 Call 2013-01"), :z50 => Models::Contract::Option.new(:symbol => "Z", :exchange => "LIFFE", :expiry => "201206", :right => "CALL", :strike => 50.0, :description => " FTSE-100 index 50 Call 2012-06"), :spy75 => Models::Contract::Option.new(:symbol => 'SPY', :expiry => "20120615", :right => "P", :currency => "USD", :strike => 75.0, :description => "SPY 75.0 Put 2012-06-16"), :spy100 => Models::Contract::Option.new(:osi => 'SPY 121222P00100000'), }
Class Method Summary collapse
-
.future(base_symbol, exchange, currency, description = "", expiry = nil) ⇒ Object
Convenience method; generates a Models::Contract instance for a futures contract with the given parameters.
-
.next_expiry(time = Time.now) ⇒ Object
WARNING: This is currently broken.
-
.next_quarter_month(time = Time.now) ⇒ Object
Find the next front month of quarterly futures.
- .next_quarter_year(time = Time.now) ⇒ Object
Class Method Details
.future(base_symbol, exchange, currency, description = "", expiry = nil) ⇒ Object
Convenience method; generates a Models::Contract instance for a futures contract with the given parameters.
If expiry is nil, it will use the end month of the current quarter. This will be wrong for most contracts most of the time, since most contracts have the majority of their volume in a nearby intraquarter month.
It is recommended that you specify an expiration date manually until next_expiry is fixed. Expiry should be a string in the format “YYYYMM”, where YYYY is the 4 digit year and MM is the 2 digit month. For example, November 2011 is “201111”.
55 56 57 58 59 60 61 62 |
# File 'lib/ib-ruby/symbols/futures.rb', line 55 def self.future(base_symbol, exchange, currency, description="", expiry=nil) Models::Contract.new(:symbol => base_symbol, :expiry => expiry || next_expiry, :exchange => exchange, :currency => currency, :sec_type => SECURITY_TYPES[:future], :description => description) end |
.next_expiry(time = Time.now) ⇒ Object
WARNING: This is currently broken. It returns the next quarterly expiration month after the current month. Many futures instruments have monthly contracts for the near months. This method will not work for such contracts; it will return the next quarter after the current month, even though the present month has the majority of the trading volume.
For example, in early November of 2011, many contracts have the vast majority of their volume in the Nov 2011 contract, but this method will return the Dec 2011 contract instead.
38 39 40 |
# File 'lib/ib-ruby/symbols/futures.rb', line 38 def self.next_expiry time=Time.now "#{ next_quarter_year(time) }#{ sprintf("%02d", next_quarter_month(time)) }" end |
.next_quarter_month(time = Time.now) ⇒ Object
Find the next front month of quarterly futures.
N.B. This will not work as expected during the front month before expiration, as it will point to the next quarter even though the current month is still valid!
19 20 21 |
# File 'lib/ib-ruby/symbols/futures.rb', line 19 def self.next_quarter_month time=Time.now [3, 6, 9, 12].find { |month| month > time.month } || 3 # for December, next March end |
.next_quarter_year(time = Time.now) ⇒ Object
23 24 25 |
# File 'lib/ib-ruby/symbols/futures.rb', line 23 def self.next_quarter_year time=Time.now next_quarter_month(time) < time.month ? time.year + 1 : time.year end |