Sha256: 5a81570bec7ea164391c462b7b3f656dd2efda164f8764516503387732e05156

Contents?: true

Size: 1006 Bytes

Versions: 3

Compression:

Stored size: 1006 Bytes

Contents

module Bitstamp
  class Orders < Bitstamp::Collection
    def all(options = {})
      Bitstamp::Helper.parse_objects! Bitstamp::Net.post('/open_orders').body, self.model
    end

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

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

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

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

      return all[index] if index
    end
  end

  class Order < Bitstamp::Model
    BUY  = 0
    SELL = 1

    attr_accessor :type, :amount, :price, :id, :datetime
    attr_accessor :error, :message

    def cancel!
      Bitstamp::Net.post('/cancel_order', {id: self.id}).body
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bitstamp-2-0.4.4 lib/bitstamp/orders.rb
bitstamp-2-0.4.2 lib/bitstamp/orders.rb
bitstamp-2-0.4.1 lib/bitstamp/orders.rb