ish_models 0.0.33.94 → 0.0.33.95
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ish/stockwatcher.rb +29 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7401d2a3cc4a7307b3412349efacb2cdee41af38dd8de4eb186e6309934c373f
|
4
|
+
data.tar.gz: a10804ed4c144bca8fbca9e8feba4d791d94a1078e852c9e8891ac0d604cf46d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4469ecea660c1f7412e4996af018d5a01caf0db1b186bee6fde773fa20fae2007e0d5f2ca790a0643959d4caa66240a71e37f01a668795d7175162e3057c9e89
|
7
|
+
data.tar.gz: 5b5bd86289210441897094c11a87daef03aea26b8e686f963f6e6ab302fc3068b846ed2e83b360aa8610dd506d41ab53e1c2d64c1cba2a6c1d88e3072a7ac7c0
|
data/lib/ish/stockwatcher.rb
CHANGED
@@ -6,23 +6,36 @@ class Stockwatcher
|
|
6
6
|
|
7
7
|
# every minute, for alphavantage.co
|
8
8
|
def watch
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
9
|
+
while true
|
10
|
+
|
11
|
+
if Time.now.hour > 14 && Time.now.hours < 21
|
12
|
+
|
13
|
+
stocks = Ish::StockWatch.where( :notification_type => :EMAIL )
|
14
|
+
# puts! stocks.map(&:ticker), "Watching these stocks:"
|
15
|
+
stocks.each do |stock|
|
16
|
+
# puts! stock.ticker, 'stock'
|
17
|
+
r = HTTParty.get "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=#{stock.ticker}&interval=1min&apikey=X1C5GGH5MZSXMF3O", timeout: 10
|
18
|
+
r2 = JSON.parse( r.body )['Time Series (1min)']
|
19
|
+
r3 = r2[r2.keys.first]['4. close'].to_f
|
20
|
+
if stock.direction == :ABOVE && r3 >= stock.price ||
|
21
|
+
stock.direction == :BELOW && r3 <= stock.price
|
22
|
+
IshManager::ApplicationMailer.stock_alert( stock ).deliver
|
23
|
+
|
24
|
+
## actions
|
25
|
+
## exit the position
|
26
|
+
# stock.stock_actions.where( :is_active => true ).each do |action|
|
27
|
+
# # @TODO: actions
|
28
|
+
# end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
print '.'
|
33
|
+
else
|
34
|
+
print '-'
|
25
35
|
end
|
36
|
+
|
37
|
+
sleep 60
|
38
|
+
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|