Class: Coinigy::Alert

Inherits:
Model
  • Object
show all
Defined in:
lib/coinigy/alert.rb

Overview

Represents an Alert on a market

Constant Summary

ABOVE =

Alert operator types

:>.freeze
BELOW =
:<.freeze

Instance Attribute Summary collapse

Attributes inherited from Model

#errors

Instance Method Summary collapse

Methods inherited from Model

#errors?, #initialize, #inspect, #save

Constructor Details

This class inherits a constructor from Coinigy::Model

Instance Attribute Details

#alert_addedObject

Returns the value of attribute alert_added



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def alert_added
  @alert_added
end

#alert_history_idObject

Returns the value of attribute alert_history_id



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def alert_history_id
  @alert_history_id
end

#alert_idObject

Returns the value of attribute alert_id



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def alert_id
  @alert_id
end

#alert_noteObject

Returns the value of attribute alert_note



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def alert_note
  @alert_note
end

#alert_priceObject

Returns the value of attribute alert_price



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def alert_price
  @alert_price
end

#display_nameObject

Returns the value of attribute display_name



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def display_name
  @display_name
end

#exch_codeObject

Returns the value of attribute exch_code



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def exch_code
  @exch_code
end

#exch_nameObject

Returns the value of attribute exch_name



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def exch_name
  @exch_name
end

#exchangeObject

Relations



17
18
19
# File 'lib/coinigy/alert.rb', line 17

def exchange
  @exchange
end

#marketObject

Relations



17
18
19
# File 'lib/coinigy/alert.rb', line 17

def market
  @market
end

#mkt_nameObject

Returns the value of attribute mkt_name



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def mkt_name
  @mkt_name
end

#operatorObject

Returns the value of attribute operator



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def operator
  @operator
end

#operator_textObject

Returns the value of attribute operator_text



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def operator_text
  @operator_text
end

#priceObject

Returns the value of attribute price



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def price
  @price
end

#subscriptionObject

Relations



17
18
19
# File 'lib/coinigy/alert.rb', line 17

def subscription
  @subscription
end

#timestampObject

Returns the value of attribute timestamp



8
9
10
# File 'lib/coinigy/alert.rb', line 8

def timestamp
  @timestamp
end

Instance Method Details

#attributesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/coinigy/alert.rb', line 19

def attributes
  { 'exch_name' => exch_name,
    'mkt_name' => mkt_name,
    'price' => price,
    'operator' => operator,
    'alert_id' => alert_id,
    'operator_text' => operator_text,
    'alert_note' => alert_note,
    'alert_added' => alert_added,
    'display_name' => display_name,
    'exch_code' => exch_code,
    'alert_history_id' => alert_history_id,
    'timestamp' => timestamp,
    'alert_price' => alert_price }
end

#cancelObject



56
57
58
# File 'lib/coinigy/alert.rb', line 56

def cancel
  subscription.client.delete_alert(alert_id)
end

#placeObject



43
44
45
46
47
48
# File 'lib/coinigy/alert.rb', line 43

def place
  subscription.client.add_alert('exch_code' => exch_code,
                                'market_name' => mkt_name,
                                'alert_price' => price,
                                'alert_note' => alert_note)
end

#replace(changes = {}) ⇒ Object



50
51
52
53
54
# File 'lib/coinigy/alert.rb', line 50

def replace(changes = {})
  cancel
  assign_attributes(changes.slice(:price, :note))
  place
end