Class: Gekko::LimitOrder
Overview
Represents a limit order. These order must specify a price.
Instance Attribute Summary collapse
-
#price ⇒ Object
Returns the value of attribute price.
Attributes inherited from Order
#created_at, #expiration, #id, #remaining, #side, #size, #uid
Class Method Summary collapse
-
.from_hash(hsh) ⇒ Gekko::LimitOrder
Initializes a
Gekko::LimitOrder
subclass from aHash
instance.
Instance Method Summary collapse
-
#<=>(other) ⇒ Fixnum
LimitOrders are sorted by ASC price for asks, DESC price for bids, if prices are equal then creation timestamp is used, and older orders get priority.
- #done? ⇒ Boolean
-
#filled? ⇒ Boolean
Returns
true
if the order is filled. -
#initialize(side, id, uid, size, price, expiration = nil) ⇒ LimitOrder
constructor
A new instance of LimitOrder.
Methods inherited from Order
#ask?, #bid?, #crosses?, #expired?, #fill_or_kill?, #message, #to_hash
Methods included from Serialization
Constructor Details
#initialize(side, id, uid, size, price, expiration = nil) ⇒ LimitOrder
Returns a new instance of LimitOrder.
10 11 12 13 14 15 |
# File 'lib/gekko/limit_order.rb', line 10 def initialize(side, id, uid, size, price, expiration = nil) super(side, id, uid, size, expiration) @price = price raise 'Price must be a positive integer' if @price.nil? || (!@price.is_a?(Fixnum) || (@price <= 0)) end |
Instance Attribute Details
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/gekko/limit_order.rb', line 8 def price @price end |
Class Method Details
.from_hash(hsh) ⇒ Gekko::LimitOrder
Initializes a Gekko::LimitOrder
subclass from a Hash
instance
47 48 49 50 51 52 |
# File 'lib/gekko/limit_order.rb', line 47 def self.from_hash(hsh) order = LimitOrder.new(hsh[:side], UUID.parse(hsh[:id]), UUID.parse(hsh[:uid]), hsh[:size], hsh[:price], hsh[:expiration]) order.remaining = hsh[:remaining] || hsh[:size] order.created_at = hsh[:created_at] if hsh[:created_at] order end |
Instance Method Details
#<=>(other) ⇒ Fixnum
LimitOrders are sorted by ASC price for asks, DESC price for bids, if prices are equal then creation timestamp is used, and older orders get priority.
35 36 37 38 39 |
# File 'lib/gekko/limit_order.rb', line 35 def <=>(other) cmp = (ask? ? 1 : -1) * (price <=> other.price) cmp = (created_at <=> other.created_at) if cmp.zero? cmp end |
#done? ⇒ Boolean
24 25 26 |
# File 'lib/gekko/limit_order.rb', line 24 def done? filled? end |
#filled? ⇒ Boolean
Returns true
if the order is filled
20 21 22 |
# File 'lib/gekko/limit_order.rb', line 20 def filled? remaining.zero? end |