cotcube-bardata 0.1.16 → 0.1.17

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: aa52a5fd519f8351f712e30495d4dda59bb37a4d4b588c84904d1971d7ad734c
4
- data.tar.gz: b1eaacc5e75d13d84edf8c095cdaebc7ec588fe0e61ef6dc764d2a5633fedece
3
+ metadata.gz: 2bb98a590c08cbd0dafba80850aab164befd778fb6425e67e304a7fc909f9411
4
+ data.tar.gz: cc3ec5166d4610605c0afd14c16f07798e092c537c82b2ed19d9a3326c10b642
5
5
  SHA512:
6
- metadata.gz: 1798e058b377f50f2efe78f8f6b0936763ce29686a639f10e893914202ca27f4469665d9520d7adcda4df5f4346e5f9f87e8ce229c389ac78dde666335f1efd3
7
- data.tar.gz: 8e245ebcea3acdde99f7c5673f97024432648938e530fd9ae11dae4b7f67091a5128536fa70c0e4ba0cb372d85f7c713460249da574278501e60f4bf66ebf1ac
6
+ metadata.gz: 8a85816eefa18b6b72d98c9f6642881784678a99d1b4e402129bdcbe613ee0827ffd389bf996da31408306bf6a2f3ba8fe3cbd992b462460362b935d3e24dde2
7
+ data.tar.gz: 0f227bf5199375e04cda8382787170e2654689278eb93ac59f0573523030aecde9771f9a035a1b321f626e500a040ab01c5a35199ea54a63293adbf97357f2a0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.17 (December 06, 2021)
2
+ - changed parameter for building of continuous (in daily.rb)
3
+ - added bin/intra + symbols. improved bin/daily
4
+ - bin/*: created (sym, daily) and improved (eod) cmd wrappers
5
+ - daily.rb: improved silence in .continuous
6
+
1
7
  ## 0.1.16 (November 23, 2021)
2
8
  - bin/eod.rb: little helper to display eod data in bash resp. in xinetdhttpservice
3
9
  - eods.rb: minor change to adapt move of symbols to Helpers
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.16
1
+ 0.1.17
data/bin/daily.rb ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/cotcube-bardata'
4
+ require 'cotcube-level'
5
+ require 'cotcube-indicators'
6
+ CcI = Cotcube::Indicators
7
+
8
+ def exit_with_error(err)
9
+ msg = { error: 1, message: "#{err}" }
10
+ p msg.to_json
11
+ exit 1
12
+ end
13
+
14
+
15
+ contract = ARGV[0].nil? ? nil : ARGV[0].upcase
16
+ if contract.nil?
17
+ exit_with_error('No contract given')
18
+ end
19
+
20
+ output = true
21
+
22
+ sym = Cotcube::Helpers.get_id_set(symbol: contract[..1])
23
+ # TODO: apply daylight time pimped diff to all relevant datetimes in series
24
+ timediff = if %w[ NYBOT NYMEX ].include? sym[:exchange]
25
+ 5.hours
26
+ elsif %w[ DTB ].include? sym[:exchane]
27
+ 1.hour
28
+ else
29
+ 6.hours
30
+ end
31
+
32
+ continuous = %w[currencies interest indices].include? sym[:type]
33
+ intraday = false
34
+ interval = intraday ? 30.minutes : 1.day
35
+ ema_period = 50
36
+
37
+ indicators = {
38
+ ema_high: CcI.ema(key: :high, length: ema_period, smoothing: 2),
39
+ ema_low: CcI.ema(key: :low, length: ema_period, smoothing: 2)
40
+ }
41
+
42
+ dailybase = []
43
+ stencil = nil
44
+ stencil = Cotcube::Level::EOD_Stencil.new( interval: :daily, swap_type: :full)
45
+ dailybase = if continuous
46
+ Cotcube::Bardata.continuous(symbol: contract[..1], indicators: indicators)[-300..].
47
+ map{ |z|
48
+ z[:datetime] = DateTime.parse(z[:date])
49
+ z.delete(:contracts)
50
+ z
51
+ }
52
+ else
53
+ Cotcube::Bardata.provide_daily(contract: contract, indicators: indicators)[-300..]
54
+ end
55
+
56
+ base = dailybase
57
+ base.select!{|z| z[:high]}
58
+
59
+ scaleBreaks = []
60
+ brb = stencil.base
61
+ brb.each_with_index.map{|z,i|
62
+ next if i.zero?
63
+ if brb[i][:datetime] - brb[i-1][:datetime] > (intraday ? 1 : 1.day) and brb[i][:datetime] > base.first[:datetime] and brb[i-1][:datetime] < base.last[:datetime]
64
+ scaleBreaks << { startValue: brb[i-1][:datetime] + 0.5 * interval, endValue: brb[i][:datetime] - 0.5 * interval }
65
+ end
66
+ } unless base.empty?
67
+
68
+ pkg = {
69
+ base: base,
70
+ breaks: scaleBreaks
71
+ }
72
+
73
+ puts pkg.to_json if output
data/bin/eod.rb CHANGED
@@ -3,6 +3,16 @@
3
3
  require_relative '../lib/cotcube-bardata.rb'
4
4
 
5
5
  symbol = ARGV[0].nil? ? nil : ARGV[0].upcase
6
+ json = ARGV.include? 'json'
6
7
 
7
- s = Cotcube::Bardata.provide_eods(threshold: 0.10, contracts_only: false, symbol: symbol, filter: :oi_part)
8
- s.each {|x| puts x.values.to_csv}
8
+ begin
9
+ s = Cotcube::Bardata.provide_eods(threshold: 0.10, contracts_only: false, symbol: symbol, filter: :oi_part)
10
+ if json
11
+ p s.to_json
12
+ else
13
+ s.each {|x| puts x.values.to_csv}
14
+ end
15
+ rescue
16
+ msg = { error: 503, message: "Could not processes symbol '#{symbol}'." }
17
+ p msg.to_json
18
+ end
data/bin/intra.rb ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cotcube-bardata'
4
+ require 'cotcube-level'
5
+ require 'cotcube-indicators'
6
+
7
+ def exit_with_error(err)
8
+ msg = { error: 1, message: "#{err}" }
9
+ p msg.to_json
10
+ exit 1
11
+ end
12
+
13
+
14
+ contract = ARGV[0].nil? ? nil : ARGV[0].upcase
15
+
16
+ debug = ARGV.include? 'debug'
17
+ if contract.nil?
18
+ exit_with_error('No contract given')
19
+ end
20
+
21
+ sym = Cotcube::Helpers.get_id_set(symbol: contract[..1])
22
+ # TODO: apply daylight time pimped diff to all relevant datetimes in series
23
+ timediff = if %w[ NYBOT NYMEX ].include? sym[:exchange]
24
+ 5.hours
25
+ elsif %w[ DTB ].include? sym[:exchane]
26
+ 1.hour
27
+ else
28
+ 6.hours
29
+ end
30
+
31
+ continuous = %w[currencies interest indices].include? sym[:type]
32
+ interval = 30.minutes
33
+
34
+ intrabase = []
35
+ istencil = []
36
+ collector_threads = []
37
+
38
+ collector_threads << Thread.new do
39
+ istencil = Cotcube::Level::Intraday_Stencil.new( interval: 30.minutes, swap_type: :full, asset: :full, weeks: 8)
40
+ end
41
+
42
+ collector_threads << Thread.new do
43
+ begin
44
+ intrabase = JSON.parse(Cotcube::Helpers::DataClient.new.get_historical(contract: contract, interval: :min30, duration: '3_W' ), symbolize_names: true)[:base].
45
+ map{ |z|
46
+ z[:datetime] = DateTime.parse(z[:time])
47
+ %i[time created_at wap trades].each{|k| z.delete(k)}
48
+ z
49
+ }
50
+ rescue
51
+ intrabase = []
52
+ end
53
+ end
54
+
55
+ collector_threads.each(&:join)
56
+
57
+ base = intrabase
58
+ base.select!{|z| z[:high]}
59
+
60
+ scaleBreaks = []
61
+ brb = istencil.base
62
+ brb.each_with_index.map{|z,i|
63
+ next if i.zero?
64
+ if brb[i][:datetime] - brb[i-1][:datetime] > (1) and brb[i][:datetime] > base.first[:datetime] and brb[i-1][:datetime] < base.last[:datetime]
65
+ scaleBreaks << { startValue: brb[i-1][:datetime] + 0.5 * interval, endValue: brb[i][:datetime] - 0.5 * interval }
66
+ end
67
+ } unless base.empty?
68
+
69
+ pkg = {
70
+ sym: sym,
71
+ base: base,
72
+ breaks: scaleBreaks
73
+ }
74
+
75
+ puts pkg.to_json
data/bin/sym.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cotcube-level'
4
+ require 'cotcube-helpers'
5
+ include Cotcube::Helpers
6
+ require_relative '../lib/cotcube-bardata.rb'
7
+
8
+ contract = ARGV[0].nil? ? nil : ARGV[0].upcase
9
+
10
+ begin
11
+ s = Cotcube::Helpers.get_id_set(symbol: contract[..1])
12
+ p s.to_json
13
+ rescue
14
+ msg = { error: 503, message: "Could not process contract '#{contract}'." }
15
+ p msg.to_json
16
+ end
data/bin/symbols.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cotcube-helpers'
4
+
5
+ begin
6
+ s = Cotcube::Helpers.symbols + Cotcube::Helpers.micros
7
+ p s.to_json
8
+ rescue
9
+ msg = { error: 503, message: "Could not provide symbols." }
10
+ p msg.to_json
11
+ end
@@ -116,7 +116,7 @@ module Cotcube
116
116
  # this boosts from 4.5sec to 0.3sec
117
117
  rewriting = (force_rewrite or not(File.exist?(c_file)) or (Time.now - File.mtime(c_file) > 8.days))
118
118
  if rewriting
119
- puts "In daily+continuous: Rewriting #{c_file} #{force_rewrite ? "forcibly" : "due to fileage"}.".light_yellow
119
+ puts "In daily+continuous: Rewriting #{c_file} #{force_rewrite ? "forcibly" : "due to fileage"}.".light_yellow if debug
120
120
  `rm #{c_file}; find #{id_path} | xargs cat 2>/dev/null | grep -v ',0,' | grep -v ',0$'| sort -t, -k2 | cut -d, -f1-8 | grep ',.*,' | uniq > #{c_file}`
121
121
  end
122
122
  loading = lambda do
@@ -394,7 +394,7 @@ module Cotcube
394
394
  last_avg: lavg,
395
395
  last_max: ldays.max,
396
396
  until_start: fday - ytoday,
397
- until_end: ldays.min - ytoday
397
+ until_end: lavg - ytoday
398
398
  }
399
399
  current[:until_end] += 365 if current[:until_end] - current[:until_start] < 0
400
400
  current[:until_end] -= 365 if current[:until_end] > 365
@@ -78,12 +78,14 @@ module Cotcube
78
78
  # l_symbol = l_sym[:symbol]
79
79
  id_path = id_path_get.call(i)
80
80
  data_file = "#{id_path}/#{d}.csv"
81
+ current_sym = Cotcube::Helpers.get_id_set(id: i, config: config)
81
82
  raise "No data found for requested :id (#{id_path} does not exist)" unless Dir.exist?(id_path)
82
83
 
83
84
  unless File.exist?(data_file)
84
85
  unless quiet
85
- puts 'WARNING: No data found for requested id/symbol'\
86
- " #{id}/#{symbol} in #{id_path} for #{d}.".colorize(:light_yellow)
86
+ puts 'WARNING: No data found for requested symbol'\
87
+ " #{current_sym[:symbol]} in #{id_path} for #{d}.".colorize(:light_yellow)
88
+
87
89
  end
88
90
  return []
89
91
  end
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.16
4
+ version: 0.1.17
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-11-23 00:00:00.000000000 Z
11
+ date: 2021-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,7 +164,11 @@ files:
164
164
  - README.md
165
165
  - Rakefile
166
166
  - VERSION
167
+ - bin/daily.rb
167
168
  - bin/eod.rb
169
+ - bin/intra.rb
170
+ - bin/sym.rb
171
+ - bin/symbols.rb
168
172
  - cotcube-bardata.gemspec
169
173
  - lib/cotcube-bardata.rb
170
174
  - lib/cotcube-bardata/cached.rb