Class: Excoin::Market::Exchange::Trades
- Inherits:
-
Array
- Object
- Array
- Excoin::Market::Exchange::Trades
- Defined in:
- lib/exchange/trades.rb
Instance Method Summary collapse
- #add(trade_data) ⇒ Object
- #buys ⇒ Object
- #highest(type = nil) ⇒ Object
-
#initialize(exchange) ⇒ Trades
constructor
A new instance of Trades.
- #lowest(type = nil) ⇒ Object
- #sells ⇒ Object
- #trim(number) ⇒ Object
- #update(limit_type = "count", limit = 100) ⇒ Object
Constructor Details
#initialize(exchange) ⇒ Trades
Returns a new instance of Trades.
3 4 5 6 7 |
# File 'lib/exchange/trades.rb', line 3 def initialize(exchange) @currency = exchange.currency @commodity = exchange.commodity self.update end |
Instance Method Details
#add(trade_data) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/exchange/trades.rb', line 46 def add(trade_data) begin unless trade_data.has_key?("currency") trade_data.merge!({"currency" => @currency, "commodity" => @commodity}) end self.insert(0, Excoin::Market::Exchange::Trade.new(trade_data)) rescue puts "Error in Excoin::Market::Exchange::Trades.add" puts trade_data end end |
#buys ⇒ Object
22 23 24 |
# File 'lib/exchange/trades.rb', line 22 def buys self.select{|trade| trade.type == "BUY"} end |
#highest(type = nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/exchange/trades.rb', line 30 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
38 39 40 41 42 43 44 |
# File 'lib/exchange/trades.rb', line 38 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 |
#sells ⇒ Object
26 27 28 |
# File 'lib/exchange/trades.rb', line 26 def sells self.select{|trade| trade.type == "SELL"} end |
#trim(number) ⇒ Object
58 59 60 |
# File 'lib/exchange/trades.rb', line 58 def trim(number) self.pop(number) end |
#update(limit_type = "count", limit = 100) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/exchange/trades.rb', line 9 def update(limit_type = "count", limit = 100) self.clear trade_data = self.get_recent(@currency, @commodity, limit_type, limit) begin trade_data['trades'].each do |trade| self.push(Excoin::Market::Exchange::Trade.new(trade)) end rescue puts "Error in Excoin::Market::Exchange::Trades.update" puts trade_data end end |