market_data 0.3.0 → 0.4.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: c83d3644178f120e069d283ebfc132d543ac8dbe2aca9734388d2cd56274bf7c
4
- data.tar.gz: eeef52d93f45e64b4869749bd787b0af576924a0b617e8897c4eada6dcf813b2
3
+ metadata.gz: a5feb3cbcff5474737a925a855588baf09152953e44595542122629072c55412
4
+ data.tar.gz: 1087e1885b7d70e91afe3d32904fadf95314180518d37073c146ec108ed75919
5
5
  SHA512:
6
- metadata.gz: b01a71a756244d6461e19cad34abb3b25df2705b43e03e47a936a66a471879f8ae0038e49ab01f062ec0db4c046e40e2d80d3162a5c065f535ffa7877efed548
7
- data.tar.gz: fe1a289aa65eb0e6a0682b9e263a232f0eb2b913a808b9c6ac5271e46b52123a4c805a586bc5b2a1b9aeda92c17fb640815e6230907a9dcf6a0c5379bcd34b59
6
+ metadata.gz: b3c2f565abae69a1b2c2d107535cd7bfbb92ece1667f29a97ab262cfeecf00a0849d9ccc5ef115c2b5a7c9552bd44a60b541c95c45fa1ec050b1471fd5f5d8a3
7
+ data.tar.gz: e57d6e8d18f9aefb841f450dec15f54dd7ae9a8ad81c02a097ce83e02452790a4e1e2252c4b810ce86ccbb1e01fe31571fb36775803088a458b839cf849e1bc3
data/CHANGELOG.md CHANGED
@@ -29,4 +29,8 @@
29
29
  ## [0.3.0] - 2024-10-09
30
30
 
31
31
  - Add support for Earnings endpoint under the `earnings` method
32
- - Introduced `Validations` module for parameter validation logic
32
+ - Introduced `Validations` module for parameter validation logic
33
+
34
+ ## [0.4.0] - 2024-10-14
35
+
36
+ - Add support for Markets status endpoint under the `market_status` method
@@ -47,5 +47,9 @@ module MarketData
47
47
  high52: "high52",
48
48
  low52: "low52",
49
49
  }
50
+ MARKET_STATUS_FIELD_MAPPING = {
51
+ date: "date",
52
+ status: "status"
53
+ }
50
54
  end
51
55
  end
@@ -47,6 +47,13 @@ module MarketData
47
47
  ar
48
48
  end
49
49
 
50
+ def map_market_status response
51
+ MarketData::Models::MarketStatus.new(
52
+ date: response["date"][0],
53
+ status: response["status"][0],
54
+ )
55
+ end
56
+
50
57
  def map_fields_for(response, kind, i=0)
51
58
  mapping = {}
52
59
  case kind
@@ -0,0 +1,17 @@
1
+ module MarketData
2
+ module Markets
3
+ include MarketData::Validations
4
+
5
+ @@status = "/v1/markets/status/"
6
+
7
+ def market_status(country: nil, date: nil, from: nil, to: nil, countback: nil)
8
+ query = validate_market_status_input!(country: country, date: date, from: from, to: to, countback: countback)
9
+
10
+ path_hash = { host: MarketData.base_host, path: @@status }
11
+ path_hash[:query] = URI.encode_www_form(query)
12
+
13
+ res = do_connect(get_uri path_hash)
14
+ map_market_status res
15
+ end
16
+ end
17
+ end
@@ -15,5 +15,6 @@ module MarketData
15
15
  end
16
16
 
17
17
  Earning = Struct.new(*Constants::EARNING_FIELD_MAPPING.keys)
18
+ MarketStatus = Struct.new(*Constants::MARKET_STATUS_FIELD_MAPPING.keys)
18
19
  end
19
20
  end
@@ -56,10 +56,7 @@ module MarketData
56
56
  r.merge({symbols: symbols.join(",")})
57
57
  end
58
58
 
59
- def validate_candles_input!(
60
- resolution: nil, from: nil, to: nil, countback: nil
61
- )
62
-
59
+ def validate_candles_input!(resolution: nil, from: nil, to: nil, countback: nil)
63
60
  state, response = validate_from_to_countback_strategy(from: from, to: to, countback: countback)
64
61
  if state == :invalid
65
62
  raise BadParameterError.new(response)
@@ -73,9 +70,7 @@ module MarketData
73
70
  response.merge(res)
74
71
  end
75
72
 
76
- def validate_earnings_input!(
77
- from: nil, to: nil, countback: nil, date: nil, report: nil
78
- )
73
+ def validate_earnings_input!(from: nil, to: nil, countback: nil, date: nil, report: nil)
79
74
  if !date.nil?
80
75
  return {date: date}
81
76
  end
@@ -91,6 +86,34 @@ module MarketData
91
86
  return response
92
87
  end
93
88
 
89
+ def validate_market_status_input!(country: nil, date: nil, from: nil, to: nil, countback: nil)
90
+ result = {}
91
+
92
+ if [country, date, from, to, countback].all? { |x| x.nil? }
93
+ return result
94
+ end
95
+
96
+ if !country.nil?
97
+ result.merge!({country: country})
98
+ end
99
+
100
+ if !date.nil?
101
+ # date has higher priority than from-to-countback
102
+ return result.merge({date: date})
103
+ end
104
+
105
+ if [from, to, countback].all? { |x| x.nil? }
106
+ return result
107
+ else
108
+ state, response = validate_from_to_countback_strategy(from: from, to: to, countback: countback)
109
+ if state == :invalid
110
+ raise BadParameterError.new(response)
111
+ end
112
+ end
113
+
114
+ return result.merge(response)
115
+ end
116
+
94
117
  def validate_from_to_countback_strategy(
95
118
  from: nil, to: nil, countback: nil
96
119
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MarketData
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/market_data.rb CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  require_relative "market_data/version"
4
4
  require "market_data/quotes"
5
+ require "market_data/markets"
5
6
 
6
7
  module MarketData
7
8
  @@base_host = "api.marketdata.app"
8
9
 
9
10
  class Client
10
11
  include MarketData::Quotes
11
- # include MarketData::Index
12
+ include MarketData::Markets
12
13
 
13
14
  def initialize token
14
15
  @access_token = token
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: market_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastián González
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-11 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby client for the MarketData API.
14
14
  email:
@@ -29,6 +29,7 @@ files:
29
29
  - lib/market_data/constants.rb
30
30
  - lib/market_data/errors.rb
31
31
  - lib/market_data/mappers.rb
32
+ - lib/market_data/markets.rb
32
33
  - lib/market_data/models.rb
33
34
  - lib/market_data/quotes.rb
34
35
  - lib/market_data/validations.rb