Module: Cryptum::Option::Parser

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

Overview

Common module to consume YAML config and determine which environment to use.

Class Method Summary collapse

Class Method Details

.get(opts = {}) ⇒ Object

Parse Options Passed to cryptum



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
# File 'lib/cryptum/option/parser.rb', line 9

public_class_method def self.get(opts = {})
  option_choice = Cryptum::Option::Choice.new
  option_choice.driver_name = opts[:driver_name]

  OptionParser.new do |options|
    options.banner = "USAGE: #{option_choice.driver_name} [opts]"

    options.on(
      '-sSYMBOL',
      '--symbol=SYMBOL',
      '<Required - Crypto Symbol.(e.g. btc-usd, eth-usd, etc.)'
    ) { |s| option_choice.symbol = s.to_s.gsub('-', '_').downcase.to_sym }

    options.on(
      '-l',
      '--[no-]list-products',
      '<Optional - List Supported Crypto Currency Products and Exit>'
    ) { |l| option_choice.list_products = l }

    options.on(
      '-pPROXY',
      '--proxy=PROXY',
      '<Optional - HTTP Proxy e.g. "http://127.0.0.1:8080">'
    ) { |p| option_choice.proxy = p }

    options.on(
      '-R',
      '--[no-]reset-timers',
      '<Optional - Reset Market Trend & Order Countdown at Session Init (Defaults to false)>'
    ) { |r| option_choice.reset_timers = r }

    options.on(
      '-rPATH',
      '--session-root=PATH',
      '<Optional - Directory with etc && order_books (Defaults to ~/cryptum)>'
    ) { |r| option_choice.session_root = r }

    options.on(
      '-S',
      '--[no-]sandbox',
      '<Optional - Use Coinbase Sandbox Environment for Testing Ideas>'
    ) { |s| option_choice.sandbox = s }

    options.on(
      '-tTIME',
      '--trend-reset-time=TIME',
      '<Optional - Time Between Market Trend Reset (Default 1D)>'
    ) { |t| option_choice.market_trend_reset = t }
  end.parse!

  Cryptum::Option::InputValidation.check(option_choice: option_choice)

  option_choice
rescue OptionParser::InvalidOption => e
  # Print Usage if unsupported flags are passed
  puts "ERROR: #{e.message}\n\n"
  puts `#{option_choice.driver_name} --help`
  exit 1
rescue Interrupt, StandardError => e
  Cryptum::Log.append(level: :error, msg: e, which_self: self)
end

.helpObject

Display Usage for this Module



72
73
74
75
76
# File 'lib/cryptum/option/parser.rb', line 72

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