Class: Bitcoin::Ticker

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#askObject

Returns the value of attribute ask.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def ask
  @ask
end

#bidObject

Returns the value of attribute bid.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def bid
  @bid
end

#highObject

Returns the value of attribute high.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def high
  @high
end

#lastObject

Returns the value of attribute last.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def last
  @last
end

#lowObject

Returns the value of attribute low.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def low
  @low
end

#openObject

Returns the value of attribute open.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def open
  @open
end

#symbolObject

Returns the value of attribute symbol.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def symbol
  @symbol
end

#timestampObject

Returns the value of attribute timestamp.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def timestamp
  @timestamp
end

#volumeObject

Returns the value of attribute volume.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def volume
  @volume
end

#volumeQuoteObject

Returns the value of attribute volumeQuote.


3
4
5
# File 'lib/bitcoin/ticker.rb', line 3

def volumeQuote
  @volumeQuote
end

Class Method Details

.allObject


38
39
40
41
42
43
# File 'lib/bitcoin/ticker.rb', line 38

def self.all
  data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker"))
  data.map{ |ticker|
    Bitcoin::Ticker.new_from_object(ticker)
  }
end

.new_from_object(data) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bitcoin/ticker.rb', line 18

def self.new_from_object(data)
  t = Bitcoin::Ticker.new
  t.ask = data['ask'].to_f
  t.bid = data['bid'].to_f
  t.last = data['last'].to_f
  t.open = data['open'].to_f
  t.low = data['low'].to_f
  t.high = data['high'].to_f
  t.volume = data['volume'].to_f
  t.volumeQuote = data['volumeQuote'].to_f
  t.timestamp = Time.parse(data['timestamp'])
  t.symbol = data['symbol']
  t
end

.new_from_symbol_name(symbol_name) ⇒ Object


33
34
35
36
# File 'lib/bitcoin/ticker.rb', line 33

def self.new_from_symbol_name(symbol_name)
  data = JSON.parse(RestClient.get("#{Bitcoin::BASE}/public/ticker/#{symbol_name}"))
  Bitcoin::Ticker.new_from_object(data)
end

Instance Method Details

#display_detailsObject


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bitcoin/ticker.rb', line 5

def display_details
  puts "  \#{@symbol}\n  Best Ask   : \#{@ask.to_s.rjust(9)} || Best Bid: \#{@bid}\n  Last Trade Price: \#{@last}\n  Open: \#{@open}\n  24-Hour Low: \#{@low.to_s.rjust(9)} || 24-Hour High: \#{@high}\n  Total 24-Hour Volume (Base): \#{@volume}  (Quote): \#{@volumeQuote}\n  \#{@timestamp}\n\n  DOC\nend\n"