cryptum 0.0.382 → 0.0.384

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