class Gekko::LimitOrder

Represents a limit order. These order must specify a price.

Attributes

price[RW]

Public Class Methods

from_hash(hsh) click to toggle source

Initializes a Gekko::LimitOrder subclass from a Hash instance

@param hsh [Hash] The order data @return [Gekko::LimitOrder] A limit order

# 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], expiration: hsh[:expiration])
  order.remaining   = hsh[:remaining] || hsh[:size]
  order.created_at  = hsh[:created_at] if hsh[:created_at]
  order
end
new(side, id, uid, size, price, opts = {}) click to toggle source
Calls superclass method
# File lib/gekko/limit_order.rb, line 10
def initialize(side, id, uid, size, price, opts = {})
  super(side, id, uid, size, opts)
  @price = price

  raise 'Price must be a positive integer' if @price.nil? || (!@price.is_a?(Fixnum) || (@price <= 0))
end

Public Instance Methods

<=>(other) click to toggle source

+LimitOrder+s 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.

@return [Fixnum] 1 if self < other, -1 if not, 0 if equivalent

# 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?() click to toggle source
# File lib/gekko/limit_order.rb, line 24
def done?
  filled?
end
filled?() click to toggle source

Returns true if the order is filled

# File lib/gekko/limit_order.rb, line 20
def filled?
  remaining.zero?
end