Class: Bitcoin::CLI
- Inherits:
-
Object
- Object
- Bitcoin::CLI
- Defined in:
- lib/bitcoin/cli.rb
Instance Method Summary collapse
-
#analysis_menu(symbol) ⇒ Object
ANALYSIS SUBMENU ###.
- #analysis_menu_display(symbol) ⇒ Object
- #candles_menu(symbol, candles = nil) ⇒ Object
- #candles_menu_display ⇒ Object
-
#choose(array) ⇒ Object
input: array to choose from output: object if choice is valid; -1 if ‘0’, -2 if no choice (only return key is pressed).
-
#currency_menu(list = nil) ⇒ Object
CURRENCY SUBMENU ###.
- #currency_menu_display ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #iti(input) ⇒ Object
- #main_menu_display ⇒ Object
- #menu ⇒ Object
- #order_book_menu(symbol, orders = nil) ⇒ Object
- #order_book_menu_display ⇒ Object
-
#symbol_menu(symbol = nil) ⇒ Object
SYMBOL SUBMENUS ###.
- #symbol_menu_display(symbol) ⇒ Object
-
#ticker_menu(list = nil) ⇒ Object
TICKER SUBMENU ###.
- #ticker_menu_display ⇒ Object
- #trade_menu(symbol, trades_array = nil) ⇒ Object
- #trade_menu_display ⇒ Object
-
#user_menu ⇒ Object
TODO: USER SUBMENU ###.
- #user_menu_display ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
3 4 5 6 |
# File 'lib/bitcoin/cli.rb', line 3 def initialize puts "Welcome!" end |
Instance Method Details
#analysis_menu(symbol) ⇒ Object
ANALYSIS SUBMENU ###
266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/bitcoin/cli.rb', line 266 def (symbol) (symbol) input = gets.strip if input == '0' (symbol) if input == '00' Bitcoin::Analyzer.analyze_trades symbol if input == '1' Bitcoin::Analyzer.analyze_candles symbol if input == '2' (symbol) end |
#analysis_menu_display(symbol) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/bitcoin/cli.rb', line 278 def (symbol) puts "" puts " Type 'exit' to quit" puts "" puts "///// [Analysis Mode - #{symbol.id}] /////" puts "/ [0] Main Menu" puts "/ [00] Symbol Menu" puts "/ [1] Analyze Trades Within Range..." puts "/ [2] Analyze Candles Within Range..." puts "" end |
#candles_menu(symbol, candles = nil) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/bitcoin/cli.rb', line 188 def (symbol, candles = nil) if !candles candles = Bitcoin::Candle.all(symbol.id) Bitcoin::Display.list_candles(candles) end selection = choose(candles) (symbol) if selection == -1 if selection == -2 (symbol) if selection == -3 selection.display_details end |
#candles_menu_display ⇒ Object
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/bitcoin/cli.rb', line 204 def puts "" puts " Type 'exit' to quit" puts "" puts "***** [Candles Menu] *****" puts "* [0] Main Menu" puts "* [00] Symbol Menu" puts "* [#] Select Entry to View Details" puts "" end |
#choose(array) ⇒ Object
input: array to choose from output: object if choice is valid; -1 if ‘0’, -2 if no choice (only return key is pressed)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bitcoin/cli.rb', line 43 def choose(array) puts "Make a selection, or press return to show list" choice = gets if choice.strip == '0' return -2 elsif choice == "\n" || choice.strip == "" return -1 elsif choice.strip == '00' return -3 elsif choice.strip != '0' && choice.to_i <= array.length return array[iti(choice)] else puts "Invalid selection. Try again" choose(array) end end |
#currency_menu(list = nil) ⇒ Object
CURRENCY SUBMENU ###
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/bitcoin/cli.rb', line 216 def (list = nil) if !list list = Bitcoin::Display.list_by_id(Bitcoin::Currency.all) end selection = choose(list) if selection == -1 if selection == -2 selection.display_details (list) end |
#currency_menu_display ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/bitcoin/cli.rb', line 229 def puts "" puts " Type 'exit' to quit" puts "" puts "***** [Currency Menu] *****" puts "* [0] Main Menu" puts "* [#] Select Entry to View Details" puts "" end |
#iti(input) ⇒ Object
37 38 39 |
# File 'lib/bitcoin/cli.rb', line 37 def iti(input) input.to_i - 1 # input to index end |
#main_menu_display ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bitcoin/cli.rb', line 8 def puts "" puts "Type 'exit' to quit" puts "" puts "***** [MAIN MENU] *****" puts "* What would you like to do?" puts "* [1] Select Symbol" puts "* [2] View Currency Information" puts "* [3] View Tickers" puts "* [4] User Dashboard" puts " " end |
#menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bitcoin/cli.rb', line 21 def # Display options input = gets.strip if input == '1' if input == '2' if input == '3' if input == '4' exit if input == 'exit' puts "Invalid command. Try again." end |
#order_book_menu(symbol, orders = nil) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/bitcoin/cli.rb', line 159 def (symbol, orders = nil) if !orders orders = Bitcoin::OrderBook.all(symbol.id) Bitcoin::Display.list_order_book(orders) end selection = choose(orders) (symbol) if selection == -1 if selection == -2 (symbol) if selection == -3 selection.display_details (symbol, orders) end |
#order_book_menu_display ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/bitcoin/cli.rb', line 177 def puts "" puts " Type 'exit' to quit" puts "" puts "***** [Order Book Menu] *****" puts "* [0] Main Menu" puts "* [00] Symbol Menu" puts "* [#] Select Entry to View Details" puts "" end |
#symbol_menu(symbol = nil) ⇒ Object
SYMBOL SUBMENUS ###
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 |
# File 'lib/bitcoin/cli.rb', line 87 def (symbol = nil) # display list & get symbol if it hasn't been selected yet if !symbol list = Bitcoin::Display.list_by_id(Bitcoin::Ssymbol.all) selection = choose(list) # if selection == -2 if selection == -1 symbol = selection end # display menu options for a symbol (symbol) # route choice to appropriate submenu input = gets.strip if input == '0' (symbol) if input == '1' (symbol) if input == '2' (symbol) if input == '3' (symbol) if input == '4' exit if input == 'exit' puts 'nope' (symbol) # menu loop after action end |
#symbol_menu_display(symbol) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/bitcoin/cli.rb', line 114 def (symbol) puts symbol.display_details puts "" puts "Type 'exit' to quit" puts "" puts "***** [Symbol Menu] #{symbol.id} *****" puts "* [0] Main Menu" puts "* [1] View Trades for #{symbol.id}" puts "* [2] View Order Book for #{symbol.id}" puts "* [3] View Candles for #{symbol.id}" puts "* [4] Analysis Mode" end |
#ticker_menu(list = nil) ⇒ Object
TICKER SUBMENU ###
240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/bitcoin/cli.rb', line 240 def (list = nil) if !list list = Bitcoin::Display.list_tickers(Bitcoin::Ticker.all) end selection = choose(list) if selection == -1 if selection == -2 selection.display_details (list) end |
#ticker_menu_display ⇒ Object
255 256 257 258 259 260 261 262 263 |
# File 'lib/bitcoin/cli.rb', line 255 def puts "" puts " Type 'exit' to quit" puts "" puts "***** [Ticker Menu] *****" puts "* [0] Main Menu" puts "* [#] Select Entry to View Details" puts "" end |
#trade_menu(symbol, trades_array = nil) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/bitcoin/cli.rb', line 127 def (symbol, trades_array = nil) if !trades_array # list all trades for symbol if first time trades = Bitcoin::Trade.all(symbol.id) Bitcoin::Display.list_trades(trades) end # User may either: select a trade to view, return to Main Menu, Symbol Menu, # or loop method to show list again selection = choose(trades) (symbol) if selection == -1 if selection == -2 (symbol) if selection == -3 selection.display_details # Loop method without re-listing if action performed sucessfully (symbol, trades) end |
#trade_menu_display ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/bitcoin/cli.rb', line 148 def puts "" puts " Type 'exit' to quit" puts "" puts "***** [Trades Menu] *****" puts "* [0] Main Menu" puts "* [00] Symbol Menu" puts "* [#] Select Entry to View Details" puts "" end |
#user_menu ⇒ Object
TODO: USER SUBMENU ###
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bitcoin/cli.rb', line 61 def input = gets.strip if input == '0' Bitcoin::Account.show_balances if input == '1' Bitcoin::Account.show_deposit_address if input == '2' exit if input == 'exit' end |
#user_menu_display ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bitcoin/cli.rb', line 72 def puts '' puts 'Type "exit" to quit' puts '' puts '====== [User Menu] ======' puts '| [0] Main Menu' puts '| [1] View Account Balances' puts '| [2] View Deposit Address...' # puts "* [3] Order Menu" # Create New, Cancel, Get by ID, Get History # puts "* [4] Trade Menu" # puts "* [5] Transfer To / From Bank Account" # puts '* [5] Transfer To / From Bank Account' end |