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



97
98
99
100
101
102
103
104
# File 'lib/abot/info/decorators/coin_decorator.rb', line 97

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



132
133
134
135
136
137
138
139
# File 'lib/abot/info/decorators/coin_decorator.rb', line 132

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



65
66
67
# File 'lib/abot/info/decorators/coin_decorator.rb', line 65

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

#decorated_current_price_perc_of_orderObject



69
70
71
# File 'lib/abot/info/decorators/coin_decorator.rb', line 69

def decorated_current_price_perc_of_order
  "#{current_price} (#{percent_from_order.round(2)}%)"
end

#decorated_current_profitObject



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

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



85
86
87
# File 'lib/abot/info/decorators/coin_decorator.rb', line 85

def decorated_current_quote
  current_quote.round(2)
end

#decorated_max_priceObject



77
78
79
# File 'lib/abot/info/decorators/coin_decorator.rb', line 77

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

#decorated_max_price_perc_of_orderObject



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

def decorated_max_price_perc_of_order
  "#{max_price} (#{percent_from_max.round(2)}%)"
end

#decorated_min_priceObject



73
74
75
# File 'lib/abot/info/decorators/coin_decorator.rb', line 73

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

#decorated_nameObject



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

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



57
58
59
# File 'lib/abot/info/decorators/coin_decorator.rb', line 57

def decorated_name_mobile
  name
end

#decorated_next_average_priceObject



42
43
44
# File 'lib/abot/info/decorators/coin_decorator.rb', line 42

def decorated_next_average_price
  next_average_price.zero? ? '-' : "#{next_average_price} (#{decorated_next_average_price_percent})"
end

#decorated_next_average_price_percentObject



38
39
40
# File 'lib/abot/info/decorators/coin_decorator.rb', line 38

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

#decorated_num_averagingObject



34
35
36
# File 'lib/abot/info/decorators/coin_decorator.rb', line 34

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

#decorated_potential_profitObject



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

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



61
62
63
# File 'lib/abot/info/decorators/coin_decorator.rb', line 61

def decorated_sell_price
  sell_price
end

#decorated_sell_upObject



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

def decorated_sell_up
  return '-' if sell_up == Float::INFINITY

  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



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

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