Sha256: 037197703365b39dabde257e88993e10e39aecef6a09178751b1b8d65ed80c27
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true module Capwatch class Fund attr_accessor :provider, :config, :coins, :positions def initialize(provider:, config:) @provider = provider @config = config @positions = config.positions @coins = config.coins build end def [](symbol) coins.find { |coin| coin.symbol == symbol } end def value_btc coins.map(&:value_btc).sum end def value_usd coins.map(&:value_usd).sum end def value_eth coins.map(&:value_eth).sum end def percent_change_1h coins.map { |coin| coin.percent_change_1h * coin.distribution }.sum end def percent_change_24h coins.map { |coin| coin.percent_change_24h * coin.distribution }.sum end def percent_change_7d coins.map { |coin| coin.percent_change_7d * coin.distribution }.sum end def build calculator.assign_quantity calculator.assign_prices calculator.distribution end def calculator @calculator ||= FundCalculator.new(self) end def serialize coins.map { |coin| coin.serialize }.to_json end def fund_totals { value_usd: value_usd, value_btc: value_btc, value_eth: value_eth, percent_change_24h: percent_change_24h, percent_change_7d: percent_change_7d } end def console_table Console.new(name = config.name, body = serialize, totals = fund_totals).draw_table end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
capwatch-0.2.3 | lib/capwatch/fund.rb |
capwatch-0.2.0 | lib/capwatch/fund.rb |