Class: Coinigy::Market

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

Overview

Represents a Market of a exchange

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

#exch_codeObject

Returns the value of attribute exch_code



4
5
6
# File 'lib/coinigy/market.rb', line 4

def exch_code
  @exch_code
end

#exch_idObject

Returns the value of attribute exch_id



4
5
6
# File 'lib/coinigy/market.rb', line 4

def exch_id
  @exch_id
end

#exch_nameObject

Returns the value of attribute exch_name



4
5
6
# File 'lib/coinigy/market.rb', line 4

def exch_name
  @exch_name
end

#exchangeObject

Relations



7
8
9
# File 'lib/coinigy/market.rb', line 7

def exchange
  @exchange
end

#exchmkt_idObject

Returns the value of attribute exchmkt_id



4
5
6
# File 'lib/coinigy/market.rb', line 4

def exchmkt_id
  @exchmkt_id
end

#mkt_idObject

Returns the value of attribute mkt_id



4
5
6
# File 'lib/coinigy/market.rb', line 4

def mkt_id
  @mkt_id
end

#mkt_nameObject

Returns the value of attribute mkt_name



4
5
6
# File 'lib/coinigy/market.rb', line 4

def mkt_name
  @mkt_name
end

Instance Method Details

#alert(price, note = '') ⇒ Object



64
65
66
67
68
69
70
# File 'lib/coinigy/market.rb', line 64

def alert(price, note = '')
  Coinigy::Alert.new('exch_code' => exch_code,
                     'mkt_name' => mkt_name,
                     'price' => price,
                     'alert_note' => note,
                     'subscription' => exchange.subscription).place
end

#asksObject



25
26
27
# File 'lib/coinigy/market.rb', line 25

def asks
  get_data(:asks)['asks']
end

#asks_and_bidsObject



33
34
35
36
37
38
39
# File 'lib/coinigy/market.rb', line 33

def asks_and_bids
  orders_data = get_data(:orders)
  {
    asks: orders_data['asks'],
    bids: orders_data['bids']
  }
end

#attributesObject



12
13
14
15
16
17
18
19
# File 'lib/coinigy/market.rb', line 12

def attributes
  { 'exch_id' => exch_id,
    'exch_name' => exch_name,
    'exch_code' => exch_code,
    'mkt_id' => mkt_id,
    'mkt_name' => mkt_name,
    'exchmkt_id' => exchmkt_id }
end

#bidsObject



29
30
31
# File 'lib/coinigy/market.rb', line 29

def bids
  get_data(:bids)['bids']
end

#dataObject



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

def data
  all_data = get_data(:all)
  {
    history: all_data['history'],
    asks: all_data['asks'],
    bids: all_data['bids']
  }
end

#historyObject



21
22
23
# File 'lib/coinigy/market.rb', line 21

def history
  get_data(:history)['history']
end

#open_alerts(reload = false) ⇒ Object



72
73
74
# File 'lib/coinigy/market.rb', line 72

def open_alerts(reload = false)
  exchange.subscription.open_alerts(reload).select { |alert| alert.mkt_name == mkt_name }
end

#tickerObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/coinigy/market.rb', line 50

def ticker
  values = exchange.subscription.client.ticker('exchange_code' => exch_code,
                                               'exchange_market' => mkt_name).data.first
  {
    last_trade: values['last_trade'],
    high_trade: values['high_trade'],
    low_trade: values['low_trade'],
    volume: values['current_volume'],
    timestamp: values['timestamp'],
    ask: values['ask'],
    bid: values['bid']
  }
end