class Vertpig::Order

Attributes

closed_at[R]
commission[R]
exchange[R]
executed_at[R]
fill[R]
id[R]
limit[R]
opened_at[R]
price[R]
quantity[R]
raw[R]
remaining[R]
total[R]
type[R]

Public Class Methods

book(market, type, depth = 50) click to toggle source
# File lib/vertpig/order.rb, line 27
def self.book(market, type, depth = 50)
  orders = []

  if type.to_sym == :both
    orderbook(market, type.downcase, depth).each_pair do |type, values|
      values.each do |data|
        orders << new(data.merge('Type' => type))
      end
    end
  else
    orderbook(market, type.downcase, depth).each do |data|
      orders << new(data.merge('Type' => type))
    end
  end

  orders
end
buy_limit(market, amount, price) click to toggle source
# File lib/vertpig/order.rb, line 45
def self.buy_limit(market, amount, price)
  client.get('market/buylimit', {
    market: market,
    quantity: amount,
    rate: price
  })
end
cancel(order_id) click to toggle source
# File lib/vertpig/order.rb, line 67
def self.cancel(order_id)
  client.get('market/cancel', {
    uuid: order_id
  })
end
history() click to toggle source
# File lib/vertpig/order.rb, line 77
def self.history
  client.get('account/getorderhistory').map{|data| new(data) }
end
info(order_id) click to toggle source
# File lib/vertpig/order.rb, line 61
def self.info(order_id)
  client.get('account/getorder', {
    uuid: order_id
  })
end
new(attrs = {}) click to toggle source
# File lib/vertpig/order.rb, line 10
def initialize(attrs = {})
  @id = attrs['Id'] || attrs['OrderUuid']
  @type = (attrs['Type'] || attrs['OrderType']).to_s.capitalize
  @exchange = attrs['Exchange']
  @quantity = attrs['Quantity']
  @remaining = attrs['QuantityRemaining']
  @price = attrs['Rate'] || attrs['Price']
  @total = attrs['Total']
  @fill = attrs['FillType']
  @limit = attrs['Limit']
  @commission = (attrs['Commission'] || attrs['CommissionPaid']).to_f
  @raw = attrs
  @opened_at = extract_timestamp(attrs['Opened'])
  @executed_at = extract_timestamp(attrs['TimeStamp'])
  @closed_at = extract_timestamp(attrs['Closed'])
end
open() click to toggle source
# File lib/vertpig/order.rb, line 73
def self.open
  client.get('market/getopenorders').map{|data| new(data) }
end
sell_limit(market, amount, price) click to toggle source
# File lib/vertpig/order.rb, line 53
def self.sell_limit(market, amount, price)
  client.get('market/selllimit', {
    market: market,
    quantity: amount,
    rate: price
  })
end

Private Class Methods

client() click to toggle source
# File lib/vertpig/order.rb, line 91
def self.client
  @client ||= Vertpig.client
end
orderbook(market, type, depth) click to toggle source
# File lib/vertpig/order.rb, line 83
def self.orderbook(market, type, depth)
  client.get('public/getorderbook', {
    market: market,
    type: type,
    depth: depth
  })
end