Module: Cryptum::Option::InputValidation

Defined in:
lib/cryptum/option/input_validation.rb

Overview

Common module to validate input submitted at session initiation

Class Method Summary collapse

Class Method Details

.check(opts = {}) ⇒ Object

Validate Options for cryptum Driver



9
10
11
12
13
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cryptum/option/input_validation.rb', line 9

public_class_method def self.check(opts = {})
  option_choice = opts[:option_choice]

  # Conditions to display cryptum usage
  if option_choice.symbol.nil? && option_choice.list_products.nil?
    usage = true
    reason = :symbol
  end

  option_choice.session_root = "#{Dir.home}/cryptum" if option_choice.session_root.nil?

  unless Dir.exist?(option_choice.session_root)
    usage = true
    reason = :session_root
  end

  option_choice.market_trend_reset = '1D' if option_choice.market_trend_reset.nil?
  case option_choice.market_trend_reset
  when '1W'
    option_choice.market_trend_reset_label = '1W'
    option_choice.market_trend_reset = 604_800
  when '1D'
    option_choice.market_trend_reset_label = '1D'
    option_choice.market_trend_reset = 86_400
  when '4h'
    option_choice.market_trend_reset_label = '4h'
    option_choice.market_trend_reset = 14_400
  when '3h'
    option_choice.market_trend_reset_label = '3h'
    option_choice.market_trend_reset = 10_800
  when '2h'
    option_choice.market_trend_reset_label = '2h'
    option_choice.market_trend_reset = 7_200
  when '1h'
    option_choice.market_trend_reset_label = '1h'
    option_choice.market_trend_reset = 3_600
  when '45m'
    option_choice.market_trend_reset_label = '45m'
    option_choice.market_trend_reset = 2_700
  when '30m'
    option_choice.market_trend_reset_label = '30m'
    option_choice.market_trend_reset = 1_800
  when '15m'
    option_choice.market_trend_reset_label = '15m'
    option_choice.market_trend_reset = 900
  when '5m'
    option_choice.market_trend_reset_label = '5m'
    option_choice.market_trend_reset = 300
  when '3m'
    option_choice.market_trend_reset_label = '3m'
    option_choice.market_trend_reset = 180
  when '1m'
    option_choice.market_trend_reset_label = '1m'
    option_choice.market_trend_reset = 60
  else
    usage = true
    reason = :market_trend_reset
  end

  if usage
    case reason
    when :symbol
      puts "ERROR: --symbol Flag is Required.\n\n"
    when :session_root
      puts "ERROR: #{option_choice.session_root} does not exist.\n\n"
    when :market_trend_reset
      puts "ERROR: #{option_choice.market_trend_reset} - Possible values are: 1W, 1D, 4h, 3h, 2h, 1h, 45m, 30m, 15m, 5m, 3m, 1m\n\n"
    end

    puts `#{option_choice.driver_name} --help`
    exit 1
  end
rescue Interrupt, StandardError => e
  Cryptum::Log.append(level: :error, msg: e, which_self: self)
end

.helpObject

Display Usage for this Module



86
87
88
89
90
# File 'lib/cryptum/option/input_validation.rb', line 86

public_class_method def self.help
  puts "USAGE:
    #{self}.check(option_choice: option_choice)
  "
end