Class: Iro::Alert
- Inherits:
-
Object
- Object
- Iro::Alert
- Includes:
- Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- app/models/iro/alert.rb
Constant Summary collapse
- DIRECTION_ABOVE =
SLEEP_TIME_SECONDS = Rails.env.production? ? 60 : 15
'ABOVE'
- DIRECTION_BELOW =
'BELOW'
- STATUS_ACTIVE =
'active'
- STATUS_INACTIVE =
'inactive'
- STATUSES =
[ nil, 'active', 'inactive' ]
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.active ⇒ Object
20 21 22 |
# File 'app/models/iro/alert.rb', line 20 def self.active where( status: STATUS_ACTIVE ) end |
.directions_list ⇒ Object
12 13 14 |
# File 'app/models/iro/alert.rb', line 12 def self.directions_list [ nil, DIRECTION_ABOVE, DIRECTION_BELOW ] end |
Instance Method Details
#do_run ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/iro/alert.rb', line 36 def do_run alert = self begin price = Tda::Stock.get_quote( alert.symbol )&.last return if !price if ( alert.direction == alert.class::DIRECTION_ABOVE && price >= alert.strike ) || ( alert.direction == alert.class::DIRECTION_BELOW && price <= alert.strike ) if Rails.env.production? Iro::AlertMailer.stock_alert( alert.id.to_s ).deliver_later else Iro::AlertMailer.stock_alert( alert.id.to_s ).deliver_now end alert.update({ status: alert.class::STATUS_INACTIVE }) print '^' end rescue => err puts! err, 'err' ::ExceptionNotifier.notify_exception( err, data: { alert: alert } ) end end |