finnhubrb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/FinnhubRB.gemspec +24 -0
- data/Gemfile +12 -0
- data/LICENSE.md +21 -0
- data/README.md +237 -0
- data/lib/Analysis.rb +15 -0
- data/lib/Calendar.rb +19 -0
- data/lib/Client.rb +106 -0
- data/lib/Country.rb +17 -0
- data/lib/Crypto.rb +59 -0
- data/lib/Economic.rb +18 -0
- data/lib/Error.rb +9 -0
- data/lib/Forex.rb +59 -0
- data/lib/Stock.rb +55 -0
- data/lib/Timeseries.rb +55 -0
- data/lib/Websocket.rb +29 -0
- data/lib/finnhubrb.rb +16 -0
- data/spec/1.0.0/crypto.rb +84 -0
- data/spec/1.0.0/forex.rb +84 -0
- data/spec/1.0.0/other.rb +62 -0
- data/spec/1.0.0/stock.rb +112 -0
- data/spec/1.0.0/websocket.rb +48 -0
- data/spec/all.rb +5 -0
- data/spec/config.yml +1 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/test_all.rb +5 -0
- metadata +202 -0
data/spec/1.0.0/other.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "1.0.0" do
|
4
|
+
context "Other" do
|
5
|
+
it "create a new client" do
|
6
|
+
@store[:client] = Finnhub::Client.new(key: @key, verbose: true)
|
7
|
+
expect(@store[:client].class).to be Finnhub::Client
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can retrieve news" do
|
11
|
+
output = @store[:client].news(category: "forex")
|
12
|
+
expect(output[0][:datetime].class).to be Integer
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can retrieve merge countries" do
|
16
|
+
output = @store[:client].merge_countries(plain: true)
|
17
|
+
expect(output).to include "France"
|
18
|
+
@store[:country] = output[0]
|
19
|
+
|
20
|
+
output = @store[:client].merge_countries
|
21
|
+
expect(output[0].class).to be Finnhub::Merge_Country
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can retrieve merge countries" do
|
25
|
+
country = @store[:client].merge_country(country: @store[:country])
|
26
|
+
mergers = country.merger
|
27
|
+
expect(mergers[0][:targetNation]).to eq @store[:country]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can retrieve economic codes" do
|
31
|
+
output = @store[:client].economic_codes(plain: true)
|
32
|
+
expect(output.size).to be > 100
|
33
|
+
@store[:economic_code] = output[0][0]
|
34
|
+
|
35
|
+
output = @store[:client].economic_codes
|
36
|
+
expect(output[0].class).to be Finnhub::Economic_Code
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can retrieve economic codes" do
|
40
|
+
economic = @store[:client].economic_code(code: @store[:economic_code])
|
41
|
+
output = economic.data(plain: true)
|
42
|
+
expect(output[0][0].class).to eq String
|
43
|
+
|
44
|
+
output = economic.data
|
45
|
+
expect(output[0][0].class).to eq Time
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can retrieve calendars" do
|
49
|
+
calendar = @store[:client].economic_calendar
|
50
|
+
expect(calendar.key?(:economicCalendar)).to eq true
|
51
|
+
|
52
|
+
calendar = @store[:client].earnings_calendar
|
53
|
+
expect(calendar.key?(:earningsCalendar)).to eq true
|
54
|
+
|
55
|
+
calendar = @store[:client].ipo_calendar
|
56
|
+
expect(calendar.key?(:ipoCalendar)).to eq true
|
57
|
+
|
58
|
+
calendar = @store[:client].ico_calendar
|
59
|
+
expect(calendar.key?(:icoCalendar)).to eq true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/1.0.0/stock.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe "1.0.0" do
|
4
|
+
context "Stock" do
|
5
|
+
it "create a new client" do
|
6
|
+
@store[:client] = Finnhub::Client.new(key: @key, verbose: true)
|
7
|
+
expect(@store[:client].class).to be Finnhub::Client
|
8
|
+
end
|
9
|
+
|
10
|
+
it "create a new stock" do
|
11
|
+
@store[:stock] = @store[:client].stock(symbol: "AAPL")
|
12
|
+
expect(@store[:stock].symbol).to eq "AAPL"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can retrieve a profile" do
|
16
|
+
output = @store[:stock].profile
|
17
|
+
|
18
|
+
expect(output[:ticker]).to eq "AAPL"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can retrieve a ceo_compensation" do
|
22
|
+
output = @store[:stock].ceo_compensation
|
23
|
+
|
24
|
+
expect(output[:companyName]).to eq "Apple Inc."
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can retrieve a recommendation" do
|
28
|
+
output = @store[:stock].recommendation
|
29
|
+
|
30
|
+
expect(output[0][:symbol]).to eq "AAPL"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can retrieve a price_target" do
|
34
|
+
output = @store[:stock].price_target
|
35
|
+
|
36
|
+
expect(output[:symbol]).to eq "AAPL"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can retrieve a option_chain" do
|
40
|
+
output = @store[:stock].option_chain
|
41
|
+
|
42
|
+
expect(output[:code]).to eq "AAPL"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can retrieve a peers" do
|
46
|
+
output = @store[:stock].peers(plain: true)
|
47
|
+
expect(output).to include "ALOT"
|
48
|
+
|
49
|
+
output2 = @store[:stock].peers[0].profile
|
50
|
+
expect(output2[:ticker]).to eq output[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can retrieve a earnings" do
|
54
|
+
output = @store[:stock].earnings
|
55
|
+
|
56
|
+
expect(output[0][:symbol]).to eq "AAPL"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can retrieve a news" do
|
60
|
+
output = @store[:stock].news
|
61
|
+
|
62
|
+
expect(output[0][:related]).to eq "AAPL"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "can retrieve a sentiment" do
|
66
|
+
output = @store[:stock].sentiment
|
67
|
+
|
68
|
+
expect(output[:symbol]).to eq "AAPL"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "can retrieve timeseries" do
|
72
|
+
timeseries = @store[:stock].timeseries(count: 100)
|
73
|
+
expect(timeseries.open.class).to be Array
|
74
|
+
expect(timeseries.high.class).to be Array
|
75
|
+
expect(timeseries.low.class).to be Array
|
76
|
+
expect(timeseries.close.class).to be Array
|
77
|
+
expect(timeseries.volume.class).to be Array
|
78
|
+
expect(timeseries.status).to eq "ok"
|
79
|
+
expect(timeseries.output.class).to be Hash
|
80
|
+
|
81
|
+
timeseries = @store[:stock].timeseries(resolution: 60, from: Time.now-24*30*3600, to: Time.now)
|
82
|
+
expect(timeseries.open.class).to be Array
|
83
|
+
expect(timeseries.status).to eq "ok"
|
84
|
+
|
85
|
+
timeseries = @store[:stock].timeseries(resolution: 60, from: Time.now-24*30*3600, to: Time.now, format: "csv")
|
86
|
+
expect(timeseries.output.class).to be String
|
87
|
+
|
88
|
+
error = nil
|
89
|
+
begin
|
90
|
+
@store[:stock].timeseries(resolution: 60, from: Time.now-24*30*3600, to: Time.now, format: "wrong")
|
91
|
+
rescue Finnhub::Error => e
|
92
|
+
error = e
|
93
|
+
end
|
94
|
+
expect(error.class).to be Finnhub::Error
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can retrieve pattern" do
|
98
|
+
output = @store[:stock].pattern
|
99
|
+
expect(output[:points][0].key?(:symbol)).to eq true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "can retrieve support_resistance" do
|
103
|
+
output = @store[:stock].support_resistance
|
104
|
+
expect(output.key?(:levels)).to be true
|
105
|
+
end
|
106
|
+
|
107
|
+
it "can retrieve technical_indicators" do
|
108
|
+
output = @store[:stock].technical_indicators
|
109
|
+
expect(output.key?(:technicalAnalysis)).to be true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require "thread"
|
3
|
+
|
4
|
+
describe "1.0.0" do
|
5
|
+
context "Websocket" do
|
6
|
+
before :all do
|
7
|
+
@client = Finnhub::Client.new(key: @key, verbose: true)
|
8
|
+
@result = {result: nil}
|
9
|
+
@websocket = nil
|
10
|
+
Thread.new do
|
11
|
+
EM.run do
|
12
|
+
@websocket = @client.websocket
|
13
|
+
@websocket.on :message do |event|
|
14
|
+
puts event.data
|
15
|
+
@result[:result] = event.data
|
16
|
+
end
|
17
|
+
@websocket.on :close do |event|
|
18
|
+
puts [:close, event.code, event.reason]
|
19
|
+
@result[:result] = [:close, event.code, event.reason]
|
20
|
+
@websocket = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
sleep(0.5)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can subscribe" do
|
28
|
+
@websocket.subscribe("AAPL")
|
29
|
+
error = true
|
30
|
+
10.times do
|
31
|
+
if @result[:result].nil?
|
32
|
+
error = false
|
33
|
+
break
|
34
|
+
else
|
35
|
+
sleep(0.5)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
expect(error).to be false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can unsubscribe" do
|
42
|
+
@websocket.unsubscribe("AAPL")
|
43
|
+
@result[:result] = nil
|
44
|
+
sleep(0.5)
|
45
|
+
expect(@result[:result].nil?).to be true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/all.rb
ADDED
data/spec/config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
key: "bn0s9fvrh5r8qh5rphq0"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "pry-byebug"
|
3
|
+
require "yaml"
|
4
|
+
# require_relative "../lib/finnhub"
|
5
|
+
require "finnhubrb"
|
6
|
+
require "openssl"
|
7
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.color = true
|
11
|
+
config.before(:all) do
|
12
|
+
val = YAML.load_file("#{__dir__}/config.yml")
|
13
|
+
@key = val["key"]
|
14
|
+
@store = {}
|
15
|
+
end
|
16
|
+
end
|
data/spec/test_all.rb
ADDED
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: finnhubrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefano Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.17.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.17.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.17.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.17.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: oj
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.9.0
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 3.9.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.9.0
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.9.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: faye-websocket
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.10.9
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.10.9
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.10.9
|
70
|
+
- - "~>"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.10.9
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: pry-byebug
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: rspec
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.5'
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.5'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.5'
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '3.5'
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
name: awesome_print
|
109
|
+
requirement: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '1.7'
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '1.7'
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '1.7'
|
124
|
+
- - "~>"
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '1.7'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: eventmachine
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.2.7
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.2.7
|
137
|
+
type: :development
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 1.2.7
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 1.2.7
|
147
|
+
description: A ruby wrapper for Finnhub's HTTP API
|
148
|
+
email:
|
149
|
+
- stefano.martin87@gmail.com
|
150
|
+
executables: []
|
151
|
+
extensions: []
|
152
|
+
extra_rdoc_files: []
|
153
|
+
files:
|
154
|
+
- FinnhubRB.gemspec
|
155
|
+
- Gemfile
|
156
|
+
- LICENSE.md
|
157
|
+
- README.md
|
158
|
+
- lib/Analysis.rb
|
159
|
+
- lib/Calendar.rb
|
160
|
+
- lib/Client.rb
|
161
|
+
- lib/Country.rb
|
162
|
+
- lib/Crypto.rb
|
163
|
+
- lib/Economic.rb
|
164
|
+
- lib/Error.rb
|
165
|
+
- lib/Forex.rb
|
166
|
+
- lib/Stock.rb
|
167
|
+
- lib/Timeseries.rb
|
168
|
+
- lib/Websocket.rb
|
169
|
+
- lib/finnhubrb.rb
|
170
|
+
- spec/1.0.0/crypto.rb
|
171
|
+
- spec/1.0.0/forex.rb
|
172
|
+
- spec/1.0.0/other.rb
|
173
|
+
- spec/1.0.0/stock.rb
|
174
|
+
- spec/1.0.0/websocket.rb
|
175
|
+
- spec/all.rb
|
176
|
+
- spec/config.yml
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/test_all.rb
|
179
|
+
homepage: https://github.com/StefanoMartin/FinnhubRB
|
180
|
+
licenses:
|
181
|
+
- MIT
|
182
|
+
metadata: {}
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubygems_version: 3.0.3
|
199
|
+
signing_key:
|
200
|
+
specification_version: 4
|
201
|
+
summary: A gem for Alpha Vantage
|
202
|
+
test_files: []
|