Class: Trader::Balance
- Inherits:
-
Object
- Object
- Trader::Balance
- Defined in:
- lib/trade-o-matic/core/balance.rb
Instance Method Summary collapse
- #amount ⇒ Object
- #available_amount ⇒ Object
- #convert_to(_currency) ⇒ Object
- #currency ⇒ Object
- #frozen_amount ⇒ Object
-
#initialize(_backend, _session, _currency, _forced_currency = nil) ⇒ Balance
constructor
A new instance of Balance.
- #original_currency ⇒ Object
- #refresh! ⇒ Object
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
#amount ⇒ Object
27 28 29 |
# File 'lib/trade-o-matic/core/balance.rb', line 27 def amount convert original_currency.pack raw.amount end |
#available_amount ⇒ Object
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 |
#currency ⇒ Object
12 13 14 |
# File 'lib/trade-o-matic/core/balance.rb', line 12 def currency forced_currency || @currency end |
#frozen_amount ⇒ Object
35 36 37 |
# File 'lib/trade-o-matic/core/balance.rb', line 35 def frozen_amount convert(amount - available_amount) end |
#original_currency ⇒ Object
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 |