cryptum 0.0.381 → 0.0.383

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,300 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ module UI
5
+ # This plugin is used to Display Order Execute Details
6
+ # selected from the Order Execute Window Pane.
7
+ module Order
8
+ module ExecuteDetails
9
+ # Supported Method Parameters::
10
+ # Cryptum::UI::Order::ExecuteDetails.refresh(
11
+ # )
12
+
13
+ public_class_method def self.refresh(opts = {})
14
+ event_history = opts[:event_history]
15
+ order_execute_details_win = opts[:order_execute_details_win]
16
+
17
+ order_meta_data = event_history.order_execute_selected_data
18
+
19
+ order_color = order_meta_data[:color].to_sym
20
+ case order_color
21
+ when :cyan, :red
22
+ order_id = order_meta_data[:buy_order_id]
23
+ when :green, :magenta, :yellow
24
+ order_id = order_meta_data[:sell_order_id]
25
+ when :white
26
+ order_id = 'Expired'
27
+ else
28
+ order_id = 'N/A'
29
+ end
30
+
31
+ order_id_details = "- ID: #{order_id}"
32
+
33
+ order_history_arr = event_history.order_book[:order_history].select do |order|
34
+ order if order[:id] == order_id
35
+ end
36
+
37
+ if order_history_arr.empty? && order_color == :yellow
38
+ order_meta_data.delete(:sell_order_id)
39
+ order_id = order_meta_data[:buy_order_id]
40
+ order_meta_data[:color] = :cyan
41
+ order_history_arr = event_history.order_book[:order_history].select do |order|
42
+ order if order[:id] == order_id
43
+ end
44
+ end
45
+
46
+ order_type_ln = '- Type: N/A'
47
+ order_status_ln = '- Status: N/A'
48
+ fill_fees = 'N/A'
49
+ fill_size = 'N/A'
50
+ executed_value = 'N/A'
51
+ market_type = 'N/A'
52
+ settled = 'N/A'
53
+ unless order_history_arr.empty?
54
+ order_history = order_history_arr.first
55
+ order_type = order_history[:type].capitalize
56
+ time_in_force = order_history[:time_in_force].upcase
57
+ order_status = order_history[:status].upcase
58
+ created_at = order_history[:created_at]
59
+ fill_fees = order_history[:fill_fees]
60
+ fill_size = order_history[:filled_size]
61
+ executed_value = order_history[:executed_value]
62
+ market_type = order_history[:market_type]
63
+ settled = order_history[:settled]
64
+
65
+ order_side = order_history[:side].capitalize
66
+ case order_side.to_sym
67
+ when :Buy
68
+ expire_time = order_history[:expire_time]
69
+ done_at = order_history[:done_at]
70
+ order_meta_data[:color] = :cyan if done_at
71
+ when :Sell
72
+ done_at = order_history[:done_at]
73
+ end
74
+
75
+ order_type_ln = "- Type: #{order_type} #{order_side} #{time_in_force}"
76
+ order_type_ln = "- Type: #{order_type} #{order_side} #{time_in_force} 1m" if time_in_force == 'GTT'
77
+ order_status_ln = "- Status: #{order_status}"
78
+ end
79
+
80
+ if created_at && (!expire_time || !done_at)
81
+ order_hist_created_finished_ln = "- Creation Date: #{created_at} | Finished Date: N/A"
82
+ elsif created_at && expire_time && !done_at
83
+ order_hist_created_finished_ln = "- Creation Date: #{created_at} | Expiring Date: #{expire_time}"
84
+ elsif created_at && done_at
85
+ order_hist_created_finished_ln = "- Creation Date: #{created_at} | Finished Date: #{done_at}"
86
+ else
87
+ order_hist_created_finished_ln = '- Creation Date: N/A | Finished Date: N/A'
88
+ end
89
+
90
+ invest_out = Cryptum.beautify_large_number(
91
+ value: order_meta_data[:invest]
92
+ )
93
+ price_out = Cryptum.beautify_large_number(
94
+ value: order_meta_data[:price]
95
+ )
96
+ size_out = Cryptum.beautify_large_number(
97
+ value: order_meta_data[:size]
98
+ )
99
+ target_price_out = Cryptum.beautify_large_number(
100
+ value: order_meta_data[:target_price]
101
+ )
102
+
103
+ invest = "$#{invest_out} @ "
104
+ tick = "$#{price_out} = "
105
+ size = "*#{size_out} + "
106
+ tpm_out = "#{order_meta_data[:tpm]}% = "
107
+ targ_tick = "$#{target_price_out}"
108
+ profit = " | Profit: $#{order_meta_data[:profit]}"
109
+
110
+ details_ln1 = "- Slice Plan: #{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}"
111
+ details_ln2 = "- Fees: $#{fill_fees} | Fill Size: *#{fill_size}"
112
+ details_ln3 = "- Executed Value: $#{executed_value} | Market Type: #{market_type} | Settled: #{settled}"
113
+
114
+ # UI
115
+ col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
116
+
117
+ # ROW 1
118
+ out_line_no = 0
119
+ line_color = order_color
120
+ header_color = order_color
121
+ header_style = :bold
122
+ style = :bold
123
+ header_style = :reverse if event_history.order_execute_details_win_active
124
+
125
+ Cryptum::UI.line(
126
+ ui_win: order_execute_details_win,
127
+ out_line_no: out_line_no,
128
+ color: line_color
129
+ )
130
+
131
+ # ROW 2
132
+ out_line_no += 1
133
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
134
+ order_execute_details_win.clrtoeol
135
+ Cryptum::UI.colorize(
136
+ ui_win: order_execute_details_win,
137
+ color: header_color,
138
+ style: header_style,
139
+ string: ''.ljust(col_just1, ' ')
140
+ )
141
+
142
+ header_str = "- ORDER ##{order_meta_data[:plan_no]} DETAILS -"
143
+ order_execute_details_win.setpos(
144
+ out_line_no,
145
+ Cryptum::UI.col_center(str: header_str)
146
+ )
147
+
148
+ Cryptum::UI.colorize(
149
+ ui_win: order_execute_details_win,
150
+ color: order_color,
151
+ style: header_style,
152
+ string: header_str
153
+ )
154
+
155
+ # ROW 3
156
+ out_line_no += 1
157
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
158
+ order_execute_details_win.clrtoeol
159
+
160
+ Cryptum::UI.colorize(
161
+ ui_win: order_execute_details_win,
162
+ color: order_color,
163
+ style: style,
164
+ string: order_id_details.ljust(col_just1, ' ')
165
+ )
166
+
167
+ # ROW 4
168
+ out_line_no += 1
169
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
170
+ order_execute_details_win.clrtoeol
171
+
172
+ Cryptum::UI.colorize(
173
+ ui_win: order_execute_details_win,
174
+ color: order_color,
175
+ style: style,
176
+ string: order_type_ln.ljust(col_just1, ' ')
177
+ )
178
+
179
+ # ROW 5
180
+ out_line_no += 1
181
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
182
+ order_execute_details_win.clrtoeol
183
+
184
+ Cryptum::UI.colorize(
185
+ ui_win: order_execute_details_win,
186
+ color: order_color,
187
+ style: style,
188
+ string: order_status_ln.ljust(col_just1, ' ')
189
+ )
190
+
191
+ # ROW 6
192
+ out_line_no += 1
193
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
194
+ order_execute_details_win.clrtoeol
195
+
196
+ Cryptum::UI.colorize(
197
+ ui_win: order_execute_details_win,
198
+ color: order_color,
199
+ style: style,
200
+ string: order_hist_created_finished_ln.ljust(col_just1, ' ')
201
+ )
202
+
203
+ # ROW 7
204
+ out_line_no += 1
205
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
206
+ order_execute_details_win.clrtoeol
207
+
208
+ Cryptum::UI.colorize(
209
+ ui_win: order_execute_details_win,
210
+ color: order_color,
211
+ style: style,
212
+ string: details_ln1.ljust(col_just1, ' ')
213
+ )
214
+
215
+ # ROW 8
216
+ out_line_no += 1
217
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
218
+ order_execute_details_win.clrtoeol
219
+
220
+ Cryptum::UI.colorize(
221
+ ui_win: order_execute_details_win,
222
+ color: order_color,
223
+ style: style,
224
+ string: details_ln2.ljust(col_just1, ' ')
225
+ )
226
+
227
+ # ROW 9
228
+ out_line_no += 1
229
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
230
+ order_execute_details_win.clrtoeol
231
+
232
+ Cryptum::UI.colorize(
233
+ ui_win: order_execute_details_win,
234
+ color: order_color,
235
+ style: style,
236
+ string: details_ln3.ljust(col_just1, ' ')
237
+ )
238
+
239
+ # Clear to OK ROW
240
+ ok_row = 9
241
+ out_line_no += 1
242
+ to_ok_row = ok_row - 1
243
+ (out_line_no..to_ok_row).each do |clr_line|
244
+ order_execute_details_win.setpos(clr_line, Cryptum::UI.col_first)
245
+ Cryptum::UI.colorize(
246
+ ui_win: order_execute_details_win,
247
+ color: order_color,
248
+ style: :normal,
249
+ string: ''.ljust(col_just1, ' ')
250
+ )
251
+ end
252
+
253
+ # OK ROW
254
+ out_line_no = ok_row
255
+ order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first)
256
+ order_execute_details_win.clrtoeol
257
+ Cryptum::UI.colorize(
258
+ ui_win: order_execute_details_win,
259
+ color: order_color,
260
+ string: ''.ljust(col_just1, ' ')
261
+ )
262
+
263
+ header_str = '- OK -'
264
+ order_execute_details_win.setpos(
265
+ out_line_no,
266
+ Cryptum::UI.col_center(str: header_str)
267
+ )
268
+
269
+ Cryptum::UI.colorize(
270
+ ui_win: order_execute_details_win,
271
+ color: order_color,
272
+ style: :reverse,
273
+ string: header_str
274
+ )
275
+
276
+ order_execute_details_win.refresh
277
+
278
+ event_history
279
+ rescue Interrupt
280
+ # Exit Gracefully if CTRL+C is Pressed During Session
281
+ Cryptum::UI::Exit.gracefully(
282
+ which_self: self,
283
+ event_history: event_history
284
+ )
285
+ rescue StandardError => e
286
+ raise e
287
+ end
288
+
289
+ # Display Usage for this Module
290
+
291
+ public_class_method def self.help
292
+ puts "USAGE:
293
+ #{self}.refresh(
294
+ )
295
+ "
296
+ end
297
+ end
298
+ end
299
+ end
300
+ end