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,629 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cryptum
4
+ # This plugin is used to Refresh the Cryptum console UI
5
+ module UI
6
+ module Order
7
+ module Execute
8
+ # Supported Method Parameters::
9
+ # Cryptum::UI::Order::Execute.refresh(
10
+ # order_book: 'required - Order Book Data Structure',
11
+ # event: 'required - Event from Coinbase Web Socket'
12
+ # )
13
+
14
+ public_class_method def self.refresh(opts = {})
15
+ option_choice = opts[:option_choice]
16
+ order_execute_win = opts[:order_execute_win]
17
+ env = opts[:env]
18
+ event_history = opts[:event_history]
19
+ indicator_status = opts[:indicator_status]
20
+ bot_conf = opts[:bot_conf]
21
+
22
+ event_type = event_history.event_type if option_choice.autotrade
23
+ event_side = event_history.event[:side].to_s.to_sym if option_choice.autotrade
24
+ event_reason = event_history.event[:reason].to_s.to_sym if option_choice.autotrade
25
+
26
+ ticker_price = event_history.order_book[:ticker_price].to_f
27
+ open_24h = event_history.order_book[:open_24h].to_f
28
+ this_product = event_history.order_book[:this_product]
29
+ min_market_funds = this_product[:min_market_funds]
30
+ base_increment = this_product[:base_increment]
31
+ quote_increment = this_product[:quote_increment]
32
+ crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length
33
+ fiat_smallest_decimal = quote_increment.to_s.split('.')[-1].length
34
+
35
+ last_three_prices_arr = []
36
+ last_ticker_price = event_history.order_book[:ticker_price].to_f
37
+ second_to_last_ticker_price = event_history.order_book[:ticker_price_second_to_last].to_f
38
+ third_to_last_ticker_price = event_history.order_book[:ticker_price_third_to_last].to_f
39
+ last_three_prices_arr.push(last_ticker_price)
40
+ last_three_prices_arr.push(second_to_last_ticker_price)
41
+ last_three_prices_arr.push(third_to_last_ticker_price)
42
+ limit_price = last_three_prices_arr.sort[1]
43
+ return event_history unless limit_price.positive?
44
+
45
+ tpm = bot_conf[:target_profit_margin_percent].to_f
46
+ tpm_cast_as_decimal = tpm / 100
47
+
48
+ order_history_meta = event_history.order_book[:order_history_meta]
49
+ order_history = event_history.order_book[:order_history] if option_choice.autotrade
50
+
51
+ margin_percent_open_24h = (1 - (open_24h / ticker_price)) * 100
52
+ cast_margin_to_sec = margin_percent_open_24h * 0.1
53
+
54
+ # Reset times to max or default depending on
55
+ # BULL or BEAR market trend
56
+ event_history.bullish_trend = true if cast_margin_to_sec.positive?
57
+ event_history.bullish_trend = false if cast_margin_to_sec.negative?
58
+
59
+ buy_total = event_history.order_book[:market_trend][:buy].to_i
60
+ sell_total = event_history.order_book[:market_trend][:sell].to_i
61
+
62
+ if event_history.order_book[:order_plan].length.positive?
63
+ if event_history.order_ready
64
+ event_history.order_book[:last_order_exec] = Time.now.strftime(
65
+ '%Y-%m-%d %H:%M:%S.%N%z'
66
+ )
67
+ end
68
+
69
+ # BUY
70
+ # Reset times to max or default depending on
71
+ # BULL or BEAR market trend
72
+ event_history.time_between_orders = event_history.time_between_orders_max if buy_total >= sell_total &&
73
+ !event_history.bullish_trend
74
+
75
+ event_history.time_between_orders = event_history.time_between_orders_reset if sell_total > buy_total &&
76
+ !event_history.bullish_trend
77
+
78
+ if event_history.order_ready &&
79
+ indicator_status.action_signal == :buy &&
80
+ !event_history.red_pill
81
+
82
+ if option_choice.autotrade
83
+ this_order = event_history.order_book[:order_plan].first
84
+
85
+ # If price is greater than the previous order,
86
+ # force it to be slightly less
87
+ last_order = order_history_meta.select do |order|
88
+ order if order[:color] == 'yellow'
89
+ end.last
90
+
91
+ last_purchase_price = 0.0
92
+ last_purchase_price = last_order[:price].to_f if last_order
93
+
94
+ limit_price = last_purchase_price - quote_increment.to_f if last_purchase_price.positive? && last_purchase_price < limit_price
95
+
96
+ # Debug last order
97
+ File.open('/tmp/cryptum-errors.txt', 'a') do |f|
98
+ f.puts "Last Order: #{last_order}"
99
+ f.puts "Last Purchase Price: #{last_purchase_price}"
100
+ f.puts "Limit Price (Should be <= quote_increment-- ^): #{limit_price}"
101
+ f.puts "\n\n\n"
102
+ end
103
+
104
+ price = format(
105
+ "%0.#{fiat_smallest_decimal}f",
106
+ limit_price
107
+ )
108
+
109
+ size = this_order[:invest].to_f / limit_price
110
+
111
+ loop do
112
+ size = size.to_f + base_increment.to_f
113
+ break if (size.to_f * price.to_f) > min_market_funds.to_f
114
+ end
115
+
116
+ size = format(
117
+ "%0.#{crypto_smallest_decimal}f",
118
+ size
119
+ )
120
+
121
+ fiat_invested_this_order = size.to_f * price.to_f
122
+
123
+ fiat_portfolio = event_history.order_book[:fiat_portfolio]
124
+ fiat_avail_to_trade = format('%0.2f', fiat_portfolio.first[:available])
125
+
126
+ event_history.red_pill = true if fiat_invested_this_order > fiat_avail_to_trade.to_f
127
+
128
+ unless event_history.red_pill
129
+ event_history = Cryptum::API::Orders.submit_limit_order(
130
+ option_choice: option_choice,
131
+ env: env,
132
+ price: price,
133
+ size: size,
134
+ buy_or_sell: :buy,
135
+ event_history: event_history,
136
+ bot_conf: bot_conf
137
+ )
138
+ end
139
+ else
140
+ this_order = event_history.order_book[:order_plan].shift
141
+ # Mock Order ID
142
+ this_order[:buy_order_id] = format(
143
+ '%0.6i',
144
+ Random.rand(0..999_999)
145
+ )
146
+
147
+ this_order[:price] = limit_price.to_s
148
+ this_order[:size] = format(
149
+ "%0.#{crypto_smallest_decimal}f",
150
+ this_order[:invest].to_f / limit_price
151
+ )
152
+
153
+ targ_price = limit_price + (limit_price * tpm_cast_as_decimal)
154
+ this_order[:tpm] = format(
155
+ '%0.2f',
156
+ tpm
157
+ )
158
+ this_order[:target_price] = format(
159
+ "%0.#{fiat_smallest_decimal}f",
160
+ targ_price
161
+ )
162
+ this_order[:color] = :cyan
163
+ order_history_meta.push(this_order)
164
+ end
165
+
166
+ # SAUCE 4 (SAUCE 3 RELATES TO SAUCE 4)
167
+ # Time between orders
168
+ # Increment n Seconds between buys to
169
+ # account for bearish and bullish trends
170
+ dynamic_time_increment = cast_margin_to_sec * -1
171
+
172
+ # Lets also take balance into play
173
+ balance_as_arbitrary_float = fiat_avail_to_trade.to_f / 1_000_000
174
+ tbo = dynamic_time_increment - balance_as_arbitrary_float
175
+
176
+ event_history.time_between_orders += tbo
177
+
178
+ # Time between orders should never
179
+ # be less than event_history.time_between_orders_min
180
+ event_history.time_between_orders = event_history.time_between_orders_min if event_history.time_between_orders < event_history.time_between_orders_min
181
+ # Time between orders should never
182
+ # be more than event_history.time_between_orders_max
183
+ event_history.time_between_orders = event_history.time_between_orders_max if event_history.time_between_orders > event_history.time_between_orders_max
184
+ end
185
+
186
+ # SELL
187
+ # Once buy arders are fulfilled submit a
188
+ # limit sell order for fulfillment
189
+ unless option_choice.autotrade
190
+ # Testing logic via Mock
191
+ event_type_arr = %i[received open done]
192
+ last_et_index = event_type_arr.length - 1
193
+ rand_et_index = Random.rand(0..last_et_index)
194
+ event_type = event_type_arr[rand_et_index]
195
+
196
+ event_side_arr = %i[buy sell]
197
+ last_es_index = event_side_arr.length - 1
198
+ rand_es_index = Random.rand(0..last_es_index)
199
+ event_side = event_type_arr[rand_es_index].to_s.to_sym
200
+ event_reason = 'mock'
201
+ end
202
+ end
203
+
204
+ # Update Completed Sell Orders w/ Green
205
+ if event_type == :open &&
206
+ event_side == :buy
207
+
208
+ buy_order_id = event_history.event[:order_id]
209
+ order_history_meta.each do |meta|
210
+ meta[:color] = :red if meta[:buy_order_id] == buy_order_id
211
+ end
212
+ end
213
+
214
+ if event_type == :done &&
215
+ event_side == :buy &&
216
+ event_reason == :canceled
217
+
218
+ buy_order_id = event_history.event[:order_id]
219
+ order_history_meta.each do |meta|
220
+ next unless meta[:buy_order_id] == buy_order_id
221
+
222
+ meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
223
+ meta[:color] = :white
224
+ end
225
+ end
226
+
227
+ if event_type == :done &&
228
+ event_side == :buy &&
229
+ event_reason != :canceled
230
+
231
+ if option_choice.autotrade
232
+ order_ready_to_sell_arr = order_history_meta.select do |meta|
233
+ meta[:buy_order_id] == event_history.event[:order_id]
234
+ end
235
+ else
236
+ last_index = order_history_meta.length - 1
237
+ rand_index = Random.rand(0..last_index)
238
+ order_ready_to_sell_arr = [
239
+ order_history_meta[rand_index]
240
+ ]
241
+ end
242
+
243
+ if order_ready_to_sell_arr.length.positive?
244
+ order_ready_to_sell = order_ready_to_sell_arr.first
245
+ buy_order_id = order_ready_to_sell[:buy_order_id]
246
+
247
+ if option_choice.autotrade
248
+ price = format(
249
+ "%0.#{fiat_smallest_decimal}f",
250
+ order_ready_to_sell[:target_price]
251
+ )
252
+
253
+ size = order_ready_to_sell[:size]
254
+
255
+ Cryptum::API::Orders.submit_limit_order(
256
+ option_choice: option_choice,
257
+ env: env,
258
+ price: price,
259
+ size: size,
260
+ buy_or_sell: :sell,
261
+ event_history: event_history,
262
+ bot_conf: bot_conf,
263
+ buy_order_id: buy_order_id
264
+ )
265
+ else
266
+ sell_order_id = format(
267
+ '%0.2i',
268
+ Random.rand(0..999_999)
269
+ )
270
+
271
+ event_history.order_book[:order_history_meta].each do |meta|
272
+ if meta[:buy_order_id] == buy_order_id
273
+ meta[:sell_order_id] = sell_order_id
274
+ meta[:color] = :yellow
275
+ end
276
+ end
277
+ end
278
+ end
279
+ end
280
+
281
+ # Update Canceled Sell Orders w/ Black &&
282
+ # Include done_at Timestamp for 24h gain calc
283
+ if event_type == :done &&
284
+ event_side == :sell &&
285
+ event_reason == :canceled
286
+
287
+ sell_order_id = event_history.event[:order_id]
288
+ order_history_meta.each do |meta|
289
+ next unless meta[:sell_order_id] == sell_order_id
290
+
291
+ meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
292
+
293
+ # TODO: Retry sell order if the original sell order expires.
294
+
295
+ # Reinitiate GTFO if the previous GTFO Order Expires.
296
+ terminal_win.key_press_event.key_g = true if meta[:color] == :magenta
297
+ meta[:color] = :white
298
+ end
299
+ end
300
+
301
+ # Update Completed Sell Orders w/ Green &&
302
+ # Include done_at Timestamp for 24h gain calc
303
+ if event_type == :done &&
304
+ event_side == :sell &&
305
+ event_reason != :canceled
306
+
307
+ sell_order_id = event_history.event[:order_id]
308
+ order_history_meta.each do |meta|
309
+ next unless meta[:sell_order_id] == sell_order_id
310
+
311
+ meta[:done_at] = Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z')
312
+ meta[:color] = :green
313
+ end
314
+ end
315
+
316
+ # OK, now let's tally up everything...
317
+ twenty_four_hrs_ago = Time.now - 86_400
318
+
319
+ # Snag all sold orders
320
+ oh_meta_sold_arr = order_history_meta.select do |ohm|
321
+ ohm[:color].to_sym == :green && ohm.key?(:done_at)
322
+ end
323
+ order_hist_meta_sold = oh_meta_sold_arr.length
324
+
325
+ # Snag all sold orders within past 24 hrs
326
+ ohm_sold_twenty_four_arr = []
327
+ unless oh_meta_sold_arr.empty?
328
+ ohm_sold_twenty_four_arr = oh_meta_sold_arr.select do |o|
329
+ Time.parse(o[:done_at]) >= twenty_four_hrs_ago
330
+ end
331
+ end
332
+ order_hist_meta_sold_twenty_four = ohm_sold_twenty_four_arr.length
333
+
334
+ # Snag all expired orders
335
+ oh_meta_expired_arr = order_history_meta.select do |ohm|
336
+ ohm[:color].to_sym == :white && ohm.key?(:done_at)
337
+ end
338
+ order_hist_meta_expired = oh_meta_expired_arr.length
339
+
340
+ # Snag all expired orders within past 24 hrs
341
+ ohm_expire_twenty_four_arr = []
342
+ unless oh_meta_expired_arr.empty?
343
+ ohm_expire_twenty_four_arr = oh_meta_expired_arr.select do |o|
344
+ Time.parse(o[:done_at]) >= twenty_four_hrs_ago
345
+ end
346
+ end
347
+ order_hist_meta_24h_expired = ohm_expire_twenty_four_arr.length
348
+
349
+ # Calculate total gains and gains within past 24 hrs
350
+ gains_sum = oh_meta_sold_arr.map do |ohms|
351
+ ohms[:profit].to_f
352
+ end.sum
353
+
354
+ gains_out = Cryptum.beautify_large_number(
355
+ value: format(
356
+ '%0.2f',
357
+ gains_sum
358
+ )
359
+ )
360
+
361
+ gains_24h_sum = ohm_sold_twenty_four_arr.map do |ohms|
362
+ ohms[:profit].to_f
363
+ end.sum
364
+
365
+ gains_24h_out = Cryptum.beautify_large_number(
366
+ value: format(
367
+ '%0.2f',
368
+ gains_24h_sum
369
+ )
370
+ )
371
+
372
+ total_to_sell = order_history.select do |oh|
373
+ oh[:status].to_sym == :open && oh[:side].to_sym == :sell
374
+ end.length
375
+
376
+ event_history.open_sell_orders = total_to_sell
377
+ oh_meta_total_selling_profit_arr = order_history_meta.select do |ohm|
378
+ ohm[:color].to_sym == :yellow
379
+ end
380
+
381
+ total_selling_profit = oh_meta_total_selling_profit_arr.map do |ohms|
382
+ ohms[:profit].to_f
383
+ end.sum
384
+
385
+ total_selling_profit_out = Cryptum.beautify_large_number(
386
+ value: format(
387
+ '%0.2f',
388
+ total_selling_profit
389
+ )
390
+ )
391
+
392
+ # TODO: when event_history.open_sell_orders > event_history.open_sell_orders_max
393
+ # Capture highest amount to sell, cancel all orders, and create _one_ limit sell
394
+ # order set to a price of the previously captured highest amount to sell.
395
+ event_history.open_sell_orders_merge = true if total_to_sell > event_history.open_sell_orders_max
396
+
397
+ # TODO: Everything Above this Line Needs to be Indicators ^
398
+
399
+ # UI
400
+ col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1
401
+ col_just4 = Curses.cols - Cryptum::UI.col_fourth
402
+
403
+ # ROW 1
404
+ out_line_no = 0
405
+ line_color = :white
406
+ header_color = :white
407
+ header_style = :bold
408
+ style = :bold
409
+ if event_history.order_execute_win_active
410
+ line_color = :blue
411
+ header_color = :blue
412
+ header_style = :reverse
413
+ end
414
+
415
+ Cryptum::UI.line(
416
+ ui_win: order_execute_win,
417
+ out_line_no: out_line_no,
418
+ color: line_color
419
+ )
420
+
421
+ # ROW 2
422
+ out_line_no += 1
423
+ order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
424
+ order_execute_win.clrtoeol
425
+ Cryptum::UI.colorize(
426
+ ui_win: order_execute_win,
427
+ color: header_color,
428
+ style: header_style,
429
+ string: ''.ljust(col_just1, ' ')
430
+ )
431
+
432
+ header_str = '- ORDER HISTORY -'
433
+ order_execute_win.setpos(
434
+ out_line_no,
435
+ Cryptum::UI.col_center(str: header_str)
436
+ )
437
+
438
+ Cryptum::UI.colorize(
439
+ ui_win: order_execute_win,
440
+ color: header_color,
441
+ style: header_style,
442
+ string: header_str
443
+ )
444
+
445
+ order_execute_win.setpos(out_line_no, Cryptum::UI.col_fourth)
446
+ order_execute_win.clrtoeol
447
+ Cryptum::UI.colorize(
448
+ ui_win: order_execute_win,
449
+ color: header_color,
450
+ style: header_style,
451
+ string: ''.ljust(col_just4, ' ')
452
+ )
453
+
454
+ # ROWS 3-10
455
+ remaining_blank_rows = 0
456
+ remaining_blank_rows = max_rows_to_display if order_history_meta.empty?
457
+ max_rows_to_display = event_history.order_execute_max_rows_to_display
458
+ first_row = event_history.order_execute_index_offset
459
+ last_row = first_row + max_rows_to_display
460
+ if last_row >= order_history_meta.length
461
+ last_row = order_history_meta.length - 1
462
+ event_history.order_execute_max_records_available_to_display = last_row if last_row < max_rows_to_display
463
+ first_row = last_row - event_history.order_execute_max_records_available_to_display
464
+ event_history.order_execute_index_offset = first_row
465
+ remaining_blank_rows = max_rows_to_display - last_row
466
+ end
467
+
468
+ if order_history_meta.any?
469
+ selected_order = event_history.order_execute_selected_data
470
+ order_history_meta.reverse[first_row..last_row].each do |meta|
471
+ out_line_no += 1
472
+ current_line = out_line_no - 2
473
+
474
+ style = :normal
475
+ if event_history.order_execute_row_to_select == current_line
476
+ style = :highlight
477
+ selected_order = meta
478
+ selected_order[:color] = meta[:color]
479
+ end
480
+
481
+ invest_out = Cryptum.beautify_large_number(
482
+ value: meta[:invest]
483
+ )
484
+ price_out = Cryptum.beautify_large_number(
485
+ value: meta[:price]
486
+ )
487
+ size_out = Cryptum.beautify_large_number(
488
+ value: meta[:size]
489
+ )
490
+ target_price_out = Cryptum.beautify_large_number(
491
+ value: meta[:target_price]
492
+ )
493
+ plan_no = meta[:plan_no]
494
+
495
+ buy_created_at_hash_arr = order_history.select do |oh|
496
+ oh[:id] == meta[:buy_order_id]
497
+ end
498
+
499
+ buy_created_at = '____-__-__ __:__:__'
500
+ unless buy_created_at_hash_arr.empty?
501
+ buy_created_at = Time.parse(
502
+ buy_created_at_hash_arr.first[:created_at]
503
+ ).strftime('%Y-%m-%d %H:%M:%S')
504
+ end
505
+
506
+ invest = "$#{invest_out} @ "
507
+ tick = "$#{price_out} = "
508
+ size = "*#{size_out} + "
509
+ tpm_out = "#{meta[:tpm]}% = "
510
+ targ_tick = "$#{target_price_out}"
511
+ profit = "|Profit: $#{meta[:profit]}"
512
+
513
+ order_exec_ln = "#{buy_created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}|#{plan_no}"
514
+
515
+ order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
516
+ order_execute_win.clrtoeol
517
+ Cryptum::UI.colorize(
518
+ ui_win: order_execute_win,
519
+ color: meta[:color],
520
+ style: style,
521
+ string: order_exec_ln.ljust(col_just1, '.')
522
+ )
523
+
524
+ Cryptum::UI.colorize(
525
+ ui_win: order_execute_win,
526
+ color: meta[:color],
527
+ style: style,
528
+ string: ''.ljust(col_just4, ' ')
529
+ )
530
+ end
531
+ event_history.order_execute_selected_data = selected_order
532
+ end
533
+
534
+ # Clear to SUMMARY
535
+ # (Only Applicable if order_book[:order_history_meta] < max_rows_to_display)
536
+ # out_line_no += 1
537
+ if remaining_blank_rows.positive?
538
+ rows_to_blank = out_line_no + remaining_blank_rows
539
+ out_line_no += 1
540
+ (out_line_no..rows_to_blank).each do |clr_line|
541
+ out_line_no = clr_line
542
+ order_execute_win.setpos(clr_line, Cryptum::UI.col_first)
543
+ order_execute_win.clrtoeol
544
+ Cryptum::UI.colorize(
545
+ ui_win: order_execute_win,
546
+ color: :white,
547
+ style: :normal,
548
+ string: ''.ljust(col_just1, ' ')
549
+ )
550
+ end
551
+ end
552
+
553
+ # ROW 10
554
+ out_line_no += 1
555
+ order_execute_win.setpos(out_line_no, Cryptum::UI.col_first)
556
+ order_execute_win.clrtoeol
557
+ Cryptum::UI.colorize(
558
+ ui_win: order_execute_win,
559
+ color: header_color,
560
+ style: header_style,
561
+ string: ''.ljust(col_just1, ' ')
562
+ )
563
+
564
+ header_str = "SELLING: #{total_to_sell} w tProf: $#{total_selling_profit_out} | "
565
+ header_str += "SOLD 24h: #{order_hist_meta_sold_twenty_four} Tot: #{order_hist_meta_sold} | "
566
+ header_str += "GAINS 24h: $#{gains_24h_out} Tot: $#{gains_out} | "
567
+ header_str += "EXPIRED 24h: #{order_hist_meta_24h_expired} Tot: #{order_hist_meta_expired}"
568
+ order_execute_win.setpos(
569
+ out_line_no,
570
+ Cryptum::UI.col_center(str: header_str)
571
+ )
572
+
573
+ Cryptum::UI.colorize(
574
+ ui_win: order_execute_win,
575
+ color: header_color,
576
+ style: header_style,
577
+ string: header_str
578
+ )
579
+
580
+ # order_execute_win.setpos(out_line_no, Cryptum::UI.col_fourth)
581
+ # order_execute_win.clrtoeol
582
+ # Cryptum::UI.colorize(
583
+ # ui_win: order_execute_win,
584
+ # color: header_color,
585
+ # style: header_style,
586
+ # string: ''.ljust(col_just4, ' ')
587
+ # )
588
+
589
+ # ROW 11
590
+ out_line_no += 1
591
+ Cryptum::UI.line(
592
+ ui_win: order_execute_win,
593
+ out_line_no: out_line_no,
594
+ color: line_color
595
+ )
596
+
597
+ order_execute_win.refresh
598
+
599
+ # Reset Order Ready && Open Sell Orders Merge (If Applicable) Booleans
600
+ event_history.order_ready = false
601
+ event_history.open_sell_orders_merge = false
602
+
603
+ event_history
604
+ rescue Interrupt
605
+ # Exit Gracefully if CTRL+C is Pressed During Session
606
+ Cryptum::UI::Exit.gracefully(
607
+ which_self: self,
608
+ event_history: event_history,
609
+ option_choice: option_choice,
610
+ env: env
611
+ )
612
+ rescue StandardError => e
613
+ raise e
614
+ end
615
+
616
+ # Display Usage for this Module
617
+
618
+ public_class_method def self.help
619
+ puts "USAGE:
620
+ #{self}.refresh(
621
+ order_book: 'required - Order Book Data Structure',
622
+ event: 'required - Event from Coinbase Web Socket'
623
+ )
624
+ "
625
+ end
626
+ end
627
+ end
628
+ end
629
+ end