Sha256: a6b20b1d30f3fd1a456ca9f2fbeacb2d01972c8fa527b3172870f9a6a67e63b3

Contents?: true

Size: 982 Bytes

Versions: 5

Compression:

Stored size: 982 Bytes

Contents

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

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

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

    def buy(options = {})
      options.merge!({type: Bitso::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 < Bitso::Model
    BUY  = 0
    SELL = 1

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bitso-0.1.5 lib/bitso/orders.rb
bitso-0.1.4 lib/bitso/orders.rb
bitso-0.1.3 lib/bitso/orders.rb
bitso-0.1.2 lib/bitso/orders.rb
bitso-0.1.1 lib/bitso/orders.rb