alphavantagerb 1.0.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.
@@ -0,0 +1,44 @@
1
+ require_relative './../../spec_helper'
2
+
3
+ describe Alphavantage::Sector do
4
+ context "#new" do
5
+ it "create a new sector without client" do
6
+ sleep(1); exchange = Alphavantage::Sector.new key: @config["key"]
7
+ expect(exchange.class).to eq Alphavantage::Sector
8
+ end
9
+
10
+ it "create a new sector with client" do
11
+ sleep(1); exchange = @client.sector
12
+ expect(exchange.class).to eq Alphavantage::Sector
13
+ end
14
+
15
+ it "has several parameters" do
16
+ sleep(1); exchange = @client.sector
17
+ bool = []
18
+ bool << exchange.information.is_a?(String)
19
+ bool << exchange.last_refreshed.is_a?(String)
20
+ bool << exchange.hash.is_a?(Hash)
21
+ bool << exchange.real_time_performance.is_a?(Hash)
22
+ bool << exchange.one_day_performance.is_a?(Hash)
23
+ bool << exchange.five_day_performance.is_a?(Hash)
24
+ bool << exchange.one_month_performance.is_a?(Hash)
25
+ bool << exchange.three_month_performance.is_a?(Hash)
26
+ bool << exchange.year_to_date_performance.is_a?(Hash)
27
+ bool << exchange.one_year_performance.is_a?(Hash)
28
+ bool << exchange.three_year_performance.is_a?(Hash)
29
+ bool << exchange.five_year_performance.is_a?(Hash)
30
+ bool << exchange.ten_year_performance.is_a?(Hash)
31
+ expect(bool.all?{|e| e}).to eq true
32
+ end
33
+
34
+ it "cannot retrieve with wrong key" do
35
+ error = false
36
+ begin
37
+ sleep(1); stock = Alphavantage::Sector.new key:"wrong_key"
38
+ rescue Alphavantage::Error => e
39
+ error = true
40
+ end
41
+ expect(error).to eq true
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ require_relative './../../spec_helper'
2
+
3
+ describe Alphavantage::Stock do
4
+ context "#new" do
5
+ it "create a new stock without client" do
6
+ stock = Alphavantage::Stock.new symbol: "MSFT", key: @config["key"]
7
+ expect(stock.class).to eq Alphavantage::Stock
8
+ end
9
+
10
+ it "create a new stock from client" do
11
+ stock = @client.stock symbol: "MSFT"
12
+ expect(stock.class).to eq Alphavantage::Stock
13
+ end
14
+
15
+ it "can change datatype" do
16
+ bool = []
17
+ stock = @client.stock symbol: "MSFT"
18
+ bool << stock.datatype
19
+ begin
20
+ stock.datatype = "ciao"
21
+ rescue Alphavantage::Error => e
22
+ bool << "error"
23
+ end
24
+ stock.datatype = "csv"
25
+ bool <<stock.datatype
26
+ stock.datatype = "json"
27
+ expect(bool).to eq ["json", "error", "csv"]
28
+ end
29
+
30
+ it "can create a new timeseries from stock" do
31
+ stock = @client.stock symbol: "MSFT"
32
+ sleep(1); timeseries = stock.timeseries
33
+ expect(timeseries.class).to eq Alphavantage::Timeseries
34
+ end
35
+
36
+ it "can create a new indicator from stock" do
37
+ stock = @client.stock symbol: "MSFT"
38
+ sleep(1); indicator = stock.indicator function: "SMA"
39
+ expect(indicator.class).to eq Alphavantage::Indicator
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,101 @@
1
+ require_relative './../../spec_helper'
2
+
3
+ describe Alphavantage::Stock do
4
+ context "#new" do
5
+ it "create a new timeseries without stock" do
6
+ stock = Alphavantage::Timeseries.new symbol: "MSFT", key: @config["key"], verbose: false
7
+ expect(stock.class).to eq Alphavantage::Timeseries
8
+ end
9
+
10
+ it "create a new stock from stock" do
11
+ sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "compact")
12
+ expect(timeseries.class).to eq Alphavantage::Timeseries
13
+ end
14
+
15
+ it "own multiple data" do
16
+ sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "full")
17
+ bool = []
18
+ bool << timeseries.information.is_a?(String)
19
+ bool << (timeseries.symbol == "MSFT")
20
+ bool << timeseries.last_refreshed.is_a?(String)
21
+ bool << (timeseries.output_size == "Full size")
22
+ bool << timeseries.time_zone.is_a?(String)
23
+ bool << timeseries.hash.is_a?(Hash)
24
+ bool << timeseries.open.is_a?(Array)
25
+ bool << timeseries.high.is_a?(Array)
26
+ bool << timeseries.low.is_a?(Array)
27
+ bool << timeseries.close.is_a?(Array)
28
+ bool << timeseries.volume("asc").is_a?(Array)
29
+ expect(bool.all?{|e| e}).to eq true
30
+ end
31
+
32
+ it "can retrieve intraday" do
33
+ sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "intraday", interval: "30min")
34
+ bool = []
35
+ bool << timeseries.information.is_a?(String)
36
+ bool << (timeseries.symbol == "MSFT")
37
+ bool << timeseries.last_refreshed.is_a?(String)
38
+ bool << (timeseries.interval == "30min")
39
+ bool << (timeseries.output_size == "Compact")
40
+ bool << timeseries.time_zone.is_a?(String)
41
+ bool << timeseries.hash.is_a?(Hash)
42
+ bool << timeseries.open.is_a?(Array)
43
+ bool << timeseries.high.is_a?(Array)
44
+ bool << timeseries.low.is_a?(Array)
45
+ bool << timeseries.close.is_a?(Array)
46
+ bool << timeseries.volume("asc").is_a?(Array)
47
+ expect(bool.all?{|e| e}).to eq true
48
+ end
49
+
50
+ it "can retrieve adjusted data" do
51
+ sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "compact", adjusted: true)
52
+ bool = []
53
+ bool << timeseries.information.is_a?(String)
54
+ bool << (timeseries.symbol == "MSFT")
55
+ bool << timeseries.last_refreshed.is_a?(String)
56
+ bool << (timeseries.output_size == "Compact")
57
+ bool << timeseries.time_zone.is_a?(String)
58
+ bool << timeseries.hash.is_a?(Hash)
59
+ bool << timeseries.open.is_a?(Array)
60
+ bool << timeseries.high.is_a?(Array)
61
+ bool << timeseries.low.is_a?(Array)
62
+ bool << timeseries.close.is_a?(Array)
63
+ bool << timeseries.adjusted_close.is_a?(Array)
64
+ bool << timeseries.dividend_amount.is_a?(Array)
65
+ bool << timeseries.split_coefficient.is_a?(Array)
66
+ bool << timeseries.volume("asc").is_a?(Array)
67
+ expect(bool.all?{|e| e}).to eq true
68
+ end
69
+
70
+ it "can retrieve csv files" do
71
+ bool = []
72
+ directory = "#{__dir__}/test.csv"
73
+ bool << File.exists?(directory)
74
+ sleep(1); @client.stock(symbol: "MSFT").timeseries(type: "daily",
75
+ outputsize: "compact", adjusted: true, datatype: "csv", file: directory)
76
+ bool << File.exists?(directory)
77
+ File.delete(directory)
78
+ expect(bool).to eq [false, true]
79
+ end
80
+
81
+ it "cannot retrieve with wrong key" do
82
+ error = false
83
+ begin
84
+ sleep(1); stock = Alphavantage::Timeseries.new symbol: "MSFT", key:"wrong key"
85
+ rescue Alphavantage::Error => e
86
+ error = true
87
+ end
88
+ expect(error).to eq true
89
+ end
90
+
91
+ it "cannot retrieve with wrong symbol" do
92
+ error = false
93
+ begin
94
+ sleep(1); stock = Alphavantage::Timeseries.new symbol: "wrong_symbol", key: @config["key"]
95
+ rescue Alphavantage::Error => e
96
+ error = true
97
+ end
98
+ expect(error).to eq true
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,16 @@
1
+ require "rspec"
2
+ require "pry-byebug"
3
+ require "yaml"
4
+ require "openssl"
5
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
6
+ require "alphavantagerb"
7
+ # require_relative File.expand_path('../../lib/alphavantagerb', __FILE__)
8
+
9
+ RSpec.configure do |config|
10
+ config.color = true
11
+ config.before(:all) do
12
+ @config = YAML::load_file(File.join(__dir__, 'config.yml'))
13
+ @client = Alphavantage::Client.new key: @config["key"]
14
+ @stock = @client.stock(symbol: "MSFT")
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "lib/1.0.0/client"
2
+ require_relative "lib/1.0.0/crypto_timeseries"
3
+ require_relative "lib/1.0.0/crypto"
4
+ require_relative "lib/1.0.0/exchange"
5
+ require_relative "lib/1.0.0/indicator"
6
+ require_relative "lib/1.0.0/sector"
7
+ require_relative "lib/1.0.0/stock"
8
+ require_relative "lib/1.0.0/timeseries"
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alphavantagerb
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: 2017-11-23 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.15.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: humanize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.0
41
+ description: A ruby wrapper for Alpha Vantage's HTTP API
42
+ email:
43
+ - stefano.martin87@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - AlphavantageRB.gemspec
49
+ - Gemfile
50
+ - LICENSE.md
51
+ - README.md
52
+ - lib/Client.rb
53
+ - lib/Crypto.rb
54
+ - lib/Crypto_Timeseries.rb
55
+ - lib/Errors.rb
56
+ - lib/Exchange.rb
57
+ - lib/Indicator.rb
58
+ - lib/Sector.rb
59
+ - lib/Stock.rb
60
+ - lib/Timeseries.rb
61
+ - lib/alphavantagerb.rb
62
+ - lib/helper_function.rb
63
+ - spec/config.yml
64
+ - spec/lib/1.0.0/client.rb
65
+ - spec/lib/1.0.0/crypto.rb
66
+ - spec/lib/1.0.0/crypto_timeseries.rb
67
+ - spec/lib/1.0.0/exchange.rb
68
+ - spec/lib/1.0.0/indicator.rb
69
+ - spec/lib/1.0.0/sector.rb
70
+ - spec/lib/1.0.0/stock.rb
71
+ - spec/lib/1.0.0/timeseries.rb
72
+ - spec/spec_helper.rb
73
+ - spec/test_all.rb
74
+ homepage: https://github.com/StefanoMartin/AlphaVantageRB
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.12
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A gem for Alpha Vantage
98
+ test_files: []