class Gekko::MarketOrder

Represents a market order. If a bid, it must specify the maximum spendable quote currency as remaining quote margin

Attributes

max_precision[RW]
quote_margin[RW]
remaining_quote_margin[RW]

Public Class Methods

from_hash(hsh) click to toggle source

Initializes a Gekko::MarketOrder subclass from a Hash instance

@param hsh [Hash] The order data @return [Gekko::MarketOrder] A market order

# File lib/gekko/market_order.rb, line 48
def self.from_hash(hsh)
  order = MarketOrder.new(hsh[:side], UUID.parse(hsh[:id]), UUID.parse(hsh[:uid]), hsh[:size], hsh[:quote_margin], expiration: hsh[:expiration])
  order.created_at  = hsh[:created_at] if hsh[:created_at]
  order
end
new(side, id, uid, size, quote_margin, opts = {}) click to toggle source
Calls superclass method
# File lib/gekko/market_order.rb, line 11
def initialize(side, id, uid, size, quote_margin, opts = {})
  super(side, id, uid, size, opts)

  @quote_margin           = quote_margin
  @remaining_quote_margin = @quote_margin

  if bid?
    quote_margin.nil? && raise('Quote currency margin must be provided for a market bid')
  elsif ask?
    size.nil? && raise('Size must be provided for a market ask')
  end
end

Public Instance Methods

done?() click to toggle source

Returns true if the order has been filled or can not keep executing further due to quote currency margin constraints

# File lib/gekko/market_order.rb, line 37
def done?
  filled? ||
    (bid? && remaining_quote_margin.zero?)
end
filled?() click to toggle source

Returns true if the order is filled

# File lib/gekko/market_order.rb, line 27
def filled?
  max_precision ||
    (!size.nil? && remaining.zero?) ||
    (!quote_margin.nil? && remaining_quote_margin.zero?)
end