cryptum 0.0.381 → 0.0.383

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +11 -8
  4. data/Gemfile +1 -2
  5. data/bin/cryptum +2 -2
  6. data/lib/cryptum/api/exchange_rates.rb +0 -2
  7. data/lib/cryptum/api/orders.rb +9 -7
  8. data/lib/cryptum/api/portfolio.rb +0 -2
  9. data/lib/cryptum/api/rest.rb +3 -4
  10. data/lib/cryptum/api/signature.rb +0 -4
  11. data/lib/cryptum/api.rb +1 -40
  12. data/lib/cryptum/bot_conf.rb +14 -6
  13. data/lib/cryptum/event/exit.rb +1 -1
  14. data/lib/cryptum/event/history.rb +4 -1
  15. data/lib/cryptum/event/parse.rb +6 -6
  16. data/lib/cryptum/event.rb +0 -2
  17. data/lib/cryptum/log.rb +18 -4
  18. data/lib/cryptum/open_ai.rb +129 -32
  19. data/lib/cryptum/option/choice.rb +1 -1
  20. data/lib/cryptum/option/environment.rb +0 -2
  21. data/lib/cryptum/option/parser.rb +0 -2
  22. data/lib/cryptum/order_book/generate.rb +3 -8
  23. data/lib/cryptum/order_book.rb +0 -3
  24. data/lib/cryptum/portfolio.rb +0 -2
  25. data/lib/cryptum/ui/command.rb +1 -3
  26. data/lib/cryptum/ui/exit.rb +43 -0
  27. data/lib/cryptum/ui/key_press_event.rb +1 -1
  28. data/lib/cryptum/ui/market_trend.rb +4 -3
  29. data/lib/cryptum/ui/matrix.rb +185 -0
  30. data/lib/cryptum/ui/order/execute.rb +629 -0
  31. data/lib/cryptum/ui/order/execute_details.rb +300 -0
  32. data/lib/cryptum/ui/order/plan.rb +518 -0
  33. data/lib/cryptum/ui/order/plan_details.rb +243 -0
  34. data/lib/cryptum/ui/order/timer.rb +140 -0
  35. data/lib/cryptum/ui/order.rb +21 -0
  36. data/lib/cryptum/ui/portfolio.rb +5 -3
  37. data/lib/cryptum/ui/signal_engine.rb +1 -3
  38. data/lib/cryptum/ui/terminal_window.rb +1 -3
  39. data/lib/cryptum/ui/ticker.rb +4 -3
  40. data/lib/cryptum/ui.rb +17 -22
  41. data/lib/cryptum/version.rb +1 -1
  42. data/lib/cryptum/web_sock/coinbase.rb +1 -6
  43. data/lib/cryptum/web_sock/event_machine.rb +3 -7
  44. data/lib/cryptum.rb +16 -33
  45. data/spec/lib/cryptum/{matrix_spec.rb → ui/exit_spec.rb} +2 -2
  46. data/spec/lib/cryptum/ui/{order_plan_spec.rb → matrix_spec.rb} +2 -2
  47. data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
  48. data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
  49. data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/plan_details_spec.rb} +2 -2
  50. data/spec/lib/cryptum/ui/order/plan_spec.rb +10 -0
  51. data/spec/lib/cryptum/ui/order/timer_spec.rb +10 -0
  52. data/spec/lib/cryptum/ui/{order_timer_spec.rb → order_spec.rb} +2 -2
  53. metadata +20 -30
  54. data/lib/cryptum/matrix.rb +0 -181
  55. data/lib/cryptum/ui/order_execute_details.rb +0 -297
  56. data/lib/cryptum/ui/order_execution.rb +0 -624
  57. data/lib/cryptum/ui/order_plan.rb +0 -514
  58. data/lib/cryptum/ui/order_plan_details.rb +0 -240
  59. data/lib/cryptum/ui/order_timer.rb +0 -136
@@ -1,240 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'logger'
4
-
5
- module Cryptum
6
- module UI
7
- # This plugin is used to Display Order Plan Details
8
- # selected from the Order Plan Window Pane.
9
- module OrderPlanDetails
10
- # Supported Method Parameters::
11
- # Cryptum::UI::OrderPlanDetails.refresh(
12
- # )
13
-
14
- public_class_method def self.refresh(opts = {})
15
- event_history = opts[:event_history]
16
- order_plan_details_win = opts[:order_plan_details_win]
17
-
18
- order = event_history.order_plan_selected_data
19
- tpm = order[:tpm]
20
- autotrade_percent = order[:autotrade_percent]
21
- order_color = order[:color]
22
-
23
- fiat_avail_out = Cryptum.beautify_large_number(
24
- value: order[:fiat_available]
25
- )
26
- risk_alloc_out = Cryptum.beautify_large_number(
27
- value: order[:risk_alloc]
28
- )
29
- slice_alloc_out = Cryptum.beautify_large_number(
30
- value: order[:slice_alloc]
31
- )
32
- previous_slice_invest_out = Cryptum.beautify_large_number(
33
- value: order[:previous_slice_invest]
34
- )
35
- invest_out = Cryptum.beautify_large_number(
36
- value: order[:invest]
37
- )
38
- profit_out = Cryptum.beautify_large_number(
39
- value: order[:profit]
40
- )
41
- tpm_out = format('%0.2f', tpm)
42
- return_out = Cryptum.beautify_large_number(
43
- value: order[:return]
44
- )
45
- autotrade_ln1_details = "1. Autotrade is set to #{autotrade_percent}% of $#{fiat_avail_out}, making $#{risk_alloc_out} available for this slice in"
46
- autotrade_ln2_details = ' the order plan.'
47
- if order[:last_slice]
48
- slice_alloc_ln1_details = "2. Since $#{risk_alloc_out} is the remaining amount within the criteria defined in the Autotrade % above,"
49
- slice_alloc_ln2_details = " $#{invest_out} will be allocated for this slice."
50
- else
51
- slice_alloc_ln1_details = "2. With $#{risk_alloc_out} available and a slice allocation of #{order[:allocation_percent]}%, $#{slice_alloc_out} plus the previous"
52
- slice_alloc_ln2_details = " slice of $#{previous_slice_invest_out} results in $#{invest_out} being allocated for this slice."
53
- end
54
- profit_ln1_details = "3. With a slice allocation of $#{invest_out}, plus a TPM equal to #{tpm_out}%, $#{return_out} will be returned"
55
- profit_ln2_details = " once sold. With $#{invest_out} invested, the gross profit equals $#{profit_out}, minus any Maker &"
56
- profit_ln3_details = ' Taker (transaction) fees.'
57
-
58
- # UI
59
- col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
60
-
61
- # ROW 1
62
- out_line_no = 0
63
- line_color = order_color
64
- header_color = order_color
65
- header_style = :bold
66
- style = :bold
67
- header_style = :reverse if event_history.order_plan_details_win_active
68
-
69
- Cryptum::UI.line(
70
- ui_win: order_plan_details_win,
71
- out_line_no: out_line_no,
72
- color: line_color
73
- )
74
-
75
- # ROW 2
76
- out_line_no += 1
77
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
78
- order_plan_details_win.clrtoeol
79
- Cryptum::UI.colorize(
80
- ui_win: order_plan_details_win,
81
- color: header_color,
82
- style: header_style,
83
- string: ''.ljust(col_just1, ' ')
84
- )
85
-
86
- header_str = "- ORDER SLICE ##{order[:plan_no]} DETAILS -"
87
- order_plan_details_win.setpos(
88
- out_line_no,
89
- Cryptum::UI.col_center(str: header_str)
90
- )
91
-
92
- Cryptum::UI.colorize(
93
- ui_win: order_plan_details_win,
94
- color: order_color,
95
- style: header_style,
96
- string: header_str
97
- )
98
-
99
- # ROW 3
100
- out_line_no += 1
101
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
102
- order_plan_details_win.clrtoeol
103
-
104
- Cryptum::UI.colorize(
105
- ui_win: order_plan_details_win,
106
- color: order_color,
107
- style: style,
108
- string: autotrade_ln1_details.ljust(col_just1, ' ')
109
- )
110
-
111
- # ROW 4
112
- out_line_no += 1
113
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
114
- order_plan_details_win.clrtoeol
115
-
116
- Cryptum::UI.colorize(
117
- ui_win: order_plan_details_win,
118
- color: order_color,
119
- style: style,
120
- string: autotrade_ln2_details.ljust(col_just1, ' ')
121
- )
122
-
123
- # ROW 5
124
- out_line_no += 1
125
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
126
- order_plan_details_win.clrtoeol
127
-
128
- Cryptum::UI.colorize(
129
- ui_win: order_plan_details_win,
130
- color: order_color,
131
- style: style,
132
- string: slice_alloc_ln1_details.ljust(col_just1, ' ')
133
- )
134
-
135
- # ROW 6
136
- out_line_no += 1
137
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
138
- order_plan_details_win.clrtoeol
139
-
140
- Cryptum::UI.colorize(
141
- ui_win: order_plan_details_win,
142
- color: order_color,
143
- style: style,
144
- string: slice_alloc_ln2_details.ljust(col_just1, ' ')
145
- )
146
-
147
- # ROW 7
148
- out_line_no += 1
149
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
150
- order_plan_details_win.clrtoeol
151
-
152
- Cryptum::UI.colorize(
153
- ui_win: order_plan_details_win,
154
- color: order_color,
155
- style: style,
156
- string: profit_ln1_details.ljust(col_just1, ' ')
157
- )
158
-
159
- # ROW 8
160
- out_line_no += 1
161
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
162
- order_plan_details_win.clrtoeol
163
-
164
- Cryptum::UI.colorize(
165
- ui_win: order_plan_details_win,
166
- color: order_color,
167
- style: style,
168
- string: profit_ln2_details.ljust(col_just1, ' ')
169
- )
170
-
171
- # ROW 9
172
- out_line_no += 1
173
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
174
- order_plan_details_win.clrtoeol
175
-
176
- Cryptum::UI.colorize(
177
- ui_win: order_plan_details_win,
178
- color: order_color,
179
- style: style,
180
- string: profit_ln3_details.ljust(col_just1, ' ')
181
- )
182
-
183
- # Clear to OK ROW
184
- ok_row = 9
185
- out_line_no += 1
186
- to_ok_row = ok_row - 1
187
- (out_line_no..to_ok_row).each do |clr_line|
188
- order_plan_details_win.setpos(clr_line, Cryptum::UI.col_first)
189
- Cryptum::UI.colorize(
190
- ui_win: order_plan_details_win,
191
- color: order_color,
192
- style: :normal,
193
- string: ''.ljust(col_just1, ' ')
194
- )
195
- end
196
-
197
- # OK ROW
198
- out_line_no = ok_row
199
- order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first)
200
- order_plan_details_win.clrtoeol
201
- Cryptum::UI.colorize(
202
- ui_win: order_plan_details_win,
203
- color: order_color,
204
- string: ''.ljust(col_just1, ' ')
205
- )
206
-
207
- header_str = '- OK -'
208
- order_plan_details_win.setpos(
209
- out_line_no,
210
- Cryptum::UI.col_center(str: header_str)
211
- )
212
-
213
- Cryptum::UI.colorize(
214
- ui_win: order_plan_details_win,
215
- color: order_color,
216
- style: :reverse,
217
- string: header_str
218
- )
219
-
220
- order_plan_details_win.refresh
221
-
222
- event_history
223
- rescue Interrupt
224
- # Exit Gracefully if CTRL+C is Pressed During Session
225
- Cryptum.exit_gracefully(which_self: self)
226
- rescue StandardError => e
227
- raise e
228
- end
229
-
230
- # Display Usage for this Module
231
-
232
- public_class_method def self.help
233
- puts "USAGE:
234
- #{self}.refresh(
235
- )
236
- "
237
- end
238
- end
239
- end
240
- end
@@ -1,136 +0,0 @@
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 Status Section UI
8
- module OrderTimer
9
- # Supported Method Parameters::
10
- # Cryptum::UI::Timer.refresh(
11
- # )
12
-
13
- public_class_method def self.refresh(opts = {})
14
- option_choice = opts[:option_choice]
15
- event_history = opts[:event_history]
16
- order_timer_win = opts[:order_timer_win]
17
- indicator_status = opts[:indicator_status]
18
-
19
- last_trend_reset_time = event_history.order_book[:last_trend_reset]
20
- last_order_exec_time = event_history.order_book[:last_order_exec]
21
-
22
- # Market Trend Reset Timer
23
- time_between_trend_reset = option_choice.market_trend_reset
24
- trend_timer_begin = Time.parse(last_trend_reset_time)
25
- trend_timer_end = trend_timer_begin + time_between_trend_reset
26
- trend_time_remaining = trend_timer_end - Time.now
27
-
28
- if trend_time_remaining.zero? || trend_time_remaining.negative?
29
- event_history.order_book[:market_trend][:buy] = 0
30
- event_history.order_book[:market_trend][:sell] = 0
31
- event_history.order_book[:last_trend_reset] = Time.now.strftime(
32
- '%Y-%m-%d %H:%M:%S.%N%z'
33
- )
34
-
35
- last_trend_reset_time = event_history.order_book[:last_trend_reset]
36
- time_between_trend_reset = option_choice.market_trend_reset
37
- trend_timer_begin = Time.parse(last_trend_reset_time)
38
- trend_timer_end = trend_timer_begin + time_between_trend_reset
39
- trend_time_remaining = trend_timer_end - Time.now
40
- end
41
-
42
- trend_countdown = Cryptum.beautify_large_number(
43
- value: format('%0.2f', trend_time_remaining)
44
- )
45
-
46
- # Market Trend Reset Timer
47
- time_between_order_exec = event_history.time_between_orders
48
- time_between_order_exec_out = Cryptum.beautify_large_number(
49
- value: format('%0.2f', time_between_order_exec)
50
- )
51
- order_begin_time = Time.parse(last_order_exec_time)
52
- order_end_time = order_begin_time + time_between_order_exec
53
- order_exec_time_remaining = order_end_time - Time.now
54
- order_countdown = Cryptum.beautify_large_number(
55
- value: format('%0.2f', order_exec_time_remaining)
56
- )
57
-
58
- buy_total = event_history.order_book[:market_trend][:buy].to_i
59
- sell_total = event_history.order_book[:market_trend][:sell].to_i
60
-
61
- color = :white
62
- color = indicator_status.market_trend[:color] if indicator_status.market_trend
63
- case color
64
- when :green
65
- # TODO: add condition to check if open sell orders exist.
66
- # If so intent should be something like, "- SEE ORDER HISTORY -"
67
- # Otherwise, intent should be something like, "- WAIT FOR MARKET TREND SHIFT -"
68
- intent = "- #{Cryptum.down_arrow} SEE ORDER HISTORY #{Cryptum.down_arrow} -"
69
- else
70
- speed = 'FAST'
71
- speed = 'SLOW' if buy_total >= sell_total
72
-
73
- intent = "- #{speed} BUY: #{order_countdown} of #{time_between_order_exec_out} -"
74
- intent = '- BUYING PAUSED -' if event_history.red_pill
75
- end
76
-
77
- # Have a Clock
78
- clock = Time.now.strftime('%Y-%m-%d %H:%M:%S%z')
79
-
80
- # UI
81
- col_just4 = (Curses.cols - Cryptum::UI.col_fourth) - 1
82
-
83
- # ROW 1
84
- # COLUMN 1
85
- out_line_no = 0
86
- order_timer_win.setpos(out_line_no, Cryptum::UI.col_first)
87
- order_timer_win.clrtoeol
88
- Cryptum::UI.colorize(
89
- ui_win: order_timer_win,
90
- color: :white,
91
- style: :bold,
92
- string: "#{option_choice.market_trend_reset_label} M. Trend Rst: #{trend_countdown}"
93
- )
94
-
95
- # COLUMN 2
96
- order_timer_win.setpos(
97
- out_line_no,
98
- Cryptum::UI.col_center(str: intent)
99
- )
100
- Cryptum::UI.colorize(
101
- ui_win: order_timer_win,
102
- color: :white,
103
- style: :bold,
104
- string: intent
105
- )
106
-
107
- # COLUMN 3
108
- order_timer_win.setpos(out_line_no, Cryptum::UI.col_fourth)
109
- Cryptum::UI.colorize(
110
- ui_win: order_timer_win,
111
- color: :white,
112
- style: :bold,
113
- string: clock.rjust(col_just4)
114
- )
115
-
116
- order_timer_win.refresh
117
-
118
- order_countdown.to_f
119
- rescue Interrupt
120
- # Exit Gracefully if CTRL+C is Pressed During Session
121
- Cryptum.exit_gracefully(which_self: self)
122
- rescue StandardError => e
123
- raise e
124
- end
125
-
126
- # Display Usage for this Module
127
-
128
- public_class_method def self.help
129
- puts "USAGE:
130
- #{self}.refresh(
131
- )
132
- "
133
- end
134
- end
135
- end
136
- end