# frozen_string_literal: true require 'logger' module Cryptum # This plugin is used to Refresh the Cryptum console UI module UI module MarketTrend # Supported Method Parameters:: # Cryptum::UI::Candle.refresh( # order_book: 'required - Order Book Data Structure', # event: 'required - Event from Coinbase Web Socket' # ) public_class_method def self.refresh(opts = {}) option_choice = opts[:option_choice] market_trend_win = opts[:market_trend_win] event_history = opts[:event_history] key_press_event = opts[:key_press_event] event = opts[:event] indicator_status = opts[:indicator_status] bot_conf = opts[:bot_conf] reset_counter = opts[:reset_counter] indicator_hash = Cryptum::OrderBook::MarketTrend.status( event_history: event_history, event: event, indicator_status: indicator_status ) color = indicator_hash[:color] order_trend_out = indicator_hash[:ui] case color when :green order_trend_color = :green trend_arrow = Cryptum.up_arrow trend = 'Bull' when :yellow order_trend_color = :yellow trend_arrow = Cryptum.flat_arrow trend = 'Flatline' when :red order_trend_color = :red trend_arrow = Cryptum.down_arrow trend = 'Bear' end market_trend_out = "Market Trend #{trend_arrow} |#{trend} | #{order_trend_out}" # UI # col_just1 = 12 col_just1 = (Curses.cols - Cryptum::UI.col_first) - 1 col_just2 = 14 col_just3 = 21 col_just3_alt = (Curses.cols - Cryptum::UI.col_third) - 1 col_just4 = Curses.cols - Cryptum::UI.col_fourth Cryptum::UI.detect_key_press_in_ui( key_press_event: key_press_event, ui_win: market_trend_win ) # ROW 1 out_line_no = 0 Cryptum::UI.line( ui_win: market_trend_win, out_line_no: out_line_no ) # ROW 2 out_line_no += 1 market_trend_win.setpos(out_line_no, Cryptum::UI.col_first) market_trend_win.clrtoeol Cryptum::UI.colorize( ui_win: market_trend_win, color: order_trend_color, string: ''.ljust(col_just1, ' ') ) market_trend_win.setpos( out_line_no, Cryptum::UI.col_center(str: market_trend_out) ) Cryptum::UI.colorize( ui_win: market_trend_win, color: order_trend_color, style: :bold, string: market_trend_out ) market_trend_win.setpos(out_line_no, Cryptum::UI.col_fourth) Cryptum::UI.colorize( ui_win: market_trend_win, color: order_trend_color, string: ''.ljust(col_just4, ' ') ) market_trend_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( order_book: 'required - Order Book Data Structure', event: 'required - Event from Coinbase Web Socket' ) " end end end end