cotcube-bardata 0.1.2 → 0.1.3

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: 7cc8f5a19330f55ec26073d90b2c7da30547b61903daa93f8b2977c05ad308f8
4
- data.tar.gz: 3dac9e49fb0143d8dd91a86f5a7779dcb25a5c8fca719de5b23a46a5e742380f
3
+ metadata.gz: e879208e6163ff7f56d5b4135e62e67e4054426e98d446fd13742fe34bbb6935
4
+ data.tar.gz: 8bafe1a22673d497a55c201870b94b9561d3a01cb523606900e8592c0d0b1c6d
5
5
  SHA512:
6
- metadata.gz: aafb4160d474f4f4d0694faee22821f1e8a65a510dcc2c84999acce0e0f3b7511dc52cd2d28cb21856162fbed9c5fa2e9b8e65b8065b7c1603128f8ef1cdea75
7
- data.tar.gz: 51ba4678419a6daf9f4d2a18810432f2f3c93c7a6417e8d0e7beae822e76ad9214450bfb1bf4479fc30c4032b51e4504c923e707f6ea8feff295f16071040df3
6
+ metadata.gz: e8bbe5746c9c07435a80b647d222ea6420b5057c1b26e4370f0e1dccedae71028fb54fb25f45ef47719501f0b297c928a6d589ca7a0dfb67a02e40836d2ff1d4
7
+ data.tar.gz: 6cb37bdbc50a0c4fd2f9867dd983c6348df5a8f9372e0195e6c0f4dfd90463057e993b5a3c57a39b7f932166ad09f325dbff77311473513575cdd874d728a136
@@ -1,3 +1,8 @@
1
+ ## 0.1.3 (December 23, 2020)
2
+ - added .provide_most_liquids_by_eod which supports :age, filtering out files that have been updated more recently
3
+ - added 'type' to symbols to filter for e.g. currencies
4
+ - changed .provide_eods not to raise on missing eod-file but just to WARN
5
+
1
6
  ## 0.1.2 (December 22, 2020)
2
7
  - created and added .provide_quarters
3
8
  - added cotcube-helpers as new dependency to gempsec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -30,6 +30,7 @@ module Cotcube
30
30
  :provide, #
31
31
  :most_liquid_for, # the most_liquid contract for a given symbol or id, based on date or last_trade_date
32
32
  :provide_eods, # provides the list of eods, either with data or just the contracts, filtered for liquidity threshold
33
+ :provide_most_liquids_by_eod,
33
34
  :provide_daily, # provides the list of dailies for a given symbol, which include OI. Note that the close is settlement price.
34
35
  :continuous, # for a given date or range, provide all contracts that exceed a given threshold of volume share
35
36
  :continuous_overview, # based on continuous, create list of when which contract was most liquid
@@ -3,7 +3,7 @@
3
3
  module Cotcube
4
4
  module Bardata
5
5
 
6
- def most_liquid_for(symbol: nil, id: nil, date: last_trade_date, config: init)
6
+ def most_liquid_for(symbol: nil, id: nil, date: last_trade_date, config: init, quiet: false)
7
7
  unless symbol.nil?
8
8
  symbol_id = symbols.select{|s| s[:symbol] == symbol.to_s.upcase}.first[:id]
9
9
  raise ArgumentError, "Could not find match in #{config[:symbols_file]} for given symbol #{symbol}" if symbol_id.nil?
@@ -14,14 +14,30 @@ module Cotcube
14
14
  provide_eods(id: id, dates: date, contracts_only: true).first
15
15
  end
16
16
 
17
-
17
+ def provide_most_liquids_by_eod(config: init, date: last_trade_date, filter: :volume_part, age: 1.hour)
18
+ eods = provide_eods(config: config, dates: date, filter: filter)
19
+ result = []
20
+ eods.map do |eod|
21
+ symbol = eod[0..1]
22
+ contract = eod[2..4]
23
+ sym = symbols.select{|s| s[:symbol] == symbol.to_s.upcase}.first
24
+ quarter = "#{config[:data_path]}/quarters/#{sym[:id]}/#{contract}.csv"
25
+ if File.exist?(quarter)
26
+ puts "#{quarter}: #{ Time.now } - #{File.mtime(quarter)} > #{age} : #{Time.now - File.mtime(quarter) > age}"
27
+ result << eod if Time.now - File.mtime(quarter) > age
28
+ else
29
+ result << eod
30
+ end
31
+ end
32
+ result
33
+ end
18
34
 
19
35
  def provide_eods(symbol: nil,
20
36
  id: nil,
21
37
  contract: nil,
22
38
  config: init,
23
39
  dates: last_trade_date, # should accept either a date or datelike or date string OR a range of 2 datelike
24
- # if omitted returns the eods of last trading date
40
+ # if omitted returns the eods of last trading date
25
41
  threshold: 0.1, # set threshold to 0 to disable filtering at all. otherwise only contracts with partial of >= threshold are returned
26
42
  filter: :volume_part, # filter can be set to volume_part and oi_part. determines, which property is used for filtering.
27
43
  contracts_only: true # set to false to return the complete row instead of just the contracts matching filter and threshold
@@ -52,7 +68,10 @@ module Cotcube
52
68
  id_path = id_path_get.call(i)
53
69
  data_file = "#{id_path}/#{d}.csv"
54
70
  raise RuntimeError, "No data found for requested :id (#{id_path} does not exist)" unless Dir.exist?(id_path)
55
- raise RuntimeError, "No data found for requested contract #{symbol}:#{contract} in #{id_path}." unless File.exist?(data_file)
71
+ unless File.exist?(data_file)
72
+ puts "WARNING: No data found for requested id/symbol #{id}/#{symbol} in #{id_path}.".light_yellow unless quiet
73
+ return []
74
+ end
56
75
  data = CSV.read(data_file, headers: %i[contract date open high low close volume oi] ).map do |row|
57
76
  row = row.to_h
58
77
  row.each do |k, _|
@@ -4,7 +4,7 @@ module Cotcube
4
4
  module Bardata
5
5
 
6
6
 
7
- def symbols(config: init)
7
+ def symbols(config: init, type: nil)
8
8
  if config[:symbols_file].nil?
9
9
  SYMBOL_EXAMPLES
10
10
  else
@@ -13,6 +13,7 @@ module Cotcube
13
13
  .map{|row| row.to_h }
14
14
  .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row }
15
15
  .reject{|row| row[:id].nil? }
16
+ .tap{|all| all.select!{|x| x[:type] == type} unless type.nil? }
16
17
  end
17
18
  end
18
19
 
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.2
4
+ version: 0.1.3
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: 2020-12-22 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cotcube-indicators