Class: Iro::Alert
- Inherits:
-
Object
- Object
- Iro::Alert
- Includes:
- Mongoid::Document, 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
19 20 21 |
# File 'app/models/iro/alert.rb', line 19 def self.active where( status: STATUS_ACTIVE ) end |
.directions_list ⇒ Object
11 12 13 |
# File 'app/models/iro/alert.rb', line 11 def self.directions_list [ nil, DIRECTION_ABOVE, DIRECTION_BELOW ] end |
Instance Method Details
#do_run ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/iro/alert.rb', line 35 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 ) Iro::AlertMailer.stock_alert( alert.id.to_s ).deliver_later alert.update({ status: alert.class::STATUS_INACTIVE }) print '^' end rescue => err puts! err, 'err' ::ExceptionNotifier.notify_exception( err, data: { alert: alert } ) end end |