class CoinPortfolio::Calculator

Attributes

api_key[R]
api_secret[R]

Public Class Methods

new(api_key:, api_secret:) click to toggle source
# File lib/coin_portfolio/calculator.rb, line 3
def initialize(api_key:, api_secret:)
  @api_key = api_key
  @api_secret = api_secret
end

Public Instance Methods

potential_returns() click to toggle source
# File lib/coin_portfolio/calculator.rb, line 8
def potential_returns
  liquidation = Liquidation.new(inventory_items)
  details = liquidation.details(price)
  puts "Gains percentage: #{format_percentage(details.gains_percentage)}"
  puts "Portfolio cost: #{details.portfolio_cost}"
  puts "Current portfolio value: #{details.current_portfolio_value}"
  details
end

Private Instance Methods

client() click to toggle source
# File lib/coin_portfolio/calculator.rb, line 38
def client
  @client ||= ExchangeClient.new(api_key: api_key, api_secret: api_secret)
end
format_percentage(percentage) click to toggle source
# File lib/coin_portfolio/calculator.rb, line 21
def format_percentage(percentage)
  rounded = (percentage * 100).round(2)
  "#{sprintf("%.2f", rounded)}%"
end
inventory_items() click to toggle source
# File lib/coin_portfolio/calculator.rb, line 26
def inventory_items
  Inventory.new(transactions).build
end
price() click to toggle source
# File lib/coin_portfolio/calculator.rb, line 34
def price
  client.price
end
transactions() click to toggle source
# File lib/coin_portfolio/calculator.rb, line 30
def transactions
  client.transactions
end