class Bitstamp::Orders

Public Instance Methods

all(options = {}) click to toggle source
# File lib/bitstamp/orders.rb, line 4
def all(options = {})
  path = options[:currency_pair] ? "/v2/open_orders/#{options[:currency_pair]}" : "/v2/open_orders/all"
  Bitstamp::Helper.parse_objects! Bitstamp::Net::post(path).to_str, self.model
end
buy(options = {}) click to toggle source
# File lib/bitstamp/orders.rb, line 19
def buy(options = {})
  options.merge!({type: Bitstamp::Order::BUY})
  self.create options
end
cancel_all() click to toggle source
# File lib/bitstamp/orders.rb, line 35
def cancel_all
  Bitstamp::Net::post('/cancel_all_orders').to_str
end
create(options = {}) click to toggle source
# File lib/bitstamp/orders.rb, line 9
def create(options = {})
  path = build_path(options)
  Bitstamp::Helper.parse_object! Bitstamp::Net::post(path, options).to_str, self.model
end
find(order_id) click to toggle source
# File lib/bitstamp/orders.rb, line 24
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 = {}) click to toggle source
# File lib/bitstamp/orders.rb, line 14
def sell(options = {})
  options.merge!({type: Bitstamp::Order::SELL})
  self.create options
end
status(order_id) click to toggle source
# File lib/bitstamp/orders.rb, line 31
def status(order_id)
  Bitstamp::Helper.parse_object!(Bitstamp::Net::post('/order_status', id: order_id).to_str, self.model)
end

Private Instance Methods

build_path(options={}) click to toggle source
# File lib/bitstamp/orders.rb, line 40
def build_path(options={})
  base = "/v2"
  currency_pair = options[:currency_pair] || "btcusd"

  if options[:type] == Bitstamp::Order::SELL
    base += "/sell"
  else
    base += "/buy"
  end

  if options[:market].present?
    base += "/market"
  end

  base += "/#{currency_pair}"

  return base
end