Class: Excoin::Account::Trades

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

Instance Method Summary collapse

Constructor Details

#initializeTrades

Returns a new instance of Trades.



3
4
5
# File 'lib/account/trades.rb', line 3

def initialize
  self.update
end

Instance Method Details

#add(trade_data) ⇒ Object



45
46
47
# File 'lib/account/trades.rb', line 45

def add(trade_data)
  self.insert(0, Excoin::Account::Trade.new(trade_data))
end

#buysObject



21
22
23
# File 'lib/account/trades.rb', line 21

def buys
  self.select{|trade| trade.type == "BUY"}
end

#highest(type = nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/account/trades.rb', line 29

def highest(type = nil)
  unless type
    self.max_by{|trade| trade.price}
  else
    self.select{|trade| trade.type == type.upcase}.max_by{|trade| trade.price}
  end
end

#lowest(type = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/account/trades.rb', line 37

def lowest(type = nil)
  unless type
    self.min_by{|trade| trade.price}
  else
    self.select{|trade| trade.type == type.upcase}.min_by{|trade| trade.price}
  end
end

#sellsObject



25
26
27
# File 'lib/account/trades.rb', line 25

def sells
  self.select{|trade| trade.type == "SELL"}
end

#trim(number) ⇒ Object



49
50
51
# File 'lib/account/trades.rb', line 49

def trim(number)
  self.pop(number)
end

#update(count = 100) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/account/trades.rb', line 7

def update(count = 100)
  self.clear
  recent_trade_data = self.get(count)
  begin
    recent_trade_data['trades'].each do |trade_data|
      trade = Excoin::Account::Trade.new(trade_data)
      self.push(trade)
    end
  rescue
    puts "Error in Excoin::Account::Trades.update"
    puts recent_trade_data
  end
end