Class: Excoin::Account::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/account/order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order_data) ⇒ Order

Returns a new instance of Order.



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

def initialize(order_data)
  self.update(order_data)
end

Instance Attribute Details

#commodityObject (readonly)

Returns the value of attribute commodity.



2
3
4
# File 'lib/account/order.rb', line 2

def commodity
  @commodity
end

#commodity_amountObject (readonly)

Returns the value of attribute commodity_amount.



2
3
4
# File 'lib/account/order.rb', line 2

def commodity_amount
  @commodity_amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



2
3
4
# File 'lib/account/order.rb', line 2

def currency
  @currency
end

#currency_amountObject (readonly)

Returns the value of attribute currency_amount.



2
3
4
# File 'lib/account/order.rb', line 2

def currency_amount
  @currency_amount
end

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/account/order.rb', line 2

def id
  @id
end

#priceObject (readonly)

Returns the value of attribute price.



2
3
4
# File 'lib/account/order.rb', line 2

def price
  @price
end

#statusObject (readonly)

Returns the value of attribute status.



2
3
4
# File 'lib/account/order.rb', line 2

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



2
3
4
# File 'lib/account/order.rb', line 2

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/account/order.rb', line 2

def type
  @type
end

Instance Method Details

#cancelObject



38
39
40
41
# File 'lib/account/order.rb', line 38

def cancel
  order_data = Excoin.api.(self.id)
  self.update(order_data)
end

#exchangeObject



29
30
31
# File 'lib/account/order.rb', line 29

def exchange
  Excoin.market.exchange(@currency + @commodity)
end

#refreshObject



33
34
35
36
# File 'lib/account/order.rb', line 33

def refresh
  order_data = Excoin.api.(self.id)
  self.update(order_data)
end

#update(order_data) ⇒ Object



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

def update(order_data)
  begin
    unless order_data['currency'] and order_data['commodity']
      order_data.merge!({"currency" => order_data['id'].split("-").first, "commodity" => order_data['id'].split("-")[1]})
    end
    @currency ||= order_data['currency']
    @commodity ||= order_data['commodity']
    @type ||= order_data['type']
    @id ||= order_data['id']
    @timestamp ||= Time.parse(order_data['timestamp'])
    @price = BigDecimal.new(order_data['price'])
    @currency_amount = BigDecimal.new(order_data['currency_amount'])
    @commodity_amount = BigDecimal.new(order_data['commodity_amount'])
    @status = order_data['status']
  rescue
    puts "Error in Excoin::Account::Order.update"
    puts order_data
  end
end