Class: Fcoin::Orders::CreateOrderLimitValidator

Inherits:
BaseValidator show all
Includes:
ValidatorUtility
Defined in:
lib/fcoin/validator/orders/create_order_limit_validator.rb

Instance Method Summary collapse

Methods included from ValidatorUtility

#between_error_message, #includes_error_message, #presence_error_message

Constructor Details

#initialize(params) ⇒ CreateOrderLimitValidator

Returns a new instance of CreateOrderLimitValidator.

Parameters:

  • params (Hash)

    Parameter you want to verify including the called method name

Options Hash (params):

  • :symbol (String or Symbol)

    Transaction pair

  • :side (String or Symbol)

    Direction of the transaction

  • :price (Float)
  • :amount (Float)


14
15
16
17
18
19
# File 'lib/fcoin/validator/orders/create_order_limit_validator.rb', line 14

def initialize(params)
  self.symbol      = params[:symbol]
  self.side        = params[:side]
  self.price       = params[:price]
  self.amount      = params[:amount]
end

Instance Method Details

#messagesObject

Error message when invalid



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fcoin/validator/orders/create_order_limit_validator.rb', line 31

def messages
  return {} if valid?
  results = []

  results << presence_error_message(symbol, :symbol) unless valid_symbol?
  results << includes_error_message(side, :side, valid_sides) unless valid_side?
  if valid_symbol_setting_exist?
    results << between_error_message(price,  :price,  min(:price),  max(:price)) unless valid_price?
    results << between_error_message(amount, :amount, min(:amount), max(:amount)) unless valid_amount?
  end
  results.compact&.each_with_object({}) { |message, data| data.merge!(message) }
end

#valid?Boolean

Validate according to method_name

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/fcoin/validator/orders/create_order_limit_validator.rb', line 22

def valid?
  if valid_symbol_setting_exist?
    valid_price? && valid_amount?
  else
    valid_symbol? && valid_side?
  end
end