Class: Abot::Info::Coin
- Inherits:
-
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 =
%w[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
#decorated_buy_date, #decorated_cell, #decorated_current_price, #decorated_current_price_perc_of_order, #decorated_current_profit, #decorated_current_quote, #decorated_max_price, #decorated_max_price_perc_of_order, #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.
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/abot/info/coin.rb', line 16
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
#account ⇒ Object
Returns the value of attribute account.
10
11
12
|
# File 'lib/abot/info/coin.rb', line 10
def account
@account
end
|
#average_price ⇒ Object
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_asset ⇒ Object
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_price ⇒ Object
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_price ⇒ Object
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_averaging ⇒ Object
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_asset ⇒ Object
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_price ⇒ Object
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_averaging ⇒ Object
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_size ⇒ Object
Returns the value of attribute tick_size.
10
11
12
|
# File 'lib/abot/info/coin.rb', line 10
def tick_size
@tick_size
end
|
#timer ⇒ Object
Returns the value of attribute timer.
10
11
12
|
# File 'lib/abot/info/coin.rb', line 10
def timer
@timer
end
|
#total_quote ⇒ Object
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_params ⇒ Object
Returns the value of attribute trade_params.
10
11
12
|
# File 'lib/abot/info/coin.rb', line 10
def trade_params
@trade_params
end
|
#volume ⇒ Object
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
54
55
56
57
58
59
60
61
62
|
# File 'lib/abot/info/coin.rb', line 54
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/abot/info/coin.rb', line 33
def self.current_coins(account, trade_params)
DatabaseTable.data_coins.map do |coin|
Coin.new(
trade_params: trade_params,
account: 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
64
65
66
67
|
# File 'lib/abot/info/coin.rb', line 64
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
69
70
71
72
|
# File 'lib/abot/info/coin.rb', line 69
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_profit ⇒ Object
102
103
104
|
# File 'lib/abot/info/coin.rb', line 102
def current_profit
@current_profit ||= ((current_price - average_price) * volume)
end
|
#current_quote ⇒ Object
110
111
112
|
# File 'lib/abot/info/coin.rb', line 110
def current_quote
@current_quote ||= (total_quote + current_profit)
end
|
#max_price ⇒ Object
98
99
100
|
# File 'lib/abot/info/coin.rb', line 98
def max_price
@max_price ||= account.symbol_max_price(symbol)
end
|
#min_price ⇒ Object
94
95
96
|
# File 'lib/abot/info/coin.rb', line 94
def min_price
@min_price ||= account.symbol_min_price(symbol)
end
|
#name ⇒ Object
127
128
129
|
# File 'lib/abot/info/coin.rb', line 127
def name
quote_asset == 'USDT' ? base_asset : symbol
end
|
#next_average_price ⇒ Object
118
119
120
121
|
# File 'lib/abot/info/coin.rb', line 118
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_percent ⇒ Object
123
124
125
|
# File 'lib/abot/info/coin.rb', line 123
def next_average_price_percent
@next_average_price_percent ||= ((current_price / next_average_price - 1) * 100)
end
|
#percent_from_max ⇒ Object
90
91
92
|
# File 'lib/abot/info/coin.rb', line 90
def percent_from_max
@percent_from_max ||= ((1 - max_price / sell_price) * 100)
end
|
#percent_from_min_to_average ⇒ Object
82
83
84
|
# File 'lib/abot/info/coin.rb', line 82
def percent_from_min_to_average
@percent_to_min ||= ((min_price / next_average_price - 1) * 100)
end
|
#percent_from_order ⇒ Object
78
79
80
|
# File 'lib/abot/info/coin.rb', line 78
def percent_from_order
@percent_from_order ||= ((1 - current_price / sell_price) * 100)
end
|
#percent_to_max ⇒ Object
86
87
88
|
# File 'lib/abot/info/coin.rb', line 86
def percent_to_max
@percent_to_max ||= ((sell_price / max_price - 1) * 100)
end
|
#percent_to_order ⇒ Object
74
75
76
|
# File 'lib/abot/info/coin.rb', line 74
def percent_to_order
@percent_to_order ||= ((sell_price / current_price - 1) * 100)
end
|
#potential_profit ⇒ Object
106
107
108
|
# File 'lib/abot/info/coin.rb', line 106
def potential_profit
((sell_price - average_price) * volume)
end
|
#sell_up ⇒ Object
114
115
116
|
# File 'lib/abot/info/coin.rb', line 114
def sell_up
@sell_up ||= ((potential_profit / total_quote) * 100 - 0.15)
end
|
#symbol ⇒ Object
131
132
133
|
# File 'lib/abot/info/coin.rb', line 131
def symbol
base_asset + quote_asset
end
|