Class: Order
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#local_id ⇒ Object
readonly
Returns the value of attribute local_id.
-
#price ⇒ Object
readonly
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.
8 9 10 11 12 13 |
# File 'lib/order.rb', line 8 def initialize id, side, price, size @id, @side, @price, @size = id, side, price, size @sent_at = Time.now @cancelled = false @status = :pending_accept 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 |
#local_id ⇒ Object (readonly)
Returns the value of attribute local_id.
6 7 8 |
# File 'lib/order.rb', line 6 def local_id @local_id end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
6 7 8 |
# File 'lib/order.rb', line 6 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
19 20 21 22 23 24 25 |
# File 'lib/order.rb', line 19 def <=> order if order.price == price @sent_at <=> order.sent_at else price <=> order.price end end |
#cancel! ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/order.rb', line 42 def cancel! return if @cancelled # can only cancel an order once @cancelled = true changed notify_observers :cancel, self end |
#cancelled? ⇒ Boolean
27 28 29 |
# File 'lib/order.rb', line 27 def cancelled? @cancelled end |
#fill!(amount) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/order.rb', line 31 def fill! amount changed status = :fill status = :partial_fill if amount < @size @size -= amount notify_observers status, self end |