eodhd.rb 0.16.0 → 0.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1400c119e7a404b5100e55d51234c2bde712e9227454799556191bcb96bc2923
4
- data.tar.gz: ed91c5bc5a273e50f5462780c55529dd26bb5a98fa318747ccbb390b5d4b2228
3
+ metadata.gz: 32a73dbd43fadc7f1f4f84e0e3cd8490fd08cc8ee75afa9207bf6f341514bd20
4
+ data.tar.gz: d40408203120a0dc787345d3545c118570e58488053705f6c6280bfa0c523971
5
5
  SHA512:
6
- metadata.gz: 4e13b25610267151935b2e57d2367ed3274ba327d3edcee569b16ad5ac2a956671cebbf81e4146ff727a1b36522d53c6005e1c14c4ffbf4ce49342bf11f70878
7
- data.tar.gz: 03e6404cc5fc0e7e58758dbb4086deb5039fd9807f3c26e350c4b7f33cbb4cf9e363e123b94f37ea394a5ee973e35616b83c1bbd426403e3e8de1fc9cee64d5f
6
+ metadata.gz: f77f80889b5a92557731cb2753be73cafc1f663568dfa0d52ae844532cd1bbc95446f9c8951cbf0bf2874a8a74eb90e3baecf0cf7fdcee223d440611077e9ed1
7
+ data.tar.gz: ac326a3aba6438c3911a6184f4c932253c7f6fed4875a9bd11bac19dd411c7623c0c25ec7ff7856c677889b15b1b605938b4961ec638839d34fb8a098b982a5e
data/lib/Eodhd/Client.rb CHANGED
@@ -44,9 +44,7 @@ class Eodhd
44
44
  from: from,
45
45
  to: to
46
46
  )
47
- args = {period: period}
48
- args.merge!(from: from) if from
49
- args.merge!(to: to) if to
47
+ args = {period: period, from: from, to: to}.compact
50
48
  response = get(path: "/eod/#{symbol}.#{exchange_id}", args: args)
51
49
  handle_response(response)
52
50
  end
@@ -58,6 +56,19 @@ class Eodhd
58
56
  handle_response(response)
59
57
  end
60
58
 
59
+ def intraday(exchange_code:, symbol:, interval:, from: nil, to: nil)
60
+ validate_arguments(
61
+ exchange_code: exchange_code,
62
+ symbol: symbol,
63
+ interval: interval,
64
+ from: from,
65
+ to: to
66
+ )
67
+ args = {interval: interval, from: from, to: to}.compact
68
+ response = get(path: "/intraday/#{symbol}.#{exchange_code}", args: args)
69
+ handle_response(response)
70
+ end
71
+
61
72
  attr_accessor\
62
73
  :api_token,
63
74
  :logger
@@ -0,0 +1,76 @@
1
+ # Eodhd/Intraday.rb
2
+ # Eodhd::Intraday
3
+
4
+ class Eodhd
5
+ class Intraday
6
+ class << self
7
+ def all(client: nil, api_token: nil, exchange_code: 'US', symbol:, interval:, from: nil, to: nil)
8
+ load(
9
+ client: client,
10
+ api_token: api_token,
11
+ exchange_code: exchange_code,
12
+ symbol: symbol,
13
+ interval: interval,
14
+ from: from,
15
+ to: to
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ def load(client: nil, api_token: nil, exchange_code: 'US', symbol:, interval:, from:, to:)
22
+ client ||= Client.new(api_token: api_token)
23
+ client.intraday(
24
+ exchange_code: exchange_code,
25
+ symbol: symbol,
26
+ interval: interval,
27
+ from: from,
28
+ to: to
29
+ ).collect do |intraday_data|
30
+ self.new(
31
+ exchange_code: exchange_code,
32
+ symbol: symbol,
33
+ interval: interval,
34
+ timestamp: intraday_data['timestamp'],
35
+ gmtoffset: intraday_data['gmtoffset'],
36
+ datetime: intraday_data['datetime'],
37
+ open: intraday_data['open'],
38
+ high: intraday_data['high'],
39
+ low: intraday_data['low'],
40
+ close: intraday_data['close'],
41
+ volume: intraday_data['volume']
42
+ )
43
+ end
44
+ end
45
+ end # class << self
46
+
47
+ attr_reader\
48
+ :exchange_code,
49
+ :symbol,
50
+ :interval,
51
+ :timestamp,
52
+ :gmtoffset,
53
+ :datetime,
54
+ :open,
55
+ :high,
56
+ :low,
57
+ :close,
58
+ :volume
59
+
60
+ private
61
+
62
+ def initialize(exchange_code:, symbol:, interval:, timestamp:, gmtoffset:, datetime:, open:, high:, low:, close:, volume:)
63
+ @exchange_code = exchange_code
64
+ @symbol = symbol
65
+ @interval = interval
66
+ @timestamp = timestamp
67
+ @gmtoffset = gmtoffset
68
+ @datetime = datetime
69
+ @open = open
70
+ @high = high
71
+ @low = low
72
+ @close = close
73
+ @volume = volume
74
+ end
75
+ end
76
+ end
data/lib/Eodhd/VERSION.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Eodhd
2
- VERSION = '0.16.0'
2
+ VERSION = '0.17.0'
3
3
  end
@@ -3,11 +3,12 @@
3
3
 
4
4
  class Eodhd
5
5
  module Validations
6
- def validate_arguments(exchange_code: nil, exchange_id: nil, symbol: nil, period: nil, from: nil, to: nil, date: nil)
6
+ def validate_arguments(exchange_code: nil, exchange_id: nil, symbol: nil, period: nil, interval: nil, from: nil, to: nil, date: nil)
7
7
  exchange_code ||= exchange_id
8
8
  validate_exchange_code(exchange_code)
9
9
  validate_symbol(symbol)
10
10
  validate_period(period)
11
+ validate_interval(interval)
11
12
  validate_date(from, 'from')
12
13
  validate_date(to, 'to')
13
14
  validate_date_range(from, to)
@@ -38,6 +39,14 @@ class Eodhd
38
39
  end
39
40
  end
40
41
 
42
+ def validate_interval(interval)
43
+ return unless interval
44
+ valid_intervals = %w[1m 5m 15m 30m 1h 4h 1d 1w 1mo]
45
+ unless valid_intervals.include?(interval)
46
+ raise ArgumentError, "Invalid interval: #{interval}. Must be one of: #{valid_intervals.join(', ')}"
47
+ end
48
+ end
49
+
41
50
  def validate_date(date, param_name = 'date')
42
51
  return unless date
43
52
  case date
data/lib/Eodhd.rb CHANGED
@@ -6,6 +6,7 @@ require_relative './Eodhd/EodBulkLastDay'
6
6
  require_relative './Eodhd/EodData'
7
7
  require_relative './Eodhd/Exchange'
8
8
  require_relative './Eodhd/ExchangeSymbol'
9
+ require_relative './Eodhd/Intraday'
9
10
  require_relative './Eodhd/WebSocketClient'
10
11
 
11
12
  class Eodhd
@@ -34,13 +35,13 @@ class Eodhd
34
35
  Eodhd::EodBulkLastDay.all(api_token: @api_token, exchange_code: exchange_code, date: date)
35
36
  end
36
37
 
38
+ def intraday(exchange: nil, exchange_code: nil, symbol:, interval:, from: nil, to: nil)
39
+ exchange_code ||= exchange&.code || 'US'
40
+ Eodhd::Intraday.all(api_token: @api_token, exchange_code: exchange_code, symbol: symbol, interval: interval, from: from, to: to)
41
+ end
42
+
37
43
  def web_socket(asset_class:, symbols:)
38
- Eodhd::WebSocketClient.new(
39
- api_token: @api_token,
40
- asset_class: asset_class,
41
- symbols: symbols,
42
- consumer: @consumer,
43
- )
44
+ Eodhd::WebSocketClient.new(api_token: @api_token, asset_class: asset_class, symbols: symbols, consumer: @consumer)
44
45
  end
45
46
 
46
47
  def stream(asset_class:, symbols:)
data/test/client_test.rb CHANGED
@@ -53,6 +53,22 @@ describe Eodhd::Client do
53
53
  end
54
54
  end
55
55
 
56
+ describe "#intraday" do
57
+ it "intraday returns parsed JSON array" do
58
+ VCR.use_cassette('client_intraday') do
59
+ result = client.intraday(exchange_code: 'US', symbol: 'AAPL', interval: '5m')
60
+ _(result).must_be_kind_of(Array)
61
+ _(result.first.keys).must_equal(%w{timestamp gmtoffset datetime open high low close volume})
62
+ end
63
+ end
64
+
65
+ it "raises Eodhd::Error on failure" do
66
+ VCR.use_cassette('client_intraday_401_error') do
67
+ _{client.intraday(exchange_code: 'US', symbol: 'AAPL', interval: '5m')}.must_raise(Eodhd::Error)
68
+ end
69
+ end
70
+ end
71
+
56
72
  describe "#eod_bulk_last_day" do
57
73
  it "eod_bulk_last_day returns parsed JSON array" do
58
74
  VCR.use_cassette("client_eod_bulk_last_day") do
data/test/eodhd_test.rb CHANGED
@@ -2,6 +2,7 @@ require_relative "helper"
2
2
 
3
3
  describe Eodhd do
4
4
  let(:api_token){ENV.fetch('EODHD_API_TOKEN', '<API_TOKEN>')}
5
+
5
6
  let(:eodhd){Eodhd.new(api_token: api_token)}
6
7
 
7
8
  describe "#exchanges" do
@@ -47,4 +48,15 @@ describe Eodhd do
47
48
  end
48
49
  end
49
50
  end
51
+
52
+ describe "#intraday" do
53
+ it "delegates to Eodhd::Intraday.all" do
54
+ VCR.use_cassette('eodhd_intraday') do
55
+ intraday_data = eodhd.intraday(exchange_code: 'US', symbol: 'AAPL', interval: '5m')
56
+ _(intraday_data).must_be_kind_of(Array)
57
+ _(intraday_data).wont_be_empty
58
+ _(intraday_data.first).must_be_kind_of(Eodhd::Intraday)
59
+ end
60
+ end
61
+ end
50
62
  end
@@ -92,6 +92,21 @@ describe "Eodhd::Validations" do
92
92
  end
93
93
  end
94
94
 
95
+ describe "#validate_interval" do
96
+ it "accepts valid intervals" do
97
+ _{v.validate_interval('1m')}.must_be_silent
98
+ _{v.validate_interval('5m')}.must_be_silent
99
+ _{v.validate_interval('1h')}.must_be_silent
100
+ _{v.validate_interval('1d')}.must_be_silent
101
+ end
102
+
103
+ it "rejects invalid intervals" do
104
+ _{v.validate_interval('2m')}.must_raise(ArgumentError)
105
+ _{v.validate_interval('invalid')}.must_raise(ArgumentError)
106
+ _{v.validate_interval('')}.must_raise(ArgumentError)
107
+ end
108
+ end
109
+
95
110
  describe "#validate_date" do
96
111
  it "accepts valid date formats and Date objects" do
97
112
  _{v.validate_date('2024-09-30')}.must_be_silent
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eodhd.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -138,6 +138,7 @@ files:
138
138
  - lib/Eodhd/Error.rb
139
139
  - lib/Eodhd/Exchange.rb
140
140
  - lib/Eodhd/ExchangeSymbol.rb
141
+ - lib/Eodhd/Intraday.rb
141
142
  - lib/Eodhd/VERSION.rb
142
143
  - lib/Eodhd/Validations.rb
143
144
  - lib/Eodhd/WebSocketClient.rb