# frozen_string_literal: true require 'logger' module Cryptum module UI # This plugin is used to Refresh the Cryptum Status Section UI module OrderTimer # Supported Method Parameters:: # Cryptum::UI::Timer.refresh( # ) 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] # 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 = Cryptum.beautify_large_number( value: format('%0.2f', trend_time_remaining) ) # Market Trend Reset Timer time_between_order_exec = event_history.time_between_orders time_between_order_exec_out = Cryptum.beautify_large_number( value: format('%0.2f', 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 = Cryptum.beautify_large_number( value: format('%0.2f', order_exec_time_remaining) ) color = :white color = indicator_status.market_trend[:color] if indicator_status.market_trend case color when :green # TODO: add condition to check if open sell orders exist. # If so intent should be something like, "- SEE ORDER HISTORY -" # Otherwise, intent should be something like, "- WAIT FOR MARKET TREND SHIFT -" intent = "- SEE ORDER HISTORY #{Cryptum.down_arrow} -" else speed = 'FAST' speed = 'SLOW' if event_history.bullish_trend intent = "- #{speed} 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 # COLUMN 1 out_line_no = 0 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}" ) # COLUMN 2 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 ) # COLUMN 3 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 # Display Usage for this Module public_class_method def self.help puts "USAGE: #{self}.refresh( ) " end end end end