Class: IB::OutgoingMessages::AbstractMessage

Inherits:
ExtremelyAbstractMessage show all
Defined in:
lib/ib-ruby/messages.rb

Instance Attribute Summary

Attributes inherited from ExtremelyAbstractMessage

#created_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExtremelyAbstractMessage

#to_human

Constructor Details

#initialize(data = nil) ⇒ AbstractMessage

data is a Hash.



51
52
53
54
# File 'lib/ib-ruby/messages.rb', line 51

def initialize(data=nil)
  @created_at = Time.now
  @data = Datatypes::StringentHash.new(data)
end

Class Method Details

.message_idObject



46
47
48
# File 'lib/ib-ruby/messages.rb', line 46

def self.message_id
  raise Exception("AbstractMessage.message_id called - you need to override this in a subclass.")
end

Instance Method Details

#queueObject



78
79
80
# File 'lib/ib-ruby/messages.rb', line 78

def queue
  raise Exception("AbstractMessage.queue() called - you need to override this in a subclass.")
end

#send(server) ⇒ Object

This causes the message to send itself over the server socket in server. “server” is the @server instance variable from the IB object. You can also use this to e.g. get the server version number.

Subclasses can either override this method for precise control over how stuff gets sent to the server, or else define a method queue() that returns an Array of elements that ought to be sent to the server by calling to_s on each one and postpending a ‘0’.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ib-ruby/messages.rb', line 66

def send(server)
  self.queue(server).each {|datum|

    # TWS wants to receive booleans as 1 or 0... rewrite as
    # necessary.
    datum = "1" if datum == true
    datum = "0" if datum == false

   server[:socket].syswrite(datum.to_s + "\0")
 }
end