lita-onewheel-finance 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00f1e5670bd0eb3308b2f6d14bedb2013fc4c61cf36d7162a43663e9c8dbd099
4
- data.tar.gz: 9d577a5c2baa823dd3ce3bd56ba269bcbed6f039b867a10e1e2b13252b0bacdc
3
+ metadata.gz: 5edbbe2ef63969dd624af3c1657c738648ff8b5faf965379860c87e8283f95f2
4
+ data.tar.gz: 978e055da01a370ce7f6c835ecffedb4cf8bee00edc29cda2586d4a9cbee57db
5
5
  SHA512:
6
- metadata.gz: d01b6df24ffbf30a0be8c394fa9a1f68de39a0e764a3f50665468aba1248558dc8f5abfc2b58c00449bf66f97b33142c9a5807899048b68df33e2b704f94ba60
7
- data.tar.gz: d36ea075cd9cbab56f0934b8ea8e2df4d116a3a5de97aa4ec8bf0b51f7f27937ab2ec8d3fd03a1378c579a2be33047af927b58056b2fd55d570630f42d8afc82
6
+ metadata.gz: ddb1e70d29cccdc9862a6de746db606b3818ca6bc64d45d4b7836f103c4f53766b91f891ce029277507534be70b8942cbf6ce0e5617741c149c812196bf99e0d
7
+ data.tar.gz: 44b36a8c69c951f93355db2286fe0113458d6d2323fd97e486fb46166eb82e6546e497a5cd18ff7978272b427d66b7e7d63f9b890ea40f6bf81a9c6c32ffbf8e
@@ -1,6 +1,6 @@
1
1
  require 'rest-client'
2
2
 
3
- class Colors
3
+ class IrcColors
4
4
  prefix = "\x03"
5
5
  @white = "#{prefix}00"
6
6
  @black = "#{prefix}01"
@@ -28,7 +28,7 @@ class Colors
28
28
  end
29
29
  end
30
30
 
31
- class GlobalQuote
31
+ class AlphaVantageQuote
32
32
  attr_reader :symbol, :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent
33
33
 
34
34
  def initialize(json_blob)
@@ -67,6 +67,47 @@ class GlobalQuote
67
67
  end
68
68
  end
69
69
 
70
+ class WorldTradeDataQuote
71
+ attr_reader :symbol, :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange
72
+
73
+ def initialize(json_blob)
74
+ Lita.logger.debug "parsing: #{json_blob}"
75
+ hash = JSON.parse(json_blob)
76
+ quote = hash['data'][0]
77
+
78
+ quote.keys.each do |key|
79
+ case key
80
+ when "symbol"
81
+ @symbol = quote[key]
82
+ when "price_open"
83
+ @open = self.fix_number quote[key]
84
+ when "day_high"
85
+ @high = self.fix_number quote[key]
86
+ when "day_low"
87
+ @low = self.fix_number quote[key]
88
+ when "price"
89
+ @price = self.fix_number quote[key]
90
+ when "volume"
91
+ @volume = quote[key].to_i
92
+ when "last_trade_time"
93
+ @trading_day = quote[key]
94
+ when "08. previous close"
95
+ @prev_close = self.fix_number quote[key]
96
+ when "day_change"
97
+ @change = self.fix_number quote[key]
98
+ when "change_pct"
99
+ @change_percent = self.fix_number quote[key]
100
+ when 'stock_exchange_short'
101
+ @exchange = quote[key].sub /NYSEARCA/, 'NYSE'
102
+ end
103
+ end
104
+ end
105
+
106
+ def fix_number(price_str)
107
+ price_str.to_f.round(2)
108
+ end
109
+ end
110
+
70
111
  module Lita
71
112
  module Handlers
72
113
  class OnewheelFinance < Handler
@@ -74,22 +115,38 @@ module Lita
74
115
  route /quote\s+(.+)/i, :handle_quote, command: true
75
116
 
76
117
  def handle_quote(response)
77
- url = "https://www.alphavantage.co/query"
78
- Lita.logger.debug "#{url} #{{function: 'GLOBAL_QUOTE', symbol: response.matches[0][0], apikey: config.apikey}.inspect}"
79
- resp = RestClient.get url, {params: {function: 'GLOBAL_QUOTE', symbol: response.matches[0][0], apikey: config.apikey}}
80
- stock = GlobalQuote.new resp
118
+ stock = handle_world_trade_data response.matches[0][0]
81
119
 
82
- str = "#{stock.symbol}: $#{stock.price} "
120
+ str = "#{stock.exchange} - #{stock.symbol}: $#{stock.price} "
83
121
  if stock.change >= 0
84
122
  # if irc
85
- str += "#{Colors::green} ⬆$#{stock.change}#{Colors::reset}, #{Colors::green}#{stock.change_percent}%#{Colors::reset} "
123
+ str += "#{IrcColors::green} ⬆$#{stock.change}#{IrcColors::reset}, #{IrcColors::green}#{stock.change_percent}%#{IrcColors::reset} "
86
124
  else
87
- str += "#{Colors::red} ↯$#{stock.change}#{Colors::reset}, #{Colors::red}#{stock.change_percent}%#{Colors::reset} "
125
+ str += "#{IrcColors::red} ↯$#{stock.change}#{IrcColors::reset}, #{IrcColors::red}#{stock.change_percent}%#{IrcColors::reset} "
88
126
  end
89
127
 
90
128
  response.reply str
91
129
  end
92
130
 
131
+ def handle_world_trade_data(symbol)
132
+ url = "https://api.worldtradingdata.com/api/v1/stock"
133
+ params = {symbol: symbol, api_token: config.apikey}
134
+
135
+ Lita.logger.debug "#{url} #{params.inspect}"
136
+
137
+ resp = RestClient.get url, {params: params}
138
+ stock = WorldTradeDataQuote.new resp
139
+ end
140
+
141
+ # deprecated for now
142
+ def handle_alphavantage
143
+ url = "https://www.alphavantage.co/query"
144
+ params = {function: 'GLOBAL_QUOTE', symbol: response.matches[0][0], apikey: config.apikey}
145
+ Lita.logger.debug "#{url} #{params.inspect}"
146
+ resp = RestClient.get url, {params: params}
147
+ stock = GlobalQuote.new resp
148
+ end
149
+
93
150
  Lita.register_handler(self)
94
151
  end
95
152
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-onewheel-finance"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.1.0"
4
4
  spec.authors = ["Andrew Kreps"]
5
5
  spec.email = ["andrew.kreps@gmail.com"]
6
6
  spec.description = "Wee li'l stock quote bot"
@@ -0,0 +1,32 @@
1
+ {
2
+ "symbols_requested": 1,
3
+ "symbols_returned": 1,
4
+ "data": [
5
+ {
6
+ "symbol": "XLP",
7
+ "name": "Consumer Staples Select Sector SPDR Fund",
8
+ "currency": "USD",
9
+ "price": "62.51",
10
+ "price_open": "63.10",
11
+ "day_high": "63.10",
12
+ "day_low": "62.31",
13
+ "52_week_high": "63.36",
14
+ "52_week_low": "50.11",
15
+ "day_change": "-0.47",
16
+ "change_pct": "-0.75",
17
+ "close_yesterday": "62.98",
18
+ "market_cap": "13136800768",
19
+ "volume": "10945550",
20
+ "volume_avg": "6313883",
21
+ "shares": "210172000",
22
+ "stock_exchange_long": "NYSE Arca (Archipelago Exchange)",
23
+ "stock_exchange_short": "NYSEARCA",
24
+ "timezone": "EST",
25
+ "timezone_name": "America/New_York",
26
+ "gmt_offset": "-18000",
27
+ "last_trade_time": "2020-01-02 15:49:03",
28
+ "pe": "N/A",
29
+ "eps": "N/A"
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "symbols_requested": 1,
3
+ "symbols_returned": 1,
4
+ "data": [
5
+ {
6
+ "symbol": "LULU",
7
+ "name": "Lululemon Athletica Inc.",
8
+ "currency": "USD",
9
+ "price": "233.01",
10
+ "price_open": "232.90",
11
+ "day_high": "233.40",
12
+ "day_low": "231.79",
13
+ "52_week_high": "235.50",
14
+ "52_week_low": "120.32",
15
+ "day_change": "1.34",
16
+ "change_pct": "0.58",
17
+ "close_yesterday": "231.67",
18
+ "market_cap": "30360037376",
19
+ "volume": "1052704",
20
+ "volume_avg": "1253383",
21
+ "shares": "123335000",
22
+ "stock_exchange_long": "NASDAQ Stock Exchange",
23
+ "stock_exchange_short": "NASDAQ",
24
+ "timezone": "EST",
25
+ "timezone_name": "America/New_York",
26
+ "gmt_offset": "-18000",
27
+ "last_trade_time": "2020-01-02 15:43:52",
28
+ "pe": "54.09",
29
+ "eps": "4.31"
30
+ }
31
+ ]
32
+ }
@@ -11,17 +11,17 @@ describe Lita::Handlers::OnewheelFinance, lita_handler: true do
11
11
  #end
12
12
 
13
13
  it 'quotes up' do
14
- mock_up 'alphavantage-global-quote'
14
+ mock_up 'worldtradedata-quote-up'
15
15
  send_command 'quote lulu'
16
16
  puts replies.last
17
- expect(replies.last).to include('LULU: $230.83')
17
+ expect(replies.last).to include('NASDAQ - LULU: $233.01')
18
18
  end
19
19
 
20
20
  it 'quotes down' do
21
- mock_up 'alphavantage-quote-down'
22
- send_command 'quote clb'
21
+ mock_up 'worldtradedata-quote-down'
22
+ send_command 'quote xlp'
23
23
  puts replies.last
24
- expect(replies.last).to include('CLB: $37.67')
25
- expect(replies.last).to include('$-9.79')
24
+ expect(replies.last).to include('NYSE - XLP: $62.51')
25
+ expect(replies.last).to include('↯$-0.47')
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-finance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
@@ -141,6 +141,8 @@ files:
141
141
  - spec/fixtures/alphavantage-global-quote.json
142
142
  - spec/fixtures/alphavantage-quote-down.json
143
143
  - spec/fixtures/effr.html
144
+ - spec/fixtures/worldtradedata-quote-down.json
145
+ - spec/fixtures/worldtradedata-quote-up.json
144
146
  - spec/lita/handlers/onewheel_finance_spec.rb
145
147
  - spec/spec_helper.rb
146
148
  homepage: https://github.com/onewheelskyward/lita-onewheel-finance
@@ -171,5 +173,7 @@ test_files:
171
173
  - spec/fixtures/alphavantage-global-quote.json
172
174
  - spec/fixtures/alphavantage-quote-down.json
173
175
  - spec/fixtures/effr.html
176
+ - spec/fixtures/worldtradedata-quote-down.json
177
+ - spec/fixtures/worldtradedata-quote-up.json
174
178
  - spec/lita/handlers/onewheel_finance_spec.rb
175
179
  - spec/spec_helper.rb