alphavantagerb 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,21 +3,21 @@ require_relative './../../spec_helper'
3
3
  describe Alphavantage::Sector do
4
4
  context "#new" do
5
5
  it "create a new sector without client" do
6
- sleep(1); exchange = Alphavantage::Sector.new key: @config["key"]
6
+ exchange = Alphavantage::Sector.new key: @config["key"]
7
7
  expect(exchange.class).to eq Alphavantage::Sector
8
8
  end
9
9
 
10
10
  it "create a new sector with client" do
11
- sleep(1); exchange = @client.sector
11
+ exchange = @client.sector
12
12
  expect(exchange.class).to eq Alphavantage::Sector
13
13
  end
14
14
 
15
15
  it "has several parameters" do
16
- sleep(1); exchange = @client.sector
16
+ exchange = @client.sector
17
17
  bool = []
18
18
  bool << exchange.information.is_a?(String)
19
19
  bool << exchange.last_refreshed.is_a?(String)
20
- bool << exchange.hash.is_a?(Hash)
20
+ bool << exchange.output.is_a?(Hash)
21
21
  bool << exchange.real_time_performance.is_a?(Hash)
22
22
  bool << exchange.one_day_performance.is_a?(Hash)
23
23
  bool << exchange.five_day_performance.is_a?(Hash)
@@ -34,7 +34,7 @@ describe Alphavantage::Sector do
34
34
  # it "cannot retrieve with wrong key" do
35
35
  # error = false
36
36
  # begin
37
- # sleep(1); stock = Alphavantage::Sector.new key:"wrong_key"
37
+ # stock = Alphavantage::Sector.new key:"wrong_key"
38
38
  # rescue Alphavantage::Error => e
39
39
  # error = true
40
40
  # end
@@ -29,13 +29,13 @@ describe Alphavantage::Stock do
29
29
 
30
30
  it "can create a new timeseries from stock" do
31
31
  stock = @client.stock symbol: "MSFT"
32
- sleep(1); timeseries = stock.timeseries
32
+ timeseries = stock.timeseries
33
33
  expect(timeseries.class).to eq Alphavantage::Timeseries
34
34
  end
35
35
 
36
36
  it "can create a new indicator from stock" do
37
37
  stock = @client.stock symbol: "MSFT"
38
- sleep(1); indicator = stock.indicator function: "SMA"
38
+ indicator = stock.indicator function: "SMA"
39
39
  expect(indicator.class).to eq Alphavantage::Indicator
40
40
  end
41
41
  end
@@ -8,19 +8,19 @@ describe Alphavantage::Stock do
8
8
  end
9
9
 
10
10
  it "create a new stock from stock" do
11
- sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "compact")
11
+ timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "compact")
12
12
  expect(timeseries.class).to eq Alphavantage::Timeseries
13
13
  end
14
14
 
15
15
  it "own multiple data" do
16
- sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "full")
16
+ timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "full")
17
17
  bool = []
18
18
  bool << timeseries.information.is_a?(String)
19
19
  bool << (timeseries.symbol == "MSFT")
20
20
  bool << timeseries.last_refreshed.is_a?(String)
21
21
  bool << (timeseries.output_size == "Full size")
22
22
  bool << timeseries.time_zone.is_a?(String)
23
- bool << timeseries.hash.is_a?(Hash)
23
+ bool << timeseries.output.is_a?(Hash)
24
24
  bool << timeseries.open.is_a?(Array)
25
25
  bool << timeseries.high.is_a?(Array)
26
26
  bool << timeseries.low.is_a?(Array)
@@ -30,7 +30,7 @@ describe Alphavantage::Stock do
30
30
  end
31
31
 
32
32
  it "can retrieve intraday" do
33
- sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "intraday", interval: "30min")
33
+ timeseries = @client.stock(symbol: "MSFT").timeseries(type: "intraday", interval: "30min")
34
34
  bool = []
35
35
  bool << timeseries.information.is_a?(String)
36
36
  bool << (timeseries.symbol == "MSFT")
@@ -38,7 +38,7 @@ describe Alphavantage::Stock do
38
38
  bool << (timeseries.interval == "30min")
39
39
  bool << (timeseries.output_size == "Compact")
40
40
  bool << timeseries.time_zone.is_a?(String)
41
- bool << timeseries.hash.is_a?(Hash)
41
+ bool << timeseries.output.is_a?(Hash)
42
42
  bool << timeseries.open.is_a?(Array)
43
43
  bool << timeseries.high.is_a?(Array)
44
44
  bool << timeseries.low.is_a?(Array)
@@ -48,14 +48,14 @@ describe Alphavantage::Stock do
48
48
  end
49
49
 
50
50
  it "can retrieve adjusted data" do
51
- sleep(1); timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "compact", adjusted: true)
51
+ timeseries = @client.stock(symbol: "MSFT").timeseries(type: "daily", outputsize: "compact", adjusted: true)
52
52
  bool = []
53
53
  bool << timeseries.information.is_a?(String)
54
54
  bool << (timeseries.symbol == "MSFT")
55
55
  bool << timeseries.last_refreshed.is_a?(String)
56
56
  bool << (timeseries.output_size == "Compact")
57
57
  bool << timeseries.time_zone.is_a?(String)
58
- bool << timeseries.hash.is_a?(Hash)
58
+ bool << timeseries.output.is_a?(Hash)
59
59
  bool << timeseries.open.is_a?(Array)
60
60
  bool << timeseries.high.is_a?(Array)
61
61
  bool << timeseries.low.is_a?(Array)
@@ -71,7 +71,7 @@ describe Alphavantage::Stock do
71
71
  bool = []
72
72
  directory = "#{__dir__}/test.csv"
73
73
  bool << File.exists?(directory)
74
- sleep(1); @client.stock(symbol: "MSFT").timeseries(type: "daily",
74
+ @client.stock(symbol: "MSFT").timeseries(type: "daily",
75
75
  outputsize: "compact", adjusted: true, datatype: "csv", file: directory)
76
76
  bool << File.exists?(directory)
77
77
  File.delete(directory)
@@ -81,7 +81,7 @@ describe Alphavantage::Stock do
81
81
  # it "cannot retrieve with wrong key" do
82
82
  # error = false
83
83
  # begin
84
- # sleep(1); stock = Alphavantage::Timeseries.new symbol: "MSFT", key:"wrong key"
84
+ # stock = Alphavantage::Timeseries.new symbol: "MSFT", key:"wrong key"
85
85
  # rescue Alphavantage::Error => e
86
86
  # error = true
87
87
  # end
@@ -91,7 +91,7 @@ describe Alphavantage::Stock do
91
91
  it "cannot retrieve with wrong symbol" do
92
92
  error = false
93
93
  begin
94
- sleep(1); stock = Alphavantage::Timeseries.new symbol: "wrong_symbol", key: @config["key"]
94
+ stock = Alphavantage::Timeseries.new symbol: "wrong_symbol", key: @config["key"]
95
95
  rescue Alphavantage::Error => e
96
96
  error = true
97
97
  end
@@ -2,8 +2,8 @@ require_relative "lib/1.0.0/client"
2
2
  require_relative "lib/1.0.0/crypto_timeseries"
3
3
  require_relative "lib/1.0.0/crypto"
4
4
  require_relative "lib/1.0.0/exchange"
5
+ require_relative "lib/1.0.0/exchange_timeseries"
5
6
  require_relative "lib/1.0.0/indicator"
6
7
  require_relative "lib/1.0.0/sector"
7
8
  require_relative "lib/1.0.0/stock"
8
9
  require_relative "lib/1.0.0/timeseries"
9
- require_relative "lib/1.1.0/batch"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alphavantagerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-10 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -49,12 +49,12 @@ files:
49
49
  - Gemfile
50
50
  - LICENSE.md
51
51
  - README.md
52
- - lib/Batch.rb
53
52
  - lib/Client.rb
54
53
  - lib/Crypto.rb
55
54
  - lib/Crypto_Timeseries.rb
56
55
  - lib/Errors.rb
57
56
  - lib/Exchange.rb
57
+ - lib/Exchange_Timeseries.rb
58
58
  - lib/Indicator.rb
59
59
  - lib/Sector.rb
60
60
  - lib/Stock.rb
@@ -66,11 +66,11 @@ files:
66
66
  - spec/lib/1.0.0/crypto.rb
67
67
  - spec/lib/1.0.0/crypto_timeseries.rb
68
68
  - spec/lib/1.0.0/exchange.rb
69
+ - spec/lib/1.0.0/exchange_timeseries.rb
69
70
  - spec/lib/1.0.0/indicator.rb
70
71
  - spec/lib/1.0.0/sector.rb
71
72
  - spec/lib/1.0.0/stock.rb
72
73
  - spec/lib/1.0.0/timeseries.rb
73
- - spec/lib/1.1.0/batch.rb
74
74
  - spec/spec_helper.rb
75
75
  - spec/test_all.rb
76
76
  homepage: https://github.com/StefanoMartin/AlphaVantageRB
@@ -1,52 +0,0 @@
1
- module Alphavantage
2
- class Batch
3
- include HelperFunctions
4
-
5
- def initialize symbols:, datatype: "json", key:, verbose: false, file: nil
6
- check_argument([true, false], verbose, "verbose")
7
- symbols = [symbols] unless symbols.is_a?(Array)
8
- @client = return_client(key, verbose)
9
- @symbols = symbols
10
- @datatype = datatype
11
- @verbose = verbose
12
- @file = file
13
- check_argument(["json", "csv"], datatype, "datatype")
14
- if datatype == "csv" && file.nil?
15
- raise Alphavantage::Error.new message: "No file specified where to save the CSV ata"
16
- elsif datatype != "csv" && !file.nil?
17
- raise Alphavantage::Error.new message: "Hash error: No file necessary"
18
- end
19
- name_symbols = symbols.join(",")
20
- name_symbols.upcase!
21
- url = "function=BATCH_STOCK_QUOTES&symbols=#{name_symbols}"
22
- return @client.download(url, file) if datatype == "csv"
23
- @hash = @client.request(url)
24
- metadata = @hash.dig("Meta Data") || {}
25
- metadata.each do |key, val|
26
- key_sym = recreate_metadata_key(key)
27
- define_singleton_method(key_sym) do
28
- return val
29
- end
30
- end
31
-
32
- begin
33
- stock_quote = @hash.find{|key, val| key.include?("Stock Quotes")}[1]
34
- rescue Exception => e
35
- raise Alphavantage::Error.new message: "No Stock Quotes found: #{e.message}",
36
- data: @hash
37
- end
38
-
39
- @stock_quote = []
40
- stock_quote.each do |sq|
41
- sval = {}
42
- sq.each do |key, val|
43
- key_sym = key.downcase.gsub(/[0-9.]/, "").lstrip.gsub(" ", "_")
44
- sval[key_sym] = val
45
- end
46
- @stock_quote << sval
47
- end
48
- end
49
-
50
- attr_reader :datatype, :stock_quote, :hash, :symbols
51
- end
52
- end
@@ -1,45 +0,0 @@
1
- require_relative './../../spec_helper'
2
-
3
- describe Alphavantage::Batch do
4
- context "#new" do
5
- it "create a new batch without client" do
6
- stock = Alphavantage::Batch.new symbols: ["MSFT", "FB", "AAPL"], key: @config["key"]
7
- expect(stock.class).to eq Alphavantage::Batch
8
- end
9
-
10
- it "create a new batch from client" do
11
- stock = @client.batch symbols: ["MSFT", "FB", "AAPL"]
12
- expect(stock.class).to eq Alphavantage::Batch
13
- end
14
-
15
- it "own multiple data" do
16
- sleep(1); timeseries = @client.batch symbols: ["MSFT", "FB", "AAPL"]
17
- bool = []
18
- bool << timeseries.information.is_a?(String)
19
- bool << timeseries.notes.is_a?(String)
20
- bool << timeseries.time_zone.is_a?(String)
21
- bool << timeseries.stock_quote.is_a?(Array)
22
- expect(bool.all?{|e| e}).to eq true
23
- end
24
-
25
- it "can retrieve csv files" do
26
- bool = []
27
- directory = "#{__dir__}/test.csv"
28
- bool << File.exists?(directory)
29
- sleep(1); @client.batch(symbols: ["MSFT", "FB", "AAPL"], datatype: "csv", file: directory)
30
- bool << File.exists?(directory)
31
- File.delete(directory)
32
- expect(bool).to eq [false, true]
33
- end
34
-
35
- it "cannot retrieve with wrong symbol" do
36
- error = false
37
- begin
38
- sleep(1); stock = Alphavantage::Batch.new symbols: ["MSAFT", "FDB", "AAAPL"], key: @config["key"]
39
- rescue Alphavantage::Error => e
40
- error = true
41
- end
42
- expect(stock.stock_quote.empty?).to eq true
43
- end
44
- end
45
- end