Class: Trader::Balance

Inherits:
Object
  • Object
show all
Defined in:
lib/trade-o-matic/core/balance.rb

Instance Method Summary collapse

Constructor Details

#initialize(_backend, _session, _currency, _forced_currency = nil) ⇒ Balance

Returns a new instance of Balance.



4
5
6
7
8
9
10
# File 'lib/trade-o-matic/core/balance.rb', line 4

def initialize(_backend, _session, _currency, _forced_currency=nil)
  @backend = _backend
  @session = _session
  @currency = _currency
  @forced_currency = _forced_currency
  @raw = nil
end

Instance Method Details

#amountObject



27
28
29
# File 'lib/trade-o-matic/core/balance.rb', line 27

def amount
  convert original_currency.pack raw.amount
end

#available_amountObject



31
32
33
# File 'lib/trade-o-matic/core/balance.rb', line 31

def available_amount
  convert original_currency.pack raw.available_amount
end

#convert_to(_currency) ⇒ Object



20
21
22
23
24
25
# File 'lib/trade-o-matic/core/balance.rb', line 20

def convert_to(_currency)
  return self if _currency == currency
  copy = self.class.new backend, session, original_currency, _currency
  copy.raw = raw unless raw.nil?
  copy
end

#currencyObject



12
13
14
# File 'lib/trade-o-matic/core/balance.rb', line 12

def currency
  forced_currency || @currency
end

#frozen_amountObject



35
36
37
# File 'lib/trade-o-matic/core/balance.rb', line 35

def frozen_amount
  convert(amount - available_amount)
end

#original_currencyObject



16
17
18
# File 'lib/trade-o-matic/core/balance.rb', line 16

def original_currency
  @currency
end

#refresh!Object



39
40
41
42
# File 'lib/trade-o-matic/core/balance.rb', line 39

def refresh!
  self.raw = backend.get_balance(session, currency)
  self
end