Class: Abot::Info::Coin

Inherits:
Object
  • Object
show all
Includes:
CoinDecorator
Defined in:
lib/abot/info/coin.rb,
lib/abot/info/decorators/coin_decorator.rb

Defined Under Namespace

Modules: CoinDecorator

Constant Summary collapse

FIAT =
['USDT', 'BUSD', 'AUD', 'BIDR', 'BRL', 'EUR', 'GBR', 'RUB', 'TRY', 'TUSD', 'USDC', 'DAI', 'IDRT', 'PAX', 'UAH', 'NGN', 'VAI', 'BVND']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CoinDecorator

#decorated_buy_date, #decorated_cell, #decorated_current_price, #decorated_current_profit, #decorated_current_quote, #decorated_max_price, #decorated_min_price, #decorated_name, #decorated_name_mobile, #decorated_next_average_price, #decorated_next_average_price_percent, #decorated_num_averaging, #decorated_potential_profit, #decorated_sell_price, #decorated_sell_up, #decorated_timer

Constructor Details

#initialize(options = {}) ⇒ Coin

Returns a new instance of Coin.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/abot/info/coin.rb', line 15

def initialize(options = {})
  @trade_params = options[:trade_params]
  @account = options[:account]
  @base_asset = options[:base_asset]
  @quote_asset = options[:quote_asset]
  @average_price = options[:average_price]
  @current_price = options[:current_price]
  @sell_price = options[:sell_price]
  @volume = options[:volume]
  @num_averaging = options[:num_averaging]
  @total_quote = options[:total_quote]
  @buy_price = options[:buy_price]
  @step_averaging = options[:step_averaging]
  @tick_size = options[:tick_size]
  @timer = options[:timer]
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def 
  @account
end

#average_priceObject (readonly)

Returns the value of attribute average_price.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def average_price
  @average_price
end

#base_assetObject (readonly)

Returns the value of attribute base_asset.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def base_asset
  @base_asset
end

#buy_priceObject (readonly)

Returns the value of attribute buy_price.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def buy_price
  @buy_price
end

#current_priceObject (readonly)

Returns the value of attribute current_price.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def current_price
  @current_price
end

#num_averagingObject (readonly)

Returns the value of attribute num_averaging.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def num_averaging
  @num_averaging
end

#quote_assetObject (readonly)

Returns the value of attribute quote_asset.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def quote_asset
  @quote_asset
end

#sell_priceObject (readonly)

Returns the value of attribute sell_price.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def sell_price
  @sell_price
end

#step_averagingObject (readonly)

Returns the value of attribute step_averaging.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def step_averaging
  @step_averaging
end

#tick_sizeObject (readonly)

Returns the value of attribute tick_size.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def tick_size
  @tick_size
end

#timerObject (readonly)

Returns the value of attribute timer.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def timer
  @timer
end

#total_quoteObject (readonly)

Returns the value of attribute total_quote.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def total_quote
  @total_quote
end

#trade_paramsObject (readonly)

Returns the value of attribute trade_params.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def trade_params
  @trade_params
end

#volumeObject (readonly)

Returns the value of attribute volume.



10
11
12
# File 'lib/abot/info/coin.rb', line 10

def volume
  @volume
end

Class Method Details

.available_coins_number(current_coins, data_settings, free_balance) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/abot/info/coin.rb', line 53

def self.available_coins_number(current_coins, data_settings, free_balance)
  aver_arr = []
  current_coins.each_with_index {|m| aver_arr[m.num_averaging] = ((aver_arr[m.num_averaging].to_i) + 1) }
  aver_weight = 0
  aver_arr.each_with_index { |e, idx| aver_weight += (e.to_i * idx) }
  max_pairs = (free_balance / 100) * data_settings["max_trade_pairs"].to_i
  progressive_max_pairs = max_pairs - aver_weight
  progressive_max_pairs.positive? ? progressive_max_pairs.round(0) : 0
end

.current_coins(account, trade_params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/abot/info/coin.rb', line 32

def self.current_coins(, trade_params)
  DatabaseTable.data_coins.map do |coin|
    Coin.new(
      trade_params: trade_params,
      account: ,
      base_asset: coin['baseAsset'],
      quote_asset: coin['quoteAsset'],
      average_price: coin['averagePrice'].to_f,
      current_price: coin['askPrice'].to_f,
      sell_price: coin['sellPrice'].to_f,
      volume: coin['allQuantity'].to_f,
      num_averaging: (coin['numAveraging'].to_i - 1),
      total_quote: coin['totalQuote'].to_f.round(2),
      buy_price: coin['buyPrice'].to_f,
      step_averaging: coin['stepAveraging'].to_f,
      tick_size: coin['tickSize'],
      timer: coin['timer'].to_s[0..9],
    )
  end
end

.sum_current_profit(current_coins, quote) ⇒ Object



63
64
65
66
# File 'lib/abot/info/coin.rb', line 63

def self.sum_current_profit(current_coins, quote)
  current_coins = current_coins.select { |s| s.quote_asset == quote }
  current_coins.sum(&:current_profit)
end

.sum_potential_profit(current_coins, quote) ⇒ Object



68
69
70
71
# File 'lib/abot/info/coin.rb', line 68

def self.sum_potential_profit(current_coins, quote)
  current_coins = current_coins.select { |s| s.quote_asset == quote }
  current_coins.sum(&:potential_profit)
end

Instance Method Details

#current_profitObject



93
94
95
# File 'lib/abot/info/coin.rb', line 93

def current_profit
  @current_profit ||= ((current_price - average_price) * volume)
end

#current_quoteObject



101
102
103
# File 'lib/abot/info/coin.rb', line 101

def current_quote
  @current_quote ||= (total_quote + current_profit)
end

#max_priceObject



89
90
91
# File 'lib/abot/info/coin.rb', line 89

def max_price
  @max_price ||= .symbol_max_price(symbol)
end

#min_priceObject



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

def min_price
  @min_price ||= .symbol_min_price(symbol)
end

#nameObject



118
119
120
# File 'lib/abot/info/coin.rb', line 118

def name
  quote_asset == 'USDT' ? base_asset : symbol
end

#next_average_priceObject



109
110
111
112
# File 'lib/abot/info/coin.rb', line 109

def next_average_price
  @next_average_price ||=
    (buy_price - (buy_price / 100 * (step_averaging - trade_params['buy_down'].to_f))).round(tick_round_size)
end

#next_average_price_percentObject



114
115
116
# File 'lib/abot/info/coin.rb', line 114

def next_average_price_percent
  @next_average_price_percent ||= ((current_price / next_average_price - 1) * 100)
end

#percent_from_min_to_averageObject



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

def percent_from_min_to_average
  @percent_to_min ||= ((min_price / next_average_price - 1) * 100)
end

#percent_to_maxObject



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

def percent_to_max
  @percent_to_max ||= ((sell_price / max_price - 1) * 100)
end

#percent_to_orderObject



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

def percent_to_order
  @percent_to_order ||= ((sell_price / current_price - 1) * 100)
end

#potential_profitObject



97
98
99
# File 'lib/abot/info/coin.rb', line 97

def potential_profit
  ((sell_price - average_price) * volume)
end

#sell_upObject



105
106
107
# File 'lib/abot/info/coin.rb', line 105

def sell_up
  @sell_up ||= ((potential_profit / total_quote) * 100 - 0.15)
end

#symbolObject



122
123
124
# File 'lib/abot/info/coin.rb', line 122

def symbol
  base_asset + quote_asset
end