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, self.model
end

#buy(options = {}) ⇒ Object



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

def buy(options = {})
  options.merge!({
    type: Bitstamp::Order::BUY,
    side_execution: Bitstamp::Order::LIMIT_ORDER
  })

  self.create options
end

#create(options = {}) ⇒ Object



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

def create(options = {})
  path = self.order_path(options)
  Bitstamp::Helper.parse_object! Bitstamp::Net.post(path, options).body, self.model
end

#find(order_id) ⇒ Object



48
49
50
51
52
53
# File 'lib/bitstamp/orders.rb', line 48

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

  return all[index] if index
end

#limit_order_path(type, options = {}) ⇒ Object



75
76
77
# File 'lib/bitstamp/orders.rb', line 75

def limit_order_path(type, options = {})
  "/#{type}"
end

#market_buy(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/bitstamp/orders.rb', line 30

def market_buy(options = {})
  options.merge!({
    type: Bitstamp::Order::BUY,
    side_execution: Bitstamp::Order::MARKET_ORDER
  })

  self.create options
end

#market_order_path(type, options = {}) ⇒ Object



70
71
72
73
# File 'lib/bitstamp/orders.rb', line 70

def market_order_path(type, options = {})
  currency_pair = options[:currency_pair].to_s.empty? ? "btcusd" : options[:currency_pair]
  "/v2/#{type}/market/#{currency_pair}"
end

#market_sell(options = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/bitstamp/orders.rb', line 39

def market_sell(options = {})
  options.merge!({
    type: Bitstamp::Order::SELL,
    side_execution: Bitstamp::Order::MARKET_ORDER
  })

  self.create options
end

#order_path(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/bitstamp/orders.rb', line 60

def order_path(options = {})
  currency_pair = options[:currency_pair].to_s.empty? ? "btcusd" : options[:currency_pair]
  type = (options[:type] == Bitstamp::Order::SELL ? "sell" : "buy")
  if options[:side_execution] == Bitstamp::Order::MARKET_ORDER
    market_order_path(type, options)
  else
    limit_order_path(type, options)
  end
end

#sell(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/bitstamp/orders.rb', line 12

def sell(options = {})
  options.merge!({
    type: Bitstamp::Order::SELL,
    side_execution: Bitstamp::Order::LIMIT_ORDER
  })

  self.create options
end

#status(order_id, options = {}) ⇒ Object



55
56
57
58
# File 'lib/bitstamp/orders.rb', line 55

def status(order_id, options = {})
  options.merge!({id: order_id})
  Bitstamp::Helper.parse_objects! Bitstamp::Net.post('/order_status', options).body, self.model
end