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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ish/stockwatcher.rb +29 -16
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70debd7a9ae9d44c72b135dc07c1d2e72f01d7381c154a68ad47b72600e3f5b7
4
- data.tar.gz: c8361dce103b2f3ac55e3aeb440ed967048e40d17e1e495f4b80b4d2c9918885
3
+ metadata.gz: 7401d2a3cc4a7307b3412349efacb2cdee41af38dd8de4eb186e6309934c373f
4
+ data.tar.gz: a10804ed4c144bca8fbca9e8feba4d791d94a1078e852c9e8891ac0d604cf46d
5
5
  SHA512:
6
- metadata.gz: 1b0a2d11b62f6841bf034113917f75cca41814cd716205394dc3223ae82134d24bcf59ed9a3f8945a8f520dc58877523a21dbfb56e350bcc8432fce1927de61e
7
- data.tar.gz: 90affd7f361d3b63f4b6c4711132614032788d0d41c09551542a0fa467bbe08ee522911c9d68b1ed5521934eba88d27706cb228dce3afcf95a0853fd9c21ebab
6
+ metadata.gz: 4469ecea660c1f7412e4996af018d5a01caf0db1b186bee6fde773fa20fae2007e0d5f2ca790a0643959d4caa66240a71e37f01a668795d7175162e3057c9e89
7
+ data.tar.gz: 5b5bd86289210441897094c11a87daef03aea26b8e686f963f6e6ab302fc3068b846ed2e83b360aa8610dd506d41ab53e1c2d64c1cba2a6c1d88e3072a7ac7c0
@@ -6,23 +6,36 @@ class Stockwatcher
6
6
 
7
7
  # every minute, for alphavantage.co
8
8
  def watch
9
- stocks = Ish::StockWatch.where( :notification_type => :EMAIL )
10
- puts! stocks.map(&:ticker), "Watching these stocks:"
11
- stocks.each do |stock|
12
- r = HTTParty.get "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=#{stock.ticker}&interval=1min&apikey=X1C5GGH5MZSXMF3O", timeout: 10
13
- r2 = JSON.parse( r.body )['Time Series (1min)']
14
- r3 = r2[r2.keys.first]['4. close'].to_f
15
- if stock.direction == :ABOVE && r3 >= stock.price ||
16
- stock.direction == :BELOW && r3 <= stock.price
17
- IshManager::ApplicationMailer.stock_alert( stock ).deliver
18
-
19
- ## actions
20
- ## exit the position
21
- # stock.stock_actions.where( :is_active => true ).each do |action|
22
- # # @TODO: actions
23
- # end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.94
4
+ version: 0.0.33.95
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox