Class: Abot::Info::Coin
- Inherits:
-
Object
- Object
- Abot::Info::Coin
- 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
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#average_price ⇒ Object
readonly
Returns the value of attribute average_price.
-
#base_asset ⇒ Object
readonly
Returns the value of attribute base_asset.
-
#buy_price ⇒ Object
readonly
Returns the value of attribute buy_price.
-
#current_price ⇒ Object
readonly
Returns the value of attribute current_price.
-
#num_averaging ⇒ Object
readonly
Returns the value of attribute num_averaging.
-
#quote_asset ⇒ Object
readonly
Returns the value of attribute quote_asset.
-
#sell_price ⇒ Object
readonly
Returns the value of attribute sell_price.
-
#step_averaging ⇒ Object
readonly
Returns the value of attribute step_averaging.
-
#tick_size ⇒ Object
readonly
Returns the value of attribute tick_size.
-
#timer ⇒ Object
readonly
Returns the value of attribute timer.
-
#total_quote ⇒ Object
readonly
Returns the value of attribute total_quote.
-
#trade_params ⇒ Object
readonly
Returns the value of attribute trade_params.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Class Method Summary collapse
- .available_coins_number(current_coins, data_settings, free_balance) ⇒ Object
- .current_coins(account, trade_params) ⇒ Object
- .sum_current_profit(current_coins, quote) ⇒ Object
- .sum_potential_profit(current_coins, quote) ⇒ Object
Instance Method Summary collapse
- #current_profit ⇒ Object
- #current_quote ⇒ Object
-
#initialize(options = {}) ⇒ Coin
constructor
A new instance of Coin.
- #max_price ⇒ Object
- #min_price ⇒ Object
- #name ⇒ Object
- #next_average_price ⇒ Object
- #next_average_price_percent ⇒ Object
- #percent_from_min_to_average ⇒ Object
- #percent_to_max ⇒ Object
- #percent_to_order ⇒ Object
- #potential_profit ⇒ Object
- #sell_up ⇒ Object
- #symbol ⇒ Object
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( = {}) @trade_params = [:trade_params] @account = [:account] @base_asset = [:base_asset] @quote_asset = [:quote_asset] @average_price = [:average_price] @current_price = [:current_price] @sell_price = [:sell_price] @volume = [:volume] @num_averaging = [:num_averaging] @total_quote = [:total_quote] @buy_price = [:buy_price] @step_averaging = [:step_averaging] @tick_size = [:tick_size] @timer = [:timer] end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
10 11 12 |
# File 'lib/abot/info/coin.rb', line 10 def account @account end |
#average_price ⇒ Object (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_asset ⇒ Object (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_price ⇒ Object (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_price ⇒ Object (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_averaging ⇒ Object (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_asset ⇒ Object (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_price ⇒ Object (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_averaging ⇒ Object (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_size ⇒ Object (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 |
#timer ⇒ Object (readonly)
Returns the value of attribute timer.
10 11 12 |
# File 'lib/abot/info/coin.rb', line 10 def timer @timer end |
#total_quote ⇒ Object (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_params ⇒ Object (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 |
#volume ⇒ Object (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(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
93 94 95 |
# File 'lib/abot/info/coin.rb', line 93 def current_profit @current_profit ||= ((current_price - average_price) * volume) end |
#current_quote ⇒ Object
101 102 103 |
# File 'lib/abot/info/coin.rb', line 101 def current_quote @current_quote ||= (total_quote + current_profit) end |
#max_price ⇒ Object
89 90 91 |
# File 'lib/abot/info/coin.rb', line 89 def max_price @max_price ||= account.symbol_max_price(symbol) end |
#min_price ⇒ Object
85 86 87 |
# File 'lib/abot/info/coin.rb', line 85 def min_price @min_price ||= account.symbol_min_price(symbol) end |
#name ⇒ Object
118 119 120 |
# File 'lib/abot/info/coin.rb', line 118 def name quote_asset == 'USDT' ? base_asset : symbol end |
#next_average_price ⇒ Object
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_percent ⇒ Object
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_average ⇒ Object
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_max ⇒ Object
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_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
97 98 99 |
# File 'lib/abot/info/coin.rb', line 97 def potential_profit ((sell_price - average_price) * volume) end |
#sell_up ⇒ Object
105 106 107 |
# File 'lib/abot/info/coin.rb', line 105 def sell_up @sell_up ||= ((potential_profit / total_quote) * 100 - 0.15) end |
#symbol ⇒ Object
122 123 124 |
# File 'lib/abot/info/coin.rb', line 122 def symbol base_asset + quote_asset end |