Module: Cryptum::UI::Portfolio
- Defined in:
- lib/cryptum/ui/portfolio.rb
Overview
Update the Portfolio Section of the UI
Class Method Summary collapse
-
.help ⇒ Object
Display Usage for this Module.
-
.refresh(opts = {}) ⇒ Object
- Supported Method Parameters
-
Cryptum::UI::Candle.refresh( order_book: ‘required - Order Book Data Structure’, event: ‘required - Event from Coinbase Web Socket’ ).
Class Method Details
.help ⇒ Object
Display Usage for this Module
211 212 213 214 215 216 217 218 |
# File 'lib/cryptum/ui/portfolio.rb', line 211 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 |
.refresh(opts = {}) ⇒ Object
- Supported Method Parameters
-
Cryptum::UI::Candle.refresh(
order_book: 'required - Order Book Data Structure', event: 'required - Event from Coinbase Web Socket'
)
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/cryptum/ui/portfolio.rb', line 15 public_class_method def self.refresh(opts = {}) option_choice = opts[:option_choice] portfolio_win = opts[:portfolio_win] event_history = opts[:event_history] bot_conf = opts[:bot_conf] ticker_price = event_history.order_book[:ticker_price].to_f this_product = event_history.order_book[:this_product] symbol_out = this_product[:id] base_increment = this_product[:base_increment] crypto_smallest_decimal = base_increment.to_s.split('.')[-1].length autotrade_percent = format( '%0.2f', bot_conf[:autotrade_portfolio_percent].to_f ) tpm = format( '%0.2f', bot_conf[:target_profit_margin_percent] ) crypto_currency = option_choice.symbol.to_s.upcase.split('_').first.to_sym portfolio = event_history.order_book[:portfolio] this_account = portfolio.select do |account| account[:currency] == crypto_currency.to_s end if this_account.empty? e = "ID for Crypto Currency, #{crypto_currency} Not Found" Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end balance = format("%0.#{crypto_smallest_decimal}f", this_account.first[:balance]) balance_out = Cryptum.beautify_large_number( value: balance ) avail_for_trade = format("%0.#{crypto_smallest_decimal}f", this_account.first[:available]) avail_for_trade_out = Cryptum.beautify_large_number( value: avail_for_trade ) fiat_portfolio = event_history.order_book[:fiat_portfolio] fiat = option_choice.symbol.to_s.upcase.split('_').last.to_sym total_holdings = format('%0.2f', fiat_portfolio.first[:total_holdings]) total_holdings_out = Cryptum.beautify_large_number( value: total_holdings ) fiat_balance = format('%0.2f', fiat_portfolio.first[:balance]) fiat_balance_out = Cryptum.beautify_large_number( value: fiat_balance ) fiat_avail_for_trade = format('%0.2f', fiat_portfolio.first[:available]) fiat_avail_for_trade_out = Cryptum.beautify_large_number( value: fiat_avail_for_trade ) fees = event_history.order_book[:fees] maker_fee = format('%0.2f', fees[:maker_fee_rate].to_f * 100) taker_fee = format('%0.2f', fees[:taker_fee_rate].to_f * 100) volume_tier = format('%0.2f', fees[:usd_volume].to_f) volume_tier_out = Cryptum.beautify_large_number( value: volume_tier ) current_crypto_fiat_value = format( '%0.2f', balance.to_f * ticker_price ) current_crypto_fiat_value_out = Cryptum.beautify_large_number( value: current_crypto_fiat_value ) fiat_budget = fiat_avail_for_trade.to_f current_fiat_invested_percent = format( '%0.2f', (1 - (fiat_budget / total_holdings.to_f)) * 100 ) crypto_invested_percent = format( '%0.2f', current_crypto_fiat_value.to_f.fdiv(total_holdings.to_f) * 100 ) # TODO: Everything Above this Line Needs to be Indicators ^ # UI col_just3 = (Curses.cols - Cryptum::UI.col_third) - 1 # ROW 1 out_line_no = 0 Cryptum::UI.line( ui_win: portfolio_win, out_line_no: out_line_no ) # ROW 2 out_line_no += 1 portfolio_win.setpos(out_line_no, Cryptum::UI.col_first) portfolio_win.clrtoeol Cryptum::UI.colorize( ui_win: portfolio_win, color: :white, style: :bold, string: "Portfolio | % Tied Up | % #{symbol_out}:" ) portfolio_win.setpos(out_line_no, Cryptum::UI.col_third) Cryptum::UI.colorize( ui_win: portfolio_win, color: :white, string: "$#{total_holdings_out} | #{current_fiat_invested_percent}% | #{crypto_invested_percent}%".rjust(col_just3, '.') ) # ROW 3 out_line_no += 1 portfolio_win.setpos(out_line_no, Cryptum::UI.col_first) portfolio_win.clrtoeol Cryptum::UI.colorize( ui_win: portfolio_win, color: :cyan, string: 'TPM % | Autotrade %:' ) portfolio_win.setpos(out_line_no, Cryptum::UI.col_third) Cryptum::UI.colorize( ui_win: portfolio_win, color: :cyan, string: "#{tpm}% | #{autotrade_percent}%".rjust(col_just3, '.') ) # ROW 4 out_line_no += 1 portfolio_win.setpos(out_line_no, Cryptum::UI.col_first) portfolio_win.clrtoeol Cryptum::UI.colorize( ui_win: portfolio_win, color: :green, style: :bold, string: "#{fiat} Bal | Tradeable:" ) portfolio_win.setpos(out_line_no, Cryptum::UI.col_third) Cryptum::UI.colorize( ui_win: portfolio_win, color: :green, string: "$#{fiat_balance_out} | $#{fiat_avail_for_trade_out}".rjust( col_just3, '.' ) ) # ROW 5 out_line_no += 1 portfolio_win.setpos(out_line_no, Cryptum::UI.col_first) portfolio_win.clrtoeol Cryptum::UI.colorize( ui_win: portfolio_win, color: :yellow, style: :bold, string: 'Crypto Val | Bal | Tradeable:' ) portfolio_win.setpos(out_line_no, Cryptum::UI.col_third) Cryptum::UI.colorize( ui_win: portfolio_win, color: :yellow, string: "$#{current_crypto_fiat_value_out} | *#{balance_out} | *#{avail_for_trade_out}".rjust(col_just3, '.') ) # ROW 6 out_line_no += 1 portfolio_win.setpos(out_line_no, Cryptum::UI.col_first) portfolio_win.clrtoeol Cryptum::UI.colorize( ui_win: portfolio_win, color: :red, style: :bold, string: 'Maker & Taker Fees | My Volume:' ) portfolio_win.setpos(out_line_no, Cryptum::UI.col_third) Cryptum::UI.colorize( ui_win: portfolio_win, color: :red, string: "#{maker_fee}% & #{taker_fee}% | $#{volume_tier_out}".rjust(col_just3, '.') ) portfolio_win.refresh event_history rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self, event_history: event_history) end |