Class: Vertpig::Order

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/vertpig/order.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#extract_timestamp

Constructor Details

#initialize(attrs = {}) ⇒ Order

Returns a new instance of Order.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#closed_atObject (readonly)

Returns the value of attribute closed_at.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def closed_at
  @closed_at
end

#commissionObject (readonly)

Returns the value of attribute commission.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def commission
  @commission
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def exchange
  @exchange
end

#executed_atObject (readonly)

Returns the value of attribute executed_at.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def executed_at
  @executed_at
end

#fillObject (readonly)

Returns the value of attribute fill.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def fill
  @fill
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def id
  @id
end

#limitObject (readonly)

Returns the value of attribute limit.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def limit
  @limit
end

#opened_atObject (readonly)

Returns the value of attribute opened_at.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def opened_at
  @opened_at
end

#priceObject (readonly)

Returns the value of attribute price.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def quantity
  @quantity
end

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def raw
  @raw
end

#remainingObject (readonly)

Returns the value of attribute remaining.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def remaining
  @remaining
end

#totalObject (readonly)

Returns the value of attribute total.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def total
  @total
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/vertpig/order.rb', line 6

def type
  @type
end

Class Method Details

.book(market, type, depth = 50) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



45
46
47
48
49
50
51
# 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) ⇒ Object



67
68
69
70
71
# File 'lib/vertpig/order.rb', line 67

def self.cancel(order_id)
  client.get('market/cancel', {
    uuid: order_id
  })
end

.historyObject



77
78
79
# File 'lib/vertpig/order.rb', line 77

def self.history
  client.get('account/getorderhistory').map{|data| new(data) }
end

.info(order_id) ⇒ Object



61
62
63
64
65
# File 'lib/vertpig/order.rb', line 61

def self.info(order_id)
  client.get('account/getorder', {
    uuid: order_id
  })
end

.openObject



73
74
75
# File 'lib/vertpig/order.rb', line 73

def self.open
  client.get('market/getopenorders').map{|data| new(data) }
end

.sell_limit(market, amount, price) ⇒ Object



53
54
55
56
57
58
59
# 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