Class: Gekko::MarketOrder

Inherits:
Order
  • Object
show all
Defined in:
lib/gekko/market_order.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Order

#created_at, #expiration, #id, #price, #remaining, #side, #size, #uid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Order

#ask?, #bid?, #crosses?, #expired?, #fill_or_kill?, #message, #to_hash

Methods included from Serialization

included, #serialize

Constructor Details

#initialize(side, id, uid, size, quote_margin, expiration = nil) ⇒ MarketOrder

Returns a new instance of MarketOrder.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gekko/market_order.rb', line 11

def initialize(side, id, uid, size, quote_margin, expiration = nil)
  super(side, id, uid, size, expiration)

  @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

Instance Attribute Details

#max_precisionObject

Returns the value of attribute max_precision.



9
10
11
# File 'lib/gekko/market_order.rb', line 9

def max_precision
  @max_precision
end

#quote_marginObject

Returns the value of attribute quote_margin.



9
10
11
# File 'lib/gekko/market_order.rb', line 9

def quote_margin
  @quote_margin
end

#remaining_quote_marginObject

Returns the value of attribute remaining_quote_margin.



9
10
11
# File 'lib/gekko/market_order.rb', line 9

def remaining_quote_margin
  @remaining_quote_margin
end

Class Method Details

.from_hash(hsh) ⇒ Gekko::MarketOrder

Initializes a Gekko::MarketOrder subclass from a Hash instance

Parameters:

  • hsh (Hash)

    The order data

Returns:



48
49
50
51
52
# 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], hsh[:expiration])
  order.created_at  = hsh[:created_at] if hsh[:created_at]
  order
end

Instance Method Details

#done?Boolean

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

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/gekko/market_order.rb', line 37

def done?
  filled? ||
    (bid? && remaining_quote_margin.zero?)
end

#filled?Boolean

Returns true if the order is filled

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/gekko/market_order.rb', line 27

def filled?
  max_precision ||
    (!size.nil? && remaining.zero?) ||
    (!quote_margin.nil? && remaining_quote_margin.zero?)
end