Module: Abot::Info::Coin::CoinDecorator

Included in:
Abot::Info::Coin
Defined in:
lib/abot/info/decorators/coin_decorator.rb

Instance Method Summary collapse

Instance Method Details

#decorated_buy_dateObject



87
88
89
90
91
92
93
94
# File 'lib/abot/info/decorators/coin_decorator.rb', line 87

def decorated_buy_date
  sec = timer.to_s[0..9].to_f
  return '-' if sec < 1_577_836_800 # 2020-01-01 00:00:00 +0000

  Time.at(sec).strftime('%d %h %H:%M')
rescue StandardError
  '-'
end

#decorated_cell(name) ⇒ Object



122
123
124
125
126
127
128
129
# File 'lib/abot/info/decorators/coin_decorator.rb', line 122

def decorated_cell(name)
  str = public_send("decorated_#{name}")
  value = Paint[str, (Helpers::AVERAGE_COLORS[num_averaging] || :red)]
  row = { value: value }
  row[:alignment] = :right if name == :timer
  row[:alignment] = :center if name == :buy_date
  row
end

#decorated_current_priceObject



63
64
65
# File 'lib/abot/info/decorators/coin_decorator.rb', line 63

def decorated_current_price
  "#{current_price} (#{percent_to_order.round(2)}%)"
end

#decorated_current_profitObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/abot/info/decorators/coin_decorator.rb', line 19

def decorated_current_profit
  rounded_current_profit = if trade_params['quote_asset'].split(' ').count > 1
                             "#{current_profit.round(2)} #{quote_asset}"
                           else
                             current_profit.round(2)
                           end
  if current_profit >= 0
    Paint[rounded_current_profit, :green]
  else
    Paint[rounded_current_profit, :red]
  end
end

#decorated_current_quoteObject



75
76
77
# File 'lib/abot/info/decorators/coin_decorator.rb', line 75

def decorated_current_quote
  current_quote.round(2)
end

#decorated_max_priceObject



71
72
73
# File 'lib/abot/info/decorators/coin_decorator.rb', line 71

def decorated_max_price
  "#{max_price} (#{percent_to_max.round(2)}%)"
end

#decorated_min_priceObject



67
68
69
# File 'lib/abot/info/decorators/coin_decorator.rb', line 67

def decorated_min_price
  "#{min_price} (#{percent_from_min_to_average.round(2)}%)"
end

#decorated_nameObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/abot/info/decorators/coin_decorator.rb', line 44

def decorated_name
  arrow = if .symbol_info(symbol).try(:[], :lastPrice).to_f < .symbol_info(symbol).try(:[], :askPrice).to_f
            Paint['', :green]
          elsif .symbol_info(symbol).try(:[], :lastPrice).to_f > .symbol_info(symbol).try(:[], :askPrice).to_f
            Paint['', :red]
          else
            ''
          end
  "#{name}(#{.symbol_info(symbol).try(:[], :priceChangePercent)}%)#{arrow}"
end

#decorated_name_mobileObject



55
56
57
# File 'lib/abot/info/decorators/coin_decorator.rb', line 55

def decorated_name_mobile
  name
end

#decorated_next_average_priceObject



40
41
42
# File 'lib/abot/info/decorators/coin_decorator.rb', line 40

def decorated_next_average_price
  "#{next_average_price} (#{decorated_next_average_price_percent})"
end

#decorated_next_average_price_percentObject



36
37
38
# File 'lib/abot/info/decorators/coin_decorator.rb', line 36

def decorated_next_average_price_percent
  "#{next_average_price_percent.round(2)}%"
end

#decorated_num_averagingObject



32
33
34
# File 'lib/abot/info/decorators/coin_decorator.rb', line 32

def decorated_num_averaging
  Paint[num_averaging, (Helpers::AVERAGE_COLORS[num_averaging] || :red)]
end

#decorated_potential_profitObject



79
80
81
82
83
84
85
# File 'lib/abot/info/decorators/coin_decorator.rb', line 79

def decorated_potential_profit
  if trade_params['quote_asset'].split(' ').count > 1
    "#{potential_profit.round(2)} #{quote_asset}"
  else
    potential_profit.round(2)
  end
end

#decorated_sell_priceObject



59
60
61
# File 'lib/abot/info/decorators/coin_decorator.rb', line 59

def decorated_sell_price
  sell_price
end

#decorated_sell_upObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/abot/info/decorators/coin_decorator.rb', line 7

def decorated_sell_up
  rounded_sell_up = sell_up.round(2)
  case num_averaging
  when 1, 2
    rounded_sell_up > 2 ? Paint[rounded_sell_up, :red] : rounded_sell_up
  when 3, 4, 5
    rounded_sell_up > 2 ? rounded_sell_up : Paint[rounded_sell_up, :red]
  else
    rounded_sell_up
  end
end

#decorated_timerObject



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
# File 'lib/abot/info/decorators/coin_decorator.rb', line 96

def decorated_timer
  sec = timer.to_s[0..9].to_f
  return '-' if sec < 1_577_836_800 # 2020-01-01 00:00:00 +0000

  medidas = ["г", "мес", "д", "ч", "м", "c"]
  array = [1970, 1, 1, 0, 0, 0]
  text = ''
  Time.at(Time.now.to_i - sec).utc.to_a.take(6).reverse.each_with_index do |k, i|
    case i
    when 0, 1, 2
      next if text.blank? && (k - array[i]).zero?

      text = "#{text} #{k - array[i]}#{medidas[i]}"
    when 3
      next_text = (k - array[i]).to_s.rjust(2, '0')
      text = "#{text} #{next_text}"
    when 4
      next_text = (k - array[i]).to_s.rjust(2, '0')
      text = "#{text}:#{next_text}"
    end
  end
  text
rescue StandardError
  '-'
end