Class: Bitcoin::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



3
4
5
6
# File 'lib/bitcoin/cli.rb', line 3

def initialize
  puts "Welcome!"
  menu
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 analysis_menu(symbol)

  analysis_menu_display(symbol)

  input = gets.strip
  menu if input == '0'
  symbol_menu(symbol) if input == '00'
  Bitcoin::Analyzer.analyze_trades symbol if input == '1'
  Bitcoin::Analyzer.analyze_candles symbol if input == '2'
  analysis_menu(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 analysis_menu_display(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 candles_menu(symbol, candles = nil)
  if !candles
    candles = Bitcoin::Candle.all(symbol.id)
    Bitcoin::Display.list_candles(candles)
  end

  candles_menu_display

  selection = choose(candles)
  candles_menu(symbol) if selection == -1
  menu                 if selection == -2
  symbol_menu(symbol)  if selection == -3

  selection.display_details
end

#candles_menu_displayObject



204
205
206
207
208
209
210
211
212
213
# File 'lib/bitcoin/cli.rb', line 204

def candles_menu_display
  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 currency_menu(list = nil)
  if !list
    list = Bitcoin::Display.list_by_id(Bitcoin::Currency.all)
  end
  currency_menu_display
  selection = choose(list)
  currency_menu if selection == -1
  menu          if selection == -2

  selection.display_details
  currency_menu(list)
end

#currency_menu_displayObject



229
230
231
232
233
234
235
236
237
# File 'lib/bitcoin/cli.rb', line 229

def currency_menu_display
  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


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bitcoin/cli.rb', line 8

def main_menu_display
  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


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bitcoin/cli.rb', line 21

def menu
  # Display options
  main_menu_display

  input = gets.strip
  symbol_menu   if input == '1'
  currency_menu if input == '2'
  ticker_menu   if input == '3'
  user_menu     if input == '4'
  exit          if input == 'exit'

  puts "Invalid command. Try again."
  menu

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 order_book_menu(symbol, orders = nil)
  if !orders
    orders = Bitcoin::OrderBook.all(symbol.id)
    Bitcoin::Display.list_order_book(orders)
  end

  order_book_menu_display

  selection = choose(orders)
  order_book_menu(symbol) if selection == -1
  menu                    if selection == -2
  symbol_menu(symbol)     if selection == -3

  selection.display_details

  order_book_menu(symbol, orders)
end

#order_book_menu_displayObject



177
178
179
180
181
182
183
184
185
186
# File 'lib/bitcoin/cli.rb', line 177

def order_book_menu_display
  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_menu(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) #
    menu if selection == -2
    symbol_menu if selection == -1
    symbol = selection
  end

  # display menu options for a symbol
  symbol_menu_display(symbol)

  # route choice to appropriate submenu
  input = gets.strip
  menu                    if input == '0'
  trade_menu(symbol)      if input == '1'
  order_book_menu(symbol) if input == '2'
  candles_menu(symbol)    if input == '3'
  analysis_menu(symbol)   if input == '4'
  exit                    if input == 'exit'
  puts 'nope'
  symbol_menu(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_menu_display(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 ticker_menu(list = nil)
  if !list
    list = Bitcoin::Display.list_tickers(Bitcoin::Ticker.all)
  end

  ticker_menu_display

  selection = choose(list)
  ticker_menu if selection == -1
  menu        if selection == -2

  selection.display_details
  ticker_menu(list)
end

#ticker_menu_displayObject



255
256
257
258
259
260
261
262
263
# File 'lib/bitcoin/cli.rb', line 255

def ticker_menu_display
  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 trade_menu(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

  trade_menu_display

  # User may either: select a trade to view, return to Main Menu, Symbol Menu,
  #   or loop method to show list again
  selection = choose(trades)
  trade_menu(symbol)  if selection == -1
  menu                if selection == -2
  symbol_menu(symbol) if selection == -3

  selection.display_details
  # Loop method without re-listing if action performed sucessfully
  trade_menu(symbol, trades)
end

#trade_menu_displayObject



148
149
150
151
152
153
154
155
156
157
# File 'lib/bitcoin/cli.rb', line 148

def trade_menu_display
  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_menuObject

TODO: USER SUBMENU ###



61
62
63
64
65
66
67
68
69
70
# File 'lib/bitcoin/cli.rb', line 61

def user_menu
  user_menu_display

  input = gets.strip
  menu if input == '0'
  Bitcoin::Account.show_balances if input == '1'
  Bitcoin::Account.show_deposit_address if input == '2'
  exit if input == 'exit'
  user_menu
end

#user_menu_displayObject



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bitcoin/cli.rb', line 72

def user_menu_display
  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