Class: Bitstamp::Orders

Inherits:
Collection show all
Defined in:
lib/bitstamp/orders.rb

Instance Attribute Summary

Attributes inherited from Collection

#access_token, #model, #module, #name, #path

Instance Method Summary collapse

Methods inherited from Collection

#initialize, #update

Constructor Details

This class inherits a constructor from Bitstamp::Collection

Instance Method Details

#all(options = {}) ⇒ Object



3
4
5
# File 'lib/bitstamp/orders.rb', line 3

def all(options = {})
  Bitstamp::Helper.parse_objects! Bitstamp::Net::post('/open_orders').body_str, self.model
end

#buy(options = {}) ⇒ Object



17
18
19
20
# File 'lib/bitstamp/orders.rb', line 17

def buy(options = {})
  options.merge!({type: Bitstamp::Order::BUY})
  self.create options
end

#create(options = {}) ⇒ Object



7
8
9
10
# File 'lib/bitstamp/orders.rb', line 7

def create(options = {})
  path = (options[:type] == Bitstamp::Order::SELL ? "/sell" : "/buy")
  Bitstamp::Helper.parse_object! Bitstamp::Net::post(path, options).body_str, self.model
end

#find(order_id) ⇒ Object



22
23
24
25
26
27
# File 'lib/bitstamp/orders.rb', line 22

def find(order_id)
  all = self.all
  index = all.index {|order| order.id.to_i == order_id}

  return all[index] if index
end

#sell(options = {}) ⇒ Object



12
13
14
15
# File 'lib/bitstamp/orders.rb', line 12

def sell(options = {})
  options.merge!({type: Bitstamp::Order::SELL})
  self.create options
end