polygon-ruby-client 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 88a32dcdcf095e88b1f0263483dc1f3b1744525e97f243d2d8778224e27bee0d
4
+ data.tar.gz: 61edd7dd2fbbde5a0e573ef4cb7e3d282859c4ca69254f2517abd20f9da5315b
5
+ SHA512:
6
+ metadata.gz: a0316425b8e05f75850b5760cb407196acba7a328d3be5caa7ff6db4897b6769b7d27c8cb33019e2204438e4895d69b304f464df9f02a7a1cd492a07d3924173
7
+ data.tar.gz: f6c8d4f96c22a68b87d3d4ed6b96c2faca782c28c6a16c0fbbd26c1cacffd348f492fc56255d266e742780051df01a26aa4f5b8514ad7645394d56ce9cc517f9
@@ -0,0 +1,6 @@
1
+ .env
2
+ pkg
3
+ Gemfile.lock
4
+ .DS_Store
5
+ .bundle
6
+ .idea
@@ -0,0 +1,207 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Style/AndOr:
5
+ Enabled: false
6
+ Style/GlobalVars:
7
+ Enabled: false
8
+
9
+ Metrics/BlockLength:
10
+ Enabled: false
11
+
12
+ Style/MultilineIfModifier:
13
+ Enabled: false
14
+ Security/JSONLoad:
15
+ Enabled: false
16
+
17
+ Style/RescueModifier:
18
+ Enabled: false
19
+
20
+ Naming/MethodParameterName:
21
+ MinNameLength: 1
22
+
23
+ Layout/SpaceAroundMethodCallOperator:
24
+ Enabled: true
25
+ Lint/RaiseException:
26
+ Enabled: true
27
+ Lint/StructNewOverride:
28
+ Enabled: true
29
+ Style/ExponentialNotation:
30
+ Enabled: true
31
+ Style/HashEachMethods:
32
+ Enabled: true
33
+ Style/HashTransformKeys:
34
+ Enabled: true
35
+ Style/HashTransformValues:
36
+ Enabled: true
37
+
38
+ # Style/Alias:
39
+ # Enabled: false
40
+ # StyleGuide: https://relaxed.ruby.style/#stylealias
41
+
42
+ # Style/AsciiComments:
43
+ # Enabled: false
44
+ # StyleGuide: https://relaxed.ruby.style/#styleasciicomments
45
+
46
+ # Style/BeginBlock:
47
+ # Enabled: false
48
+ # StyleGuide: https://relaxed.ruby.style/#stylebeginblock
49
+
50
+ # Style/BlockDelimiters:
51
+ # Enabled: false
52
+ # StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
53
+
54
+ Style/CommentAnnotation:
55
+ Enabled: false
56
+ StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
57
+
58
+ Style/Documentation:
59
+ Enabled: false
60
+ StyleGuide: https://relaxed.ruby.style/#styledocumentation
61
+
62
+ # Layout/DotPosition:
63
+ # Enabled: false
64
+ # StyleGuide: https://relaxed.ruby.style/#layoutdotposition
65
+
66
+ # Style/DoubleNegation:
67
+ # Enabled: false
68
+ # StyleGuide: https://relaxed.ruby.style/#styledoublenegation
69
+
70
+ # Style/EndBlock:
71
+ # Enabled: false
72
+ # StyleGuide: https://relaxed.ruby.style/#styleendblock
73
+
74
+ # Style/FormatString:
75
+ # Enabled: false
76
+ # StyleGuide: https://relaxed.ruby.style/#styleformatstring
77
+
78
+ # Style/IfUnlessModifier:
79
+ # Enabled: false
80
+ # StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
81
+
82
+ # Style/Lambda:
83
+ # Enabled: false
84
+ # StyleGuide: https://relaxed.ruby.style/#stylelambda
85
+
86
+ # Style/ModuleFunction:
87
+ # Enabled: false
88
+ # StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
89
+
90
+ # Style/MultilineBlockChain:
91
+ # Enabled: false
92
+ # StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
93
+
94
+ # Style/NegatedIf:
95
+ # Enabled: false
96
+ # StyleGuide: https://relaxed.ruby.style/#stylenegatedif
97
+
98
+ # Style/NegatedWhile:
99
+ # Enabled: false
100
+ # StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
101
+
102
+ # Style/NumericPredicate:
103
+ # Enabled: false
104
+ # StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate
105
+
106
+ # Style/ParallelAssignment:
107
+ # Enabled: false
108
+ # StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
109
+
110
+ # Style/PercentLiteralDelimiters:
111
+ # Enabled: false
112
+ # StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
113
+
114
+ # Style/PerlBackrefs:
115
+ # Enabled: false
116
+ # StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
117
+
118
+ # Style/Semicolon:
119
+ # Enabled: false
120
+ # StyleGuide: https://relaxed.ruby.style/#stylesemicolon
121
+
122
+ # Style/SignalException:
123
+ # Enabled: false
124
+ # StyleGuide: https://relaxed.ruby.style/#stylesignalexception
125
+
126
+ # Style/SingleLineBlockParams:
127
+ # Enabled: false
128
+ # StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
129
+
130
+ # Style/SingleLineMethods:
131
+ # Enabled: false
132
+ # StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
133
+
134
+ # Layout/SpaceBeforeBlockBraces:
135
+ # Enabled: false
136
+ # StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
137
+
138
+ # Layout/SpaceInsideParens:
139
+ # Enabled: false
140
+ # StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
141
+
142
+ # Style/SpecialGlobalVars:
143
+ # Enabled: false
144
+ # StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
145
+
146
+ # Style/StringLiterals:
147
+ # Enabled: false
148
+ # StyleGuide: https://relaxed.ruby.style/#stylestringliterals
149
+
150
+ # Style/TrailingCommaInArguments:
151
+ # Enabled: false
152
+ # StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
153
+
154
+ # Style/TrailingCommaInArrayLiteral:
155
+ # Enabled: false
156
+ # StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
157
+
158
+ # Style/TrailingCommaInHashLiteral:
159
+ # Enabled: false
160
+ # StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
161
+
162
+ # Style/SymbolArray:
163
+ # Enabled: false
164
+ # StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
165
+
166
+ # Style/WhileUntilModifier:
167
+ # Enabled: false
168
+ # StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
169
+
170
+ # Style/WordArray:
171
+ # Enabled: false
172
+ # StyleGuide: https://relaxed.ruby.style/#stylewordarray
173
+
174
+ # Lint/AmbiguousRegexpLiteral:
175
+ # Enabled: false
176
+ # StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
177
+
178
+ # Lint/AssignmentInCondition:
179
+ # Enabled: false
180
+ # StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
181
+
182
+ Metrics/AbcSize:
183
+ Enabled: false
184
+
185
+ # Metrics/BlockNesting:
186
+ # Enabled: false
187
+
188
+ Metrics/ClassLength:
189
+ Enabled: false
190
+
191
+ Metrics/ModuleLength:
192
+ Enabled: false
193
+
194
+ Metrics/CyclomaticComplexity:
195
+ Enabled: false
196
+
197
+ Layout/LineLength:
198
+ Enabled: false
199
+
200
+ Metrics/MethodLength:
201
+ Enabled: false
202
+
203
+ Metrics/ParameterLists:
204
+ Enabled: false
205
+
206
+ Metrics/PerceivedComplexity:
207
+ Enabled: false
@@ -0,0 +1,8 @@
1
+ # polygon-ruby-client
2
+ Polygon.io API ruby client
3
+
4
+ Example usage:
5
+ ```ruby
6
+ client = Polygon::Api::Client.new(api_key: 'xxx')
7
+ client.trades('AAPL', '2020-08-14', {limit: 100})
8
+ ```
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FaradayMiddleware
4
+ class ParseOj < ResponseMiddleware
5
+ dependency 'oj'
6
+
7
+ define_parser do |body|
8
+ Oj.load(body, mode: :compat, symbol_keys: true) unless body.strip.empty?
9
+ end
10
+ end
11
+ end
12
+
13
+ Faraday::Response.register_middleware oj: FaradayMiddleware::ParseOj
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'oj'
5
+ require 'faraday_middleware'
6
+ require 'faraday_middleware/response_middleware'
7
+ require_relative 'faraday_middleware/parse_oj'
8
+
9
+ require_relative 'polygon/version'
10
+ require_relative 'polygon/logger'
11
+ require_relative 'polygon/api'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'api/endpoints'
4
+ require_relative 'api/connection'
5
+ require_relative 'api/request'
6
+ require_relative 'api/config'
7
+ require_relative 'api/client'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polygon
4
+ module Api
5
+ class Client
6
+ include Endpoints
7
+ include Connection
8
+ include Request
9
+ include Config
10
+
11
+ def initialize(options = {})
12
+ Config::ATTRIBUTES.each do |key|
13
+ send("#{key}=", options[key] || Polygon::Api.config.send(key))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polygon
4
+ module Api
5
+ module Config
6
+ extend self
7
+
8
+ ATTRIBUTES = %i[
9
+ proxy
10
+ user_agent
11
+ ca_path
12
+ ca_file
13
+ logger
14
+ timeout
15
+ open_timeout
16
+ endpoint
17
+ api_key
18
+ ].freeze
19
+
20
+ attr_accessor(*Config::ATTRIBUTES)
21
+
22
+ def reset!
23
+ self.endpoint = 'https://api.polygon.io'
24
+ self.api_key = ENV['POLYGON_API_KEY']
25
+ self.user_agent = "Polygon Ruby Client/#{Polygon::VERSION}"
26
+ self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil
27
+ self.ca_file = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_FILE : nil
28
+ self.proxy = nil
29
+ self.logger = nil
30
+ self.timeout = nil
31
+ self.open_timeout = nil
32
+ end
33
+ end
34
+
35
+ class << self
36
+ def configure
37
+ block_given? ? yield(Config) : Config
38
+ end
39
+
40
+ def config
41
+ Config
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ Polygon::Api::Config.reset!
@@ -0,0 +1,36 @@
1
+ module Polygon
2
+ module Api
3
+ module Connection
4
+ private
5
+
6
+ def headers
7
+ {}
8
+ end
9
+
10
+ def connection
11
+ @connection ||= begin
12
+ options = {}
13
+
14
+ options[:headers] = {}
15
+ options[:headers]['Accept'] = 'application/json; charset=utf-8'
16
+ options[:headers]['Content-Type'] = 'application/json; charset=utf-8'
17
+ options[:headers]['User-Agent'] = user_agent if user_agent
18
+ options[:proxy] = proxy if proxy
19
+ options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file
20
+
21
+ request_options = {}
22
+ request_options[:timeout] = timeout if timeout
23
+ request_options[:open_timeout] = open_timeout if open_timeout
24
+ request_options[:params_encoder] = Faraday::FlatParamsEncoder
25
+ options[:request] = request_options if request_options.any?
26
+
27
+ ::Faraday::Connection.new(endpoint, options) do |connection|
28
+ connection.use ::FaradayMiddleware::ParseOj, content_type: /\bjson$/
29
+ connection.response :logger, logger if logger
30
+ connection.adapter ::Faraday.default_adapter
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polygon
4
+ module Api
5
+ module Endpoints
6
+ def trades(symbol, date, options = {})
7
+ get("/v2/ticks/stocks/trades/#{symbol}/#{date}", { apiKey: api_key }.merge(options))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ module Polygon
2
+ module Api
3
+ module Request
4
+ def get(path, options = {})
5
+ request(:get, path, options)
6
+ end
7
+
8
+ def post(path, options = {})
9
+ request(:post, path, options)
10
+ end
11
+
12
+ def put(path, options = {})
13
+ request(:put, path, options)
14
+ end
15
+
16
+ def delete(path, options = {})
17
+ request(:delete, path, options)
18
+ end
19
+
20
+ private
21
+
22
+ def request(method, path, options)
23
+ path = [endpoint, path].join
24
+ response = connection.send(method) do |request|
25
+ case method
26
+ when :get, :delete
27
+ request.url(path, options)
28
+ when :post, :put
29
+ request.path = path
30
+ request.body = options.to_json unless options.empty?
31
+ end
32
+ request.options.merge!(options.delete(:request)) if options.key?(:request)
33
+ end
34
+ response.body
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ require 'logger'
2
+
3
+ module Polygon
4
+ class Logger < ::Logger
5
+ def self.logger
6
+ @logger ||= begin
7
+ logger = new STDOUT
8
+ logger.level = Logger::WARN
9
+ logger
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Polygon
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+ require 'polygon/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'polygon-ruby-client'
8
+ s.bindir = 'bin'
9
+ s.version = Polygon::VERSION
10
+ s.authors = ['Alex Yussupov']
11
+ s.email = 'alex@klepa.co'
12
+ s.platform = Gem::Platform::RUBY
13
+ s.required_rubygems_version = '>= 1.3.6'
14
+ s.required_ruby_version = '>= 2.3.0'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- spec/*`.split("\n")
17
+ s.require_paths = ['lib']
18
+ s.homepage = 'http://github.com/alex-klepa/polygon-ruby-client'
19
+ s.licenses = ['MIT']
20
+ s.summary = 'Polygon API.'
21
+ s.add_dependency 'faraday', '>= 1.00'
22
+ s.add_dependency 'faraday_middleware'
23
+ s.add_dependency 'oj'
24
+ s.add_development_dependency 'rake', '~> 10'
25
+ s.add_development_dependency 'rspec'
26
+ s.add_development_dependency 'rubocop', '0.72.0'
27
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polygon-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Yussupov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.00'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.00'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oj
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.72.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.72.0
97
+ description:
98
+ email: alex@klepa.co
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rubocop.yml"
105
+ - README.md
106
+ - lib/faraday_middleware/parse_oj.rb
107
+ - lib/polygon-ruby-client.rb
108
+ - lib/polygon/api.rb
109
+ - lib/polygon/api/client.rb
110
+ - lib/polygon/api/config.rb
111
+ - lib/polygon/api/connection.rb
112
+ - lib/polygon/api/endpoints.rb
113
+ - lib/polygon/api/request.rb
114
+ - lib/polygon/logger.rb
115
+ - lib/polygon/version.rb
116
+ - polygon-ruby-client.gemspec
117
+ homepage: http://github.com/alex-klepa/polygon-ruby-client
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.3.0
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.3.6
135
+ requirements: []
136
+ rubygems_version: 3.1.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Polygon API.
140
+ test_files: []