Class: IB::Datatypes::Contract
- Inherits:
-
AbstractDatum
- Object
- AbstractDatum
- IB::Datatypes::Contract
- Defined in:
- lib/ib-ruby/datatypes.rb
Constant Summary collapse
- SECURITY_TYPES =
Valid security types (sec_type attribute)
{ :stock => "STK", :option => "OPT", :future => "FUT", :index => "IND", :futures_option => "FOP", :forex => "CASH", :bag => "BAG" }
Instance Attribute Summary collapse
-
#bond_type ⇒ Object
Bond values.
-
#callable ⇒ Object
Bond values.
-
#combo_legs ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#convertible ⇒ Object
Bond values.
-
#coupon ⇒ Object
Bond values.
-
#coupon_type ⇒ Object
Bond values.
-
#currency ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#cusip ⇒ Object
Bond values.
-
#desc_append ⇒ Object
Bond values.
-
#description ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#exchange ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#expiry ⇒ Object
Returns the value of attribute expiry.
-
#issue_date ⇒ Object
Bond values.
-
#local_symbol ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#maturity ⇒ Object
Bond values.
-
#multiplier ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#primary_exchange ⇒ Object
Returns the value of attribute primary_exchange.
-
#puttable ⇒ Object
Bond values.
-
#ratings ⇒ Object
Bond values.
-
#right ⇒ Object
Returns the value of attribute right.
-
#sec_type ⇒ Object
Returns the value of attribute sec_type.
-
#strike ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
-
#symbol ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS.
Class Method Summary collapse
-
.from_ib_ruby(string) ⇒ Object
This returns a Contract initialized from the serialize_ib_ruby format string.
Instance Method Summary collapse
- #init ⇒ Object
- #reset ⇒ Object
-
#serialize_combo_legs(include_open_close = false) ⇒ Object
Some messages send open_close too, some don’t.
-
#serialize_ib_ruby(version) ⇒ Object
This produces a string uniquely identifying this contract, in the format used for command line arguments in the IB-Ruby examples.
-
#serialize_long(version) ⇒ Object
This returns an Array of data from the given contract, in standard format.
-
#serialize_short(version) ⇒ Object
Different messages serialize contracts differently.
- #to_human ⇒ Object
- #to_s ⇒ Object
- #to_short ⇒ Object
Methods inherited from AbstractDatum
Constructor Details
This class inherits a constructor from IB::Datatypes::AbstractDatum
Instance Attribute Details
#bond_type ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def bond_type @bond_type end |
#callable ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def callable @callable end |
#combo_legs ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def combo_legs @combo_legs end |
#convertible ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def convertible @convertible end |
#coupon ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def coupon @coupon end |
#coupon_type ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def coupon_type @coupon_type end |
#currency ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def currency @currency end |
#cusip ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def cusip @cusip end |
#desc_append ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def desc_append @desc_append end |
#description ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def description @description end |
#exchange ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def exchange @exchange end |
#expiry ⇒ Object
Returns the value of attribute expiry.
180 181 182 |
# File 'lib/ib-ruby/datatypes.rb', line 180 def expiry @expiry end |
#issue_date ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def issue_date @issue_date end |
#local_symbol ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def local_symbol @local_symbol end |
#maturity ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def maturity @maturity end |
#multiplier ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def multiplier @multiplier end |
#primary_exchange ⇒ Object
Returns the value of attribute primary_exchange.
180 181 182 |
# File 'lib/ib-ruby/datatypes.rb', line 180 def primary_exchange @primary_exchange end |
#puttable ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def puttable @puttable end |
#ratings ⇒ Object
Bond values
177 178 179 |
# File 'lib/ib-ruby/datatypes.rb', line 177 def @ratings end |
#right ⇒ Object
Returns the value of attribute right.
180 181 182 |
# File 'lib/ib-ruby/datatypes.rb', line 180 def right @right end |
#sec_type ⇒ Object
Returns the value of attribute sec_type.
180 181 182 |
# File 'lib/ib-ruby/datatypes.rb', line 180 def sec_type @sec_type end |
#strike ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def strike @strike end |
#symbol ⇒ Object
note that the :description field is entirely local to ib-ruby, and not part of TWS. You can use it to store whatever arbitrary data you want.
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def symbol @symbol end |
Class Method Details
.from_ib_ruby(string) ⇒ Object
This returns a Contract initialized from the serialize_ib_ruby format string.
276 277 278 279 280 281 |
# File 'lib/ib-ruby/datatypes.rb', line 276 def self.from_ib_ruby(string) c = Contract.new c.symbol, c.sec_type, c.expiry, c.strike, c.right, c.multiplier, c.exchange, c.primary_exchange, c.currency, c.local_symbol = string.split(":") c end |
Instance Method Details
#init ⇒ Object
292 293 294 295 296 297 298 |
# File 'lib/ib-ruby/datatypes.rb', line 292 def init super @combo_legs = Array.new @strike = 0 @sec_type = '' end |
#reset ⇒ Object
214 215 216 217 |
# File 'lib/ib-ruby/datatypes.rb', line 214 def reset @combo_legs = Array.new @strike = 0 end |
#serialize_combo_legs(include_open_close = false) ⇒ Object
Some messages send open_close too, some don’t. WTF.
284 285 286 287 288 289 290 |
# File 'lib/ib-ruby/datatypes.rb', line 284 def serialize_combo_legs(include_open_close = false) if self.combo_legs.nil? [0] else [ self.combo_legs.size ].concat(self.combo_legs.serialize(include_open_close)) end end |
#serialize_ib_ruby(version) ⇒ Object
This produces a string uniquely identifying this contract, in the format used for command line arguments in the IB-Ruby examples. The format is:
symbol:security_type:expiry:strike:right:multiplier:exchange:primary_exchange:currency:local_symbol
Fields not needed for a particular security should be left blank (e.g. strike and right are only relevant for options.)
For example, to query the British pound futures contract trading on Globex expiring in September, 2008, the string is:
GBP:FUT:200809:::62500:GLOBEX::USD:
271 272 273 |
# File 'lib/ib-ruby/datatypes.rb', line 271 def serialize_ib_ruby(version) serialize_long(version).join(":") end |
#serialize_long(version) ⇒ Object
This returns an Array of data from the given contract, in standard format. Note that it does not include the combo legs.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/ib-ruby/datatypes.rb', line 239 def serialize_long(version) queue = [ self.symbol, self.sec_type, self.expiry, self.strike, self.right ] queue.push(self.multiplier) if version >= 15 queue.push(self.exchange) queue.push(self.primary_exchange) if version >= 14 queue.push(self.currency) queue.push(self.local_symbol) if version >= 2 queue end |
#serialize_short(version) ⇒ Object
Different messages serialize contracts differently. Go figure.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ib-ruby/datatypes.rb', line 220 def serialize_short(version) q = [ self.symbol, self.sec_type, self.expiry, self.strike, self.right ] q.push(self.multiplier) if version >= 15 q.concat([ self.exchange, self.currency, self.local_symbol ]) q end |
#to_human ⇒ Object
300 301 302 |
# File 'lib/ib-ruby/datatypes.rb', line 300 def to_human "<IB-Contract: " + [symbol, expiry, sec_type, strike, right, exchange, currency].join("-") + "}>" end |
#to_s ⇒ Object
308 309 310 |
# File 'lib/ib-ruby/datatypes.rb', line 308 def to_s to_human end |
#to_short ⇒ Object
304 305 306 |
# File 'lib/ib-ruby/datatypes.rb', line 304 def to_short "#{symbol}#{expiry}#{strike}#{right}#{exchange}#{currency}" end |