lib/cotcube-bardata/helpers.rb
# diminishes a given base of bars to fit into a given range (DO NOT CONFUSE with trading_hours)
# note that the last bar is simply required to _start_ within the given range, not to end withing
diminishes a given base of bars to fit into a given range (DO NOT CONFUSE with trading_hours)
note that the last bar is simply required to _start_ within the given range, not to end withing
diminishes a given base of bars to fit into a given range ( DO NOT CONFUSE with trading_hours ) note that the last bar is simply required to _start_ within the given range not to end withing
def extended_select_for_range(base:,
                                  range: ('1900-01-01'...'2100-01-01'),
                                  timezone: Time.find_zone('America/Chicago'),
                                  quiet: false)
      starting = range.begin
      starting = timezone.parse(starting) if starting.is_a? String
      ending   = range.end
      ending   = timezone.parse(ending) if ending.is_a? String
      puts "#{starting}\t#{ending}" unless quiet
      if starting.hour.zero? && starting.min.zero? && ending.hour.zero? && ending.min.zero?
        unless quiet
          puts 'WARNING: When sending midnight, full trading day'\
            ' is assumed (starting 5 pm CT yesterday, ending 4 pm CT today)'.colorize(:light_yellow)
        end
        result = select_specific_date(date: starting, base: base)
        result += base.select { |d| d[:datetime] >= starting and d[:datetime] < ending.to_date }
        result += select_specific_date(date: ending, base: base)
        result.uniq!
      else
        result = base.select { |x| x[:datetime] >= starting and x[:datetime] <= ending }
      end
      result
    end
def extended_select_for_range ( base : , range : ( '1900-01-01' ... '2100-01-01' ) , timezone : Time . find_zone ( 'America/Chicago' ) , quiet : false ) starting = range . begin starting = timezone . parse ( starting ) if starting . is_a? String ending = range . end ending = timezone . parse ( ending ) if ending . is_a? String puts "#{starting}\t#{ending}" unless quiet if starting . hour . zero? && starting . min . zero? && ending . hour . zero? && ending . min . zero? unless quiet puts 'WARNING: When sending midnight, full trading day' ' is assumed (starting 5 pm CT yesterday, ending 4 pm CT today)' . colorize ( :light_yellow ) end result = select_specific_date ( date : starting , base : base ) result += base . select { | d | d [ :datetime ] >= starting and d [ :datetime ] < ending . to_date } result += select_specific_date ( date : ending , base : base ) result . uniq! else result = base . select { | x | x [ :datetime ] >= starting and x [ :datetime ] <= ending } end result end
diminishes a given base of bars to fit into a given range (DO NOT CONFUSE with trading_hours)
note that the last bar is simply required to _start_ within the given range, not to end withing
diminishes a given base of bars to fit into a given range ( DO NOT CONFUSE with trading_hours ) note that the last bar is simply required to _start_ within the given range not to end withing
base
<not_specific>
range
<not_specific>
timezone
<not_specific>
find_zone
<not_specific>
quiet
<not_specific>