Sha256: 178c4ebeddf38bd9a62a344c3e5705a61ca7509f5a732ec7c6e9c811269af730

Contents?: true

Size: 796 Bytes

Versions: 11

Compression:

Stored size: 796 Bytes

Contents

# frozen_string_literal: true

module Cotcube
  # missing top level documentation
  module Bardata
    # fetching official trade dates from CME
    # it returns the current trade date or, if today isn't a trading day, the last trade date.
    def last_trade_date
      uri = 'https://www.cmegroup.com/CmeWS/mvc/Volume/TradeDates?exchange=CME'
      begin
        HTTParty.get(uri)
                .parsed_response
                .map do |x|
                  a = x['tradeDate'].chars.each_slice(2).map(&:join)
                  "#{a[0]}#{a[1]}-#{a[2]}-#{a[3]}"
                end
                .first
      rescue StandardError
        nil
      end
    end

    def holidays(config: init)
      CSV.read("#{config[:data_path]}/holidays.csv").map{|x| DateTime.parse(x[0])}
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cotcube-bardata-0.1.12 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.11 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.10 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.9.3 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.9.2 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.9.1 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.8 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.7 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.6 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.5 lib/cotcube-bardata/trade_dates.rb
cotcube-bardata-0.1.4 lib/cotcube-bardata/trade_dates.rb