Class: Trade

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Trade

Returns a new instance of Trade.



12
13
14
15
16
17
18
19
20
# File 'lib/trades/trade.rb', line 12

def initialize(data)
  parsed      = JSON.parse data.strip.tr("\x00", '')
  @id         = parsed['id']
  @market     = parsed['symbol']
  @timestamp  = parsed['timestamp']
  @currency   = parsed['symbol'][-3, 3]
  @price      = parsed['price']
  @volume     = parsed['volume']
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



7
8
9
# File 'lib/trades/trade.rb', line 7

def currency
  @currency
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/trades/trade.rb', line 4

def id
  @id
end

#marketObject (readonly)

Returns the value of attribute market.



5
6
7
# File 'lib/trades/trade.rb', line 5

def market
  @market
end

#priceObject

Returns the value of attribute price.



10
11
12
# File 'lib/trades/trade.rb', line 10

def price
  @price
end

#timestamp(show_date = false) ⇒ Object (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/trades/trade.rb', line 6

def timestamp
  @timestamp
end

#volumeObject (readonly)

Returns the value of attribute volume.



8
9
10
# File 'lib/trades/trade.rb', line 8

def volume
  @volume
end

Instance Method Details

#to_sObject



27
28
29
30
# File 'lib/trades/trade.rb', line 27

def to_s
  "#{@market.ljust(15)} | #{timestamp()} | #{@currency.ljust(9)} | " +
  "#{@price.round(4).to_s.ljust(9)} | #{@volume.to_s}"
end