market_data 0.4.0 → 0.5.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: a5feb3cbcff5474737a925a855588baf09152953e44595542122629072c55412
4
- data.tar.gz: 1087e1885b7d70e91afe3d32904fadf95314180518d37073c146ec108ed75919
3
+ metadata.gz: 76061b4644a7a3092a819581faa9b7141dfb88e064b3a78a3615aa4c76ac1b0a
4
+ data.tar.gz: '09d87650d7235f8419524a0bb4cba5a43dd1d8d1a4e0eae4cb1b2cc24fc27dbf'
5
5
  SHA512:
6
- metadata.gz: b3c2f565abae69a1b2c2d107535cd7bfbb92ece1667f29a97ab262cfeecf00a0849d9ccc5ef115c2b5a7c9552bd44a60b541c95c45fa1ec050b1471fd5f5d8a3
7
- data.tar.gz: e57d6e8d18f9aefb841f450dec15f54dd7ae9a8ad81c02a097ce83e02452790a4e1e2252c4b810ce86ccbb1e01fe31571fb36775803088a458b839cf849e1bc3
6
+ metadata.gz: d369b7b3d1e391decd1679262e2c0f9ef8fe20463aac5ef3ebc05ce00a46c86ea94d13441e8d8d2f76ed78220a3f45b99f3cb4caf80da52d115b8e97d54fdb7f
7
+ data.tar.gz: 50a5fc1e57d70f12722d84ecac720a4649a1e71ea6f4fa12f7d521f15b2ca8940c19f95e33f93d78b2b998e299f015091812a033b61011f6a1d80ea07a98c84e
data/CHANGELOG.md CHANGED
@@ -33,4 +33,8 @@
33
33
 
34
34
  ## [0.4.0] - 2024-10-14
35
35
 
36
- - Add support for Markets status endpoint under the `market_status` method
36
+ - Add support for Markets status endpoint under the `market_status` method
37
+
38
+ ## [0.5.0] - 2024-10-15
39
+
40
+ - Add support for Indexes endpoints under `index_quote` and `ìndex_candles`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- market_data (0.1.2)
4
+ market_data (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Ruby wrapper for the [MarketData API](https://www.marketdata.app/docs/api).
4
4
 
5
- ![coverage](https://img.shields.io/badge/coverage%3A-87.77%25-yellow.svg)
5
+ ![coverage](https://img.shields.io/badge/coverage%3A-87.68%25-yellow.svg)
6
6
 
7
7
  ## Installation
8
8
 
@@ -139,11 +139,11 @@ From Stocks endpoints:
139
139
  - [X] Earnings
140
140
 
141
141
  From Markets endpoints:
142
- - [ ] Status
142
+ - [X] Status
143
143
 
144
144
  From Indices endpoints:
145
- - [ ] Quotes
146
- - [ ] Candles
145
+ - [X] Quotes
146
+ - [X] Candles
147
147
 
148
148
  From Stocks endpoints:
149
149
  - [ ] Support for optional parameters for Candles
@@ -6,6 +6,18 @@ module MarketData
6
6
  module Conn
7
7
  include MarketData::Errors
8
8
 
9
+ def do_request path, query
10
+ path_hash = {
11
+ host: MarketData.base_host,
12
+ path: path,
13
+ }
14
+ path_hash[:query] = URI.encode_www_form(query) unless query.empty?
15
+
16
+ do_connect(
17
+ get_uri path_hash
18
+ )
19
+ end
20
+
9
21
  def do_connect(path)
10
22
  begin
11
23
  conn = URI.open(path, get_auth_headers)
@@ -51,5 +51,22 @@ module MarketData
51
51
  date: "date",
52
52
  status: "status"
53
53
  }
54
+ INDEX_QUOTE_FIELD_MAPPING = {
55
+ symbol: "symbol",
56
+ last: "last",
57
+ change: "change",
58
+ change_pct: "changepct",
59
+ high52: "52weekHigh",
60
+ low52: "52weekLow",
61
+ updated: "updated",
62
+ }
63
+ INDEX_CANDLE_FIELD_MAPPING = {
64
+ symbol: "symbol",
65
+ open: "o",
66
+ close: "c",
67
+ low: "l",
68
+ high: "h",
69
+ time: "t",
70
+ }
54
71
  end
55
72
  end
@@ -0,0 +1,27 @@
1
+ module MarketData
2
+ module Indexes
3
+ include MarketData::Conn
4
+ include MarketData::Mappers
5
+ include MarketData::Validations
6
+
7
+ @@quotes = "/v1/indices/quotes/"
8
+ @@candles = "/v1/indices/candles/"
9
+
10
+ def index_quote(symbol, opts = {w52: nil})
11
+ query = validate_index_quote_input!(**opts)
12
+
13
+ map_index_quote(
14
+ do_request(@@quotes + symbol, query)
15
+ )
16
+ end
17
+
18
+ def index_candles(symbol, opts = {resolution: nil, from: nil, to: nil, countback: nil})
19
+ query = validate_index_candles_input!(**opts)
20
+
21
+ map_index_candles(
22
+ do_request("#{@@candles}#{opts[:resolution]}/#{symbol}", query),
23
+ symbol
24
+ )
25
+ end
26
+ end
27
+ end
@@ -5,6 +5,7 @@ module MarketData
5
5
  include MarketData::Models
6
6
  SYMBOL_RESPONSE_KEY = "symbol"
7
7
  STATUS_RESPONSE_KEY = "s"
8
+ OPEN_RESPONSE_KEY = "o"
8
9
 
9
10
  def map_quote response, i=0
10
11
  Quote.new(**map_fields_for(response, :quote, i))
@@ -21,7 +22,7 @@ module MarketData
21
22
 
22
23
  def map_candles response, symbol
23
24
  ar = []
24
- (0..(response["o"].size - 1)).each do |i|
25
+ (0..(response[OPEN_RESPONSE_KEY].size - 1)).each do |i|
25
26
  args = map_fields_for(response, :candle, i)
26
27
  args[:symbol] = symbol
27
28
  ar << Candle.new(**args)
@@ -53,6 +54,20 @@ module MarketData
53
54
  status: response["status"][0],
54
55
  )
55
56
  end
57
+
58
+ def map_index_quote response
59
+ IndexQuote.new(**map_fields_for(response, :index_quote))
60
+ end
61
+
62
+ def map_index_candles response, symbol
63
+ ar = []
64
+ (0..(response[OPEN_RESPONSE_KEY].size - 1)).each do |i|
65
+ args = map_fields_for(response, :index_candle, i)
66
+ args[:symbol] = symbol
67
+ ar << Models::IndexCandle.new(**args)
68
+ end
69
+ ar
70
+ end
56
71
 
57
72
  def map_fields_for(response, kind, i=0)
58
73
  mapping = {}
@@ -61,6 +76,10 @@ module MarketData
61
76
  mapping = Constants::CANDLE_FIELD_MAPPING
62
77
  when :earning
63
78
  mapping = Constants::EARNING_FIELD_MAPPING
79
+ when :index_candle
80
+ mapping = Constants::INDEX_CANDLE_FIELD_MAPPING
81
+ when :index_quote
82
+ mapping = Constants::INDEX_QUOTE_FIELD_MAPPING
64
83
  when :quote
65
84
  mapping = Constants::QUOTE_FIELD_MAPPING
66
85
  else
@@ -15,6 +15,11 @@ module MarketData
15
15
  end
16
16
 
17
17
  Earning = Struct.new(*Constants::EARNING_FIELD_MAPPING.keys)
18
+
18
19
  MarketStatus = Struct.new(*Constants::MARKET_STATUS_FIELD_MAPPING.keys)
20
+
21
+ IndexQuote = Struct.new(*Constants::INDEX_QUOTE_FIELD_MAPPING.keys)
22
+
23
+ IndexCandle = Struct.new(*Constants::INDEX_CANDLE_FIELD_MAPPING.keys)
19
24
  end
20
25
  end
@@ -18,24 +18,18 @@ module MarketData
18
18
 
19
19
  def quote(symbol, w52 = false, extended = false)
20
20
  query = validate_quotes_input!(symbol: symbol, w52: w52, extended: extended)
21
-
22
- path_hash = { host: MarketData.base_host, path: @@single + symbol }
23
- if !query.empty?
24
- path_hash[:query] = URI.encode_www_form(query)
25
- end
26
-
27
- res = do_connect(get_uri path_hash)
28
- map_quote(res)
21
+
22
+ map_quote(
23
+ do_request @@single + symbol, query
24
+ )
29
25
  end
30
26
 
31
27
  def bulk_quotes(symbols, snapshot = false, extended = false)
32
28
  query = validate_bulk_quotes_input!(symbols: symbols, snapshot: snapshot, extended: extended)
33
29
 
34
- path_hash = { host: MarketData.base_host, path: @@bulk }
35
- path_hash[:query] = URI.encode_www_form(query)
36
-
37
- res = do_connect(get_uri path_hash)
38
- map_bulk_quotes res
30
+ map_bulk_quotes(
31
+ do_request @@bulk, query
32
+ )
39
33
  end
40
34
 
41
35
  def candles(symbol, opts = {})
@@ -43,31 +37,27 @@ module MarketData
43
37
  opts = defaults.merge(opts)
44
38
  query = validate_candles_input!(**opts)
45
39
 
46
- path_hash = { host: MarketData.base_host, path: @@candles + opts[:resolution] + "/" + symbol }
47
- path_hash[:query] = URI.encode_www_form(query)
48
-
49
- res = do_connect(get_uri path_hash)
50
- map_candles res, symbol
40
+ map_candles(
41
+ do_request(@@candles + opts[:resolution] + "/" + symbol, query),
42
+ symbol
43
+ )
51
44
  end
52
45
 
53
46
  def bulk_candles(symbols, resolution = "D")
54
47
  query = validate_bulk_candles_input!(symbols: symbols, resolution: resolution)
55
48
  query = query.except(:resolution)
56
49
 
57
- path_hash = { host: MarketData.base_host, path: @@bulk_candles + resolution + "/" }
58
- path_hash[:query] = URI.encode_www_form(query)
59
-
60
- res = do_connect(get_uri path_hash)
61
- map_bulk_candles res
50
+ map_bulk_candles(
51
+ do_request @@bulk_candles + resolution + "/", query
52
+ )
62
53
  end
63
54
 
64
55
  def earnings(symbol, opts = {from: nil, to: nil, countback: nil, date: nil, report: nil})
65
- path_hash = { host: MarketData.base_host(), path: @@earnings + symbol}
66
56
  query = validate_earnings_input!(**opts)
67
- path_hash[:query] = URI.encode_www_form(query)
68
57
 
69
- res = do_connect(get_uri path_hash)
70
- map_earning res
58
+ map_earning(
59
+ do_request @@earnings + symbol, query
60
+ )
71
61
  end
72
62
  end
73
63
  end
@@ -109,9 +109,20 @@ module MarketData
109
109
  if state == :invalid
110
110
  raise BadParameterError.new(response)
111
111
  end
112
+
113
+ return result.merge(response)
112
114
  end
115
+ end
116
+
117
+ def validate_index_quote_input!(w52: nil)
118
+ if w52.nil? || !w52
119
+ return {}
120
+ end
121
+ {"52week" => w52}
122
+ end
113
123
 
114
- return result.merge(response)
124
+ def validate_index_candles_input!(resolution: nil, from: nil, to: nil, countback: nil)
125
+ validate_candles_input!(resolution: resolution, from: from, to: to, countback: countback)
115
126
  end
116
127
 
117
128
  def validate_from_to_countback_strategy(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MarketData
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/market_data.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "market_data/version"
4
4
  require "market_data/quotes"
5
5
  require "market_data/markets"
6
+ require "market_data/indexes"
6
7
 
7
8
  module MarketData
8
9
  @@base_host = "api.marketdata.app"
@@ -10,6 +11,7 @@ module MarketData
10
11
  class Client
11
12
  include MarketData::Quotes
12
13
  include MarketData::Markets
14
+ include MarketData::Indexes
13
15
 
14
16
  def initialize token
15
17
  @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.4.0
4
+ version: 0.5.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-14 00:00:00.000000000 Z
11
+ date: 2024-10-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby client for the MarketData API.
14
14
  email:
@@ -28,6 +28,7 @@ files:
28
28
  - lib/market_data/conn.rb
29
29
  - lib/market_data/constants.rb
30
30
  - lib/market_data/errors.rb
31
+ - lib/market_data/indexes.rb
31
32
  - lib/market_data/mappers.rb
32
33
  - lib/market_data/markets.rb
33
34
  - lib/market_data/models.rb