# frozen_string_literal: true module Cryptum module UI # This plugin is used to Display Order Plan Details # selected from the Order Plan Window Pane. module Order module PlanDetails # Supported Method Parameters:: # Cryptum::UI::Order::PlanDetails.refresh( # ) public_class_method def self.refresh(opts = {}) event_history = opts[:event_history] order_plan_details_win = opts[:order_plan_details_win] order = event_history.order_plan_selected_data tpm = order[:tpm] autotrade_percent = order[:autotrade_percent] order_color = order[:color] fiat_avail_out = Cryptum.beautify_large_number( value: order[:fiat_available] ) risk_alloc_out = Cryptum.beautify_large_number( value: order[:risk_alloc] ) slice_alloc_out = Cryptum.beautify_large_number( value: order[:slice_alloc] ) previous_slice_invest_out = Cryptum.beautify_large_number( value: order[:previous_slice_invest] ) invest_out = Cryptum.beautify_large_number( value: order[:invest] ) profit_out = Cryptum.beautify_large_number( value: order[:profit] ) tpm_out = format('%0.2f', tpm) return_out = Cryptum.beautify_large_number( value: order[:return] ) autotrade_ln1_details = "1. Autotrade is set to #{autotrade_percent}% of $#{fiat_avail_out}, making $#{risk_alloc_out} available for this slice in" autotrade_ln2_details = ' the order plan.' if order[:last_slice] slice_alloc_ln1_details = "2. Since $#{risk_alloc_out} is the remaining amount within the criteria defined in the Autotrade % above," slice_alloc_ln2_details = " $#{invest_out} will be allocated for this slice." else slice_alloc_ln1_details = "2. With $#{risk_alloc_out} available and a slice allocation of #{order[:allocation_percent]}%, $#{slice_alloc_out} plus the previous" slice_alloc_ln2_details = " slice of $#{previous_slice_invest_out} results in $#{invest_out} being allocated for this slice." end profit_ln1_details = "3. With a slice allocation of $#{invest_out}, plus a TPM equal to #{tpm_out}%, $#{return_out} will be returned" profit_ln2_details = " once sold. With $#{invest_out} invested, the gross profit equals $#{profit_out}, minus any Maker &" profit_ln3_details = ' Taker (transaction) fees.' # UI col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1 # 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_plan_details_win_active Cryptum::UI.line( ui_win: order_plan_details_win, out_line_no: out_line_no, color: line_color ) # ROW 2 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: header_color, style: header_style, string: ''.ljust(col_just1, ' ') ) header_str = "- ORDER SLICE ##{order[:plan_no]} DETAILS -" order_plan_details_win.setpos( out_line_no, Cryptum::UI.col_center(str: header_str) ) Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: header_style, string: header_str ) # ROW 3 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: autotrade_ln1_details.ljust(col_just1, ' ') ) # ROW 4 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: autotrade_ln2_details.ljust(col_just1, ' ') ) # ROW 5 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: slice_alloc_ln1_details.ljust(col_just1, ' ') ) # ROW 6 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: slice_alloc_ln2_details.ljust(col_just1, ' ') ) # ROW 7 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: profit_ln1_details.ljust(col_just1, ' ') ) # ROW 8 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: profit_ln2_details.ljust(col_just1, ' ') ) # ROW 9 out_line_no += 1 order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: style, string: profit_ln3_details.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_plan_details_win.setpos(clr_line, Cryptum::UI.col_first) Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: :normal, string: ''.ljust(col_just1, ' ') ) end # OK ROW out_line_no = ok_row order_plan_details_win.setpos(out_line_no, Cryptum::UI.col_first) order_plan_details_win.clrtoeol Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, string: ''.ljust(col_just1, ' ') ) header_str = '- OK -' order_plan_details_win.setpos( out_line_no, Cryptum::UI.col_center(str: header_str) ) Cryptum::UI.colorize( ui_win: order_plan_details_win, color: order_color, style: :reverse, string: header_str ) order_plan_details_win.refresh event_history rescue Interrupt # Exit Gracefully if CTRL+C is Pressed During Session Cryptum::UI::Exit.gracefully( which_self: self, event_history: event_history ) 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 end