eodhd.rb 0.14.2 → 0.15.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/eodhd.rb.gemspec +4 -2
- data/lib/Eodhd/Client.rb +32 -13
- data/lib/Eodhd/VERSION.rb +3 -0
- data/lib/Eodhd/Validations.rb +59 -0
- data/lib/eodhd.rb +0 -20
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d710273541a726ea8483974f5ac0f0a78ddee69fcb5024fe5a003ecfff3f35
|
4
|
+
data.tar.gz: d156d5857f9cc1892d23f54c491a7a5cdefcea49135c50e16f1ab70ea402a0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c09445a3ef620a5ee45be611bf41d4d70c9edc2aef5a52ab691849eb4dea1c06381decb9534faa2b6ff680d11a3e44c47133b4a997125697fa84209add6c49a
|
7
|
+
data.tar.gz: 30f076f3f55ff6c11fbd8551627b01b90791ca467834b6154e3be2f64f66c3edb7695a2dc6ed04be9464f3befd653ea854108833c8313a2939fe0fead7b2c478
|
data/eodhd.rb.gemspec
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
require_relative './lib/Eodhd/VERSION'
|
2
|
+
|
1
3
|
Gem::Specification.new do |spec|
|
2
4
|
spec.name = 'eodhd.rb'
|
3
5
|
|
4
|
-
spec.version =
|
5
|
-
spec.date = '2025-
|
6
|
+
spec.version = Eodhd::VERSION
|
7
|
+
spec.date = '2025-09-16'
|
6
8
|
|
7
9
|
spec.summary = "Access the eodhd.com API with Ruby."
|
8
10
|
spec.description = "Access the eodhd.com API with Ruby."
|
data/lib/Eodhd/Client.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Eodhd/Client.rb
|
2
2
|
# Eodhd::Client
|
3
3
|
|
4
|
-
require 'fileutils'
|
5
4
|
gem 'http.rb'
|
5
|
+
|
6
|
+
require 'fileutils'
|
6
7
|
require 'http.rb'
|
7
8
|
require 'json'
|
8
9
|
require 'logger'
|
@@ -47,11 +48,19 @@ class Eodhd
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def exchange_symbol_list(exchange_code:)
|
51
|
+
validate_arguments(exchange_code: exchange_code)
|
50
52
|
response = get(path: "/exchange-symbol-list/#{exchange_code}")
|
51
53
|
handle_response(response)
|
52
54
|
end
|
53
55
|
|
54
56
|
def eod_data(exchange_id:, symbol:, period:, from: nil, to: nil)
|
57
|
+
validate_arguments(
|
58
|
+
exchange_id: exchange_id,
|
59
|
+
symbol: symbol,
|
60
|
+
period: period,
|
61
|
+
from: from,
|
62
|
+
to: to
|
63
|
+
)
|
55
64
|
args = {period: period}
|
56
65
|
args.merge!(from: from) if from
|
57
66
|
args.merge!(to: to) if to
|
@@ -60,6 +69,7 @@ class Eodhd
|
|
60
69
|
end
|
61
70
|
|
62
71
|
def eod_bulk_last_day(exchange_id:, date:)
|
72
|
+
validate_arguments(exchange_id: exchange_id, date: date)
|
63
73
|
args = {date: date}
|
64
74
|
response = get(path: "/eod-bulk-last-day/#{exchange_id}", args: args)
|
65
75
|
handle_response(response)
|
@@ -71,6 +81,16 @@ class Eodhd
|
|
71
81
|
@api_token = api_token
|
72
82
|
end
|
73
83
|
|
84
|
+
def validate_arguments(exchange_code: nil, exchange_id: nil, symbol: nil, period: nil, from: nil, to: nil, date: nil)
|
85
|
+
exchange_code ||= exchange_id
|
86
|
+
validate_exchange_code!(exchange_code) if exchange_code
|
87
|
+
validate_symbol!(symbol) if symbol
|
88
|
+
validate_period!(period) if period
|
89
|
+
validate_date!(from, 'from') if from
|
90
|
+
validate_date!(to, 'to') if to
|
91
|
+
validate_date_range!(from, to) if from && to
|
92
|
+
end
|
93
|
+
|
74
94
|
def request_string(path)
|
75
95
|
"https://#{API_HOST}#{self.class.path_prefix}#{path}"
|
76
96
|
end
|
@@ -87,16 +107,21 @@ class Eodhd
|
|
87
107
|
self.class.logger.info(log_string)
|
88
108
|
end
|
89
109
|
|
110
|
+
def log_response(code:, message:, body:)
|
111
|
+
log_string = "#{code}\n#{message}\n#{body}"
|
112
|
+
self.class.logger.info(log_string)
|
113
|
+
end
|
114
|
+
|
90
115
|
def log_error(code:, message:, body:)
|
91
116
|
log_string = "#{code}\n#{message}\n#{body}"
|
92
117
|
self.class.logger.error(log_string)
|
93
118
|
end
|
94
119
|
|
95
120
|
def do_request(verb:, path:, args: {})
|
96
|
-
log_request(verb: verb, request_string: request_string(path), args: args)
|
97
121
|
api_token = args[:api_token] || @api_token
|
98
122
|
fmt = args[:fmt] || 'json'
|
99
123
|
args.merge!(api_token: api_token, fmt: fmt)
|
124
|
+
log_request(verb: verb, request_string: request_string(path), args: args)
|
100
125
|
HTTP.send(verb.to_s.downcase, request_string(path), args)
|
101
126
|
end
|
102
127
|
|
@@ -106,18 +131,12 @@ class Eodhd
|
|
106
131
|
|
107
132
|
def handle_response(response)
|
108
133
|
if response.success?
|
109
|
-
JSON.parse(response.body)
|
134
|
+
parsed_body = JSON.parse(response.body)
|
135
|
+
log_response(code: response.code, message: response.message, body: response.body) if use_logging?
|
136
|
+
parsed_body
|
110
137
|
else
|
111
|
-
log_error(
|
112
|
-
|
113
|
-
message: response.message,
|
114
|
-
body: response.body
|
115
|
-
)
|
116
|
-
raise Eodhd::Error.new(
|
117
|
-
code: response.code,
|
118
|
-
message: response.message,
|
119
|
-
body: response.body
|
120
|
-
)
|
138
|
+
log_error(code: response.code, message: response.message, body: response.body)
|
139
|
+
raise Eodhd::Error.new(code: response.code, message: response.message, body: response.body)
|
121
140
|
end
|
122
141
|
end
|
123
142
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Eodhd/Validations.rb
|
2
|
+
# Eodhd::Validations
|
3
|
+
|
4
|
+
module Eodhd
|
5
|
+
module Validations
|
6
|
+
def validate_exchange_code!(exchange_code)
|
7
|
+
return unless exchange_code
|
8
|
+
unless exchange_code.match?(/\A[A-Z]{2,6}\z/)
|
9
|
+
raise ArgumentError, "Invalid exchange_code '#{exchange_code}'. Must be 2-6 uppercase letters"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def validate_symbol!(symbol)
|
14
|
+
return unless symbol
|
15
|
+
if symbol.strip.empty?
|
16
|
+
raise ArgumentError, "Symbol cannot be empty"
|
17
|
+
end
|
18
|
+
unless symbol.match?(/\A[A-Za-z0-9.-]{1,12}\z/)
|
19
|
+
raise ArgumentError, "Invalid symbol '#{symbol}'. Must be 1-12 characters, letters/numbers/dots/hyphens only"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_period!(period)
|
24
|
+
return unless period
|
25
|
+
valid_periods = %w[d w m]
|
26
|
+
unless valid_periods.include?(period)
|
27
|
+
raise ArgumentError, "Invalid period '#{period}'. Must be one of: #{valid_periods.join(', ')}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_date!(date, param_name = 'date')
|
32
|
+
return unless date
|
33
|
+
case date
|
34
|
+
when Date
|
35
|
+
return
|
36
|
+
when String
|
37
|
+
unless date.match?(/\A\d{4}-\d{2}-\d{2}\z/)
|
38
|
+
raise ArgumentError, "Invalid #{param_name} '#{date}'. Must be in format 'yyyy-mm-dd'"
|
39
|
+
end
|
40
|
+
begin
|
41
|
+
Date.parse(date)
|
42
|
+
rescue Date::Error
|
43
|
+
raise ArgumentError, "Invalid #{param_name} '#{date}'. Not a valid date"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
raise ArgumentError, "Invalid #{param_name}. Must be String in 'yyyy-mm-dd' format or Date object"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_date_range!(from, to)
|
51
|
+
return unless from && to
|
52
|
+
from_date = from.is_a?(Date) ? from : Date.parse(from.to_s)
|
53
|
+
to_date = to.is_a?(Date) ? to : Date.parse(to.to_s)
|
54
|
+
if from_date > to_date
|
55
|
+
raise ArgumentError, "from date (#{from}) cannot be after to date (#{to})"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/eodhd.rb
CHANGED
@@ -1,26 +1,6 @@
|
|
1
1
|
# Eodhd.rb
|
2
2
|
# Eodhd
|
3
3
|
|
4
|
-
# 20250326
|
5
|
-
# 0.14.2
|
6
|
-
|
7
|
-
# Changes since 0.13:
|
8
|
-
# -/0: Add WebSockets.
|
9
|
-
# 1. + Eodhd::WebSocketClient
|
10
|
-
# 2. + Eodhd#web_socket
|
11
|
-
# 3. + Eodhd#stream
|
12
|
-
# 4. + Eodhd#us_quote_stream
|
13
|
-
# 5. + Eodhd#us_trade_stream
|
14
|
-
# 6. + Eodhd#forex_stream
|
15
|
-
# 7. + Eodhd#crypto_stream
|
16
|
-
# 8. Moved Eodhd::Error from Eodhd::Client to a separate file.
|
17
|
-
# 0/1: Some fixes for the WebSocketClient interface.
|
18
|
-
# 9. ~ Eodhd::WebSocketClient: + attr_accessor :consumer
|
19
|
-
# 10. ~ Eodhd::WebSocketClient: /attr_accessor :symbols/attr_reader :symbols/
|
20
|
-
# 11. + Eodhd::WebSocketClient#symbols=
|
21
|
-
# 1/2: Remove reference to currently unused library UnixTime.
|
22
|
-
# 12. ~ Eodhd::WebSocketClient: - require 'UnixTime'
|
23
|
-
|
24
4
|
require_relative 'Eodhd/Client'
|
25
5
|
require_relative 'Eodhd/EodBulkLastDay'
|
26
6
|
require_relative 'Eodhd/EodData'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eodhd.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoran
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-09-16 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: http.rb
|
@@ -38,6 +38,8 @@ files:
|
|
38
38
|
- lib/Eodhd/Error.rb
|
39
39
|
- lib/Eodhd/Exchange.rb
|
40
40
|
- lib/Eodhd/ExchangeSymbol.rb
|
41
|
+
- lib/Eodhd/VERSION.rb
|
42
|
+
- lib/Eodhd/Validations.rb
|
41
43
|
- lib/Eodhd/WebSocketClient.rb
|
42
44
|
- lib/Hash/x_www_form_urlencode.rb
|
43
45
|
- lib/Thoran/Hash/XWwwFormUrlencode/x_www_form_urlencode.rb
|
@@ -61,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
63
|
- !ruby/object:Gem::Version
|
62
64
|
version: '0'
|
63
65
|
requirements: []
|
64
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.7.2
|
65
67
|
specification_version: 4
|
66
68
|
summary: Access the eodhd.com API with Ruby.
|
67
69
|
test_files: []
|