schwab-api-ruby 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,351 @@
1
+ require 'spec_helper'
2
+ require 'support/authenticated_client'
3
+ require 'schwab'
4
+
5
+ describe Schwab::Operations::GetQuotes do
6
+ include_context 'authenticated client'
7
+ # include_context 'webmock off'
8
+
9
+ pending 'valid symbol' do
10
+ subject do
11
+ client.get_quotes(symbols)
12
+ end
13
+
14
+ let(:symbols) { %w(PG MSFT CVX) }
15
+
16
+ let!(:expected_request) do
17
+ Schwab::Spec::Mocks::MockGetQuotes.mock_find(
18
+ request: {
19
+ headers: { 'Authorization': "Bearer #{client.access_token}" },
20
+ query: {
21
+ apikey: client.client_id,
22
+ symbol: symbols.join(','),
23
+ }.map {|k,v| [k, v.to_s] }.to_h,
24
+ },
25
+ response: {
26
+ body: <<~RESPONSE
27
+ {
28
+ "PG": {
29
+ "assetType": "EQUITY",
30
+ "symbol": "PG",
31
+ "description": "Procter & Gamble Company (The) Common Stock",
32
+ "bidPrice": 120.55,
33
+ "bidSize": 500,
34
+ "bidId": "P",
35
+ "askPrice": 120.99,
36
+ "askSize": 500,
37
+ "askId": "P",
38
+ "lastPrice": 120.55,
39
+ "lastSize": 0,
40
+ "lastId": "N",
41
+ "openPrice": 119.99,
42
+ "highPrice": 121.05,
43
+ "lowPrice": 119.78,
44
+ "bidTick": " ",
45
+ "closePrice": 119.32,
46
+ "netChange": 1.23,
47
+ "totalVolume": 6996550,
48
+ "quoteTimeInLong": 1566950400020,
49
+ "tradeTimeInLong": 1566945034633,
50
+ "mark": 120.55,
51
+ "exchange": "n",
52
+ "exchangeName": "NYSE",
53
+ "marginable": true,
54
+ "shortable": true,
55
+ "volatility": 0.01,
56
+ "digits": 2,
57
+ "52WkHigh": 121.76,
58
+ "52WkLow": 78.49,
59
+ "nAV": 0.0,
60
+ "peRatio": 79.1467,
61
+ "divAmount": 2.9836,
62
+ "divYield": 2.5,
63
+ "divDate": "2019-07-18 00:00:00.000",
64
+ "securityStatus": "Normal",
65
+ "regularMarketLastPrice": 120.55,
66
+ "regularMarketLastSize": 12155,
67
+ "regularMarketNetChange": 1.23,
68
+ "regularMarketTradeTimeInLong": 1566945000012,
69
+ "netPercentChangeInDouble": 1.0308,
70
+ "markChangeInDouble": 1.23,
71
+ "markPercentChangeInDouble": 1.0308,
72
+ "regularMarketPercentChangeInDouble": 1.0308,
73
+ "delayed": false
74
+ },
75
+ "MSFT": {
76
+ "assetType": "EQUITY",
77
+ "symbol": "MSFT",
78
+ "description": "Microsoft Corporation - Common Stock",
79
+ "bidPrice": 135.87,
80
+ "bidSize": 500,
81
+ "bidId": "K",
82
+ "askPrice": 136.06,
83
+ "askSize": 200,
84
+ "askId": "Q",
85
+ "lastPrice": 136.04,
86
+ "lastSize": 200,
87
+ "lastId": "D",
88
+ "openPrice": 136.39,
89
+ "highPrice": 136.72,
90
+ "lowPrice": 134.66,
91
+ "bidTick": " ",
92
+ "closePrice": 135.45,
93
+ "netChange": 0.59,
94
+ "totalVolume": 23115635,
95
+ "quoteTimeInLong": 1566950328949,
96
+ "tradeTimeInLong": 1566950275129,
97
+ "mark": 135.87,
98
+ "exchange": "q",
99
+ "exchangeName": "NASD",
100
+ "marginable": true,
101
+ "shortable": true,
102
+ "volatility": 0.0095,
103
+ "digits": 4,
104
+ "52WkHigh": 141.675,
105
+ "52WkLow": 93.96,
106
+ "nAV": 0.0,
107
+ "peRatio": 28.1021,
108
+ "divAmount": 1.84,
109
+ "divYield": 1.36,
110
+ "divDate": "2019-08-14 00:00:00.000",
111
+ "securityStatus": "Normal",
112
+ "regularMarketLastPrice": 135.74,
113
+ "regularMarketLastSize": 2,
114
+ "regularMarketNetChange": 0.29,
115
+ "regularMarketTradeTimeInLong": 1566936001000,
116
+ "netPercentChangeInDouble": 0.4356,
117
+ "markChangeInDouble": 0.42,
118
+ "markPercentChangeInDouble": 0.3101,
119
+ "regularMarketPercentChangeInDouble": 0.2141,
120
+ "delayed": false
121
+ },
122
+ "CVX": {
123
+ "assetType": "EQUITY",
124
+ "symbol": "CVX",
125
+ "description": "Chevron Corporation Common Stock",
126
+ "bidPrice": 116.06,
127
+ "bidSize": 1000,
128
+ "bidId": "P",
129
+ "askPrice": 117.75,
130
+ "askSize": 300,
131
+ "askId": "P",
132
+ "lastPrice": 116.38,
133
+ "lastSize": 0,
134
+ "lastId": "N",
135
+ "openPrice": 116.27,
136
+ "highPrice": 117.03,
137
+ "lowPrice": 115.04,
138
+ "bidTick": " ",
139
+ "closePrice": 115.74,
140
+ "netChange": 0.64,
141
+ "totalVolume": 4238458,
142
+ "quoteTimeInLong": 1566950400019,
143
+ "tradeTimeInLong": 1566949966528,
144
+ "mark": 116.06,
145
+ "exchange": "n",
146
+ "exchangeName": "NYSE",
147
+ "marginable": true,
148
+ "shortable": true,
149
+ "volatility": 0.0147,
150
+ "digits": 2,
151
+ "52WkHigh": 127.6,
152
+ "52WkLow": 100.22,
153
+ "nAV": 0.0,
154
+ "peRatio": 14.94,
155
+ "divAmount": 4.76,
156
+ "divYield": 4.11,
157
+ "divDate": "2019-08-16 00:00:00.000",
158
+ "securityStatus": "Normal",
159
+ "regularMarketLastPrice": 115.83,
160
+ "regularMarketLastSize": 7908,
161
+ "regularMarketNetChange": 0.09,
162
+ "regularMarketTradeTimeInLong": 1566945000008,
163
+ "netPercentChangeInDouble": 0.553,
164
+ "markChangeInDouble": 0.32,
165
+ "markPercentChangeInDouble": 0.2765,
166
+ "regularMarketPercentChangeInDouble": 0.0778,
167
+ "delayed": false
168
+ }
169
+ }
170
+ RESPONSE
171
+ }
172
+ )
173
+ end
174
+
175
+ let(:expected_result) do
176
+ {"PG"=>
177
+ {"assetType"=>"EQUITY",
178
+ "symbol"=>"PG",
179
+ "description"=>"Procter & Gamble Company (The) Common Stock",
180
+ "bidPrice"=>120.55,
181
+ "bidSize"=>500,
182
+ "bidId"=>"P",
183
+ "askPrice"=>120.99,
184
+ "askSize"=>500,
185
+ "askId"=>"P",
186
+ "lastPrice"=>120.55,
187
+ "lastSize"=>0,
188
+ "lastId"=>"N",
189
+ "openPrice"=>119.99,
190
+ "highPrice"=>121.05,
191
+ "lowPrice"=>119.78,
192
+ "bidTick"=>" ",
193
+ "closePrice"=>119.32,
194
+ "netChange"=>1.23,
195
+ "totalVolume"=>6996550,
196
+ "quoteTimeInLong"=>1566950400020,
197
+ "tradeTimeInLong"=>1566945034633,
198
+ "mark"=>120.55,
199
+ "exchange"=>"n",
200
+ "exchangeName"=>"NYSE",
201
+ "marginable"=>true,
202
+ "shortable"=>true,
203
+ "volatility"=>0.01,
204
+ "digits"=>2,
205
+ "52WkHigh"=>121.76,
206
+ "52WkLow"=>78.49,
207
+ "nAV"=>0.0,
208
+ "peRatio"=>79.1467,
209
+ "divAmount"=>2.9836,
210
+ "divYield"=>2.5,
211
+ "divDate"=>"2019-07-18 00:00:00.000",
212
+ "securityStatus"=>"Normal",
213
+ "regularMarketLastPrice"=>120.55,
214
+ "regularMarketLastSize"=>12155,
215
+ "regularMarketNetChange"=>1.23,
216
+ "regularMarketTradeTimeInLong"=>1566945000012,
217
+ "netPercentChangeInDouble"=>1.0308,
218
+ "markChangeInDouble"=>1.23,
219
+ "markPercentChangeInDouble"=>1.0308,
220
+ "regularMarketPercentChangeInDouble"=>1.0308,
221
+ "delayed"=>false},
222
+ "MSFT"=>
223
+ {"assetType"=>"EQUITY",
224
+ "symbol"=>"MSFT",
225
+ "description"=>"Microsoft Corporation - Common Stock",
226
+ "bidPrice"=>135.87,
227
+ "bidSize"=>500,
228
+ "bidId"=>"K",
229
+ "askPrice"=>136.06,
230
+ "askSize"=>200,
231
+ "askId"=>"Q",
232
+ "lastPrice"=>136.04,
233
+ "lastSize"=>200,
234
+ "lastId"=>"D",
235
+ "openPrice"=>136.39,
236
+ "highPrice"=>136.72,
237
+ "lowPrice"=>134.66,
238
+ "bidTick"=>" ",
239
+ "closePrice"=>135.45,
240
+ "netChange"=>0.59,
241
+ "totalVolume"=>23115635,
242
+ "quoteTimeInLong"=>1566950328949,
243
+ "tradeTimeInLong"=>1566950275129,
244
+ "mark"=>135.87,
245
+ "exchange"=>"q",
246
+ "exchangeName"=>"NASD",
247
+ "marginable"=>true,
248
+ "shortable"=>true,
249
+ "volatility"=>0.0095,
250
+ "digits"=>4,
251
+ "52WkHigh"=>141.675,
252
+ "52WkLow"=>93.96,
253
+ "nAV"=>0.0,
254
+ "peRatio"=>28.1021,
255
+ "divAmount"=>1.84,
256
+ "divYield"=>1.36,
257
+ "divDate"=>"2019-08-14 00:00:00.000",
258
+ "securityStatus"=>"Normal",
259
+ "regularMarketLastPrice"=>135.74,
260
+ "regularMarketLastSize"=>2,
261
+ "regularMarketNetChange"=>0.29,
262
+ "regularMarketTradeTimeInLong"=>1566936001000,
263
+ "netPercentChangeInDouble"=>0.4356,
264
+ "markChangeInDouble"=>0.42,
265
+ "markPercentChangeInDouble"=>0.3101,
266
+ "regularMarketPercentChangeInDouble"=>0.2141,
267
+ "delayed"=>false},
268
+ "CVX"=>
269
+ {"assetType"=>"EQUITY",
270
+ "symbol"=>"CVX",
271
+ "description"=>"Chevron Corporation Common Stock",
272
+ "bidPrice"=>116.06,
273
+ "bidSize"=>1000,
274
+ "bidId"=>"P",
275
+ "askPrice"=>117.75,
276
+ "askSize"=>300,
277
+ "askId"=>"P",
278
+ "lastPrice"=>116.38,
279
+ "lastSize"=>0,
280
+ "lastId"=>"N",
281
+ "openPrice"=>116.27,
282
+ "highPrice"=>117.03,
283
+ "lowPrice"=>115.04,
284
+ "bidTick"=>" ",
285
+ "closePrice"=>115.74,
286
+ "netChange"=>0.64,
287
+ "totalVolume"=>4238458,
288
+ "quoteTimeInLong"=>1566950400019,
289
+ "tradeTimeInLong"=>1566949966528,
290
+ "mark"=>116.06,
291
+ "exchange"=>"n",
292
+ "exchangeName"=>"NYSE",
293
+ "marginable"=>true,
294
+ "shortable"=>true,
295
+ "volatility"=>0.0147,
296
+ "digits"=>2,
297
+ "52WkHigh"=>127.6,
298
+ "52WkLow"=>100.22,
299
+ "nAV"=>0.0,
300
+ "peRatio"=>14.94,
301
+ "divAmount"=>4.76,
302
+ "divYield"=>4.11,
303
+ "divDate"=>"2019-08-16 00:00:00.000",
304
+ "securityStatus"=>"Normal",
305
+ "regularMarketLastPrice"=>115.83,
306
+ "regularMarketLastSize"=>7908,
307
+ "regularMarketNetChange"=>0.09,
308
+ "regularMarketTradeTimeInLong"=>1566945000008,
309
+ "netPercentChangeInDouble"=>0.553,
310
+ "markChangeInDouble"=>0.32,
311
+ "markPercentChangeInDouble"=>0.2765,
312
+ "regularMarketPercentChangeInDouble"=>0.0778,
313
+ "delayed"=>false}
314
+ }
315
+ end
316
+
317
+ it { is_expected.to eql(expected_result) }
318
+ end
319
+
320
+ pending 'invalid symbol' do
321
+ subject do
322
+ client.get_quotes(symbols)
323
+ end
324
+
325
+ let(:symbols) { %w(XZXX) }
326
+
327
+ let!(:expected_request) do
328
+ Schwab::Spec::Mocks::MockGetQuotes.mock_find(
329
+ request: {
330
+ headers: { 'Authorization': "Bearer #{client.access_token}" },
331
+ query: {
332
+ apikey: client.client_id,
333
+ symbol: symbols.join(','),
334
+ }.map {|k,v| [k, v.to_s] }.to_h,
335
+ },
336
+ response: {
337
+ body: <<~RESPONSE
338
+ {}
339
+ RESPONSE
340
+ }
341
+ )
342
+ end
343
+
344
+ let(:expected_result) do
345
+ {}
346
+ end
347
+
348
+ it { is_expected.to eql(expected_result) }
349
+ end
350
+
351
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schwab-api-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Winston Kotzan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0.20'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.20'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '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'
97
+ description: 'This is a gem for connecting to the OAuth/JSON-based Schwab API. See '
98
+ email:
99
+ - wak@wakproductions.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - CHANGELOG.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/schwab-api-ruby.rb
112
+ - lib/schwab.rb
113
+ - lib/schwab/authentication.rb
114
+ - lib/schwab/client.rb
115
+ - lib/schwab/error.rb
116
+ - lib/schwab/operations/base_operation.rb
117
+ - lib/schwab/operations/get_instrument_fundamentals.rb
118
+ - lib/schwab/operations/get_price_history.rb
119
+ - lib/schwab/operations/get_quotes.rb
120
+ - lib/schwab/operations/support/build_watchlist_items.rb
121
+ - lib/schwab/util.rb
122
+ - lib/schwab/version.rb
123
+ - schwab-api-ruby.gemspec
124
+ - spec/spec_helper.rb
125
+ - spec/support/authenticated_client.rb
126
+ - spec/support/spec/mocks/mock_get_instrument_fundamentals.rb
127
+ - spec/support/spec/mocks/mock_get_price_history.rb
128
+ - spec/support/spec/mocks/mock_get_quotes.rb
129
+ - spec/support/spec/mocks/mock_watchlists.rb
130
+ - spec/support/spec/mocks/tdameritrade_api_mock_base.rb
131
+ - spec/support/webmock_off.rb
132
+ - spec/tdameritrade/operations/error_spec.rb
133
+ - spec/tdameritrade/operations/get_instrument_fundamentals_spec.rb
134
+ - spec/tdameritrade/operations/get_price_history_spec.rb
135
+ - spec/tdameritrade/operations/get_quotes_spec.rb
136
+ homepage: https://github.com/wakproductions/schwab-api-ruby
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubygems_version: 3.3.26
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: This is a simple gem for connecting to the Schwab OAuth API
159
+ test_files:
160
+ - spec/spec_helper.rb
161
+ - spec/support/authenticated_client.rb
162
+ - spec/support/spec/mocks/mock_get_instrument_fundamentals.rb
163
+ - spec/support/spec/mocks/mock_get_price_history.rb
164
+ - spec/support/spec/mocks/mock_get_quotes.rb
165
+ - spec/support/spec/mocks/mock_watchlists.rb
166
+ - spec/support/spec/mocks/tdameritrade_api_mock_base.rb
167
+ - spec/support/webmock_off.rb
168
+ - spec/tdameritrade/operations/error_spec.rb
169
+ - spec/tdameritrade/operations/get_instrument_fundamentals_spec.rb
170
+ - spec/tdameritrade/operations/get_price_history_spec.rb
171
+ - spec/tdameritrade/operations/get_quotes_spec.rb