cryptum 0.0.382 → 0.0.383

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +5 -8
  3. data/lib/cryptum/api/exchange_rates.rb +0 -2
  4. data/lib/cryptum/api/orders.rb +0 -6
  5. data/lib/cryptum/api/portfolio.rb +0 -2
  6. data/lib/cryptum/api/rest.rb +3 -4
  7. data/lib/cryptum/api/signature.rb +0 -4
  8. data/lib/cryptum/api.rb +0 -6
  9. data/lib/cryptum/bot_conf.rb +0 -3
  10. data/lib/cryptum/event/parse.rb +5 -5
  11. data/lib/cryptum/event.rb +0 -2
  12. data/lib/cryptum/log.rb +18 -4
  13. data/lib/cryptum/open_ai.rb +129 -32
  14. data/lib/cryptum/option/environment.rb +0 -2
  15. data/lib/cryptum/option/parser.rb +0 -2
  16. data/lib/cryptum/order_book/generate.rb +0 -4
  17. data/lib/cryptum/order_book.rb +0 -3
  18. data/lib/cryptum/portfolio.rb +0 -2
  19. data/lib/cryptum/ui/command.rb +0 -2
  20. data/lib/cryptum/ui/market_trend.rb +0 -2
  21. data/lib/cryptum/ui/matrix.rb +0 -2
  22. data/lib/cryptum/ui/order/execute.rb +629 -0
  23. data/lib/cryptum/ui/order/execute_details.rb +300 -0
  24. data/lib/cryptum/ui/order/plan.rb +518 -0
  25. data/lib/cryptum/ui/order/plan_details.rb +243 -0
  26. data/lib/cryptum/ui/order/timer.rb +140 -0
  27. data/lib/cryptum/ui/order.rb +21 -0
  28. data/lib/cryptum/ui/portfolio.rb +0 -2
  29. data/lib/cryptum/ui/signal_engine.rb +0 -2
  30. data/lib/cryptum/ui/terminal_window.rb +0 -2
  31. data/lib/cryptum/ui/ticker.rb +0 -2
  32. data/lib/cryptum/ui.rb +1 -8
  33. data/lib/cryptum/version.rb +1 -1
  34. data/lib/cryptum/web_sock/coinbase.rb +0 -5
  35. data/lib/cryptum/web_sock/event_machine.rb +2 -6
  36. data/lib/cryptum.rb +16 -2
  37. data/spec/lib/cryptum/ui/{order_execute_details_spec.rb → order/execute_details_spec.rb} +2 -2
  38. data/spec/lib/cryptum/ui/{order_execution_spec.rb → order/execute_spec.rb} +2 -2
  39. data/spec/lib/cryptum/ui/order/plan_details_spec.rb +10 -0
  40. data/spec/lib/cryptum/ui/{order_timer_spec.rb → order/plan_spec.rb} +2 -2
  41. data/spec/lib/cryptum/ui/{order_plan_details_spec.rb → order/timer_spec.rb} +2 -2
  42. data/spec/lib/cryptum/ui/{order_plan_spec.rb → order_spec.rb} +2 -2
  43. metadata +13 -11
  44. data/lib/cryptum/ui/order_execute_details.rb +0 -300
  45. data/lib/cryptum/ui/order_execution.rb +0 -629
  46. data/lib/cryptum/ui/order_plan.rb +0 -518
  47. data/lib/cryptum/ui/order_plan_details.rb +0 -243
  48. data/lib/cryptum/ui/order_timer.rb +0 -140
@@ -1,243 +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::UI::Exit.gracefully(
226
- which_self: self,
227
- event_history: event_history
228
- )
229
- rescue StandardError => e
230
- raise e
231
- end
232
-
233
- # Display Usage for this Module
234
-
235
- public_class_method def self.help
236
- puts "USAGE:
237
- #{self}.refresh(
238
- )
239
- "
240
- end
241
- end
242
- end
243
- end
@@ -1,140 +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::UI::Exit.gracefully(
122
- which_self: self,
123
- event_history: event_history,
124
- option_choice: option_choice
125
- )
126
- rescue StandardError => e
127
- raise e
128
- end
129
-
130
- # Display Usage for this Module
131
-
132
- public_class_method def self.help
133
- puts "USAGE:
134
- #{self}.refresh(
135
- )
136
- "
137
- end
138
- end
139
- end
140
- end