Module: Cryptum::UI::OrderTimer

Defined in:
lib/cryptum/ui/order_timer.rb

Overview

This plugin is used to Refresh the Cryptum Status Section UI

Class Method Summary collapse

Class Method Details

.helpObject

Display Usage for this Module



111
112
113
114
115
116
# File 'lib/cryptum/ui/order_timer.rb', line 111

public_class_method def self.help
  puts "USAGE:
   #{self}.refresh(
   )
  "
end

.refresh(opts = {}) ⇒ Object

Supported Method Parameters

Cryptum::UI::Timer.refresh( )



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cryptum/ui/order_timer.rb', line 13

public_class_method def self.refresh(opts = {})
  option_choice = opts[:option_choice]
  event_history = opts[:event_history]
  order_timer_win = opts[:order_timer_win]
  indicator_status = opts[:indicator_status]
  key_press_event = opts[:key_press_event]

  last_trend_reset_time = event_history.order_book[:last_trend_reset]
  last_order_exec_time = event_history.order_book[:last_order_exec]

  Cryptum::UI.detect_key_press_in_ui(
    key_press_event: key_press_event,
    ui_win: order_timer_win
  )

  # Market Trend Reset Timer
  time_between_trend_reset = option_choice.market_trend_reset
  trend_timer_begin = Time.parse(last_trend_reset_time)
  trend_timer_end = trend_timer_begin + time_between_trend_reset
  trend_time_remaining = trend_timer_end - Time.now
  trend_countdown = format('%0.4f', trend_time_remaining)

  # Market Trend Reset Timer
  time_between_order_exec = event_history.time_between_orders
  time_between_order_exec_out = format(
    '%0.4f',
    time_between_order_exec
  )
  order_begin_time = Time.parse(last_order_exec_time)
  order_end_time = order_begin_time + time_between_order_exec
  order_exec_time_remaining = order_end_time - Time.now
  order_countdown = format('%0.4f', order_exec_time_remaining)

  color = :white
  color = indicator_status.market_trend[:color] if indicator_status.market_trend
  case color
  when :green
    intent = "- Wait for Open Sell Orders -"
  else
    intent = "Next BUY: #{order_countdown} of #{time_between_order_exec_out}"
    intent = '- BUYING PAUSED -' if event_history.red_pill
  end
  
  # Have a Clock
  clock = Time.now.strftime('%Y-%m-%d %H:%M:%S%z')

  # UI
  col_just4 = (Curses.cols - Cryptum::UI.col_fourth) - 1

  # ROW 1
  out_line_no = 0
  Cryptum::UI.line(
    ui_win: order_timer_win,
    out_line_no: out_line_no
  )

  # ROW 2
  out_line_no += 1
  order_timer_win.setpos(out_line_no, Cryptum::UI.col_first)
  order_timer_win.clrtoeol
  Cryptum::UI.colorize(
    ui_win: order_timer_win,
    color: :white,
    style: :bold,
    string: "Market Trend Reset: #{trend_countdown}"
  )

  order_timer_win.setpos(
    out_line_no,
    Cryptum::UI.col_center(str: intent)
  )
  Cryptum::UI.colorize(
    ui_win: order_timer_win,
    color: :white,
    style: :bold,
    string: intent
  )

  order_timer_win.setpos(out_line_no, Cryptum::UI.col_fourth)
  Cryptum::UI.colorize(
    ui_win: order_timer_win,
    color: :white,
    style: :bold,
    string: clock.rjust(col_just4)
  )

  order_timer_win.refresh

  order_countdown.to_f
rescue Interrupt
  # Exit Gracefully if CTRL+C is Pressed During Session
  Cryptum.exit_gracefully(which_self: self)
rescue StandardError => e
  raise e
end