cryptum 0.0.230

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  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 +5 -0
  7. data/.rubocop_todo.yml +250 -0
  8. data/.ruby-gemset +1 -0
  9. data/.ruby-version +1 -0
  10. data/CODE_OF_CONDUCT.md +84 -0
  11. data/Gemfile +36 -0
  12. data/LICENSE +674 -0
  13. data/README.md +72 -0
  14. data/Rakefile +19 -0
  15. data/bin/cryptum +72 -0
  16. data/bin/cryptum-forecast +199 -0
  17. data/bin/cryptum-repl +73 -0
  18. data/bin/cryptum_autoinc_version +38 -0
  19. data/build_cryptum_gem.sh +52 -0
  20. data/cryptum.gemspec +50 -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/git_commit.sh +22 -0
  36. data/lib/cryptum/api.rb +693 -0
  37. data/lib/cryptum/bot_conf.rb +76 -0
  38. data/lib/cryptum/event/buy.rb +144 -0
  39. data/lib/cryptum/event/cancel.rb +49 -0
  40. data/lib/cryptum/event/history.rb +64 -0
  41. data/lib/cryptum/event/key_press.rb +64 -0
  42. data/lib/cryptum/event/sell.rb +120 -0
  43. data/lib/cryptum/event.rb +168 -0
  44. data/lib/cryptum/log.rb +34 -0
  45. data/lib/cryptum/matrix.rb +181 -0
  46. data/lib/cryptum/option/choice.rb +26 -0
  47. data/lib/cryptum/option.rb +161 -0
  48. data/lib/cryptum/order_book/generate.rb +111 -0
  49. data/lib/cryptum/order_book/indicator.rb +16 -0
  50. data/lib/cryptum/order_book/market_trend.rb +161 -0
  51. data/lib/cryptum/order_book/profit_margin.rb +55 -0
  52. data/lib/cryptum/order_book/weighted_avg.rb +157 -0
  53. data/lib/cryptum/order_book.rb +156 -0
  54. data/lib/cryptum/portfolio/balance.rb +123 -0
  55. data/lib/cryptum/portfolio.rb +15 -0
  56. data/lib/cryptum/ui/command.rb +274 -0
  57. data/lib/cryptum/ui/key_press_event.rb +22 -0
  58. data/lib/cryptum/ui/market_trend.rb +117 -0
  59. data/lib/cryptum/ui/order_execution.rb +478 -0
  60. data/lib/cryptum/ui/order_plan.rb +376 -0
  61. data/lib/cryptum/ui/order_timer.rb +119 -0
  62. data/lib/cryptum/ui/portfolio.rb +231 -0
  63. data/lib/cryptum/ui/signal_engine.rb +122 -0
  64. data/lib/cryptum/ui/terminal_window.rb +95 -0
  65. data/lib/cryptum/ui/ticker.rb +317 -0
  66. data/lib/cryptum/ui.rb +306 -0
  67. data/lib/cryptum/version.rb +5 -0
  68. data/lib/cryptum/web_sock/coinbase.rb +94 -0
  69. data/lib/cryptum/web_sock/event_machine.rb +182 -0
  70. data/lib/cryptum/web_sock.rb +16 -0
  71. data/lib/cryptum.rb +183 -0
  72. data/order_books/.gitkeep +0 -0
  73. data/reinstall_cryptum_gemset.sh +29 -0
  74. data/spec/lib/cryptum/api_spec.rb +10 -0
  75. data/spec/lib/cryptum/event_spec.rb +10 -0
  76. data/spec/lib/cryptum/log_spec.rb +10 -0
  77. data/spec/lib/cryptum/option_spec.rb +10 -0
  78. data/spec/lib/cryptum/order_book/generate_spec.rb +10 -0
  79. data/spec/lib/cryptum/order_book/market_trend_spec.rb +10 -0
  80. data/spec/lib/cryptum/order_book_spec.rb +10 -0
  81. data/spec/lib/cryptum/ui/command_spec.rb +10 -0
  82. data/spec/lib/cryptum/ui/ticker_spec.rb +10 -0
  83. data/spec/lib/cryptum/ui_spec.rb +10 -0
  84. data/spec/lib/cryptum/web_sock_spec.rb +10 -0
  85. data/spec/lib/cryptum_spec.rb +10 -0
  86. data/spec/spec_helper.rb +3 -0
  87. data/upgrade_Gemfile_gems.sh +20 -0
  88. data/upgrade_cryptum.sh +13 -0
  89. data/upgrade_gem.sh +4 -0
  90. data/upgrade_ruby.sh +46 -0
  91. metadata +472 -0
@@ -0,0 +1,274 @@
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_g
23
+ key_g_color = :cyan
24
+ key_g_style = :reverse
25
+ else
26
+ key_g_color = :white
27
+ key_g_style = :bold
28
+ end
29
+
30
+ if key_press_event.key_r
31
+ key_r_color = :cyan
32
+ key_r_style = :reverse
33
+ else
34
+ key_r_color = :white
35
+ key_r_style = :bold
36
+ end
37
+
38
+ if key_press_event.key_u
39
+ key_u_color = :cyan
40
+ key_u_style = :reverse
41
+ else
42
+ key_u_color = :white
43
+ key_u_style = :bold
44
+ end
45
+
46
+ if key_press_event.key_w
47
+ key_w_color = :cyan
48
+ key_w_style = :reverse
49
+ else
50
+ key_w_color = :white
51
+ key_w_style = :bold
52
+ end
53
+
54
+ if key_press_event.key_x
55
+ key_x_color = :cyan
56
+ key_x_style = :reverse
57
+ else
58
+ key_x_color = :white
59
+ key_x_style = :bold
60
+ end
61
+
62
+ command_str_r2_arr = [
63
+ "* v#{Cryptum::VERSION} >>> ",
64
+ '[',
65
+ 'G',
66
+ ']TFO',
67
+ ' | ',
68
+ '[',
69
+ 'r',
70
+ ']eload bot conf',
71
+ ' | ',
72
+ '[',
73
+ 'u',
74
+ ']pdate summary'
75
+ ]
76
+
77
+ command_str_r3_arr = [
78
+ '[',
79
+ 'w',
80
+ ']rite order book',
81
+ ' | ',
82
+ 'e[',
83
+ 'x',
84
+ ']it'
85
+ ]
86
+ # ROW 1
87
+ out_line_no = 0
88
+ Cryptum::UI.line(
89
+ ui_win: command_win,
90
+ out_line_no: out_line_no
91
+ )
92
+
93
+ # ROW 2
94
+ out_line_no += 1
95
+ command_win.setpos(
96
+ out_line_no,
97
+ Cryptum::UI.col_center(str: command_str_r2_arr.join(''))
98
+ )
99
+ command_win.clrtoeol
100
+
101
+ Cryptum::UI.colorize(
102
+ ui_win: command_win,
103
+ color: :yellow,
104
+ style: :bold,
105
+ string: command_str_r2_arr.first
106
+ )
107
+
108
+ Cryptum::UI.colorize(
109
+ ui_win: command_win,
110
+ color: key_g_color,
111
+ style: key_g_style,
112
+ string: command_str_r2_arr[1]
113
+ )
114
+
115
+ Cryptum::UI.colorize(
116
+ ui_win: command_win,
117
+ color: :yellow,
118
+ style: key_g_style,
119
+ string: command_str_r2_arr[2]
120
+ )
121
+
122
+ Cryptum::UI.colorize(
123
+ ui_win: command_win,
124
+ color: key_g_color,
125
+ style: key_g_style,
126
+ string: command_str_r2_arr[3]
127
+ )
128
+
129
+ # |
130
+ Cryptum::UI.colorize(
131
+ ui_win: command_win,
132
+ color: :white,
133
+ string: command_str_r2_arr[4]
134
+ )
135
+
136
+ Cryptum::UI.colorize(
137
+ ui_win: command_win,
138
+ color: key_r_color,
139
+ style: key_r_style,
140
+ string: command_str_r2_arr[5]
141
+ )
142
+
143
+ Cryptum::UI.colorize(
144
+ ui_win: command_win,
145
+ color: :yellow,
146
+ style: key_r_style,
147
+ string: command_str_r2_arr[6]
148
+ )
149
+
150
+ Cryptum::UI.colorize(
151
+ ui_win: command_win,
152
+ color: key_r_color,
153
+ style: key_r_style,
154
+ string: command_str_r2_arr[7]
155
+ )
156
+
157
+ # |
158
+ Cryptum::UI.colorize(
159
+ ui_win: command_win,
160
+ color: :white,
161
+ string: command_str_r2_arr[8]
162
+ )
163
+
164
+ Cryptum::UI.colorize(
165
+ ui_win: command_win,
166
+ color: key_u_color,
167
+ style: key_u_style,
168
+ string: command_str_r2_arr[9]
169
+ )
170
+
171
+ Cryptum::UI.colorize(
172
+ ui_win: command_win,
173
+ color: :yellow,
174
+ style: key_u_style,
175
+ string: command_str_r2_arr[10]
176
+ )
177
+
178
+ Cryptum::UI.colorize(
179
+ ui_win: command_win,
180
+ color: key_u_color,
181
+ style: key_u_style,
182
+ string: command_str_r2_arr[11]
183
+ )
184
+
185
+ # ROW 3
186
+ out_line_no += 1
187
+ command_win.setpos(
188
+ out_line_no,
189
+ Cryptum::UI.col_center(str: command_str_r3_arr.join(''))
190
+ )
191
+ command_win.clrtoeol
192
+
193
+ Cryptum::UI.colorize(
194
+ ui_win: command_win,
195
+ color: key_w_color,
196
+ style: key_w_style,
197
+ string: command_str_r3_arr.first
198
+ )
199
+
200
+ Cryptum::UI.colorize(
201
+ ui_win: command_win,
202
+ color: :yellow,
203
+ style: key_w_style,
204
+ string: command_str_r3_arr[1]
205
+ )
206
+
207
+ Cryptum::UI.colorize(
208
+ ui_win: command_win,
209
+ color: key_w_color,
210
+ style: key_w_style,
211
+ string: command_str_r3_arr[2]
212
+ )
213
+
214
+ # |
215
+ Cryptum::UI.colorize(
216
+ ui_win: command_win,
217
+ color: :white,
218
+ string: command_str_r3_arr[3]
219
+ )
220
+
221
+ Cryptum::UI.colorize(
222
+ ui_win: command_win,
223
+ color: key_x_color,
224
+ style: key_x_style,
225
+ string: command_str_r3_arr[4]
226
+ )
227
+
228
+ Cryptum::UI.colorize(
229
+ ui_win: command_win,
230
+ color: :yellow,
231
+ style: key_x_style,
232
+ string: command_str_r3_arr[5]
233
+ )
234
+
235
+ Cryptum::UI.colorize(
236
+ ui_win: command_win,
237
+ color: key_x_color,
238
+ style: key_x_style,
239
+ string: command_str_r3_arr.last
240
+ )
241
+
242
+ # ROW 4
243
+ out_line_no += 1
244
+ Cryptum::UI.line(
245
+ ui_win: command_win,
246
+ out_line_no: out_line_no
247
+ )
248
+
249
+ command_win.refresh
250
+
251
+ sleep 0.15 if key_press_event.key_g ||
252
+ key_press_event.key_r ||
253
+ key_press_event.key_u ||
254
+ key_press_event.key_w ||
255
+ key_press_event.key_x
256
+ rescue Interrupt
257
+ # Exit Gracefully if CTRL+C is Pressed During Session
258
+ Cryptum.exit_gracefully(which_self: self)
259
+ rescue StandardError => e
260
+ raise e
261
+ end
262
+
263
+ # Display Usage for this Module
264
+
265
+ public_class_method def self.help
266
+ puts "USAGE:
267
+ #{self}.refresh(
268
+ command_status: 'required - Instatiated Cryptum::OrderBook::Probabilities Object'
269
+ )
270
+ "
271
+ end
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,22 @@
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_g,
8
+ :key_r,
9
+ :key_u,
10
+ :key_w,
11
+ :key_x
12
+
13
+ rescue Interrupt
14
+ # Exit Gracefully if CTRL+C is Pressed During Session
15
+ Cryptum.exit_gracefully(which_self: self)
16
+ rescue StandardError => e
17
+ # Produce a Stacktrace for anything else
18
+ Curses.close_screen
19
+ raise e
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Cryptum
6
+ # This plugin is used to Refresh the Cryptum console UI
7
+ module UI
8
+ module MarketTrend
9
+ # Supported Method Parameters::
10
+ # Cryptum::UI::Candle.refresh(
11
+ # order_book: 'required - Order Book Data Structure',
12
+ # event: 'required - Event from Coinbase Web Socket'
13
+ # )
14
+
15
+ public_class_method def self.refresh(opts = {})
16
+ option_choice = opts[:option_choice]
17
+ market_trend_win = opts[:market_trend_win]
18
+ event_history = opts[:event_history]
19
+ key_press_event = opts[:key_press_event]
20
+ event = opts[:event]
21
+ indicator_status = opts[:indicator_status]
22
+ bot_conf = opts[:bot_conf]
23
+ reset_counter = opts[:reset_counter]
24
+
25
+ indicator_hash = Cryptum::OrderBook::MarketTrend.status(
26
+ event_history: event_history,
27
+ event: event,
28
+ indicator_status: indicator_status
29
+ )
30
+
31
+ color = indicator_hash[:color]
32
+ order_trend_out = indicator_hash[:ui]
33
+
34
+ case color
35
+ when :green
36
+ order_trend_color = :green
37
+ trend_arrow = Cryptum.up_arrow
38
+ when :yellow
39
+ order_trend_color = :yellow
40
+ trend_arrow = Cryptum.flat_arrow
41
+ when :red
42
+ order_trend_color = :red
43
+ trend_arrow = Cryptum.down_arrow
44
+ end
45
+
46
+ market_trend_out = "Market Trend #{trend_arrow} | #{order_trend_out}"
47
+
48
+ # UI
49
+ # col_just1 = 12
50
+ col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
51
+ col_just2 = 14
52
+ col_just3 = 21
53
+ col_just3_alt = (Curses.cols - Cryptum::UI.col_third) - 1
54
+ col_just4 = Curses.cols - Cryptum::UI.col_fourth
55
+
56
+ Cryptum::UI.detect_key_press_in_ui(
57
+ key_press_event: key_press_event,
58
+ ui_win: market_trend_win
59
+ )
60
+
61
+ # ROW 1
62
+ out_line_no = 0
63
+ Cryptum::UI.line(
64
+ ui_win: market_trend_win,
65
+ out_line_no: out_line_no
66
+ )
67
+
68
+ # ROW 2
69
+ out_line_no += 1
70
+ market_trend_win.setpos(out_line_no, Cryptum::UI.col_first)
71
+ market_trend_win.clrtoeol
72
+
73
+ Cryptum::UI.colorize(
74
+ ui_win: market_trend_win,
75
+ color: order_trend_color,
76
+ string: ''.ljust(col_just1, ' ')
77
+ )
78
+
79
+ market_trend_win.setpos(
80
+ out_line_no,
81
+ Cryptum::UI.col_center(str: market_trend_out)
82
+ )
83
+ Cryptum::UI.colorize(
84
+ ui_win: market_trend_win,
85
+ color: order_trend_color,
86
+ style: :bold,
87
+ string: market_trend_out
88
+ )
89
+
90
+ market_trend_win.setpos(out_line_no, Cryptum::UI.col_fourth)
91
+ Cryptum::UI.colorize(
92
+ ui_win: market_trend_win,
93
+ color: order_trend_color,
94
+ string: ''.ljust(col_just4, ' ')
95
+ )
96
+
97
+ market_trend_win.refresh
98
+ rescue Interrupt
99
+ # Exit Gracefully if CTRL+C is Pressed During Session
100
+ Cryptum.exit_gracefully(which_self: self)
101
+ rescue StandardError => e
102
+ raise e
103
+ end
104
+
105
+ # Display Usage for this Module
106
+
107
+ public_class_method def self.help
108
+ puts "USAGE:
109
+ #{self}.refresh(
110
+ order_book: 'required - Order Book Data Structure',
111
+ event: 'required - Event from Coinbase Web Socket'
112
+ )
113
+ "
114
+ end
115
+ end
116
+ end
117
+ end