Class: Excoin::Account::Order
- Inherits:
-
Object
- Object
- Excoin::Account::Order
- Defined in:
- lib/account/order.rb
Instance Attribute Summary collapse
-
#commodity ⇒ Object
readonly
Returns the value of attribute commodity.
-
#commodity_amount ⇒ Object
readonly
Returns the value of attribute commodity_amount.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#currency_amount ⇒ Object
readonly
Returns the value of attribute currency_amount.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #cancel ⇒ Object
- #exchange ⇒ Object
-
#initialize(order_data) ⇒ Order
constructor
A new instance of Order.
- #refresh ⇒ Object
- #update(order_data) ⇒ Object
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
#commodity ⇒ Object (readonly)
Returns the value of attribute commodity.
2 3 4 |
# File 'lib/account/order.rb', line 2 def commodity @commodity end |
#commodity_amount ⇒ Object (readonly)
Returns the value of attribute commodity_amount.
2 3 4 |
# File 'lib/account/order.rb', line 2 def commodity_amount @commodity_amount end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
2 3 4 |
# File 'lib/account/order.rb', line 2 def currency @currency end |
#currency_amount ⇒ Object (readonly)
Returns the value of attribute currency_amount.
2 3 4 |
# File 'lib/account/order.rb', line 2 def currency_amount @currency_amount end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/account/order.rb', line 2 def id @id end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
2 3 4 |
# File 'lib/account/order.rb', line 2 def price @price end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
2 3 4 |
# File 'lib/account/order.rb', line 2 def status @status end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
2 3 4 |
# File 'lib/account/order.rb', line 2 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
2 3 4 |
# File 'lib/account/order.rb', line 2 def type @type end |
Instance Method Details
#cancel ⇒ Object
38 39 40 41 |
# File 'lib/account/order.rb', line 38 def cancel order_data = Excoin.api.account_cancel_order(self.id) self.update(order_data) end |
#exchange ⇒ Object
29 30 31 |
# File 'lib/account/order.rb', line 29 def exchange Excoin.market.exchange(@currency + @commodity) end |
#refresh ⇒ Object
33 34 35 36 |
# File 'lib/account/order.rb', line 33 def refresh order_data = Excoin.api.account_view_order(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 |