Class: Abot::Info::BinanceAccount
- Inherits:
-
Object
- Object
- Abot::Info::BinanceAccount
- Defined in:
- lib/abot/info/binance_account.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #account_info ⇒ Object
- #current_balance(balance_btc, quote) ⇒ Object
- #current_balance_btc ⇒ Object
- #current_balance_wl(current_coins, quote) ⇒ Object
- #free_balance(quote) ⇒ Object
-
#initialize(api_key, secret_key) ⇒ BinanceAccount
constructor
A new instance of BinanceAccount.
- #percent_free_balance(balance, quote) ⇒ Object
- #potential_balance(current_coins, trade_params) ⇒ Object
- #symbol_info(symbol) ⇒ Object
- #symbol_max_price(symbol) ⇒ Object
- #symbol_min_price(symbol) ⇒ Object
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_key ⇒ Object (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_key ⇒ Object (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_info ⇒ Object
33 34 35 36 37 38 |
# File 'lib/abot/info/binance_account.rb', line 33 def account_info @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_btc ⇒ Object
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) account_info[: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 |