class Bitfinex::Models::Order
Constants
- BOOL_FIELDS
- FIELDS
- FLAG_HIDDEN
- FLAG_NO_VR
- FLAG_OCO
- FLAG_POSTONLY
- FLAG_POS_CLOSE
- FLAG_REDUCE_ONLY
Attributes
last_amount[RW]
lev[RW]
Public Class Methods
gen_cid()
click to toggle source
# File lib/models/order.rb, line 58 def self.gen_cid @@last_cid += 1 @@last_cid end
new(data)
click to toggle source
Calls superclass method
Bitfinex::Models::Model::new
# File lib/models/order.rb, line 63 def initialize (data) super(data, FIELDS, BOOL_FIELDS) @flags = 0 unless @flags.is_a?(Numeric) @amount_orig = @amount if @amount_orig.nil? && !@amount.nil? @last_amount = @amount if data.kind_of?(Hash) set_oco(data[:oco]) if data.has_key?(:oco) set_hidden(data[:hidden]) if data.has_key?(:hidden) set_post_only(data[:post_only]) if data.has_key?(:post_only) if data.has_key?(:lev) @lev = data[:lev] end end end
unserialize(data)
click to toggle source
# File lib/models/order.rb, line 80 def self.unserialize (data) return Model.unserialize(data, FIELDS, BOOL_FIELDS) end
Public Instance Methods
get_base_currency()
click to toggle source
# File lib/models/order.rb, line 148 def get_base_currency @symbol[1...4] end
get_last_fill_amount()
click to toggle source
# File lib/models/order.rb, line 140 def get_last_fill_amount @last_amount - @amount end
get_notional_value()
click to toggle source
# File lib/models/order.rb, line 156 def get_notional_value (@amount * @price).abs end
get_quote_currency()
click to toggle source
# File lib/models/order.rb, line 152 def get_quote_currency @symbol[4..-1] end
includes_variable_rates()
click to toggle source
# File lib/models/order.rb, line 128 def includes_variable_rates return !!(@flags & FLAG_NO_VR) end
is_oco()
click to toggle source
# File lib/models/order.rb, line 116 def is_oco return !!(@flags & FLAG_OCO) end
is_partially_filled()
click to toggle source
# File lib/models/order.rb, line 160 def is_partially_filled a = @amount.abs a > 0 && a < @amount_orig.abs end
is_position_close()
click to toggle source
# File lib/models/order.rb, line 132 def is_position_close return !!(@flags & FLAG_POS_CLOSE) end
is_post_only()
click to toggle source
# File lib/models/order.rb, line 124 def is_post_only return !!(@flags & FLAG_POSTONLY) end
is_reduce_only()
click to toggle source
# File lib/models/order.rb, line 136 def is_reduce_only return !!(@flags & FLAG_REDUCE_ONLY) end
modify_flag(flag, active)
click to toggle source
# File lib/models/order.rb, line 84 def modify_flag (flag, active) return if (@flags & flag != 0) == active @flags += active ? flag : -flag end
reset_fill_amount()
click to toggle source
# File lib/models/order.rb, line 144 def reset_fill_amount @last_amount = @amount end
set_no_variable_rates(v)
click to toggle source
# File lib/models/order.rb, line 104 def set_no_variable_rates (v) modify_flag(FLAG_NO_VR, v) end
set_oco(v, stop_price = @price_aux_limit)
click to toggle source
# File lib/models/order.rb, line 90 def set_oco (v, stop_price = @price_aux_limit) @price_aux_limit = stop_price if v modify_flag(FLAG_OCO, v) end
set_position_close(v)
click to toggle source
# File lib/models/order.rb, line 108 def set_position_close (v) modify_flag(FLAG_POS_CLOSE, v) end
set_post_only(v)
click to toggle source
# File lib/models/order.rb, line 100 def set_post_only (v) modify_flag(FLAG_POSTONLY, v) end
set_reduce_only(v)
click to toggle source
# File lib/models/order.rb, line 112 def set_reduce_only (v) modify_flag(FLAG_REDUCE_ONLY, v) end
to_new_order_packet()
click to toggle source
# File lib/models/order.rb, line 165 def to_new_order_packet if !@cid.nil? cid = @cid else cid = Order.gen_cid end data = { :cid => cid, :symbol => @symbol, :type => @type, :amount => BigDecimal(@amount, 8).to_s, :flags => @flags || 0, :meta => @meta } if !@gid.nil? data[:gid] = @gid end if !@lev.nil? data[:lev] = @lev end data[:price] = BigDecimal(@price, 5).to_s if !@price.nil? data[:price_trailing] = BigDecimal(@price_trailing, 5).to_s if !@price_trailing.nil? if !@price_aux_limit.nil? if is_oco data[:price_oco_stop] = BigDecimal(@price_aux_limit, 5).to_s else data[:price_aux_limit] = BigDecimal(@price_aux_limit, 5).to_s end end data end
update(changes = {})
click to toggle source
# File lib/models/order.rb, line 201 def update (changes = {}) changes.each do |k, v| return if k == 'id' if FIELDS.has_key?(k) instance_variable_set(k, v) elsif k == 'price_trailing' @price_trailing = v.to_f elsif k == 'price_oco_stop' || k == 'price_aux_limit' @price_aux_limit = v.to_f elsif k == 'delta' && v.is_a?(Numeric) && @amount.is_a?(Numeric) @amount += v.to_f @last_amount = @amount end end end