Class: Abot::Info::BinanceAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/abot/info/binance_account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key) ⇒ BinanceAccount

Returns a new instance of BinanceAccount.



8
9
10
11
# File 'lib/abot/info/binance_account.rb', line 8

def initialize(api_key, secret_key)
  @api_key = api_key
  @secret_key = secret_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/abot/info/binance_account.rb', line 6

def api_key
  @api_key
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



6
7
8
# File 'lib/abot/info/binance_account.rb', line 6

def secret_key
  @secret_key
end

Instance Method Details

#account_infoObject



33
34
35
36
37
38
# File 'lib/abot/info/binance_account.rb', line 33

def 
  @account_info ||= Binance::Api::Account.info!(
    api_key: api_key,
    api_secret_key: secret_key,
    )
end

#current_balance(balance_btc, quote) ⇒ Object



21
22
23
# File 'lib/abot/info/binance_account.rb', line 21

def current_balance(balance_btc, quote)
  calculation_current_balance(balance_btc, quote)
end

#current_balance_btcObject



17
18
19
# File 'lib/abot/info/binance_account.rb', line 17

def current_balance_btc
  @current_balance_btc ||= calculation_current_balance_btc
end

#current_balance_wl(current_coins, quote) ⇒ Object



25
26
27
# File 'lib/abot/info/binance_account.rb', line 25

def current_balance_wl(current_coins, quote)
  calculation_current_balance_wl(current_coins, quote)
end

#free_balance(quote) ⇒ Object



13
14
15
# File 'lib/abot/info/binance_account.rb', line 13

def free_balance(quote)
  [:balances].find { |f| f[:asset] == quote }.try(:[], :free).to_f
end

#percent_free_balance(balance, quote) ⇒ Object



29
30
31
# File 'lib/abot/info/binance_account.rb', line 29

def percent_free_balance(balance, quote)
  ((free_balance(quote) / balance) * 100).round(2)
end

#potential_balance(current_coins, trade_params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/abot/info/binance_account.rb', line 40

def potential_balance(current_coins, trade_params)
  return @potential_balance if @potential_balance

  balance = current_balance(current_balance_btc, 'USDT')
  quote_assets = trade_params['quote_asset'].split(' ')
  potential = 0.0
  btcusdt = get_symbols.find { |f| f[:symbol] == 'BTCUSDT' }

  quote_assets.each do |q|
    begin
      pp_q = Coin.sum_potential_profit(current_coins, q) - Coin.sum_current_profit(current_coins, q)
      if q == 'USDT'
        potential += pp_q
      elsif q == 'BTC'
        potential += pp_q * btcusdt[:askPrice].to_f
      elsif Coin::FIAT.include?(q)
        btc = pp_q / get_symbols.find { |f| f[:symbol] == "BTC#{quote_asset}" }[:askPrice].to_f
        potential += btc * btcusdt[:askPrice].to_f
      else
        c = pp_q / get_symbols.find { |f| f[:symbol] == "#{quote_asset}BTC" }[:askPrice].to_f
        potential += btcusdt[:askPrice].to_f / c
      end
    rescue StandardError
      puts "Ошибка подсчета потенц. баланса: #{q}"
    end
  end

  @potential_balance ||= potential + balance
end

#symbol_info(symbol) ⇒ Object



70
71
72
# File 'lib/abot/info/binance_account.rb', line 70

def symbol_info(symbol)
  get_symbols.find { |f| f[:symbol] == symbol }
end

#symbol_max_price(symbol) ⇒ Object



78
79
80
# File 'lib/abot/info/binance_account.rb', line 78

def symbol_max_price(symbol)
  symbol_info(symbol).try(:[], :highPrice).to_f
end

#symbol_min_price(symbol) ⇒ Object



74
75
76
# File 'lib/abot/info/binance_account.rb', line 74

def symbol_min_price(symbol)
  symbol_info(symbol).try(:[], :lowPrice).to_f
end