Class: CossApiRubyWrapper::ParamsValidations

Inherits:
Object
  • Object
show all
Defined in:
lib/coss_api_ruby_wrapper/params_validations.rb

Defined Under Namespace

Classes: InvalidParameter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, params) ⇒ ParamsValidations

Returns a new instance of ParamsValidations.



8
9
10
11
12
# File 'lib/coss_api_ruby_wrapper/params_validations.rb', line 8

def initialize(endpoint, params)
  @endpoint = endpoint
  @params = params
  @errors = []
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/coss_api_ruby_wrapper/params_validations.rb', line 6

def endpoint
  @endpoint
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/coss_api_ruby_wrapper/params_validations.rb', line 6

def errors
  @errors
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/coss_api_ruby_wrapper/params_validations.rb', line 6

def params
  @params
end

Instance Method Details

#run!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/coss_api_ruby_wrapper/params_validations.rb', line 14

def run!
  case endpoint
  when '/order/add'
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:order_symbol] =~ /\w+_\w+/
    @errors << '"price" parameter should be convertable to float and be greater than zero' if params[:order_price] <= 0
    @errors << '"side" parameter should be either BUY or SELL string' unless %w[BUY SELL].include?(params[:order_side])
    @errors << '"amount" parameter should be convertable to float and be greater than zero' if params[:order_size] <= 0
  when '/order/cancel'
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:order_symbol] =~ /\w+_\w+/
    @errors << '"order_id" parameter should be a non-empty string' if params[:order_id].empty?
  when '/order/details'
    @errors << '"order_id" parameter should be a non-empty string' if params[:order_id].empty?
  when '/order/list/open'
    @errors << '"limit" parameter should be a positive integer' if params[:limit] <= 0
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:symbol] =~ /\w+_\w+/
  when '/order/list/completed'
    @errors << '"limit" parameter should be a positive integer' if params[:limit] <= 0
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:symbol] =~ /\w+_\w+/
  when '/order/list/all'
    @errors << '"limit" parameter should be a positive integer' if params[:limit] <= 0
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:symbol] =~ /\w+_\w+/
    @errors << '"from_order_id" parameter should be a non-empty string' if params[:from_order_id].empty?
  when '/market-price'
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:symbol] =~ /\w+_\w+/
  when '/dp'
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:symbol] =~ /\w+_\w+/
  when '/getmarketsummaries'
    @errors << '"symbol" parameter should be a string representing trading pair, for example: "COSS_ETH"' unless params[:symbol] =~ /\w+_\w+/
  end
end