cryptum 0.0.359 → 0.0.360

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +16 -0
  3. data/.gitignore +30 -0
  4. data/.rspec +3 -0
  5. data/.rspec_status +0 -0
  6. data/.rubocop.yml +31 -0
  7. data/.rubocop_todo.yml +36 -0
  8. data/.ruby-gemset +1 -0
  9. data/.ruby-version +1 -0
  10. data/CODE_OF_CONDUCT.md +84 -0
  11. data/Gemfile +38 -0
  12. data/LICENSE +674 -0
  13. data/README.md +87 -0
  14. data/Rakefile +19 -0
  15. data/bin/cryptum +73 -0
  16. data/bin/cryptum-forecast +200 -0
  17. data/bin/cryptum-repl +73 -0
  18. data/bin/cryptum_autoinc_version +38 -0
  19. data/build_cryptum_gem.sh +58 -0
  20. data/cryptum.gemspec +52 -0
  21. data/cryptum_container.sh +1 -0
  22. data/docker/cryptum.json +60 -0
  23. data/docker/cryptum_container.sh +59 -0
  24. data/docker/packer_secrets.json.EXAMPLE +7 -0
  25. data/docker/provisioners/cryptum.sh +11 -0
  26. data/docker/provisioners/docker_bashrc.sh +2 -0
  27. data/docker/provisioners/docker_rvm.sh +22 -0
  28. data/docker/provisioners/init_image.sh +28 -0
  29. data/docker/provisioners/post_install.sh +6 -0
  30. data/docker/provisioners/ruby.sh +16 -0
  31. data/docker/provisioners/upload_globals.sh +49 -0
  32. data/etc/bot_confs/.gitkeep +0 -0
  33. data/etc/bot_confs/BOT_CONF.TEMPLATE +10 -0
  34. data/etc/coinbase_pro.yaml.EXAMPLE +8 -0
  35. data/etc/open_ai.yaml.EXAMPLE +1 -0
  36. data/git_commit.sh +22 -0
  37. data/lib/cryptum/api.rb +688 -0
  38. data/lib/cryptum/bot_conf.rb +197 -0
  39. data/lib/cryptum/event/bot_conf.rb +34 -0
  40. data/lib/cryptum/event/buy.rb +145 -0
  41. data/lib/cryptum/event/cancel.rb +35 -0
  42. data/lib/cryptum/event/exit.rb +35 -0
  43. data/lib/cryptum/event/gtfo.rb +36 -0
  44. data/lib/cryptum/event/history.rb +108 -0
  45. data/lib/cryptum/event/key_press.rb +64 -0
  46. data/lib/cryptum/event/order_book.rb +34 -0
  47. data/lib/cryptum/event/pane.rb +65 -0
  48. data/lib/cryptum/event/parse.rb +181 -0
  49. data/lib/cryptum/event/scroll.rb +200 -0
  50. data/lib/cryptum/event/sell.rb +124 -0
  51. data/lib/cryptum/event.rb +27 -0
  52. data/lib/cryptum/log.rb +34 -0
  53. data/lib/cryptum/matrix.rb +181 -0
  54. data/lib/cryptum/open_ai.rb +156 -0
  55. data/lib/cryptum/option/choice.rb +28 -0
  56. data/lib/cryptum/option.rb +206 -0
  57. data/lib/cryptum/order_book/generate.rb +114 -0
  58. data/lib/cryptum/order_book/indicator.rb +15 -0
  59. data/lib/cryptum/order_book/market_trend.rb +137 -0
  60. data/lib/cryptum/order_book/profit_margin.rb +55 -0
  61. data/lib/cryptum/order_book.rb +19 -0
  62. data/lib/cryptum/portfolio/balance.rb +123 -0
  63. data/lib/cryptum/portfolio.rb +15 -0
  64. data/lib/cryptum/ui/command.rb +314 -0
  65. data/lib/cryptum/ui/key_press_event.rb +33 -0
  66. data/lib/cryptum/ui/market_trend.rb +77 -0
  67. data/lib/cryptum/ui/order_execute_details.rb +297 -0
  68. data/lib/cryptum/ui/order_execution.rb +573 -0
  69. data/lib/cryptum/ui/order_plan.rb +512 -0
  70. data/lib/cryptum/ui/order_plan_details.rb +240 -0
  71. data/lib/cryptum/ui/order_timer.rb +136 -0
  72. data/lib/cryptum/ui/portfolio.rb +221 -0
  73. data/lib/cryptum/ui/signal_engine.rb +109 -0
  74. data/lib/cryptum/ui/terminal_window.rb +111 -0
  75. data/lib/cryptum/ui/ticker.rb +319 -0
  76. data/lib/cryptum/ui.rb +343 -0
  77. data/lib/cryptum/version.rb +5 -0
  78. data/lib/cryptum/web_sock/coinbase.rb +104 -0
  79. data/lib/cryptum/web_sock/event_machine.rb +276 -0
  80. data/lib/cryptum/web_sock.rb +16 -0
  81. data/lib/cryptum.rb +120 -0
  82. data/order_books/.gitkeep +0 -0
  83. data/reinstall_cryptum_gemset.sh +29 -0
  84. data/spec/lib/cryptum/api_spec.rb +10 -0
  85. data/spec/lib/cryptum/event_spec.rb +10 -0
  86. data/spec/lib/cryptum/log_spec.rb +10 -0
  87. data/spec/lib/cryptum/option_spec.rb +10 -0
  88. data/spec/lib/cryptum/order_book/generate_spec.rb +10 -0
  89. data/spec/lib/cryptum/order_book/market_trend_spec.rb +10 -0
  90. data/spec/lib/cryptum/order_book_spec.rb +10 -0
  91. data/spec/lib/cryptum/ui/command_spec.rb +10 -0
  92. data/spec/lib/cryptum/ui/ticker_spec.rb +10 -0
  93. data/spec/lib/cryptum/ui_spec.rb +10 -0
  94. data/spec/lib/cryptum/web_sock_spec.rb +10 -0
  95. data/spec/lib/cryptum_spec.rb +10 -0
  96. data/spec/spec_helper.rb +3 -0
  97. data/upgrade_Gemfile_gems.sh +20 -0
  98. data/upgrade_cryptum.sh +13 -0
  99. data/upgrade_gem.sh +4 -0
  100. data/upgrade_ruby.sh +45 -0
  101. metadata +112 -9
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to indicate if the order trend
5
+
6
+ module OrderBook
7
+ module MarketTrend
8
+ # Supported Method Parameters::
9
+ # Cryptum::OrderBook::OrderTrend.status(
10
+ # )
11
+
12
+ public_class_method def self.status(opts = {})
13
+ event_history = opts[:event_history]
14
+ event = opts[:event]
15
+ indicator_status = opts[:indicator_status]
16
+
17
+ # Compatible w/ l2update websocket channel
18
+ # buy_or_sell = event[:changes].first[0].to_s.to_sym
19
+ # case buy_or_sell
20
+ # when :buy
21
+ # event_history.order_book[:market_trend][:buy] += 1
22
+ # when :sell
23
+ # event_history.order_book[:market_trend][:sell] += 1
24
+ # else
25
+ # raise "UNKNOWN Value in event[:changes] => #{buy_or_sell}"
26
+ # end
27
+
28
+ # Compatible w/ l2update_batch websocket channel
29
+ buy_count = event[:changes].select { |change| change.first == 'buy' }.length
30
+ sell_count = event[:changes].select { |change| change.first == 'sell' }.length
31
+ event_history.order_book[:market_trend][:buy] += buy_count
32
+ event_history.order_book[:market_trend][:sell] += sell_count
33
+
34
+ indicator_hash = {}
35
+ buy_total = event_history.order_book[:market_trend][:buy].to_i
36
+ indicator_hash[:buy] = buy_total
37
+
38
+ sell_total = event_history.order_book[:market_trend][:sell].to_i
39
+ indicator_hash[:sell] = sell_total
40
+
41
+ # order_difference = 0
42
+ if buy_total > sell_total
43
+ order_difference = buy_total - sell_total
44
+ motivation = 'BUYING THE DIP'
45
+ indicator_hash[:color] = :red
46
+ if event_history.bullish_trend
47
+ motivation = 'FOMO' if event_history.bullish_trend
48
+ indicator_hash[:color] = :green
49
+ end
50
+ trend = "BUYS #{Cryptum.up_arrow} BY #{order_difference.to_i}"
51
+ indicator_hash[:status] = "B#{Cryptum.up_arrow}"
52
+ elsif buy_total < sell_total
53
+ order_difference = sell_total - buy_total
54
+ motivation = 'REKT'
55
+ indicator_hash[:color] = :red
56
+ if event_history.bullish_trend
57
+ motivation = 'TAKING PROFITS' if event_history.bullish_trend
58
+ indicator_hash[:color] = :green
59
+ end
60
+ trend = "SELLS #{Cryptum.up_arrow} BY #{order_difference.to_i}"
61
+ indicator_hash[:status] = "S#{Cryptum.up_arrow}"
62
+ else
63
+ # This Condition is Met When candle_buy_tot == candle_sell_tot
64
+ motivation = 'FLAT'
65
+ indicator_hash[:color] = :yellow
66
+ trend = 'BUYS == SELLS'
67
+ indicator_hash[:status] = "F#{Cryptum.up_arrow}"
68
+ end
69
+ indicator_hash[:ui] = "Market is #{motivation} | #{trend}"
70
+
71
+ indicator_status.market_trend = indicator_hash
72
+ rescue StandardError => e
73
+ raise e
74
+ end
75
+
76
+ # public_class_method def self.reset(opts = {})
77
+ # # IT IS ABSOLUTELY CRITICAL THIS METHOD IS AS FAST AS POSSIBLE
78
+ # # TO AVOID TICKER PRICE SYNCING ISSUES.
79
+ # event_history = opts[:event_history]
80
+
81
+ # # order_history = event_history.order_book[:order_history]
82
+ # # order_history_meta = event_history.order_book[:order_history_meta]
83
+
84
+ # # Only retain past 24 hours of
85
+ # # order history meta for bought, sold, and expired
86
+ # # keep open limit sell orders indefintely
87
+ # # before_twenty_four_hrs_ago = Time.now - 86_400
88
+ # # order_history_meta.delete_if do |ohm|
89
+ # # order_history.find do |oh|
90
+ # # next unless oh[:done_at]
91
+
92
+ # # Time.parse(oh[:done_at]) < before_twenty_four_hrs_ago && (
93
+ # # oh[:id] == ohm[:buy_order_id] ||
94
+ # # oh[:id] == ohm[:sell_order_id]
95
+ # # ) && (
96
+ # # ohm[:color].to_sym == :white ||
97
+ # # ohm[:color].to_sym == :green ||
98
+ # # ohm[:color].to_sym == :cyan ||
99
+ # # ohm[:color].to_sym == :red
100
+ # # )
101
+ # # end
102
+ # # end
103
+
104
+ # # Only keep order history meta for those
105
+ # # hashes that exist in the last order history
106
+ # # response
107
+ # # order_history_meta.keep_if do |ohm|
108
+ # # order_history.find do |oh|
109
+ # # (oh[:id] == ohm[:buy_order_id] || oh[:id] == ohm[:sell_order_id]) && (
110
+ # # ohm[:color].to_sym == :white ||
111
+ # # ohm[:color].to_sym == :green ||
112
+ # # ohm[:color].to_sym == :yellow
113
+ # # )
114
+ # # end
115
+ # # end
116
+ # # event_history.order_book[:order_history_meta] = order_history_meta
117
+
118
+ # # Reset Market Trend Counter
119
+ # event_history.order_book[:market_trend][:buy] = 0
120
+ # event_history.order_book[:market_trend][:sell] = 0
121
+ # event_history.order_book[:last_trend_reset] = Time.now.strftime(
122
+ # '%Y-%m-%d %H:%M:%S.%N%z'
123
+ # )
124
+ # rescue StandardError => e
125
+ # raise e
126
+ # end
127
+
128
+ # Display Usage for this Module
129
+
130
+ public_class_method def self.help
131
+ puts "USAGE:
132
+ order_trend_indicator_hash = #{self}.status
133
+ "
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to indicate if the
5
+ # Projected Profit Margin is greater than
6
+ # the Target Profit Margin Outlined in the
7
+ # Respective Bot Conf
8
+
9
+ module OrderBook
10
+ module ProfitMargin
11
+ # Supported Method Parameters::
12
+ # Cryptum::OrderBook::ProfitMargin.status(
13
+ # )
14
+
15
+ public_class_method def self.status(opts = {})
16
+ indicator_hash = {}
17
+ target_profit_margin_percent = opts[:target_profit_margin_percent]
18
+ total_invested = opts[:total_invested]
19
+ total_projected_return = opts[:total_projected_return]
20
+ indicator_status = opts[:indicator_status]
21
+ invested = opts[:invested]
22
+
23
+ ave_profit_margin_percent = 100 - ((total_invested / total_projected_return) * 100)
24
+
25
+ if ave_profit_margin_percent > target_profit_margin_percent
26
+ indicator_hash[:color] = :green
27
+ pm_op = '>'
28
+ elsif ave_profit_margin_percent < target_profit_margin_percent
29
+ indicator_hash[:color] = :red
30
+ pm_op = '<'
31
+ else
32
+ indicator_hash[:color] = :yellow
33
+ pm_op = '=='
34
+ end
35
+
36
+ profit_margin_status_out = "Profit Margin #{pm_op} TPM"
37
+ indicator_hash[:invested] = invested
38
+ indicator_hash[:status] = profit_margin_status_out
39
+
40
+ indicator_status.profit_margin = indicator_hash
41
+ rescue StandardError => e
42
+ raise e
43
+ end
44
+
45
+ # Display Usage for this Module
46
+
47
+ public_class_method def self.help
48
+ puts "USAGE:
49
+ weighted_ave_indicator_hash = #{self}.status(
50
+ )
51
+ "
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ module Cryptum
7
+ # This module is used to define the Order Book Data Structure
8
+ module OrderBook
9
+ require 'cryptum/order_book/generate'
10
+ require 'cryptum/order_book/indicator'
11
+ require 'cryptum/order_book/market_trend'
12
+ require 'cryptum/order_book/profit_margin'
13
+
14
+ # Display Usage for this Module
15
+ public_class_method def self.help
16
+ constants.sort
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Cryptum
6
+ # This plugin is used to instantiate a Cryptum logger with a custom message format
7
+ module Portfolio
8
+ module Balance
9
+ # Supported Method Parameters::
10
+ # Cryptum::Event::Update.summary(
11
+ # )
12
+ public_class_method def self.refresh(opts = {})
13
+ option_choice = opts[:option_choice]
14
+ env = opts[:env]
15
+ terminal_win = opts[:terminal_win]
16
+ event_history = opts[:event_history]
17
+ fiat_portfolio_file = opts[:fiat_portfolio_file]
18
+
19
+ this_product = event_history.order_book[:this_product]
20
+ crypto = this_product[:base_currency]
21
+ fiat = this_product[:quote_currency]
22
+
23
+ if event_history.first_event ||
24
+ event_history.reconnected ||
25
+ event_history.event_type == :received ||
26
+ event_history.event_type == :open ||
27
+ event_history.event_type == :done ||
28
+ event_history.event_type == :match ||
29
+ event_history.event_type == :change ||
30
+ event_history.event_type == :activate ||
31
+ terminal_win.key_press_event.key_u
32
+
33
+ etype = event_history.event_type
34
+ manual_refresh = terminal_win.key_press_event.key_u
35
+ etype = :manual_refresh if manual_refresh
36
+ etype = :first_event if event_history.first_event
37
+ etype = :reconnected if event_history.reconnected
38
+ event_history.event_type = etype
39
+
40
+ # Prevent Multiple Order Events from Occuring --- #
41
+ ocancel = event_history.order_canceled
42
+ osubmit = event_history.order_submitted
43
+
44
+ # POTENTIAL STOP IN ORDERS WHEN
45
+ # event_history.order_canceled = true
46
+ # Verify it's not due to EMA being red.
47
+ # ocancel = false if (etype == :open || etype == :done) &&
48
+ # osubmit == false &&
49
+ # !manual_refresh
50
+
51
+ ocancel = false if etype == :done &&
52
+ osubmit == true &&
53
+ !manual_refresh
54
+
55
+ event_history.order_canceled = ocancel
56
+
57
+ osubmit = false if etype == :done &&
58
+ !manual_refresh
59
+
60
+ event_history.order_submitted = osubmit
61
+ # ---------------------------------------------- #
62
+
63
+ enotes = event_history.event_notes
64
+ enotes = "{ \"event_type\": \"#{etype}\", \"cancel\": \"#{ocancel}\", \"submitted\": \"#{osubmit}\" }" if option_choice.proxy
65
+ event_history.event_notes = enotes
66
+
67
+ portfolio = Cryptum::API.get_portfolio(
68
+ option_choice: option_choice,
69
+ env: env,
70
+ crypto: crypto,
71
+ fiat: fiat,
72
+ fiat_portfolio_file: fiat_portfolio_file,
73
+ event_notes: event_history.event_notes
74
+ )
75
+ event_history.order_book[:portfolio] = portfolio unless portfolio.empty?
76
+
77
+ order_history = Cryptum::API.get_order_history(
78
+ option_choice: option_choice,
79
+ env: env
80
+ )
81
+ event_history.order_book[:order_history] = order_history unless order_history.empty?
82
+
83
+ fees = Cryptum::API.get_fees(
84
+ option_choice: option_choice,
85
+ env: env
86
+ )
87
+ event_history.order_book[:fees] = fees unless fees.empty?
88
+
89
+ terminal_win.key_press_event.key_u = false if manual_refresh
90
+ # First Event to Refresh No Longer Needed
91
+ event_history.first_event = false
92
+ # Reconnected Event to Refresh No Longer Needed
93
+ event_history.reconnected = false
94
+ end
95
+
96
+ # Always reload fiat portfolio as it's shared
97
+ # by all sessions (unless it's empty)
98
+ fpf = ''
99
+ fpf = File.read(fiat_portfolio_file) unless File.empty?(
100
+ fiat_portfolio_file
101
+ )
102
+
103
+ unless fpf.empty?
104
+ event_history.order_book[:fiat_portfolio] = JSON.parse(
105
+ fpf,
106
+ symbolize_names: true
107
+ )
108
+ end
109
+
110
+ event_history
111
+ rescue StandardError => e
112
+ raise e
113
+ end
114
+
115
+ # Display Usage for this Module
116
+ public_class_method def self.help
117
+ puts "USAGE:
118
+ event_history.order_book = #{self}.crypto()
119
+ "
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Cryptum
6
+ # This plugin is used to instantiate a Cryptum logger with a custom message format
7
+ module Portfolio
8
+ require 'cryptum/portfolio/balance'
9
+
10
+ # Display Usage for this Module
11
+ public_class_method def self.help
12
+ constants.sort
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,314 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Cryptum
6
+ module UI
7
+ # This plugin is used to Refresh the Cryptum Command Section UI
8
+ module Command
9
+ # Supported Method Parameters::
10
+ # Cryptum::UI::Command.refresh(
11
+ # action_command_status: 'required - Instatiated Cryptum::OrderBook::Probabilities Object'
12
+ # )
13
+ public_class_method def self.refresh(opts = {})
14
+ command_win = opts[:command_win]
15
+ key_press_event = opts[:key_press_event]
16
+
17
+ key_press_event = Cryptum::UI.detect_key_press_in_ui(
18
+ key_press_event: key_press_event,
19
+ ui_win: command_win
20
+ )
21
+
22
+ if key_press_event.key_c
23
+ key_c_color = :cyan
24
+ key_c_style = :reverse
25
+ else
26
+ key_c_color = :white
27
+ key_c_style = :bold
28
+ end
29
+
30
+ if key_press_event.key_g
31
+ key_g_color = :cyan
32
+ key_g_style = :reverse
33
+ else
34
+ key_g_color = :white
35
+ key_g_style = :bold
36
+ end
37
+
38
+ if key_press_event.key_r
39
+ key_r_color = :cyan
40
+ key_r_style = :reverse
41
+ else
42
+ key_r_color = :white
43
+ key_r_style = :bold
44
+ end
45
+
46
+ if key_press_event.key_u
47
+ key_u_color = :cyan
48
+ key_u_style = :reverse
49
+ else
50
+ key_u_color = :white
51
+ key_u_style = :bold
52
+ end
53
+
54
+ if key_press_event.key_w
55
+ key_w_color = :cyan
56
+ key_w_style = :reverse
57
+ else
58
+ key_w_color = :white
59
+ key_w_style = :bold
60
+ end
61
+
62
+ if key_press_event.key_x
63
+ key_x_color = :cyan
64
+ key_x_style = :reverse
65
+ else
66
+ key_x_color = :white
67
+ key_x_style = :bold
68
+ end
69
+
70
+ command_str_r2_arr = [
71
+ "* v#{Cryptum::VERSION} >>> ",
72
+ '[',
73
+ 'C',
74
+ ']ancel Open Orders',
75
+ ' | ',
76
+ '[',
77
+ 'G',
78
+ ']TFO',
79
+ ' | ',
80
+ '[',
81
+ 'r',
82
+ ']eload bot conf'
83
+ ]
84
+
85
+ command_str_r3_arr = [
86
+ '[',
87
+ 'u',
88
+ ']pdate summary',
89
+ ' | ',
90
+ '[',
91
+ 'w',
92
+ ']rite order book',
93
+ ' | ',
94
+ 'e[',
95
+ 'x',
96
+ ']it'
97
+ ]
98
+ # ROW 1
99
+ out_line_no = 0
100
+ command_win.clrtoeol
101
+ command_win.setpos(
102
+ out_line_no,
103
+ Cryptum::UI.col_center(str: command_str_r2_arr.join)
104
+ )
105
+
106
+ # * v#{Cryptum::VERSION} >>>
107
+ Cryptum::UI.colorize(
108
+ ui_win: command_win,
109
+ color: :yellow,
110
+ style: :bold,
111
+ string: command_str_r2_arr.first
112
+ )
113
+
114
+ # [C]ancel Open Orders
115
+ Cryptum::UI.colorize(
116
+ ui_win: command_win,
117
+ color: key_c_color,
118
+ style: key_c_style,
119
+ string: command_str_r2_arr[1]
120
+ )
121
+
122
+ Cryptum::UI.colorize(
123
+ ui_win: command_win,
124
+ color: :yellow,
125
+ style: key_c_style,
126
+ string: command_str_r2_arr[2]
127
+ )
128
+
129
+ Cryptum::UI.colorize(
130
+ ui_win: command_win,
131
+ color: key_c_color,
132
+ style: key_c_style,
133
+ string: command_str_r2_arr[3]
134
+ )
135
+
136
+ # |
137
+ Cryptum::UI.colorize(
138
+ ui_win: command_win,
139
+ color: :white,
140
+ string: command_str_r2_arr[4]
141
+ )
142
+
143
+ # [G]TFO
144
+ Cryptum::UI.colorize(
145
+ ui_win: command_win,
146
+ color: key_g_color,
147
+ style: key_g_style,
148
+ string: command_str_r2_arr[5]
149
+ )
150
+
151
+ Cryptum::UI.colorize(
152
+ ui_win: command_win,
153
+ color: :yellow,
154
+ style: key_g_style,
155
+ string: command_str_r2_arr[6]
156
+ )
157
+
158
+ Cryptum::UI.colorize(
159
+ ui_win: command_win,
160
+ color: key_g_color,
161
+ style: key_g_style,
162
+ string: command_str_r2_arr[7]
163
+ )
164
+
165
+ # |
166
+ Cryptum::UI.colorize(
167
+ ui_win: command_win,
168
+ color: :white,
169
+ string: command_str_r2_arr[8]
170
+ )
171
+
172
+ # [r]eload bot conf
173
+ Cryptum::UI.colorize(
174
+ ui_win: command_win,
175
+ color: key_r_color,
176
+ style: key_r_style,
177
+ string: command_str_r2_arr[9]
178
+ )
179
+
180
+ Cryptum::UI.colorize(
181
+ ui_win: command_win,
182
+ color: :yellow,
183
+ style: key_r_style,
184
+ string: command_str_r2_arr[10]
185
+ )
186
+
187
+ Cryptum::UI.colorize(
188
+ ui_win: command_win,
189
+ color: key_r_color,
190
+ style: key_r_style,
191
+ string: command_str_r2_arr.last
192
+ )
193
+
194
+ # ROW 3
195
+ out_line_no += 1
196
+ command_win.setpos(
197
+ out_line_no,
198
+ Cryptum::UI.col_center(str: command_str_r3_arr.join)
199
+ )
200
+ command_win.clrtoeol
201
+
202
+ # [u]date summary
203
+ Cryptum::UI.colorize(
204
+ ui_win: command_win,
205
+ color: key_u_color,
206
+ style: key_u_style,
207
+ string: command_str_r3_arr.first
208
+ )
209
+
210
+ Cryptum::UI.colorize(
211
+ ui_win: command_win,
212
+ color: :yellow,
213
+ style: key_u_style,
214
+ string: command_str_r3_arr[1]
215
+ )
216
+
217
+ Cryptum::UI.colorize(
218
+ ui_win: command_win,
219
+ color: key_u_color,
220
+ style: key_u_style,
221
+ string: command_str_r3_arr[2]
222
+ )
223
+
224
+ # |
225
+ Cryptum::UI.colorize(
226
+ ui_win: command_win,
227
+ color: :white,
228
+ string: command_str_r3_arr[3]
229
+ )
230
+
231
+ # [w]rite order book
232
+ Cryptum::UI.colorize(
233
+ ui_win: command_win,
234
+ color: key_w_color,
235
+ style: key_w_style,
236
+ string: command_str_r3_arr[4]
237
+ )
238
+
239
+ Cryptum::UI.colorize(
240
+ ui_win: command_win,
241
+ color: :yellow,
242
+ style: key_w_style,
243
+ string: command_str_r3_arr[5]
244
+ )
245
+
246
+ Cryptum::UI.colorize(
247
+ ui_win: command_win,
248
+ color: key_w_color,
249
+ style: key_w_style,
250
+ string: command_str_r3_arr[6]
251
+ )
252
+
253
+ # |
254
+ Cryptum::UI.colorize(
255
+ ui_win: command_win,
256
+ color: :white,
257
+ string: command_str_r3_arr[7]
258
+ )
259
+
260
+ # e[x]it
261
+ Cryptum::UI.colorize(
262
+ ui_win: command_win,
263
+ color: key_x_color,
264
+ style: key_x_style,
265
+ string: command_str_r3_arr[8]
266
+ )
267
+
268
+ Cryptum::UI.colorize(
269
+ ui_win: command_win,
270
+ color: :yellow,
271
+ style: key_x_style,
272
+ string: command_str_r3_arr[9]
273
+ )
274
+
275
+ Cryptum::UI.colorize(
276
+ ui_win: command_win,
277
+ color: key_x_color,
278
+ style: key_x_style,
279
+ string: command_str_r3_arr.last
280
+ )
281
+
282
+ # ROW 4
283
+ out_line_no += 1
284
+ Cryptum::UI.line(
285
+ ui_win: command_win,
286
+ out_line_no: out_line_no
287
+ )
288
+
289
+ command_win.refresh
290
+
291
+ sleep 0.15 if key_press_event.key_g ||
292
+ key_press_event.key_r ||
293
+ key_press_event.key_u ||
294
+ key_press_event.key_w ||
295
+ key_press_event.key_x
296
+ rescue Interrupt
297
+ # Exit Gracefully if CTRL+C is Pressed During Session
298
+ Cryptum.exit_gracefully(which_self: self)
299
+ rescue StandardError => e
300
+ raise e
301
+ end
302
+
303
+ # Display Usage for this Module
304
+
305
+ public_class_method def self.help
306
+ puts "USAGE:
307
+ #{self}.refresh(
308
+ command_status: 'required - Instatiated Cryptum::OrderBook::Probabilities Object'
309
+ )
310
+ "
311
+ end
312
+ end
313
+ end
314
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ module UI
5
+ # This Class is Used to Detect Key Press Events
6
+ class KeyPressEvent
7
+ attr_accessor :key_c,
8
+ :key_g,
9
+ :key_r,
10
+ :key_u,
11
+ :key_w,
12
+ :key_x,
13
+ :key_ansi,
14
+ :key_down_arrow,
15
+ :key_end,
16
+ :key_enter,
17
+ :key_esc,
18
+ :key_home,
19
+ :key_page_down,
20
+ :key_page_up,
21
+ :key_tab,
22
+ :key_up_arrow
23
+
24
+ rescue Interrupt
25
+ # Exit Gracefully if CTRL+C is Pressed During Session
26
+ Cryptum.exit_gracefully(which_self: self)
27
+ rescue StandardError => e
28
+ # Produce a Stacktrace for anything else
29
+ Curses.close_screen
30
+ raise e
31
+ end
32
+ end
33
+ end