class Abot::Info::Table
Constants
- ALL_HEADINGS
- COLUMN_WITH_TOTAL
- HEADINGS_COINS_TABLE_DEFAULT
- HEADINGS_COINS_TABLE_MOBILE
Attributes
account[R]
columns[R]
current_coins[R]
rate_coins[R]
trade_params[R]
Public Class Methods
last_columns_set(col)
click to toggle source
# File lib/abot/info/table.rb, line 69 def self.last_columns_set(col) col = col.map { |m| ALL_HEADINGS.keys.include?(m) ? m : nil }.compact COLUMN_WITH_TOTAL.each { |e| col << col.delete(e) } col.compact end
new(options)
click to toggle source
Calls superclass method
# File lib/abot/info/table.rb, line 54 def initialize(options) @account = options[:account] @columns = options[:columns] || HEADINGS_COINS_TABLE_DEFAULT @rate_coins = options.fetch(:rate_coins, []) @trade_params ||= DatabaseTable.data_settings @current_coins = Coin.current_coins(account, trade_params) options = { headings: columns.map { |h| { value: ALL_HEADINGS[h], alignment: :center } }, style: { border_x: '=' } } super options end
Public Instance Methods
available_coins_number()
click to toggle source
# File lib/abot/info/table.rb, line 128 def available_coins_number @available_coins_number ||= Coin.available_coins_number( current_coins, trade_params, account.percent_free_balance(current_coins) ) end
colspan()
click to toggle source
# File lib/abot/info/table.rb, line 136 def colspan (columns - COLUMN_WITH_TOTAL).count - 1 end
generate()
click to toggle source
# File lib/abot/info/table.rb, line 75 def generate sorted_current_coins.each do |coin| row = columns.map do |m| coin.decorated_cell(m) end add_row row end add_separator add_row row_total self end
info_str()
click to toggle source
# File lib/abot/info/table.rb, line 99 def info_str "#{Helpers.check_coins(account, trade_params["quote_asset"].split(' '))}" \ "#{Helpers.check_abot}" \ "#{Helpers.today_info_str}\n" \ "#{Helpers.balance_str(account, current_coins, trade_params)}\n" \ "#{Helpers.potential_balance_str(account, current_coins, trade_params)}\n" \ "#{rate_coins_str}" end
rate_coins_str()
click to toggle source
# File lib/abot/info/table.rb, line 108 def rate_coins_str result = '' rate_coins.each_with_index do |c, idx| number = colspan / 2 number += 1 if number.zero? result += if idx != 0 && (idx % number).zero? "\n" elsif idx != 0 ' ' else '' end str = Helpers.symbol_price_str(account, c.upcase) str.slice!('USDT') result += str end result end
row_total()
click to toggle source
# File lib/abot/info/table.rb, line 140 def row_total row_total = [ total_averages, { value: info_str, colspan: colspan } ] quote_assets = trade_params['quote_asset'].split(' ') cell_current_profit = '' cell_potential_profit = '' quote_assets.each do |qa| if quote_assets.count > 1 cell_current_profit += "#{Coin.sum_current_profit(current_coins, qa).round(2)} #{qa}\n"if columns.include?(:current_profit) cell_potential_profit += "#{Coin.sum_potential_profit(current_coins, qa).round(2)} #{qa}\n" if columns.include?(:potential_profit) else cell_current_profit += Coin.sum_current_profit(current_coins, qa).round(2).to_s if columns.include?(:current_profit) cell_potential_profit += Coin.sum_potential_profit(current_coins, qa).round(2).to_s if columns.include?(:potential_profit) end end row_total << cell_current_profit if columns.include?(:current_profit) row_total << cell_potential_profit if columns.include?(:potential_profit) row_total end
sorted_current_coins()
click to toggle source
# File lib/abot/info/table.rb, line 162 def sorted_current_coins current_coins.sort_by(&:percent_to_order) end
total_averages()
click to toggle source
# File lib/abot/info/table.rb, line 87 def total_averages av_arr = [] current_coins.each { |coin| av_arr[coin.num_averaging] = av_arr[coin.num_averaging].to_i + 1 } count = av_arr.compact.sum av_arr = av_arr.map.with_index do |av, idx| Paint["#{idx}: #{av.to_i}", (Helpers::AVERAGE_COLORS[idx] || :red)] if av.to_i != 0 end.compact av_arr << "∑: #{count}" # av_arr << "M: #{available_coins_number}" if available_coins_number av_arr.join("\n") end