Sha256: 33c90e4c4a658c1057dc2359fc8f945eec0004494e1a57a8d0bcaf2ab1399c05

Contents?: true

Size: 1021 Bytes

Versions: 12

Compression:

Stored size: 1021 Bytes

Contents

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

    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

    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_str
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
bitstamp-rbtc-arbitrage-0.4.0 lib/bitstamp/orders.rb
rbtc_arbitrage-2.3.0 bitstamp/lib/bitstamp/orders.rb
rbtc_arbitrage-2.2.1 bitstamp/lib/bitstamp/orders.rb
rbtc_arbitrage-2.2.0 bitstamp/lib/bitstamp/orders.rb
rbtc_arbitrage-2.1.2 bitstamp/lib/bitstamp/orders.rb
rbtc_arbitrage-2.1.1 bitstamp/lib/bitstamp/orders.rb
rbtc_arbitrage-2.1.0 bitstamp/lib/bitstamp/orders.rb
cgore-bitstamp-0.3.1 lib/bitstamp/orders.rb
bitstamp-0.3.0 lib/bitstamp/orders.rb
bitstamp-0.2.8 lib/bitstamp/orders.rb
bitstamp-0.2.7 lib/bitstamp/orders.rb
bitstamp-0.2.6 lib/bitstamp/orders.rb