Module: Coinbot::Option
- Defined in:
- lib/coinbot/option.rb,
lib/coinbot/option/choice.rb
Overview
This plugin is used to Cancel Open Limit Orders
Defined Under Namespace
Classes: Choice
Class Method Summary collapse
-
.get_env(opts = {}) ⇒ Object
Initialize Coinbot Session Environment.
-
.help ⇒ Object
Display a List of Every UI Module.
-
.input_validation(opts = {}) ⇒ Object
Validate Options for coinbot Driver.
-
.list_products_and_exit(opts = {}) ⇒ Object
List Supported Coinbot Products and Exit.
-
.parser(opts = {}) ⇒ Object
Options for coinbot Driver.
Class Method Details
.get_env(opts = {}) ⇒ Object
Initialize Coinbot Session Environment
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/coinbot/option.rb', line 177 public_class_method def self.get_env(opts = {}) option_choice = opts[:option_choice] yaml_conf_file = "#{option_choice.repo_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 env rescue StandardError => e raise e end |
.help ⇒ Object
Display a List of Every UI Module
197 198 199 |
# File 'lib/coinbot/option.rb', line 197 public_class_method def self.help constants.sort end |
.input_validation(opts = {}) ⇒ Object
Validate Options for coinbot 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 151 152 153 |
# File 'lib/coinbot/option.rb', line 82 public_class_method def self.input_validation(opts = {}) option_choice = opts[:option_choice] # Conditions to display coinbot usage if option_choice.symbol.nil? && option_choice.list_products.nil? usage = true reason = :symbol end option_choice.candle_duration = 86_400 if option_choice.candle_duration.to_i.zero? valid_candle_durations = [0, 60, 300, 900, 3_600, 21_600, 86_400] unless valid_candle_durations.include?(option_choice.candle_duration) usage = true reason = :candle_duration end case option_choice.candle_duration when 0, 60 option_choice.trading_on = '1m' option_choice.candle_history = 5_000 if option_choice.candle_history.nil? when 300 option_choice.trading_on = '5m' option_choice.candle_history = 5_000 if option_choice.candle_history.nil? when 900 option_choice.trading_on = '15m' option_choice.candle_history = 5_000 if option_choice.candle_history.nil? when 3_600 option_choice.trading_on = '1h' option_choice.candle_history = 2_160 if option_choice.candle_history.nil? when 21_600 option_choice.trading_on = '6h' option_choice.candle_history = 1_460 if option_choice.candle_history.nil? when 86_400 option_choice.trading_on = '1d' option_choice.candle_history = 90 if option_choice.candle_history.nil? end candle_history = option_choice.candle_history.to_i option_choice.candle_history = 5_000 if candle_history.zero? unless option_choice.candle_history.to_i.positive? && option_choice.candle_history.to_i <= 12_960 usage = true reason = :candle_history end option_choice.repo_root = "#{Dir.home}/coinbot" if option_choice.repo_root.nil? unless Dir.exist?(option_choice.repo_root) usage = true reason = :repo_root end if usage case reason when :symbol puts "ERROR: --symbol Flag is Required.\n\n" when :candle_duration puts "ERROR: --candle-duration must be 60 (1m), 300 (5m), 900 (15m), 3_600 (1h), 21_600 (6h), or 86_400 (1d)\n\n" when :candle_history puts "ERROR: --candle-history must be between 0 and 300.\n\n" when :repo_root puts "ERROR: #{option_choice.repo_root} does not exist.\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 Coinbot Products and Exit
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/coinbot/option.rb', line 156 public_class_method def self.list_products_and_exit(opts = {}) option_choice = opts[:option_choice] env = opts[:env] puts `#{option_choice.driver_name} --help` puts "\n#{option_choice.driver_name} Supports the Following Products:" products = Coinbot::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 coinbot 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/coinbot/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 || . = "USAGE: #{option_choice.driver_name} [opts]" .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 } .on( '-A', '--[no-]autotrade', '<Optional - Automatically Buy and Sell Crypto>' ) { |a| option_choice.autotrade = a } .on( '-cSECONDS', '--candle-duration=SECONDS', '<Optional - Candle Duration in Seconds (60, 300, 900, 3_600, 21_600, 86_400, Defaults to 86_400 i.e. Daily Chart)' ) { |c| option_choice.candle_duration = c.to_i } .on( '-hCANDLES', '--candle-history=CANDLES', '<Optional - Candles to Retrieve from Coinbase (0-12_960, Default 5_000)' ) { |h| option_choice.candle_history = h.to_i } .on( '-l', '--[no-]list-products', '<Optional - List Supported Crypto Currency Products and Exit>' ) { |l| option_choice.list_products = l } .on( '-pPROXY', '--proxy=PROXY', '<Optional - HTTP Proxy e.g. "http://127.0.0.1:8080">' ) { |p| option_choice.proxy = p } .on( '-rPATH', '--repo-root=PATH', '<Optional - Directory of Cloned Repo (Defaults to ~/coinbot)>' ) { |r| option_choice.repo_root = r } .on( '-S', '--[no-]sandbox', '<Optional - Use Coinbase Sandbox Environment for Testing Ideas>' ) { |n| option_choice.sandbox = n } end.parse! input_validation(option_choice: option_choice) option_choice rescue OptionParser::InvalidOption => e # Print Usage if unsupported flags are passed puts "ERROR: #{e.}\n\n" puts `#{option_choice.driver_name} --help` exit 1 rescue StandardError => e raise e end |