polygonio 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +49 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +121 -0
- data/README.md +50 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/lib/polygon_client/rest/api/crypto.rb +198 -0
- data/lib/polygon_client/rest/api/forex.rb +129 -0
- data/lib/polygon_client/rest/api/reference/locales.rb +22 -0
- data/lib/polygon_client/rest/api/reference/markets.rb +55 -0
- data/lib/polygon_client/rest/api/reference/stocks.rb +70 -0
- data/lib/polygon_client/rest/api/reference/tickers.rb +124 -0
- data/lib/polygon_client/rest/api/stocks.rb +327 -0
- data/lib/polygon_client/rest/api.rb +34 -0
- data/lib/polygon_client/rest/client.rb +70 -0
- data/lib/polygon_client/rest/errors.rb +43 -0
- data/lib/polygon_client/rest.rb +5 -0
- data/lib/polygon_client/types.rb +7 -0
- data/lib/polygon_client/version.rb +5 -0
- data/lib/polygon_client/websocket/client.rb +140 -0
- data/lib/polygon_client/websocket/errors.rb +20 -0
- data/lib/polygon_client/websocket/events.rb +101 -0
- data/lib/polygon_client/websocket.rb +5 -0
- data/lib/polygon_client.rb +16 -0
- data/polygon_client.gemspec +53 -0
- metadata +398 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb0ff578b04db8fe6b41f9a3244b4659b0f6d23dd394e29ff64e0237a3f9374c
|
4
|
+
data.tar.gz: 1d56b28b3eff0e966dad4229d224df0537bc2e9629c56f8dc3cf37122b521996
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a6a1e9f20f1134030737810b1242572745eccc840f90f1871dcff1ce9d1fbf00b7338b87171f8ef35da6352eb3398028e905edf45fcca963080ddb0517c4168
|
7
|
+
data.tar.gz: 3844d43a7caa11833c11c5fff6d993612c3378c2b6b916b97006e1a17eb31afd89b413e1f5da7615b51b046829472a54bd62257f09c37bf38e1fc8bffe69c8c4
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.6.0
|
6
|
+
DisabledByDefault: false
|
7
|
+
Exclude:
|
8
|
+
- '**/vendor/**/*'
|
9
|
+
- 'bin/**/*'
|
10
|
+
|
11
|
+
Layout/LineLength:
|
12
|
+
Max: 120
|
13
|
+
|
14
|
+
Metrics/AbcSize:
|
15
|
+
Max: 24
|
16
|
+
|
17
|
+
Metrics/CyclomaticComplexity:
|
18
|
+
Max: 10
|
19
|
+
|
20
|
+
Metrics/PerceivedComplexity:
|
21
|
+
Max: 10
|
22
|
+
|
23
|
+
Style/StringLiterals:
|
24
|
+
EnforcedStyle: double_quotes
|
25
|
+
|
26
|
+
Style/Documentation:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/SymbolArray:
|
30
|
+
EnforcedStyle: brackets
|
31
|
+
|
32
|
+
Style/AccessModifierDeclarations:
|
33
|
+
EnforcedStyle: group
|
34
|
+
|
35
|
+
Style/HashEachMethods:
|
36
|
+
Enabled: true
|
37
|
+
|
38
|
+
Style/HashTransformKeys:
|
39
|
+
Enabled: true
|
40
|
+
|
41
|
+
Style/HashTransformValues:
|
42
|
+
Enabled: true
|
43
|
+
|
44
|
+
Layout/MultilineMethodCallIndentation:
|
45
|
+
EnforcedStyle: indented_relative_to_receiver
|
46
|
+
|
47
|
+
Performance:
|
48
|
+
Exclude:
|
49
|
+
- '**/test/**/*'
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
polygonio (0.1.0)
|
5
|
+
activesupport (~> 6.0, >= 6.0.2.2)
|
6
|
+
dry-struct (~> 1.2, >= 1.2.0)
|
7
|
+
dry-types (~> 1.2, >= 1.2.2)
|
8
|
+
eventmachine (~> 1.2, >= 1.2.7)
|
9
|
+
faraday (~> 0.17, >= 0.17.3)
|
10
|
+
faraday_middleware (~> 0.13, >= 0.13.1)
|
11
|
+
faraday_middleware-parse_oj (~> 0.3, >= 0.3.2)
|
12
|
+
oj (~> 3.10, >= 3.10.1)
|
13
|
+
permessage_deflate (~> 0.1, >= 0.1.4)
|
14
|
+
websocket-driver (~> 0.7, >= 0.7.1)
|
15
|
+
|
16
|
+
GEM
|
17
|
+
remote: https://rubygems.org/
|
18
|
+
specs:
|
19
|
+
activesupport (6.0.2.2)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 0.7, < 2)
|
22
|
+
minitest (~> 5.1)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
zeitwerk (~> 2.2)
|
25
|
+
ast (2.4.0)
|
26
|
+
bundler-audit (0.6.1)
|
27
|
+
bundler (>= 1.2.0, < 3)
|
28
|
+
thor (~> 0.18)
|
29
|
+
concurrent-ruby (1.1.6)
|
30
|
+
dotenv (2.7.5)
|
31
|
+
dry-configurable (0.11.5)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
dry-core (~> 0.4, >= 0.4.7)
|
34
|
+
dry-equalizer (~> 0.2)
|
35
|
+
dry-container (0.7.2)
|
36
|
+
concurrent-ruby (~> 1.0)
|
37
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
38
|
+
dry-core (0.4.9)
|
39
|
+
concurrent-ruby (~> 1.0)
|
40
|
+
dry-equalizer (0.3.0)
|
41
|
+
dry-inflector (0.2.0)
|
42
|
+
dry-logic (1.0.6)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
dry-core (~> 0.2)
|
45
|
+
dry-equalizer (~> 0.2)
|
46
|
+
dry-struct (1.3.0)
|
47
|
+
dry-core (~> 0.4, >= 0.4.4)
|
48
|
+
dry-equalizer (~> 0.3)
|
49
|
+
dry-types (~> 1.3)
|
50
|
+
ice_nine (~> 0.11)
|
51
|
+
dry-types (1.4.0)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
dry-container (~> 0.3)
|
54
|
+
dry-core (~> 0.4, >= 0.4.4)
|
55
|
+
dry-equalizer (~> 0.3)
|
56
|
+
dry-inflector (~> 0.1, >= 0.1.2)
|
57
|
+
dry-logic (~> 1.0, >= 1.0.2)
|
58
|
+
eventmachine (1.2.7)
|
59
|
+
faker (2.11.0)
|
60
|
+
i18n (>= 1.6, < 2)
|
61
|
+
faraday (0.17.3)
|
62
|
+
multipart-post (>= 1.2, < 3)
|
63
|
+
faraday_middleware (0.14.0)
|
64
|
+
faraday (>= 0.7.4, < 1.0)
|
65
|
+
faraday_middleware-parse_oj (0.3.2)
|
66
|
+
faraday (~> 0.9)
|
67
|
+
faraday_middleware (>= 0.9.1, < 1.0)
|
68
|
+
oj (>= 2.0, < 4.0)
|
69
|
+
i18n (1.8.2)
|
70
|
+
concurrent-ruby (~> 1.0)
|
71
|
+
ice_nine (0.11.2)
|
72
|
+
jaro_winkler (1.5.4)
|
73
|
+
minitest (5.14.0)
|
74
|
+
multipart-post (2.1.1)
|
75
|
+
oj (3.10.6)
|
76
|
+
parallel (1.19.1)
|
77
|
+
parser (2.7.0.5)
|
78
|
+
ast (~> 2.4.0)
|
79
|
+
permessage_deflate (0.1.4)
|
80
|
+
rainbow (3.0.0)
|
81
|
+
rake (13.0.1)
|
82
|
+
rexml (3.2.4)
|
83
|
+
rubocop (0.80.1)
|
84
|
+
jaro_winkler (~> 1.5.1)
|
85
|
+
parallel (~> 1.10)
|
86
|
+
parser (>= 2.7.0.1)
|
87
|
+
rainbow (>= 2.2.2, < 4.0)
|
88
|
+
rexml
|
89
|
+
ruby-progressbar (~> 1.7)
|
90
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
91
|
+
rubocop-performance (1.5.2)
|
92
|
+
rubocop (>= 0.71.0)
|
93
|
+
ruby-progressbar (1.10.1)
|
94
|
+
thor (0.20.3)
|
95
|
+
thread_safe (0.3.6)
|
96
|
+
tzinfo (1.2.7)
|
97
|
+
thread_safe (~> 0.1)
|
98
|
+
unicode-display_width (1.6.1)
|
99
|
+
vcr (5.1.0)
|
100
|
+
websocket-driver (0.7.1)
|
101
|
+
websocket-extensions (>= 0.1.0)
|
102
|
+
websocket-extensions (0.1.4)
|
103
|
+
zeitwerk (2.3.0)
|
104
|
+
|
105
|
+
PLATFORMS
|
106
|
+
ruby
|
107
|
+
|
108
|
+
DEPENDENCIES
|
109
|
+
bundler (~> 2.0)
|
110
|
+
bundler-audit (~> 0.6)
|
111
|
+
dotenv (~> 2.7)
|
112
|
+
faker (~> 2.11)
|
113
|
+
minitest (~> 5.0)
|
114
|
+
polygonio!
|
115
|
+
rake (~> 13.0)
|
116
|
+
rubocop (~> 0.80)
|
117
|
+
rubocop-performance (~> 1.5)
|
118
|
+
vcr (~> 5.1)
|
119
|
+
|
120
|
+
BUNDLED WITH
|
121
|
+
2.1.2
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# PolygonClient (Ruby)
|
2
|
+
|
3
|
+
## Table of Contents
|
4
|
+
|
5
|
+
- [Background](#background)
|
6
|
+
- [Installation](#installation)
|
7
|
+
- [Usage](#usage)
|
8
|
+
|
9
|
+
## Background
|
10
|
+
|
11
|
+
This is a client library for Polygon.io. Please see [Polygon.io](https://polygon.io)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'polygon_client'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle install
|
24
|
+
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
**Create an instance of the client:**
|
29
|
+
|
30
|
+
All methods follow the documentation found [here]:https://polygon.io/docs pretty closely:
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
client = PolygonClient::Rest::Client.new(api_key)
|
36
|
+
|
37
|
+
# See tests for a full reference of all of methods
|
38
|
+
client.reference.tickers.list
|
39
|
+
|
40
|
+
client.stocks.
|
41
|
+
|
42
|
+
client.forex.historic_ticks
|
43
|
+
|
44
|
+
client.crypto.list # list exchanges
|
45
|
+
|
46
|
+
PolgygonClient::Websocket::Client.new(api_key).subscribe("XQ.BTC-USD") do |event|
|
47
|
+
pp "Incoming message"
|
48
|
+
pp event
|
49
|
+
end
|
50
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "polygon_client"
|
5
|
+
require "dotenv/load"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PolygonClient
|
4
|
+
module Rest
|
5
|
+
class Crypto < PolygonRestHandler
|
6
|
+
class CryptoExchange < PolygonResponse
|
7
|
+
attribute :id, Types::Integer
|
8
|
+
attribute :type, Types::String
|
9
|
+
attribute :market, Types::String
|
10
|
+
attribute :name, Types::String
|
11
|
+
attribute :url, Types::String
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
res = client.request.get("/v1/meta/crypto-exchanges")
|
16
|
+
Types::Array.of(CryptoExchange)[res.body]
|
17
|
+
end
|
18
|
+
|
19
|
+
class LastTradeResponse < PolygonResponse
|
20
|
+
attribute :status, Types::String
|
21
|
+
attribute :symbol, Types::String
|
22
|
+
attribute :last do
|
23
|
+
attribute :price, Types::JSON::Decimal
|
24
|
+
attribute :size, Types::JSON::Decimal
|
25
|
+
attribute :exchange, Types::Integer
|
26
|
+
attribute :conditions, Types::Array.of(Types::Integer)
|
27
|
+
attribute :timestamp, Types::Integer
|
28
|
+
end
|
29
|
+
attribute :last_average do
|
30
|
+
attribute :avg, Types::JSON::Decimal
|
31
|
+
attribute :trades_averaged, Types::Integer
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def last_trade(from, to)
|
36
|
+
from = Types::String[from]
|
37
|
+
to = Types::String[to]
|
38
|
+
|
39
|
+
res = client.request.get("/v1/last/crypto/#{from}/#{to}")
|
40
|
+
LastTradeResponse[res.body]
|
41
|
+
end
|
42
|
+
|
43
|
+
class DailyOpenCloseResponse < PolygonResponse
|
44
|
+
attribute :symbol, Types::String
|
45
|
+
attribute :is_utc, Types::Bool
|
46
|
+
attribute :day, Types::JSON::Date
|
47
|
+
attribute :open, Types::JSON::Decimal
|
48
|
+
attribute :close, Types::JSON::Decimal
|
49
|
+
attribute :open_trades, Types::Array do
|
50
|
+
attribute? :p, Types::JSON::Decimal
|
51
|
+
attribute? :s, Types::JSON::Decimal
|
52
|
+
attribute? :x, Types::Integer
|
53
|
+
attribute? :c, Types::Array.of(Types::Integer)
|
54
|
+
attribute? :t, Types::Integer
|
55
|
+
end
|
56
|
+
attribute :closing_trades, Types::Array do
|
57
|
+
attribute? :p, Types::JSON::Decimal
|
58
|
+
attribute? :s, Types::JSON::Decimal
|
59
|
+
attribute? :x, Types::Integer
|
60
|
+
attribute? :c, Types::Array.of(Types::Integer)
|
61
|
+
attribute? :t, Types::Integer
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def daily_open_close(from, to, date)
|
66
|
+
from = Types::String[from]
|
67
|
+
to = Types::String[to]
|
68
|
+
date = Types::JSON::Date[date]
|
69
|
+
|
70
|
+
res = client.request.get("/v1/open-close/crypto/#{from}/#{to}/#{date}")
|
71
|
+
DailyOpenCloseResponse[res.body]
|
72
|
+
end
|
73
|
+
|
74
|
+
class HistoricTradesResponse < PolygonResponse
|
75
|
+
attribute? :day, Types::JSON::Date
|
76
|
+
attribute? :map, Types::Hash
|
77
|
+
attribute? :ms_latency, Types::Integer
|
78
|
+
attribute? :status, Types::String
|
79
|
+
attribute? :symbol, Types::String
|
80
|
+
attribute? :type, Types::String
|
81
|
+
attribute :ticks, Types::Array do
|
82
|
+
attribute? :p, Types::JSON::Decimal
|
83
|
+
attribute? :s, Types::JSON::Decimal
|
84
|
+
attribute? :x, Types::Integer
|
85
|
+
attribute? :c, Types::Array.of(Types::Integer)
|
86
|
+
attribute? :t, Types::Integer
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def historic_trades(from, to, date, opts = {})
|
91
|
+
from = Types::String[from]
|
92
|
+
to = Types::String[to]
|
93
|
+
date = Types::JSON::Date[date]
|
94
|
+
opts = PagingParameters[opts]
|
95
|
+
|
96
|
+
res = client.request.get("/v1/historic/crypto/#{from}/#{to}/#{date}", opts.to_h)
|
97
|
+
HistoricTradesResponse[res.body]
|
98
|
+
end
|
99
|
+
|
100
|
+
class SnapshotTicker < PolygonResponse
|
101
|
+
attribute :ticker, Types::String
|
102
|
+
attribute :day do
|
103
|
+
attribute :c, Types::JSON::Decimal
|
104
|
+
attribute :h, Types::JSON::Decimal
|
105
|
+
attribute :l, Types::JSON::Decimal
|
106
|
+
attribute :o, Types::JSON::Decimal
|
107
|
+
attribute :v, Types::JSON::Decimal
|
108
|
+
end
|
109
|
+
attribute :last_trade do
|
110
|
+
attribute :p, Types::JSON::Decimal
|
111
|
+
attribute :s, Types::JSON::Decimal
|
112
|
+
attribute :x, Types::Integer
|
113
|
+
attribute :c, Types::Array.of(Types::Integer)
|
114
|
+
attribute :t, Types::Integer
|
115
|
+
end
|
116
|
+
attribute :min do
|
117
|
+
attribute :c, Types::JSON::Decimal
|
118
|
+
attribute :h, Types::JSON::Decimal
|
119
|
+
attribute :l, Types::JSON::Decimal
|
120
|
+
attribute :o, Types::JSON::Decimal
|
121
|
+
attribute :v, Types::JSON::Decimal
|
122
|
+
end
|
123
|
+
attribute :prev_day do
|
124
|
+
attribute :c, Types::JSON::Decimal
|
125
|
+
attribute :h, Types::JSON::Decimal
|
126
|
+
attribute :l, Types::JSON::Decimal
|
127
|
+
attribute :o, Types::JSON::Decimal
|
128
|
+
attribute :v, Types::JSON::Decimal
|
129
|
+
end
|
130
|
+
attribute :todays_change, Types::JSON::Decimal
|
131
|
+
attribute :todays_change_perc, Types::JSON::Decimal
|
132
|
+
attribute :updated, Types::Integer
|
133
|
+
end
|
134
|
+
|
135
|
+
class FullSnapshotResponse < PolygonResponse
|
136
|
+
attribute :status, Types::String
|
137
|
+
attribute :tickers, Types::Array.of(SnapshotTicker)
|
138
|
+
end
|
139
|
+
|
140
|
+
def full_snapshot
|
141
|
+
res = client.request.get("/v2/snapshot/locale/global/markets/crypto/tickers")
|
142
|
+
FullSnapshotResponse[res.body]
|
143
|
+
end
|
144
|
+
|
145
|
+
class SnapshotResponse < PolygonResponse
|
146
|
+
attribute :status, Types::String
|
147
|
+
attribute :ticker, SnapshotTicker
|
148
|
+
end
|
149
|
+
|
150
|
+
def snapshot(ticker)
|
151
|
+
ticker = Types::String[ticker]
|
152
|
+
res = client.request.get("/v2/snapshot/locale/global/markets/crypto/tickers/#{ticker}")
|
153
|
+
SnapshotResponse[res.body]
|
154
|
+
end
|
155
|
+
|
156
|
+
class SnapshotBookResponse < PolygonResponse
|
157
|
+
attribute :status, Types::String
|
158
|
+
attribute :data do
|
159
|
+
attribute :ticker, Types::String
|
160
|
+
attribute :bids, Types::Array do
|
161
|
+
attribute :p, Types::JSON::Decimal
|
162
|
+
attribute :x do
|
163
|
+
PolygonResponse::NUMBERS_TO_WORDS.each do |_n, w|
|
164
|
+
attribute? w.to_sym, Types::JSON::Decimal
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
attribute :asks, Types::Array do
|
169
|
+
attribute :p, Types::JSON::Decimal
|
170
|
+
attribute :x do
|
171
|
+
PolygonResponse::NUMBERS_TO_WORDS.each do |_n, w|
|
172
|
+
attribute? w.to_sym, Types::JSON::Decimal
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
attribute :bid_count, Types::JSON::Decimal
|
177
|
+
attribute :ask_count, Types::JSON::Decimal
|
178
|
+
attribute :spread, Types::JSON::Decimal
|
179
|
+
attribute :updated, Types::Integer
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def snapshot_book(ticker)
|
184
|
+
ticker = Types::String[ticker]
|
185
|
+
res = client.request.get("/v2/snapshot/locale/global/markets/crypto/tickers/#{ticker}/book")
|
186
|
+
SnapshotBookResponse[res.body]
|
187
|
+
end
|
188
|
+
|
189
|
+
class SnapshotGainersLosersResponse < FullSnapshotResponse; end
|
190
|
+
|
191
|
+
def snapshot_gainers_losers(direction)
|
192
|
+
direction = Types::Coercible::String.enum("gainers", "losers")[direction]
|
193
|
+
res = client.request.get("/v2/snapshot/locale/global/markets/crypto/#{direction}")
|
194
|
+
SnapshotGainersLosersResponse[res.body]
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PolygonClient
|
4
|
+
module Rest
|
5
|
+
class Forex < PolygonRestHandler
|
6
|
+
class HistoricTicksResponse < PolygonResponse
|
7
|
+
attribute? :day, Types::JSON::Date
|
8
|
+
attribute? :map, Types::Hash
|
9
|
+
attribute? :ms_latency, Types::Integer
|
10
|
+
attribute? :status, Types::String
|
11
|
+
attribute? :pair, Types::String
|
12
|
+
attribute? :type, Types::String
|
13
|
+
attribute :ticks, Types::Array do
|
14
|
+
attribute? :a, Types::JSON::Decimal # Asking price
|
15
|
+
attribute? :b, Types::JSON::Decimal # Bidding price
|
16
|
+
attribute? :x, Types::Integer # Exchange ID
|
17
|
+
attribute? :t, Types::Integer
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def historic_ticks(from, to, date, opts = {})
|
22
|
+
from = Types::String[from]
|
23
|
+
to = Types::String[to]
|
24
|
+
date = Types::JSON::Date[date]
|
25
|
+
opts = PagingParameters[opts]
|
26
|
+
|
27
|
+
res = client.request.get("/v1/historic/forex/#{from}/#{to}/#{date}", opts.to_h)
|
28
|
+
HistoricTicksResponse[res.body]
|
29
|
+
end
|
30
|
+
|
31
|
+
class CurrencyConversionResponse < PolygonResponse
|
32
|
+
attribute :status, Types::String
|
33
|
+
attribute :from, Types::String
|
34
|
+
attribute :to, Types::String
|
35
|
+
attribute :initial_amount, Types::Integer
|
36
|
+
attribute :converted, Types::JSON::Decimal
|
37
|
+
attribute :last do
|
38
|
+
attribute :bid, Types::JSON::Decimal
|
39
|
+
attribute :ask, Types::JSON::Decimal
|
40
|
+
attribute :exchange, Types::Integer
|
41
|
+
attribute :timestamp, Types::Integer
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def convert_currency(from, to, amount, precision = 2)
|
46
|
+
from = Types::String[from]
|
47
|
+
to = Types::String[to]
|
48
|
+
amount = Types::Coercible::Decimal[amount]
|
49
|
+
precision = Types::Integer[precision]
|
50
|
+
opts = { amount: amount, precision: precision }
|
51
|
+
|
52
|
+
res = client.request.get("/v1/conversion/#{from}/#{to}", opts)
|
53
|
+
CurrencyConversionResponse[res.body]
|
54
|
+
end
|
55
|
+
|
56
|
+
class LastQuoteResponse < PolygonResponse
|
57
|
+
attribute :status, Types::String
|
58
|
+
attribute :symbol, Types::String
|
59
|
+
attribute :last do
|
60
|
+
attribute :bid, Types::JSON::Decimal
|
61
|
+
attribute :ask, Types::JSON::Decimal
|
62
|
+
attribute :exchange, Types::Integer
|
63
|
+
attribute :timestamp, Types::Integer
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def last_quote(from, to)
|
68
|
+
from = Types::String[from]
|
69
|
+
to = Types::String[to]
|
70
|
+
|
71
|
+
res = client.request.get("/v1/last_quote/currencies/#{from}/#{to}")
|
72
|
+
LastQuoteResponse[res.body]
|
73
|
+
end
|
74
|
+
|
75
|
+
class SnapshotTicker < PolygonResponse
|
76
|
+
attribute :ticker, Types::String
|
77
|
+
attribute :day do
|
78
|
+
attribute :c, Types::JSON::Decimal
|
79
|
+
attribute :h, Types::JSON::Decimal
|
80
|
+
attribute :l, Types::JSON::Decimal
|
81
|
+
attribute :o, Types::JSON::Decimal
|
82
|
+
attribute :v, Types::JSON::Decimal
|
83
|
+
end
|
84
|
+
attribute :last_quote do
|
85
|
+
attribute :a, Types::JSON::Decimal
|
86
|
+
attribute :b, Types::JSON::Decimal
|
87
|
+
attribute :i, Types::JSON::Decimal
|
88
|
+
attribute :x, Types::Integer
|
89
|
+
attribute :t, Types::Integer
|
90
|
+
end
|
91
|
+
attribute :min do
|
92
|
+
attribute :c, Types::JSON::Decimal
|
93
|
+
attribute :h, Types::JSON::Decimal
|
94
|
+
attribute :l, Types::JSON::Decimal
|
95
|
+
attribute :o, Types::JSON::Decimal
|
96
|
+
attribute :v, Types::JSON::Decimal
|
97
|
+
end
|
98
|
+
attribute :prev_day do
|
99
|
+
attribute :c, Types::JSON::Decimal
|
100
|
+
attribute :h, Types::JSON::Decimal
|
101
|
+
attribute :l, Types::JSON::Decimal
|
102
|
+
attribute :o, Types::JSON::Decimal
|
103
|
+
attribute :v, Types::JSON::Decimal
|
104
|
+
end
|
105
|
+
attribute :todays_change, Types::JSON::Decimal
|
106
|
+
attribute :todays_change_perc, Types::JSON::Decimal
|
107
|
+
attribute :updated, Types::Integer
|
108
|
+
end
|
109
|
+
|
110
|
+
class FullSnapshotResponse < PolygonResponse
|
111
|
+
attribute :status, Types::String
|
112
|
+
attribute :tickers, Types::Array.of(SnapshotTicker)
|
113
|
+
end
|
114
|
+
|
115
|
+
def full_snapshot
|
116
|
+
res = client.request.get("/v2/snapshot/locale/global/markets/forex/tickers")
|
117
|
+
FullSnapshotResponse[res.body]
|
118
|
+
end
|
119
|
+
|
120
|
+
class SnapshotGainersLosersResponse < FullSnapshotResponse; end
|
121
|
+
|
122
|
+
def snapshot_gainers_losers(direction)
|
123
|
+
direction = Types::Coercible::String.enum("gainers", "losers")[direction]
|
124
|
+
res = client.request.get("/v2/snapshot/locale/global/markets/forex/#{direction}")
|
125
|
+
SnapshotGainersLosersResponse[res.body]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PolygonClient
|
4
|
+
module Rest
|
5
|
+
module Reference
|
6
|
+
class Locales < PolygonRestHandler
|
7
|
+
class LocalesResponse < PolygonResponse
|
8
|
+
attribute :status, Types::String
|
9
|
+
attribute :results, Types::Array do
|
10
|
+
attribute :locale, Types::String
|
11
|
+
attribute :name, Types::String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
res = client.request.get("/v2/reference/locales")
|
17
|
+
LocalesResponse[res.body]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PolygonClient
|
4
|
+
module Rest
|
5
|
+
module Reference
|
6
|
+
class Markets < PolygonRestHandler
|
7
|
+
class MarketsResponse < PolygonResponse
|
8
|
+
attribute :status, Types::String
|
9
|
+
attribute :results, Types::Array do
|
10
|
+
attribute :market, Types::String
|
11
|
+
attribute :desc, Types::String
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def list
|
16
|
+
res = client.request.get("/v2/reference/markets")
|
17
|
+
MarketsResponse[res.body]
|
18
|
+
end
|
19
|
+
|
20
|
+
class MarketStatusResponse < PolygonResponse
|
21
|
+
attribute :market, Types::String
|
22
|
+
attribute :server_time, Types::String
|
23
|
+
attribute :exchanges do
|
24
|
+
attribute :nyse, Types::String
|
25
|
+
attribute :nasdaq, Types::String
|
26
|
+
attribute :otc, Types::String
|
27
|
+
end
|
28
|
+
attribute :currencies do
|
29
|
+
attribute :fx, Types::String
|
30
|
+
attribute :crypto, Types::String
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def status
|
35
|
+
res = client.request.get("/v1/marketstatus/now")
|
36
|
+
MarketStatusResponse[res.body]
|
37
|
+
end
|
38
|
+
|
39
|
+
class MarketHolidaysResponse < PolygonResponse
|
40
|
+
attribute :exchange, Types::String
|
41
|
+
attribute :name, Types::String
|
42
|
+
attribute :status, Types::String
|
43
|
+
attribute :date, Types::JSON::DateTime
|
44
|
+
attribute? :open, Types::JSON::DateTime
|
45
|
+
attribute? :close, Types::JSON::DateTime
|
46
|
+
end
|
47
|
+
|
48
|
+
def holidays
|
49
|
+
res = client.request.get("/v1/marketstatus/upcoming")
|
50
|
+
Types::Array.of(MarketHolidaysResponse)[res.body]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|