Class: Capwatch::Fund

Inherits:
Object
  • Object
show all
Defined in:
lib/capwatch/fund.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, config:) ⇒ Fund



7
8
9
10
11
12
13
# File 'lib/capwatch/fund.rb', line 7

def initialize(provider:, config:)
  @provider = provider
  @config = config
  @positions = config.positions
  @coins = config.coins
  build
end

Instance Attribute Details

#coinsObject

Returns the value of attribute coins.



5
6
7
# File 'lib/capwatch/fund.rb', line 5

def coins
  @coins
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/capwatch/fund.rb', line 5

def config
  @config
end

#positionsObject

Returns the value of attribute positions.



5
6
7
# File 'lib/capwatch/fund.rb', line 5

def positions
  @positions
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/capwatch/fund.rb', line 5

def provider
  @provider
end

Instance Method Details

#[](symbol) ⇒ Object



15
16
17
# File 'lib/capwatch/fund.rb', line 15

def [](symbol)
  coins.find { |coin| coin.symbol == symbol }
end

#buildObject



43
44
45
46
47
# File 'lib/capwatch/fund.rb', line 43

def build
  calculator.assign_quantity
  calculator.assign_prices
  calculator.distribution
end

#calculatorObject



49
50
51
# File 'lib/capwatch/fund.rb', line 49

def calculator
  @calculator ||= FundCalculator.new(self)
end

#console_tableObject



67
68
69
# File 'lib/capwatch/fund.rb', line 67

def console_table
  Console.new(name = config.name, body = serialize, totals = fund_totals).draw_table
end

#fund_totalsObject



57
58
59
60
61
62
63
64
65
# File 'lib/capwatch/fund.rb', line 57

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

#percent_change_1hObject



31
32
33
# File 'lib/capwatch/fund.rb', line 31

def percent_change_1h
  coins.map { |coin| coin.percent_change_1h * coin.distribution }.sum
end

#percent_change_24hObject



35
36
37
# File 'lib/capwatch/fund.rb', line 35

def percent_change_24h
  coins.map { |coin| coin.percent_change_24h * coin.distribution }.sum
end

#percent_change_7dObject



39
40
41
# File 'lib/capwatch/fund.rb', line 39

def percent_change_7d
  coins.map { |coin| coin.percent_change_7d * coin.distribution }.sum
end

#serializeObject



53
54
55
# File 'lib/capwatch/fund.rb', line 53

def serialize
  coins.map { |coin| coin.serialize }.to_json
end

#value_btcObject



19
20
21
# File 'lib/capwatch/fund.rb', line 19

def value_btc
  coins.map(&:value_btc).sum
end

#value_ethObject



27
28
29
# File 'lib/capwatch/fund.rb', line 27

def value_eth
  coins.map(&:value_eth).sum
end

#value_usdObject



23
24
25
# File 'lib/capwatch/fund.rb', line 23

def value_usd
  coins.map(&:value_usd).sum
end