market_data 0.2.0 → 0.2.1
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/CHANGELOG.md +6 -1
- data/README.md +99 -9
- data/lib/market_data/quotes.rb +17 -5
- data/lib/market_data/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b63212c9e8ada21f198021bc3537392d9a6a34933682ebe789923883c2f38131
|
4
|
+
data.tar.gz: 9afa24ef746a81f115628f65aff4bccfdbfbf3086887444d62409545be76b7fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e21e172593fcee9340de7ca5ac37373db2d07479e2c912c01d7bf05399e012edcf405caf12c2cbf3ad0545b4ae8a166d6c98f40f67367e60040f818356866666
|
7
|
+
data.tar.gz: a3fcd6d6368c073621e9f400be5412b82e88ada5cce2b00a26b4e6697b97b6beb568564f64032c6c8eb777db93fe7afa3f324c616465e2913b838fd02ffa3eed
|
data/CHANGELOG.md
CHANGED
@@ -19,4 +19,9 @@
|
|
19
19
|
- Internal rework of code. New modules for models, mappers, constants and errors
|
20
20
|
- Introduced unit tests for almost all modules.
|
21
21
|
- Introduced coverage. Currently at 85%
|
22
|
-
- Add functionality for [Candles](https://www.marketdata.app/docs/api/stocks/candles) and [Bulk Candles](https://www.marketdata.app/docs/api/stocks/bulkcandles) endpoints
|
22
|
+
- Add functionality for [Candles](https://www.marketdata.app/docs/api/stocks/candles) and [Bulk Candles](https://www.marketdata.app/docs/api/stocks/bulkcandles) endpoints
|
23
|
+
|
24
|
+
## [0.2.1] - 2024-10-09
|
25
|
+
|
26
|
+
- Fix broken tests
|
27
|
+
- Add support for new optional parameters for `quotes` and `bulk_quotes` endpoint
|
data/README.md
CHANGED
@@ -2,17 +2,107 @@
|
|
2
2
|
|
3
3
|
A Ruby wrapper for the [MarketData API](https://www.marketdata.app/docs/api).
|
4
4
|
|
5
|
+

|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
$ gem install
|
9
|
+
$ gem install market_data
|
8
10
|
$ bundle install
|
9
11
|
|
10
12
|
## Usage
|
11
13
|
|
12
|
-
|
14
|
+
You must instantiate a `MarketData::Client` before running any method. You'll need your MarketData API token first.
|
15
|
+
|
16
|
+
$ client = MarketData::Client.new "YOUR_API_TOKEN"
|
17
|
+
|
13
18
|
$ client.quote("AAPL")
|
14
19
|
$ => <struct MarketData::Models::Quote symbol="AAPL", ask=231.42, askSize=2, bid=231.4, .....
|
15
20
|
|
21
|
+
### Quotes
|
22
|
+
For getting a single quote, run the `quote` method just as the example above.
|
23
|
+
|
24
|
+
#### Optional parameters
|
25
|
+
|
26
|
+
* `w52`
|
27
|
+
|
28
|
+
For getting fields with 52-week low and high information, pass true as the `w52` parameter.
|
29
|
+
|
30
|
+
$ q = client.quote("AAPL", w52=true)
|
31
|
+
$ => q.high52 = 252.11
|
32
|
+
$ => q.low52 = 222.35
|
33
|
+
**It is `false` by default.**
|
34
|
+
|
35
|
+
* `extended`
|
36
|
+
|
37
|
+
For getting a quote when market is on extended hours, you have to supply the `extended` parameter as true.
|
38
|
+
|
39
|
+
**It is false by default**, so if you fetch a quote during extended hours without the parameter, you'll always get the quote at closing time.
|
40
|
+
|
41
|
+
### Bulk quotes
|
42
|
+
|
43
|
+
For getting multiple quotes in a single request, use the `bulk_candle` method.
|
44
|
+
|
45
|
+
$ quotes = client.bulk_quotes(["AAPL", "AMD", "NOTAQUOTE])
|
46
|
+
|
47
|
+
$ quotes["AMD"] => <struct MarketData::Models::Quote symbol="AMD", ask=150.42, askSize=2, bid=146.4, .....
|
48
|
+
|
49
|
+
$ quotes["NOTAQUOTE"] = nil
|
50
|
+
|
51
|
+
If a quote is not found, the hashmap will return a nil value for that ticker's key.
|
52
|
+
|
53
|
+
#### Optional parameters
|
54
|
+
|
55
|
+
* `snapshot`
|
56
|
+
|
57
|
+
If snapshot is true, any supplied array of symbols will be ignored and a complete snapshot of the market ticker's will be returned.
|
58
|
+
|
59
|
+
$ quotes = client.bulk_quotes([], snapshot = true)
|
60
|
+
|
61
|
+
$ quotes["A"] => <struct MarketData::Models::Quote symbol="A", ask=56.32, askSize=45, bid=67, .....
|
62
|
+
....
|
63
|
+
$ quotes["Z"] => <struct MarketData::Models::Quote symbol="Z", ask=25, askSize=3, bid=14.5, .....
|
64
|
+
|
65
|
+
**This could use all you API credits. Use with caution.**
|
66
|
+
|
67
|
+
* `extended`
|
68
|
+
|
69
|
+
For getting a quote when market is on extended hours, you have to supply the `extended` parameter as true.
|
70
|
+
|
71
|
+
**It is false by default**, so if you fetch a quote during extended hours without the parameter, you'll get the quote at closing time.
|
72
|
+
|
73
|
+
### Candles
|
74
|
+
For getting ticker candles, you'll need to specify:
|
75
|
+
* a ticker symbol
|
76
|
+
* a resolution (`M`, `D`, `W`, etc. See [docs](https://www.marketdata.app/docs/api/stocks/candles#request-parameters) for a complete list)
|
77
|
+
* a strategy to specfy a date range. You can use `from` and `to` OR `to` and `countback`.
|
78
|
+
|
79
|
+
|
80
|
+
As an example, for getting candles for last week, for the first strategy:
|
81
|
+
|
82
|
+
$ quotes = client.candles("AAPL", "D", (Time.current - 1.week).iso8601, Time.current.iso8601, nil)
|
83
|
+
|
84
|
+
and for the second
|
85
|
+
|
86
|
+
$ quotes = client.candles("AAPL", "D", nil, Time.current.iso8601, 7)
|
87
|
+
|
88
|
+
`to` and `from` can receive an ISO 8601 compliant utc format or a unix timestamp.
|
89
|
+
|
90
|
+
### Bulk candles
|
91
|
+
|
92
|
+
For the `bulk_candles` method you pass a array of ticker symbols. Resolution is daily by default, although any daily variation will work as well (like `2D`, `3D`, etc.)
|
93
|
+
|
94
|
+
It returns a hashmap with the ticker symbol as a key.
|
95
|
+
|
96
|
+
$ candles = cl.bulk_candles(["AAPL", "AMD", "NOTAQUOTE"])
|
97
|
+
|
98
|
+
$ candles["AMD"]
|
99
|
+
$ => #<struct MarketData::Models::Candle symbol="AMD", open=174.05, high=174.05, low=169.55, close=171.02, volume=33391035, time=1728446400>
|
100
|
+
$ candles["AAPL"]
|
101
|
+
$ => #<struct MarketData::Models::Candle symbol="AAPL", open=225.23, high=229.75, low=224.83, close=229.54, volume=31398884, time=1728446400>
|
102
|
+
$ candles["NOTAQUOTE"] => nil
|
103
|
+
|
104
|
+
If a quote is not found, the hashmap will return a nil value for that ticker's key.
|
105
|
+
|
16
106
|
## ROADMAP
|
17
107
|
|
18
108
|
The following is an ordered list of next expected developments, based on the endpoints present in the [docs](https://www.marketdata.app/docs/api)
|
@@ -22,19 +112,19 @@ From Stocks endpoints:
|
|
22
112
|
- [X] Bulk Stocks
|
23
113
|
- [X] Candles
|
24
114
|
- [X] Bulk Candles
|
25
|
-
- [X] Support for optional parameters for Bulk
|
26
|
-
- [] Earnings
|
115
|
+
- [X] Support for new optional parameters for Quotes and Bulk Quotes
|
116
|
+
- [ ] Earnings
|
27
117
|
|
28
118
|
From Markets endpoints:
|
29
|
-
- [] Status
|
119
|
+
- [ ] Status
|
30
120
|
|
31
121
|
From Indices endpoints:
|
32
|
-
- [] Quotes
|
33
|
-
- [] Candles
|
122
|
+
- [ ] Quotes
|
123
|
+
- [ ] Candles
|
34
124
|
|
35
125
|
From Stocks endpoints:
|
36
|
-
- [] Support for optional parameters for Candles
|
37
|
-
- [] Support for optional parameters for Bulk Candles
|
126
|
+
- [ ] Support for optional parameters for Candles
|
127
|
+
- [ ] Support for optional parameters for Bulk Candles
|
38
128
|
|
39
129
|
|
40
130
|
## Tests
|
data/lib/market_data/quotes.rb
CHANGED
@@ -13,28 +13,40 @@ module MarketData
|
|
13
13
|
@@candles = "/v1/stocks/candles/"
|
14
14
|
@@bulk_candles = "/v1/stocks/bulkcandles/"
|
15
15
|
|
16
|
-
def quote(symbol, w52 = false)
|
16
|
+
def quote(symbol, w52 = false, extended = false)
|
17
17
|
path_hash = { host: MarketData.base_host, path: @@single + symbol }
|
18
|
+
query_hash = {}
|
18
19
|
if w52
|
19
|
-
|
20
|
+
query_hash["52week"] = true
|
21
|
+
end
|
22
|
+
# MarketData API considers extended as true by default
|
23
|
+
if !extended
|
24
|
+
query_hash[:extended] = false
|
25
|
+
end
|
26
|
+
if !query_hash.empty?
|
27
|
+
path_hash[:query] = URI.encode_www_form(query_hash)
|
20
28
|
end
|
21
29
|
res = do_connect(get_uri path_hash)
|
22
30
|
map_quote(res)
|
23
31
|
end
|
24
32
|
|
25
|
-
def bulk_quotes(symbols, snapshot = false)
|
33
|
+
def bulk_quotes(symbols, snapshot = false, extended = false)
|
26
34
|
path_hash = { host: MarketData.base_host, path: @@bulk }
|
27
35
|
query_hash = {}
|
28
36
|
|
37
|
+
# MarketData API considers extended as true by default
|
38
|
+
if !extended
|
39
|
+
query_hash[:extended] = false
|
40
|
+
end
|
41
|
+
|
29
42
|
if snapshot
|
30
43
|
query_hash[:snapshot] = true
|
31
44
|
else
|
32
45
|
if !symbols.is_a?(Array) || symbols.size < 1
|
33
46
|
raise BadParameterError.new("symbols must be a non-empty list")
|
34
47
|
end
|
35
|
-
query_hash =
|
48
|
+
query_hash[:symbols] = symbols.join(",")
|
36
49
|
end
|
37
|
-
|
38
50
|
path_hash[:query] = URI.encode_www_form(query_hash)
|
39
51
|
|
40
52
|
res = do_connect(get_uri path_hash)
|
data/lib/market_data/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
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-09
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby client for the MarketData API.
|
14
14
|
email:
|