lita-onewheel-finance 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5edbbe2ef63969dd624af3c1657c738648ff8b5faf965379860c87e8283f95f2
|
4
|
+
data.tar.gz: 978e055da01a370ce7f6c835ecffedb4cf8bee00edc29cda2586d4a9cbee57db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb1e70d29cccdc9862a6de746db606b3818ca6bc64d45d4b7836f103c4f53766b91f891ce029277507534be70b8942cbf6ce0e5617741c149c812196bf99e0d
|
7
|
+
data.tar.gz: 44b36a8c69c951f93355db2286fe0113458d6d2323fd97e486fb46166eb82e6546e497a5cd18ff7978272b427d66b7e7d63f9b890ea40f6bf81a9c6c32ffbf8e
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
|
3
|
-
class
|
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
|
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
|
-
|
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 += "#{
|
123
|
+
str += "#{IrcColors::green} ⬆$#{stock.change}#{IrcColors::reset}, #{IrcColors::green}#{stock.change_percent}%#{IrcColors::reset} "
|
86
124
|
else
|
87
|
-
str += "#{
|
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
|
@@ -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 '
|
14
|
+
mock_up 'worldtradedata-quote-up'
|
15
15
|
send_command 'quote lulu'
|
16
16
|
puts replies.last
|
17
|
-
expect(replies.last).to include('LULU: $
|
17
|
+
expect(replies.last).to include('NASDAQ - LULU: $233.01')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'quotes down' do
|
21
|
-
mock_up '
|
22
|
-
send_command 'quote
|
21
|
+
mock_up 'worldtradedata-quote-down'
|
22
|
+
send_command 'quote xlp'
|
23
23
|
puts replies.last
|
24
|
-
expect(replies.last).to include('
|
25
|
-
expect(replies.last).to include('
|
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
|
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
|