accern 3.0.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +61 -2
- data/accern.gemspec +1 -1
- data/bin/console +6 -6
- data/lib/accern/alpha.rb +20 -6
- data/lib/accern/cli.rb +43 -3
- data/lib/accern/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d98bb97d1e447d5ab00d4543d233a81c79320976
|
4
|
+
data.tar.gz: dbb9c2da127d6da30b59406b1cee447be57c5767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae51b0a920b3fd85d90ac62226055232daa7598dbe19292670e39206356ff519788cccdc1c6dee2d1e56879ef3381f7093450e548153d6dfb25496a0c7fad33
|
7
|
+
data.tar.gz: f8a5b856fe9aaa653c46022646697d9a8ab40a603b853f5fdbc6535996a0f04abf9698776371b59d4d647d395134341259985a406c9b8f738e9655db4808785a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,11 @@ A command line interface for the Accern API. Which is used for streaming the rea
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
```shell
|
10
|
-
|
10
|
+
# default macOS Ruby
|
11
|
+
$ sudo gem install accern
|
12
|
+
|
13
|
+
# When using a Ruby version manager
|
14
|
+
$ gem install accern
|
11
15
|
```
|
12
16
|
|
13
17
|
## Usage
|
@@ -26,7 +30,62 @@ The the next time you run `accern` the client will begin streaming the full data
|
|
26
30
|
To reset and bring up the getting started prompts run:
|
27
31
|
|
28
32
|
```shell
|
29
|
-
accern --init
|
33
|
+
$ accern --init
|
34
|
+
```
|
35
|
+
|
36
|
+
### Filter by ticker
|
37
|
+
|
38
|
+
```shell
|
39
|
+
# single ticker
|
40
|
+
$ accern --ticker appl
|
41
|
+
|
42
|
+
# multiple tickers
|
43
|
+
$ accern --ticker "appl,amzn"
|
44
|
+
```
|
45
|
+
|
46
|
+
### Filter by ticker file
|
47
|
+
Create a newline delimited ticker file:
|
48
|
+
|
49
|
+
```
|
50
|
+
appl
|
51
|
+
amzn
|
52
|
+
```
|
53
|
+
|
54
|
+
```shell
|
55
|
+
$ accern --ticker-file ./my_tickers.txt
|
56
|
+
```
|
57
|
+
|
58
|
+
### Filter by index
|
59
|
+
|
60
|
+
The index value must be one of the following values
|
61
|
+
|
62
|
+
index | expected value
|
63
|
+
-----------------|----------------------
|
64
|
+
S&P 500 | sp500
|
65
|
+
Russell 1000 | russell1000
|
66
|
+
Russell 3000 | russell3000
|
67
|
+
Wilshire 5000 | wilshire5000
|
68
|
+
Barron's 400 | barrons400
|
69
|
+
DOW 30 | dow30
|
70
|
+
|
71
|
+
```shell
|
72
|
+
# single index
|
73
|
+
$ accern --index sp500
|
74
|
+
|
75
|
+
# multiple indexes
|
76
|
+
$ accern --index "dow30,russell1000"
|
77
|
+
```
|
78
|
+
|
79
|
+
### Filter by index file
|
80
|
+
Create a newline delimited index file with the any of the allowed values:
|
81
|
+
|
82
|
+
```
|
83
|
+
dow30
|
84
|
+
sp500
|
85
|
+
```
|
86
|
+
|
87
|
+
```shell
|
88
|
+
$ accern --index-file ./my_indexes.txt
|
30
89
|
```
|
31
90
|
|
32
91
|
## Contributing
|
data/accern.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'accern/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'accern'
|
8
8
|
spec.version = Accern::VERSION
|
9
|
-
spec.authors = ['Carlos Espejo']
|
9
|
+
spec.authors = ['Carlos Espejo', 'Kerry Imai']
|
10
10
|
spec.email = ['vendors@accern.com']
|
11
11
|
spec.summary = 'A command line interface for the Accern API.'
|
12
12
|
spec.homepage = 'https://github.com/Accern/accern'
|
data/bin/console
CHANGED
@@ -12,14 +12,14 @@ require 'pry'
|
|
12
12
|
# require "irb"
|
13
13
|
# IRB.start(__FILE__)
|
14
14
|
|
15
|
-
# args = ['-h']
|
16
|
-
# args = []
|
17
15
|
|
18
|
-
args = {token: "0652400596ecf80e014176dd4bc17044",
|
19
|
-
format: :json}
|
20
16
|
|
21
|
-
a = Accern::Alpha.new(args)
|
22
17
|
|
23
|
-
# c = Accern::Cli.new(args)
|
24
18
|
|
19
|
+
ticker = "amzn,aapl"
|
20
|
+
# ["--ticker", "aapp,amaz,lol"]
|
21
|
+
# token: '08b14780c4b4aae5ac97d92c33d25495',
|
22
|
+
args = {format: :json, index: "sp500"}
|
23
|
+
c = Accern::Cli.new( args: ["--index", "sp500,barrons400"])
|
25
24
|
binding.pry
|
25
|
+
# ticker=amzn&
|
data/lib/accern/alpha.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Accern
|
2
2
|
class Alpha
|
3
3
|
attr_reader :token, :base_url, :uri, :last_id, :new_id, :docs,
|
4
|
-
:format, :flat, :params
|
4
|
+
:format, :flat, :params, :ticker, :index
|
5
5
|
|
6
|
-
def initialize(token:, format: :json
|
6
|
+
def initialize(token:, ticker:, index:, format: :json)
|
7
7
|
@token = token
|
8
|
+
@ticker = ticker
|
9
|
+
@index = index
|
8
10
|
@format = format
|
9
11
|
@params = params
|
10
12
|
@base_url = 'http://feed.accern.com/v3/alphas'
|
@@ -14,9 +16,7 @@ module Accern
|
|
14
16
|
end
|
15
17
|
|
16
18
|
def download(path)
|
17
|
-
|
18
|
-
puts uri
|
19
|
-
|
19
|
+
create_uri
|
20
20
|
format_response(
|
21
21
|
Net::HTTP.new(uri.host, uri.port).request_get(uri, header)
|
22
22
|
)
|
@@ -42,15 +42,29 @@ module Accern
|
|
42
42
|
puts e.backtrace
|
43
43
|
end
|
44
44
|
|
45
|
-
def download_loop(path)
|
45
|
+
def download_loop(path:)
|
46
46
|
loop do
|
47
47
|
download(path)
|
48
48
|
sleep 8
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
|
53
|
+
def create_uri
|
54
|
+
uri.query = URI.encode_www_form(combine_query)
|
55
|
+
puts uri
|
56
|
+
end
|
57
|
+
|
52
58
|
private
|
53
59
|
|
60
|
+
def combine_query
|
61
|
+
filters = Hash.new
|
62
|
+
filters[:ticker] = ticker unless ticker.empty?
|
63
|
+
filters[:last_id] = last_id if last_id
|
64
|
+
filters[:index] = index unless index.empty?
|
65
|
+
filters
|
66
|
+
end
|
67
|
+
|
54
68
|
def header
|
55
69
|
{ 'Authorization' => %(Token token="#{token}"), 'User-Agent' => "Accern #{VERSION} (#{RUBY_PLATFORM})" }
|
56
70
|
end
|
data/lib/accern/cli.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Accern
|
2
2
|
class Cli
|
3
3
|
attr_reader :stdout, :stdin, :token, :filetype, :valid_types, :config_path,
|
4
|
-
:options, :args, :feed
|
4
|
+
:options, :args, :feed, :tickers,:indexes
|
5
|
+
|
5
6
|
|
6
7
|
def initialize(stdout: $stdout, stdin: $stdin, args: [], feed: Alpha)
|
7
8
|
@stdout = stdout
|
@@ -12,6 +13,8 @@ module Accern
|
|
12
13
|
@valid_types = %w(json csv)
|
13
14
|
@config_path = "#{ENV['HOME']}/.accern.rc.yml"
|
14
15
|
@feed = feed
|
16
|
+
@tickers = []
|
17
|
+
@indexes = []
|
15
18
|
end
|
16
19
|
|
17
20
|
def start
|
@@ -21,8 +24,8 @@ module Accern
|
|
21
24
|
if options[:init]
|
22
25
|
ask_for_info
|
23
26
|
else
|
24
|
-
feed.new(token: token, format: filetype.to_sym)
|
25
|
-
.download_loop('./feed.jsonl')
|
27
|
+
feed.new(token: token, format: filetype.to_sym, ticker: tickers.join(','), index: indexes.join(','))
|
28
|
+
.download_loop(path: './feed.jsonl')
|
26
29
|
end
|
27
30
|
end
|
28
31
|
|
@@ -58,13 +61,45 @@ module Accern
|
|
58
61
|
puts Accern::VERSION
|
59
62
|
exit
|
60
63
|
end
|
64
|
+
|
65
|
+
opts.on("--ticker NAME", "Filters document by ticker") do |tic|
|
66
|
+
|
67
|
+
options[:ticker] = tic.to_s.downcase.split(',')
|
68
|
+
@tickers += options[:ticker]
|
69
|
+
end
|
70
|
+
|
71
|
+
opts.on("--ticker-file PATH", "Receives the path to a file that has tickers") do |t_path|
|
72
|
+
options[:ticker_path] = t_path
|
73
|
+
@tickers += read_file(t_path)
|
74
|
+
end
|
75
|
+
|
76
|
+
index_options = ['sp500', 'russell1000', 'russell3000', 'wilshire5000', 'barrons400', 'dow30']
|
77
|
+
opts.on("--index TYPE", "Filters document by index") do |i|
|
78
|
+
options[:index] = i.to_s.downcase.split(',')
|
79
|
+
options[:index] = sanitizes_input(options[:index])
|
80
|
+
raise OptionParser::InvalidArgument.new("Invalid index options") unless (options[:index] - index_options).empty?
|
81
|
+
@indexes += options[:index]
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on("--index-file PATH", "get filter indexes from file") do |i_path|
|
85
|
+
parsed = read_file(i_path)
|
86
|
+
parsed = sanitizes_input(parsed)
|
87
|
+
raise OptionParser::InvalidArgument.new("Invalid index options") unless (parsed - index_options).empty?
|
88
|
+
@indexes += parsed
|
89
|
+
end
|
90
|
+
|
61
91
|
end
|
62
92
|
|
63
93
|
parser.parse!(args)
|
94
|
+
@tickers = sanitizes_input(@tickers)
|
64
95
|
end
|
65
96
|
|
66
97
|
private
|
67
98
|
|
99
|
+
def sanitizes_input(arg)
|
100
|
+
arg.map {|t| t.gsub(/\W/, '')}
|
101
|
+
end
|
102
|
+
|
68
103
|
def ask_for_info
|
69
104
|
ask_for_token
|
70
105
|
# ask_for_filetype
|
@@ -93,5 +128,10 @@ module Accern
|
|
93
128
|
File.write(config_path, config.to_yaml)
|
94
129
|
stdout.puts 'Your client is now configured and settings saved to ~/.accern.rc.yml.'
|
95
130
|
end
|
131
|
+
|
132
|
+
def read_file(path)
|
133
|
+
return [] unless File.exist?(path)
|
134
|
+
File.readlines(path).map { |x| x.downcase.chomp }
|
135
|
+
end
|
96
136
|
end
|
97
137
|
end
|
data/lib/accern/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: accern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Espejo
|
8
|
+
- Kerry Imai
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2017-
|
12
|
+
date: 2017-03-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|