lita-onewheel-finance 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 +4 -4
- data/lib/lita/handlers/onewheel_finance.rb +42 -65
- data/lita-onewheel-finance.gemspec +1 -1
- data/spec/lita/handlers/onewheel_finance_spec.rb +16 -4
- 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: 86924c83a1b54b7034f09552a2ff66c46723de2baa4c3b061efbdfc9bcb39d70
|
4
|
+
data.tar.gz: 4b2908349083d6dc6c740fd5c2ddc4b18e7cd90d6180fc672644c09be07530cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 750a2b4e836adfaf7bea9913051037a6277c8f26787861fe14ae38389c5479c5e97e8412a9a1cd3251d4c6ad451914cf42776c400d1e97babf88adcdcdbfb4d9
|
7
|
+
data.tar.gz: d67f291c283fc66939cb3a3c59b2954247f7d807c4ba208c8beda96bc4ac6c5c504823dae63f31d944f1f43a6a3cbb51ba40f718a31f39eeb15bc725dd5aed6f
|
@@ -68,7 +68,7 @@ class AlphaVantageQuote
|
|
68
68
|
end
|
69
69
|
|
70
70
|
class WorldTradeDataQuote
|
71
|
-
attr_reader :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange, :error, :name
|
71
|
+
attr_reader :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange, :error, :name, :message
|
72
72
|
attr_accessor :symbol
|
73
73
|
|
74
74
|
def initialize(symbol, api_key)
|
@@ -76,6 +76,10 @@ class WorldTradeDataQuote
|
|
76
76
|
@symbol = symbol
|
77
77
|
@api_key = api_key
|
78
78
|
|
79
|
+
if @symbol[':']
|
80
|
+
(@exchange, @symbol) = @symbol.split /:/
|
81
|
+
end
|
82
|
+
|
79
83
|
self.call_api
|
80
84
|
|
81
85
|
hash = JSON.parse(@response)
|
@@ -84,13 +88,25 @@ class WorldTradeDataQuote
|
|
84
88
|
if hash['Message'].to_s.include? 'Error'
|
85
89
|
@error = true
|
86
90
|
self.run_search
|
87
|
-
|
88
|
-
|
89
|
-
|
91
|
+
|
92
|
+
if @message
|
93
|
+
@error = true
|
94
|
+
return
|
95
|
+
else
|
96
|
+
self.call_api
|
97
|
+
hash = JSON.parse(@response)
|
98
|
+
@error = false
|
99
|
+
end
|
90
100
|
else
|
91
101
|
@error = false
|
92
102
|
end
|
93
103
|
|
104
|
+
unless hash['data']
|
105
|
+
@message = "Error getting data for #{@symbol}"
|
106
|
+
@error = true
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
94
110
|
quote = hash['data'][0]
|
95
111
|
|
96
112
|
quote.keys.each do |key|
|
@@ -128,6 +144,10 @@ class WorldTradeDataQuote
|
|
128
144
|
url = "#{@base_uri}/stock"
|
129
145
|
params = {symbol: @symbol, api_token: @api_key}
|
130
146
|
|
147
|
+
if @exchange
|
148
|
+
params[:stock_exchange] = @exchange
|
149
|
+
end
|
150
|
+
|
131
151
|
Lita.logger.debug "call_api: #{url} #{params.inspect}"
|
132
152
|
|
133
153
|
@response = RestClient.get url, {params: params}
|
@@ -149,62 +169,15 @@ class WorldTradeDataQuote
|
|
149
169
|
|
150
170
|
response = RestClient.get url, {params: params}
|
151
171
|
|
152
|
-
Lita.logger.debug "response: #{
|
172
|
+
Lita.logger.debug "response: #{response}"
|
153
173
|
result = JSON.parse(response)
|
154
174
|
|
155
175
|
if result['total_returned'] == 1
|
156
176
|
@symbol = result['data'][0]['symbol']
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
price_str.to_f.round(2)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
class WorldTradeDataSearch
|
166
|
-
attr_reader :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange, :error, :name
|
167
|
-
|
168
|
-
def initialize(json_blob)
|
169
|
-
Lita.logger.debug "parsing: #{json_blob}"
|
170
|
-
hash = JSON.parse(json_blob)
|
171
|
-
|
172
|
-
if hash['Message'].to_s.include? 'Error'
|
173
|
-
@error = true
|
174
|
-
return
|
175
|
-
else
|
176
|
-
@error = false
|
177
|
-
end
|
178
|
-
|
179
|
-
quote = hash['data'][0]
|
180
|
-
|
181
|
-
quote.keys.each do |key|
|
182
|
-
case key
|
183
|
-
when "symbol"
|
184
|
-
@symbol = quote[key]
|
185
|
-
when "price_open"
|
186
|
-
@open = self.fix_number quote[key]
|
187
|
-
when "day_high"
|
188
|
-
@high = self.fix_number quote[key]
|
189
|
-
when "day_low"
|
190
|
-
@low = self.fix_number quote[key]
|
191
|
-
when "price"
|
192
|
-
@price = self.fix_number quote[key]
|
193
|
-
when "volume"
|
194
|
-
@volume = quote[key].to_i
|
195
|
-
when "last_trade_time"
|
196
|
-
@trading_day = quote[key]
|
197
|
-
when "08. previous close"
|
198
|
-
@prev_close = self.fix_number quote[key]
|
199
|
-
when "day_change"
|
200
|
-
@change = self.fix_number quote[key]
|
201
|
-
when "change_pct"
|
202
|
-
@change_percent = self.fix_number quote[key]
|
203
|
-
when 'stock_exchange_short'
|
204
|
-
@exchange = quote[key].sub /NYSEARCA/, 'NYSE'
|
205
|
-
when 'name'
|
206
|
-
@name = quote[key]
|
207
|
-
end
|
177
|
+
elsif result['total_returned'].to_i > 1
|
178
|
+
Lita.logger.debug "many search results: #{result.inspect}"
|
179
|
+
x = result['data'].map { |k| k.values[0] }
|
180
|
+
@message = "`#{symbol}` not found, did you mean one of #{x.join(', ')}?"
|
208
181
|
end
|
209
182
|
end
|
210
183
|
|
@@ -217,13 +190,17 @@ module Lita
|
|
217
190
|
module Handlers
|
218
191
|
class OnewheelFinance < Handler
|
219
192
|
config :apikey, required: true
|
220
|
-
route /
|
193
|
+
route /qu*o*t*e*\s+(.+)/i, :handle_quote, command: true
|
221
194
|
|
222
195
|
def handle_quote(response)
|
223
196
|
stock = handle_world_trade_data response.matches[0][0]
|
224
197
|
|
225
198
|
if stock.error
|
226
|
-
|
199
|
+
if stock.message
|
200
|
+
str = stock.message
|
201
|
+
else
|
202
|
+
str = "`#{stock.symbol}` not found on any stock exchange."
|
203
|
+
end
|
227
204
|
else
|
228
205
|
str = "#{IrcColors::grey}#{stock.exchange} - #{IrcColors::reset}#{stock.symbol}: #{IrcColors::blue}$#{stock.price}#{IrcColors::reset} "
|
229
206
|
if stock.change >= 0
|
@@ -248,13 +225,13 @@ module Lita
|
|
248
225
|
end
|
249
226
|
|
250
227
|
# deprecated for now
|
251
|
-
def handle_alphavantage
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
end
|
228
|
+
#def handle_alphavantage
|
229
|
+
# url = "https://www.alphavantage.co/query"
|
230
|
+
# params = {function: 'GLOBAL_QUOTE', symbol: response.matches[0][0], apikey: config.apikey}
|
231
|
+
# Lita.logger.debug "#{url} #{params.inspect}"
|
232
|
+
# resp = RestClient.get url, {params: params}
|
233
|
+
# stock = GlobalQuote.new resp
|
234
|
+
#end
|
258
235
|
|
259
236
|
Lita.register_handler(self)
|
260
237
|
end
|
@@ -25,12 +25,24 @@ describe Lita::Handlers::OnewheelFinance, lita_handler: true do
|
|
25
25
|
expect(replies.last).to include('(Consumer Staples Select Sector SPDR Fund)')
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
29
|
-
mock_up 'worldtradedata-
|
30
|
-
send_command '
|
31
|
-
expect(replies.last).to
|
28
|
+
it 'nasdaq:lulu' do
|
29
|
+
mock_up 'worldtradedata-quote-up'
|
30
|
+
send_command 'q nasdaq:lulu'
|
31
|
+
expect(replies.last).to include("\u000314NASDAQ - \u0003LULU: \u000302$233.01\u0003")
|
32
32
|
end
|
33
33
|
|
34
|
+
#it 'errors' do
|
35
|
+
# mock_up 'worldtradedata-error'
|
36
|
+
# send_command 'quote in'
|
37
|
+
# expect(replies.last).to eq('`in` not found on any stock exchange.')
|
38
|
+
#end
|
39
|
+
|
40
|
+
|
41
|
+
# This doesn't exist
|
42
|
+
#it 'TADAWUL:2222' do
|
43
|
+
# mock_up 'worldtradedata-TADAWUL-2222.json'
|
44
|
+
#
|
45
|
+
#end
|
34
46
|
#it 'searches with 1 result' do
|
35
47
|
# mock_up 'worldtradedata-search-1'
|
36
48
|
# send_command 'quote nike'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-onewheel-finance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kreps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|