Class: Bitcoin::Trade

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

Returns the value of attribute id.


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

def id
  @id
end

#priceObject

Returns the value of attribute price.


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

def price
  @price
end

#quantityObject

Returns the value of attribute quantity.


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

def quantity
  @quantity
end

#sideObject

Returns the value of attribute side.


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

def side
  @side
end

#symbolObject

Returns the value of attribute symbol.


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

def symbol
  @symbol
end

#timestampObject

Returns the value of attribute timestamp.


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

def timestamp
  @timestamp
end

Class Method Details

.all(symbol_name) ⇒ Object

[View source]

26
27
28
29
30
31
# File 'lib/bitcoin/trade.rb', line 26

def self.all(symbol_name)
  data = JSON.parse RestClient.get("#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000")
  data.map{ |e|
    Bitcoin::Trade.new_from_object(symbol_name, e)
  }
end

.get_trades_in_range(symbol_name, timestamps = nil) ⇒ Object

Input: currency pair and formatted date range. Output: array of trades from range

[View source]

34
35
36
37
38
39
# File 'lib/bitcoin/trade.rb', line 34

def self.get_trades_in_range(symbol_name, timestamps = nil)
  data = JSON.parse RestClient.get "#{Bitcoin::BASE}/public/trades/#{symbol_name}?limit=1000&sort=DESC&from=#{timestamps[0]}&till=#{timestamps[1]}"
  data.map{|e|
    Bitcoin::Trade.new_from_object(symbol_name, e)
  }
end

.new_from_object(symbol_name, data) ⇒ Object

[View source]

15
16
17
18
19
20
21
22
23
24
# File 'lib/bitcoin/trade.rb', line 15

def self.new_from_object(symbol_name, data)
  t = Bitcoin::Trade.new
  t.id = data['id']
  t.price = data['price'].to_f
  t.quantity = data['quantity'].to_f
  t.side = data['side']
  t.timestamp = Time.parse(data['timestamp'])
  t.symbol = symbol_name
  t
end

Instance Method Details

#display_detailsObject

[View source]

5
6
7
8
9
10
11
12
13
# File 'lib/bitcoin/trade.rb', line 5

def display_details
  puts <<-DOC
| #{@symbol}
| ID: #{@id} : #{@side.upcase} : #{@price}
| Quantity: #{@quantity}
| #{@timestamp}
|_____________________
  DOC
end