Class: Mcoin::Data::Ticker

Inherits:
Object
  • Object
show all
Defined in:
lib/mcoin/data/ticker.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(market, type, currency, data = {}) ⇒ Ticker

Returns a new instance of Ticker.



10
11
12
13
14
15
16
17
# File 'lib/mcoin/data/ticker.rb', line 10

def initialize(market, type, currency, data = {})
  @market = market
  @type = type
  @currency = currency
  data.each do |key, value|
    send("#{key}=", value)
  end
end

Instance Attribute Details

#askObject

Returns the value of attribute ask.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def ask
  @ask
end

#bidObject

Returns the value of attribute bid.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def bid
  @bid
end

#currencyObject (readonly)

Returns the value of attribute currency.



7
8
9
# File 'lib/mcoin/data/ticker.rb', line 7

def currency
  @currency
end

#highObject

Returns the value of attribute high.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def high
  @high
end

#lastObject

Returns the value of attribute last.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def last
  @last
end

#lowObject

Returns the value of attribute low.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def low
  @low
end

#marketObject (readonly)

Returns the value of attribute market.



7
8
9
# File 'lib/mcoin/data/ticker.rb', line 7

def market
  @market
end

#timestampObject

Returns the value of attribute timestamp.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/mcoin/data/ticker.rb', line 7

def type
  @type
end

#volumeObject

Returns the value of attribute volume.



8
9
10
# File 'lib/mcoin/data/ticker.rb', line 8

def volume
  @volume
end

Instance Method Details

#timeObject



19
20
21
# File 'lib/mcoin/data/ticker.rb', line 19

def time
  Time.at(timestamp.to_i).to_s
end

#to_influxObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mcoin/data/ticker.rb', line 23

def to_influx
  tags = { type: @type, currency: @currency, market: @market }
  values = {
    last: @last,
    ask: @ask, bid: @bid,
    low: @low, high: @high,
    volume: @volume
  }
  "prices,#{tags.map { |t| t.join('=') }.join(',')} " \
  "#{values.map { |v| v.join('=') }.join(',')} #{influx_time}"
end