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 =
['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.
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
#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
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(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
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_profit ⇒ Object
101
102
103
|
# File 'lib/abot/info/coin.rb', line 101
def current_profit
@current_profit ||= ((current_price - average_price) * volume)
end
|
#current_quote ⇒ Object
109
110
111
|
# File 'lib/abot/info/coin.rb', line 109
def current_quote
@current_quote ||= (total_quote + current_profit)
end
|
#max_price ⇒ Object
97
98
99
|
# File 'lib/abot/info/coin.rb', line 97
def max_price
@max_price ||= account.symbol_max_price(symbol)
end
|
#min_price ⇒ Object
93
94
95
|
# File 'lib/abot/info/coin.rb', line 93
def min_price
@min_price ||= account.symbol_min_price(symbol)
end
|
#name ⇒ Object
126
127
128
|
# File 'lib/abot/info/coin.rb', line 126
def name
quote_asset == 'USDT' ? base_asset : symbol
end
|
#next_average_price ⇒ Object
117
118
119
120
|
# File 'lib/abot/info/coin.rb', line 117
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
122
123
124
|
# File 'lib/abot/info/coin.rb', line 122
def next_average_price_percent
@next_average_price_percent ||= ((current_price / next_average_price - 1) * 100)
end
|
#percent_from_max ⇒ Object
89
90
91
|
# File 'lib/abot/info/coin.rb', line 89
def percent_from_max
@percent_from_max ||= ((1 - max_price / sell_price) * 100)
end
|
#percent_from_min_to_average ⇒ Object
81
82
83
|
# File 'lib/abot/info/coin.rb', line 81
def percent_from_min_to_average
@percent_to_min ||= ((min_price / next_average_price - 1) * 100)
end
|
#percent_from_order ⇒ Object
77
78
79
|
# File 'lib/abot/info/coin.rb', line 77
def percent_from_order
@percent_from_order ||= ((1 - current_price / sell_price) * 100)
end
|
#percent_to_max ⇒ Object
85
86
87
|
# File 'lib/abot/info/coin.rb', line 85
def percent_to_max
@percent_to_max ||= ((sell_price / max_price - 1) * 100)
end
|
#percent_to_order ⇒ Object
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_profit ⇒ Object
105
106
107
|
# File 'lib/abot/info/coin.rb', line 105
def potential_profit
((sell_price - average_price) * volume)
end
|
#sell_up ⇒ Object
113
114
115
|
# File 'lib/abot/info/coin.rb', line 113
def sell_up
@sell_up ||= ((potential_profit / total_quote) * 100 - 0.15)
end
|
#symbol ⇒ Object
130
131
132
|
# File 'lib/abot/info/coin.rb', line 130
def symbol
base_asset + quote_asset
end
|