cotcube-bardata 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5607a73308b8d9d7aff10caccdd3785189072a7d5b2a0b37ea0b6d2bd1ebf4f9
4
- data.tar.gz: 18bf8b90e2aad0d32a6608037de861d5383df1bd6d8c6b11e903724c91f172df
3
+ metadata.gz: 6b1f66885f510fbe8be92a8e543f7206220db76940825862115c60be6892d5d4
4
+ data.tar.gz: a12e509a14c41cc17e31d95fca73d09ab09c342b029e973baf30377ebe8f1d6a
5
5
  SHA512:
6
- metadata.gz: 3589e6b49ba104aed0177032cd46299c2c0e1db37330e2b869ab6a97f8b81400917bf29ec631cb37b2f35245ece8dcdb147dd56194487d441773d8c79628d38e
7
- data.tar.gz: 3be51d9604d9fb1092939b30fa099801c989babae6ec528479d8af5c8b8750e087dc5965f8b05a3cc5d68281a58de93295cba1b2249030a106220b0eea9594bd
6
+ metadata.gz: dc53284daf85e21387ba1d7b24b3e2518be8dae3d49f6b2893e6aa6442e082516be12f76f23001ad3f04aee3e3ae5601ae7e747fd8451d5d9a437c7ac2b45976
7
+ data.tar.gz: 3b496b4e75e73feee1dbc08fd355572471ba78eb1b692c91e81dd3b1f515eab510cab0d22bc712cabab84cfe621a536e91a81e0925ce897e8d48c05770b0b015
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.13 (April 07, 2021)
2
+ - daily: fixed const_caching in continuous
3
+ - trade_dates: FIXING call with HTTParty must send Agent Header
4
+ - helpers/get_id_set: added support for params given as Symbols (:NG instead of 'NG')
5
+
1
6
  ## 0.1.12 (March 13, 2021)
2
7
  - range_matrix: adapted to accept block for range provision; added params :days_only and :last_n
3
8
  - minor fix on previous patch
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -8,6 +8,7 @@ module Cotcube
8
8
  symbol: nil, id: nil,
9
9
  range: nil,
10
10
  timezone: Time.find_zone('America/Chicago'),
11
+ keep_last: false,
11
12
  config: init)
12
13
  contract = contract.to_s.upcase
13
14
  unless contract.is_a?(String) && [3, 5].include?(contract.size)
@@ -48,7 +49,7 @@ module Cotcube
48
49
  row[:type] = :daily
49
50
  row
50
51
  end
51
- data.pop if data.last[:high].zero?
52
+ data.pop if data.last[:high].zero? and not keep_last
52
53
  if range.nil?
53
54
  data
54
55
  else
@@ -68,6 +69,7 @@ module Cotcube
68
69
  measuring.call("Starting")
69
70
  sym = get_id_set(symbol: symbol, id: id)
70
71
  id = sym[:id]
72
+ symbol = sym[:symbol]
71
73
  id_path = "#{config[:data_path]}/daily/#{id}"
72
74
  c_file = "#{id_path}/continuous.csv"
73
75
 
@@ -158,7 +160,7 @@ module Cotcube
158
160
  oi: x[:contracts].sort_by { |z| - z[:oi] }[0..4].compact.reject { |z| z[:oi].zero? }
159
161
  }
160
162
  end
161
- measuring.call("Retrieved continuous")
163
+ measuring.call("Retrieved continuous for #{sym[:symbol]}")
162
164
  data.reject! { |x| x[selector].empty? }
163
165
  result = data.group_by { |x| x[selector].first[:contract] }
164
166
  result.each_key do |key|
@@ -194,6 +196,7 @@ module Cotcube
194
196
  selector: :volume,
195
197
  filter: nil,
196
198
  date: Date.today,
199
+ short: true,
197
200
  measure: nil,
198
201
  debuglevel: 1,
199
202
  debug: false)
@@ -230,39 +233,47 @@ module Cotcube
230
233
  measuring.call("Retrieved continous_overview")
231
234
  output_sent = []
232
235
  early_year=nil
236
+ long_output = []
233
237
  data.keys.sort.each do |month|
238
+ current_long = { month: month }
234
239
  puts "Processing #{sym[:symbol]}#{month}" if debuglevel > 1
235
240
  v0 = data[month]
236
- ydays = v0.map { |_, v1| Date.parse(v1.last[:date]).yday }
241
+ ldays = v0.map { |_, v1| Date.parse(v1.last[:date]).yday }
237
242
  fdays = v0.map { |_, v1| Date.parse(v1.first[:date]).yday }.sort
238
243
  # if the last ml day nears the end of the year, we must fix
239
- ydays.map! { |x| x > 350 ? x - 366 : x } if ydays.min < 50
244
+ ldays.map! { |x| x > 350 ? x - 366 : x } if ldays.min < 50
240
245
  fday = fdays[fdays.size / 2]
241
- yavg = ydays.reduce(:+) / ydays.size
242
- # a contract is proposed to use after fday - 1, but before ydays.min (green)
243
- # it is warned to user after fday - 1 but before yavg - 1 (red)
244
- # it is warned red >= yavg - 1 and <= yavg + 1
245
- color = if (ytoday >= yavg - 1) && (ytoday <= yavg + 1)
246
+ lavg = ldays.reduce(:+) / ldays.size
247
+ # a contract is proposed to use after fday - 1, but before ldays.min (green)
248
+ # it is warned to user after fday - 1 but before lavg - 1 (red)
249
+ # it is warned red >= lavg - 1 and <= lavg + 1
250
+ color = if (ytoday >= lavg - 1) && (ytoday <= lavg + 1)
246
251
  :light_red
247
- elsif (ytoday > ydays.min) && (ytoday < yavg - 1)
252
+ elsif (ytoday > ldays.min) && (ytoday < lavg - 1)
248
253
  :light_yellow
249
- elsif (ytoday >= (fday > yavg ? 0 : fday - 5)) && (ytoday <= ydays.min)
254
+ elsif (ytoday >= (fday > lavg ? 0 : fday - 5)) && (ytoday <= ldays.min)
250
255
  :light_green
251
256
  else
252
257
  :white
253
258
  end
254
259
  # rubocop:disable Layout/ClosingParenthesisIndentation
260
+ long_output << {
261
+ month: month,
262
+ first_ml: fday,
263
+ last_min: ldays.min,
264
+ last_avg: lavg,
265
+ last_max: ldays.max }
255
266
  output = "#{sym[:symbol]
256
267
  }#{month
257
268
  }\t#{format '%12s', sym[:type]
258
- }\t#{ytoday
259
- }/#{fday
260
- }\t#{format '%5d', ydays.min
261
- }: #{dfm.call(ydays.min)
262
- }\t#{format '%5d', yavg
263
- }: #{dfm.call(yavg)
264
- }\t#{format '%5d', ydays.max
265
- }: #{dfm.call(ydays.max)}".colorize(color)
269
+ }\ttoday is #{ytoday
270
+ } -- median of first is #{fday
271
+ }\tlast ranges from #{format '%5d', ldays.min
272
+ }: #{dfm.call(ldays.min)
273
+ }\t#{format '%5d', lavg
274
+ }: #{dfm.call(lavg)
275
+ }\tto #{format '%5d', ldays.max
276
+ }: #{dfm.call(ldays.max)}".colorize(color)
266
277
  if debug || (color != :white)
267
278
  puts output
268
279
  output_sent << "#{sym[:symbol]}#{month}" unless color == :white
@@ -273,12 +284,12 @@ module Cotcube
273
284
  v0.each do |contract, v1|
274
285
  puts "\t#{contract
275
286
  }\t#{v1.first[:date]
276
- }\t#{Date.parse(v1.last[:date]).strftime('%a')
277
- }, #{v1.last[:date]
278
- } (#{Date.parse(v1.last[:date]).yday}"
287
+ } (#{format '%3d', Date.parse(v1.first[:date]).yday
288
+ })\t#{Date.parse(v1.last[:date]).strftime('%a, %Y-%m-%d')
289
+ } (#{Date.parse(v1.last[:date]).yday})"
279
290
  # rubocop:enable Layout/ClosingParenthesisIndentation
280
291
  end
281
- end
292
+ end
282
293
  case output_sent.size
283
294
  when 0
284
295
  puts "WARNING: No output was sent for symbol '#{sym[:symbol]}'.".colorize(:light_yellow)
@@ -288,11 +299,10 @@ module Cotcube
288
299
  # all ok
289
300
  true
290
301
  else
291
- puts "---- #{output_sent} for #{sym[:symbol]} ---------------"
292
-
302
+ puts "Continuous table show #{output_sent.size} active contracts ( #{output_sent} ) for #{sym[:symbol]} ---------------"
293
303
  end
294
304
  measuring.call("Finished processing")
295
- output_sent
305
+ short ? output_sent : long_output
296
306
  end
297
307
  end
298
308
  end
@@ -46,6 +46,10 @@ module Cotcube
46
46
  end
47
47
 
48
48
  def get_id_set(symbol: nil, id: nil, contract: nil, config: init)
49
+ contract = contract.to_s.upcase if contract.is_a? Symbol
50
+ id = id.to_s.upcase if id.is_a? Symbol
51
+ symbol = symbol.to_s.upcase if symbol.is_a? Symbol
52
+
49
53
  if contract.is_a?(String) && (contract.length == 5)
50
54
  c_symbol = contract[0..1]
51
55
  if (not symbol.nil?) && (symbol != c_symbol)
@@ -38,7 +38,6 @@ module Cotcube
38
38
 
39
39
  %i[days weeks months].each do |period|
40
40
  next if days_only and %i[weeks months].include? period
41
- p yield(source[period].first)
42
41
  source[period].map! do |x|
43
42
  x[:range] = block_given? ? yield(x) : (((x[:high] - x[:low]) / sym[:ticksize]).round)
44
43
  x
@@ -8,7 +8,7 @@ module Cotcube
8
8
  def last_trade_date
9
9
  uri = 'https://www.cmegroup.com/CmeWS/mvc/Volume/TradeDates?exchange=CME'
10
10
  begin
11
- HTTParty.get(uri)
11
+ HTTParty.get(uri, headers: { "User-Agent" => "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"})
12
12
  .parsed_response
13
13
  .map do |x|
14
14
  a = x['tradeDate'].chars.each_slice(2).map(&:join)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-bardata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin L. Tischendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-13 00:00:00.000000000 Z
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport