diff --git a/lib/ib/messages/incoming/historical_data.rb b/lib/ib/messages/incoming/historical_data.rb index 2235d77..7d924a0 100644 --- a/lib/ib/messages/incoming/historical_data.rb +++ b/lib/ib/messages/incoming/historical_data.rb @@ -41,12 +41,12 @@ def load IB::Bar.new :time => buffer.read_int_date, # conversion of epoche-time-integer to Dateime # requires format_date in request to be "2" # (outgoing/bar_requests # RequestHistoricalData#Encoding) - :open => buffer.read_decimal, - :high => buffer.read_decimal, - :low => buffer.read_decimal, - :close => buffer.read_decimal, + :open => buffer.read_float, + :high => buffer.read_float, + :low => buffer.read_float, + :close => buffer.read_float, :volume => buffer.read_int, - :wap => buffer.read_decimal, + :wap => buffer.read_float, # :has_gaps => buffer.read_string, # only in ServerVersion < 124 :trades => buffer.read_int end @@ -79,6 +79,26 @@ def load end end + HistoricalDataUpdate = def_message [90, 0] , + [:request_id, :int] , + [:count, :int], + [:bar, :bar] # defined in support.rb + + class HistoricalDataUpdate + attr_accessor :results + using IBSupport # extended Array-Class from abstract_message + + def bar + @bar = IB::Bar.new @data[:bar] + end + + def to_human + "" + end + end + + + end # module Incoming end # module Messages end # module IB diff --git a/lib/ib/support.rb b/lib/ib/support.rb index 767614d..85471f9 100644 --- a/lib/ib/support.rb +++ b/lib/ib/support.rb @@ -62,7 +62,7 @@ def read_xml def read_int_date t= read_int - s= Time.at(t) + s= Time.at(t.to_i) # s.year == 1970 --> data is most likely a date-string s.year == 1970 ? Date.parse(t.to_s) : s end @@ -139,20 +139,35 @@ def read_hash end # - def read_contract # read a standard contract and return als hash - { con_id: read_int, - symbol: read_string, - sec_type: read_string, - expiry: read_string, - strike: read_decimal, - right: read_string, - multiplier: read_int, - exchange: read_string, - currency: read_string, - local_symbol: read_string, - trading_class: read_string } # new Version 8 - - end + def read_contract # read a standard contract and return als hash + { con_id: read_int, + symbol: read_string, + sec_type: read_string, + expiry: read_string, + strike: read_decimal, + right: read_string, + multiplier: read_int, + exchange: read_string, + currency: read_string, + local_symbol: read_string, + trading_class: read_string } # new Version 8 + end + + + def read_bar # read a standard bar (Historical data bars) + { :time => read_int_date, # conversion of epoche-time-integer to Dateime + # requires format_date in request to be "2" + # (outgoing/bar_requests # RequestHistoricalData#Encoding) + :open => read_float, + :high => read_float, + :low => read_float, + :close => read_float, + :wap => read_float, + :volume => read_int, + # :has_gaps => read_string, # only in ServerVersion < 124 + :trades => read_int } + + end alias read_bool read_boolean diff --git a/lib/models/ib/bar.rb b/lib/models/ib/bar.rb index 734b4c4..8d02e51 100644 --- a/lib/models/ib/bar.rb +++ b/lib/models/ib/bar.rb @@ -22,7 +22,7 @@ class Bar < IB::Model validates_numericality_of :open, :high, :low, :close, :volume def to_human - "" end