class IB::IBSocket

Public Instance Methods

read_array(&block) click to toggle source

Returns loaded Array or [] if count was 0

# File lib/ib/socket.rb, line 68
def read_array &block
  count = read_int
  count > 0 ? Array.new(count, &block) : []
end
read_boolean() click to toggle source
# File lib/ib/socket.rb, line 32
def read_boolean
  str = self.read_string
  str.nil? ? false : str.to_i != 0
end
read_decimal() click to toggle source
# File lib/ib/socket.rb, line 37
def read_decimal
  # Floating-point numbers shouldn't be used to store money...
  # ...but BigDecimals are too unwieldy to use in this case... maybe later
  #  self.read_string.to_d
  self.read_string.to_f
end
read_decimal_limit(limit = -1) click to toggle source

If received decimal is below limit (“not yet computed”), return nil

# File lib/ib/socket.rb, line 53
def read_decimal_limit limit = -1
  value = self.read_decimal
  # limit is the "not yet computed" indicator
  value <= limit ? nil : value
end
Also aliased as: read_decimal_limit_1
read_decimal_limit_1(limit = -1)
Alias for: read_decimal_limit
read_decimal_limit_2() click to toggle source
# File lib/ib/socket.rb, line 61
def read_decimal_limit_2
  read_decimal_limit -2
end
read_decimal_max() click to toggle source
# File lib/ib/socket.rb, line 44
def read_decimal_max
  str = self.read_string
  # Floating-point numbers shouldn't be used to store money...
  # ...but BigDecimals are too unwieldy to use in this case... maybe later
  #  str.nil? || str.empty? ? nil : str.to_d
  str.to_f unless str.nil? || str.empty? || str.to_f > 1.797 * 10.0 ** 306
end
read_hash() click to toggle source

Returns loaded Hash

# File lib/ib/socket.rb, line 74
def read_hash
  tags = read_array { |_| [read_string, read_string] }
  tags.empty? ? Hash.new : Hash[*tags.flatten]
end
read_int() click to toggle source
# File lib/ib/socket.rb, line 23
def read_int
  self.read_string.to_i
end
read_int_max() click to toggle source
# File lib/ib/socket.rb, line 27
def read_int_max
  str = self.read_string
  str.to_i unless str.nil? || str.empty?
end
read_string() click to toggle source
# File lib/ib/socket.rb, line 11
def read_string
  string = self.gets(EOL)

  until string
    # Silently ignores nils
    string = self.gets(EOL)
    sleep 0.1
  end

  string.chop
end
write_data(data) click to toggle source

Sends null terminated data string into socket

# File lib/ib/socket.rb, line 7
def write_data data
  self.syswrite(data.to_s + EOL)
end