Module: Cryptum::Option

Defined in:
lib/cryptum/option.rb,
lib/cryptum/option/choice.rb

Overview

This plugin is used to Cancel Open Limit Orders

Defined Under Namespace

Classes: Choice

Class Method Summary collapse

Class Method Details

.get_env(opts = {}) ⇒ Object

Initialize Cryptum Session Environment



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/cryptum/option.rb', line 173

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

  yaml_conf_file = "#{option_choice.session_root}/etc/coinbase_pro.yaml"
  yaml_conf = YAML.load_file(
    yaml_conf_file,
    symbolize_names: true
  )

  env = yaml_conf[:prod]
  env[:env] = :prod
  env = yaml_conf[:sandbox] if option_choice.sandbox
  env[:env] = :sandbox if option_choice.sandbox

  open_ai_yaml_conf_file = "#{option_choice.session_root}/etc/open_ai.yaml"
  if File.exist?(open_ai_yaml_conf_file)
    open_ai_yaml_conf = YAML.load_file(
      open_ai_yaml_conf_file,
      symbolize_names: true
    )
    env[:open_ai_bearer_token] = open_ai_yaml_conf[:bearer_token]
  end

  env
rescue StandardError => e
  raise e
end

.helpObject

Display a List of Every UI Module



202
203
204
# File 'lib/cryptum/option.rb', line 202

public_class_method def self.help
  constants.sort
end

.input_validation(opts = {}) ⇒ Object

Validate Options for cryptum Driver



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/cryptum/option.rb', line 82

public_class_method def self.input_validation(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 = 86_400 if option_choice.market_trend_reset.to_i.zero?
  unless option_choice.market_trend_reset.to_i >= 60 &&
         option_choice.market_trend_reset <= 604_800
    usage = true
    reason = :market_trend_reset
  end

  case option_choice.market_trend_reset
  when 604_800
    option_choice.market_trend_reset_label = '1W'
  when 86_400
    option_choice.market_trend_reset_label = '1D'
  when 14_400
    option_choice.market_trend_reset_label = '4h'
  when 10_800
    option_choice.market_trend_reset_label = '3h'
  when 7_200
    option_choice.market_trend_reset_label = '2h'
  when 3_600
    option_choice.market_trend_reset_label = '1h'
  when 2_700
    option_choice.market_trend_reset_label = '45m'
  when 1_800
    option_choice.market_trend_reset_label = '30m'
  when 900
    option_choice.market_trend_reset_label = '15m'
  when 300
    option_choice.market_trend_reset_label = '5m'
  when 180
    option_choice.market_trend_reset_label = '3m'
  when 60
    option_choice.market_trend_reset_label = '1m'
  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: 604_800 || 86_400 || 14_400 || 10_800 || 7_200 || 3_600 || 2_700 || 1_800 || 900 || 300 || 180 || 60\n\n"
    end

    puts `#{option_choice.driver_name} --help`
    exit 1
  end
rescue StandardError => e
  raise e
end

.list_products_and_exit(opts = {}) ⇒ Object

List Supported Cryptum Products and Exit



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/cryptum/option.rb', line 153

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

  puts "\n#{option_choice.driver_name} Supports the Following Products:"
  products = Cryptum::API.get_products(
    option_choice: option_choice,
    env: env
  )

  products.map do |product|
    puts product[:id].downcase
  end

  exit 0
rescue StandardError => e
  raise e
end

.parser(opts = {}) ⇒ Object

Options for cryptum Driver



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

public_class_method def self.parser(opts = {})
  option_choice = 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(
      '-A',
      '--[no-]autotrade',
      '<Optional - Automatically Buy and Sell Crypto>'
    ) { |a| option_choice.autotrade = a }

    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-session-countdown',
      '<Optional - Reset Timers / Market Trend Stats at Session Init (Defaults to false)>'
    ) { |t| option_choice.reset_session_countdown = t }

    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>'
    ) { |n| option_choice.sandbox = n }

    options.on(
      '-tSECONDS',
      '--time-between-market-trend-reset=SECONDS',
      '<Optional - Seconds Between Market Trend Reset (Default 60 i.e. 1 hour)>'
    ) { |t| option_choice.market_trend_reset = t.to_i }
  end.parse!

  input_validation(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 StandardError => e
  raise e
end