Class: Order
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#price ⇒ Object
Returns the value of attribute price.
-
#sent_at ⇒ Object
readonly
Returns the value of attribute sent_at.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #<=>(order) ⇒ Object
- #cancel! ⇒ Object
- #cancelled? ⇒ Boolean
- #fill!(amount) ⇒ Object
-
#initialize(id, side, price, size) ⇒ Order
constructor
A new instance of Order.
Constructor Details
#initialize(id, side, price, size) ⇒ Order
Returns a new instance of Order.
9 10 11 12 13 14 15 16 |
# File 'lib/order.rb', line 9 def initialize id, side, price, size @id, @side, @price, @size = id, side, price, size @sent_at = Time.now @cancelled = false @status = :pending_accept @price = @price.round 2 end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/order.rb', line 6 def id @id end |
#price ⇒ Object
Returns the value of attribute price.
7 8 9 |
# File 'lib/order.rb', line 7 def price @price end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
6 7 8 |
# File 'lib/order.rb', line 6 def sent_at @sent_at end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
6 7 8 |
# File 'lib/order.rb', line 6 def side @side end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/order.rb', line 6 def size @size end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/order.rb', line 6 def status @status end |
Instance Method Details
#<=>(order) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/order.rb', line 18 def <=> order if order.price == price @sent_at <=> order.sent_at else price <=> order.price end end |
#cancel! ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/order.rb', line 41 def cancel! return if @cancelled # can only cancel an order once @cancelled = true changed notify_observers :cancel, self end |
#cancelled? ⇒ Boolean
26 27 28 |
# File 'lib/order.rb', line 26 def cancelled? @cancelled end |
#fill!(amount) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/order.rb', line 30 def fill! amount changed status = :fill status = :partial_fill if amount < @size @size -= amount notify_observers status, self end |