lib/cotcube-bardata/helpers.rb
# small helper to select a specific full trading day from quarters (or reduced)
#   this special handling is needed, as full trading days start '5pm CT yesterday'
small helper to select a specific full trading day from quarters (or reduced)
this special handling is needed, as full trading days start '5pm CT yesterday'
small helper to select a specific full trading day from quarters ( or reduced ) this special handling is needed as full trading days start ' 5pm CT yesterday '
def compare(contract:, format: '%5.2f')
      format = "%#{format}" unless format[0] == '%'
      daily = provide(contract: contract, interval: :daily)
      full  = provide(contract: contract, interval: :days, filter: :full)
      rth   = provide(contract: contract, interval: :days, filter: :rth)
      rth_dates = rth.map { |x| x[:datetime] }
      daily.select! { |x| rth_dates.include? x[:datetime].to_datetime }
      full.select! {  |x| rth_dates.include? x[:datetime].to_datetime }
      printer = lambda { |z|
           "#{z[:datetime].strftime('%m-%d') 
         }\t#{format format, z[:open]
         }\t#{format format, z[:high]
         }\t#{format format, z[:low]
         }\t#{format format, z[:close]
         }\t#{format '%7d', z[:volume]}"
      }
      daily.each_with_index do |_x, i|
        puts "DAILY #{printer.call daily[i]}"
        puts "FULL  #{printer.call full[i]}"
        puts "RTH   #{printer.call rth[i]}"
        puts ' '
      end
    end
def compare ( contract : , format : '%5.2f' ) format = "%#{format}" unless format [ 0 ] == '%' daily = provide ( contract : contract , interval : :daily ) full = provide ( contract : contract , interval : :days , filter : :full ) rth = provide ( contract : contract , interval : :days , filter : :rth ) rth_dates = rth . map { | x | x [ :datetime ] } daily . select! { | x | rth_dates . include? x [ :datetime ] . to_datetime } full . select! { | x | rth_dates . include? x [ :datetime ] . to_datetime } printer = lambda { | z | "#{z[:datetime].strftime('%m-%d') # rubocop:disable Layout/IndentationWidth
         }\t#{format format, z[:open]
         }\t#{format format, z[:high]
         }\t#{format format, z[:low]
         }\t#{format format, z[:close]
         }\t#{format '%7d', z[:volume]}" } daily . each_with_index do | _x , i | puts "DAILY #{printer.call daily[i]}" puts "FULL  #{printer.call full[i]}" puts "RTH   #{printer.call rth[i]}" puts ' ' end end
small helper to select a specific full trading day from quarters (or reduced)
this special handling is needed, as full trading days start '5pm CT yesterday'
small helper to select a specific full trading day from quarters ( or reduced ) this special handling is needed as full trading days start ' 5pm CT yesterday '
# rubocop:disable Layout/ClosingParenthesisIndentation # rubocop:disable Layout/IndentationWidth # rubocop:enable Layout/ClosingParenthesisIndentation
contract
<not_specific>
format
<not_specific>