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
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def bond_type @bond_type end |
#callable ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 def combo_legs @combo_legs end |
#convertible ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def convertible @convertible end |
#coupon ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def coupon @coupon end |
#coupon_type ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 def currency @currency end |
#cusip ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def cusip @cusip end |
#desc_append ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 def exchange @exchange end |
#expiry ⇒ Object
Returns the value of attribute expiry.
176 177 178 |
# File 'lib/ib-ruby/datatypes.rb', line 176 def expiry @expiry end |
#issue_date ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 def local_symbol @local_symbol end |
#maturity ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 def multiplier @multiplier end |
#primary_exchange ⇒ Object
Returns the value of attribute primary_exchange.
176 177 178 |
# File 'lib/ib-ruby/datatypes.rb', line 176 def primary_exchange @primary_exchange end |
#puttable ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def puttable @puttable end |
#ratings ⇒ Object
Bond values
173 174 175 |
# File 'lib/ib-ruby/datatypes.rb', line 173 def @ratings end |
#right ⇒ Object
Returns the value of attribute right.
176 177 178 |
# File 'lib/ib-ruby/datatypes.rb', line 176 def right @right end |
#sec_type ⇒ Object
Returns the value of attribute sec_type.
176 177 178 |
# File 'lib/ib-ruby/datatypes.rb', line 176 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 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.
169 170 171 |
# File 'lib/ib-ruby/datatypes.rb', line 169 def symbol @symbol end |
Class Method Details
.from_ib_ruby(string) ⇒ Object
This returns a Contract initialized from the serialize_ib_ruby format string.
274 275 276 277 278 279 |
# File 'lib/ib-ruby/datatypes.rb', line 274 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
290 291 292 293 294 295 296 |
# File 'lib/ib-ruby/datatypes.rb', line 290 def init super @combo_legs = Array.new @strike = 0 @sec_type = '' end |
#reset ⇒ Object
212 213 214 215 |
# File 'lib/ib-ruby/datatypes.rb', line 212 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.
282 283 284 285 286 287 288 |
# File 'lib/ib-ruby/datatypes.rb', line 282 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:
269 270 271 |
# File 'lib/ib-ruby/datatypes.rb', line 269 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.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/ib-ruby/datatypes.rb', line 237 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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/ib-ruby/datatypes.rb', line 218 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
298 299 300 |
# File 'lib/ib-ruby/datatypes.rb', line 298 def to_human "<IB-Contract: " + [symbol, expiry, sec_type, strike, right, exchange, currency].join("-") + "}>" end |
#to_s ⇒ Object
306 307 308 |
# File 'lib/ib-ruby/datatypes.rb', line 306 def to_s to_human end |
#to_short ⇒ Object
302 303 304 |
# File 'lib/ib-ruby/datatypes.rb', line 302 def to_short "#{symbol}#{expiry}#{strike}#{right}#{exchange}#{currency}" end |