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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vertpig/order.rb', line 9

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.



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

def closed_at
  @closed_at
end

#commissionObject (readonly)

Returns the value of attribute commission.



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

def commission
  @commission
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



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

def exchange
  @exchange
end

#executed_atObject (readonly)

Returns the value of attribute executed_at.



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

def executed_at
  @executed_at
end

#fillObject (readonly)

Returns the value of attribute fill.



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

def fill
  @fill
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

#opened_atObject (readonly)

Returns the value of attribute opened_at.



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

def opened_at
  @opened_at
end

#priceObject (readonly)

Returns the value of attribute price.



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

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



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

def quantity
  @quantity
end

#rawObject (readonly)

Returns the value of attribute raw.



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

def raw
  @raw
end

#remainingObject (readonly)

Returns the value of attribute remaining.



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

def remaining
  @remaining
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vertpig/order.rb', line 26

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(market, amount, price) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/vertpig/order.rb', line 44

def self.buy(market, amount, price)
  client.get('/market/buylimit', {
    market: market,
    quantity: amount,
    rate: price
  })
end

.cancel(order_id) ⇒ Object



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

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

.historyObject



70
71
72
# File 'lib/vertpig/order.rb', line 70

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

.openObject



66
67
68
# File 'lib/vertpig/order.rb', line 66

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

.sell(market, amount, price) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/vertpig/order.rb', line 52

def self.sell(market, amount, price)
  client.get('/market/selllimit', {
    market: market,
    quantity: amount,
    rate: price
  })
end