# frozen_string_literal: true require 'logger' module Cryptum module UI # This plugin is used to Display Order Execute Details # selected from the Order Execute Window Pane. module OrderExecuteDetails # Supported Method Parameters:: # Cryptum::UI::OrderExecuteDetails.refresh( # ) public_class_method def self.refresh(opts = {}) option_choice = opts[:option_choice] event_history = opts[:event_history] order_execute_details_win = opts[:order_execute_details_win] indicator_status = opts[:indicator_status] key_press_event = opts[:key_press_event] order = event_history.order_execute_selected_data tpm = order[:tpm] autotrade_percent = order[:autotrade_percent] order_color = order[:color].to_sym order_plan_no = order[:plan_no] case order_color when :cyan, :red order_id = order[:buy_order_id] order_type = 'Buy' when :green, :magenta, :yellow order_id = order[:sell_order_id] order_type = 'Sell' when :black order_id = 'Expired' order_type = 'Expired' else order_id = 'N/A' order_type = 'N/A' end risk_alloc_out = Cryptum.beautify_large_number( value: order[:risk_alloc] ) invest_out = Cryptum.beautify_large_number( value: order[:invest] ) price_out = Cryptum.beautify_large_number( value: order[:price] ) size_out = Cryptum.beautify_large_number( value: order[:size] ) target_price_out = Cryptum.beautify_large_number( value: order[:target_price] ) profit_out = Cryptum.beautify_large_number( value: order[:profit] ) plan_no = "#{order[:plan_no]}|" created_at = order[:created_at] invest = "$#{invest_out} @ " tick = "$#{price_out} = " size = "*#{size_out} + " tpm_out = "#{order[:tpm]}% = " targ_tick = "$#{target_price_out}" profit = "|Profit: $#{order[:profit]}" order_id_details = "#{order_type} Order ID: #{order_id}" order_plan_details = "Order Slice #: #{order_plan_no}" order_exec_ln = "Details: #{created_at}|#{invest}#{tick}#{size}#{tpm_out}#{targ_tick}#{profit}" # UI col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1 col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1 col_just4 = Curses.cols - Cryptum::UI.col_fourth # ROW 1 out_line_no = 0 line_color = order_color header_color = order_color header_style = :bold style = :bold header_style = :reverse if event_history.order_execute_details_win_active Cryptum::UI.line( ui_win: order_execute_details_win, out_line_no: out_line_no, color: line_color ) # ROW 2 out_line_no += 1 order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_execute_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_execute_details_win, color: header_color, style: header_style, string: ''.ljust(col_just1, ' ') ) header_str = "- ORDER ##{order[:plan_no]} DETAILS -" order_execute_details_win.setpos( out_line_no, Cryptum::UI.col_center(str: header_str) ) Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, style: header_style, string: header_str ) # ROW 3 out_line_no += 1 order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_execute_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, style: style, string: order_id_details.ljust(col_just1, ' ') ) # ROW 5 out_line_no += 1 order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_execute_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, style: style, string: order_plan_details.ljust(col_just1, ' ') ) # ROW 4 out_line_no += 1 order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_execute_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, style: style, string: order_exec_ln.ljust(col_just1, ' ') ) # Clear to OK ROW ok_row = 9 out_line_no += 1 to_ok_row = ok_row - 1 (out_line_no..to_ok_row).each do |clr_line| order_execute_details_win.setpos(clr_line, Cryptum::UI.col_first) Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, style: :normal, string: ''.ljust(col_just1, ' ') ) end # OK ROW out_line_no = ok_row order_execute_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_execute_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, string: ''.ljust(col_just1, ' ') ) header_str = '- OK -' order_execute_details_win.setpos( out_line_no, Cryptum::UI.col_center(str: header_str) ) Cryptum::UI.colorize( ui_win: order_execute_details_win, color: order_color, style: :reverse, string: header_str ) order_execute_details_win.refresh 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